List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:io.mapsquare.osmcontributor.ui.activities.MapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); ((OsmTemplateApplication) getApplication()).getOsmTemplateComponent().inject(this); ButterKnife.bind(this); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); setSupportActionBar(toolbar);//from ww w . j a v a2s . c om eventBus.post(new UpdateFirstConnectionEvent()); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getGroupId()) { case R.id.drawer_options_group: onOptionsClick(menuItem); break; case R.id.sync: onOptionsSyncClick(menuItem); break; } return true; } }); filterView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.select_all_item) { selectAllMenuItem.setChecked(!selectAllMenuItem.isChecked()); onSelectAllClick(); } else if (menuItem.getItemId() != R.id.display_open_notes_item && menuItem.getItemId() != R.id.display_closed_notes_item) { menuItem.setChecked(!menuItem.isChecked()); onFilterItemClick(menuItem); } else { menuItem.setChecked(!menuItem.isChecked()); onNoteItemClick(menuItem); } return true; } }); selectAllMenuItem = filterView.getMenu().findItem(R.id.select_all_item); if (!FlavorUtils.isPoiStorage() && configManager.hasPoiModification()) { navigationView.getMenu().findItem(R.id.edit_way).setVisible(true); } if (configManager.hasPoiAddition()) { navigationView.getMenu().findItem(R.id.replay_tuto_menu).setVisible(true); } navigationView.getMenu().findItem(R.id.save_changes).setEnabled(false); drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { } @Override public void onDrawerOpened(View drawerView) { eventBus.post(new PleaseTellIfDbChanges()); } @Override public void onDrawerClosed(View drawerView) { } @Override public void onDrawerStateChanged(int newState) { } }); navigationView.getMenu().findItem(R.id.manage_poi_types) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { startPoiTypeEditionActivity(); return true; } }); // Get the arpi fragment. arpiGlFragment = (ArpiGlFragment) getFragmentManager().findFragmentById(R.id.engine_fragment); getFragmentManager().beginTransaction().hide(arpiGlFragment).commit(); if (sharedPreferences.getBoolean(getString(R.string.easter_egg), false)) { navigationView.getMenu().findItem(R.id.arpi_view).setVisible(true); } }
From source file:com.granita.tasks.TaskListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { //custom start if (item.getItemId() == R.id.removeads) { mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001, mPurchaseFinishedListener, "mypurchasetoken"); }/* www . ja v a 2s . c om*/ if (item.getItemId() == R.id.add_account) { Intent myIntent = new Intent(); myIntent.setClassName("com.granita.icloudcalsync", "com.granita.caldavsync.ui.setup.AddAccountActivity"); startActivity(myIntent); } //custom end if (item.getItemId() == R.id.menu_visible_list) { Intent settingsIntent = new Intent(getBaseContext(), SyncSettingsActivity.class); startActivity(settingsIntent); return true; } else if (item.getItemId() == R.id.menu_alarms) { // set and save state boolean activatedAlarms = !item.isChecked(); item.setChecked(activatedAlarms); AlarmBroadcastReceiver.setAlarmPreference(this, activatedAlarms); return true; } else { return super.onOptionsItemSelected(item); } }
From source file:github.popeen.dsub.activity.SubsonicActivity.java
private void populateServers() { drawerList.getMenu().clear();/*from w w w. j a v a 2 s .c o m*/ int serverCount = Util.getServerCount(this); int activeServer = Util.getActiveServer(this); for (int i = 1; i <= serverCount; i++) { MenuItem item = drawerList.getMenu().add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_BASE + i, MENU_ITEM_SERVER_BASE + i, Util.getServerName(this, i)); if (activeServer == i) { item.setChecked(true); } } drawerList.getMenu().setGroupCheckable(MENU_GROUP_SERVER, true, true); drawerHeaderToggle.setImageResource(R.drawable.main_select_tabs_dark); showingTabs = false; }
From source file:com.bt.heliniumstudentapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainContext = this; HeliniumStudentApp.setLocale(this); if (!isOnline() && PreferenceManager.getDefaultSharedPreferences(this).getString("schedule_0", null) == null) { //TODO Keep app running and display empty ScheduleFragment with retry option Toast.makeText(this, getResources().getString(R.string.error_conn_no) + ". " + getResources().getString(R.string.database_no) + ".", Toast.LENGTH_LONG).show(); finish();//from w ww .j av a 2 s . c om } else if ((PreferenceManager.getDefaultSharedPreferences(this).getString("username", null) == null || PreferenceManager.getDefaultSharedPreferences(this).getString("password", null) == null) && PreferenceManager.getDefaultSharedPreferences(this).getString("schedule_0", null) == null) { startActivity(new Intent(this, LoginActivity.class)); finish(); } else { setContentView(R.layout.activity_main); toolbarTB = (Toolbar) findViewById(R.id.tb_toolbar_am); drawerDL = (DrawerLayout) findViewById(R.id.dl_drawer_am); drawerNV = (NavigationView) findViewById(R.id.nv_drawer_am); containerFL = findViewById(R.id.fl_container_am); containerLL = findViewById(R.id.ll_container_am); statusLL = findViewById(R.id.ll_status_am); weekTV = (TextView) findViewById(R.id.tv_week_am); yearTV = (TextView) findViewById(R.id.tv_year_am); prevIV = (ImageView) findViewById(R.id.iv_prev_am); historyIV = (ImageView) findViewById(R.id.iv_select_am); nextIV = (ImageView) findViewById(R.id.iv_next_am); setColors( Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_theme", "0")), Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_primary", "4")), Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_accent", "14"))); setSupportActionBar(toolbarTB); toolbarTB.setBackgroundColor(ContextCompat.getColor(this, primaryColor)); drawerDLtoggle = new ActionBarDrawerToggle(this, drawerDL, toolbarTB, 0, 0); drawerDLtoggle.setDrawerIndicatorEnabled(false); Drawable navigationIcon = ContextCompat.getDrawable(this, R.drawable.ic_menu); navigationIcon.setColorFilter(ContextCompat.getColor(this, primaryTextColor), PorterDuff.Mode.SRC_ATOP); drawerDLtoggle.setHomeAsUpIndicator(navigationIcon); drawerDLtoggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawerDL.openDrawer(drawerNV); } }); drawerDLtoggle.syncState(); ((ProgressBar) findViewById(R.id.pb_progressbar_am)).getIndeterminateDrawable().setColorFilter( ContextCompat.getColor(this, accentPrimaryColor), android.graphics.PorterDuff.Mode.MULTIPLY); weekTV.setTextColor(ContextCompat.getColor(this, primaryTextColor)); yearTV.setTextColor(ContextCompat.getColor(this, secondaryTextColor)); prevIV.setColorFilter(ContextCompat.getColor(this, primaryTextColor)); historyIV.setColorFilter(ContextCompat.getColor(this, accentTextColor)); nextIV.setColorFilter(ContextCompat.getColor(this, primaryTextColor)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (themeColor == R.color.theme_dark) getWindow().setStatusBarColor(ContextCompat.getColor(this, themeColor)); else getWindow().setStatusBarColor(ContextCompat.getColor(this, themeDisabledTextColor)); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher), ContextCompat.getColor(this, themeColor))); ((GradientDrawable) ((RippleDrawable) prevIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, primaryColor)); //FIXME Improve this ridiculous workaround ((GradientDrawable) ((RippleDrawable) historyIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, accentPrimaryColor)); ((GradientDrawable) ((RippleDrawable) nextIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, primaryColor)); } else { ((GradientDrawable) prevIV.getBackground()).setColor(ContextCompat.getColor(this, primaryColor)); ((GradientDrawable) historyIV.getBackground()) .setColor(ContextCompat.getColor(this, accentPrimaryColor)); ((GradientDrawable) nextIV.getBackground()).setColor(ContextCompat.getColor(this, primaryColor)); } final ColorStateList drawerItemColorStateList = new ColorStateList( new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }, new int[] { ContextCompat.getColor(this, accentSecondaryColor), ContextCompat.getColor(this, themeSecondaryTextColor) }); FM = getSupportFragmentManager(); FM.beginTransaction().replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit(); drawerDL.setBackgroundResource(themeColor); drawerNV.setBackgroundResource(themeColor); containerLL.setBackgroundResource(primaryColor); drawerNV.setItemIconTintList(drawerItemColorStateList); drawerNV.setItemTextColor(drawerItemColorStateList); drawerNV.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) { drawerDL.closeDrawers(); new Handler().postDelayed(new Runnable() { @Override public void run() { switch (menuItem.getItemId()) { case R.id.i_schedule_md: menuItem.setChecked(true); if (!FM.findFragmentById(R.id.fl_container_am).getTag().equals("SCHEDULE")) { weekTV.setText(""); yearTV.setText(""); prevIV.setOnClickListener(null); historyIV.setOnClickListener(null); nextIV.setOnClickListener(null); FM.beginTransaction() .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE") .commit(); } break; case R.id.i_grades_md: menuItem.setChecked(true); if (!FM.findFragmentById(R.id.fl_container_am).getTag().equals("GRADES")) { weekTV.setText(""); yearTV.setText(""); prevIV.setOnClickListener(null); historyIV.setOnClickListener(null); nextIV.setOnClickListener(null); FM.beginTransaction() .replace(R.id.fl_container_am, new GradesFragment(), "GRADES").commit(); } break; case R.id.i_settings_md: startActivity(new Intent(mainContext, SettingsActivity.class)); break; case R.id.i_logout_md: if (isOnline()) { final AlertDialog.Builder logoutDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, themeDialog)); logoutDialogBuilder.setTitle(R.string.logout); logoutDialogBuilder.setMessage(R.string.logout_confirm); logoutDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ScheduleFragment.scheduleJson = null; GradesFragment.gradesHtml = null; PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("username", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("password", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_general_class", "0").apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_start_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_schedule_version_0", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_start_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_schedule_version_1", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("html_grades", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_grades_version", null).apply(); new Handler().postDelayed(new Runnable() { @Override public void run() { finish(); startActivity( new Intent(mainContext, MainActivity.class)); } }, HeliniumStudentApp.DELAY_RESTART); } }); logoutDialogBuilder.setNegativeButton(android.R.string.no, null); final AlertDialog logoutDialog = logoutDialogBuilder.create(); logoutDialog.setCanceledOnTouchOutside(true); logoutDialog.show(); logoutDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor( ContextCompat.getColor(mainContext, accentSecondaryColor)); logoutDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor( ContextCompat.getColor(mainContext, accentSecondaryColor)); } else { Toast.makeText(mainContext, R.string.error_conn_no, Toast.LENGTH_SHORT).show(); } break; case R.id.i_about_md: final AlertDialog.Builder aboutDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, themeDialog)); aboutDialogBuilder.setTitle(R.string.about); aboutDialogBuilder.setMessage(getResources().getString(R.string.app_name) + "\n\nCopyright (C) 2016 Bastiaan Teeuwen <bastiaan.teeuwen170@gmail.com>\n\n" + "This program is free software; you can redistribute it and/or " + "modify it under the terms of the GNU General Public License " + "as published by the Free Software Foundation; version 2 " + "of the License, or (at your option) any later version.\n\n" + "This program is distributed in the hope that it will be useful, " + "but WITHOUT ANY WARRANTY; without even the implied warranty of " + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " + "GNU General Public License for more details.\n\n" + "You should have received a copy of the GNU General Public License " + "along with this program; if not, write to the Free Software " + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA."); aboutDialogBuilder.setNeutralButton(R.string.website, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(HeliniumStudentApp.URL_WEBSITE))); } catch (ActivityNotFoundException e) { Toast.makeText(mainContext, "Couldn't find a browser", Toast.LENGTH_SHORT).show(); } } }); aboutDialogBuilder.setPositiveButton(R.string.github, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(HeliniumStudentApp.URL_GITHUB))); } catch (ActivityNotFoundException e) { Toast.makeText(mainContext, "Couldn't find a browser", Toast.LENGTH_SHORT).show(); } } }); aboutDialogBuilder.setNegativeButton(android.R.string.cancel, null); final AlertDialog aboutDialog = aboutDialogBuilder.create(); aboutDialog.setCanceledOnTouchOutside(true); aboutDialog.show(); ((TextView) aboutDialog.findViewById(android.R.id.message)).setTextSize(12); aboutDialog.getButton(AlertDialog.BUTTON_NEUTRAL) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); aboutDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); aboutDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); break; } } }, HeliniumStudentApp.DELAY_DRAWER); return true; } }); } }
From source file:com.vinidsl.googleioextended.ui.MainActivity.java
private void setupDrawerContent(final NavigationView navigationView) { navigationView.setItemIconTintList(getResources().getColorStateList(R.color.tint_selector)); navigationView.setItemTextColor(getResources().getColorStateList(R.color.tint_selector)); navigationView.getMenu().findItem(R.id.nav_explore).setChecked(true); if (PreferencesHelper.getBoolean(PreferencesHelper.FIRST_SYNC, this)) { changeFrameContent(new ExploreFragment()); }// w w w. j a v a 2 s.c o m navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (PreferencesHelper.getBoolean(PreferencesHelper.FIRST_SYNC, MainActivity.this)) { switch (menuItem.getItemId()) { case R.id.nav_map: PreferencesHelper.putInt(PreferencesHelper.MAP, 1, MainActivity.this); mDrawerLayout.closeDrawers(); Intent intent = new Intent(MainActivity.this, MapActivity.class); startActivity(intent); return true; case R.id.nav_diary: getSupportActionBar().setTitle(R.string.diary_title); changeFrameContent(new DiaryFragment()); break; case R.id.nav_explore: getSupportActionBar().setTitle(R.string.main_titlee); changeFrameContent(new ExploreFragment()); break; case R.id.nav_social: getSupportActionBar().setTitle(R.string.social_title); changeFrameContent(new SocialFragment()); break; case R.id.nav_about: getSupportActionBar().setTitle(R.string.about_title); changeFrameContent(new AboutFragment()); break; } menuItem.setChecked(true); } mDrawerLayout.closeDrawers(); return true; } }); }
From source file:com.esri.squadleader.view.SquadLeaderActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { SharedPreferences prefs = getPreferences(MODE_PRIVATE); String key = getString(R.string.pref_labels); if (!prefs.contains(key)) { prefs.edit().putBoolean(key, true).commit(); }//from w w w. jav a 2 s. c o m boolean labelsOn = prefs.getBoolean(key, true); if (null != mil2525cController) { mil2525cController.setShowLabels(labelsOn); } MenuItem menuItem_toggleLabels = menu.findItem(R.id.toggle_labels); menuItem_toggleLabels.setIcon(labelsOn ? R.drawable.ic_action_labels : R.drawable.ic_action_labels_off); menuItem_toggleLabels.setChecked(labelsOn); return super.onPrepareOptionsMenu(menu); }
From source file:com.jefftharris.passwdsafe.PasswdSafeOpenFileFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_file_open_help: { View root = getView();//from ww w . j av a 2s .c om if (root != null) { View help = root.findViewById(R.id.file_open_help_text); help.setVisibility((help.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE); GuiUtils.setKeyboardVisible(itsPasswordEdit, getContext(), false); } return true; } case R.id.menu_slot_1: { item.setChecked(true); itsYubiSlot = 1; return true; } case R.id.menu_slot_2: { item.setChecked(true); itsYubiSlot = 2; return true; } default: { return super.onOptionsItemSelected(item); } } }
From source file:it.rainbowbreeze.playtog.ui.MainActivity.java
public boolean onNavigationDrawerItemSelected(MenuItem menuItem) { final String TAG_START_GAME = "StartGame"; int menuId = menuItem.getItemId(); boolean checkItem; // update the main content by replacing fragments FragmentManager fragmentManager = getSupportFragmentManager(); Fragment finalFragment = null;/* w w w .j a v a 2s.c o m*/ String finalFragmentTAG = null; Intent intent = null; checkItem = false; switch (menuId) { case R.id.action_play: // Game fragment finalFragmentTAG = TAG_START_GAME; // Code to save memory, instead of recreating a new Fragment each time finalFragment = fragmentManager.findFragmentByTag(TAG_START_GAME); if (null == finalFragment) { mLogFacility.v(LOG_TAG, "Creating new instance of StartGameFragment"); finalFragment = new StartGameFragment(); } checkItem = true; break; case R.id.action_stats: Snackbar.make(mContent, "Stats aren't implemented yet!", Snackbar.LENGTH_SHORT).show(); break; case R.id.action_profile: // Profile activity intent = prepareSignInActivityIntent(true); break; case R.id.action_settings: Snackbar.make(mContent, "Settings aren't implemented yet!", Snackbar.LENGTH_SHORT).show(); break; default: break; } mDrawerLayout.closeDrawers(); if (checkItem) menuItem.setChecked(true); if (null != intent) { startActivity(intent); } else if (null != finalFragment) { fragmentManager.beginTransaction().replace(R.id.main_container, finalFragment, finalFragmentTAG) .commit(); } else { return false; } return true; }
From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_file_open_help: { View root = getView();/* w ww .j a va2 s . c o m*/ if (root != null) { GuiUtils.setKeyboardVisible(itsPasswordEdit, getContext(), false); PasswdSafeUtil.showInfoMsg(getResources().getString(R.string.file_open_help), getContext()); } return true; } case R.id.menu_slot_1: { item.setChecked(true); itsYubiSlot = 1; return true; } case R.id.menu_slot_2: { item.setChecked(true); itsYubiSlot = 2; return true; } case R.id.menu_slot_none: { item.setChecked(true); itsYubiSlot = 0; return true; } default: { return super.onOptionsItemSelected(item); } } }
From source file:com.hyperaware.conference.android.activity.MainActivity.java
@Override public boolean onNavigationItemSelected(final MenuItem menuItem) { Section section;/* w w w . j a va 2 s. co m*/ // TODO include mi_ values in Section and create a mapping switch (menuItem.getItemId()) { case R.id.mi_home: section = homeSection; break; case R.id.mi_agenda: section = agendaSection; break; case R.id.mi_speakers: section = speakersSection; break; case R.id.mi_attendees: section = attendeesSection; break; case R.id.mi_maps: section = mapsSection; break; case R.id.mi_tweets: section = tweetsSection; break; case R.id.mi_sponsors: section = sponsorsSection; break; case R.id.mi_event_info: section = eventInfoSection; break; case R.id.mi_about: section = aboutSection; break; default: section = null; break; } if (section != null) { menuItem.setChecked(true); showSection(section); } return true; }