List of usage examples for android.view Menu size
public int size();
From source file:com.wanikani.androidnotifier.WebReviewActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem mi;//from ww w . j a v a2 s. c om int i; for (i = 0; i < menu.size(); i++) { mi = menu.getItem(i); if (mi.getItemId() == R.id.em_fonts) { mi.setVisible(keyboard.canOverrideFonts()); mi.setIcon(keyboard.getOverrideFonts() ? R.drawable.ic_menu_font_enabled : R.drawable.ic_menu_font); } } return true; }
From source file:org.tigase.mobile.bookmarks.BookmarksActivity.java
@TargetApi(11) private void initializeContextActions() { listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { private Bookmark getBookmarkFromFlatPosition(int pos) { long packed = listView.getExpandableListPosition(pos); int child = ExpandableListView.getPackedPositionChild(packed); int group = ExpandableListView.getPackedPositionGroup(packed); return (Bookmark) adapter.getChild(group, child); }// w w w .j av a 2 s . com @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { SparseBooleanArray selection = listView.getCheckedItemPositions(); if (item.getItemId() == R.id.edit) { for (int i = 0; i < selection.size(); i++) { if (selection.valueAt(i)) { int pos = selection.keyAt(i); Bookmark bookmark = getBookmarkFromFlatPosition(pos); editItem(bookmark); } } mode.finish(); // Action picked, so close the CAB return true; } else if (item.getItemId() == R.id.remove) { List<Bookmark> items = new ArrayList<Bookmark>(); for (int i = 0; i < selection.size(); i++) { if (selection.valueAt(i)) { int pos = selection.keyAt(i); Bookmark bookmark = getBookmarkFromFlatPosition(pos); if (bookmark != null) { items.add(bookmark); } } } removeItems(items); mode.finish(); return true; } else { return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.bookmarks_context_menu, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { // TODO Auto-generated method stub } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { Menu menu = mode.getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem mi = menu.getItem(i); if (mi.getItemId() == R.id.edit) { mi.setVisible(listView.getCheckedItemCount() < 2); } } } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { // TODO Auto-generated method stub return true; } }); }
From source file:com.morlunk.mumbleclient.app.PlumbleActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem disconnectButton = menu.findItem(R.id.action_disconnect); disconnectButton.setVisible(mService != null && mService.isSynchronized()); // Color the action bar icons to the primary text color of the theme. int foregroundColor = getSupportActionBar().getThemedContext() .obtainStyledAttributes(new int[] { android.R.attr.textColor }).getColor(0, -1); for (int x = 0; x < menu.size(); x++) { MenuItem item = menu.getItem(x); if (item.getIcon() != null) { Drawable icon = item.getIcon().mutate(); // Mutate the icon so that the color filter is exclusive to the action bar icon.setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY); }/* w w w .j ava 2 s . c om*/ } return super.onPrepareOptionsMenu(menu); }
From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // super.onCreateOptionsMenu(menu, inflater); for (int i = 0; i < menu.size(); i++) { menu.removeItem(i);//from ww w.j av a 2 s .c o m } inflater.inflate(R.menu.menu_map, menu); }
From source file:im.vector.adapters.VectorMessagesAdapter.java
/** * The user taps on the action icon./*from www. ja va 2 s. c o m*/ * @param event the selected event. * @param textMsg the event text * @param anchorView the popup anchor. */ @SuppressLint("NewApi") private void onMessageClick(final Event event, final String textMsg, final View anchorView) { final PopupMenu popup = (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) ? new PopupMenu(mContext, anchorView, Gravity.END) : new PopupMenu(mContext, anchorView); popup.getMenuInflater().inflate(R.menu.vector_room_message_settings, popup.getMenu()); // force to display the icons try { Field[] fields = popup.getClass().getDeclaredFields(); for (Field field : fields) { if ("mPopup".equals(field.getName())) { field.setAccessible(true); Object menuPopupHelper = field.get(popup); Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); setForceIcons.invoke(menuPopupHelper, true); break; } } } catch (Exception e) { Log.e(LOG_TAG, "onMessageClick : force to display the icons failed " + e.getLocalizedMessage()); } Menu menu = popup.getMenu(); // hide entries for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(false); } menu.findItem(R.id.ic_action_view_source).setVisible(true); menu.findItem(R.id.ic_action_vector_permalink).setVisible(true); if (!TextUtils.isEmpty(textMsg)) { menu.findItem(R.id.ic_action_vector_copy).setVisible(true); menu.findItem(R.id.ic_action_vector_quote).setVisible(true); } if (event.isUploadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_upload).setVisible(true); } if (event.isDownloadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_download).setVisible(true); } if (event.canBeResent()) { menu.findItem(R.id.ic_action_vector_resend_message).setVisible(true); if (event.isUndeliverable()) { menu.findItem(R.id.ic_action_vector_redact_message).setVisible(true); } } else if (event.mSentState == Event.SentState.SENT) { // test if the event can be redacted boolean canBeRedacted = !mIsPreviewMode; if (canBeRedacted) { // oneself message -> can redact it if (TextUtils.equals(event.sender, mSession.getMyUserId())) { canBeRedacted = true; } else { // need the mininum power level to redact an event Room room = mSession.getDataHandler().getRoom(event.roomId); if ((null != room) && (null != room.getLiveState().getPowerLevels())) { PowerLevels powerLevels = room.getLiveState().getPowerLevels(); canBeRedacted = powerLevels.getUserPowerLevel(mSession.getMyUserId()) >= powerLevels.redact; } } } menu.findItem(R.id.ic_action_vector_redact_message).setVisible(canBeRedacted); if (Event.EVENT_TYPE_MESSAGE.equals(event.type)) { Message message = JsonUtils.toMessage(event.getContentAsJsonObject()); // share / forward the message menu.findItem(R.id.ic_action_vector_share).setVisible(true); menu.findItem(R.id.ic_action_vector_forward).setVisible(true); // save the media in the downloads directory if (Message.MSGTYPE_IMAGE.equals(message.msgtype) || Message.MSGTYPE_VIDEO.equals(message.msgtype) || Message.MSGTYPE_FILE.equals(message.msgtype)) { menu.findItem(R.id.ic_action_vector_save).setVisible(true); } // offer to report a message content menu.findItem(R.id.ic_action_vector_report) .setVisible(!mIsPreviewMode && !TextUtils.equals(event.sender, mSession.getMyUserId())); } } // display the menu popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { // warn the listener if (null != mVectorMessagesAdapterEventsListener) { mVectorMessagesAdapterEventsListener.onEventAction(event, textMsg, item.getItemId()); } // disable the selection mHighlightedEventId = null; notifyDataSetChanged(); return true; } }); popup.show(); }
From source file:com.terracom.mumbleclient.app.QRPushToTalkActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem disconnectButton = menu.findItem(R.id.action_disconnect); try {// ww w.j av a 2s .c o m disconnectButton.setVisible(mService != null && mService.isConnected()); } catch (RemoteException e) { e.printStackTrace(); } // Color the action bar icons to the primary text color of the theme. int foregroundColor = getSupportActionBar().getThemedContext() .obtainStyledAttributes(new int[] { android.R.attr.textColor }).getColor(0, -1); for (int x = 0; x < menu.size(); x++) { MenuItem item = menu.getItem(x); if (item.getIcon() != null) { Drawable icon = item.getIcon().mutate(); // Mutate the icon so that the color filter is exclusive to the action bar icon.setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY); } } return super.onPrepareOptionsMenu(menu); }
From source file:gov.wa.wsdot.android.wsdot.ui.TrafficMapActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { menu.clear();//from w w w. ja v a 2 s.com getMenuInflater().inflate(R.menu.traffic, menu); if (showCameras) { menu.getItem(0).setTitle("Hide Cameras"); } else { menu.getItem(0).setTitle("Show Cameras"); } /** * Check if current location is within a lat/lon bounding box surrounding * the greater Seattle area. */ try { LatLng center = map.getCameraPosition().target; if (inPolygon(seattleArea, center.latitude, center.longitude)) { MenuItem menuItem_Alerts = menu.add(0, MENU_ITEM_SEATTLE_ALERTS, menu.size(), "Seattle Alerts") .setIcon(R.drawable.ic_menu_alerts); MenuItemCompat.setShowAsAction(menuItem_Alerts, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); MenuItem menuItem_Lanes = menu.add(0, MENU_ITEM_EXPRESS_LANES, menu.size(), "Express Lanes"); MenuItemCompat.setShowAsAction(menuItem_Lanes, MenuItemCompat.SHOW_AS_ACTION_NEVER); } } catch (NullPointerException e) { Log.e(TAG, "Error getting LatLng center"); } return super.onPrepareOptionsMenu(menu); }
From source file:fiskinfoo.no.sintef.fiskinfoo.MyToolsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { for (int i = 0; i < menu.size(); i++) { menu.removeItem(i);/*from ww w .java 2 s. com*/ } inflater.inflate(R.menu.menu_tool_registration, menu); }
From source file:im.neon.adapters.VectorMessagesAdapter.java
/** * The user taps on the action icon./*from w w w. j a v a 2 s.c o m*/ * @param event the selected event. * @param textMsg the event text * @param anchorView the popup anchor. */ @SuppressLint("NewApi") private void onMessageClick(final Event event, final String textMsg, final View anchorView) { final PopupMenu popup = (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) ? new PopupMenu(mContext, anchorView, Gravity.END) : new PopupMenu(mContext, anchorView); popup.getMenuInflater().inflate(R.menu.vector_room_message_settings, popup.getMenu()); // force to display the icons try { Field[] fields = popup.getClass().getDeclaredFields(); for (Field field : fields) { if ("mPopup".equals(field.getName())) { field.setAccessible(true); Object menuPopupHelper = field.get(popup); Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); setForceIcons.invoke(menuPopupHelper, true); break; } } } catch (Exception e) { Log.e(LOG_TAG, "onMessageClick : force to display the icons failed " + e.getLocalizedMessage()); } Menu menu = popup.getMenu(); // hide entries for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(false); } menu.findItem(R.id.ic_action_view_source).setVisible(true); menu.findItem(R.id.ic_action_vector_permalink).setVisible(true); if (!TextUtils.isEmpty(textMsg)) { menu.findItem(R.id.ic_action_vector_copy).setVisible(true); menu.findItem(R.id.ic_action_vector_quote).setVisible(true); } if (event.isUploadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_upload).setVisible(true); } if (event.isDownloadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_download).setVisible(true); } if (event.canBeResent()) { menu.findItem(R.id.ic_action_vector_resend_message).setVisible(true); if (event.isUndeliverable() || event.isUnkownDevice()) { menu.findItem(R.id.ic_action_vector_redact_message).setVisible(true); } } else if (event.mSentState == Event.SentState.SENT) { // test if the event can be redacted boolean canBeRedacted = !mIsPreviewMode && !TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE_ENCRYPTION); if (canBeRedacted) { // oneself message -> can redact it if (TextUtils.equals(event.sender, mSession.getMyUserId())) { canBeRedacted = true; } else { // need the mininum power level to redact an event Room room = mSession.getDataHandler().getRoom(event.roomId); if ((null != room) && (null != room.getLiveState().getPowerLevels())) { PowerLevels powerLevels = room.getLiveState().getPowerLevels(); canBeRedacted = powerLevels.getUserPowerLevel(mSession.getMyUserId()) >= powerLevels.redact; } } } menu.findItem(R.id.ic_action_vector_redact_message).setVisible(canBeRedacted); if (Event.EVENT_TYPE_MESSAGE.equals(event.getType())) { Message message = JsonUtils.toMessage(event.getContentAsJsonObject()); // share / forward the message menu.findItem(R.id.ic_action_vector_share).setVisible(true); menu.findItem(R.id.ic_action_vector_forward).setVisible(true); // save the media in the downloads directory if (Message.MSGTYPE_IMAGE.equals(message.msgtype) || Message.MSGTYPE_VIDEO.equals(message.msgtype) || Message.MSGTYPE_FILE.equals(message.msgtype)) { menu.findItem(R.id.ic_action_vector_save).setVisible(true); } // offer to report a message content menu.findItem(R.id.ic_action_vector_report) .setVisible(!mIsPreviewMode && !TextUtils.equals(event.sender, mSession.getMyUserId())); } } // e2e menu.findItem(R.id.ic_action_device_verification).setVisible(mE2eIconByEventId.containsKey(event.eventId)); // display the menu popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { // warn the listener if (null != mVectorMessagesAdapterEventsListener) { mVectorMessagesAdapterEventsListener.onEventAction(event, textMsg, item.getItemId()); } // disable the selection mHighlightedEventId = null; notifyDataSetChanged(); return true; } }); // fix an issue reported by GA try { popup.show(); } catch (Exception e) { Log.e(LOG_TAG, " popup.show failed " + e.getMessage()); } }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.activity, menu); // Actions are always visible when showing as dialog if (mShowAsDialog) { for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); }/*from w ww .ja v a 2s . co m*/ } final MenuItem searchMenu = menu.findItem(R.id.menu_search); mSearchView = (SearchView) searchMenu.getActionView(); mSearchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { mState.currentSearch = query; mSearchView.clearFocus(); onCurrentDirectoryChanged(ANIM_NONE); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); searchMenu.setOnActionExpandListener(new OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { if (mIgnoreNextCollapse) { mIgnoreNextCollapse = false; return true; } mState.currentSearch = null; onCurrentDirectoryChanged(ANIM_NONE); return true; } }); mSearchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { if (mIgnoreNextClose) { mIgnoreNextClose = false; return false; } mState.currentSearch = null; onCurrentDirectoryChanged(ANIM_NONE); return false; } }); return true; }