コード例 #1
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   final int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
   final ListView view = (ListView) getTabHost().getCurrentView();
   final Bookmark bookmark = ((BookmarksAdapter) view.getAdapter()).getItem(position);
   switch (item.getItemId()) {
     case OPEN_ITEM_ID:
       gotoBookmark(bookmark);
       return true;
     case EDIT_ITEM_ID:
       final Intent intent = new Intent(this, BookmarkEditActivity.class);
       OrientationUtil.startActivityForResult(this, intent, 1);
       // TODO: implement
       return true;
     case DELETE_ITEM_ID:
       myCollection.deleteBookmark(bookmark);
       if (myThisBookAdapter != null) {
         myThisBookAdapter.remove(bookmark);
       }
       if (myAllBooksAdapter != null) {
         myAllBooksAdapter.remove(bookmark);
       }
       if (mySearchResultsAdapter != null) {
         mySearchResultsAdapter.remove(bookmark);
       }
       return true;
   }
   return super.onContextItemSelected(item);
 }
コード例 #2
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case CONTEXT_DELETE_TAG:
       AdapterView.AdapterContextMenuInfo menuInfo =
           (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
       db.deleteTag(menuInfo.id);
       ListView lv = (ListView) viewTagList.findViewById(R.id.item_list);
       Cursor listItem = (Cursor) lv.getItemAtPosition(menuInfo.position);
       String tagName = listItem.getString(1);
       ((TagViewListAdaptor) lv.getAdapter()).refreshData();
       Toast.makeText(SBActivity.this, "Tag '" + tagName + "' deleted.", Toast.LENGTH_SHORT)
           .show();
       return true;
     case CONTEXT_VIEW_NOTES:
       AdapterView.AdapterContextMenuInfo menuInfo2 =
           (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
       Gallery g = (Gallery) viewNoteGallery.findViewById(R.id.note_gallery);
       g.setAdapter(new NoteGalleryImageAdaptor(SBActivity.this, db.findNotesByTag(menuInfo2.id)));
       setContentView(viewNoteGallery);
     default:
       return super.onContextItemSelected(item);
   }
 }
コード例 #3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.menu_view_tags:
        // little hack to refresh the data in our tag list view when we open it
        ListView lv = (ListView) viewTagList.findViewById(R.id.item_list);
        ((TagViewListAdaptor) lv.getAdapter()).refreshData();
        setContentView(viewTagList);
        return true;
      case R.id.menu_delete_note:
        Note n = ((NoteView) viewNote).getNote();
        db.deleteTag(n.getId());
        Toast.makeText(SBActivity.this, "Note " + n.getId() + " deleted.", Toast.LENGTH_SHORT)
            .show();
        goBack();
        return true;
      case R.id.menu_save_note:
        setContentView(viewCaptureNote);
        return true;
      case R.id.menu_tag_note:
        final Note curNote = ((NoteView) viewNote).getNote();
        final Cursor c = db.getTagListForImg(curNote.getId());
        CharSequence[] items = new CharSequence[c.getCount()];
        for (int i = 0; i < items.length; i++) {
          c.moveToNext();
          items[i] = c.getString(1);
        }

        final boolean[] checked = new boolean[c.getCount()];
        c.moveToFirst();
        for (int i = 0; i < items.length; i++) {
          checked[i] = c.getInt(2) == 1;
          c.moveToNext();
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder
            .setTitle("Set tags for note " + curNote.getId())
            .setIcon(android.R.drawable.ic_menu_edit)
            .setMultiChoiceItems(
                items,
                checked,
                new DialogInterface.OnMultiChoiceClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                    c.moveToPosition(i);
                    db.setTagForNote(curNote.getId(), c.getLong(0), b);
                  }
                });
        builder.show();
        return true;
      case R.id.menu_bluetooth_sync:
        Cursor c1 = getDbAdaptor().getUpdateList(null);
        int idxId = c1.getColumnIndex("_id");
        int idxTable = c1.getColumnIndex("table_name");
        int idxTarget = c1.getColumnIndex("target_id");
        int idxTarget2 = c1.getColumnIndex("target2_id");
        int idxType = c1.getColumnIndex("update_type");
        int idxTime = c1.getColumnIndex("update_time");
        Log.i(getClass().getName(), "Update list:");
        while (c1.moveToNext()) {
          Log.i(
              getClass().getName(),
              " [_id="
                  + c1.getInt(idxId)
                  + "] "
                  + (c1.getInt(idxType) == DbAdaptor.UPDATE_TYPE_ADD ? "Added" : "Deleted")
                  + " "
                  + "id "
                  + c1.getInt(idxTarget)
                  + (!c1.isNull(idxTarget2) ? " (id2 " + c1.getInt(idxTarget2) + ")" : "")
                  + " in table "
                  + c1.getString(idxTable)
                  + " (@ "
                  + new Date(c1.getInt(idxTime))
                  + ")");
        }

        if (bService.requestEnableBluetooth()) bService.bluetoothDiscoverable();
        return true;
    }
    return false;
  }