List of usage examples for android.view ContextMenu findItem
public MenuItem findItem(int id);
From source file:com.cerema.cloud2.ui.fragment.OCFileListFragment.java
/** * {@inheritDoc}//w w w . j a va 2s .c om */ @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { Bundle args = getArguments(); boolean allowContextualActions = (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); if (allowContextualActions) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.file_actions_menu, menu); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; OCFile targetFile = (OCFile) mAdapter.getItem(info.position); if (mContainerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter(targetFile, mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity()); mf.filter(menu); } /// TODO break this direct dependency on FileDisplayActivity... if possible MenuItem item = menu.findItem(R.id.action_open_file_with); FileFragment frag = ((FileDisplayActivity) getActivity()).getSecondFragment(); if (frag != null && frag instanceof FileDetailFragment && frag.getFile().getFileId() == targetFile.getFileId()) { item = menu.findItem(R.id.action_see_details); if (item != null) { item.setVisible(false); item.setEnabled(false); } } // String.format(mContext.getString(R.string.subject_token), // getClient().getCredentials().getUsername(), file.getFileName())); } }
From source file:com.money.manager.ex.fragment.AllDataFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // take info and cursor from listview adapter AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; Cursor cursor = (Cursor) getListAdapter().getItem(info.position); // check if cursor is valid if (cursor == null) return;/*from w w w .ja va 2s. com*/ /* getActivity().getMenuInflater().inflate(R.menu.contextmenu_accountfragment, menu); // add manually int[] menuItem = new int[] { R.id.menu_edit, R.id.menu_delete, R.id.menu_reconciled, R.id.menu_none, R.id.menu_follow_up, R.id.menu_duplicate, R.id.menu_void }; int[] menuText = new int[] { R.string.edit, R.string.delete, R.string.status_reconciled, R.string.status_none, R.string.status_follow_up, R.string.status_duplicate, R.string.status_void }; for (int i = 0; i < menuItem.length; i++) { menu.add(getContextMenuGroupId(), menuItem[i], i, menuText[i]); } */ // create a context menu getSherlockActivity().getMenuInflater().inflate(R.menu.menu_all_data_adapter, menu); menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(QueryAllData.AccountName))); // hide current status if (menu.findItem(R.id.menu_reconciled) != null) menu.findItem(R.id.menu_reconciled).setVisible(!Constants.TRANSACTION_STATUS_RECONCILED .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status)))); if (menu.findItem(R.id.menu_none) != null) menu.findItem(R.id.menu_none).setVisible(!Constants.TRANSACTION_STATUS_UNRECONCILED .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status)))); if (menu.findItem(R.id.menu_duplicate) != null) menu.findItem(R.id.menu_duplicate).setVisible(!Constants.TRANSACTION_STATUS_DUPLICATE .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status)))); if (menu.findItem(R.id.menu_follow_up) != null) menu.findItem(R.id.menu_follow_up).setVisible(!Constants.TRANSACTION_STATUS_FOLLOWUP .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status)))); if (menu.findItem(R.id.menu_void) != null) menu.findItem(R.id.menu_void).setVisible(!Constants.TRANSACTION_STATUS_VOID .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status)))); }
From source file:com.androsz.electricsleepbeta.alarmclock.AlarmClock.java
@Override public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenuInfo menuInfo) { // Inflate the menu from xml. // super.getMenuInflater().inflate(R.menu.context_menu, (Menu)menu); menu.add(android.view.Menu.NONE, R.id.enable_alarm, android.view.Menu.NONE, R.string.enable_alarm); menu.add(android.view.Menu.NONE, R.id.edit_alarm, android.view.Menu.NONE, R.string.menu_edit_alarm); menu.add(android.view.Menu.NONE, R.id.delete_alarm, android.view.Menu.NONE, R.string.delete_alarm); // Use the current item to create a custom view for the header. final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; final Cursor c = (Cursor) mAlarmsList.getAdapter().getItem(info.position); final Alarm alarm = new Alarm(c); // Construct the Calendar to compute the time. final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, alarm.hour); cal.set(Calendar.MINUTE, alarm.minutes); final String time = Alarms.formatTime(this, cal); // Inflate the custom view and set each TextView's text. final View v = mFactory.inflate(R.layout.context_menu_header, null); TextView textView = (TextView) v.findViewById(R.id.header_time); textView.setText(time);//from ww w .ja v a 2 s .c o m textView = (TextView) v.findViewById(R.id.header_label); textView.setText(alarm.label); // Set the custom view on the menu. menu.setHeaderView(v); // Change the text based on the state of the alarm. if (alarm.enabled) { menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm); } }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java
/** * {@inheritDoc}//from w w w .j a va 2 s .com */ @Override public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); // Get the MenuInflater. final MenuInflater inflater = getActivity().getMenuInflater(); // Cast the menuInfo object to something we understand. final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; // Get the item relating to the selected item. selectedStop = ad.getItem(info.position); final String name; if (selectedStop.locality != null) { name = getString(R.string.busstop_locality, selectedStop.stopName, selectedStop.locality, selectedStop.stopCode); } else { name = getString(R.string.busstop, selectedStop.stopName, selectedStop.stopCode); } // Set the title of the context menu. menu.setHeaderTitle(name); // Inflate the menu from XML. inflater.inflate(R.menu.neareststops_context_menu, menu); // Title depends on whether it's already a favourite or not. MenuItem item = menu.findItem(R.id.neareststops_context_menu_favourite); if (sd.getFavouriteStopExists(selectedStop.stopCode)) { item.setTitle(R.string.neareststops_context_remasfav); } else { item.setTitle(R.string.neareststops_context_addasfav); } // Title depends on whether a proximity alert has already been added or // not. item = menu.findItem(R.id.neareststops_context_menu_prox_alert); if (sd.isActiveProximityAlert(selectedStop.stopCode)) { item.setTitle(R.string.neareststops_menu_prox_rem); } else { item.setTitle(R.string.neareststops_menu_prox_add); } // Title depends on whether a time alert has already been added or not. item = menu.findItem(R.id.neareststops_context_menu_time_alert); if (sd.isActiveTimeAlert(selectedStop.stopCode)) { item.setTitle(R.string.neareststops_menu_time_rem); } else { item.setTitle(R.string.neareststops_menu_time_add); } // If the Google Play Services is not available, then don't show the // option to show the stop on the map. item = menu.findItem(R.id.neareststops_context_menu_showonmap); if (!GenericUtils.isGoogleMapsAvailable(getActivity())) { item.setVisible(false); } }
From source file:de.elanev.studip.android.app.widget.UserListFragment.java
/** * Creating floating context menu//from w ww . jav a 2s.c om */ @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getActivity().getMenuInflater(); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; Cursor listItemCursor = (Cursor) mListView.getAdapter().getItem(info.position); final String[] projection = new String[] { ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_NAME, ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_ID, ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_ID }; final String contactId = listItemCursor .getString(listItemCursor.getColumnIndex(UsersContract.Columns.USER_ID)); CursorLoader loader = new CursorLoader(getActivity(), ContactsContract.CONTENT_URI_CONTACTS.buildUpon().appendPath(contactId).build(), projection, null, null, ContactsContract.Columns.ContactGroups.GROUP_NAME + " ASC"); final Cursor c = loader.loadInBackground(); if (c.getCount() <= 0) { inflater.inflate(R.menu.user_add_context_menu, menu); } else { inflater.inflate(R.menu.user_context_menu, menu); c.moveToFirst(); while (!c.isAfterLast()) { String currGroupName = c .getString(c.getColumnIndex(ContactsContract.Columns.ContactGroups.GROUP_NAME)); if (TextUtils.equals(currGroupName, getString(R.string.studip_app_contacts_favorites))) { menu.removeItem(R.id.add_to_favorites); menu.findItem(R.id.remove_from_favorites).setVisible(true); } c.moveToNext(); } } c.close(); }
From source file:com.googlecode.networklog.AppFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView.getPackedPositionType(info.packedPosition); int group = ExpandableListView.getPackedPositionGroup(info.packedPosition); int child = ExpandableListView.getPackedPositionChild(info.packedPosition); MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.layout.app_context_menu, menu); if (type != ExpandableListView.PACKED_POSITION_TYPE_CHILD) { menu.findItem(R.id.app_copy_ip).setVisible(false); menu.findItem(R.id.app_whois_ip).setVisible(false); }//from ww w . ja v a 2 s . c o m GroupItem groupItem = (GroupItem) adapter.getGroup(group); if (NetworkLogService.toastBlockedApps.get(groupItem.app.packageName) != null) { menu.findItem(R.id.app_toggle_app_notifications).setTitle(R.string.enable_notifications); } else { menu.findItem(R.id.app_toggle_app_notifications).setTitle(R.string.disable_notifications); } if (NetworkLogService.blockedApps.get(groupItem.app.packageName) != null) { menu.findItem(R.id.app_toggle_app_logging).setTitle(R.string.unblock_app); } else { menu.findItem(R.id.app_toggle_app_logging).setTitle(R.string.block_app); } }
From source file:cgeo.geocaching.CacheListActivity.java
@Override public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenu.ContextMenuInfo info) { super.onCreateContextMenu(menu, view, info); AdapterContextMenuInfo adapterInfo = null; try {/*from w w w .ja va 2s . com*/ adapterInfo = (AdapterContextMenuInfo) info; } catch (final Exception e) { Log.w("CacheListActivity.onCreateContextMenu", e); } if (adapterInfo == null || adapterInfo.position >= adapter.getCount()) { return; } final Geocache cache = adapter.getItem(adapterInfo.position); menu.setHeaderTitle(StringUtils.defaultIfBlank(cache.getName(), cache.getGeocode())); contextMenuGeocode = cache.getGeocode(); getMenuInflater().inflate(R.menu.cache_list_context, menu); menu.findItem(R.id.menu_default_navigation) .setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName()); final boolean hasCoords = cache.getCoords() != null; menu.findItem(R.id.menu_default_navigation).setVisible(hasCoords); menu.findItem(R.id.menu_navigate).setVisible(hasCoords); menu.findItem(R.id.menu_cache_details).setVisible(hasCoords); final boolean isOffline = cache.isOffline(); menu.findItem(R.id.menu_drop_cache).setVisible(isOffline); menu.findItem(R.id.menu_move_to_list).setVisible(isOffline); menu.findItem(R.id.menu_copy_to_list).setVisible(isOffline); menu.findItem(R.id.menu_refresh).setVisible(isOffline); menu.findItem(R.id.menu_store_cache).setVisible(!isOffline); LoggingUI.onPrepareOptionsMenu(menu, cache); }
From source file:com.fsck.k9.activity.Accounts.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle(R.string.accounts_context_menu_title); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; BaseAccount account = mAdapter.getItem(info.position); if ((account instanceof Account) && !((Account) account).isEnabled()) { getMenuInflater().inflate(R.menu.disabled_accounts_context, menu); } else {//from w w w . j a v a 2 s .c o m 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:cgeo.geocaching.CacheDetailActivity.java
@Override public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenu.ContextMenuInfo info) { super.onCreateContextMenu(menu, view, info); final int viewId = view.getId(); switch (viewId) { case R.id.waypoint: menu.setHeaderTitle(selectedWaypoint.getName() + " (" + res.getString(R.string.waypoint) + ")"); getMenuInflater().inflate(R.menu.waypoint_options, menu); final boolean isOriginalWaypoint = selectedWaypoint.getWaypointType() == WaypointType.ORIGINAL; menu.findItem(R.id.menu_waypoint_reset_cache_coords).setVisible(isOriginalWaypoint); menu.findItem(R.id.menu_waypoint_edit).setVisible(!isOriginalWaypoint); menu.findItem(R.id.menu_waypoint_duplicate).setVisible(!isOriginalWaypoint); menu.findItem(R.id.menu_waypoint_delete).setVisible(!isOriginalWaypoint); final boolean hasCoords = selectedWaypoint.getCoords() != null; final MenuItem defaultNavigationMenu = menu.findItem(R.id.menu_waypoint_navigate_default); defaultNavigationMenu.setVisible(hasCoords); defaultNavigationMenu.setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName()); menu.findItem(R.id.menu_waypoint_navigate).setVisible(hasCoords); menu.findItem(R.id.menu_waypoint_caches_around).setVisible(hasCoords); menu.findItem(R.id.menu_waypoint_copy_coordinates).setVisible(hasCoords); final boolean canClearCoords = hasCoords && (selectedWaypoint.isUserDefined() || selectedWaypoint.isOriginalCoordsEmpty()); menu.findItem(R.id.menu_waypoint_clear_coordinates).setVisible(canClearCoords); break;/* w ww .ja va2s.c o m*/ default: if (imagesList != null) { imagesList.onCreateContextMenu(menu, view); } break; } }
From source file:org.mozilla.gecko.AwesomeBar.java
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); ListView list = (ListView) view; Object selectedItem = null;//w w w.j av a 2 s . c o m String title = ""; if (list == findViewById(R.id.history_list)) { if (!(menuInfo instanceof ExpandableListView.ExpandableListContextMenuInfo)) { Log.e(LOGTAG, "menuInfo is not ExpandableListContextMenuInfo"); return; } ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition); int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition); // Check if long tap is on a header row if (groupPosition < 0 || childPosition < 0) return; ExpandableListView exList = (ExpandableListView) list; selectedItem = exList.getExpandableListAdapter().getChild(groupPosition, childPosition); // The history list is backed by a SimpleExpandableListAdapter @SuppressWarnings("rawtypes") Map map = (Map) selectedItem; title = (String) map.get(URLColumns.TITLE); } else { if (!(menuInfo instanceof AdapterView.AdapterContextMenuInfo)) { Log.e(LOGTAG, "menuInfo is not AdapterContextMenuInfo"); return; } AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; selectedItem = list.getItemAtPosition(info.position); if (!(selectedItem instanceof Cursor)) { Log.e(LOGTAG, "item at " + info.position + " is not a Cursor"); return; } Cursor cursor = (Cursor) selectedItem; title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE)); // Don't show the context menu for folders if (list == findViewById(R.id.bookmarks_list) && cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.IS_FOLDER)) == 1) { selectedItem = null; } } if (selectedItem == null || !((selectedItem instanceof Cursor) || (selectedItem instanceof Map))) { mContextMenuSubject = null; return; } mContextMenuSubject = selectedItem; MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.awesomebar_contextmenu, menu); if (list != findViewById(R.id.bookmarks_list)) { MenuItem removeBookmarkItem = menu.findItem(R.id.remove_bookmark); removeBookmarkItem.setVisible(false); } menu.setHeaderTitle(title); }