List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:android_network.hetnet.vpn_service.ActivityLog.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); switch (item.getItemId()) { case android.R.id.home: Log.i(TAG, "Up"); NavUtils.navigateUpFromSameTask(this); return true; case R.id.menu_protocol_udp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_udp", item.isChecked()).apply(); updateAdapter();//from w ww . jav a 2s . com return true; case R.id.menu_protocol_tcp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_protocol_other: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_other", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_allowed: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_blocked: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_log_live: item.setChecked(!item.isChecked()); live = item.isChecked(); if (live) { DatabaseHelper.getInstance(this).addLogChangedListener(listener); updateAdapter(); } else DatabaseHelper.getInstance(this).removeLogChangedListener(listener); return true; case R.id.menu_refresh: updateAdapter(); return true; case R.id.menu_log_resolve: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("resolve", item.isChecked()).apply(); adapter.setResolve(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_log_organization: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("organization", item.isChecked()).apply(); adapter.setOrganization(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_pcap_enabled: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("pcap", item.isChecked()).apply(); ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this); return true; case R.id.menu_pcap_export: startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP); return true; case R.id.menu_log_clear: new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... objects) { DatabaseHelper.getInstance(ActivityLog.this).clearLog(); if (prefs.getBoolean("pcap", false)) { ServiceSinkhole.setPcap(false, ActivityLog.this); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); ServiceSinkhole.setPcap(true, ActivityLog.this); } else { if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); } return null; } @Override protected void onPostExecute(Object result) { if (running) updateAdapter(); } }.execute(); return true; case R.id.menu_log_support: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27")); if (getPackageManager().resolveActivity(intent, 0) != null) startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } }
From source file:eu.faircode.netguard.ActivityLog.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); switch (item.getItemId()) { case android.R.id.home: Log.i(TAG, "Up"); NavUtils.navigateUpFromSameTask(this); return true; case R.id.menu_protocol_udp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_udp", item.isChecked()).apply(); updateAdapter();/*w w w.j a v a 2 s . c om*/ return true; case R.id.menu_protocol_tcp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_protocol_other: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_other", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_allowed: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_blocked: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_log_live: item.setChecked(!item.isChecked()); live = item.isChecked(); if (live) { DatabaseHelper.getInstance(this).addLogChangedListener(listener); updateAdapter(); } else DatabaseHelper.getInstance(this).removeLogChangedListener(listener); return true; case R.id.menu_refresh: updateAdapter(); return true; case R.id.menu_log_resolve: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("resolve", item.isChecked()).apply(); adapter.setResolve(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_log_organization: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("organization", item.isChecked()).apply(); adapter.setOrganization(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_pcap_enabled: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("pcap", item.isChecked()).apply(); ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this); return true; case R.id.menu_pcap_export: startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP); return true; case R.id.menu_log_clear: new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... objects) { DatabaseHelper.getInstance(ActivityLog.this).clearLog(-1); if (prefs.getBoolean("pcap", false)) { ServiceSinkhole.setPcap(false, ActivityLog.this); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); ServiceSinkhole.setPcap(true, ActivityLog.this); } else { if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); } return null; } @Override protected void onPostExecute(Object result) { if (running) updateAdapter(); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return true; case R.id.menu_log_support: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27")); if (getPackageManager().resolveActivity(intent, 0) != null) startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.davidmiguel.gobees.apiaries.ApiariesActivity.java
/** * Set the actions to be carried out from the drawerLayout. *///ww w .ja va 2s. co m private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.settings_navigation_menu_item: // Settings openSettings(); break; case R.id.help_navigation_menu_item: // Help openHelp(); break; case R.id.feedback_navigation_menu_item: // Feedback openSendFeedback(); break; case R.id.share_app_navigation_menu_item: // Share app openShareApp(); break; case R.id.about_navigation_menu_item: // About openAbout(); break; default: break; } // Close the navigation drawer when an item is selected. menuItem.setChecked(false); drawerLayout.closeDrawers(); return true; } }); }
From source file:github.daneren2005.dsub.activity.SubsonicFragmentActivity.java
@Override public void onCreate(Bundle savedInstanceState) { if (savedInstanceState == null) { String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE); boolean firstRun = false; if (fragmentType == null) { fragmentType = Util.openToTab(this); if (fragmentType != null) { firstRun = true;//from w w w . j a v a 2 s .c om } } if ("".equals(fragmentType) || fragmentType == null || firstRun) { // Initial startup stuff if (!sessionInitialized) { loadSession(); } } } super.onCreate(savedInstanceState); if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { stopService(new Intent(this, DownloadService.class)); finish(); getImageLoader().clearCache(); } else if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) { getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, "Download"); lastSelectedPosition = R.id.drawer_downloading; } setContentView(R.layout.abstract_fragment_activity); UserUtil.seedCurrentUser(this); if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) { String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE); if (fragmentType == null) { fragmentType = Util.openToTab(this); if (fragmentType != null) { getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType); lastSelectedPosition = getDrawerItemId(fragmentType); } else { lastSelectedPosition = R.id.drawer_home; } MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition); if (item != null) { item.setChecked(true); } } currentFragment = getNewFragment(fragmentType); currentFragment.setPrimaryFragment(true); getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit(); if (getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) { SearchFragment fragment = new SearchFragment(); replaceFragment(fragment, fragment.getSupportTag()); } // If a album type is set, switch to that album type view String albumType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); if (albumType != null) { SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, albumType); args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20); args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); fragment.setArguments(args); replaceFragment(fragment, fragment.getSupportTag()); } } slideUpPanel = (SlidingUpPanelLayout) findViewById(R.id.slide_up_panel); panelSlideListener = new SlidingUpPanelLayout.PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) { } @Override public void onPanelCollapsed(View panel) { bottomBar.setVisibility(View.VISIBLE); nowPlayingToolbar.setVisibility(View.GONE); nowPlayingFragment.setPrimaryFragment(false); setSupportActionBar(mainToolbar); recreateSpinner(); } @Override public void onPanelExpanded(View panel) { currentFragment.stopActionMode(); // Disable custom view before switching getSupportActionBar().setDisplayShowCustomEnabled(false); bottomBar.setVisibility(View.GONE); nowPlayingToolbar.setVisibility(View.VISIBLE); setSupportActionBar(nowPlayingToolbar); nowPlayingFragment.setPrimaryFragment(true); drawerToggle.setDrawerIndicatorEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @Override public void onPanelAnchored(View panel) { } @Override public void onPanelHidden(View panel) { } }; slideUpPanel.setPanelSlideListener(panelSlideListener); if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD)) { // Post this later so it actually runs handler.postDelayed(new Runnable() { @Override public void run() { openNowPlaying(); } }, 200); } bottomBar = findViewById(R.id.bottom_bar); mainToolbar = (Toolbar) findViewById(R.id.main_toolbar); nowPlayingToolbar = (Toolbar) findViewById(R.id.now_playing_toolbar); coverArtView = (ImageView) bottomBar.findViewById(R.id.album_art); trackView = (TextView) bottomBar.findViewById(R.id.track_name); artistView = (TextView) bottomBar.findViewById(R.id.artist_name); setSupportActionBar(mainToolbar); if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) { nowPlayingFragment = new NowPlayingFragment(); FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); trans.add(R.id.now_playing_fragment_container, nowPlayingFragment, nowPlayingFragment.getTag() + ""); trans.commit(); } ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) { @Override protected Void doInBackground() throws Throwable { if (getDownloadService() == null) { return null; } getDownloadService().previous(); return null; } }.execute(); } }); startButton = (ImageButton) findViewById(R.id.download_start); startButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) { @Override protected Void doInBackground() throws Throwable { PlayerState state = getDownloadService().getPlayerState(); if (state == PlayerState.STARTED) { getDownloadService().pause(); } else { getDownloadService().start(); } return null; } }.execute(); } }); ImageButton nextButton = (ImageButton) findViewById(R.id.download_next); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) { @Override protected Void doInBackground() throws Throwable { if (getDownloadService() == null) { return null; } getDownloadService().next(); return null; } }.execute(); } }); }
From source file:com.android.mms.ui.SelectRecipientsList.java
@Override public boolean onOptionsItemSelected(MenuItem item) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); switch (item.getItemId()) { case MENU_DONE: Intent intent = new Intent(); putExtraWithContact(intent);/* w ww .ja va 2 s . c om*/ setResult(RESULT_OK, intent); finish(); return true; case MENU_MOBILE: // If it was checked before it should be unchecked now and vice versa mMobileOnly = !mMobileOnly; item.setChecked(mMobileOnly); prefs.edit().putBoolean(PREF_MOBILE_NUMBERS_ONLY, mMobileOnly).commit(); if (mContactFragment != null) { mContactFragment.setIsMobileOnly(mMobileOnly); } // Restart the loader to reflect the change getLoaderManager().restartLoader(0, null, this); return true; case MENU_NAME_ORDER: int currOrder = mContactsPreferences.getSortOrder(); int newOrder = currOrder == ContactsPreferences.SORT_ORDER_ALTERNATIVE ? ContactsPreferences.SORT_ORDER_PRIMARY : ContactsPreferences.SORT_ORDER_ALTERNATIVE; mContactsPreferences.setSortOrder(newOrder); invalidateOptionsMenu(); // Restart the loader to reflect the change getLoaderManager().restartLoader(0, null, this); return true; case android.R.id.home: //avoid start compose screen with empty intent. setResult(RESULT_CANCELED, null); finish(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.ht117.dina.activities.MainActivity.java
private void updatePosition(final MenuItem menuItem) { runnable = null;/*from ww w . j a va 2 s.c om*/ switch (menuItem.getItemId()) { case R.id.nav_library: runnable = navigateLibrary; break; case R.id.nav_playlists: runnable = navigatePlaylist; break; case R.id.nav_folders: runnable = navigateFolder; break; case R.id.nav_nowplaying: NavigationUtils.navigateToNowplaying(MainActivity.this, false); break; case R.id.nav_queue: runnable = navigateQueue; break; case R.id.nav_settings: NavigationUtils.navigateToSettings(MainActivity.this); break; } if (runnable != null) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { runnable.run(); } }, 350); } }
From source file:com.granita.tasks.TaskListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); if (itemId == R.id.menu_add_task) { mCallbacks.onAddNewTask();/*from www .j a va 2 s . c o m*/ return true; } else if (itemId == R.id.menu_show_completed) { mSavedCompletedFilter = !mSavedCompletedFilter; item.setChecked(mSavedCompletedFilter); mAdapter.setChildCursorFilter(mSavedCompletedFilter ? null : COMPLETED_FILTER); // reload the child cursors only for (int i = 0; i < mAdapter.getGroupCount(); ++i) { mAdapter.reloadGroup(i); } return true; } else if (itemId == R.id.menu_sync_now) { doSyncNow(); return true; } else { return super.onOptionsItemSelected(item); } }
From source file:br.com.gabrielmonteiro.urbancoffee.view.activity.MainActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override/* w ww . jav a2 s . c om*/ public boolean onNavigationItemSelected(MenuItem item) { Class fragmentClass = null; boolean isAlert = false; int id = item.getItemId(); if (id == R.id.nav_store) { fragmentClass = StoreFragment.class; } else if (id == R.id.nav_payments) { fragmentClass = PaymentsListFragment.class; } else if (id == R.id.nav_license) { fragmentClass = LicenseFragment.class; } else if (id == R.id.nav_about) { isAlert = true; } if (isAlert) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(getString(R.string.about_text_title)); alertDialogBuilder.setMessage(getString(R.string.about_text_msg)); alertDialogBuilder.setNeutralButton(getString(R.string.ok), getNegativeAction()); alertDialogBuilder.show(); } else { openFragment(fragmentClass); item.setChecked(true); setTitle(item.getTitle()); } drawer.closeDrawer(GravityCompat.START); return true; }
From source file:de.aw.monma.wertpapier.FragmentWertpapierUebersicht.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_sortieren_name: sortOrder = NAME;// ww w . ja v a 2 s .co m break; case R.id.menu_item_sortieren_bestand: sortOrder = BESTAND; break; case R.id.menu_item_sortieren_marktwert: sortOrder = MARKTWERT; break; case R.id.menu_item_sortieren_einstandspreis: sortOrder = EINSTAND; break; case R.id.menu_item_sortieren_gewinn: sortOrder = GEWINN; break; case R.id.menu_item_sortieren_gewinn_perc: sortOrder = GEWINNPERC; break; default: return super.onOptionsItemSelected(item); } item.setChecked(true); getAdapter().swap(itemList); return true; }
From source file:com.example.android.foldinglayout.FoldingLayoutActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.animate_fold: animateFold();/*from w w w.j a va2s. com*/ break; case R.id.toggle_orientation: mOrientation = (mOrientation == Orientation.HORIZONTAL) ? Orientation.VERTICAL : Orientation.HORIZONTAL; item.setTitle((mOrientation == Orientation.HORIZONTAL) ? R.string.vertical : R.string.horizontal); mTranslation = 0; mFoldLayout.setOrientation(mOrientation); break; case R.id.camera_feed: if (mTextureView != null) { mIsCameraFeed = !mIsCameraFeed; item.setTitle(mIsCameraFeed ? R.string.static_image : R.string.camera_feed); item.setChecked(mIsCameraFeed); if (mIsCameraFeed) { mFoldLayout.removeView(mImageView); mFoldLayout.addView(mTextureView, new ViewGroup.LayoutParams(mFoldLayout.getWidth(), mFoldLayout.getHeight())); } else { mFoldLayout.removeView(mTextureView); mFoldLayout.addView(mImageView, new ViewGroup.LayoutParams(mFoldLayout.getWidth(), mFoldLayout.getHeight())); } mTranslation = 0; } break; case R.id.sepia: mIsSepiaOn = !mIsSepiaOn; item.setChecked(!mIsSepiaOn); if (mIsSepiaOn && mFoldLayout.getFoldFactor() != 0) { setSepiaLayer(mFoldLayout.getChildAt(0), true); } else { setSepiaLayer(mFoldLayout.getChildAt(0), false); } break; default: break; } return super.onOptionsItemSelected(item); }