Example usage for android.view Menu removeItem

List of usage examples for android.view Menu removeItem

Introduction

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

Prototype

public void removeItem(int id);

Source Link

Document

Remove the item with the given identifier.

Usage

From source file:cs.man.ac.uk.tavernamobile.fragments.SearchResultFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    // remove menu added by previous fragment
    for (int i = 1; i < menu.size(); i++) {
        menu.removeItem(menu.getItem(i).getItemId());
    }/*from   w w  w . j  a  va2s.com*/
    parentActivity.getMenuInflater().inflate(R.menu.search_results_screen, menu);
    LinearLayout searchView = (LinearLayout) menu.findItem(R.id.search_results_search).getActionView();

    final EditText query = (EditText) searchView.getChildAt(0);
    query.requestFocus();
    query.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                searchQuery = query.getText().toString();
                search(searchQuery);
                return true;
            }
            return false;
        }
    });
    ImageButton searchButton = (ImageButton) searchView.getChildAt(1);

    searchButton.setOnClickListener(new android.view.View.OnClickListener() {
        public void onClick(android.view.View v) {
            searchQuery = query.getText().toString();
            search(searchQuery);
        }
    });
    super.onPrepareOptionsMenu(menu);
}

From source file:com.hybris.mobile.activity.AbstractProductDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate menu
    MenuUtil.onCreateProductDetailsOptionsMenu(menu, this);
    menu.removeItem(R.id.search);

    if (!getResources().getBoolean(R.bool.nfc_write_enabled)) {
        menu.removeItem(R.id.write_tag);
    }//  ww  w  . j  a  v a  2s  . c  o  m

    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.share);

    // Fetch and store ShareActionProvider
    setShareActionProvider((ShareActionProvider) item.getActionProvider());

    return true;
}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment.java

public boolean openPopupMenu(View view, int position) {
    PopupMenu popupMenu = new PopupMenu(getContext(), view);
    popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
    Menu menu = popupMenu.getMenu();
    final GBDeviceApp selectedApp = appList.get(position);

    if (!selectedApp.isInCache()) {
        menu.removeItem(R.id.appmanager_app_reinstall);
        menu.removeItem(R.id.appmanager_app_delete_cache);
    }/*from w w w  .ja  v a 2s  . c o  m*/
    if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_health_activate);
        menu.removeItem(R.id.appmanager_health_deactivate);
    }
    if (!PebbleProtocol.UUID_WORKOUT.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_hrm_activate);
        menu.removeItem(R.id.appmanager_hrm_deactivate);
    }
    if (!PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_weather_activate);
        menu.removeItem(R.id.appmanager_weather_deactivate);
        menu.removeItem(R.id.appmanager_weather_install_provider);
    }
    if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM
            || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) {
        menu.removeItem(R.id.appmanager_app_delete);
    }
    if (!selectedApp.isConfigurable()) {
        menu.removeItem(R.id.appmanager_app_configure);
    }

    if (PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        PackageManager pm = getActivity().getPackageManager();
        try {
            pm.getPackageInfo("ru.gelin.android.weather.notification", PackageManager.GET_ACTIVITIES);
            menu.removeItem(R.id.appmanager_weather_install_provider);
        } catch (PackageManager.NameNotFoundException e) {
            menu.removeItem(R.id.appmanager_weather_activate);
            menu.removeItem(R.id.appmanager_weather_deactivate);
        }
    }

    switch (selectedApp.getType()) {
    case WATCHFACE:
    case APP_GENERIC:
    case APP_ACTIVITYTRACKER:
        break;
    default:
        menu.removeItem(R.id.appmanager_app_openinstore);
    }
    //menu.setHeaderTitle(selectedApp.getName());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            return onContextItemSelected(item, selectedApp);
        }
    });

    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    popupMenu.show();
    return true;
}

From source file:org.dmfs.webcal.NavbarActivity.java

