List of usage examples for android.view MenuItem getSubMenu
public SubMenu getSubMenu();
From source file:com.vuze.android.remote.fragment.TorrentListFragment.java
private void setupSideActions(View view) { listSideActions = (RecyclerView) view.findViewById(R.id.sideactions_list); if (listSideActions == null) { return;//from w w w. j a v a 2 s.c om } listSideActions.setLayoutManager(new PreCachingLayoutManager(getContext())); sideActionsAdapter = new SideActionsAdapter(getContext(), sessionInfo, new FlexibleRecyclerSelectionListener<SideActionsAdapter, SideActionsAdapter.SideActionsInfo>() { @Override public void onItemClick(SideActionsAdapter adapter, int position) { SideActionsAdapter.SideActionsInfo item = adapter.getItem(position); if (item == null) { return; } if (getActivity().onOptionsItemSelected(item.menuItem)) { return; } int itemId = item.menuItem.getItemId(); if (itemId == R.id.action_social) { MenuBuilder menuBuilder = new MenuBuilder(getContext()); MenuInflater menuInflater = getActivity().getMenuInflater(); menuInflater.inflate(R.menu.menu_torrent_list, menuBuilder); getActivity().onPrepareOptionsMenu(menuBuilder); MenuItem itemSocial = menuBuilder.findItem(R.id.action_social); if (itemSocial != null) { SubMenu subMenu = itemSocial.getSubMenu(); if (subMenu instanceof SubMenuBuilder) { ((SubMenuBuilder) subMenu).setCallback(new MenuBuilder.Callback() { @Override public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { return getActivity().onOptionsItemSelected(item); } @Override public void onMenuModeChange(MenuBuilder menu) { } }); MenuDialogHelper menuDialogHelper = new MenuDialogHelper( (SubMenuBuilder) subMenu); menuDialogHelper.show(null); } } } } @Override public boolean onItemLongClick(SideActionsAdapter adapter, int position) { return false; } @Override public void onItemSelected(SideActionsAdapter adapter, int position, boolean isChecked) { } @Override public void onItemCheckedChanged(SideActionsAdapter adapter, SideActionsAdapter.SideActionsInfo item, boolean isChecked) { } }); listSideActions.setAdapter(sideActionsAdapter); }
From source file:org.brandroid.openmanager.fragments.ContentFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item == null) return false; if (DEBUG)/*from w w w . j ava 2 s. c om*/ Logger.LogDebug( "ContentFragment.onOptionsItemSelected(0x" + Integer.toHexString(item.getItemId()) + ")"); OpenPath path = null; if (mMenuContextItemIndex > -1 && mMenuContextItemIndex < getContentAdapter().getCount()) path = getContentAdapter().getItem(mMenuContextItemIndex); if (path != null && executeMenu(item.getItemId(), mActionMode, path)) return true; switch (item.getItemId()) { case R.id.menu_sort: case R.id.menu_view: case R.id.menu_content_ops: if (OpenExplorer.USE_PRETTY_MENUS) onPrepareOptionsMenu(item.getSubMenu()); return !OpenExplorer.USE_PRETTY_MENUS; // for system menus, return false case R.id.menu_new_file: EventHandler.createNewFile(getPath(), getActivity()); return true; case R.id.menu_new_folder: EventHandler.createNewFolder(getPath(), getActivity()); return true; case R.id.menu_sort_name_asc: onSortingChanged(SortType.ALPHA); return true; case R.id.menu_sort_name_desc: onSortingChanged(SortType.ALPHA_DESC); return true; case R.id.menu_sort_date_asc: onSortingChanged(SortType.DATE); return true; case R.id.menu_sort_date_desc: onSortingChanged(SortType.DATE_DESC); return true; case R.id.menu_sort_size_asc: onSortingChanged(SortType.SIZE); return true; case R.id.menu_sort_size_desc: onSortingChanged(SortType.SIZE_DESC); return true; case R.id.menu_sort_type: onSortingChanged(SortType.TYPE); return true; case R.id.menu_view_hidden: onHiddenFilesChanged(!getShowHiddenFiles()); return true; case R.id.menu_view_thumbs: onThumbnailChanged(!getShowThumbnails()); return true; case R.id.menu_sort_folders_first: onFoldersFirstChanged(!getFoldersFirst()); return true; default: if (executeMenu(item.getItemId(), null, mPath)) return true; } return false; }
From source file:com.nachiket.titan.LibraryActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item.getGroupId() != 0) return super.onContextItemSelected(item); Intent intent = item.getIntent();/*w w w. j a v a2 s. c o m*/ switch (item.getItemId()) { case MENU_EXPAND: expand(intent); if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) { mLastAction = ACTION_EXPAND; updateHeaders(); } break; case MENU_ENQUEUE: pickSongs(intent, ACTION_ENQUEUE); break; case MENU_PLAY: pickSongs(intent, ACTION_PLAY); break; case MENU_PLAY_ALL: pickSongs(intent, ACTION_PLAY_ALL); break; case MENU_ENQUEUE_ALL: pickSongs(intent, ACTION_ENQUEUE_ALL); break; case MENU_NEW_PLAYLIST: { NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, intent); dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog)); dialog.show(); break; } case MENU_RENAME_PLAYLIST: { NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename, intent); dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog)); dialog.show(); break; } case MENU_DELETE: mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent)); break; case MENU_ADD_TO_PLAYLIST: { SubMenu playlistMenu = item.getSubMenu(); playlistMenu.add(0, MENU_NEW_PLAYLIST, 0, R.string.new_playlist).setIntent(intent); Cursor cursor = Playlist.queryPlaylists(getContentResolver()); if (cursor != null) { for (int i = 0, count = cursor.getCount(); i != count; ++i) { cursor.moveToPosition(i); long id = cursor.getLong(0); String name = cursor.getString(1); Intent copy = new Intent(intent); copy.putExtra("playlist", id); copy.putExtra("playlistName", name); playlistMenu.add(0, MENU_SELECT_PLAYLIST, 0, name).setIntent(copy); } cursor.close(); } break; } case MENU_SELECT_PLAYLIST: mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, intent)); break; case MENU_MORE_FROM_ARTIST: { String selection; if (intent.getIntExtra(LibraryAdapter.DATA_TYPE, -1) == MediaUtils.TYPE_ALBUM) { selection = "album_id="; } else { selection = "_id="; } selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID); setLimiter(MediaUtils.TYPE_ARTIST, selection); updateLimiterViews(); break; } case MENU_MORE_FROM_ALBUM: setLimiter(MediaUtils.TYPE_ALBUM, "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID)); updateLimiterViews(); break; } return true; }
From source file:org.mariotaku.twidere.util.Utils.java
public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) { if (context == null || menu == null || status == null) return;//from w w w.jav a 2 s .c o m final int activated_color = context.getResources().getColor(R.color.holo_blue_bright); final MenuItem delete = menu.findItem(R.id.delete_submenu); if (delete != null) { delete.setVisible(status.account_id == status.user_id && !isMyRetweet(status)); } final MenuItem retweet = menu.findItem(MENU_RETWEET); if (retweet != null) { final Drawable icon = retweet.getIcon().mutate(); retweet.setVisible(!status.is_protected || isMyRetweet(status)); if (isMyRetweet(status)) { icon.setColorFilter(activated_color, Mode.MULTIPLY); retweet.setTitle(R.string.cancel_retweet); } else { icon.clearColorFilter(); retweet.setTitle(R.string.retweet); } } final MenuItem favorite = menu.findItem(MENU_FAVORITE); if (favorite != null) { final Drawable icon = favorite.getIcon().mutate(); if (status.is_favorite) { icon.setColorFilter(activated_color, Mode.MULTIPLY); favorite.setTitle(R.string.unfavorite); } else { icon.clearColorFilter(); favorite.setTitle(R.string.favorite); } } final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU); if (extensions != null) { final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS); final Bundle extras = new Bundle(); extras.putParcelable(INTENT_KEY_STATUS, status); intent.putExtras(extras); final PackageManager pm = context.getPackageManager(); final List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); final boolean has_extension = !activities.isEmpty(); extensions.setVisible(has_extension); if (has_extension) { addIntentToSubMenu(context, extensions.getSubMenu(), intent); } } }
From source file:org.mozilla.gecko.BrowserApp.java
private static Menu findParentMenu(Menu menu, MenuItem item) { final int itemId = item.getItemId(); final int count = (menu != null) ? menu.size() : 0; for (int i = 0; i < count; i++) { MenuItem menuItem = menu.getItem(i); if (menuItem.getItemId() == itemId) { return menu; }/*from w w w . j a v a 2 s . c o m*/ if (menuItem.hasSubMenu()) { Menu parent = findParentMenu(menuItem.getSubMenu(), item); if (parent != null) { return parent; } } } return null; }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) { if (context == null || menu == null || status == null) return;/* w ww . j a v a 2 s.c o m*/ final int activatedColor = ThemeUtils.getUserThemeColor(context); final boolean isMyRetweet = isMyRetweet(status); final MenuItem delete = menu.findItem(MENU_DELETE); if (delete != null) { delete.setVisible(status.account_id == status.user_id && !isMyRetweet); } final MenuItem retweet = menu.findItem(MENU_RETWEET); if (retweet != null) { final Drawable icon = retweet.getIcon().mutate(); retweet.setVisible(!status.user_is_protected || isMyRetweet); if (isMyRetweet) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); retweet.setTitle(R.string.cancel_retweet); } else { icon.clearColorFilter(); retweet.setTitle(R.string.retweet); } } final MenuItem itemRetweetSubmenu = menu.findItem(R.id.retweet_submenu); if (itemRetweetSubmenu != null) { final Drawable icon = itemRetweetSubmenu.getIcon().mutate(); if (isMyRetweet) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { icon.clearColorFilter(); } } final MenuItem favorite = menu.findItem(MENU_FAVORITE); if (favorite != null) { final Drawable icon = favorite.getIcon().mutate(); if (status.is_favorite) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); favorite.setTitle(R.string.unfavorite); } else { icon.clearColorFilter(); favorite.setTitle(R.string.favorite); } } final MenuItem love = menu.findItem(MENU_LOVE); if (love != null) { final Drawable icon = love.getIcon().mutate(); love.setVisible(!status.user_is_protected || isMyRetweet); if (isMyRetweet && status.is_favorite) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { icon.clearColorFilter(); } } final MenuItem translate = menu.findItem(MENU_TRANSLATE); if (translate != null) { final AccountWithCredentials account = Account.getAccountWithCredentials(context, status.account_id); final boolean isOfficialKey = AccountWithCredentials.isOfficialCredentials(context, account); setMenuItemAvailability(menu, MENU_TRANSLATE, isOfficialKey); } final MenuItem shareItem = menu.findItem(R.id.share_submenu); final Menu shareSubmenu = shareItem != null && shareItem.hasSubMenu() ? shareItem.getSubMenu() : null; if (shareSubmenu != null) { final Intent shareIntent = createStatusShareIntent(context, status); shareSubmenu.removeGroup(MENU_GROUP_STATUS_SHARE); addIntentToMenu(context, shareSubmenu, shareIntent, MENU_GROUP_STATUS_SHARE); } }
From source file:org.mozilla.gecko.BrowserApp.java
/** * Add the provided item to the provided menu, which should be * the root (mMenu).//from ww w.j ava 2 s . co m */ private void addAddonMenuItemToMenu(final Menu menu, final MenuItemInfo info) { info.added = true; final Menu destination; if (info.parent == 0) { destination = menu; } else if (info.parent == GECKO_TOOLS_MENU) { // The tools menu only exists in our -v11 resources. if (Versions.feature11Plus) { final MenuItem tools = menu.findItem(R.id.tools); destination = tools != null ? tools.getSubMenu() : menu; } else { destination = menu; } } else { final MenuItem parent = menu.findItem(info.parent); if (parent == null) { return; } Menu parentMenu = findParentMenu(menu, parent); if (!parent.hasSubMenu()) { parentMenu.removeItem(parent.getItemId()); destination = parentMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle()); if (parent.getIcon() != null) { ((SubMenu) destination).getItem().setIcon(parent.getIcon()); } } else { destination = parent.getSubMenu(); } } final MenuItem item = destination.add(Menu.NONE, info.id, Menu.NONE, info.label); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET))); return true; } }); if (info.icon == null) { item.setIcon(R.drawable.ic_menu_addons_filler); } else { final int id = info.id; BitmapUtils.getDrawable(this, info.icon, new BitmapUtils.BitmapLoader() { @Override public void onBitmapFound(Drawable d) { // TODO: why do we re-find the item? final MenuItem item = destination.findItem(id); if (item == null) { return; } if (d == null) { item.setIcon(R.drawable.ic_menu_addons_filler); return; } item.setIcon(d); } }); } item.setCheckable(info.checkable); item.setChecked(info.checked); item.setEnabled(info.enabled); item.setVisible(info.visible); }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
private void handleMoreMenu(Menu menu, boolean forceFromToolbar, int max) { if (forceFromToolbar || (menu.size() > max && Build.VERSION.SDK_INT > 13 && getWindowWidth() < 700)) { MenuItem more = menu.findItem(R.id.menu_more); if (more != null) { SubMenu moreSub = more.getSubMenu(); if (moreSub != null) { for (int i = Math.max(0, max - 1); i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (item.getItemId() == R.id.menu_more) continue; MenuItem ni = MenuUtils.transferMenu(item, moreSub); if (ni == null) continue; ni.setAlphabeticShortcut((char) ('a' + i)); item.setVisible(false); }// ww w.j av a 2s . com MenuUtils.scanMenuShortcuts(moreSub); } } } else MenuUtils.setMenuVisible(menu, false, R.id.menu_more); }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (DEBUG)/*w ww . ja va 2 s. c o m*/ Logger.LogDebug("OpenExplorer.onOptionsItemSelected(" + item + ")"); if (item.getItemId() == R.id.menu_more && isGTV()) { showMenu(mOptsMenu, findViewById(item.getItemId()), false); return true; } if (item.getSubMenu() != null) { onPrepareOptionsMenu(item.getSubMenu()); if (!USE_PRETTY_MENUS) return false; else { View anchor = findViewById(item.getItemId()); if (anchor == null && !BEFORE_HONEYCOMB && item.getActionView() != null) anchor = item.getActionView(); if (anchor == null && !BEFORE_HONEYCOMB) { anchor = getActionBar().getCustomView(); if (anchor.findViewById(item.getItemId()) != null) anchor = anchor.findViewById(item.getItemId()); } if (anchor == null) anchor = mToolbarButtons; if (anchor == null) anchor = findViewById(android.R.id.home); if (anchor == null && !BEFORE_HONEYCOMB && USE_ACTION_BAR) anchor = getActionBar().getCustomView().findViewById(android.R.id.home); if (anchor == null) anchor = getCurrentFocus().getRootView(); OpenFragment f = getSelectedFragment(); if (f != null) if (f.onClick(item.getItemId(), anchor)) return true; } } if (item.isCheckable()) item.setChecked(item.getGroupId() > 0 ? true : !item.isChecked()); OpenFragment f = getSelectedFragment(); if (f != null && f.onOptionsItemSelected(item)) return true; if (DEBUG) Logger.LogDebug("OpenExplorer.onOptionsItemSelected(0x" + Integer.toHexString(item.getItemId()) + ")"); return onClick(item.getItemId(), item, null); }
From source file:mp.teardrop.LibraryActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item.getGroupId() == MENU_GROUP_ROUND_BUTTON) { Limiter limiter = mPagerAdapter.getCurrentLimiter(); Intent intent = null;// ww w . ja v a2 s . c om switch (mPagerAdapter.getCurrentType()) { case MediaUtils.TYPE_FILE: intent = new Intent(); intent.putExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_FILE); intent.putExtra("file", limiter == null ? "/" : limiter.data.toString()); break; case MediaUtils.TYPE_UNIFIED: if (limiter != null && limiter.type <= 20) { intent = new Intent(); intent.putExtra(LibraryAdapter.DATA_TYPE, limiter.type); intent.putExtra(LibraryAdapter.DATA_ID, (Long) limiter.data); } //else continue with null limiter, which will play the entire MediaStore break; } mRoundPlayAllButton.setVisibility(View.GONE); pickSongs(intent, item.getItemId() == MENU_PLAY_ALL ? ACTION_PLAY_ALL : ACTION_ENQUEUE_ALL); return true; } if (item.getGroupId() != 0) { return super.onContextItemSelected(item); } final Intent intent = item.getIntent(); switch (item.getItemId()) { case MENU_EXPAND: expand(intent); if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) { mLastAction = ACTION_EXPAND; } break; case MENU_ENQUEUE: pickSongs(intent, ACTION_ENQUEUE); break; case MENU_PLAY: pickSongs(intent, ACTION_PLAY); break; case MENU_PLAY_ALL: pickSongs(intent, ACTION_PLAY_ALL); break; case MENU_ENQUEUE_ALL: pickSongs(intent, ACTION_ENQUEUE_ALL); break; case MENU_NEW_PLAYLIST: { NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, intent); dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog)); dialog.show(); break; } case MENU_RENAME_PLAYLIST: { NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename, intent); dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog)); dialog.show(); break; } case MENU_DELETE: String delete_message = getString(R.string.delete_item, intent.getStringExtra("title")); AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.delete); dialog.setMessage(delete_message) .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent)); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); dialog.create().show(); break; case MENU_ADD_TO_PLAYLIST: { SubMenu playlistMenu = item.getSubMenu(); playlistMenu.add(0, MENU_NEW_PLAYLIST, 0, R.string.new_playlist).setIntent(intent); Cursor cursor = Playlist.queryPlaylists(getContentResolver()); if (cursor != null) { for (int i = 0, count = cursor.getCount(); i != count; ++i) { cursor.moveToPosition(i); long id = cursor.getLong(0); String name = cursor.getString(1); Intent copy = new Intent(intent); copy.putExtra("playlist", id); copy.putExtra("playlistName", name); playlistMenu.add(0, MENU_SELECT_PLAYLIST, 0, name).setIntent(copy); } cursor.close(); } break; } case MENU_SELECT_PLAYLIST: mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, intent)); break; case MENU_MORE_FROM_ARTIST: { String selection = "_id="; selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID); setLimiter(-1, selection); updateLimiterViews(); break; } case MENU_MORE_FROM_ALBUM: setLimiter(-1, "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID)); updateLimiterViews(); break; } return true; }