List of usage examples for android.view MenuItem getMenuInfo
public ContextMenuInfo getMenuInfo();
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.FavouriteStopsFragment.java
/** * {@inheritDoc}/*from www. ja v a 2s. c o m*/ */ @Override public boolean onContextItemSelected(final MenuItem item) { // Get the info so we can get the stopCode. final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); final Cursor c = (Cursor) ca.getItem(info.position); final String selectedStopCode; if (c != null) { selectedStopCode = c.getString(0); } else { selectedStopCode = ""; } switch (item.getItemId()) { case R.id.favouritestops_context_menu_modify: // Allow the user to edit the name of the favourite stop. callbacks.onShowEditFavouriteStop(selectedStopCode); return true; case R.id.favouritestops_context_menu_delete: callbacks.onShowConfirmFavouriteDeletion(selectedStopCode); return true; case R.id.favouritestops_context_menu_showonmap: // Show the selected bus stop on the map. callbacks.onShowBusStopMapWithStopCode(selectedStopCode); return true; case R.id.favouritestops_context_menu_prox_alert: // Either show the Activity which allows the user to add a // proximity alert, or the DialogFragment to confirm the alert's // removal. if (sd.isActiveProximityAlert(selectedStopCode)) { callbacks.onShowConfirmDeleteProximityAlert(); } else { callbacks.onShowAddProximityAlert(selectedStopCode); } return true; case R.id.favouritestops_context_menu_time_alert: // Either show the Activity which allows the user to add a time // alert, or the DialogFragment to confirm the alert's removal. if (sd.isActiveTimeAlert(selectedStopCode)) { callbacks.onShowConfirmDeleteTimeAlert(); } else { callbacks.onShowAddTimeAlert(selectedStopCode); } return true; default: return super.onContextItemSelected(item); } }
From source file:org.mozilla.gecko.home.HomeFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { // onContextItemSelected() is first dispatched to the activity and // then dispatched to its fragments. Since fragments cannot "override" // menu item selection handling, it's better to avoid menu id collisions // between the activity and its fragments. ContextMenuInfo menuInfo = item.getMenuInfo(); if (!(menuInfo instanceof HomeContextMenuInfo)) { return false; }//from w w w. ja v a2s . co m final HomeContextMenuInfo info = (HomeContextMenuInfo) menuInfo; final Context context = getActivity(); final int itemId = item.getItemId(); // Track the menu action. We don't know much about the context, but we can use this to determine // the frequency of use for various actions. Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.CONTEXT_MENU, getResources().getResourceEntryName(itemId)); if (itemId == R.id.home_copyurl) { if (info.url == null) { Log.e(LOGTAG, "Can't copy address because URL is null"); return false; } Clipboard.setText(info.url); return true; } if (itemId == R.id.home_share) { if (info.url == null) { Log.e(LOGTAG, "Can't share because URL is null"); return false; } else { GeckoAppShell.openUriExternal(info.url, SHARE_MIME_TYPE, "", "", Intent.ACTION_SEND, info.getDisplayTitle()); // Context: Sharing via chrome homepage contextmenu list (home session should be active) Telemetry.sendUIEvent(TelemetryContract.Event.SHARE, TelemetryContract.Method.LIST); return true; } } if (itemId == R.id.home_add_to_launcher) { if (info.url == null) { Log.e(LOGTAG, "Can't add to home screen because URL is null"); return false; } // Fetch an icon big enough for use as a home screen icon. Favicons.getPreferredSizeFaviconForPage(context, info.url, new GeckoAppShell.CreateShortcutFaviconLoadedListener(info.url, info.getDisplayTitle())); return true; } if (itemId == R.id.home_open_private_tab || itemId == R.id.home_open_new_tab) { if (info.url == null) { Log.e(LOGTAG, "Can't open in new tab because URL is null"); return false; } // Some pinned site items have "user-entered" urls. URLs entered in // the PinSiteDialog are wrapped in a special URI until we can get a // valid URL. If the url is a user-entered url, decode the URL // before loading it. final String url = StringUtils.decodeUserEnteredUrl( info.isInReadingList() ? ReaderModeUtils.getAboutReaderForUrl(info.url) : info.url); final EnumSet<OnUrlOpenInBackgroundListener.Flags> flags = EnumSet .noneOf(OnUrlOpenInBackgroundListener.Flags.class); if (item.getItemId() == R.id.home_open_private_tab) { flags.add(OnUrlOpenInBackgroundListener.Flags.PRIVATE); } mUrlOpenInBackgroundListener.onUrlOpenInBackground(url, flags); Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.CONTEXT_MENU); return true; } if (itemId == R.id.home_edit_bookmark) { // UI Dialog associates to the activity context, not the applications'. new EditBookmarkDialog(context).show(info.url); return true; } if (itemId == R.id.home_remove) { // For Top Sites grid items, position is required in case item is Pinned. final int position = info instanceof TopSitesGridContextMenuInfo ? info.position : -1; (new RemoveItemByUrlTask(context, info.url, info.itemType, position)).execute(); return true; } return false; }
From source file:com.plined.liftlog.WorkoutBeginFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.f_workout_begin_menu_editRoutine: { /*/*from ww w .ja v a 2s . c o m*/ * They want to edit this routine. Launch it into the routine manager. */ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int position = info.position; //Figure out whjich routine we're trying to edit. RoutineCursorAdapter adapter = (RoutineCursorAdapter) getListAdapter(); RoutineCursor rotCursor = (RoutineCursor) adapter.getItem(position); Routine rotEdit = rotCursor.getRoutine(); //Launch into the routine manager with its ID Intent i = new Intent(getActivity(), RoutineFactoryActivity.class); //Putthe routine id in i.putExtra(RoutineFactoryActivity.EXTRA_ROUTINE_ID, rotEdit.getId()); //Start the routine factory. startActivity(i); return true; } default: return super.onContextItemSelected(item); } }
From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java
@Override public boolean onContextItemSelected(MenuItem item) { boolean handled = false; AdapterView.AdapterContextMenuInfo info; try {/* w w w. j a v a 2s . c o m*/ info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(this, "Bad menuInfo", e); return handled; } Object listItem = getListAdapter().getItem(info.position); if (listItem instanceof Cursor) { Cursor cursor = (Cursor) listItem; mDialogTrackUri = ContentUris.withAppendedId(Tracks.CONTENT_URI, cursor.getLong(0)); mDialogCurrentName = cursor.getString(1); mDialogCurrentName = mDialogCurrentName != null ? mDialogCurrentName : ""; switch (item.getItemId()) { case MENU_DELETE: { showDialog(DIALOG_DELETE); handled = true; break; } case MENU_SHARE: { Intent actionIntent = new Intent(Intent.ACTION_RUN); actionIntent.setDataAndType(mDialogTrackUri, Tracks.CONTENT_ITEM_TYPE); actionIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(actionIntent, getString(R.string.share_track))); handled = true; break; } case MENU_RENAME: { showDialog(DIALOG_RENAME); handled = true; break; } case MENU_STATS: { Intent actionIntent = new Intent(this, Statistics.class); actionIntent.setData(mDialogTrackUri); startActivity(actionIntent); handled = true; break; } default: handled = super.onContextItemSelected(item); break; } } return handled; }
From source file:org.videolan.vlc.gui.audio.AudioPlayer.java
@Override public boolean onContextItemSelected(MenuItem item) { if (getUserVisibleHint() && item.getMenuInfo() instanceof AdapterContextMenuInfo) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); if (info == null) // info can be null return super.onContextItemSelected(item); int id = item.getItemId(); if (id == R.id.audio_player_mini_remove) { Log.d(TAG, "Context menu removing " + info.position); if (mClient.isConnected()) mClient.remove(info.position); return true; }//from w ww .j a va2 s.c om return super.onContextItemSelected(item); } else return false; }
From source file:com.lgallardo.qbittorrentclient.RSSFeedActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // Log.d("Debug", "Item: " + getResources().getResourceEntryName(item.getItemId())); ArrayList<RSSFeed> rssChannels = myadapter.getRssChannels(); switch (item.getItemId()) { case R.id.action_edit: // Log.d("Debug", "Edit!"); editRssFeed(info.position, rssChannels.get(info.position)); return true; case R.id.action_delete: // Log.d("Debug", "Delete!"); rssChannels.remove(info.position); myadapter.setRssChannels(rssChannels); myadapter.notifyDataSetChanged(); // Save all; rss_feeds = ""; for (int i = 0; i < rssChannels.size(); i++) { RSSFeed rssFeed = rssChannels.get(i); saveRssFeed(rssFeed.getChannelTitle(), rssFeed.getChannelLink(), rssFeed.getChannelFilter(), rssFeed.getChannelPubDate(), rssFeed.getAutodDownload(), rssFeed.getNotifyNew()); }/*from w ww .j a va2 s.c o m*/ return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.pdftron.pdf.controls.AnnotationDialogFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int menuItemIndex = item.getItemId(); switch (menuItemIndex) { case CONTEXT_MENU_DELETE_ITEM: AnnotationInfo annotationInfo = mAnnotationListAdapter.getItem(info.position); if (annotationInfo.getAnnotation() != null) { try { // Locks the document first as accessing annotation/doc information isn't thread // safe. mPDFViewCtrl.docLock(true); Page page = mPDFViewCtrl.getDoc().getPage(annotationInfo.getPageNum()); page.annotRemove(annotationInfo.getAnnotation()); mPDFViewCtrl.update(annotationInfo.getAnnotation(), annotationInfo.getPageNum()); mAnnotationListAdapter.remove(mAnnotationListAdapter.getItem(info.position)); mAnnotationListAdapter.notifyDataSetChanged(); } catch (Exception e) { } finally { mPDFViewCtrl.docUnlock(); }//from w ww. j a v a 2 s. c o m } com.pdftron.pdf.utils.AnalyticsHandlerAdapter.getInstance() .sendEvent(AnalyticsHandlerAdapter.CATEGORY_ANNOTATIONTOOLBAR, "Annotation Delete Clicked"); break; case CONTEXT_MENU_DELETE_ITEM_ONPAGE: if (mDebug) { annotationInfo = mAnnotationListAdapter.getItem(info.position); if (annotationInfo.getAnnotation() != null) { deleteOnPage(annotationInfo); } } break; case CONTEXT_MENU_DELETE_ALL: if (mDebug) { deleteAll(); } break; } return super.onContextItemSelected(item); }
From source file:com.chess.genesis.activity.GameListOnlineFrag.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (!act.lastContextMenu.equals(getBTag())) return super.onContextItemSelected(item); switch (item.getItemId()) { case R.id.new_game: case R.id.resync: case R.id.readall_msgs: return onOptionsItemSelected(item); }/* w w w. j a v a2s.co m*/ final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); final GameListAdapter listAdapter = gamelistadapter_arr[pager.getCurrentItem()]; final Bundle bundle = (Bundle) listAdapter.getItem((int) info.id); switch (item.getItemId()) { case R.id.delete_game: new DeleteArchiveDialog(act, handle, bundle.getString("gameid")).show(); break; case R.id.local_copy: final int type = (pager.getCurrentItem() == ARCHIVE_PAGE) ? Enums.ARCHIVE_GAME : Enums.ONLINE_GAME; new CopyGameConfirm(act, bundle.getString("gameid"), type).show(); break; case R.id.rematch: final String username = listAdapter.getExtras().getString("username"); final String opponent = username.equals(bundle.getString("white")) ? bundle.getString("black") : bundle.getString("white"); new RematchConfirm(act, handle, opponent).show(); break; case R.id.nudge: new NudgeConfirm(act, handle, bundle.getString("gameid")).show(); break; case R.id.share_game: sendGame(bundle); break; default: return super.onContextItemSelected(item); } return true; }
From source file:org.bombusim.lime.fragments.RosterFragment.java
public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo cmi = (AdapterContextMenuInfo) item.getMenuInfo(); //contextItem = getListAdapter().getItem(cmi.position); if (contextItem instanceof Contact) { final Contact ctc = (Contact) contextItem; switch (item.getItemId()) { case R.id.cmdChat: openChatActivity(ctc);// w w w. j ava 2 s . c om return true; case R.id.cmdVcard: openVCardActivity(ctc); return true; case R.id.cmdEdit: openEditContactActivity(ctc); return true; case R.id.cmdDelete: confirmDeleteContact(ctc); return true; case R.id.cmdSubscrRequestFrom: subscription(ctc, XmppPresence.PRESENCE_SUBSCRIBE); return true; case R.id.cmdSubscrSendTo: subscription(ctc, XmppPresence.PRESENCE_SUBSCRIBED); return true; case R.id.cmdSubscrRemove: subscription(ctc, XmppPresence.PRESENCE_UNSUBSCRIBED); return true; default: Toast.makeText(getActivity(), "Not implemented yet", Toast.LENGTH_SHORT).show(); } } return super.onContextItemSelected(item); }