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:gov.wa.wsdot.android.wsdot.ui.TrafficMapActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();/*from  ww w.  ja  v a 2 s. c  om*/
    getMenuInflater().inflate(R.menu.traffic, menu);

    if (showCameras) {
        menu.getItem(0).setTitle("Hide Cameras");
    } else {
        menu.getItem(0).setTitle("Show Cameras");
    }

    /**
     * Check if current location is within a lat/lon bounding box surrounding
     * the greater Seattle area.
     */
    try {
        LatLng center = map.getCameraPosition().target;

        if (inPolygon(seattleArea, center.latitude, center.longitude)) {
            MenuItem menuItem_Alerts = menu.add(0, MENU_ITEM_SEATTLE_ALERTS, menu.size(), "Seattle Alerts")
                    .setIcon(R.drawable.ic_menu_alerts);

            MenuItemCompat.setShowAsAction(menuItem_Alerts,
                    MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);

            MenuItem menuItem_Lanes = menu.add(0, MENU_ITEM_EXPRESS_LANES, menu.size(), "Express Lanes");
            MenuItemCompat.setShowAsAction(menuItem_Lanes, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        }

    } catch (NullPointerException e) {
        Log.e(TAG, "Error getting LatLng center");
    }

    return super.onPrepareOptionsMenu(menu);
}

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 {//  w  w  w.  jav a 2  s  .c  o  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);
}

From source file:hu.zelena.guide.MainActivity.java

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
        mDrawer.closeDrawers();/*from w w w  . j av  a2 s .  c  o  m*/
    } else {

        if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }

        Fragment fragment = new AboutFragment();
        if (fragment != null) {
            firstFrag = true;
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
            setTitle("MOBILTUDS GUIDE");

            final Menu menu = nvDrawer.getMenu();
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                if (item.hasSubMenu()) {
                    SubMenu subMenu = item.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        subMenuItem.setChecked(false);
                    }
                } else {
                    item.setChecked(false);
                }
            }
        } else {
            Intent i = new Intent(this, ErrorActivity.class);
            i.putExtra("error", "Nem sikerlt a HOME-FRAGMENT betltse. [Null object]");
            startActivity(i);

            Log.e("MainActivity", "Error in creating fragment");
        }
        this.doubleBackToExitPressedOnce = true;
        Toast.makeText(this, "Nyomja meg mgegyszer a kilpshez", Toast.LENGTH_SHORT).show();

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                doubleBackToExitPressedOnce = false;
            }
        }, 2000);
    }
}

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

/**
 * Set the badge number to all menu items visible
 *///w ww. jav  a  2s  .c o  m
private static void setBadgesNumberUI() {
    if (navigationView != null) {
        NavigationMenuView v = (NavigationMenuView) navigationView.getChildAt(0);
        Menu drawerMenu = navigationView.getMenu();

        if (v != null)
            // Iterate all children
            for (int childIndex = 0; childIndex < v.getChildCount(); childIndex++) {
                View v1 = v.getChildAt(childIndex);
                if (v1 instanceof NavigationMenuItemView) {
                    TextView mTextView = (TextView) ((NavigationMenuItemView) v1).getChildAt(0);
                    if (mTextView != null) {
                        // Get the menu index
                        Integer menuIndex = reverseMenuText.get(mTextView.getText().toString());
                        if (menuIndex != null && menuIndex < badgeNumbers.length) {
                            Drawable numberText = null;
                            if (badgeNumbers[menuIndex] > 0) {
                                int height = mTextView.getHeight();
                                numberText = new TextDrawable(badgeNumbers[menuIndex], mTextView.getTextSize(),
                                        mTextView.getCurrentTextColor(), height);
                                numberText.setBounds(0, 0, height, height);
                            }

                            // Similar to NavigationMenuItemView.setIcon
                            Drawable icon = drawerMenu.getItem(menuIndex).getIcon();
                            Drawable.ConstantState state = icon.getConstantState();
                            icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate();
                            int mIconSize = navigationView.getContext().getResources().getDimensionPixelSize(
                                    android.support.design.R.dimen.design_navigation_icon_size);
                            icon.setBounds(0, 0, mIconSize, mIconSize);
                            DrawableCompat.setTintList(icon, navigationView.getItemIconTintList());
                            TextViewCompat.setCompoundDrawablesRelative(mTextView, icon, null, numberText,
                                    null);
                        }
                    }
                }
            }
    }
}

From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.info.InfoListingFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    /*//w  ww .j  a  va  2 s  .  c  o m
     * menu.clear(); MenuItem item = menu.add(Menu.CATEGORY_SYSTEM,
     * R.id.map_view, Menu.NONE, R.string.map_view);
     * item.setIcon(R.drawable.ic_map);
     * item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
     */
    menu.clear();
    getActivity().getMenuInflater().inflate(R.menu.list_menu, menu);
    menu.getItem(0).setVisible(false);// hide show on map
    if (category == null) {
        category = (getArguments() != null) ? getArguments().getString(SearchFragment.ARG_CATEGORY) : null;
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:com.mobilinkd.tncconfig.TncConfig.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    mPowerMenuItem = menu.getItem(1);
    if (mPowerMenuItem != null) {
        mPowerMenuItem.setEnabled(mConnectButton.isChecked());
    }/* w  w  w.  ja  v a2s. c o  m*/
    return true;
}

From source file:com.tomohamat.apicem.MainTabbedActivity.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.menu_main, menu);

    try {/*  w  w  w .java2  s  . c o m*/
        // Obtain version name, e.g. 1.3.1
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        String version = pInfo.versionName;
        // Write version to options menu
        (menu.getItem(0)).setTitle(getString(R.string.version) + ": " + version);
    } catch (Exception e) {
        // do nothing
    }

    return true;
}

From source file:eu.operando.operandoapp.filters.domain.DomainFiltersActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.filter_menu, menu);
    deleteAction = menu.getItem(0);
    deleteAction.setEnabled(false);//from  w w  w. j a  va 2s  .c  o  m
    return super.onCreateOptionsMenu(menu);
}

From source file:org.libreoffice.impressremote.activity.SlideShowActivity.java

private void setMenuItemsVisibility(Menu aMenu, boolean aAreItemsVisible) {
    for (int aItemIndex = 0; aItemIndex < aMenu.size(); aItemIndex++) {
        aMenu.getItem(aItemIndex).setVisible(aAreItemsVisible);
    }//  w  w w  . j  av  a2 s.co  m
}

From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java

private void showMenu(final boolean visible) {
    Menu menu = getMenu();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (alwaysShowingMenu.contains(item.getItemId()))
            continue;
        item.setVisible(visible);/*ww w.  j a  va2 s .c  om*/
    }
}