private void saveNote() {
    Log.d(TAG, "saveNote() called");

    String title = titleEditText.getText().toString();
    String body = bodyEditText.getText().toString();

    if (title.isEmpty()) {
      if (!body.isEmpty()) {
        note.setTitle(body.substring(0, DEFAULT_TITLE_LENGTH));
      } else {
        note.setTitle(PLACEHOLDER_TEXT_FOR_DATABASE);
      }
    }
    if (body.isEmpty()) {
      note.setBody(PLACEHOLDER_TEXT_FOR_DATABASE);
    }

    note.setTitle(title);
    note.setBody(body);

    if (noteExistsInDatabase == false) {
      Log.d(TAG, "Adding the following note: " + note.toString());
      noteProvider.addNote(note);
    } else {
      Log.d(TAG, "Updating the following note: " + note.toString());
      noteProvider.updateNote(note);
    }

    noteExistsInDatabase = true;
  }
  private void handleNoteData() {
    noteProvider = NoteProvider.get(getApplicationContext());

    Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_CREATE_NEW_NOTE)) {
      note = new Note();
      noteExistsInDatabase = false;

      showKeyboardOnTitleEditText();
    } else if (intent.hasExtra(EXTRA_NOTE_ID)) {
      setUpNoteFromDatabase(intent);
    }
  }
  private void setUpNoteFromDatabase(Intent intent) {
    long id = intent.getLongExtra(EXTRA_NOTE_ID, 1);
    Log.d(TAG, "Got ID " + id + " from intent extra");

    note = noteProvider.getNote(id);
    Log.d(TAG, "Retrieved the following Note from the database: " + note.toString());

    if (note.getTitle().equals(PLACEHOLDER_TEXT_FOR_DATABASE)) {
      note.setTitle("");
    }
    if (note.getBody().equals(PLACEHOLDER_TEXT_FOR_DATABASE)) {
      note.setBody("");
    }

    titleEditText.setText(note.getTitle());
    bodyEditText.setText(note.getBody());

    noteExistsInDatabase = true;
  }