List of usage examples for android.view ContextMenu findItem
public MenuItem findItem(int id);
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); //? ? -/*from w w w .j a v a2s .c om*/ if (v.getTag() != null && v.getTag() instanceof AttachmentModel) { lastContextMenuAttachment = v; AttachmentModel model = (AttachmentModel) v.getTag(); View tnView = v.findViewById(R.id.post_thumbnail_image); if (tnView != null && tnView.getTag() == Boolean.FALSE && !downloadThumbnails()) { menu.add(Menu.NONE, R.id.context_menu_thumb_load_thumb, 1, R.string.context_menu_show_thumbnail) .setOnMenuItemClickListener(contextMenuListener); } menu.add(Menu.NONE, R.id.context_menu_thumb_download, 2, R.string.context_menu_download_file); menu.add(Menu.NONE, R.id.context_menu_thumb_copy_url, 3, R.string.context_menu_copy_url); menu.add(Menu.NONE, R.id.context_menu_thumb_attachment_info, 4, R.string.context_menu_attachment_info); menu.add(Menu.NONE, R.id.context_menu_thumb_reverse_search, 5, R.string.context_menu_reverse_search); for (int id : new int[] { R.id.context_menu_thumb_download, R.id.context_menu_thumb_copy_url, R.id.context_menu_thumb_attachment_info, R.id.context_menu_thumb_reverse_search }) { menu.findItem(id).setOnMenuItemClickListener(contextMenuListener); } switch (model.type) { case AttachmentModel.TYPE_AUDIO: case AttachmentModel.TYPE_VIDEO: case AttachmentModel.TYPE_OTHER_FILE: menu.findItem(R.id.context_menu_thumb_reverse_search).setVisible(false); break; case AttachmentModel.TYPE_OTHER_NOTFILE: menu.findItem(R.id.context_menu_thumb_reverse_search).setVisible(false); menu.findItem(R.id.context_menu_thumb_download).setVisible(false); break; } if (tabModel.type == TabModel.TYPE_LOCAL) { menu.findItem(R.id.context_menu_thumb_download).setVisible(false); } return; } if (menu.findItem(R.id.context_menu_thumb_copy_url) != null) return; //? ? ? boolean isList = true; lastContextMenuPosition = -1; final PresentationItemModel model; if (v.getId() == android.R.id.list) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; model = adapter.getItem(info.position); if (model.hidden) { return; } } else { if (v.getTag() != null && v.getTag() instanceof PostsListAdapter.PostViewTag) { PostsListAdapter.PostViewTag tag = (PostsListAdapter.PostViewTag) v.getTag(); if (!tag.isPopupDialog) return; isList = false; lastContextMenuPosition = tag.position; model = adapter.getItem(lastContextMenuPosition); } else { return; } } if (pageType == TYPE_POSTSLIST) { menu.add(Menu.NONE, R.id.context_menu_reply, 1, R.string.context_menu_reply); menu.add(Menu.NONE, R.id.context_menu_reply_with_quote, 2, R.string.context_menu_reply_with_quote); menu.add(Menu.NONE, R.id.context_menu_select_text, 3, Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && isList ? R.string.context_menu_select_text : R.string.context_menu_copy_text); menu.add(Menu.NONE, R.id.context_menu_share, 4, R.string.context_menu_share); menu.add(Menu.NONE, R.id.context_menu_hide, 5, R.string.context_menu_hide_post); menu.add(Menu.NONE, R.id.context_menu_delete, 6, R.string.context_menu_delete); menu.add(Menu.NONE, R.id.context_menu_report, 7, R.string.context_menu_report); menu.add(Menu.NONE, R.id.context_menu_subscribe, 8, R.string.context_menu_subscribe); if (!isList) { for (int id : new int[] { R.id.context_menu_reply, R.id.context_menu_reply_with_quote, R.id.context_menu_select_text, R.id.context_menu_share, R.id.context_menu_hide, R.id.context_menu_delete, R.id.context_menu_report, R.id.context_menu_subscribe }) { menu.findItem(id).setOnMenuItemClickListener(contextMenuListener); } } if (presentationModel.source.boardModel.readonlyBoard || tabModel.type == TabModel.TYPE_LOCAL) { menu.findItem(R.id.context_menu_reply).setVisible(false); menu.findItem(R.id.context_menu_reply_with_quote).setVisible(false); } if (model.isDeleted || (!presentationModel.source.boardModel.allowDeletePosts && (!presentationModel.source.boardModel.allowDeleteFiles || model.sourceModel.attachments == null || model.sourceModel.attachments.length == 0)) || tabModel.type == TabModel.TYPE_LOCAL) { menu.findItem(R.id.context_menu_delete).setVisible(false); } if (model.isDeleted || presentationModel.source.boardModel.allowReport == BoardModel.REPORT_NOT_ALLOWED || tabModel.type == TabModel.TYPE_LOCAL) { menu.findItem(R.id.context_menu_report).setVisible(false); } if (settings.isSubscriptionsEnabled()) { if (subscriptions.hasSubscription(chan.getChanName(), presentationModel.source.boardModel.boardName, presentationModel.source.pageModel.threadNumber, model.sourceModel.number)) { menu.findItem(R.id.context_menu_subscribe).setTitle(R.string.context_menu_unsubscribe); } } else { menu.findItem(R.id.context_menu_subscribe).setVisible(false); } } else if (pageType == TYPE_THREADSLIST && isList) { menu.add(Menu.NONE, R.id.context_menu_open_in_new_tab, 1, R.string.context_menu_open_in_new_tab); menu.add(Menu.NONE, R.id.context_menu_thread_preview, 2, R.string.context_menu_thread_preview); menu.add(Menu.NONE, R.id.context_menu_reply_no_reading, 3, R.string.context_menu_reply_no_reading); menu.add(Menu.NONE, R.id.context_menu_hide, 4, R.string.context_menu_hide_thread); if (presentationModel.source.boardModel.readonlyBoard || tabModel.type == TabModel.TYPE_LOCAL) { menu.findItem(R.id.context_menu_reply_no_reading).setVisible(false); } } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void editDontWantToSee() { if (!SettingConstants.UPDATING_FILTER) { Set<String> currentExclusions = PrefUtils.getStringSetValue(R.string.I_DONT_WANT_TO_SEE_ENTRIES, null); final ArrayList<ExclusionEdit> mCurrentExclusionList = new ArrayList<TvBrowser.ExclusionEdit>(); if (currentExclusions != null && !currentExclusions.isEmpty()) { for (String exclusion : currentExclusions) { mCurrentExclusionList.add(new ExclusionEdit(exclusion)); }/*from w w w . j av a 2 s . c o m*/ } Collections.sort(mCurrentExclusionList); final ArrayAdapter<ExclusionEdit> exclusionAdapter = new ArrayAdapter<TvBrowser.ExclusionEdit>( TvBrowser.this, android.R.layout.simple_list_item_1, mCurrentExclusionList); View view = getLayoutInflater().inflate(R.layout.dont_want_to_see_exclusion_edit_list, getParentViewGroup(), false); ListView list = (ListView) view.findViewById(R.id.dont_want_to_see_exclusion_list); list.setAdapter(exclusionAdapter); final Runnable cancel = new Runnable() { @Override public void run() { } }; AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final ExclusionEdit edit = exclusionAdapter.getItem(position); View editView = getLayoutInflater().inflate(R.layout.dont_want_to_see_edit, getParentViewGroup(), false); final TextView exclusion = (TextView) editView.findViewById(R.id.dont_want_to_see_value); final CheckBox caseSensitive = (CheckBox) editView .findViewById(R.id.dont_want_to_see_case_sensitve); exclusion.setText(edit.mExclusion); caseSensitive.setSelected(edit.mIsCaseSensitive); Runnable editPositive = new Runnable() { @Override public void run() { if (exclusion.getText().toString().trim().length() > 0) { edit.mExclusion = exclusion.getText().toString(); edit.mIsCaseSensitive = caseSensitive.isSelected(); exclusionAdapter.notifyDataSetChanged(); } } }; showAlertDialog(getString(R.string.action_dont_want_to_see), null, editView, null, editPositive, null, cancel, false, false); } }; list.setOnItemClickListener(onClickListener); list.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { getMenuInflater().inflate(R.menu.don_want_to_see_context, menu); MenuItem item = menu.findItem(R.id.dont_want_to_see_delete); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { ExclusionEdit edit = exclusionAdapter .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); exclusionAdapter.remove(edit); exclusionAdapter.notifyDataSetChanged(); return true; } }); } }); Thread positive = new Thread() { @Override public void run() { SettingConstants.UPDATING_FILTER = true; final NotificationCompat.Builder builder = new NotificationCompat.Builder(TvBrowser.this); builder.setSmallIcon(R.drawable.ic_stat_notify); builder.setOngoing(true); builder.setContentTitle(getResources().getText(R.string.action_dont_want_to_see)); builder.setContentText( getResources().getText(R.string.dont_want_to_see_refresh_notification_text)); final int notifyID = 2; final NotificationManager notification = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notification.notify(notifyID, builder.build()); updateProgressIcon(true); HashSet<String> newExclusions = new HashSet<String>(); final ArrayList<DontWantToSeeExclusion> exclusionList = new ArrayList<DontWantToSeeExclusion>(); for (ExclusionEdit edit : mCurrentExclusionList) { String exclusion = edit.getExclusion(); newExclusions.add(exclusion); exclusionList.add(new DontWantToSeeExclusion(exclusion)); } new Thread() { public void run() { Cursor programs = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_DATA, new String[] { TvBrowserContentProvider.KEY_ID, TvBrowserContentProvider.DATA_KEY_TITLE }, null, null, TvBrowserContentProvider.KEY_ID); programs.moveToPosition(-1); builder.setProgress(programs.getCount(), 0, true); notification.notify(notifyID, builder.build()); ArrayList<ContentProviderOperation> updateValuesList = new ArrayList<ContentProviderOperation>(); int keyColumn = programs.getColumnIndex(TvBrowserContentProvider.KEY_ID); int titleColumn = programs.getColumnIndex(TvBrowserContentProvider.DATA_KEY_TITLE); DontWantToSeeExclusion[] exclusionArr = exclusionList .toArray(new DontWantToSeeExclusion[exclusionList.size()]); while (programs.moveToNext()) { builder.setProgress(programs.getCount(), programs.getPosition(), false); notification.notify(notifyID, builder.build()); String title = programs.getString(titleColumn); boolean filter = UiUtils.filter(getApplicationContext(), title, exclusionArr); long progID = programs.getLong(keyColumn); ContentValues values = new ContentValues(); values.put(TvBrowserContentProvider.DATA_KEY_DONT_WANT_TO_SEE, filter ? 1 : 0); ContentProviderOperation.Builder opBuilder = ContentProviderOperation.newUpdate( ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_DATA_UPDATE, progID)); opBuilder.withValues(values); updateValuesList.add(opBuilder.build()); } notification.cancel(notifyID); programs.close(); if (!updateValuesList.isEmpty()) { try { getContentResolver().applyBatch(TvBrowserContentProvider.AUTHORITY, updateValuesList); UiUtils.sendDontWantToSeeChangedBroadcast(getApplicationContext(), true); handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.dont_want_to_see_sync_success, Toast.LENGTH_LONG) .show(); } }); } catch (RemoteException e) { e.printStackTrace(); } catch (OperationApplicationException e) { e.printStackTrace(); } } updateProgressIcon(false); SettingConstants.UPDATING_FILTER = false; } }.start(); Editor edit = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit(); edit.putStringSet(getString(R.string.I_DONT_WANT_TO_SEE_ENTRIES), newExclusions); edit.commit(); } }; showAlertDialog(getString(R.string.action_dont_want_to_see_edit), null, view, null, positive, null, cancel, false, true); } }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; if (v == getListView()) { if (info.position > mAdapter_Accounts.getCount() + 5) { getMenuInflater().inflate(R.menu.folder_context, menu); FolderInfoHolder folder = (FolderInfoHolder) mAdapter .getItem(info.position - (mAdapter_Accounts.getCount() + 6)); menu.setHeaderTitle(folder.displayName); } else if (info.position < mAdapter_Accounts.getCount()) { menu.setHeaderTitle(R.string.accounts_context_menu_title); if (mAdapter_Accounts == null) { Log.d("info =", "mAdapter_Accounts = null"); }/*from w ww . j a v a 2 s . c o m*/ BaseAccount account = (BaseAccount) mergeadapter.getItem(info.position); if ((account instanceof Account) && !((Account) account).isEnabled()) { getMenuInflater().inflate(R.menu.disabled_accounts_context, menu); } else { getMenuInflater().inflate(R.menu.accounts_context, menu); } if (account instanceof SearchAccount) { for (int i = 0; i < menu.size(); i++) { android.view.MenuItem item = menu.getItem(i); item.setVisible(false); } } else { EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account); if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) { menu.findItem(R.id.move_up).setEnabled(false); } else { menu.findItem(R.id.move_up).setEnabled(true); } if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) { menu.findItem(R.id.move_down).setEnabled(false); } else { menu.findItem(R.id.move_down).setEnabled(true); } } } } }
From source file:com.nttec.everychan.ui.NewTabFragment.java
private void openChansList() { final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) { private LayoutInflater inflater = LayoutInflater.from(activity); private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); {//from ww w . j a va 2s . c o m for (ChanModule chan : MainApplication.getInstance().chanModulesList) add(chan); } @Override public View getView(int position, View convertView, ViewGroup parent) { ChanModule chan = getItem(position); TextView view = (TextView) (convertView == null ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false) : convertView); view.setText(chan.getDisplayingName()); view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null); view.setCompoundDrawablePadding(drawablePadding); return view; } }; DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ChanModule chan = chansAdapter.getItem(which); UrlPageModel model = new UrlPageModel(); model.chanName = chan.getChanName(); model.type = UrlPageModel.TYPE_INDEXPAGE; openNewTab(chan.buildUrl(model)); } }; final AlertDialog chansListDialog = new AlertDialog.Builder(activity) .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected) .setNegativeButton(android.R.string.cancel, null).create(); chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() { @SuppressLint("InlinedApi") @Override public boolean onMenuItemClick(MenuItem item) { final ChanModule chan = chansAdapter .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); switch (item.getItemId()) { case R.id.context_menu_favorites_from_fragment: if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null, null)) { MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null, null, null); } else { try { UrlPageModel indexPage = new UrlPageModel(); indexPage.chanName = chan.getChanName(); indexPage.type = UrlPageModel.TYPE_INDEXPAGE; MainApplication.getInstance().database.addFavorite(chan.getChanName(), null, null, null, chan.getChanName(), chan.buildUrl(indexPage)); } catch (Exception e) { Logger.e(TAG, e); } } return true; case R.id.context_menu_quickaccess_add: QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); return true; case R.id.context_menu_quickaccess_custom_board: LinearLayout dialogLayout = new LinearLayout(activity); dialogLayout.setOrientation(LinearLayout.VERTICAL); final EditText boardField = new EditText(activity); final EditText descriptionField = new EditText(activity); boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode); descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc); LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); dialogLayout.addView(boardField, fieldsParams); dialogLayout.addView(descriptionField, fieldsParams); DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String boardName = boardField.getText().toString(); for (QuickAccess.Entry entry : list) if (entry.boardName != null && entry.chan != null) if (entry.chan.getChanName().equals(chan.getChanName()) && entry.boardName.equals(boardName)) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_already_exists, Toast.LENGTH_LONG).show(); return; } try { if (boardName.trim().length() == 0) throw new Exception(); UrlPageModel boardPageModel = new UrlPageModel(); boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE; boardPageModel.chanName = chan.getChanName(); boardPageModel.boardName = boardName; boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE; chan.buildUrl(boardPageModel); //, ?? ? } catch (Exception e) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_incorrect_code, Toast.LENGTH_LONG).show(); return; } QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; newEntry.boardName = boardName; newEntry.boardDescription = descriptionField.getText().toString(); list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); } }; new AlertDialog.Builder(activity) .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title, chan.getChanName())) .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked) .setNegativeButton(android.R.string.cancel, null).show(); return true; } return false; } }; String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position) .getChanName(); boolean canAddToQuickAccess = true; for (QuickAccess.Entry entry : list) if (entry.boardName == null && entry.chan != null && entry.chan.getChanName().equals(thisChanName)) { canAddToQuickAccess = false; break; } menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1, MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null) ? R.string.context_menu_remove_favorites : R.string.context_menu_add_favorites) .setOnMenuItemClickListener(contextMenuHandler); menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add) .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess); menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3, R.string.context_menu_quickaccess_custom_board) .setOnMenuItemClickListener(contextMenuHandler); if (isSingleboardChan( chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position))) menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false); } }); chansListDialog.show(); }