@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); long id = ((AdapterContextMenuInfo) menuInfo).id; if (id != -1) { BookmarkItem item = BookmarksProviderWrapper.getStockBookmarkById(getContentResolver(), id); if (item != null) { menu.setHeaderTitle(item.getTitle()); } } menu.add(0, MENU_OPEN_IN_TAB, 0, R.string.BookmarksListActivity_MenuOpenInTab); menu.add(0, MENU_COPY_URL, 0, R.string.BookmarksHistoryActivity_MenuCopyLinkUrl); menu.add(0, MENU_SHARE, 0, R.string.Main_MenuShareLinkUrl); menu.add(0, MENU_EDIT_BOOKMARK, 0, R.string.BookmarksListActivity_MenuEditBookmark); menu.add(0, MENU_DELETE_BOOKMARK, 0, R.string.BookmarksListActivity_MenuDeleteBookmark); }
/** Fill the bookmark to the list UI. */ private void fillData() { mCursor = BookmarksProviderWrapper.getStockBookmarks( getContentResolver(), PreferenceManager.getDefaultSharedPreferences(this) .getInt(Constants.PREFERENCES_BOOKMARKS_SORT_MODE, 0)); startManagingCursor(mCursor); String[] from = new String[] {Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL}; int[] to = new int[] {R.id.BookmarkRow_Title, R.id.BookmarkRow_Url}; mCursorAdapter = new BookmarksCursorAdapter( this, R.layout.bookmark_row, mCursor, from, to, ApplicationUtils.getFaviconSizeForBookmarks(this)); mList.setAdapter(mCursorAdapter); setAnimation(); }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Intent i; BookmarkItem bookmarkItem = BookmarksProviderWrapper.getStockBookmarkById(getContentResolver(), info.id); switch (item.getItemId()) { case MENU_OPEN_IN_TAB: i = new Intent(); i.putExtra(Constants.EXTRA_ID_NEW_TAB, true); if (bookmarkItem != null) { i.putExtra(Constants.EXTRA_ID_URL, bookmarkItem.getUrl()); } else { i.putExtra( Constants.EXTRA_ID_URL, PreferenceManager.getDefaultSharedPreferences(BookmarksListActivity.this) .getString(Constants.PREFERENCES_GENERAL_HOME_PAGE, Constants.URL_ABOUT_START)); } if (getParent() != null) { getParent().setResult(RESULT_OK, i); } else { setResult(RESULT_OK, i); } finish(); return true; case MENU_EDIT_BOOKMARK: if (bookmarkItem != null) { i = new Intent(this, EditBookmarkActivity.class); i.putExtra(Constants.EXTRA_ID_BOOKMARK_ID, info.id); i.putExtra(Constants.EXTRA_ID_BOOKMARK_TITLE, bookmarkItem.getTitle()); i.putExtra(Constants.EXTRA_ID_BOOKMARK_URL, bookmarkItem.getUrl()); startActivityForResult(i, ACTIVITY_EDIT_BOOKMARK); } return true; case MENU_COPY_URL: if (bookmarkItem != null) { ApplicationUtils.copyTextToClipboard( this, bookmarkItem.getUrl(), getString(R.string.Commons_UrlCopyToastMessage)); } return true; case MENU_SHARE: if (bookmarkItem != null) { ApplicationUtils.sharePage(this, bookmarkItem.getTitle(), bookmarkItem.getUrl()); } return true; case MENU_DELETE_BOOKMARK: // mDbAdapter.deleteBookmark(info.id); BookmarksProviderWrapper.deleteStockBookmark(getContentResolver(), info.id); fillData(); return true; default: return super.onContextItemSelected(item); } }