コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Util.setPrefTheme(this);
    super.onCreate(savedInstanceState);
    Log.i(LOG_TAG, "initiating adapter");
    mAdapter = new DatabaseAdapter(this);
    mAdapter.open();

    Bundle b = this.getIntent().getExtras();
    if (b != null) {
      mNoteId = b.getLong(DatabaseAdapter.ID_COL, Const.INVALID_LONG);
      Log.i(LOG_TAG, "Got note ID from intent's bundle: " + mNoteId);
    }
    if (mNoteId == Const.INVALID_LONG) {
      Serializable savedState = savedInstanceState.getSerializable(DatabaseAdapter.ID_COL);
      mNoteId =
          savedState == null || !(savedState instanceof Long)
              ? Const.INVALID_LONG
              : (Long) savedState;
      Log.i(LOG_TAG, "Nothing in the intent, and mNoteId in saved instance state is: " + mNoteId);
    }
    this.setContentView(R.layout.view_note);
    // note display is in onResume
    this.displayNoteOrGoUp();
  }
コード例 #2
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   if (mAdapter != null) {
     Log.i(LOG_TAG, "Close adapter");
     mAdapter.close();
   }
 }
コード例 #3
0
  /**
   * Put the note detail into view layout, and go up one level if no ID found
   *
   * <p>Note: it resets the ListAdapter each time it returns to the screen
   */
  private void displayNoteOrGoUp() {
    // this will return empty cursor only if there is no note core entry
    Cursor noteCursor = mAdapter.getFullNoteOrCoreById(mNoteId);
    if (noteCursor.getCount() < 1) {
      Log.e(LOG_TAG, mNoteId + " doesn't point to a valid note");
      // if no results from getNoteOrCore(), it means no note exists under mNoteId
      this.goUp();
      return;
    }

    Log.i(LOG_TAG, "Found " + noteCursor.getCount() + " records for note " + mNoteId);
    mNoteType = noteCursor.getInt(noteCursor.getColumnIndexOrThrow(DatabaseAdapter.TYPE_COL));
    // set title in the proper view
    TextView titleView = (TextView) this.findViewById(R.id.show_note_title);
    titleView.setText(
        noteCursor.getString(noteCursor.getColumnIndexOrThrow(DatabaseAdapter.TITLE_COL)));

    switch (mNoteType) {
      case Const.TYPE_TEXT:
        this.startManagingCursor(noteCursor); // the cursor will not be changed
        TextView bodyView = (TextView) this.findViewById(R.id.show_note_body);
        // enable scrolling
        bodyView.setMovementMethod(new ScrollingMovementMethod());
        bodyView.setText(noteCursor.getString(noteCursor.getColumnIndex(DatabaseAdapter.TEXT_COL)));
        return;
      case Const.TYPE_CHECKLIST:
        Cursor listCursor = mAdapter.getFullNoteOrNoneById(mNoteId);
        this.startManagingCursor(listCursor); // all changes to the cursor is over
        // use empty cursor if there is only title. Create a new list adapter upon creating the
        // activity and each subsequent resume
        this.setListAdapter(
            new HoloNoteCursorAdapter(
                this,
                R.layout.view_checklist_row,
                listCursor,
                new String[] {DatabaseAdapter.TEXT_COL},
                new int[] {R.id.show_checklist_item}));
        return;
      default:
        Log.w(LOG_TAG, "Display note got an unkonwn type: " + mNoteType);
        break;
    }
  }
コード例 #4
0
 public void onPositiveClick(Bundle args) {
   int dialogType = args.getInt(Const.DIALOG_TYPE);
   Log.i(LOG_TAG, "Received positive click callback from dialog. Dialog type was " + dialogType);
   switch (dialogType) {
     case Const.DELETE_NOTE:
       mAdapter.deleteNote(mNoteId);
       this.goUp();
       break;
     case Const.DELETE_CHECKED:
       mAdapter.deleteAllChecked(mNoteId);
       this.displayNoteOrGoUp();
       break;
     case Const.UNCHECK_ALL:
       mAdapter.uncheckAll(mNoteId);
       // Not sure which is faster, reload the list or loop through and asynchronously uncheck all
       this.displayNoteOrGoUp();
       break;
     default:
       Log.w(LOG_TAG, "Unknown dialog type returned positive click");
       break;
   }
 }
コード例 #5
0
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
   super.onListItemClick(l, v, position, id);
   Log.i(LOG_TAG, id + " is clicked at position " + position);
   if (v instanceof CheckedTextView) {
     // doing asynchronous view changes, because the cursor still has old data while the database
     // and the view are changed
     // because we force refresh on every resume, the synchronization after we leave the Activity
     // is taken care of
     CheckedTextView ctv = (CheckedTextView) v;
     // this check view at the certain position, rather than the item, hence the asynchrony
     ctv.setChecked(!ctv.isChecked());
     mAdapter.flipCheckedStatus(id, mNoteId, ctv.isChecked());
     ctv.setPaintFlags(
         ctv.isChecked()
             ? ctv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG
             : ctv.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
     ((HoloNoteCursorAdapter) this.getListAdapter()).getCursor().requery();
   }
 }