List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.example.android.swiperefreshlistfragment.SwipeRefreshListFragmentFragment.java
/** * Respond to the user's selection of the Refresh action item. Start the SwipeRefreshLayout * progress bar, then initiate the background task that refreshes the content. * * <p>A color scheme menu item used for demonstrating the use of SwipeRefreshLayout's color * scheme functionality. This kind of menu item should not be incorporated into your app, * it just to demonstrate the use of color. Instead you should choose a color scheme based * off of your application's branding.// ww w. ja v a 2s.c om */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_refresh: Log.i(LOG_TAG, "Refresh menu item selected"); // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator if (!isRefreshing()) { setRefreshing(true); } // Start our refresh background task // initiateRefresh(); return true; case R.id.menu_color_scheme_1: Log.i(LOG_TAG, "setColorScheme #1"); item.setChecked(true); // Change the colors displayed by the SwipeRefreshLayout by providing it with 4 // color resource ids setColorScheme(R.color.color_scheme_1_1, R.color.color_scheme_1_2, R.color.color_scheme_1_3, R.color.color_scheme_1_4); return true; case R.id.menu_color_scheme_2: Log.i(LOG_TAG, "setColorScheme #2"); item.setChecked(true); // Change the colors displayed by the SwipeRefreshLayout by providing it with 4 // color resource ids setColorScheme(R.color.color_scheme_2_1, R.color.color_scheme_2_2, R.color.color_scheme_2_3, R.color.color_scheme_2_4); return true; case R.id.menu_color_scheme_3: Log.i(LOG_TAG, "setColorScheme #3"); item.setChecked(true); // Change the colors displayed by the SwipeRefreshLayout by providing it with 4 // color resource ids setColorScheme(R.color.color_scheme_3_1, R.color.color_scheme_3_2, R.color.color_scheme_3_3, R.color.color_scheme_3_4); return true; } return super.onOptionsItemSelected(item); }
From source file:com.sukenda.todoapp.module.task.statistics.StatisticsActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*w ww. ja va 2 s . c o m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.list_navigation_menu_item: Intent intent = new Intent(StatisticsActivity.this, TasksActivity.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); } startActivity(intent); break; case R.id.statistics_navigation_menu_item: // Do nothing, we're already on that screen break; default: break; } // Close the navigation drawer when an item is selected. menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:org.fundsofhope.androidapp.activities.MainActivity.java
public void selectDrawerItem(MenuItem menuItem) { Intent intent;//from ww w . ja v a2 s . c o m switch (menuItem.getItemId()) { case R.id.nav_first_fragment: intent = new Intent(this, MainActivity.class); break; case R.id.nav_second_fragment: intent = new Intent(this, TransitionFirstActivity.class); break; case R.id.nav_third_fragment: intent = new Intent(this, ProjectsActivity.class); break; default: intent = new Intent(this, MainActivity.class); break; } startActivity(intent); menuItem.setChecked(true); setTitle(menuItem.getTitle()); mDrawer.closeDrawers(); }
From source file:no.group09.ucsoftwarestore.MainFragmentActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_search: onSearchRequested();//from w ww . j a va 2s .c o m return true; case R.id.toggle_incompitable: //Prepare to edit the setting Editor edit = sharedPref.edit(); //Fetches the current value of the 'hide incompatible' option in the preference file boolean hideIncompatible = sharedPref.getBoolean("hide_incompatible", false); if (hideIncompatible == true) { //Changes the value and commits the changes edit.putBoolean("hide_incompatible", false); edit.commit(); item.setChecked(false); } else { //Changes the value and commits the changes edit.putBoolean("hide_incompatible", true); edit.commit(); item.setChecked(true); } pagerAdapter.all.update(); pagerAdapter.topHits.update(); pagerAdapter.notifyDataSetChanged(); return true; //Start the preferences class case R.id.settings: //Create an intent to start the preferences activity Intent myIntent = new Intent(getApplicationContext(), Preferences.class); this.startActivity(myIntent); return true; //Show the device list case R.id.device_list: Intent intent = new Intent(this, Devices.class); startActivity(intent); return true; default: return false; } }
From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java
public void showAudioPopup(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu();// w w w . j ava 2s . c o m menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio); final MenuItem backgroundAudioItem = menu.findItem(0); backgroundAudioItem.setCheckable(true); backgroundAudioItem.setChecked(enableBackgroundAudio); OnMenuItemClickListener clickListener = new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item == backgroundAudioItem) { enableBackgroundAudio = !item.isChecked(); return true; } return false; } }; configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO); popup.show(); }
From source file:com.example.matt.bingeList.viewControllers.activities.shows.TVShowBrowseActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_settings: return true; case R.id.card_view: PreferencesHelper.setRecyclerviewViewType(ViewType.CARD, getApplicationContext()); PreferencesHelper.printValues(getApplicationContext()); viewPager.setAdapter(mAdapterViewPager); item.setChecked(true); tabs.setupWithViewPager(viewPager); setTabDrawables();/*from ww w. ja v a 2 s . c o m*/ return true; case R.id.compact_view: PreferencesHelper.setRecyclerviewViewType(ViewType.COMPACT_CARD, getApplicationContext()); PreferencesHelper.printValues(getApplicationContext()); viewPager.setAdapter(mAdapterViewPager); item.setChecked(true); tabs.setupWithViewPager(viewPager); setTabDrawables(); return true; case R.id.list_view: PreferencesHelper.setRecyclerviewViewType(ViewType.LIST, getApplicationContext()); mAdapterViewPager.notifyDataSetChanged(); viewPager.setAdapter(mAdapterViewPager); item.setChecked(true); tabs.setupWithViewPager(viewPager); setTabDrawables(); return true; case R.id.light_theme: PreferencesHelper.setTheme(ThemeEnum.DAY_THEME, getApplicationContext()); item.setChecked(true); finish(); startActivity(getIntent()); ; return true; case R.id.dark_theme: PreferencesHelper.setTheme(ThemeEnum.NIGHT_THEME, getApplicationContext()); item.setChecked(true); finish(); startActivity(getIntent()); ; return true; case android.R.id.home: mNavigationDrawer.openDrawer(); return true; default: // If we got here, the user's action was not recognized. // Invoke the superclass to handle it. return super.onOptionsItemSelected(item); } }
From source file:com.coinblesk.client.MainActivity.java
private void initNavigationView() { NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view); if (navigationView == null) { Log.w(TAG, "Did not find navigation view!"); return;//from w w w. j a va 2 s .c om } //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.isChecked()) menuItem.setChecked(false); else menuItem.setChecked(true); //Closing drawer on item click drawerLayout.closeDrawers(); switch (menuItem.getItemId()) { case R.id.addresses: Intent addressesAct = new Intent(getApplicationContext(), AddressActivity.class); startActivity(addressesAct); return true; case R.id.additional_services: Intent additionalServicesAct = new Intent(getApplicationContext(), AdditionalServicesActivity.class); startActivity(additionalServicesAct); return true; case R.id.wallet: Intent walletAct = new Intent(getApplicationContext(), WalletActivity.class); startActivity(walletAct); return true; case R.id.backup: Intent backupAct = new Intent(getApplicationContext(), BackupActivity.class); startActivity(backupAct); return true; case R.id.settings: Intent newAct = new Intent(getApplicationContext(), SettingsActivity.class); startActivity(newAct); return (true); case R.id.about_coinblesk: Intent aboutAct = new Intent(getApplicationContext(), AboutActivity.class); startActivity(aboutAct); return true; default: Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); return true; } } }); // Initializing Drawer Layout and ActionBarToggle drawerLayout = (DrawerLayout) findViewById(R.id.drawer); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, null, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer opens, we don't need anything to happen yet, hence leave it blank super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer opens, we don't need anything to happen yet, hence leave it blank super.onDrawerOpened(drawerView); } }; //Setting the actionbarToggle to the drawerLayout drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessary because the menu icon wouldnt show up otheriwse actionBarDrawerToggle.syncState(); }
From source file:com.owncloud.android.ui.activity.DrawerActivity.java
/** * setup drawer content, basically setting the item selected listener. * * @param navigationView the drawers navigation view *//*w w w . jav a 2 s .c o m*/ protected void setupDrawerContent(NavigationView navigationView) { // Disable help or feedback on customization if (!getResources().getBoolean(R.bool.help_enabled)) { navigationView.getMenu().removeItem(R.id.drawer_menu_help); } if (!getResources().getBoolean(R.bool.feedback_enabled)) { navigationView.getMenu().removeItem(R.id.drawer_menu_feedback); } navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { mDrawerLayout.closeDrawers(); switch (menuItem.getItemId()) { case R.id.nav_all_files: menuItem.setChecked(true); mCheckedMenuItem = menuItem.getItemId(); allFilesOption(); // TODO activate when On Device branch is merged // MainApp.showOnlyFilesOnDevice(false); // refreshDirectory(); break; // TODO activate when On Device branch is merged // case R.id.nav_on_device: // menuItem.setChecked(true); // mCheckedMenuItem = menuItem.getItemId(); // MainApp.showOnlyFilesOnDevice(true); // refreshDirectory(); // break; case R.id.nav_uploads: Intent uploadListIntent = new Intent(getApplicationContext(), UploadListActivity.class); uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(uploadListIntent); break; case R.id.nav_settings: Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class); startActivity(settingsIntent); break; case R.id.drawer_menu_account_add: createAccount(false); break; case R.id.drawer_menu_account_manage: Intent manageAccountsIntent = new Intent(getApplicationContext(), ManageAccountsActivity.class); startActivityForResult(manageAccountsIntent, ACTION_MANAGE_ACCOUNTS); break; case R.id.drawer_menu_feedback: openFeedback(); break; case R.id.drawer_menu_help: openHelp(); break; case Menu.NONE: // account clicked accountClicked(menuItem.getTitle().toString()); default: Log_OC.i(TAG, "Unknown drawer menu item clicked: " + menuItem.getTitle()); } return true; } }); // handle correct state if (mIsAccountChooserActive) { navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, true); } else { navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, false); } }
From source file:com.sukenda.todoapp.module.task.tasks.TasksActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*w ww . ja v a2 s . c om*/ public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.list_navigation_menu_item: // Do nothing, we're already on that screen break; case R.id.statistics_navigation_menu_item: Intent intent = new Intent(TasksActivity.this, StatisticsActivity.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); } startActivity(intent); break; default: break; } // Close the navigation drawer when an item is selected. menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:fr.poucedor.poucedor.MapActivity.java
private void setupDrawerLayout() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); navigationView = (NavigationView) findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//www .j a va2 s. co m public boolean onNavigationItemSelected(MenuItem menuItem) { Intent intent; switch (menuItem.getItemId()) { case R.id.navdrawer_item_ranking: intent = new Intent(MapActivity.this, RankingActivity.class); startActivity(intent); return true; case R.id.navdrawer_item_settings: intent = new Intent(MapActivity.this, SettingsActivity.class); startActivity(intent); return true; default: Snackbar.make(content, menuItem.getTitle() + " pressed", Snackbar.LENGTH_LONG).show(); menuItem.setChecked(true); drawerLayout.closeDrawers(); return true; } } }); }