List of usage examples for android.view Menu getItem
public MenuItem getItem(int index);
From source file:com.avapira.bobroreader.Bober.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { boolean valToSetVisibility = !boardsDrawer.isDrawerOpen(); for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(valToSetVisibility); }// w ww . j ava 2 s . c o m return true; }
From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java
private void onDrawerItemClicked(@IdRes final int item, boolean userClicked) { if (mDrawerItemSelected == item && userClicked) { mDrawerLayout.closeDrawer(mDrawerView); return;/*from w w w .j av a2s.c om*/ } if (isItemAFragment(item)) { mDrawerItemSelected = item; // Animate if user clicked hideFragments(userClicked); Menu menu = mDrawerView.getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem menuItem = menu.getItem(i); menuItem.setChecked(menuItem.getItemId() == item); } } if (mDrawerLayout.isDrawerOpen(mDrawerView)) { mPending = new Runnable() { @Override public void run() { performDrawerItemSelection(item); } }; } else { performDrawerItemSelection(item); } mDrawerLayout.closeDrawer(mDrawerView); }
From source file:io.demiseq.jetreader.activities.MainActivity.java
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent);// w w w . j a v a2 s .co m boolean isOpenFromNotification = intent.getBooleanExtra("favorite", false); if (isOpenFromNotification) { GetSubscription(); new getAllMangas().execute(); NavigationView view = (NavigationView) findViewById(R.id.navigation_view); Menu menu = view.getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (item.getItemId() == R.id.drawer_feeds) { savedMenuId = item.getItemId(); item.setChecked(true); } } } }
From source file:org.getlantern.firetweet.util.ThemeUtils.java
public static void wrapMenuIcon(Context context, int backgroundColor, int popupBackgroundColor, Menu menu, int... excludeGroups) { final Resources resources = context.getResources(); final int colorDark = resources.getColor(R.color.action_icon_dark); final int colorLight = resources.getColor(R.color.action_icon_light); final int itemColor = ColorUtils.getContrastYIQ(backgroundColor, colorDark, colorLight); final int popupItemColor = ColorUtils.getContrastYIQ(popupBackgroundColor, colorDark, colorLight); for (int i = 0, j = menu.size(), k = 0; i < j; i++) { final MenuItem item = menu.getItem(i); wrapMenuItemIcon(item, itemColor, excludeGroups); if (item.hasSubMenu()) { wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups); }// www. j a v a2 s . c o m if (item.isVisible()) { k++; } } }
From source file:com.alainesp.fan.sanderson.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { staticRef = this; super.onCreate(savedInstanceState); DB.currentContext = this; setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w .j av a 2 s . com DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); navigationView = (NavigationView) findViewById(R.id.nav_view); Menu drawerMenu = navigationView.getMenu(); // Create the hashtable reverseMenuText.clear(); for (int i = 0; i < drawerMenu.size(); i++) reverseMenuText.put(drawerMenu.getItem(i).getTitle().toString(), i); navigationView.setNavigationItemSelectedListener(this); // 2 listeners to show the badges navigationView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View vv, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { setBadgesNumberUI(); } }); ((NavigationMenuView) navigationView.getChildAt(0)) .addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); setBadgesNumberUI(); } }); // Select Summary at the beginning loadBadgeNumbers(); // Try to load the state in which the app was if (savedInstanceState != null) app_state = savedInstanceState.getInt(APP_FRAGMENT_INDEX); else { Intent intent = getIntent(); if (intent != null) app_state = intent.getIntExtra(APP_FRAGMENT_INDEX, -2); if (app_state == -2) app_state = APP_STATE_SUMMARY; } if (app_state == APP_STATE_ABOUT) onAboutClick(null); else navigateTo((app_state)); }
From source file:org.thaliproject.nativetest.app.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (mPeerListFragment != null) { MenuUtils.PeerMenuItemsAvailability availability = MenuUtils.resolvePeerMenuItemsAvailability( mPeerListFragment.getSelectedPeerProperties(), PeerAndConnectionModel.getInstance()); MenuItem connectMenuItem = menu.getItem(0); MenuItem sendDataMenuItem = menu.getItem(1); MenuItem disconnectMenuItem = menu.getItem(2); MenuItem killAllConnectionsMenuItem = menu.getItem(3); connectMenuItem.setVisible(availability.connectMenuItemAvailable); connectMenuItem.setEnabled(availability.connectMenuItemAvailable); sendDataMenuItem.setVisible(availability.sendDataMenuItemAvailable); sendDataMenuItem.setEnabled(availability.sendDataMenuItemAvailable); disconnectMenuItem.setEnabled(availability.disconnectMenuItemAvailable); killAllConnectionsMenuItem.setEnabled(availability.killAllConnectionsMenuItemAvailable); return true; }//from ww w. j ava2 s .c om return false; }
From source file:com.jwetherell.quick_response_code.EncoderActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_contextual_invitar, menu); if (settings.getString("modelo", "").equals("amper")) { menu.getItem(1).setVisible(false); }//from w w w. j a va 2s . c o m return true; }
From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { for (int index = 0; index < menu.size(); index++) { menu.getItem(index).setVisible(false); }//from w ww . ja v a 2 s. com getActivity().getActionBar().setDisplayShowTitleEnabled(true); getActivity().getActionBar().setTitle(getString(R.string.formula_editor_title)); super.onPrepareOptionsMenu(menu); }
From source file:cw.kop.autobackground.tutorial.ActionBarFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tutorial_action_bar_fragment, container, false); int colorFilterInt = AppSettings.getColorFilterInt(appContext); Toolbar buttonToolbar = (Toolbar) view.findViewById(R.id.button_toolbar); buttonToolbar.setTitleTextAppearance(appContext, R.style.ToolbarTitle); buttonToolbar.inflateMenu(R.menu.source_list_menu); Menu menu = buttonToolbar.getMenu(); Drawable refreshIcon = getResources().getDrawable(R.drawable.ic_refresh_white_24dp); Drawable downloadIcon = getResources().getDrawable(R.drawable.ic_file_download_white_24dp); Drawable storageIcon = getResources().getDrawable(R.drawable.ic_sort_white_24dp); refreshIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY); downloadIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY); storageIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY); menu.getItem(0).setIcon(refreshIcon); menu.getItem(1).setIcon(downloadIcon); menu.getItem(2).setIcon(storageIcon); TextView buttonTitleText = (TextView) view.findViewById(R.id.button_title_text); buttonTitleText.setTextColor(colorFilterInt); buttonTitleText.setText("ActionBar buttons"); TextView buttonTutorialText = (TextView) view.findViewById(R.id.button_tutorial_text); buttonTutorialText.setTextColor(colorFilterInt); buttonTutorialText.setText("Cycle wallpaper, download new images, and sort sources. " + "Hit download after adding some sources to fetch the images."); Toolbar settingToolbar = (Toolbar) view.findViewById(R.id.setting_toolbar); Drawable navIcon = getResources().getDrawable(R.drawable.drawer_menu_white); navIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY); settingToolbar.setNavigationIcon(navIcon); TextView settingTitleText = (TextView) view.findViewById(R.id.setting_title_text); settingTitleText.setTextColor(colorFilterInt); settingTitleText.setText("More settings"); TextView settingTutorialText = (TextView) view.findViewById(R.id.setting_tutorial_text); settingTutorialText.setTextColor(colorFilterInt); settingTutorialText.setText("Open the drawer to access additional settings."); return view;/* ww w. jav a 2s .c o m*/ }
From source file:net.named_data.accessmanager.DrawerFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); // Remove option menu items when drawer is sliding out if (m_shouldHideOptionsMenu) { for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(false); }//w ww. ja v a2 s. c o m } }