List of usage examples for android.view MenuItem isChecked
public boolean isChecked();
From source file:com.battlelancer.seriesguide.ui.ActivityFragment.java
@SuppressLint("CommitPrefEdits") private void toggleFilterSetting(MenuItem item, String key) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); prefs.edit().putBoolean(key, !item.isChecked()).commit(); // refresh filter icon state getActivity().supportInvalidateOptionsMenu(); }
From source file:org.gnucash.android.ui.report.LineChartFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.isCheckable()) item.setChecked(!item.isChecked()); switch (item.getItemId()) { case R.id.menu_toggle_legend: mChart.getLegend().setEnabled(!mChart.getLegend().isEnabled()); mChart.invalidate();//w w w .ja va 2 s . c o m return true; case R.id.menu_toggle_average_lines: if (mChart.getAxisLeft().getLimitLines().isEmpty()) { for (LineDataSet set : mChart.getData().getDataSets()) { LimitLine line = new LimitLine(set.getYValueSum() / set.getEntryCount(), set.getLabel()); line.enableDashedLine(10, 5, 0); line.setLineColor(set.getColor()); mChart.getAxisLeft().addLimitLine(line); } } else { mChart.getAxisLeft().removeAllLimitLines(); } mChart.invalidate(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:spit.matrix2017.Activities.MainActivity.java
public void setupDrawerLayout() { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from w w w . ja v a 2s. c o m public boolean onNavigationItemSelected(MenuItem item) { drawerLayout.closeDrawers(); if (!item.isChecked()) { final FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit); switch (item.getItemId()) { case R.id.homepage_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { boolean isFragmentInStack = fm.popBackStackImmediate(backStageName, 0); if (!isFragmentInStack) { MainFragment fragment = MainFragment.newInstance(); fragmentTransaction.replace(R.id.fragment_container, fragment); backStageName = fragment.getClass().getName(); fragmentTransaction.addToBackStack(backStageName).commit(); } appBarLayout.setExpanded(true, true); collapsingToolbarLayout.setTitle("Matrix 17"); } }, DRAWER_DELAY); break; case R.id.favorites_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().popBackStackImmediate(); fragmentTransaction.replace(R.id.fragment_container, new FavoritesFragment()); appBarLayout.setExpanded(false, true); fragmentTransaction.addToBackStack(null).commit(); collapsingToolbarLayout.setTitle("Favorites"); } }, DRAWER_DELAY); break; case R.id.sponsors_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Coming soon!", Toast.LENGTH_SHORT).show(); // IMPORTANT: Remove checkable=false from the 'Sponsors' menu item in res/menu/navdrawer_menu.xml when Sponsors fragment is complete /* Delete later getSupportFragmentManager().popBackStackImmediate(); fragmentTransaction.replace(R.id.fragment_container, new SponsorsFragment()); appBarLayout.setExpanded(false, true); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); collapsingToolbarLayout.setTitle("Sponsors"); */ } }, DRAWER_DELAY); return true; //Replace by 'break' later case R.id.commitee_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().popBackStackImmediate(); fragmentTransaction.replace(R.id.fragment_container, new CommitteeFragment()); appBarLayout.setExpanded(false, true); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); collapsingToolbarLayout.setTitle("Committee"); } }, DRAWER_DELAY); break; case R.id.developers_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().popBackStackImmediate(); fragmentTransaction.replace(R.id.fragment_container, new DevelopersFragment()); appBarLayout.setExpanded(false, true); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); collapsingToolbarLayout.setTitle("Developers"); } }, DRAWER_DELAY); break; case R.id.contact_us_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().popBackStackImmediate(); fragmentTransaction.replace(R.id.fragment_container, new ContactUsFragment()); appBarLayout.setExpanded(false, true); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); collapsingToolbarLayout.setTitle("Contact us"); } }, DRAWER_DELAY); break; case R.id.share_app_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "Check out the official app for Matrix 17!\n\n" + getResources().getString(R.string.playstore_link)); intent.setType("text/plain"); startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_message))); } }, DRAWER_DELAY); return true; case R.id.rate_app_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(android.content.Intent.ACTION_VIEW); intent.setData(Uri.parse(getResources().getString(R.string.playstore_link))); startActivity(intent); } }, DRAWER_DELAY); return true; case R.id.about_menuItem: new Handler().postDelayed(new Runnable() { @Override public void run() { getSupportFragmentManager().popBackStackImmediate(); fragmentTransaction.replace(R.id.fragment_container, new AboutAppFragment()); appBarLayout.setExpanded(false, true); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); collapsingToolbarLayout.setTitle(getResources().getString(R.string.aboutapp)); } }, DRAWER_DELAY); } } return true; } }); }
From source file:org.csploit.android.plugins.PortScanner.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.scanner_custom_parameters: if (item.isChecked()) hideParametersField();//w w w . j av a 2 s. co m else displayParametersField(); item.setChecked(!item.isChecked()); return true; case R.id.select_ports: new InputDialog(getString(R.string.select_ports), getString(R.string.enter_ports_list), this, new InputDialogListener() { @Override public void onInputEntered(String input) { input = input.trim(); if (!input.isEmpty()) { String[] ports = input.split("[^\\d]+"); for (String port : ports) { try { if (port.isEmpty()) throw new Exception(getString(R.string.invalid_port_) + port + "'."); else { int iport = Integer.parseInt(port); if (iport <= 0 || iport > 65535) throw new Exception(getString(R.string.port_must_be_greater)); } } catch (Exception e) { new ErrorDialog("Error", e.toString(), PortScanner.this).show(); return; } } mCustomPorts = ""; for (int i = 0, last = ports.length - 1; i < ports.length; i++) { mCustomPorts += ports[i]; if (i != last) mCustomPorts += ","; } if (mCustomPorts.isEmpty()) { mCustomPorts = null; new ErrorDialog(getString(R.string.error), getString(R.string.invalid_ports), PortScanner.this).show(); } hideParametersField(); mMenu.findItem(R.id.scanner_custom_parameters).setChecked(false); Logger.debug("mCustomPorts = " + mCustomPorts); } else new ErrorDialog(getString(R.string.error), getString(R.string.empty_port_list), PortScanner.this).show(); } }).show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.sufficientlysecure.keychain.ui.EncryptFileActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.isCheckable()) { item.setChecked(!item.isChecked()); }//ww w .ja va 2 s.c o m switch (item.getItemId()) { case R.id.check_use_symmetric: mCurrentMode = item.isChecked() ? MODE_SYMMETRIC : MODE_ASYMMETRIC; updateModeFragment(); notifyUpdate(); break; case R.id.check_use_armor: mUseArmor = item.isChecked(); notifyUpdate(); break; case R.id.check_delete_after_encrypt: mDeleteAfterEncrypt = item.isChecked(); notifyUpdate(); break; default: return super.onOptionsItemSelected(item); } return true; }
From source file:com.hippo.ehviewer.ui.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem item) { // Don't select twice if (item.isChecked()) { return false; }//from w w w .j a va 2s. c o m int id = item.getItemId(); if (id == R.id.nav_homepage) { Bundle args = new Bundle(); args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE); startSceneFirstly(new Announcer(GalleryListScene.class).setArgs(args)); } else if (id == R.id.nav_whats_hot) { Bundle args = new Bundle(); args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_WHATS_HOT); startSceneFirstly(new Announcer(GalleryListScene.class).setArgs(args)); } else if (id == R.id.nav_favourite) { startScene(new Announcer(FavoritesScene.class)); } else if (id == R.id.nav_history) { startScene(new Announcer(HistoryScene.class)); } else if (id == R.id.nav_downloads) { startScene(new Announcer(DownloadsScene.class)); } else if (id == R.id.nav_settings) { Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); } if (id != R.id.nav_stub && mDrawerLayout != null) { mDrawerLayout.closeDrawers(); } return true; }
From source file:com.google.android.apps.forscience.whistlepunk.project.ProjectTabsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_include_archived) { item.setChecked(!item.isChecked()); mIncludeArchived = item.isChecked(); loadProjects();//w w w .j av a2 s. co m } return super.onOptionsItemSelected(item); }
From source file:org.gnucash.android.ui.report.BarChartFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.isCheckable()) item.setChecked(!item.isChecked()); switch (item.getItemId()) { case R.id.menu_toggle_legend: Legend legend = mChart.getLegend(); if (!legend.isLegendCustom()) { Toast.makeText(getActivity(), R.string.toast_legend_too_long, Toast.LENGTH_LONG).show(); } else {/* w ww . ja v a 2s . c om*/ legend.setEnabled(!mChart.getLegend().isEnabled()); mChart.invalidate(); } return true; case R.id.menu_percentage_mode: mTotalPercentageMode = !mTotalPercentageMode; int msgId = mTotalPercentageMode ? R.string.toast_chart_percentage_mode_total : R.string.toast_chart_percentage_mode_current_bar; Toast.makeText(getActivity(), msgId, Toast.LENGTH_LONG).show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.thaliproject.nativetest.app.MainActivity.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_main, menu); MenuItem menuItem_action_force_screen_on = menu.findItem(R.id.action_force_screen_on); menuItem_action_force_screen_on.setChecked(preferences.getBoolean(PREF_KEY_SCREEN_ON, false)); if (menuItem_action_force_screen_on.isChecked()) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } else {/*from w ww. j a va2s . c o m*/ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } return true; }
From source file:com.dogar.geodesic.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.delete_mode: reverseCheck(item);//from www .ja v a 2s . c o m SharedPreferencesUtils.setDeletePointsMode(item.isChecked(), this); return true; case R.id.menu_refresh: SyncUtils.triggerRefresh(this); return true; case R.id.map_terrain: reverseCheck(item); selectedMapID = id; bus.post(new MapTypeChangedEvent(GoogleMap.MAP_TYPE_TERRAIN)); return true; case R.id.map_normal: reverseCheck(item); selectedMapID = id; bus.post(new MapTypeChangedEvent(GoogleMap.MAP_TYPE_NORMAL)); return true; case R.id.map_hybrid: reverseCheck(item); selectedMapID = id; bus.post(new MapTypeChangedEvent(GoogleMap.MAP_TYPE_HYBRID)); return true; default: return super.onOptionsItemSelected(item); } }