List of usage examples for android.view Menu size
public int size();
From source file:com.gelakinetic.mtgfam.FamiliarActivity.java
/** * Called whenever we call supportInvalidateOptionsMenu(). This hides action bar items when the drawer is open * * @param menu The menu to hide or show items in * @return True if the menu is to be displayed, false otherwise */// w ww . java2 s.c om @Override public boolean onPrepareOptionsMenu(Menu menu) { boolean drawerVisible = mDrawerLayout.isDrawerVisible(mDrawerList); mIsMenuVisible = !drawerVisible; for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(!drawerVisible); } return super.onPrepareOptionsMenu(menu); }
From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java
private void StyleMenuButtons(Menu m) { // Find each menu item and set its text colour for (int i = 0; i < m.size(); i++) { m.getItem(i).setTitle(createMenuItem(m.getItem(i).getTitle().toString())); }//from w w w . j a v a 2 s .co m }
From source file:com.jins_meme.bridge.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); //debug Log.d("DEBUG", "onPrepareOptionsMenu"); String barTitle;//from ww w. j a v a 2s . c om if (getSupportActionBar() != null && getSupportActionBar().getTitle() != null) { barTitle = getSupportActionBar().getTitle().toString(); Log.d("DEBUG", "Title = " + barTitle); if (barTitle.length() > 1) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); String title = item.getTitle().toString(); if (title.contains(" (for Eye VDJ)")) { title = title.substring(0, title.indexOf(" (for Eye VDJ)")); } if (barTitle.contains(title)) { item.setVisible(false); } else { item.setVisible(true); } } } else { for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(true); } } } return true; }
From source file:com.tweetlanes.android.view.TweetFeedFragment.java
@Override public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) { if (inflater != null && mContentHandle != null && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) { if (getBaseLaneActivity() instanceof HomeActivity) { inflater.inflate(R.menu.home_tweet_feed_action_bar, menu); } else {// ww w .j a va 2s . c o m inflater.inflate(R.menu.tweet_feed_action_bar, menu); } for (int i = 0; i < menu.size(); i++) { MenuItem menuItem = menu.getItem(i); if (menuItem.getItemId() == R.id.action_feed_filter) { SubMenu subMenu = menuItem.getSubMenu(); if (subMenu != null) { SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType(); int subMenuSize = subMenu.size(); for (int j = 0; j < subMenuSize; j++) { MenuItem subMenuItem = subMenu.getItem(j); switch (subMenuItem.getItemId()) { case R.id.action_replies_visibility: subMenuItem .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies() ? R.string.action_hide_replies : R.string.action_show_replies)); break; case R.id.action_retweets_visibility: subMenuItem .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets() ? socialNetType == SocialNetConstant.Type.Twitter ? R.string.action_hide_retweets : R.string.action_hide_retweets_adn : socialNetType == SocialNetConstant.Type.Twitter ? R.string.action_show_retweets : R.string.action_show_retweets_adn)); break; default: break; } } } } } return true; } return false; }
From source file:com.tct.mail.ui.ActionBarController.java
public boolean onPrepareOptionsMenu(Menu menu) { // We start out with every option enabled. Based on the current view, we disable actions // that are possible. LogUtils.d(LOG_TAG, "ActionBarView.onPrepareOptionsMenu()."); //[FEATURE]-Add-BEGIN by CDTS.zhonghua.tuo,05/21/2014,FR 670064 // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_S //boolean searchEnhance = mContext.getResources().getBoolean(R.bool.feature_email_search_enhance_on); boolean searchEnhance = PLFUtils.getBoolean(mContext, "feature_email_search_enhance_on"); // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_E if (mLocalSearchItem != null) { mLocalSearchItem//ww w . j ava 2 s . co m .setVisible(mAccount != null && mFolder != null && SERVICE_SEARCH_MODE && searchEnhance); } if (mServiceSearchItem != null) { mServiceSearchItem.setVisible(mAccount != null && mFolder != null && mAccount.supportsCapability(AccountCapabilities.SERVER_SEARCH) && !SERVICE_SEARCH_MODE && searchEnhance); } //[FEATURE]-Add-END by CDTS.zhonghua.tuo //TS: junwei-xu 2015-10-27 EMAIL BUGFIX-791734 MOD //NOTE: Check if mController is null if (mController != null && mController.shouldHideMenuItems()) { // Shortcut: hide all menu items if the drawer is shown final int size = menu.size(); for (int i = 0; i < size; i++) { final MenuItem item = menu.getItem(i); item.setVisible(false); } return false; } validateVolatileMenuOptionVisibility(); switch (getMode()) { case ViewMode.CONVERSATION: case ViewMode.SEARCH_RESULTS_CONVERSATION: // We update the ActionBar options when we are entering conversation view because // waiting for the AbstractConversationViewFragment to do it causes duplicate icons // to show up during the time between the conversation is selected and the fragment // is added. setConversationModeOptions(menu); break; case ViewMode.CONVERSATION_LIST: // Show search if the account supports it Utils.setMenuItemVisibility(menu, R.id.search, mAccount.supportsSearch());//[FEATURE]-Add-BEGIN by TSNJ Zhenhua.Fan,10/23/2014,PR 728378 //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S // Hide star toggle if not support it updateStarToggleVisible(isExpandedSearch()); //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E break; case ViewMode.SEARCH_RESULTS_LIST: // Hide compose and search Utils.setMenuItemVisibility(menu, R.id.compose, false); Utils.setMenuItemVisibility(menu, R.id.search, false); LogUtils.logFeature(LogTag.SEARCH_TAG, "EmailActionBarView onPrepareOptionsMenu SEARCH_RESULTS_LIST"); break; } return false; }
From source file:github.daneren2005.dsub.fragments.SubsonicFragment.java
protected void recreateContextMenu(Menu menu) { List<MenuItem> menuItems = new ArrayList<MenuItem>(); for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (item.isVisible()) { menuItems.add(item);/* ww w . ja v a 2 s. com*/ } } menu.clear(); for (int i = 0; i < menuItems.size(); i++) { MenuItem item = menuItems.get(i); menu.add(tag, item.getItemId(), Menu.NONE, item.getTitle()); } }
From source file:org.mariotaku.twidere.fragment.UserProfileFragment.java
@Override public void onClick(final View view) { if (getActivity() == null) return;// w ww. j av a 2s . c om switch (view.getId()) { case R.id.edit_follow: { if (mUser == null || mAccountId <= 0) return; if (mAccountId == mUserId) { final Bundle bundle = getArguments(); final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE); intent.setClass(getActivity(), EditUserProfileActivity.class); if (bundle != null) { intent.putExtras(bundle); } startActivity(intent); } else { if (mUser.is_follow_request_sent) return; if (mFriendship.isSourceFollowingTarget()) { mPopupMenu = PopupMenu.getInstance(getActivity(), view); mPopupMenu.inflate(R.menu.action_user_profile_follow); mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.unfollow: { mFollowProgress.setVisibility(View.VISIBLE); mEditFollowButton.setVisibility(View.GONE); mTwitterWrapper.destroyFriendship(mAccountId, mUser.user_id); return true; } } return false; } }); mPopupMenu.show(); } else { mFollowProgress.setVisibility(View.VISIBLE); mEditFollowButton.setVisibility(View.GONE); mTwitterWrapper.createFriendship(mAccountId, mUser.user_id); } } break; } case R.id.retry: { getUserInfo(true); break; } case R.id.profile_image_container: { final Uri uri = Uri.parse(getOriginalTwitterProfileImage(mUser.profile_image_url)); openImage(getActivity(), uri, false); break; } case R.id.tweets_container: { if (mUser == null) return; openUserTimeline(getActivity(), mAccountId, mUser.user_id, mUser.screen_name); break; } case R.id.followers_container: { if (mUser == null) return; openUserFollowers(getActivity(), mAccountId, mUser.user_id, mUser.screen_name); break; } case R.id.friends_container: { if (mUser == null) return; openUserFriends(getActivity(), mAccountId, mUser.user_id, mUser.screen_name); break; } case R.id.more_options: { if (mUser == null) return; mPopupMenu = PopupMenu.getInstance(getActivity(), view); mPopupMenu.inflate(R.menu.action_user_profile); final Menu menu = mPopupMenu.getMenu(); if (mUser.user_id != mAccountId) { if (mFriendship == null) return; final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (blockItem != null) { final Drawable blockIcon = blockItem.getIcon(); if (mFriendship.isSourceBlockingTarget()) { blockItem.setTitle(R.string.unblock); blockIcon.mutate().setColorFilter(getResources().getColor(R.color.holo_blue_bright), PorterDuff.Mode.MULTIPLY); } else { blockItem.setTitle(R.string.block); blockIcon.clearColorFilter(); } } final MenuItem sendDirectMessageItem = menu.findItem(MENU_SEND_DIRECT_MESSAGE); if (sendDirectMessageItem != null) { sendDirectMessageItem.setVisible(mFriendship.isTargetFollowingSource()); } } else { final int size = menu.size(); for (int i = 0; i < size; i++) { final MenuItem item = menu.getItem(i); final int id = item.getItemId(); item.setVisible(id == R.id.set_color_submenu || id == MENU_EXTENSIONS_SUBMENU); } } final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU); if (extensions != null) { final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(INTENT_KEY_USER, mUser); intent.putExtras(extras); addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent); } mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.show(); break; } case R.id.name_container: { if (mUser == null || mAccountId != mUserId) return; startActivity(new Intent(getActivity(), EditUserProfileActivity.class)); break; } } }
From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { mOptionsMenuContactsAvailable = mContactsAvailable; if (!mOptionsMenuContactsAvailable) { return;// w ww . j a v a2s. c o m } final boolean isSearchOrSelectionMode = mActionBarAdapter.isSearchMode() || mActionBarAdapter.isSelectionMode(); makeMenuItemVisible(menu, R.id.menu_search, !isSearchOrSelectionMode); final boolean showSelectedContactOptions = mActionBarAdapter.isSelectionMode() && getSelectedContactIds().size() != 0; makeMenuItemVisible(menu, R.id.menu_share, showSelectedContactOptions); makeMenuItemVisible(menu, R.id.menu_delete, showSelectedContactOptions); final boolean showLinkContactsOptions = mActionBarAdapter.isSelectionMode() && getSelectedContactIds().size() > 1; makeMenuItemVisible(menu, R.id.menu_join, showLinkContactsOptions); // Debug options need to be visible even in search mode. makeMenuItemVisible(menu, R.id.export_database, mEnableDebugMenuOptions && hasExportIntentHandler()); // Light tint the icons for normal mode, dark tint for search or selection mode. for (int i = 0; i < menu.size(); ++i) { final Drawable icon = menu.getItem(i).getIcon(); if (icon != null && !isSearchOrSelectionMode) { icon.mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.actionbar_icon_color), PorterDuff.Mode.SRC_ATOP); } } }
From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java
/** * Set up the App bar menu// ww w. j a va 2 s . c o m * * Loop through all menu items, checking ID for set up. * We do it this way because item indices aren't set since the menu is dynamic. * (ex. travel charts may be added to the start) * * @param menu * @return */ @Override public boolean onPrepareOptionsMenu(Menu menu) { menu.clear(); getMenuInflater().inflate(R.menu.traffic, menu); if (bestTimesAvailable) { menu.add(0, R.id.best_times_to_travel, 0, "Best Times to Travel").setIcon(R.drawable.ic_menu_chart) .setActionView(R.layout.action_bar_notification_icon) .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); final MenuItem chartMenuItem = menu.findItem(R.id.best_times_to_travel); // Since we added an action view, need to hook up the onclick ourselves. chartMenuItem.getActionView() .setOnClickListener(v -> TrafficMapActivity.this.onMenuItemSelected(0, chartMenuItem)); menu_item_refresh = 2; } else { menu_item_refresh = 1; } for (int i = 0; i < menu.size(); i++) { switch (menu.getItem(i).getItemId()) { case R.id.toggle_cameras: if (showCameras) { menu.getItem(i).setTitle("Hide Cameras"); menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam); } else { menu.getItem(i).setTitle("Show Cameras"); menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam_off); } break; default: break; } } return super.onPrepareOptionsMenu(menu); }
From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java
@Override public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) { if (inflater != null && mContentHandle != null && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) { if (getBaseLaneActivity() instanceof HomeActivity) { inflater.inflate(R.menu.home_tweet_feed_action_bar, menu); } else {/*from www .j a va 2s . c o m*/ inflater.inflate(R.menu.tweet_feed_action_bar, menu); } for (int i = 0; i < menu.size(); i++) { MenuItem menuItem = menu.getItem(i); if (menuItem.getItemId() == R.id.action_feed_filter) { SubMenu subMenu = menuItem.getSubMenu(); if (subMenu != null) { SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType(); int subMenuSize = subMenu.size(); for (int j = 0; j < subMenuSize; j++) { MenuItem subMenuItem = subMenu.getItem(j); int i1 = subMenuItem.getItemId(); if (i1 == R.id.action_replies_visibility) { subMenuItem .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies() ? R.string.action_hide_replies : R.string.action_show_replies)); } else if (i1 == R.id.action_retweets_visibility) { subMenuItem .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets() ? socialNetType == SocialNetConstant.Type.Twitter ? R.string.action_hide_retweets : R.string.action_hide_retweets_adn : socialNetType == SocialNetConstant.Type.Twitter ? R.string.action_show_retweets : R.string.action_show_retweets_adn)); } else { } } } } } return true; } return false; }