List of usage examples for android.view SubMenu getItem
public MenuItem getItem(int index);
From source file:org.tasks.ui.MenuColorizer.java
/** Sets a color filter on all menu icons, including the overflow button (if it exists) */ private static void colorMenu(final Menu menu, final int color) { for (int i = 0, size = menu.size(); i < size; i++) { final MenuItem menuItem = menu.getItem(i); colorMenuItem(menuItem, color);//from w w w. ja va 2 s.c om if (menuItem.hasSubMenu()) { final SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), color); } } } }
From source file:org.solovyev.android.widget.menu.CustomPopupMenuHelper.java
static void tintMenuItem(@Nonnull MenuItemImpl item, @Nonnull ColorStateList tintColorStateList) { Drawable icon = item.getIcon();/*from w w w. j av a 2s.c o m*/ if (icon != null) { icon = DrawableCompat.wrap(icon); DrawableCompat.setTintList(icon, tintColorStateList); item.setIcon(icon); } if (item.hasSubMenu()) { final SubMenu subMenu = item.getSubMenu(); for (int i = 0; i < subMenu.size(); i++) { final MenuItem subItem = subMenu.getItem(i); if (subItem instanceof MenuItemImpl) { tintMenuItem((MenuItemImpl) subItem, tintColorStateList); } } } }
From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java
private void applyFontToSubMenu(MenuItem item) { SubMenu subMenu = item.getSubMenu(); if (subMenu != null && subMenu.size() > 0) { for (int i = 0; i < subMenu.size(); i++) { MenuItem subMenuItem = subMenu.getItem(i); applyFontToMenuItem(subMenuItem); }/*from w w w . j a v a2s . c o m*/ } }
From source file:org.randoomz.learnit.ui.MainActivity.java
@Override protected void onResume() { super.onResume(); subscribe = db.createQuery(Language.TABLE, Language.ALL_QUERY).map(Language.MAP) .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<Language>>() { @Override//from w ww. j a va 2 s . c o m public void call(List<Language> languages) { MainActivity.this.languages = languages; final MenuItem item = navigationView.getMenu().findItem(R.id.languages); final SubMenu subMenuLanguages = item.getSubMenu(); subMenuLanguages.clear(); for (int i = 0; i < languages.size(); i++) { subMenuLanguages.add(Menu.NONE, i, i, languages.get(i).language()).setCheckable(true); } onNavigationItemSelected(subMenuLanguages.getItem(currentPosition)); } }); }
From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java
private void updateAccounts() { final Menu menu = binding.navigation.getMenu(); final MenuItem libraries = menu.findItem(R.id.nav_libraries); final SubMenu subMenu = libraries.getSubMenu(); while (subMenu.size() > 0) { subMenu.removeItem(subMenu.getItem(0).getItemId()); }/* w ww. j a v a 2 s . com*/ final List<Account> accounts = getServer().getAccounts(); for (int index = 0; index < accounts.size(); index++) { final Account account = accounts.get(index); final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName()); if (account.getId().equals("local")) { menuItem.setIcon(R.drawable.ic_folder_24dp); } else { menuItem.setIcon(R.drawable.ic_cloud_24dp); } menuItem.setCheckable(true); } final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE, R.string.nav_addaccount); menuItem.setIcon(R.drawable.ic_add_24dp); for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) { final View child = binding.navigation.getChildAt(i); if (child != null && child instanceof ListView) { final ListView menuView = (ListView) child; final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter(); final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter(); wrapped.notifyDataSetChanged(); } } getServer().loadRecent(new LoadCallback<List<String>>() { @Override public void loaded(List<String> item) { final MenuItem recent = menu.findItem(R.id.nav_recent); if (recent != null) { recent.setVisible(!item.isEmpty()); } } @Override public void error(Throwable e) { GoogleAnalytics.trackException(e); } }); getServer().loadStarred(new LoadCallback<List<String>>() { @Override public void loaded(List<String> item) { final MenuItem starred = menu.findItem(R.id.nav_starred); if (starred != null) { starred.setVisible(!item.isEmpty()); } } @Override public void error(Throwable e) { GoogleAnalytics.trackException(e); } }); }
From source file:com.eugene.fithealthmaingit.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) { mNavItemId = savedInstanceState.getInt(NAV_ITEM_ID); isFirstFragmentAdded = savedInstanceState.getBoolean(FIRST_FRAGMENT_ADDED); } else {// w w w . j ava 2 s .c o m mNavItemId = R.id.nav_journal; } mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); // Set menu header text to User Name TextView mHeaderText = (TextView) findViewById(R.id.txtName); mHeaderText.setText(PreferenceManager.getDefaultSharedPreferences(this).getString(Globals.USER_NAME, "")); /** * Initiate NavigationView * Inflate Menu based on FitBit connection status */ NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav); if (PreferenceManager.getDefaultSharedPreferences(this).getString("FITBIT_ACCESS_TOKEN", "").equals("")) { mNavigationView.inflateMenu(R.menu.drawer); } else { mNavigationView.inflateMenu(R.menu.drawer_fitbit); } mNavigationView.getMenu().findItem(mNavItemId).setChecked(true); mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() != R.id.nav_settings) { mNavItemId = menuItem.getItemId(); switchFragment(menuItem.getItemId()); menuItem.setChecked(true); Fragment loading = new FragmentBlankLoading(); Bundle b = new Bundle(); b.putInt(NAV_ITEM_ID, mNavItemId); loading.setArguments(b); getSupportFragmentManager().beginTransaction().replace(R.id.container, loading).commit(); } else { startActivity(new Intent(MainActivity.this, UserInformationActivity.class)); } handleNavigationDrawer(); return false; } }); // Nav Menu Fonts Menu m = mNavigationView.getMenu(); for (int i = 0; i < m.size(); i++) { MenuItem mi = m.getItem(i); //for aapplying a font to subMenu ... SubMenu subMenu = mi.getSubMenu(); if (subMenu != null && subMenu.size() > 0) { for (int j = 0; j < subMenu.size(); j++) { MenuItem subMenuItem = subMenu.getItem(j); applyFontToMenuItem(subMenuItem); } } //the method we have create in activity applyFontToMenuItem(mi); } switchFragment(mNavItemId); /** * Handles Home Screen Widget * Search and Add */ Intent widgetIntent = this.getIntent(); if (widgetIntent != null) { if (widgetIntent.getAction() != null && savedInstanceState == null) { if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_SEARCH)) { // Post delay to allow the app to open and not interfere with animation final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().beginTransaction() .replace(R.id.containerSearch, new FragmentSearch()).addToBackStack(null) .commit(); } }, 100); } if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_ADD)) { widgetAdd(); } } } }
From source file:org.mariotaku.twidere.menu.AccountToggleProvider.java
@Override public void onPrepareSubMenu(final SubMenu subMenu) { subMenu.removeGroup(MENU_GROUP);// w w w . ja va 2 s . c om 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); for (int i = 0, j = subMenu.size(); i < j; i++) { final MenuItem item = subMenu.getItem(i); if (mAccounts[i].is_activated) { item.setChecked(true); } } }
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 . ja va 2 s . com * <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() { if (menu != null) { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); if (isActionButton(item)) { colorMenuItem(menu.getItem(i), iconsColor, iconsAlpha); } } } if (actionBarView == null) { return; } actionBarView.post(new Runnable() { @Override public void run() { 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); } else { colorMenuItem(menu.getItem(i), 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 || iconsAlpha != null) { colorOverflowMenuItem(overflowButton); } } }); }
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>/* w w w . java 2s . 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> */ 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: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>/*from w w w . ja v a2s . 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(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); } 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); } } }); }