List of usage examples for android.view MenuItem getSubMenu
public SubMenu getSubMenu();
From source file:com.eugene.fithealthmaingit.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) { mNavItemId = savedInstanceState.getInt(NAV_ITEM_ID); isFirstFragmentAdded = savedInstanceState.getBoolean(FIRST_FRAGMENT_ADDED); } else {/*from w w w .j ava 2s . co m*/ mNavItemId = R.id.nav_journal; } mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); // Set menu header text to User Name TextView mHeaderText = (TextView) findViewById(R.id.txtName); mHeaderText.setText(PreferenceManager.getDefaultSharedPreferences(this).getString(Globals.USER_NAME, "")); /** * Initiate NavigationView * Inflate Menu based on FitBit connection status */ NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav); if (PreferenceManager.getDefaultSharedPreferences(this).getString("FITBIT_ACCESS_TOKEN", "").equals("")) { mNavigationView.inflateMenu(R.menu.drawer); } else { mNavigationView.inflateMenu(R.menu.drawer_fitbit); } mNavigationView.getMenu().findItem(mNavItemId).setChecked(true); mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() != R.id.nav_settings) { mNavItemId = menuItem.getItemId(); switchFragment(menuItem.getItemId()); menuItem.setChecked(true); Fragment loading = new FragmentBlankLoading(); Bundle b = new Bundle(); b.putInt(NAV_ITEM_ID, mNavItemId); loading.setArguments(b); getSupportFragmentManager().beginTransaction().replace(R.id.container, loading).commit(); } else { startActivity(new Intent(MainActivity.this, UserInformationActivity.class)); } handleNavigationDrawer(); return false; } }); // Nav Menu Fonts Menu m = mNavigationView.getMenu(); for (int i = 0; i < m.size(); i++) { MenuItem mi = m.getItem(i); //for aapplying a font to subMenu ... SubMenu subMenu = mi.getSubMenu(); if (subMenu != null && subMenu.size() > 0) { for (int j = 0; j < subMenu.size(); j++) { MenuItem subMenuItem = subMenu.getItem(j); applyFontToMenuItem(subMenuItem); } } //the method we have create in activity applyFontToMenuItem(mi); } switchFragment(mNavItemId); /** * Handles Home Screen Widget * Search and Add */ Intent widgetIntent = this.getIntent(); if (widgetIntent != null) { if (widgetIntent.getAction() != null && savedInstanceState == null) { if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_SEARCH)) { // Post delay to allow the app to open and not interfere with animation final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().beginTransaction() .replace(R.id.containerSearch, new FragmentSearch()).addToBackStack(null) .commit(); } }, 100); } if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_ADD)) { widgetAdd(); } } } }
From source file:org.mariotaku.twidere.fragment.UserListsListFragment.java
@Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { if (mApplication.isMultiSelectActive()) return true; mSelectedUserList = null;//from www . j a va2 s .com final ListAdapter adapter = getListAdapter(); final Object selected = adapter.getItem(position - mListView.getHeaderViewsCount()); mSelectedUserList = selected instanceof ParcelableUserList ? (ParcelableUserList) selected : null; if (mSelectedUserList == null) return false; mPopupMenu = PopupMenu.getInstance(getActivity(), view); mPopupMenu.inflate(R.menu.action_user_list); final Menu menu = mPopupMenu.getMenu(); final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU); if (extensions != null) { final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST); final Bundle extras = new Bundle(); extras.putParcelable(INTENT_KEY_USER_LIST, mSelectedUserList); intent.putExtras(extras); addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent); } mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.show(); return true; }
From source file:org.mariotaku.twidere.fragment.BaseUserListsListFragment.java
@Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { if (mApplication.isMultiSelectActive()) return true; mSelectedUserList = null;/*from w ww .ja v a 2s . co m*/ final UserListsAdapter adapter = getListAdapter(); mSelectedUserList = adapter.findItem(id); mPopupMenu = PopupMenu.getInstance(getActivity(), view); mPopupMenu.inflate(R.menu.action_user_list); final Menu menu = mPopupMenu.getMenu(); final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU); if (extensions != null) { final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST); final Bundle extras = new Bundle(); extras.putParcelable(INTENT_KEY_USER_LIST, mSelectedUserList); intent.putExtras(extras); addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent); } mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.show(); return true; }
From source file:org.mariotaku.gallery3d.ImageViewerGLActivity.java
void updateShareIntent() { final MenuItem item = mMenuBar.getMenu().findItem(MENU_SHARE); if (item == null || !item.hasSubMenu()) return;/* www . j av a 2 s.c o m*/ final SubMenu subMenu = item.getSubMenu(); subMenu.clear(); final Intent intent = getIntent(); final Uri uri = intent.getData(); final Intent shareIntent = new Intent(Intent.ACTION_SEND); if (mImageFile != null && mImageFile.exists()) { shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImageFile)); } else { shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, uri.toString()); } Utils.addIntentToMenu(this, subMenu, shareIntent); }
From source file:org.mariotaku.twidere.fragment.BaseUsersListFragment.java
@Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { mSelectedUser = null;/*from ww w .j a va 2 s . c o m*/ final UsersAdapter adapter = getListAdapter(); mSelectedUser = adapter.findItem(id); if (mApplication.isMultiSelectActive()) { final NoDuplicatesLinkedList<Object> list = mApplication.getSelectedItems(); if (!list.contains(mSelectedUser)) { list.add(mSelectedUser); } else { list.remove(mSelectedUser); } return true; } mPopupMenu = PopupMenu.getInstance(getActivity(), view); mPopupMenu.inflate(R.menu.action_user); final Menu menu = mPopupMenu.getMenu(); final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU); if (extensions != null) { final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(INTENT_KEY_USER, mSelectedUser); intent.putExtras(extras); addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent); } mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.show(); return true; }
From source file:com.beem.project.beem.ui.ContactListFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { Intent in;/*from w w w . ja v a2s . co m*/ boolean result = false; if (mSelectedContact != null) { switch (item.getItemId()) { case R.id.contact_list_context_menu_chat_item: List<String> res = mSelectedContact.getMRes(); if (res.isEmpty()) { break; } for (String resv : res) { in = new Intent(hostActivity, Chat.class); in.setData(mSelectedContact.toUri(resv)); item.getSubMenu().add(resv).setIntent(in); } result = true; break; case R.id.contact_list_context_menu_call_item: hostActivity.doContextMenuAction(item.getItemId(), mSelectedContact); break; case R.id.contact_list_context_menu_user_info: item.getSubMenu().setHeaderTitle(mSelectedContact.getJID()); result = true; break; case R.id.contact_list_context_menu_userinfo_alias: hostActivity.doContextMenuAction(item.getItemId(), mSelectedContact); result = true; break; case R.id.contact_list_context_menu_userinfo_group: in = new Intent(hostActivity, GroupList.class); in.putExtra("contact", mSelectedContact); startActivity(in); result = true; break; case R.id.contact_list_context_menu_userinfo_subscription: hostActivity.doContextMenuAction(item.getItemId(), mSelectedContact); result = true; break; case R.id.contact_list_context_menu_userinfo_block: result = true; break; case R.id.contact_list_context_menu_userinfo_delete: hostActivity.doContextMenuAction(item.getItemId(), mSelectedContact); result = true; break; default: result = super.onContextItemSelected(item); break; } return result; } return super.onContextItemSelected(item); }
From source file:hu.zelena.guide.MainActivity.java
@Override public void onBackPressed() { if (mDrawer.isDrawerOpen(GravityCompat.START)) { mDrawer.closeDrawers();/*from w ww . ja v a 2s . 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:paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity.java
private void UpdateButtonMenu(MenuListView listView, int menuItemId) { MenuItem buttonGroupItem = listView.getMenu().findItem(R.id.menuItem_buttons); if (buttonGroupItem != null && listView.getMenu().findItem(menuItemId) != null) { buttonGroupItem.getSubMenu().removeItem(menuItemId); }//w w w .j av a 2 s.co m }
From source file:android.support.v7.internal.view.menu.ActionMenuPresenter.java
@Override public void onRestoreInstanceState(Parcelable state) { SavedState saved = (SavedState) state; if (saved.openSubMenuId > 0) { MenuItem item = mMenu.findItem(saved.openSubMenuId); if (item != null) { SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); onSubMenuSelected(subMenu);//from w w w . ja v a2 s . c o m } } }
From source file:android.support.v7.view.menu.CascadingMenuPopup.java
/** * Returns the menu item within the specified parent menu that owns * specified submenu.// ww w. j a va2 s .c o m * * @param parent the parent menu * @param submenu the submenu for which the index should be returned * @return the menu item that owns the submenu, or {@code null} if not * present */ private MenuItem findMenuItemForSubmenu(@NonNull MenuBuilder parent, @NonNull MenuBuilder submenu) { for (int i = 0, count = parent.size(); i < count; i++) { final MenuItem item = parent.getItem(i); if (item.hasSubMenu() && submenu == item.getSubMenu()) { return item; } } return null; }