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.app.blockydemo.ui.fragment.FormulaEditorFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    for (int index = 0; index < menu.size(); index++) {
        menu.getItem(index).setVisible(false);
    }//  w ww  .  jav  a  2 s.co  m

    getActivity().getActionBar().setDisplayShowTitleEnabled(true);
    getActivity().getActionBar().setTitle(getString(R.string.formula_editor_title));

    super.onPrepareOptionsMenu(menu);
}

From source file:net.named_data.accessmanager.DrawerFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // Remove option menu items when drawer is sliding out
    if (m_shouldHideOptionsMenu) {
        for (int i = 0; i < menu.size(); i++) {
            menu.getItem(i).setVisible(false);
        }//from   w ww  . j  a v  a  2  s . c  o m
    }

}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    ButterKnife.bind(this);

    db = new JumpDatabaseHelper(MainActivity.this);

    initToolbar();//from  w  ww  . java2  s  .  co  m

    setupDrawerLayout();

    progressBar.getIndeterminateDrawable().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_ATOP);

    categories = db.getAllCategories();

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    searchBox.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            toggleSearch(true);
            int position = temp.indexOf(adapter.getItem(i));
            Intent intent = new Intent(MainActivity.this, DetailActivity.class);
            intent.putExtra("manga", temp.get(position));
            startActivity(intent);
        }
    });

    searchBox.setOnClearListener(new CustomAutoCompleteTextView.OnClearListener() {

        @Override
        public void onClear() {
            toggleSearch(true);
        }
    });

    boolean isOpenFromNotification = getIntent().getBooleanExtra("favorite", false);

    if (savedInstanceState == null && !isOpenFromNotification) {
        GetHotMangas();
        new getAllMangas().execute();
    } else 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);
            }
        }
    } else {
        setTitle(savedInstanceState.getString("title"));
        mangas = savedInstanceState.getParcelableArrayList("list");
        if (mangas != null)
            temp = new ArrayList<>(mangas);
        adapter = new SearchAdapter(getApplicationContext(), R.layout.search_dropdown_item, mangas);
        searchBox.setAdapter(adapter);
        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() == savedInstanceState.getInt("menu")) {
                savedMenuId = savedInstanceState.getInt("menu");
                item.setChecked(true);
            }
        }
    }

}

From source file:net.kw.shrdlu.grtgtfs.Activities.MenuListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    final MenuInflater inflater = getMenuInflater();

    // This can be called multiple times, for difference activities, or the
    // action bar & nav drawer. So try process things only once, else the menus are doubled up.

    // Borrow this menu for a moment to expand the nav menu first.
    if (mDrawerItems.size() == 0) {
        inflater.inflate(R.menu.navdrawermenu, menu);
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            mDrawerItems.add(new NavDrawerItem(item.getIcon(), item.getTitle(), item.getItemId()));
        }//  w w w.  j a  va 2s .  c  o m
        mNavAdapter.notifyDataSetChanged();
        menu.clear();
    }

    inflater.inflate(R.menu.actionbarmenu, menu);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.meetingninja.csse.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean drawerOpen = drawerLayout.isDrawerOpen(leftDrawerList)
            || drawerLayout.isDrawerOpen(rightDrawerList);
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setVisible(!drawerOpen);
    }//from   w  w w . j  av a2 s .  co  m
    return super.onPrepareOptionsMenu(menu);
}

From source file:org.apache.cordova.navigationmenu.NavigationMenu.java

/**
 * Called when a message is sent to plugin.
 *
 * @param id            The message id//from  w  w  w.  j a  v a2s.  c o m
 * @param data          The message data
 * @return              Object to stop propagation or null
 */
public Object onMessage(String id, Object data) {
    if (id.equals("onCreateOptionsMenu")) {
        this.menuinitialized = true;
        Menu menu = (Menu) data;
        Object[] items = this.items.values().toArray();
        for (Object jsonObject : items) {
            JSONObject menuItem = (JSONObject) jsonObject;
            appendItem(menu, menuItem);
        }

        this.webView.sendJavascript("console.log('onCreateOptionsMenu');");
        return null;
    } else if (id.equals("onPrepareOptionsMenu")) {
        Menu menu = (Menu) data;
        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            int itemId = menuItem.getItemId();
            JSONObject itemDescription = this.items.get(itemId);
            boolean enabled = itemDescription.optBoolean("enabled", true);
            enableMenuItem(menuItem.setEnabled(enabled), enabled);
        }
    } else if (id.equals("onOptionsItemSelected")) {
        MenuItem menuItem = (MenuItem) data;
        int itemId = menuItem.getItemId();
        this.webView.sendJavascript("menu.optionItemClick && menu.optionItemClick(" + itemId + ");");
    }

    return null;
}

