List of usage examples for android.view MenuItem getSubMenu
public SubMenu getSubMenu();
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor, final int highlightColor, final Mode mode, final int... excludedGroups) { for (int i = 0, j = menu.size(); i < j; i++) { final MenuItem item = menu.getItem(i); final Drawable icon = item.getIcon(); final ContextMenuInfo info = item.getMenuInfo(); if (icon != null && !ArrayUtils.contains(excludedGroups, item.getGroupId())) { icon.mutate();/* w ww .jav a2s .c o m*/ if (info instanceof TwidereMenuInfo) { final TwidereMenuInfo sInfo = (TwidereMenuInfo) info; icon.setColorFilter(sInfo.isHighlight() ? sInfo.getHighlightColor(highlightColor) : color, mode); } else { icon.setColorFilter(color, mode); } } if (item.hasSubMenu()) { // SubMenu item is always in popup applyColorFilterToMenuIcon(item.getSubMenu(), popupColor, popupColor, highlightColor, mode, excludedGroups); } } }
From source file:de.kuschku.util.ui.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>//from w ww.j a va2 s .co m * <p> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> */ public void apply(Activity activity) { apply(); actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(() -> { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } }); }
From source file:org.getlantern.firetweet.util.ThemeUtils.java
public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor, final int highlightColor, final Mode mode, final int... excludedGroups) { for (int i = 0, j = menu.size(); i < j; i++) { final MenuItem item = menu.getItem(i); final Drawable icon = item.getIcon(); final ContextMenuInfo info = item.getMenuInfo(); if (icon != null && !ArrayUtils.contains(excludedGroups, item.getGroupId())) { icon.mutate();/*w ww . j a v a2s . c o m*/ if (info instanceof FiretweetMenuInfo) { final FiretweetMenuInfo sInfo = (FiretweetMenuInfo) info; icon.setColorFilter(sInfo.isHighlight() ? sInfo.getHighlightColor(highlightColor) : color, mode); } else { icon.setColorFilter(color, mode); } } if (item.hasSubMenu()) { // SubMenu item is always in popup applyColorFilterToMenuIcon(item.getSubMenu(), popupColor, popupColor, highlightColor, mode, excludedGroups); } } }
From source file:com.weebly.opus1269.copyeverywhere.ui.shared.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/* www. ja v a 2 s.com*/ * <p/> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p/> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> * * @param activity the activity to apply the menu tinting on. */ public void apply(final Activity activity) { if (forceIcons) { forceMenuIcons(menu); } for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); colorMenuItem(item, menuItemIconColor, menuItemIconAlpha); if (reApplyOnChange) { View view = item.getActionView(); if (view != null) { if (item instanceof MenuItemImpl) { ((MenuItemImpl) item) .setSupportOnActionExpandListener(new SupportActionExpandListener(this)); } else { item.setOnActionExpandListener(new NativeActionExpandListener(this)); } } } } actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } } }); }
From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/*w w w . j a va 2 s .com*/ * <p/> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p/> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> * * @param activity the activity to apply the menu tinting on. */ public void apply(final Activity activity) { if (forceIcons) { forceMenuIcons(menu); } for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); colorMenuItem(item, menuItemIconColor, menuItemIconAlpha); if (reApplyOnChange) { View view = item.getActionView(); if (view != null) { if (item instanceof MenuItemImpl) { ((MenuItemImpl) item) .setSupportOnActionExpandListener(new SupportActionExpandListener(this)); } else { item.setOnActionExpandListener(new NativeActionExpandListener(this)); } } } } actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(LOG_TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } } }); }
From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/*from w w w .j a va2 s . co m*/ * <p> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> * * @param activity the activity to apply the menu tinting on. */ public void apply(final Activity activity) { if (menu != null) { if (forceIcons) { forceMenuIcons(menu); } for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); colorMenuItem(item, iconsColor, iconsAlpha); if (reApplyOnChange) { View view = item.getActionView(); if (view != null) { if (item instanceof MenuItemImpl) { ((MenuItemImpl) item) .setSupportOnActionExpandListener(new SupportActionExpandListener(this)); } else { item.setOnActionExpandListener(new NativeActionExpandListener(this)); } } } } } actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0; i < actionBarView.getChildCount(); i++) { final View v = actionBarView.getChildAt(i); //Step 1 : Changing the color of back button (or open drawer button). if (v instanceof ImageButton) { //Action Bar back button ((ImageButton) v).getDrawable() .setColorFilter(new PorterDuffColorFilter(iconsColor, PorterDuff.Mode.SRC_ATOP)); } } if (menu != null) { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, iconsColor, iconsAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), iconsColor, iconsAlpha); } } } if (iconsColor != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } } } }); }
From source file:com.adnanbal.fxdedektifi.forex.presentation.view.activity.SignalsActivity.java
private void uncheckAllMenuItems(NavigationView navigationView) { final Menu menu = navigationView.getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (item.hasSubMenu()) { SubMenu subMenu = item.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { MenuItem subMenuItem = subMenu.getItem(j); subMenuItem.setChecked(false); }// w ww . jav a2 s . c om } else { item.setChecked(false); } } }
From source file:com.github.kanata3249.ffxieq.android.EquipmentSelectorActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item; item = menu.findItem(R.id.OrderByName); if (item != null) { if (mOrderByName) item.setTitle(getString(R.string.OrderByLevel)); else/*ww w .j ava 2 s . c o m*/ item.setTitle(getString(R.string.OrderByName)); } EquipmentListView elv; item = menu.findItem(R.id.FilterByType); SubMenu submenu = item.getSubMenu(); submenu.removeGroup(R.id.FilterByType); elv = (EquipmentListView) findViewById(R.id.ListView); if (elv != null) { String types[] = elv.getAvailableWeaponTypes(); if (types == null || types.length == 1) { item.setEnabled(false); } else { item.setEnabled(true); submenu.add(R.id.FilterByType, -1, Menu.NONE, getString(R.string.ResetFilterByType)); for (int i = 0; i < types.length; i++) { submenu.add(R.id.FilterByType, i, Menu.NONE, types[i]); } } } return super.onPrepareOptionsMenu(menu); }
From source file:com.github.kanata3249.ffxieq.android.AugmentSelectorActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item; item = menu.findItem(R.id.OrderByName); if (item != null) { if (mOrderByName) item.setTitle(getString(R.string.OrderByLevel)); else//from w w w . j av a 2s.co m item.setTitle(getString(R.string.OrderByName)); } AugmentListView lv; item = menu.findItem(R.id.FilterByType); SubMenu submenu = item.getSubMenu(); submenu.removeGroup(R.id.FilterByType); lv = (AugmentListView) findViewById(R.id.ListView); if (lv != null) { String types[] = lv.getAvailableWeaponTypes(); if (types == null || types.length == 1) { item.setEnabled(false); } else { item.setEnabled(true); submenu.add(R.id.FilterByType, -1, Menu.NONE, getString(R.string.ResetFilterByType)); for (int i = 0; i < types.length; i++) { submenu.add(R.id.FilterByType, i, Menu.NONE, types[i]); } } } return super.onPrepareOptionsMenu(menu); }
From source file:org.thbz.hanguldrill.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_activity_actions, menu); try {/*w ww .j a v a 2 s.com*/ MenuItem configListItem = menu.findItem(R.id.action_configlist); String[] configIds = Settings.ConfigManager.getAllConfigIds(this); if (configListItem.hasSubMenu() && configIds.length > 0) { SubMenu configMenu = configListItem.getSubMenu(); if (configMenu == null) { if (BuildConfig.DEBUG) Log.d(TAG, "configMenu = null"); } else { // On ajoute une entre pour chacune des configurations existantes for (int i = 0; i < configIds.length; i++) { String configId = configIds[i]; Settings.Configuration config = Settings.ConfigManager.getConfigFromId(this, configId); String name = config.getName(this); configMenu.add(Menu.NONE, START_MENUITEM_ID + i, i, name); } } // Set configMenu title try { Settings.Configuration lastSelectedConfig = Settings.ConfigManager.getLastSelectedConfig(this); if (lastSelectedConfig != null) { String configName = lastSelectedConfig.getName(this); if (configName != null) { if (configName.length() > 15) configName = configName.substring(0, 13) + "\u2026"; configListItem.setTitle(configName); } } } catch (ClassCastException exc) { toastError("Exception : " + exc.getMessage()); } } } catch (InternalException exc) { if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Log.e(TAG, "Erreur interne", exc); } return super.onCreateOptionsMenu(menu); }