Example usage for android.view Menu findItem

List of usage examples for android.view Menu findItem

Introduction

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

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:com.bodeme.easycloud.syncadapter.EnterCredentialsFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean ok = editUserName.getText().length() > 0 && editPassword.getText().length() > 0;

    // check host name
    if (Constants.OWNCLOUD_URL == null) {
        try {//  w ww . j av  a  2 s  .  c  om
            URI uri = new URI(URIUtils.sanitize(editURL.getText().toString()));
            if (StringUtils.isBlank(uri.getHost()))
                ok = false;
        } catch (URISyntaxException e) {
            ok = false;
        }
    }

    MenuItem item = menu.findItem(R.id.next);
    item.setEnabled(ok);
}

From source file:edu.cnu.PowerTutor.ui.PowerViewer.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.findItem(MENU_TOGGLE_COLLECTING).setTitle(collecting ? "Pause" : "Resume");
    return true;//from www. jav  a  2s  . com
}

From source file:de.stadtrallye.rallyesoft.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // If the nav drawer is open, hide action items related to the content view
    boolean drawerOpen = tabManager.isMenuOpen();
    boolean loggedIn = isLoggedIn();

    menu.findItem(R.id.menu_logout).setVisible(!drawerOpen && loggedIn);
    menu.findItem(R.id.menu_share_barcode).setVisible(!drawerOpen).setEnabled(loggedIn);
    //      menu.findItem(R.id.menu_reconnect).setVisible(!drawerOpen && model.canReconnect());

    return true;//ww w.ja  v a  2 s .com
}

From source file:br.liveo.ndrawer.ui.fragment.MainFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu, menu);

    //Select search item
    final MenuItem menuItem = menu.findItem(R.id.menu_search);
    menuItem.setVisible(true);//from  w  ww  . j  av  a  2 s .  c o m

    SearchView searchView = (SearchView) menuItem.getActionView();
    searchView.setQueryHint(this.getString(R.string.search));

    ((EditText) searchView.findViewById(R.id.search_src_text))
            .setHintTextColor(getResources().getColor(R.color.nliveo_white));
    searchView.setOnQueryTextListener(onQuerySearchView);

    //menu.findItem(R.id.menu_add).setVisible(true);

    mSearchCheck = false;
}

From source file:org.geometerplus.android.fbreader.network.NetworkLibraryActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    final NetworkTree tree = getCurrentTree();
    for (Action a : myOptionsMenuActions) {
        final MenuItem item = menu.findItem(a.Code);
        if (a.isVisible(tree)) {
            item.setVisible(true);/*w  w  w  . j  a  va 2  s .c o  m*/
            item.setEnabled(a.isEnabled(tree));
            item.setTitle(a.getOptionsLabel(tree));
        } else {
            item.setVisible(false);
        }
    }
    return true;
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
void onPrepareOptionsMenu(Menu menu) {
    if (appType == APP_TYPE_USER) {
        menu.findItem(R.id.system_apps).setVisible(true);
    } else if (appType == APP_TYPE_SYSTEM) {
        menu.findItem(R.id.user_apps).setVisible(true);
    }/*w  w w.j  a  va 2  s  . c o m*/

    if (type == PackageManager.GET_ACTIVITIES) {
        menu.findItem(R.id.activities).setChecked(true);
    } else if (type == PackageManager.GET_RECEIVERS) {
        menu.findItem(R.id.broadcasts).setChecked(true);
    } else if (type == PackageManager.GET_SERVICES) {
        menu.findItem(R.id.services).setChecked(true);
    } else if (type == PackageManager.GET_PROVIDERS) {
        menu.findItem(R.id.content_providers).setChecked(true);
    }

    menu.findItem(R.id.simple_filter_permission).setVisible(true);
    for (int i = 0; i < PROTECTION_PRESETS_MENU_IDS.length; i++) {
        if (protection == PROTECTION_PRESETS[i]) {
            menu.findItem(PROTECTION_PRESETS_MENU_IDS[i]).setChecked(true);
        }
    }
}

From source file:com.orange.ocara.ui.activity.ListAuditActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    switch (auditListAdapter.getSortCriteria().getType()) {
    case SITE:/*  ww w  .j a  va2 s. c o  m*/
        menu.findItem(com.orange.ocara.R.id.sort_by_site).setChecked(true);
        break;

    case DATE:
        menu.findItem(com.orange.ocara.R.id.sort_by_date).setChecked(true);
        break;

    default:
    case STATUS:
        menu.findItem(com.orange.ocara.R.id.sort_by_status).setChecked(true);
        break;
    }

    menu.findItem(com.orange.ocara.R.id.sort)
            .setIcon(auditListAdapter.getSortCriteria().isAscending() ? com.orange.ocara.R.drawable.ic_sort_asc
                    : com.orange.ocara.R.drawable.ic_sort_desc);

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.scrachx.foodfacts.checker.ui.main.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.main, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchMenuItem.getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override// w  w  w  .j a va  2s .c o  m
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);

            // Not replace if no search has been done (no switch of fragment)
            if (currentFragment instanceof SearchFragment) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.fragment_container, SearchFragment.newInstance(), SearchFragment.TAG)
                        .commit();
            }

            return true;
        }
    });

    return true;
}

From source file:com.afollestad.polar.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    if (!Config.get().changelogEnabled())
        menu.findItem(R.id.changelog).setVisible(false);

    MenuItem darkTheme = menu.findItem(R.id.darkTheme);
    if (!Config.get().allowThemeSwitching())
        darkTheme.setVisible(false);//from  ww w.  j ava  2 s . co  m
    else
        darkTheme.setChecked(darkTheme());

    MenuItem navDrawerMode = menu.findItem(R.id.navDrawerMode);
    if (Config.get().navDrawerModeAllowSwitch()) {
        navDrawerMode.setVisible(true);
        navDrawerMode.setChecked(Config.get().navDrawerModeEnabled());
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.app.uafeed.activity.EditFeedActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mTabHost.getCurrentTab() == 0) {
        menu.findItem(R.id.menu_add_filter).setVisible(false);
        menu.findItem(R.id.menu_search_feed).setVisible(true);
    } else {//w w w. j a  v a  2s  . c o m
        menu.findItem(R.id.menu_search_feed).setVisible(false);
        menu.findItem(R.id.menu_add_filter).setVisible(true);
    }

    return super.onPrepareOptionsMenu(menu);
}