List of usage examples for android.view MenuItem getGroupId
public int getGroupId();
From source file:com.ruesga.rview.MainActivity.java
private void updateAccountCustomFilters() { // Remove all custom filters and re-add them final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu(); int myFiltersGroupIndex = menu.findGroupIndex(R.id.category_my_filters); MenuItem group = menu.getItem(myFiltersGroupIndex); SubMenu myFiltersSubMenu = group.getSubMenu(); int count = myFiltersSubMenu.size() - 1; for (int i = count; i >= 0; i--) { ((DrawerNavigationSubMenu) myFiltersSubMenu).removeItemAt(i); }/*from w w w.j a va 2 s . co m*/ mCustomFilters = Preferences.getAccountCustomFilters(this, mAccount); if (mCustomFilters != null) { int i = 0; for (CustomFilter filter : mCustomFilters) { int id = MY_FILTERS_GROUP_BASE_ID + i; String title = filter.mName + DrawerNavigationView.SEPARATOR + filter.mQuery.toString() + DrawerNavigationView.SEPARATOR + "ic_close"; MenuItem item = myFiltersSubMenu.add(group.getGroupId(), id, Menu.NONE, title); item.setIcon(R.drawable.ic_filter); item.setCheckable(true); i++; } } menu.setGroupVisible(R.id.category_my_filters, !mModel.isAccountExpanded && mCustomFilters != null && !mCustomFilters.isEmpty()); mBinding.drawerNavigationView.setCheckedItem(mModel.currentNavigationItemId); }
From source file:com.teitsmch.hearthmaker.MainActivity.java
public void selectItem(MenuItem currentItem) { // Reset Spinner positions mClassSpinner.setSelection(0);// w ww. j av a2s . c om for (Spinner spinner : spinners) { spinner.setSelection(0); } // Reset Search View if (mFragment != null) { searchView.setQuery("", true); searchView.onActionViewCollapsed(); } // Reset Subtitle updateSubtitle(null); // update the main content by replacing fragments switch (currentItem.getItemId()) { case CATALOG_FRAGMENT_ID: mMainActivityPresenter.resetFilter(); mFragment = CardViewFragment.newInstance(); if (mSpinnerView.getVisibility() == View.VISIBLE) { mSpinnerView.setVisibility(View.GONE); } currentClasses.clear(); currentClasses.add("CLEAR"); currentClasses.addAll(Arrays.asList(dialogClasses)); mClassSpinnerAdapter.notifyDataSetChanged(); break; case R.id.nav_new_deck: createNewDeckDialog(); return; default: if (currentItem.getGroupId() == R.id.navigation_deck_group) { mFragment = DeckFragment.newInstance(currentDeckClass, currentItem.getItemId(), (String) currentItem.getTitle()); currentDeckClass = ""; if (mSpinnerView.getVisibility() == View.VISIBLE) { mSpinnerView.setVisibility(View.GONE); updateSubtitle(cardCount); } } break; } FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.replace(R.id.content_frame, mFragment); ft.commit(); // Close the drawer setTitle(currentItem.getTitle()); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_LAUNCH: optionLaunch(item.getGroupId()); return true; case MENU_SETTINGS: optionAppSettings(item.getGroupId()); return true; case MENU_KILL: optionKill(item.getGroupId());// w w w . j a v a 2s .c o m return true; case MENU_STORE: optionStore(item.getGroupId()); return true; default: return super.onContextItemSelected(item); } }
From source file:com.ruesga.rview.MainActivity.java
private void updateAccountsDrawerInfo() { // Remove all accounts and re-add them final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu(); int otherAccountGroupIndex = menu.findGroupIndex(R.id.category_other_accounts); MenuItem group = menu.getItem(otherAccountGroupIndex); SubMenu otherAccountsSubMenu = group.getSubMenu(); int count = otherAccountsSubMenu.size() - 1; for (int i = count; i > 0; i--) { ((DrawerNavigationSubMenu) otherAccountsSubMenu).removeItemAt(i); }/* w w w . j a v a2 s . co m*/ int i = 0; for (Account account : mAccounts) { // Current account if (mAccount.isSameAs(account)) { i++; continue; } int id = OTHER_ACCOUNTS_GROUP_BASE_ID + i; String title = account.getAccountDisplayName() + DrawerNavigationView.SEPARATOR + account.getRepositoryDisplayName() + DrawerNavigationView.SEPARATOR + "ic_delete" + DrawerNavigationView.SEPARATOR + "false"; MenuItem item = otherAccountsSubMenu.add(group.getGroupId(), id, Menu.NONE, title); PicassoHelper.bindAvatar(this, PicassoHelper.getPicassoClient(this), account, account.mAccount, item, PicassoHelper.getDefaultAvatar(this, R.color.primaryDarkForeground)); i++; } if (mAccount != null) { updateAccountStatus(); } }
From source file:com.oakesville.mythling.MediaActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item.getGroupId() == MEDIA_ACTIVITY_CONTEXT_MENU_GROUP_ID) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); if (item.getItemId() == LONG_CLICK_MENU_PLAY) { Item it = (Item) getListView().getItemAtPosition(info.position); playItem(it);// w w w . j a v a 2 s .c o m return true; } else if (item.getItemId() == LONG_CLICK_MENU_TRANSCODE) { Item it = (Item) getListView().getItemAtPosition(info.position); transcodeItem(it); return true; } else if (item.getItemId() == LONG_CLICK_MENU_DOWNLOAD) { Item it = (Item) getListView().getItemAtPosition(info.position); downloadItem(it); return true; } else if (item.getItemId() == LONG_CLICK_MENU_DELETE) { Recording rec = (Recording) getListView().getItemAtPosition(info.position); int size = getListables().size(); if (size == 1 || size == info.position + 1) setSelItemIndex(getSelItemIndex() - 1); deleteRecording(rec); return true; } } return false; }
From source file:org.thoughtland.xlocation.ActivityApp.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent upIntent = NavUtils.getParentActivityIntent(this); if (upIntent != null) if (NavUtils.shouldUpRecreateTask(this, upIntent)) TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities(); else// w w w. j av a2s. c o m NavUtils.navigateUpTo(this, upIntent); return true; case R.id.menu_usage: optionUsage(); return true; case R.id.menu_accounts: optionAccounts(); return true; case R.id.menu_applications: optionApplications(); return true; case R.id.menu_contacts: if (item.getGroupId() != 0) { optionContacts(item.getGroupId()); return true; } else return false; case R.id.menu_whitelists: optionWhitelists(null); return true; case R.id.menu_apply: optionTemplate(); return true; case R.id.menu_clear: optionClear(); return true; case R.id.menu_export: optionExport(); return true; case R.id.menu_import: optionImport(); return true; case R.id.menu_submit: optionSubmit(); return true; case R.id.menu_fetch: optionFetch(); return true; case R.id.menu_settings: optionSettings(); return true; case R.id.menu_dump: optionDump(); return true; case R.id.menu_legend: optionLegend(); return true; case R.id.menu_tutorial: optionTutorial(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.audiokernel.euphonyrmt.fragments.SongsFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.songs, container, false); mList = (AbsListView) view.findViewById(R.id.list); registerForContextMenu(mList);/*from w w w .j a va2 s . c o m*/ mList.setOnItemClickListener(this); mLoadingView = view.findViewById(R.id.loadingLayout); mLoadingTextView = (TextView) view.findViewById(R.id.loadingText); mNoResultView = view.findViewById(R.id.noResultLayout); mLoadingTextView.setText(getLoadingText()); final View headerView = inflater.inflate(R.layout.song_header, null, false); mCoverArt = (ImageView) view.findViewById(R.id.albumCover); if (mCoverArt != null) { mHeaderArtist = (TextView) view.findViewById(R.id.tracks_artist); mHeaderInfo = (TextView) view.findViewById(R.id.tracks_info); mCoverArtProgress = (ProgressBar) view.findViewById(R.id.albumCoverProgress); mAlbumMenu = (ImageButton) view.findViewById(R.id.album_menu); } else { mHeaderArtist = (TextView) headerView.findViewById(R.id.tracks_artist); mHeaderInfo = (TextView) headerView.findViewById(R.id.tracks_info); mCoverArt = (ImageView) headerView.findViewById(R.id.albumCover); mCoverArtProgress = (ProgressBar) headerView.findViewById(R.id.albumCoverProgress); mAlbumMenu = (ImageButton) headerView.findViewById(R.id.album_menu); } mCoverArtListener = new AlbumCoverDownloadListener(mCoverArt, mCoverArtProgress, false); mCoverHelper = new CoverAsyncHelper(); mCoverHelper.setCoverMaxSizeFromScreen(getActivity()); final ViewTreeObserver vto = mCoverArt.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (mCoverHelper != null) { mCoverHelper.setCachedCoverMaxSize(mCoverArt.getMeasuredHeight()); } return true; } }); mCoverHelper.addCoverDownloadListener(mCoverArtListener); ((TextView) headerView.findViewById(R.id.separator_title)).setText(R.string.songs); ((ListView) mList).addHeaderView(headerView, null, false); mPopupMenu = new PopupMenu(getActivity(), mAlbumMenu); mPopupMenu.getMenu().add(Menu.NONE, ADD, Menu.NONE, R.string.addAlbum); mPopupMenu.getMenu().add(Menu.NONE, ADD_REPLACE, Menu.NONE, R.string.addAndReplace); mPopupMenu.getMenu().add(Menu.NONE, ADD_REPLACE_PLAY, Menu.NONE, R.string.addAndReplacePlay); mPopupMenu.getMenu().add(Menu.NONE, ADD_PLAY, Menu.NONE, R.string.addAndPlay); mPopupMenu.getMenu().add(Menu.NONE, GOTO_ARTIST, Menu.NONE, R.string.goToArtist); mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { final int itemId = item.getItemId(); if (itemId == GOTO_ARTIST) { final Intent intent = new Intent(getActivity(), SimpleLibraryActivity.class); intent.putExtra("artist", mAlbum.getArtist()); startActivityForResult(intent, -1); } else { mApp.oMPDAsyncHelper.execAsync(new Runnable() { @Override public void run() { boolean replace = false; boolean play = false; switch (itemId) { case ADD_REPLACE_PLAY: replace = true; play = true; break; case ADD_REPLACE: replace = true; break; case ADD_PLAY: play = true; break; default: break; } try { mApp.oMPDAsyncHelper.oMPD.add(mAlbum, replace, play); Tools.notifyUser(R.string.albumAdded, mAlbum); } catch (final IOException | MPDException e) { Log.e(TAG, "Failed to add, replace, play.", e); } } }); } return true; } }); mAlbumMenu.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(mPopupMenu)); mAlbumMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { mPopupMenu.show(); } }); mCoverPopupMenu = new PopupMenu(getActivity(), mCoverArt); mCoverPopupMenu.getMenu().add(POPUP_COVER_BLACKLIST, POPUP_COVER_BLACKLIST, 0, R.string.otherCover); mCoverPopupMenu.getMenu().add(POPUP_COVER_SELECTIVE_CLEAN, POPUP_COVER_SELECTIVE_CLEAN, 0, R.string.resetCover); mCoverPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { final int groupId = item.getGroupId(); boolean result = true; if (groupId == POPUP_COVER_BLACKLIST) { final AlbumInfo albumInfo = new AlbumInfo(mAlbum); CoverManager.getInstance().markWrongCover(albumInfo); updateCover(albumInfo); updateNowPlayingSmallFragment(albumInfo); } else if (groupId == POPUP_COVER_SELECTIVE_CLEAN) { final AlbumInfo albumInfo = new AlbumInfo(mAlbum); CoverManager.getInstance().clear(albumInfo); updateCover(albumInfo); updateNowPlayingSmallFragment(albumInfo); } else { result = false; } return result; } }); mCoverArt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(final View v) { mCoverPopupMenu.show(); return false; } }); updateFromItems(); return view; }
From source file:com.ruesga.rview.MainActivity.java
private void performNavigationAction(MenuItem item) { switch (item.getItemId()) { case R.id.menu_account_settings: openAccountSettings();/*from w ww.j a v a 2 s .c o m*/ break; case R.id.menu_account_notifications: openAccountNotifications(); break; case R.id.menu_account_status: openAccountStatusChooser(); break; case R.id.menu_account_stats: openAccountStats(); break; case R.id.menu_account_password: openAccountSetup(); break; case R.id.menu_drop_account: requestAccountDeletion(mAccount); break; case R.id.menu_add_account: Intent i = new Intent(this, SetupAccountActivity.class); startActivityForResult(i, REQUEST_WIZARD); break; case R.id.menu_share: String action = getString(R.string.action_share); String title = getString(R.string.share_app_title); final String deepLink = getString(R.string.link_play_store, getPackageName()); String text = getString(R.string.share_app_text, deepLink); ActivityHelper.share(this, action, title, text); break; case R.id.menu_privacy: final String link = getString(R.string.link_privacy); ActivityHelper.openUriInCustomTabs(this, link); break; case R.id.menu_about: String[] libraries = getResources().getStringArray(R.array.libraries_ids); LibsBuilder builder = new LibsBuilder().withAboutAppName(getString(R.string.app_name)) .withActivityColor(new Colors(ContextCompat.getColor(this, R.color.primaryDark), ContextCompat.getColor(this, R.color.primaryDark))) .withAboutIconShown(true).withActivityTitle(getString(R.string.menu_about)) .withAboutVersionShown(true).withLibraries(libraries).withFields(R.string.class.getFields()) .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR); builder.start(this); break; default: if (item.getGroupId() == R.id.category_other_accounts) { // Other accounts ground action int accountIndex = item.getItemId() - OTHER_ACCOUNTS_GROUP_BASE_ID; Account account = mAccounts.get(accountIndex); if (account != null) { mAccount = account; performAccountSwitch(); } } break; } }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent upIntent = NavUtils.getParentActivityIntent(this); if (upIntent != null) if (NavUtils.shouldUpRecreateTask(this, upIntent)) TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities(); else/* ww w . jav a 2 s . c o m*/ NavUtils.navigateUpTo(this, upIntent); return true; case R.id.menu_dump: optionDump(); return true; case R.id.menu_help: optionHelp(); return true; case R.id.menu_tutorial: optionTutorial(); return true; case R.id.menu_usage: optionUsage(); return true; case R.id.menu_apply: optionTemplate(); return true; case R.id.menu_clear: optionClear(); return true; case R.id.menu_export: optionExport(); return true; case R.id.menu_import: optionImport(); return true; case R.id.menu_submit: optionSubmit(); return true; case R.id.menu_fetch: optionFetch(); return true; case R.id.menu_accounts: optionAccounts(); return true; case R.id.menu_applications: optionApplications(); return true; case R.id.menu_contacts: if (item.getGroupId() != 0) { optionContacts(item.getGroupId()); return true; } else return false; case R.id.menu_whitelists: optionWhitelists(null); return true; case R.id.menu_settings: optionSettings(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.openintents.notepad.NoteEditor.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle all of the possible menu actions. switch (item.getItemId()) { case android.R.id.home: Intent intent = new Intent(this, NotesList.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);// w ww . ja v a 2 s . c o m break; case MENU_SEARCH: menuSearch(); break; case MENU_DELETE: deleteNoteWithConfirm(); break; case MENU_DISCARD: revertNote(); break; case MENU_REVERT: revertNote(); break; case MENU_ENCRYPT: encryptNote(true); break; case MENU_UNENCRYPT: unencryptNote(); break; case MENU_IMPORT: importNote(); break; case MENU_SAVE: saveNoteWithPermissionCheck(); break; case MENU_SAVE_AS: saveAsNote(); break; case MENU_THEME: setThemeSettings(); return true; case MENU_SETTINGS: showNotesListSettings(); return true; case MENU_SEND: shareNote(); return true; case MENU_WORD_COUNT: showWordCount(); break; } if (item.getGroupId() == GROUP_ID_TEXT_SELECTION_ALTERNATIVE) { // Process manually: // We pass the current selection along with the intent startTextSelectionActivity(item.getIntent()); // Consume event return true; } return super.onOptionsItemSelected(item); }