Example usage for android.view Menu getItem

List of usage examples for android.view Menu getItem

Introduction

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

Prototype

public MenuItem getItem(int index);

Source Link

Document

Gets the menu item at the given index.

Usage

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 a 2s.c om*/
 * @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.andybotting.tubechaser.activity.StationDetail.java

/**
 * Menu opened//from  w  w  w  . j  a va  2s  .  co  m
 */
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    // Ensure the 'Favourite' menu item has the correct text
    menu.getItem(MENU_STAR).setTitle((mStarred ? "Unfavourite" : "Favourite"));
    return super.onMenuOpened(featureId, menu);
}

From source file:com.fastbootmobile.encore.app.AlbumActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.album, menu);

    // Keep in tune with the XML!
    final ProviderAggregator aggregator = ProviderAggregator.getDefault();
    final Runnable updateMenuArtist = new Runnable() {
        @Override/*from  w  ww  .  jav a  2s.c  o m*/
        public void run() {
            String artistRef = mActiveFragment.getArtist();
            MenuItem item = menu.getItem(2);

            if (artistRef != null) {
                final Artist artist = aggregator.retrieveArtist(artistRef,
                        mActiveFragment.getAlbum().getProvider());
                if (artist != null) {
                    item.setTitle(getString(R.string.more_from, artist.getName()));
                    item.setVisible(true);
                }
            } else {
                // We don't have the tracks for that album yet, try again.
                mHandler.postDelayed(this, 1000);
                item.setVisible(false);
            }
        }
    };
    updateMenuArtist.run();

    return true;
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(//ww  w .j a v a  2  s.co 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;
}

From source file:com.andybotting.tramhunter.activity.StopDetailsActivity.java

/**
 * Overide the onMenuOpened method to allow us to dynamically set the menu item
 * title on open./*from w w  w .  jav  a2 s .c o  m*/
 */
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    boolean isFavourite = mFavouriteList.isFavourite(new Favourite(mStop, mRoute));
    menu.getItem(MENU_ITEM_FAVOURITE).setTitle(isFavourite ? "Unfavourite" : "Favourite");
    return super.onMenuOpened(featureId, menu);
}

From source file:com.monkey.entonado.MainActivity.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.main, menu);
    menu.getItem(0).setOnMenuItemClickListener(this);
    return true;/*from w  ww  .jav  a2s  .  co m*/
}

From source file:com.irccloud.android.activity.BaseActivity.java

public void setMenuColorFilter(final Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        Drawable d = menuItem.getIcon();
        if (d != null) {
            d.mutate();//from w w w  .  jav a  2 s  .  c  o  m
            d.setColorFilter(ColorScheme.getInstance().navBarSubheadingColor, PorterDuff.Mode.SRC_ATOP);
        }
    }
}

From source file:com.dm.material.dashboard.candybar.activities.CandyBarMainActivity.java

private void setFragment(Fragment fragment) {
    clearBackStack();//from  w w  w. ja v a2s .c o  m

    FragmentTransaction ft = mFragManager.beginTransaction().replace(R.id.container, fragment, mFragmentTag);
    try {
        ft.commit();
    } catch (Exception e) {
        ft.commitAllowingStateLoss();
    }

    Menu menu = mNavigationView.getMenu();
    menu.getItem(mPosition).setChecked(true);
    mToolbarTitle.setText(menu.getItem(mPosition).getTitle());
}

From source file:net.zorgblub.typhon.fragment.CatalogFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    Option<Feed> feed = adapter.getFeed();

    boolean searchEnabled = !isEmpty(feed.flatMap(Feed::getSearchLink));

    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);

        boolean enabled;

        switch (item.getItemId()) {

        case R.id.search:
            enabled = searchEnabled;//from w w  w  .j a  va2  s.  c o  m
            break;
        default:
            enabled = true;
        }

        item.setEnabled(enabled);
        item.setVisible(enabled);
    }

    LOG.debug("Adapter has feed: " + adapter.getFeed());
}

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);
            }// www . j a  v a  2 s  . c om
        }
    }

    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);
}