List of usage examples for android.view Menu findItem
public MenuItem findItem(int id);
From source file:com.hichinaschool.flashcards.anki.DeckPicker.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { boolean sdCardAvailable = AnkiDroidApp.isSdCardMounted(); if (mFragmented) { menu.findItem(MENU_SYNC).setEnabled(sdCardAvailable); menu.findItem(MENU_ADD_NOTE).setEnabled(sdCardAvailable); menu.findItem(MENU_STATISTICS).setEnabled(sdCardAvailable); menu.findItem(MENU_CARDBROWSER).setEnabled(sdCardAvailable); }/* w w w . j a v a 2 s. c o m*/ // menu.findItem(MENU_CREATE_DECK).setEnabled(sdCardAvailable); // menu.findItem(MENU_CREATE_DYNAMIC_DECK).setEnabled(sdCardAvailable); // menu.findItem(CHECK_DATABASE).setEnabled(sdCardAvailable); return true; }
From source file:com.amaze.carbonfilemanager.activities.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem s = menu.findItem(R.id.view); MenuItem search = menu.findItem(R.id.search); MenuItem paste = menu.findItem(R.id.paste); String fragmentName;//from w ww . ja v a2 s . c o m Fragment fragment; try { fragment = getSupportFragmentManager().findFragmentById(R.id.content_frame); fragmentName = fragment.getClass().getName(); } catch (Exception e) { return true; } if (fragmentName.contains("TabFragment")) { setActionBarTitle("Amaze"); if (useGridView) { s.setTitle(getResources().getString(R.string.gridview)); } else { s.setTitle(getResources().getString(R.string.listview)); } try { TabFragment tabFragment = (TabFragment) fragment; MainFragment ma = ((MainFragment) tabFragment.getTab()); if (ma.IS_LIST) s.setTitle(R.string.gridview); else s.setTitle(R.string.listview); updatePath(ma.CURRENT_PATH, ma.results, ma.openMode, ma.folder_count, ma.file_count); } catch (Exception e) { } initiatebbar(); if (SDK_INT >= 21) toolbar.setElevation(0); invalidatePasteButton(paste); search.setVisible(true); if (indicator_layout != null) indicator_layout.setVisibility(View.VISIBLE); menu.findItem(R.id.search).setVisible(true); menu.findItem(R.id.home).setVisible(true); menu.findItem(R.id.history).setVisible(true); menu.findItem(R.id.sethome).setVisible(true); menu.findItem(R.id.sort).setVisible(true); if (showHidden) menu.findItem(R.id.hiddenitems).setVisible(true); menu.findItem(R.id.view).setVisible(true); menu.findItem(R.id.extract).setVisible(false); invalidatePasteButton(menu.findItem(R.id.paste)); findViewById(R.id.buttonbarframe).setVisibility(View.VISIBLE); } else if (fragmentName.contains("AppsList") || fragmentName.contains("ProcessViewer") || fragmentName.contains(FTPServerFragment.class.getName())) { appBarLayout.setExpanded(true); menu.findItem(R.id.sethome).setVisible(false); if (indicator_layout != null) indicator_layout.setVisibility(View.GONE); findViewById(R.id.buttonbarframe).setVisibility(View.GONE); menu.findItem(R.id.search).setVisible(false); menu.findItem(R.id.home).setVisible(false); menu.findItem(R.id.history).setVisible(false); menu.findItem(R.id.extract).setVisible(false); if (fragmentName.contains("ProcessViewer")) menu.findItem(R.id.sort).setVisible(false); else { menu.findItem(R.id.dsort).setVisible(false); menu.findItem(R.id.sortby).setVisible(false); } menu.findItem(R.id.hiddenitems).setVisible(false); menu.findItem(R.id.view).setVisible(false); menu.findItem(R.id.paste).setVisible(false); } else if (fragmentName.contains("ZipViewer")) { menu.findItem(R.id.sethome).setVisible(false); if (indicator_layout != null) indicator_layout.setVisibility(View.GONE); TextView textView = (TextView) mainActivity.pathbar.findViewById(R.id.fullpath); pathbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); menu.findItem(R.id.search).setVisible(false); menu.findItem(R.id.home).setVisible(false); menu.findItem(R.id.history).setVisible(false); menu.findItem(R.id.sort).setVisible(false); menu.findItem(R.id.hiddenitems).setVisible(false); menu.findItem(R.id.view).setVisible(false); menu.findItem(R.id.paste).setVisible(false); menu.findItem(R.id.extract).setVisible(true); } return super.onPrepareOptionsMenu(menu); }
From source file:com.ichi2.anki2.Reviewer.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { Resources res = getResources(); MenuItem item = menu.findItem(MENU_MARK); if (mCurrentCard != null && mCurrentCard.note().hasTag("marked")) { item.setTitle(R.string.menu_unmark_card); item.setIcon(R.drawable.ic_menu_marked); } else {/* ww w. j a va 2 s. c o m*/ item.setTitle(R.string.menu_mark_card); item.setIcon(R.drawable.ic_menu_mark); } item = menu.findItem(MENU_UNDO); if (AnkiDroidApp.colIsOpen() && AnkiDroidApp.getCol().undoAvailable()) { item.setEnabled(true); item.setIcon(R.drawable.ic_menu_revert); } else { item.setEnabled(false); item.setIcon(R.drawable.ic_menu_revert_disabled); } item = menu.findItem(MENU_SEARCH); if (item != null) { item.setTitle(clipboardHasText() ? Lookup.getSearchStringTitle() : res.getString(R.string.menu_select)); } return true; }
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 w ww .j ava 2 s.co 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.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 w w w. ja v a 2s. 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); } */ }
From source file:com.lgallardo.qbittorrentclient.RefreshListener.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { altSpeedLimitsMenuItem = menu.findItem(R.id.action_toggle_alternative_rate); return super.onPrepareOptionsMenu(menu); }