List of usage examples for android.view Menu CATEGORY_ALTERNATIVE
int CATEGORY_ALTERNATIVE
To view the source code for android.view Menu CATEGORY_ALTERNATIVE.
Click Source Link
From source file:org.openintents.shopping.ui.ShoppingActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); boolean drawerOpen = mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mDrawerListsView); boolean holoSearch = PreferenceActivity.getUsingHoloSearchFromPrefs(this); // TODO: supposed to hide content-related actions when the drawer is open. // TODO: Add item-specific menu items (see NotesList.java example) // like edit, strike-through, delete. // Add menu option for auto adding items from string array in intent // extra if they exist if (mExtraItems == null) { menu.removeItem(MENU_INSERT_FROM_EXTRAS); }/*from w w w . ja va 2s . c om*/ // Selected list: long listId = getSelectedListId(); // set menu title for change mode MenuItem menuItem = menu.findItem(MENU_PICK_ITEMS); if (mItemsView.mMode == MODE_ADD_ITEMS) { menuItem.setTitle(R.string.menu_start_shopping); menuItem.setIcon(android.R.drawable.ic_menu_myplaces); } else { menu.findItem(MENU_PICK_ITEMS).setTitle(R.string.menu_pick_items); menuItem.setIcon(android.R.drawable.ic_menu_add); } menuItem = menu.findItem(MENU_SEARCH_ADD); if (menuItem != null) { menuItem.setVisible(holoSearch && !drawerOpen); if (!holoSearch) { mAddPanel.setVisibility(View.VISIBLE); } View searchView = menuItem.getActionView(); int searchImgId = getResources().getIdentifier("android:id/search_button", null, null); View imageView = searchView.findViewById(searchImgId); if (imageView instanceof ImageView) { ((ImageView) imageView).setImageResource(android.R.drawable.ic_menu_add); } } menuItem = menu.findItem(MENU_SYNC_WEAR); if (menuItem != null) { menuItem.setVisible(mItemsView.isWearSupportAvailable()); } menuItem = menu.findItem(MENU_MARK_ALL_ITEMS).setVisible(mItemsView.mNumUnchecked > 0); menuItem = menu.findItem(MENU_UNMARK_ALL_ITEMS).setVisible(mItemsView.mNumChecked > 0); menuItem = menu.findItem(MENU_CLEAN_UP_LIST).setEnabled(mItemsView.mNumChecked > 0).setVisible(!drawerOpen); // Delete list is possible, if we have more than one list: // AND // the current list is not the default list (listId == 0) - issue #105 // TODO: Later, the default list should be user-selectable, // and not deletable. // TODO ??? /* * menu.setItemShown(MENU_DELETE_LIST, mCursorListFilter.count() > 1 && * listId != 1); // 1 is hardcoded number of default first list. */ // The following code is put from onCreateOptionsMenu to // onPrepareOptionsMenu, // because the URI of the shopping list can change if the user switches // to another list. // Generate any additional actions that can be performed on the // overall list. This allows other applications to extend // our menu with their own actions. Intent intent = new Intent(null, getIntent().getData()); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); // menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, // new ComponentName(this, NoteEditor.class), null, intent, 0, null); // Workaround to add icons: MenuIntentOptionsWithIcons menu2 = new MenuIntentOptionsWithIcons(this, menu); menu2.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, org.openintents.shopping.ShoppingActivity.class), null, intent, 0, null); return true; }
From source file:org.openintents.shopping.ui.ShoppingActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (debug) {//from ww w .jav a 2s . co m Log.d(TAG, "onOptionsItemSelected getItemId: " + item.getItemId()); } Intent intent; switch (item.getItemId()) { case MENU_NEW_LIST: showDialog(DIALOG_NEW_LIST); return true; case MENU_CLEAN_UP_LIST: cleanupList(); return true; case MENU_RENAME_LIST: showDialog(DIALOG_RENAME_LIST); return true; case MENU_DELETE_LIST: deleteListConfirm(); return true; case MENU_PICK_ITEMS: pickItems(); return true; case MENU_SHARE: setShareSettings(); return true; case MENU_THEME: setThemeSettings(); return true; case MENU_ADD_LOCATION_ALERT: addLocationAlert(); return true; case MENU_PREFERENCES: intent = new Intent(this, PreferenceActivity.class); startActivity(intent); return true; case MENU_SEND: sendList(); return true; case MENU_INSERT_FROM_EXTRAS: insertItemsFromExtras(); return true; case MENU_MARK_ALL_ITEMS: mItemsView.toggleAllItems(true); return true; case MENU_UNMARK_ALL_ITEMS: mItemsView.toggleAllItems(false); return true; case MENU_SYNC_WEAR: mItemsView.pushItemsToWear(); return true; } if (debug) { Log.d(TAG, "Start intent group id : " + item.getGroupId()); } if (Menu.CATEGORY_ALTERNATIVE == item.getGroupId()) { // Start alternative cateogory intents with option to return a // result. if (debug) { Log.d(TAG, "Start alternative intent for : " + item.getIntent().getDataString()); } startActivityForResult(item.getIntent(), REQUEST_CODE_CATEGORY_ALTERNATIVE); return true; } if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); }