List of usage examples for android.view SubMenu size
public int size();
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. c o m * <p> * <p>This should only be called after calling {@link #apply(Activity)}. It is useful for when * {@link MenuItem}s might be re-arranged due to an action view being collapsed or expanded.</p> */ public void reapply() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); if (isActionButton(item)) { colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha); } } if (actionBarView == null) { return; } actionBarView.post(() -> { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } else { colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha); } 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) { 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 v a 2 s . c o 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: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 . ja va 2s . c om * <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:org.getlantern.firetweet.menu.SupportAccountActionProvider.java
@Override public void onPrepareSubMenu(final SubMenu subMenu) { subMenu.removeGroup(MENU_GROUP);/*w w w . j a va 2s . co m*/ if (mAccounts == null) return; for (int i = 0, j = mAccounts.length; i < j; i++) { final ParcelableAccount account = mAccounts[i]; final MenuItem item = subMenu.add(MENU_GROUP, Menu.NONE, i, account.name); final Intent intent = new Intent(); intent.putExtra(EXTRA_ACCOUNT, account); item.setIntent(intent); } subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive); if (mAccountIds == null) return; for (int i = 0, j = subMenu.size(); i < j; i++) { final MenuItem item = subMenu.getItem(i); if (ArrayUtils.contains(mAccountIds, mAccounts[i].account_id)) { item.setChecked(true); } } }
From source file:hu.zelena.guide.MainActivity.java
@Override public void onBackPressed() { if (mDrawer.isDrawerOpen(GravityCompat.START)) { mDrawer.closeDrawers();//from www. ja v a 2s . c om } else { if (doubleBackToExitPressedOnce) { super.onBackPressed(); return; } Fragment fragment = new AboutFragment(); if (fragment != null) { firstFrag = true; FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); setTitle("MOBILTUDS GUIDE"); final Menu menu = nvDrawer.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); } } else { item.setChecked(false); } } } else { Intent i = new Intent(this, ErrorActivity.class); i.putExtra("error", "Nem sikerlt a HOME-FRAGMENT betltse. [Null object]"); startActivity(i); Log.e("MainActivity", "Error in creating fragment"); } this.doubleBackToExitPressedOnce = true; Toast.makeText(this, "Nyomja meg mgegyszer a kilpshez", Toast.LENGTH_SHORT).show(); new Handler().postDelayed(new Runnable() { @Override public void run() { doubleBackToExitPressedOnce = false; } }, 2000); } }
From source file:com.github.rubensousa.bottomsheetbuilder.adapter.BottomSheetAdapterBuilder.java
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor, int itemTextColor, int itemBackground, int tintColor) { List<BottomSheetItem> items = new ArrayList<>(); boolean addedSubMenu = false; for (int i = 0; i < mMenu.size(); i++) { MenuItem item = mMenu.getItem(i); if (item.isVisible()) { if (item.hasSubMenu()) { SubMenu subMenu = item.getSubMenu(); if (i != 0 && addedSubMenu) { if (mMode == BottomSheetBuilder.MODE_GRID) { throw new IllegalArgumentException( "MODE_GRID can't have submenus." + " Use MODE_LIST instead"); }/*w ww. ja va 2 s.c o m*/ items.add(new BottomSheetDivider(dividerBackground)); } CharSequence title = item.getTitle(); if (title != null && !title.equals("")) { items.add(new BottomSheetHeader(title.toString(), titleTextColor)); } for (int j = 0; j < subMenu.size(); j++) { MenuItem subItem = subMenu.getItem(j); if (subItem.isVisible()) { items.add(new BottomSheetMenuItem(subItem, itemTextColor, itemBackground, tintColor)); addedSubMenu = true; } } } else { items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor)); } } } return items; }
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); }//from w ww . j a v a2 s .co m } else { item.setChecked(false); } } }
From source file:com.money.manager.ex.account.AccountTransactionListFragment.java
private void selectCurrentStatus(Menu menu) { MenuItem toolbarItem = menu.findItem(R.id.menuTransactionStatusSelector); if (toolbarItem == null) return;//from www .j a v a 2 s . co m SubMenu subMenu = toolbarItem.getSubMenu(); for (int i = 0; i < subMenu.size(); i++) { MenuItem subItem = subMenu.getItem(i); int menuId = subItem.getItemId(); if (mFilter.transactionStatus.contains(menuId)) { subItem.setChecked(true); } } }
From source file:com.ruesga.rview.MainActivity.java
private void updateAccountCustomFilters() { // Remove all custom filters and re-add them final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu(); int myFiltersGroupIndex = menu.findGroupIndex(R.id.category_my_filters); MenuItem group = menu.getItem(myFiltersGroupIndex); SubMenu myFiltersSubMenu = group.getSubMenu(); int count = myFiltersSubMenu.size() - 1; for (int i = count; i >= 0; i--) { ((DrawerNavigationSubMenu) myFiltersSubMenu).removeItemAt(i); }//from w w w. j a v a 2 s . c o m mCustomFilters = Preferences.getAccountCustomFilters(this, mAccount); if (mCustomFilters != null) { int i = 0; for (CustomFilter filter : mCustomFilters) { int id = MY_FILTERS_GROUP_BASE_ID + i; String title = filter.mName + DrawerNavigationView.SEPARATOR + filter.mQuery.toString() + DrawerNavigationView.SEPARATOR + "ic_close"; MenuItem item = myFiltersSubMenu.add(group.getGroupId(), id, Menu.NONE, title); item.setIcon(R.drawable.ic_filter); item.setCheckable(true); i++; } } menu.setGroupVisible(R.id.category_my_filters, !mModel.isAccountExpanded && mCustomFilters != null && !mCustomFilters.isEmpty()); mBinding.drawerNavigationView.setCheckedItem(mModel.currentNavigationItemId); }
From source file:com.ruesga.rview.MainActivity.java
private void updateAccountsDrawerInfo() { // Remove all accounts and re-add them final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu(); int otherAccountGroupIndex = menu.findGroupIndex(R.id.category_other_accounts); MenuItem group = menu.getItem(otherAccountGroupIndex); SubMenu otherAccountsSubMenu = group.getSubMenu(); int count = otherAccountsSubMenu.size() - 1; for (int i = count; i > 0; i--) { ((DrawerNavigationSubMenu) otherAccountsSubMenu).removeItemAt(i); }/* w w w . j a v a 2 s . co m*/ int i = 0; for (Account account : mAccounts) { // Current account if (mAccount.isSameAs(account)) { i++; continue; } int id = OTHER_ACCOUNTS_GROUP_BASE_ID + i; String title = account.getAccountDisplayName() + DrawerNavigationView.SEPARATOR + account.getRepositoryDisplayName() + DrawerNavigationView.SEPARATOR + "ic_delete" + DrawerNavigationView.SEPARATOR + "false"; MenuItem item = otherAccountsSubMenu.add(group.getGroupId(), id, Menu.NONE, title); PicassoHelper.bindAvatar(this, PicassoHelper.getPicassoClient(this), account, account.mAccount, item, PicassoHelper.getDefaultAvatar(this, R.color.primaryDarkForeground)); i++; } if (mAccount != null) { updateAccountStatus(); } }