From source file:com.mishiranu.dashchan.ui.gallery.GalleryActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setVisible(false);
    }/*from w  w w  .  j  av a  2  s  .  c  o  m*/
    if (!galleryMode) {
        PagerUnit.OptionsMenuCapabilities capabilities = pagerUnit != null
                ? pagerUnit.obtainOptionsMenuCapabilities()
                : null;
        if (capabilities != null && capabilities.available) {
            menu.findItem(OPTIONS_MENU_SAVE).setVisible(capabilities.save);
            menu.findItem(OPTIONS_MENU_GALLERY).setVisible(!galleryWindow && instance.galleryItems.size() > 1);
            menu.findItem(OPTIONS_MENU_REFRESH).setVisible(capabilities.refresh);
            menu.findItem(OPTIONS_MENU_TECHNICAL_INFO).setVisible(capabilities.viewTechnicalInfo);
            menu.findItem(OPTIONS_MENU_SEARCH_IMAGE).setVisible(capabilities.searchImage);
            menu.findItem(OPTIONS_MENU_COPY_LINK).setVisible(true);
            menu.findItem(OPTIONS_MENU_NAVIGATE_POST)
                    .setVisible(allowNavigatePost && !scrollThread && capabilities.navigatePost);
            menu.findItem(OPTIONS_MENU_SHARE_LINK).setVisible(true);
            menu.findItem(OPTIONS_MENU_SHARE_FILE).setVisible(capabilities.shareFile);
        }
    } else {
        menu.findItem(OPTIONS_MENU_SELECT).setVisible(listUnit.areItemsSelectable());
    }
    actionMenuConfigurator.onAfterPrepareOptionsMenu(menu);
    return true;
}

From source file:it.gulch.linuxday.android.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Hide & disable primary (contextual) action items when the main menu is opened
    if (drawerLayout.isDrawerOpen(mainMenu)) {
        final int size = menu.size();
        for (int i = 0; i < size; ++i) {
            MenuItem item = menu.getItem(i);
            if ((item.getOrder() & 0xFFFF0000) == 0) {
                item.setVisible(false).setEnabled(false);
            }//from w  w  w .ja  va 2 s. co  m
        }
    }

    MenuItem refreshMenuItem = menu.findItem(R.id.refresh);

    boolean isRefreshing = refreshItem != null;
    Log.d(TAG, "isRefreshing: " + Boolean.toString(isRefreshing));
    refreshMenuItem.setEnabled(!isRefreshing);

    return super.onPrepareOptionsMenu(menu);
}

From source file:android.hawkencompanionapp.activities.BaseActivity.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.login, menu);
    final MenuItem menuItemSignOut = menu.findItem(R.id.action_sign_out);
    final MenuItem menuItemOfflineMode = menu.findItem(R.id.action_offline_mode);

    //Disable the About option if the current activity is the About activity
    if (this instanceof AboutActivity) {
        final MenuItem about = menu.findItem(R.id.action_about);
        final int len = menu.size();
        //Disable all menu items when the about activity is being shown.
        for (int i = 0; i < len; i++) {
            final MenuItem item = menu.getItem(i);
            item.setVisible(false);/*www.j a  v  a 2  s .  co  m*/
        }
    } else if (this instanceof ForgotPasswordActvity) { //Forgot Password activity is shown
        menuItemSignOut.setVisible(false);
        menuItemOfflineMode.setVisible(false);
    } else if (this instanceof LoginActivity) { //Login activity is shown
        menuItemSignOut.setVisible(false);
    } else if (this instanceof UserAccountMainActivity) {
        menuItemOfflineMode.setVisible(false);
    }

    if (mDisableSignOutOption) { //If the user is in offline mode
        menuItemSignOut.setVisible(false);
    }

    return true;
}

From source file:com.z299studio.pb.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(//from w w  w  .j av  a2  s .c o  m
            getResources().getBoolean(R.bool.hide_drawer) ? R.menu.menu_home_small : R.menu.menu_home_large,
            menu);
    for (int i = 0; i < menu.size(); ++i) {
        menu.getItem(i).getIcon().setColorFilter(C.ThemedColors[C.colorTextNormal], PorterDuff.Mode.SRC_ATOP);
    }
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    searchView.setQueryHint(getString(R.string.search));
    searchView.setOnQueryTextListener(this);
    return true;
}