List of usage examples for android.view Menu getItem
public MenuItem getItem(int index);
From source file:com.wanikani.androidnotifier.WebReviewActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem mi;/*from ww w. jav a 2s . co m*/ 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.torproject.android.Orbot.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); mItemOnOff = menu.getItem(0); return true;// w w w .j ava 2s .c o m }
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); }/*from w ww . j av a2 s . co m*/ @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.androidaq.AndroiDAQTCPMain.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.option_menu, menu); int state = getConnectionState(); if (state == 0) { mMenuItemConnect = menu.getItem(0); if (mMenuItemConnect != null) { mMenuItemConnect.setIcon(android.R.drawable.ic_menu_search); mMenuItemConnect.setTitle(R.string.connect); }//from w w w . j a v a 2 s. c o m } else { mMenuItemConnect = menu.getItem(0); if (mMenuItemConnect != null) { mMenuItemConnect.setIcon(android.R.drawable.ic_menu_close_clear_cancel); mMenuItemConnect.setTitle(R.string.disconnect); } } 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); }/*from w w w. ja v a 2 s . co m*/ } return super.onPrepareOptionsMenu(menu); }
From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); boolean retValue = false; retValue |= mActionBarHelper.onCreateOptionsMenu(menu); retValue |= super.onCreateOptionsMenu(menu); mServersMenu = menu.getItem(0); scanForServersMenu();/*from w w w.j ava2 s. c om*/ return retValue; }
From source file:im.vector.adapters.VectorMessagesAdapter.java
/** * The user taps on the action icon./*from w w w .ja v a 2s . 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:de.bogutzky.psychophysiocollector.app.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); this.connectMenuItem = menu.getItem(4); this.disconnectMenuItem = menu.getItem(5); this.startStreamMenuItem = menu.getItem(0); this.stopStreamMenuItem = menu.getItem(1); this.addMenuItem = menu.getItem(3); return true;// w w w . j a v a 2 s. c om }
From source file:com.coincide.alphafitness.ui.Fragment_Main.java
@Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { inflater.inflate(R.menu.main, menu); MenuItem pause = menu.getItem(0); Drawable d;//from w w w.j ava 2 s . c om if (getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE).contains("pauseCount")) { // currently paused pause.setTitle(R.string.resume); d = getResources().getDrawable(R.drawable.ic_resume); } else { pause.setTitle(R.string.pause); d = getResources().getDrawable(R.drawable.ic_pause); } d.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); pause.setIcon(d); }
From source file:com.terracom.mumbleclient.app.QRPushToTalkActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem disconnectButton = menu.findItem(R.id.action_disconnect); try {//from ww w .ja va 2s.co 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); }