Exemplo n.º 1
0
  private boolean saveNote() {

    EditText mTitleText = (EditText) findViewById(R.id.title);
    EditText mBody2Text = (EditText) findViewById(R.id.body2);

    String title = mTitleText.getText().toString().trim();
    String body2 = mBody2Text.getText().toString().trim();

    if (title.equals("")) {
      NotelyLogger.Log(TAG, "not saving empty title note entry");
      return false;
    }

    if (mRowId == null) {

      NotelyLogger.Log(TAG, "creating: " + title);
      mRowId = NoteHelper.createNote(NoteEdit.this, title, body2);
      Toast.makeText(this, R.string.toast_created, Toast.LENGTH_SHORT).show();

    } else {

      Toast.makeText(this, R.string.toast_saved, Toast.LENGTH_SHORT).show();
      NotelyLogger.Log(TAG, "updating row " + mRowId + ": " + title);
      NoteHelper.updateNote(NoteEdit.this, mRowId, title, body2);
    }

    return true;
  }
Exemplo n.º 2
0
  @Override
  protected void onSaveInstanceState(Bundle outState) {

    super.onSaveInstanceState(outState);
    NotelyLogger.Log(TAG, "instance state save");

    EditText mTitleText = (EditText) findViewById(R.id.title);
    EditText mBodyText2 = (EditText) findViewById(R.id.body2);

    String title = mTitleText.getText().toString().trim();
    String body2 = mBodyText2.getText().toString().trim();

    outState.putSerializable(NoteDb.KEY_ROWID, mRowId);
    outState.putSerializable(EDITABLE_FLAG, isEditable);

    outState.putSerializable(NoteDb.KEY_TITLE, title);
    outState.putSerializable(NoteDb.KEY_BODY, body2);
  }
Exemplo n.º 3
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {

    NotelyLogger.Log(TAG, "creating options menu");

    super.onCreateOptionsMenu(menu);

    MenuItem emailItem = menu.add(0, EMAIL_ID, 0, R.string.menu_edit_email);
    emailItem.setIcon(R.drawable.ic_menu_send);

    MenuItem smsItem = menu.add(0, SMS_ID, 0, R.string.menu_edit_sms);
    smsItem.setIcon(R.drawable.ic_menu_friendslist);

    MenuItem backItem = menu.add(0, BACK_ID, 0, R.string.menu_edit_back);
    backItem.setIcon(R.drawable.ic_menu_back);

    return true;
  }
Exemplo n.º 4
0
 @Override
 protected void onStart() {
   super.onStart();
   NotelyLogger.Log(TAG, "onstart called");
 }
