List of usage examples for android.view Menu getItem
public MenuItem getItem(int index);
From source file:gov.wa.wsdot.android.wsdot.ui.CameraImageFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.share_action_provider, menu); // Set file with share history to the provider and set the share intent. MenuItem menuItem_Share = menu.findItem(R.id.action_share); shareAction = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem_Share); shareAction.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); MenuItem menuItem_Star = menu.add(0, MENU_ITEM_STAR, menu.size(), R.string.description_star); MenuItemCompat.setShowAsAction(menuItem_Star, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); if (mIsStarred) { menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on); } else {/* ww w. j ava 2 s . c o m*/ menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star); } }
From source file:com.mobicage.rogerthat.plugins.messaging.MessagingActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); switch (item.getItemId()) { case R.id.select_all: case R.id.deselect_all: item.setVisible(mEditing);//from www. j av a 2 s . c om break; case R.id.delete_messages: item.setEnabled(((CursorAdapter) getListAdapter()).getCursor().getCount() > 0); //$FALL-THROUGH$ default: item.setVisible(!mEditing); break; } } return super.onPrepareOptionsMenu(menu); }
From source file:com.pacoapp.paco.ui.FindMyExperimentsActivity.java
@SuppressLint("NewApi") @Override//from ww w . ja v a2s . c o m public boolean onCreateOptionsMenu(Menu menu) { int pos = 1; if (true || !mNavigationDrawerFragment.isDrawerOpen()) { getMenuInflater().inflate(R.menu.main, menu); // restoreActionBar(); // TODO hide find experiments (this is that item) // TODO make refresh be an always action MenuItem findExperiments = menu.getItem(0); findExperiments.setVisible(false); MenuItem refreshExperiments = menu.getItem(1); refreshExperiments.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); return true; } return super.onCreateOptionsMenu(menu); }
From source file:org.spinsuite.view.T_DynamicTab.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); menu.clear();//w w w . j av a 2 s . c om inflater.inflate(R.menu.dynamic_tab, menu); // Valid is Loaded if (!m_IsLoadOk) return; // do it // Get Items mi_Search = menu.getItem(0); mi_Edit = menu.getItem(1); mi_Add = menu.getItem(2); mi_Delete = menu.getItem(3); mi_Cancel = menu.getItem(4); mi_Save = menu.getItem(5); // Lock View changeMenuView(); }
From source file:com.dunrite.aisle5.activities.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view //boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); //Manages when to show what buttons in the Actionbar //0=Share, 1=Clear, 2=About, 3=GoToMyList if ("MyList".equals(getSupportActionBar().getTitle())) { if (myListHasItems) { menu.getItem(1).setVisible(true); } else {/*from w ww.j a v a2 s.c o m*/ menu.getItem(1).setVisible(false); } menu.getItem(3).setVisible(false); } else if ("Aisle5".equals(getSupportActionBar().getTitle())) { menu.getItem(1).setVisible(false); menu.getItem(3).setVisible(false); } else { menu.getItem(1).setVisible(false); menu.getItem(3).setVisible(true); } return super.onPrepareOptionsMenu(menu); }
From source file:org.dvbviewer.controller.ui.fragments.ChannelPager.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.channel_list, menu); for (int i = 0; i < menu.size(); i++) { if (menu.getItem(i).getItemId() == R.id.menuChannelList) { menu.getItem(i).setVisible(showFavs); } else if (menu.getItem(i).getItemId() == R.id.menuFavourties) { menu.getItem(i).setVisible(!showFavs); }/*from w ww . jav a 2s.c o m*/ } menu.findItem(R.id.menuChannelList).setVisible(showFavs); menu.findItem(R.id.menuFavourties).setVisible(!showFavs); if (getActivity() instanceof ChannelListMultiActivity) { menu.findItem(R.id.menu_refresh_now_playing).setVisible(false); menu.findItem(R.id.menuRefreshChannels).setVisible(false); } }
From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(getMenuResourceId(), menu); // Make menu icon color same as toolbar up arrow. Both use ?colorControlNormal // By default colorControlNormal has same value as textColorPrimary defined in toolbar theme overlay int colorControlNormal = Util.getThemeColor(ApptentiveInternal.getInstance().getApptentiveToolbarTheme(), R.attr.colorControlNormal);//from w w w.j a v a 2s. c o m for (int i = 0; i < menu.size(); i++) { Drawable drawable = menu.getItem(i).getIcon(); if (drawable != null) { drawable.mutate(); drawable.setColorFilter(colorControlNormal, PorterDuff.Mode.SRC_ATOP); } } attachFragmentMenuListeners(menu); super.onCreateOptionsMenu(menu, inflater); }
From source file:com.drextended.actionhandler.action.CompositeAction.java
/** * Prepares popup menu to show given menu items * * @param context The Context, which generally get from view by {@link View#getContext()} * @param view The View, which can be used for prepare any visual effect (like animation), * Generally it is that view which was clicked and initiated action to fire. * @param actionType The action type/*from w ww . jav a 2 s . c o m*/ * @param model The model which should be handled by the action. * @param menuItems list of items which will be shown in a menu * @return popup menu to show given menu items */ protected PopupMenu buildPopupMenu(final Context context, final View view, final String actionType, final M model, final List<ActionItem> menuItems) { final PopupMenu popupMenu = new PopupMenu(context, view); final Menu menu = popupMenu.getMenu(); int count = menuItems.size(); for (int index = 0; index < count; index++) { final ActionItem item = menuItems.get(index); //noinspection unchecked menu.add(0, index, 0, item.titleProvider.getTitle(context, model)); if (mShowNonAcceptedActions) { menu.getItem(index).setEnabled(item.action.isModelAccepted(model)); } } final AtomicBoolean activated = new AtomicBoolean(false); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { activated.set(true); final ActionItem actionItem = menuItems.get(item.getItemId()); if (item.isEnabled()) { fireActionItem(context, view, actionItem.actionType, model, actionItem); } else { notifyOnActionDismiss("The model is not accepted for selected action", view, actionType, model); } return true; } }); popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { if (!activated.get()) { notifyOnActionDismiss("CompositeAction menu dismissed", view, actionType, model); } } }); return popupMenu; }
From source file:gov.wa.wsdot.android.wsdot.ui.camera.CameraImageFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.share_action_provider, menu); // Set file with share history to the provider and set the share intent. MenuItem menuItem_Share = menu.findItem(R.id.action_share); shareAction = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem_Share); shareAction.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); if (showStar) { MenuItem menuItem_Star = menu.add(0, MENU_ITEM_STAR, menu.size(), R.string.description_star); MenuItemCompat.setShowAsAction(menuItem_Star, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); if (mIsStarred) { menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on); } else {//from ww w .jav a2s . c o m menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star); } } }
From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java
private void createNavDrawerItems(NavigationModel.NavigationItemEnum[] items) { if (mNavigationView != null) { Menu menu = mNavigationView.getMenu(); for (int i = 0; i < items.length; i++) { MenuItem item = menu.findItem(items[i].getId()); if (item != null) { item.setVisible(true);// w w w .j a va 2 s. co m item.setIcon(items[i].getIcon()); item.setTitle(items[i].getTitleResource()); } else { LogUtils.LOGE(TAG, "Menu Item for navigation item with title " + (items[i].getTitleResource() != 0 ? mActivity.getResources().getString(items[i].getTitleResource()) : "") + "not found"); } } for (int i = 0; i < menu.size(); i++) { MenuItem mi = menu.getItem(i); applyFontToSubMenu(mi); applyFontToMenuItem(mi); } mNavigationView.setNavigationItemSelectedListener(this); } }