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:com.kanedias.vanilla.lyrics.LyricsShowActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        switch (item.getItemId()) {
        case R.id.reload_option:
            // show only when loading is complete
            item.setVisible(mSwitcher.getDisplayedChild() == 1);
            continue;
        default://from   w  w  w  .  jav  a 2s.c om
            break;
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:de.aw.monma.mainscreen.ActivityMainScreen.java

@Override
public boolean onRecyclerItemLongClick(RecyclerView recyclerView, View view, int position, long id,
        int viewHolderLayoutID) {
    switch (viewHolderLayoutID) {
    case R.layout.reportlist_item:
        PopupMenu popUpMenu = new PopupMenu(this, view);
        Menu menu = popUpMenu.getMenu();
        popUpMenu.getMenuInflater().inflate(R.menu.context_fragment_report_selection, menu);
        for (int i = 0; i < menu.size(); i++) {
            Intent intent = new Intent();
            intent.putExtra(ID, id);// w  ww.  j  a v a 2 s.c  o m
            menu.getItem(i).setIntent(intent);
        }
        popUpMenu.setOnMenuItemClickListener(this);
        popUpMenu.show();
        return true;
    case R.layout.finanzuebersicht_item:
        DialogFragmentKontoEdit d = DialogFragmentKontoEdit.newInstance(new Account((int) id));
        d.show(getSupportFragmentManager(), null);
        return true;
    case R.layout.hbcipassport_item:
        final long mID = id;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.HBCIZugangDelete);
        builder.setMessage(R.string.HBCIZugangDeleteMsg);
        builder.setPositiveButton(getString(R.string.awlib_btnAccept), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                try {
                    MonMaPassport passport = new MonMaPassport(mID);
                    passport.delete(DBHelper.getInstance());
                } catch (GeschaeftsObjekt.LineNotFoundException e) {
                    //TODO Execption bearbeiten
                    e.printStackTrace();
                }
            }
        });
        builder.setNegativeButton(getString(R.string.awlib_btnCancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder.create().show();
        return true;
    default:
        return false;
    }
}

From source file:com.mobicage.rogerthat.NewsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        switch (item.getItemId()) {
        case R.id.saved:
            item.setVisible(newsStore != null && newsStore.countNewsPinnedItems(feedName) > 0);
            break;
        }//from  www.  ja v  a  2s . com
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void wrapMenuIcon(Context context, int backgroundColor, int popupBackgroundColor, Menu menu,
        int... excludeGroups) {
    final Resources resources = context.getResources();
    final int colorDark = resources.getColor(R.color.action_icon_dark);
    final int colorLight = resources.getColor(R.color.action_icon_light);
    final int itemColor = ColorUtils.getContrastYIQ(backgroundColor, colorDark, colorLight);
    final int popupItemColor = ColorUtils.getContrastYIQ(popupBackgroundColor, colorDark, colorLight);
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
        }/*from  ww w. j  a  va 2 s  .  c  o  m*/
        if (item.isVisible()) {
            k++;
        }
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java

private void onDrawerItemClicked(@IdRes final int item, boolean userClicked) {
    if (mDrawerItemSelected == item && userClicked) {
        mDrawerLayout.closeDrawer(mDrawerView);
        return;/*ww  w.  java 2 s  . c om*/
    }

    if (isItemAFragment(item)) {
        mDrawerItemSelected = item;
        // Animate if user clicked
        hideFragments(userClicked);

        Menu menu = mDrawerView.getMenu();
        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            menuItem.setChecked(menuItem.getItemId() == item);
        }
    }

    if (mDrawerLayout.isDrawerOpen(mDrawerView)) {
        mPending = new Runnable() {
            @Override
            public void run() {
                performDrawerItemSelection(item);
            }
        };
    } else {
        performDrawerItemSelection(item);
    }

    mDrawerLayout.closeDrawer(mDrawerView);
}

From source file:com.avapira.bobroreader.Bober.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean valToSetVisibility = !boardsDrawer.isDrawerOpen();
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setVisible(valToSetVisibility);
    }//from  w w w.jav a2  s . c om
    return true;
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);/*ww  w . jav  a 2  s . c  o  m*/
    boolean isOpenFromNotification = intent.getBooleanExtra("favorite", false);
    if (isOpenFromNotification) {
        GetSubscription();
        new getAllMangas().execute();
        NavigationView view = (NavigationView) findViewById(R.id.navigation_view);
        Menu menu = view.getMenu();
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            if (item.getItemId() == R.id.drawer_feeds) {
                savedMenuId = item.getItemId();
                item.setChecked(true);
            }
        }
    }
}

From source file:com.gigathinking.simpleapplock.AppListFragment.java

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    if (menu.size() == 0) {
        return false;
    }/*  w ww . j av a 2  s .  c  om*/
    String menu_selectt = allItemsChecked ? getString(R.string.select_none) : getString(R.string.select_all);
    menu.findItem(R.id.select_all).setTitle(menu_selectt);
    return true;
}

From source file:com.alainesp.fan.sanderson.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    staticRef = this;

    super.onCreate(savedInstanceState);
    DB.currentContext = this;
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);// ww w  . j a  va2s  .c o m

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu drawerMenu = navigationView.getMenu();
    // Create the hashtable
    reverseMenuText.clear();
    for (int i = 0; i < drawerMenu.size(); i++)
        reverseMenuText.put(drawerMenu.getItem(i).getTitle().toString(), i);
    navigationView.setNavigationItemSelectedListener(this);
    // 2 listeners to show the badges
    navigationView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View vv, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            setBadgesNumberUI();
        }
    });
    ((NavigationMenuView) navigationView.getChildAt(0))
            .addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    setBadgesNumberUI();
                }
            });

    // Select Summary at the beginning
    loadBadgeNumbers();
    // Try to load the state in which the app was
    if (savedInstanceState != null)
        app_state = savedInstanceState.getInt(APP_FRAGMENT_INDEX);
    else {
        Intent intent = getIntent();
        if (intent != null)
            app_state = intent.getIntExtra(APP_FRAGMENT_INDEX, -2);

        if (app_state == -2)
            app_state = APP_STATE_SUMMARY;
    }

    if (app_state == APP_STATE_ABOUT)
        onAboutClick(null);
    else
        navigateTo((app_state));
}

From source file:gov.wa.wsdot.android.wsdot.ui.ferries.departures.FerriesRouteSchedulesDayDeparturesActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem menuItem_Star = menu.add(0, MENU_ITEM_STAR, menu.size(), R.string.description_star);
    MenuItemCompat.setShowAsAction(menuItem_Star, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    if (mIsStarred) {
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, checked");
    } else {//from   w  w  w  .j  a  va2s  .  co m
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, not checked");
    }

    return super.onCreateOptionsMenu(menu);
}