Exemplo n.º 5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.note_edit);

    GestureOverlayView gestureView = (GestureOverlayView) findViewById(R.id.edit_gestures);
    gestureView.setGestureColor(Color.TRANSPARENT);
    gestureView.setUncertainGestureColor(Color.TRANSPARENT);

    gLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!gLib.load()) {
      NotelyLogger.Log(TAG, "could not load gestures library");
      finish();
    } else {
      NotelyLogger.Log(TAG, "gestures library loaded");
    }

    gestureView.addOnGesturePerformedListener(handleGestureListener);

    Button confirmButton = (Button) findViewById(R.id.confirm);
    Button cancelButton = (Button) findViewById(R.id.cancel);

    // get shit back if there was a saved state
    mRowId =
        (savedInstanceState == null)
            ? null
            : (Long) savedInstanceState.getSerializable(NoteDb.KEY_ROWID);
    isEditable =
        (savedInstanceState == null)
            ? false
            : (Boolean) savedInstanceState.getSerializable(EDITABLE_FLAG);

    // also see if the id was passed in via an edit activity call
    if (mRowId == null) {
      Bundle extras = getIntent().getExtras();
      mRowId = extras != null ? extras.getLong(NoteDb.KEY_ROWID) : null;
    }

    // if you're editing an existing note, have it say edit since the default is to not be editable
    if (mRowId != null) {
      confirmButton.setText(R.string.edit);
      setTitle(R.string.edit_note);
    } else {
      setTitle(R.string.create_note);
    }

    instanceState = savedInstanceState;

    confirmButton.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {

            EditText mTitleText = (EditText) findViewById(R.id.title);
            EditText mBodyText = (EditText) findViewById(R.id.body);
            EditText mBody2Text = (EditText) findViewById(R.id.body2);

            if (mRowId != null && isEditable == false) {

              NotelyLogger.Log(TAG, "setting things editable");

              isEditable = true;

              // swap views
              mBodyText.setVisibility(View.GONE);
              mBody2Text.setVisibility(View.VISIBLE);

              mTitleText.setFocusableInTouchMode(true);
              mTitleText.setCursorVisible(true);

              Button confirmButton = (Button) findViewById(R.id.confirm);
              Button cancelButton = (Button) findViewById(R.id.cancel);

              confirmButton.setText(R.string.confirm);
              cancelButton.setText(R.string.cancel);

            } else {

              boolean res = saveNote();

              if (res) {

                NotelyLogger.Log(TAG, "setting things not editable");

                isEditable = false;

                // update old text field
                String body2 = mBody2Text.getText().toString();
                mBodyText.setText(body2);

                // swap views
                mBodyText.setVisibility(View.VISIBLE);
                mBody2Text.setVisibility(View.GONE);

                mTitleText.setFocusable(false);
                mTitleText.setCursorVisible(false);

                Button confirmButton = (Button) findViewById(R.id.confirm);
                Button cancelButton = (Button) findViewById(R.id.cancel);

                confirmButton.setText(R.string.edit);
                cancelButton.setText(R.string.back);

                // close soft keyboard
                InputMethodManager inputManager =
                    (InputMethodManager)
                        NoteEdit.this.getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(
                    mBody2Text.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

              } else {

                if (mRowId != null) {
                  Toast.makeText(NoteEdit.this, R.string.toast_noupdateempty, Toast.LENGTH_SHORT)
                      .show();
                } else {
                  Toast.makeText(NoteEdit.this, R.string.toast_nocreateempty, Toast.LENGTH_SHORT)
                      .show();
                }
              }
            }
          }
        });

    cancelButton.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View v) {

            EditText mTitleText = (EditText) findViewById(R.id.title);
            EditText mBodyText = (EditText) findViewById(R.id.body);
            EditText mBody2Text = (EditText) findViewById(R.id.body2);

            if (isEditable == true) {

              isEditable = false;

              // set possibly edited text back
              String body = mBodyText.getText().toString();
              mBody2Text.setText(body);

              // set possibly edited title back too
              Note note = NoteHelper.getNote(NoteEdit.this, mRowId);
              mTitleText.setText(note.getTitle());

              // swap views
              mBodyText.setVisibility(View.VISIBLE);
              mBody2Text.setVisibility(View.GONE);

              mTitleText.setFocusable(false);
              mTitleText.setCursorVisible(false);

              Button confirmButton = (Button) findViewById(R.id.confirm);
              Button cancelButton = (Button) findViewById(R.id.cancel);

              confirmButton.setText(R.string.edit);
              cancelButton.setText(R.string.back);

              // close soft keyboard
              InputMethodManager inputManager =
                  (InputMethodManager) NoteEdit.this.getSystemService(Context.INPUT_METHOD_SERVICE);
              inputManager.hideSoftInputFromWindow(
                  mBody2Text.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

            } else {
              setResult(RESULT_OK);
              finish();
            }
          }
        });

    NotelyLogger.Log(TAG, "oncreate called");
  }
Exemplo n.º 6
0
 @Override
 protected void onResume() {
   super.onResume();
   NotelyLogger.Log(TAG, "onresume called");
   populateFields(instanceState);
 }
Exemplo n.º 7
0
 @Override
 protected void onPause() {
   super.onPause();
   NotelyLogger.Log(TAG, "onpause called");
 }