List of usage examples for android.view Menu removeGroup
public void removeGroup(int groupId);
From source file:org.mariotaku.twidere.fragment.support.UserListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { final ParcelableUserList userList = mUserList; setMenuItemAvailability(menu, MENU_INFO, userList != null); menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION); if (userList != null) { final boolean isMyList = userList.user_id == userList.account_id; final boolean isFollowing = userList.is_following; setMenuItemAvailability(menu, MENU_EDIT, isMyList); setMenuItemAvailability(menu, MENU_FOLLOW, !isMyList); setMenuItemAvailability(menu, MENU_ADD, isMyList); setMenuItemAvailability(menu, MENU_DELETE, isMyList); final MenuItem followItem = menu.findItem(MENU_FOLLOW); if (isFollowing) { followItem.setIcon(R.drawable.ic_action_cancel); followItem.setTitle(R.string.unsubscribe); } else {/* w w w .j a v a 2 s.c o m*/ followItem.setIcon(R.drawable.ic_action_add); followItem.setTitle(R.string.subscribe); } final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST); extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader()); extensionsIntent.putExtra(EXTRA_USER_LIST, userList); addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION); } else { setMenuItemAvailability(menu, MENU_EDIT, false); setMenuItemAvailability(menu, MENU_FOLLOW, false); setMenuItemAvailability(menu, MENU_ADD, false); setMenuItemAvailability(menu, MENU_DELETE, false); } }
From source file:com.inovex.zabbixmobile.activities.BaseActivity.java
private void toggleServerSelectionMode() { Menu menu = mNavigationView.getMenu(); if (mServerSelectMode) { // show normal menu menu.setGroupVisible(R.id.grp1, true); menu.setGroupVisible(R.id.grp2, true); menu.removeGroup(R.id.grp0_server); mServerSelectButton.setImageDrawable(getResources().getDrawable(R.drawable.spinner_triangle)); } else {/*from ww w . ja v a2s .co m*/ // show server selection list menu.setGroupVisible(R.id.grp1, false); menu.setGroupVisible(R.id.grp2, false); for (int i = 0; i < mServersListAdapter.getCount(); i++) { ZabbixServer server = mServersListAdapter.getItem(i); menu.add(R.id.grp0_server, (int) server.getId(), Menu.NONE, server.getName()) .setIcon(R.drawable.ic_monitor_grey600_24dp); } mServerSelectButton.setImageDrawable(getResources().getDrawable(R.drawable.spinner_triangle_flipped)); } mServerSelectMode = !mServerSelectMode; }
From source file:com.androzic.waypoint.WaypointList.java
@Override public void onPrepareOptionsMenu(final Menu menu) { Androzic application = Androzic.getApplication(); MenuItem sortItem = menu.findItem(mSortMode == 0 ? R.id.action_sort_alpha : R.id.action_sort_size); sortItem.setChecked(true);/*ww w . ja va 2 s. c om*/ Editor editor = PreferenceManager.getDefaultSharedPreferences(application).edit(); editor.putInt(getString(R.string.wpt_sort), mSortMode); editor.commit(); List<WaypointSet> sets = application.getWaypointSets(); if (sets.size() > 1) { menu.setGroupVisible(R.id.group_sets, true); menu.removeGroup(R.id.group_sets); for (int i = 1; i < sets.size(); i++) menu.add(R.id.group_sets, i, Menu.NONE, sets.get(i).name).setChecked(true); menu.setGroupCheckable(R.id.group_sets, true, false); } }
From source file:com.example.android.notepad.NotesList.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); //final boolean haveItems = getListAdapter().getCount() > 0; boolean haveItems = true; // If there are any notes in the list (which implies that one of // them is selected), then we need to generate the actions that // can be performed on the current selection. This will be a combination // of our own specific actions along with any extensions that can be // found.//from w w w. j av a 2 s . c o m if (haveItems) { // This is the selected item. Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId()); // Build menu... always starts with the EDIT action... Intent[] specifics = new Intent[1]; specifics[0] = new Intent(Intent.ACTION_EDIT, uri); MenuItem[] items = new MenuItem[1]; // ... is followed by whatever other actions are available... Intent intent = new Intent(null, uri); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items); // Give a shortcut to the edit action. if (items[0] != null) { items[0].setShortcut('1', 'e'); } } else { menu.removeGroup(Menu.CATEGORY_ALTERNATIVE); } return true; }
From source file:org.getlantern.firetweet.fragment.support.UserListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUserList userList = mUserList; final MenuItem followItem = menu.findItem(MENU_FOLLOW); if (followItem != null) { followItem.setEnabled(userList != null); if (userList == null) { followItem.setIcon(android.R.color.transparent); }//from ww w. ja v a2 s .c o m } if (twitter == null || userList == null) return; final boolean isMyList = userList.user_id == userList.account_id; setMenuItemAvailability(menu, MENU_EDIT, isMyList); setMenuItemAvailability(menu, MENU_ADD, isMyList); setMenuItemAvailability(menu, MENU_DELETE, isMyList); final boolean isFollowing = userList.is_following; if (followItem != null) { followItem.setVisible(!isMyList); if (isFollowing) { followItem.setIcon(R.drawable.ic_action_cancel); followItem.setTitle(R.string.unsubscribe); } else { followItem.setIcon(R.drawable.ic_action_add); followItem.setTitle(R.string.subscribe); } } menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION); final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST); extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader()); extensionsIntent.putExtra(EXTRA_USER_LIST, mUserList); addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION); }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) { if (context == null || menu == null || status == null) return;//from ww w. j a v a2 s. c o m final int activatedColor = ThemeUtils.getUserThemeColor(context); final boolean isMyRetweet = isMyRetweet(status); final MenuItem delete = menu.findItem(MENU_DELETE); if (delete != null) { delete.setVisible(status.account_id == status.user_id && !isMyRetweet); } final MenuItem retweet = menu.findItem(MENU_RETWEET); if (retweet != null) { final Drawable icon = retweet.getIcon().mutate(); retweet.setVisible(!status.user_is_protected || isMyRetweet); if (isMyRetweet) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); retweet.setTitle(R.string.cancel_retweet); } else { icon.clearColorFilter(); retweet.setTitle(R.string.retweet); } } final MenuItem itemRetweetSubmenu = menu.findItem(R.id.retweet_submenu); if (itemRetweetSubmenu != null) { final Drawable icon = itemRetweetSubmenu.getIcon().mutate(); if (isMyRetweet) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { icon.clearColorFilter(); } } final MenuItem favorite = menu.findItem(MENU_FAVORITE); if (favorite != null) { final Drawable icon = favorite.getIcon().mutate(); if (status.is_favorite) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); favorite.setTitle(R.string.unfavorite); } else { icon.clearColorFilter(); favorite.setTitle(R.string.favorite); } } final MenuItem love = menu.findItem(MENU_LOVE); if (love != null) { final Drawable icon = love.getIcon().mutate(); love.setVisible(!status.user_is_protected || isMyRetweet); if (isMyRetweet && status.is_favorite) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { icon.clearColorFilter(); } } final MenuItem translate = menu.findItem(MENU_TRANSLATE); if (translate != null) { final AccountWithCredentials account = Account.getAccountWithCredentials(context, status.account_id); final boolean isOfficialKey = AccountWithCredentials.isOfficialCredentials(context, account); setMenuItemAvailability(menu, MENU_TRANSLATE, isOfficialKey); } final MenuItem shareItem = menu.findItem(R.id.share_submenu); final Menu shareSubmenu = shareItem != null && shareItem.hasSubMenu() ? shareItem.getSubMenu() : null; if (shareSubmenu != null) { final Intent shareIntent = createStatusShareIntent(context, status); shareSubmenu.removeGroup(MENU_GROUP_STATUS_SHARE); addIntentToMenu(context, shareSubmenu, shareIntent, MENU_GROUP_STATUS_SHARE); } }
From source file:org.mariotaku.twidere.fragment.support.UserProfileFragment.java
private void setMenu(final Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = mUser; final Relationship relationship = mFriendship; if (twitter == null || user == null) return;//from ww w .j a v a2 s . c om final boolean isMyself = user.account_id == user.id; final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget(); final boolean isProtected = user.is_protected; final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id); final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id); setMenuItemAvailability(menu, MENU_EDIT, isMyself); final MenuItem followItem = menu.findItem(MENU_FOLLOW); followItem.setVisible(!isMyself); final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself && relationship != null; followItem.setEnabled(shouldShowFollowItem); if (shouldShowFollowItem) { followItem.setTitle( isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow); followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add); } else { followItem.setTitle(null); followItem.setIcon(null); } if (user.id != user.account_id) { setMenuItemAvailability(menu, MENU_BLOCK, mFriendship != null); final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (mFriendship != null && blockItem != null) { final Drawable blockIcon = blockItem.getIcon(); if (mFriendship.isSourceBlockingTarget()) { blockItem.setTitle(R.string.unblock); blockIcon.mutate().setColorFilter(ThemeUtils.getUserThemeColor(getActivity()), PorterDuff.Mode.MULTIPLY); } else { blockItem.setTitle(R.string.block); blockIcon.clearColorFilter(); } } final boolean is_following_me = mFriendship != null && mFriendship.isTargetFollowingSource(); setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, is_following_me); } else { setMenuItemAvailability(menu, MENU_MENTION, false); setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); setMenuItemAvailability(menu, MENU_BLOCK, false); setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); } final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_USER, user); intent.putExtras(extras); menu.removeGroup(MENU_GROUP_USER_EXTENSION); addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION); }
From source file:org.getlantern.firetweet.fragment.support.UserFragment.java
@Override public void onPrepareOptionsMenu(final Menu menu) { if (!shouldUseNativeMenu() || !menu.hasVisibleItems()) return;/* w w w . j a v a 2s . c o m*/ final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = getUser(); final Relationship relationship = mRelationship; if (twitter == null || user == null) return; final boolean isMyself = user.account_id == user.id; final MenuItem mentionItem = menu.findItem(MENU_MENTION); if (mentionItem != null) { mentionItem.setTitle( getString(R.string.mention_user_name, UserColorNameUtils.getDisplayName(getActivity(), user))); } Utils.setMenuItemAvailability(menu, MENU_MENTION, !isMyself); Utils.setMenuItemAvailability(menu, R.id.incoming_friendships, isMyself); // final MenuItem followItem = menu.findItem(MENU_FOLLOW); // followItem.setVisible(!isMyself); // final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself // && relationship != null; // followItem.setEnabled(shouldShowFollowItem); // if (shouldShowFollowItem) { // followItem.setTitle(isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request // : R.string.follow); // followItem.setIcon(isFollowing ? R.drawable.ic_action_cancel : R.drawable.ic_action_add); // } else { // followItem.setTitle(null); // followItem.setIcon(null); // } if (!isMyself && relationship != null) { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget()); setMenuItemAvailability(menu, MENU_BLOCK, true); setMenuItemAvailability(menu, MENU_MUTE_USER, true); final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (blockItem != null) { final boolean blocking = relationship.isSourceBlockingTarget(); ActionIconDrawable.setMenuHighlight(blockItem, new FiretweetMenuInfo(blocking)); blockItem.setTitle(blocking ? R.string.unblock : R.string.block); } final MenuItem muteItem = menu.findItem(MENU_MUTE_USER); if (muteItem != null) { final boolean muting = relationship.isSourceMutingTarget(); ActionIconDrawable.setMenuHighlight(muteItem, new FiretweetMenuInfo(muting)); muteItem.setTitle(muting ? R.string.unmute : R.string.mute); } final MenuItem filterItem = menu.findItem(MENU_ADD_TO_FILTER); if (filterItem != null) { final boolean filtering = Utils.isFilteringUser(getActivity(), user.id); ActionIconDrawable.setMenuHighlight(filterItem, new FiretweetMenuInfo(filtering)); filterItem.setTitle(filtering ? R.string.remove_from_filter : R.string.add_to_filter); } } else { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); setMenuItemAvailability(menu, MENU_BLOCK, false); setMenuItemAvailability(menu, MENU_MUTE_USER, false); setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); } setMenuItemAvailability(menu, R.id.muted_users, isMyself); setMenuItemAvailability(menu, R.id.blocked_users, isMyself); final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_USER, user); intent.putExtras(extras); menu.removeGroup(MENU_GROUP_USER_EXTENSION); addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION); }
From source file:org.mariotaku.twidere.fragment.UserFragment.java
@Override @UiThread/*www . j av a 2s . c om*/ public void onPrepareOptionsMenu(final Menu menu) { final AsyncTwitterWrapper twitter = mTwitterWrapper; final ParcelableUser user = getUser(); if (twitter == null || user == null) return; final boolean isMyself = user.account_key.maybeEquals(user.key); final MenuItem mentionItem = menu.findItem(R.id.mention); if (mentionItem != null) { final String displayName = UserColorNameManager.decideDisplayName(user.nickname, user.name, user.screen_name, mNameFirst); mentionItem.setTitle(getString(R.string.mention_user_name, displayName)); } MenuUtils.setMenuItemAvailability(menu, R.id.mention, !isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.incoming_friendships, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.saved_searches, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.scheduled_statuses, isMyself && MicroBlogAPIFactory .getOfficialKeyType(getActivity(), user.account_key) == ConsumerKeyType.TWEETDECK); MenuUtils.setMenuItemAvailability(menu, R.id.muted_users, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.blocked_users, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.block, !isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.mute_user, !isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.report_spam, !isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.enable_retweets, !isMyself); if (mAccount != null) { MenuUtils.setMenuItemAvailability(menu, R.id.add_to_list, TextUtils .equals(ParcelableAccount.Type.TWITTER, ParcelableAccountUtils.getAccountType(mAccount))); } else { MenuUtils.setMenuItemAvailability(menu, R.id.add_to_list, false); } final UserRelationship userRelationship = mRelationship; if (userRelationship != null) { final MenuItem filterItem = menu.findItem(R.id.add_to_filter); if (filterItem != null) { filterItem.setChecked(userRelationship.filtering); } if (isMyself) { MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, false); } else { MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, userRelationship.can_dm); MenuUtils.setMenuItemAvailability(menu, R.id.block, true); final MenuItem blockItem = menu.findItem(R.id.block); if (blockItem != null) { ActionIconDrawable.setMenuHighlight(blockItem, new TwidereMenuInfo(userRelationship.blocking)); blockItem.setTitle(userRelationship.blocking ? R.string.unblock : R.string.block); } final MenuItem muteItem = menu.findItem(R.id.mute_user); if (muteItem != null) { muteItem.setChecked(userRelationship.muting); } final MenuItem wantRetweetsItem = menu.findItem(R.id.enable_retweets); if (wantRetweetsItem != null) { wantRetweetsItem.setChecked(userRelationship.retweet_enabled); } } } else { MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, false); } final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_USER, user); intent.putExtras(extras); menu.removeGroup(MENU_GROUP_USER_EXTENSION); MenuUtils.addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION); final HeaderDrawerLayout drawer = mHeaderDrawerLayout; if (drawer != null) { final int offset = drawer.getPaddingTop() - drawer.getHeaderTop(); mPreviousActionBarItemIsDark = 0; mPreviousTabItemIsDark = 0; updateScrollOffset(offset); } }
From source file:org.getlantern.firetweet.util.Utils.java
public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status, final ParcelableCredentials account) { if (context == null || menu == null || status == null) return;/*from ww w.jav a2s . c om*/ final Resources resources = context.getResources(); final int retweetHighlight = resources.getColor(R.color.highlight_retweet); final int favoriteHighlight = resources.getColor(R.color.highlight_favorite); final boolean isMyRetweet = isMyRetweet(status); final MenuItem delete = menu.findItem(MENU_DELETE); if (delete != null) { delete.setVisible(status.account_id == status.user_id && !isMyRetweet); } final MenuItem retweet = menu.findItem(MENU_RETWEET); if (retweet != null) { retweet.setVisible(!status.user_is_protected || isMyRetweet); ActionIconDrawable.setMenuHighlight(retweet, new FiretweetMenuInfo(isMyRetweet, retweetHighlight)); retweet.setTitle(isMyRetweet ? R.string.cancel_retweet : R.string.retweet); } final MenuItem retweetSubItem = menu.findItem(R.id.retweet_submenu); if (retweetSubItem != null) { ActionIconDrawable.setMenuHighlight(retweetSubItem, new FiretweetMenuInfo(isMyRetweet, retweetHighlight)); } final MenuItem favorite = menu.findItem(MENU_FAVORITE); if (favorite != null) { ActionIconDrawable.setMenuHighlight(favorite, new FiretweetMenuInfo(status.is_favorite, favoriteHighlight)); favorite.setTitle(status.is_favorite ? R.string.unfavorite : R.string.favorite); } final MenuItem translate = menu.findItem(MENU_TRANSLATE); if (translate != null) { final boolean isOfficialKey = isOfficialCredentials(context, account); final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final boolean forcePrivateApis = prefs.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false); setMenuItemAvailability(menu, MENU_TRANSLATE, forcePrivateApis || isOfficialKey); } menu.removeGroup(MENU_GROUP_STATUS_EXTENSION); addIntentToMenuForExtension(context, menu, MENU_GROUP_STATUS_EXTENSION, INTENT_ACTION_EXTENSION_OPEN_STATUS, EXTRA_STATUS, EXTRA_STATUS_JSON, status); //final MenuItem shareItem = menu.findItem(R.id.share); //final ActionProvider shareProvider = MenuItemCompat.getActionProvider(shareItem); /* if (shareProvider instanceof SupportStatusShareProvider) { ((SupportStatusShareProvider) shareProvider).setStatus(status); } else if (shareProvider instanceof ShareActionProvider) { final Intent shareIntent = createStatusShareIntent(context, status); ((ShareActionProvider) shareProvider).setShareIntent(shareIntent); final Menu shareSubMenu = shareItem.getSubMenu(); final Intent shareIntent = createStatusShareIntent(context, status); shareSubMenu.removeGroup(MENU_GROUP_STATUS_SHARE); addIntentToMenu(context, shareSubMenu, shareIntent, MENU_GROUP_STATUS_SHARE); } */ }