Example usage for android.view Menu size

List of usage examples for android.view Menu size

Introduction

In this page you can find the example usage for android.view Menu size.

Prototype

public int size();

Source Link

Document

Get the number of items in the menu.

Usage

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 w w  . j  ava 2 s . 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:com.jefftharris.passwdsafe.FileListNavDrawerFragment.java

/**
 * Update drawer for the fragments displayed in the activity
 *///from  w w w .  j  av  a  2 s.c o m
public void updateView(Mode mode) {
    boolean openDrawer = false;
    NavMenuItem selNavItem = null;
    switch (mode) {
    case INIT: {
        break;
    }
    case ABOUT: {
        selNavItem = NavMenuItem.ABOUT;
        break;
    }
    case FILES: {
        // If the user hasn't 'learned' about the drawer, open it
        openDrawer = shouldOpenDrawer();
        selNavItem = NavMenuItem.FILES;
        break;
    }
    case PREFERENCES: {
        selNavItem = NavMenuItem.PREFERENCES;
        break;
    }
    }

    updateDrawerToggle(true, 0);

    Menu menu = getNavView().getMenu();
    for (int i = 0; i < menu.size(); ++i) {
        MenuItem item = menu.getItem(i);
        int itemId = item.getItemId();
        if (selNavItem == null) {
            item.setChecked(false);
        } else if (selNavItem.itsMenuId == itemId) {
            item.setChecked(true);
        }
    }
    itsSelNavItem = selNavItem;

    openDrawer(openDrawer);
}

From source file:com.lithidsw.wallbox.app.wallsnap.WallpaperFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (menu.size() > 0) {
        if (!simpleFirstRun) {
            if (!prefs.getBoolean(C.PREF_WALLPAPER_CHECK_SAVE_SORT, false)) {
                prefs.edit().putInt(C.PREF_WALLPAPER_CURRENT_SORT, 0);
            }/*ww  w. j a va2  s  .  com*/
            if (!prefs.getBoolean(C.PREF_WALLPAPER_FIRST_RUN_MAIN, false)) {
                runReload();
                prefs.edit().putBoolean(C.PREF_WALLPAPER_FIRST_RUN_MAIN, true).commit();
            } else {
                runReload();
            }
            simpleFirstRun = true;
        }
    }
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.vrem.wifianalyzer.navigation.NavigationMenuViewTest.java

@Test
public void testNavigationMenuView() throws Exception {
    // execute/*from   www.j a v a2  s . c  o  m*/
    final Menu menu = navigationView.getMenu();
    // validate
    assertEquals(NavigationMenu.values().length, menu.size());
    IterableUtils.forEach(EnumUtils.values(NavigationGroup.class), new Closure<NavigationGroup>() {
        @Override
        public void execute(final NavigationGroup navigationGroup) {
            IterableUtils.forEach(navigationGroup.getNavigationMenus(), new Closure<NavigationMenu>() {
                @Override
                public void execute(NavigationMenu navigationMenu) {
                    MenuItem actual = menu.getItem(navigationMenu.ordinal());
                    assertEquals(navigationGroup.ordinal(), actual.getGroupId());
                    assertEquals(mainActivity.getResources().getString(navigationMenu.getTitle()),
                            actual.getTitle());
                    assertEquals(navigationMenu.ordinal(), actual.getItemId());
                    assertEquals(navigationMenu.ordinal(), actual.getOrder());
                }
            });
        }
    });
}

From source file:com.android.screenspeak.contextmenu.ListMenuManager.java

private CharSequence[] getItemsFromMenu(Menu menu) {
    int size = menu.size();
    List<CharSequence> items = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        MenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled() && item.isVisible()) {
            items.add(item.getTitle());//from  w  w  w.  j a v  a 2  s.c o  m
        }
    }

    return items.toArray(new CharSequence[items.size()]);
}

From source file:org.chromium.chrome.browser.preferences.Preferences.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (menu.size() == 1) {
        MenuItem item = menu.getItem(0);
        if (item.getIcon() != null)
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }/* w w  w.j  a va 2s.c om*/
    return super.onPrepareOptionsMenu(menu);
}

From source file:tm.alashow.datmusic.ui.activity.BaseActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++)
        menu.getItem(i).setVisible(!shouldGoInvisible);
    return super.onPrepareOptionsMenu(menu);
}

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();//from   w w  w.  j av a  2s . c  om
            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.nextgis.maplibui.fragment.BottomToolbar.java

@Override
public void inflateMenu(@MenuRes int resId) {
    super.inflateMenu(resId);
    Menu menu = getMenu();
    MenuItem item = menu.getItem(0);
    int size = item.getIcon().getIntrinsicWidth() + ControlHelper.dpToPx(30, getResources());
    int width = getWidth();

    for (int i = 0; i < menu.size(); i++) {
        item = menu.getItem(i);/*ww  w . j av a 2  s. co m*/
        if (size * (i + 2) < width)
            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        else
            break;
    }
}

From source file:me.abhrajit.hackernewsreader.MainActivity.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu menu = navigationView.getMenu();
    int selected = -1;
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isChecked()) {
            selected = i;//from w w w  .  j  av  a2 s  .  c o  m
            break;
        }
    }
    savedInstanceState.putInt(getString(R.string.nav_Selected), selected);
    super.onSaveInstanceState(savedInstanceState);
}