List of usage examples for android.view MenuItem isChecked
public boolean isChecked();
From source file:us.cboyd.android.dicom.DcmBrowser.java
/** onMenuItemSelected handles if something from the options menu is selected */ @Override/* w ww . j a va2s .c o m*/ public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case R.id.app_about: Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_about); dialog.setTitle(getResources().getString(R.string.app_name)); dialog.show(); return true; case R.id.show_hidden: item.setChecked(!item.isChecked()); mListFragment.setHidden(item.isChecked()); return true; case R.id.show_info: item.setChecked(!item.isChecked()); mInfoFragment.refreshTagList(item.isChecked()); return true; case R.id.debug_mode: item.setChecked(!item.isChecked()); mInfoFragment.changeMode(item.isChecked()); return true; default: return super.onMenuItemSelected(featureId, item); } }
From source file:com.irateam.vkplayer.activities.ListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); emptyView = findViewById(R.id.empty_list_view); emptyView.setVisibility(View.GONE); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* w w w . j a va2 s .c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(v -> drawerLayout.openDrawer(GravityCompat.START)); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); navigationView = (NavigationView) findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(this); roundImageView = (RoundImageView) findViewById(R.id.navigation_drawer_header_avatar); userFullName = (TextView) findViewById(R.id.navigation_drawer_header_full_name); userVkId = (TextView) findViewById(R.id.navigation_drawer_header_id); new UserService(this).getCurrentUser((user) -> { ImageLoader.getInstance().displayImage(user.photo_100, roundImageView); userFullName.setText(user.first_name + " " + user.last_name); userVkId.setText(UserService.USER_LINK + String.valueOf(user.id)); }); ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawerLayout.setDrawerListener(drawerToggle); drawerToggle.syncState(); coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout); playerController = new PlayerController(this, findViewById(R.id.player_panel)); playerController.rootView.setVisibility(View.GONE); playerController.setFabOnClickListener(v -> startActivity(new Intent(this, AudioActivity.class))); refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout); refreshLayout.setColorSchemeResources(R.color.accent, R.color.primary); refreshLayout.setOnRefreshListener(() -> { if (actionMode != null) actionMode.finish(); if (audioAdapter.isSortMode()) audioAdapter.setSortMode(false); audioService.repeatLastRequest(); }); listView = (DragSortListView) findViewById(R.id.list); listView.setAdapter(audioAdapter); listView.setOnItemClickListener((parent, view, position, id) -> { List<Audio> list = audioAdapter.getListByPosition(position); playerService.setPlaylist(list); playerService.play(audioAdapter.getPosition(position)); if (actionMode != null) actionMode.finish(); MenuItem item = navigationView.getMenu().getItem(0); boolean isFromSearch = audioAdapter.belongsToSearchList(position); if (!isFromSearch) { item.setChecked(true); getSupportActionBar().setTitle(item.getTitle()); } if (!isFromSearch || item.isChecked()) { audioAdapter.setOriginalList(list); } }); listView.setOnItemLongClickListener((parent, view, position, id) -> { performCheck(position); return true; }); listView.setDropListener(audioAdapter::drop); audioAdapter.setCoverCheckListener(this::performCheck); audioService.addListener(this); downloadFinishedReceiver = new DownloadFinishedReceiver() { @Override public void onDownloadFinished(Audio audio) { audioAdapter.updateAudioById(audio); } }; registerReceiver(downloadFinishedReceiver, new IntentFilter(DownloadService.DOWNLOAD_FINISHED)); startService(new Intent(this, PlayerService.class)); bindService(new Intent(this, PlayerService.class), this, BIND_AUTO_CREATE); }
From source file:com.ichi2.anki.Statistics.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case R.id.item_time_month: if (item.isChecked()) item.setChecked(false);/* w w w . j ava2 s . c om*/ else item.setChecked(true); if (mTaskHandler.getStatType() != Stats.TYPE_MONTH) { mTaskHandler.setStatType(Stats.TYPE_MONTH); mSectionsPagerAdapter.notifyDataSetChanged(); } return true; case R.id.item_time_year: if (item.isChecked()) item.setChecked(false); else item.setChecked(true); if (mTaskHandler.getStatType() != Stats.TYPE_YEAR) { mTaskHandler.setStatType(Stats.TYPE_YEAR); mSectionsPagerAdapter.notifyDataSetChanged(); } return true; case R.id.item_time_all: if (item.isChecked()) item.setChecked(false); else item.setChecked(true); if (mTaskHandler.getStatType() != Stats.TYPE_LIFE) { mTaskHandler.setStatType(Stats.TYPE_LIFE); mSectionsPagerAdapter.notifyDataSetChanged(); } return true; case R.id.action_time_chooser: //showTimeDialog(); return true; } return super.onOptionsItemSelected(item); }
From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java
private void setupGpsMenu(MenuItem item) { item.setChecked(gpsListener.isFollowing()); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override/*from w w w . j a v a 2s. com*/ public boolean onMenuItemClick(MenuItem item) { item.setChecked(!item.isChecked()); gpsListener.setFollowing(item.isChecked()); MapScreen.this.invalidateOptionsMenu(); return true; } }); }
From source file:com.jadebyte.popularmovies.activities.MainActivity.java
private void showLabelsPopup() { View view = findViewById(R.id.action_sort); PopupMenu popup = new PopupMenu(this, view); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/* w w w . j ava 2s .co m*/ public boolean onMenuItemClick(MenuItem item) { String moviesUrl = null; switch (item.getItemId()) { case R.id.sort_popular: moviesUrl = Constants.URLS.getPopularUrl(); checkItemIndex = 0; break; case R.id.sort_rating: moviesUrl = Constants.URLS.getHighestRatingUrl(); checkItemIndex = 1; break; case R.id.sort_favourites: checkItemIndex = 2; default: break; } if (!item.isChecked()) { if (moviesUrl != null) { launchMovieListFragment(moviesUrl); } else { launchFavoriteListFragment(); } return true; } else { return false; } } }); popup.inflate(R.menu.sort_menu); popup.show(); final MenuItem popupItem = popup.getMenu().getItem(checkItemIndex); popupItem.setCheckable(true); popupItem.setChecked(true); }
From source file:com.hctrom.romcontrol.MainViewActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { SharedPreferences.Editor editor;/*from ww w . java 2s . c o m*/ SharedPreferences prefs = getSharedPreferences("ConfigMenuFlotante", Context.MODE_PRIVATE); switch (item.getItemId()) { case R.id.option1: if (item.isChecked()) { item.setChecked(false); menu.setEnabled(false); Toast.makeText(MainViewActivity.this, "Men flotante desactivado", Toast.LENGTH_LONG).show(); editor = prefs.edit(); editor.putBoolean("floating_button_activador", false); editor.commit(); } else { item.setChecked(true); menu.setEnabled(true); Toast.makeText(MainViewActivity.this, "Men flotante activado", Toast.LENGTH_LONG).show(); editor = prefs.edit(); editor.putBoolean("floating_button_activador", true); editor.commit(); } break; case R.id.option2: if (item.isChecked()) { item.setChecked(false); fab_close = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_close); menu.startAnimation(fab_close); menu.hide(); Toast.makeText(MainViewActivity.this, "Men flotante oculto", Toast.LENGTH_LONG).show(); editor = prefs.edit(); editor.putBoolean("floating_button_vista", false); editor.commit(); } else { item.setChecked(true); fab_open = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_open); menu.startAnimation(fab_open); menu.show(); Toast.makeText(MainViewActivity.this, "Men flotante visible", Toast.LENGTH_LONG).show(); editor = prefs.edit(); editor.putBoolean("floating_button_vista", true); editor.commit(); } break; case R.id.action_reboot: showHideRebootMenu(); break; } return super.onOptionsItemSelected(item); }
From source file:email.schaal.ocreader.ListActivity.java
private void showSortPopup(View view) { PopupMenu popupMenu = new PopupMenu(this, view); popupMenu.inflate(R.menu.menu_sort); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); Sort order = Preferences.ORDER.getOrder(sharedPreferences); String field = Preferences.SORT_FIELD.getString(sharedPreferences); final MenuItem orderMenuItem = popupMenu.getMenu().findItem(R.id.action_sort_order); orderMenuItem.setChecked(order != Sort.ASCENDING); final MenuItem selectedField; if (field.equals(Item.PUB_DATE)) { selectedField = popupMenu.getMenu().findItem(R.id.action_sort_pubdate); } else {/*from w w w. ja v a 2 s . c o m*/ selectedField = popupMenu.getMenu().findItem(R.id.action_sort_updatedate); } selectedField.setChecked(true); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { boolean updateSort = false; switch (item.getItemId()) { case R.id.action_sort_order: item.setChecked(!item.isChecked()); sharedPreferences.edit().putBoolean(Preferences.ORDER.getKey(), !item.isChecked()).apply(); updateSort = true; break; case R.id.action_sort_pubdate: sharedPreferences.edit().putString(Preferences.SORT_FIELD.getKey(), Item.PUB_DATE).apply(); updateSort = true; break; case R.id.action_sort_updatedate: sharedPreferences.edit().putString(Preferences.SORT_FIELD.getKey(), Item.UPDATED_AT).apply(); updateSort = true; break; } if (updateSort) { adapter.setOrder(Preferences.ORDER.getOrder(sharedPreferences), Preferences.SORT_FIELD.getString(sharedPreferences)); } return updateSort; } }); popupMenu.show(); }
From source file:io.v.android.apps.reader.PdfViewerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_link_page: toggleLinkedState(item.isChecked()); return true; default://from w w w. jav a 2 s .com 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 ww w.j a va2 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.duy.pascal.ui.editor.BaseEditorActivity.java
@Override public boolean onMenuItemClick(MenuItem item) { DLog.d(TAG, "onMenuItemClick() called with: item = [" + item + "]"); Pref pref = Pref.getInstance(this); int id = item.getItemId(); if (id == R.id.show_hidden_files_menu) { item.setChecked(!item.isChecked()); pref.setShowHiddenFiles(item.isChecked()); } else if (id == R.id.sort_by_name_menu) { item.setChecked(true);//from w w w .j ava 2 s.c o m pref.setFileSortType(FileListSorter.SORT_NAME); } else if (id == R.id.sort_by_datetime_menu) { item.setChecked(true); pref.setFileSortType(FileListSorter.SORT_DATE); } else if (id == R.id.sort_by_size_menu) { item.setChecked(true); pref.setFileSortType(FileListSorter.SORT_SIZE); } else if (id == R.id.sort_by_type_menu) { item.setChecked(true); pref.setFileSortType(FileListSorter.SORT_TYPE); } return mFileExplorer.onOptionsItemSelected(item); }