protected void setupNavbar() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // this is a hack to get a Menu
    Menu menu = new PopupMenu(this, null).getMenu();
    getMenuInflater().inflate(R.menu.side_navigation, menu);

    // remove invisible menu items
    int itemCount = menu.size();
    int i = 0;//from w w w  .j  av  a 2 s . c  om
    while (i < itemCount) {
        MenuItem item = menu.getItem(i);
        if (!item.isVisible()) {
            menu.removeItem(item.getItemId());
            --itemCount;
        } else {
            ++i;
        }
    }

    MenuAdapter menuAdapter = new MenuAdapter(this, R.layout.navdrawer_item, android.R.id.title, menu);
    mDrawerList.setAdapter(menuAdapter);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            String activityTitle = getActivityTitle();
            setTitle(activityTitle);
            invalidateOptionsMenu();
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            setTitle(R.string.app_name);
            invalidateOptionsMenu();
            super.onDrawerOpened(drawerView);
        }
    };
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerList.setOnItemClickListener(this);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
}

From source file:com.miz.mizuu.fragments.CollectionLibraryFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.menu, menu);

    menu.removeItem(R.id.update);
    menu.removeItem(R.id.search_textbox);
    menu.removeItem(R.id.filters);/*from w  ww  . j ava 2 s .  com*/
    menu.removeItem(R.id.sort);
    menu.removeItem(R.id.unidentifiedFiles);

    menu.findItem(R.id.view_collection_online).setVisible(true);
}

From source file:com.example.kjpark.smartclass.NoticeTab.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_write, menu);
    if (ConnectServer.getInstance().getType() != ConnectServer.Type.teacher) {
        menu.removeItem(R.id.action_write);
    }//from   w w  w .ja va  2  s  .  c o m
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.alfresco.mobile.android.application.fragments.actions.NodeActions.java

protected void removeActionIfNecessary(Menu menu, int menuItemId, int actionId) {
    if (!ConfigurableActionHelper.isVisible(getActivity(), getAccount(), actionId)) {
        menu.removeItem(menuItemId);
    }/*from   w  w w.  j  a  va2s  . co m*/
}

From source file:com.maxwen.wallpaper.board.activities.WallpaperBoardActivity.java

public void fileCategoryMenu(Menu menu) {
    List<Category> categories = new Database(this).getCategories();
    for (Category c : categories) {
        menu.removeItem(MENU_CATEGORY_START + c.getId());
        MenuItem item = menu.add(Menu.NONE, MENU_CATEGORY_START + c.getId(), Menu.NONE, c.getName());
        item.setCheckable(true);//from  ww  w.j  a va2  s . c  o  m
        item.setChecked(c.isSelected());
    }
}

From source file:net.exclaimindustries.geohashdroid.activities.CentralMapExtraActivity.java

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

    // Now, some menu items may not be available if we can't get to them.
    // Like, for instance, Send To Maps.  If Google Maps (or anything that
    // can receive the Intent) isn't there, we can't do that.
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("geo:0,0?q=loc:0,0"));
    if (!AndroidUtil.isIntentAvailable(this, i))
        menu.removeItem(R.id.action_send_to_maps);

    // Or the Radar intent.
    if (!AndroidUtil.isIntentAvailable(this, GHDConstants.SHOW_RADAR_ACTION))
        menu.removeItem(R.id.action_send_to_radar);

    return true;//from www. j a va2  s. c o m
}

From source file:com.stoyanr.feeder.activity.ItemsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.items_menu, menu);
    MenuUtils.setShowAsActionAll(menu);//from   ww w.j a  v a  2  s  . co m
    MenuItem item = menu.findItem(R.id.view_featured);
    item.setChecked(featuredOnly);
    int iconRes = featuredOnly ? R.drawable.btn_check_on : R.drawable.btn_check_off;
    item.setIcon(iconRes);
    if (prevChannelId < 0) {
        menu.removeItem(R.id.prev_channel);
    }
    if (nextChannelId < 0) {
        menu.removeItem(R.id.next_channel);
    }
    return true;
}