List of usage examples for android.view MenuItem isChecked
public boolean isChecked();
From source file:rebus.gitchat.ui.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem item) { closeDrawer();//www . j a va 2 s. co m if (item.isChecked()) return false; switch (item.getItemId()) { case R.id.rooms: if (!Navigator.with(MainActivity.this).utils().getActualTag().equals(Constants.TAG_ROOMS)) { Navigator.with(MainActivity.this).utils().goBackToSpecificPoint(Constants.TAG_ROOMS); } break; case R.id.suggested_rooms: Navigator.with(MainActivity.this).build() .goTo(Fragment.instantiate(MainActivity.this, SuggestedRoomsFragment.class.getName()), R.id.container) .tag(Constants.TAG_SUGGESTED_ROOMS).addToBackStack().animation().replace().commit(); break; case R.id.profile: /*LibsSupportFragment fragment = new LibsBuilder() .withLicenseDialog(true) .withLicenseShown(true) .supportFragment(); Navigator.with(MainActivity.this) .build() .goTo(fragment, R.id.container) .tag(Constants.TAG_PROFILE) .addToBackStack() .animation() .replace() .commit();*/ break; } return false; }
From source file:com.mikepenz.iconics.sample.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_randomize: item.setChecked(!item.isChecked()); mIconsFragment.randomize(item.isChecked()); mRandomize = item.isChecked();//from w ww . j a v a 2 s. com return true; case R.id.action_opensource: new LibsBuilder().withFields(R.string.class.getFields()).withLicenseShown(true) .withActivityTitle(getString(R.string.action_opensource)).withActivityTheme(R.style.AppTheme) .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).start(MainActivity.this); return true; case R.id.action_playground: startActivity(new Intent(getApplicationContext(), PlaygroundActivity.class)); return true; case R.id.action_automatic: startActivity(new Intent(getApplicationContext(), AutomaticActivity.class)); return true; case R.id.action_old_automatic: startActivity(new Intent(getApplicationContext(), OldAutomaticActivity.class)); return true; default: return super.onOptionsItemSelected(item); } }
From source file:cn.zhangls.android.weibo.ui.message.comment.CommentActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed();//from www . j av a 2 s .com return true; } else if (item.isChecked()) { return super.onOptionsItemSelected(item); } switch (item.getItemId()) { case R.id.menu_ac_msg_comment_all_comment: mCommentListType = CommentListType.ALL_COMMENT; break; case R.id.menu_ac_msg_comment_following_comment: mCommentListType = CommentListType.FOLLOWING_COMMENT; break; case R.id.menu_ac_msg_comment_mine: mCommentListType = CommentListType.MINE; break; default: mCommentListType = CommentListType.ALL_COMMENT; break; } item.setChecked(true); onRefresh(); showProgressDialog(); return super.onOptionsItemSelected(item); }
From source file:com.octade.droid.ilesansfil.IleSansFil.java
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_LOCATION: if (item.isChecked() == false) { item.setChecked(true);/* w w w . j a v a 2 s . co m*/ item.setTitle(getResources().getString(R.string.menuGpsOn)); mainApp.getMapView().setLocationDetection(true); } else { item.setChecked(false); item.setTitle(getResources().getString(R.string.menuGpsOff)); mainApp.getMapView().setLocationDetection(false); } return true; case MENU_SETTINGS: return true; case MENU_ABOUT: about(); return true; case MENU_TOGGLE_PIN: if (mainApp.getMapView().togglePins() == true) { item.setChecked(true); item.setTitle(getResources().getString(R.string.menuPinOn)); } else { item.setChecked(false); item.setTitle(getResources().getString(R.string.menuPinOff)); } return true; } return false; }
From source file:com.javierc.albuquerquenow.TransitMap.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub if (item.getItemId() == R.id.offline_routes) { if (item.isChecked()) { item.setChecked(false);/*from ww w.j a va 2s .co m*/ useOfflineRoutes = false; } else { item.setChecked(true); useOfflineRoutes = true; } } else if (item.getItemId() == R.id.action_legalnotices) { String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext()); AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(TransitMap.this); LicenseDialog.setTitle("Legal Notices"); LicenseDialog.setMessage(LicenseInfo); LicenseDialog.show(); } else if (item.getItemId() == R.id.bus_refresh) { //first delete all the current markers refreshMarkers(); //plot new markers plotBus(actionBar.getSelectedNavigationIndex()); } else if (item.getItemId() == R.id.bus_stops) { new PlotStopsTask(this).execute(); } return super.onOptionsItemSelected(item); }
From source file:com.commonsware.android.preso.decktastic.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.present: boolean original = item.isChecked(); item.setChecked(!original);/*from w w w. java 2 s. co m*/ if (original) { helper.disable(); } else { helper.enable(); } break; case R.id.first: pager.setCurrentItem(0); break; case R.id.last: pager.setCurrentItem(adapter.getCount() - 1); break; } return (super.onOptionsItemSelected(item)); }
From source file:com.oddsoft.buddhavoice2.view.MainActivity.java
private void initDrawer() { navigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//w w w .ja v a2 s . c o m public boolean onNavigationItemSelected(MenuItem menuItem) { //Checking if the item is in checked state or not, if not make it in checked state if (menuItem.isChecked()) menuItem.setChecked(false); else menuItem.setChecked(true); //Closing drawer on item click drawerLayout.closeDrawers(); switch (menuItem.getItemId()) { case R.id.navSetting: startActivity(new Intent(MainActivity.this, Prefs.class)); break; case R.id.navAbout: new LibsBuilder() //provide a style (optional) (LIGHT, DARK, LIGHT_DARK_TOOLBAR) .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).withAboutIconShown(true) .withAboutVersionShown(true).withAboutAppName(getString(R.string.app_name)) .withActivityTitle(getString(R.string.about_title)) .withAboutDescription(getString(R.string.license)) //start the activity .start(MainActivity.this); break; } return false; } }); //change navigation drawer item icons navigation.getMenu().findItem(R.id.navSetting).setIcon( new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_settings).color(Color.GRAY).sizeDp(24)); navigation.getMenu().findItem(R.id.navAbout) .setIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info).color(Color.GRAY).sizeDp(24)); actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.app_name, R.string.app_name) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank super.onDrawerOpened(drawerView); } }; //Setting the actionbarToggle to drawer layout drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:org.mariotaku.twidere.fragment.support.RetweetQuoteDialogFragment.java
@NonNull @Override//from w ww. j av a2s .c o m public Dialog onCreateDialog(final Bundle savedInstanceState) { final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity()); final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped); final Context context = builder.getContext(); mValidator = new TwidereValidator(context); mPreferences = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE, SharedPreferenceConstants.class); final LayoutInflater inflater = LayoutInflater.from(context); @SuppressLint("InflateParams") final View view = inflater.inflate(R.layout.dialog_status_quote_retweet, null); final StatusViewHolder holder = new StatusViewHolder(new DummyStatusHolderAdapter(context), view.findViewById(R.id.item_content)); final ParcelableStatus status = getStatus(); assert status != null; builder.setView(view); builder.setTitle(R.string.retweet_quote_confirm_title); if (isMyRetweet(status)) { builder.setPositiveButton(R.string.cancel_retweet, this); } else if (!status.user_is_protected) { builder.setPositiveButton(R.string.retweet, this); } builder.setNeutralButton(R.string.quote, this); builder.setNegativeButton(android.R.string.cancel, null); holder.displayStatus(status, null, false, true); view.findViewById(R.id.item_menu).setVisibility(View.GONE); view.findViewById(R.id.action_buttons).setVisibility(View.GONE); view.findViewById(R.id.item_content).setFocusable(false); view.findViewById(R.id.comment_container) .setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE); mEditComment = (UserHashtagAutoCompleteEditText) view.findViewById(R.id.edit_comment); mEditComment.setAccountId(status.account_id); mEditComment.setLengthChecker(new METLengthChecker() { final String statusLink = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.quote_id) .toString(); @Override public int getLength(CharSequence text) { return mValidator.getTweetLength(text + " " + statusLink); } }); mEditComment.setMaxCharacters(mValidator.getMaxTweetLength()); final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND); final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(mEditComment, new EditTextEnterHandler.EnterListener() { @Override public void onHitEnter() { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableStatus status = getStatus(); if (twitter == null || status == null) return; retweetOrQuote(twitter, status); dismiss(); } }, sendByEnter); enterHandler.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { final Dialog dialog = getDialog(); if (!(dialog instanceof AlertDialog)) return; final Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); if (positiveButton == null) return; positiveButton.setText(s.length() > 0 ? R.string.comment : R.string.retweet); } @Override public void afterTextChanged(Editable s) { } }); mCommentMenu = view.findViewById(R.id.comment_menu); mPopupMenu = new PopupMenu(context, mCommentMenu, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0); mCommentMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mPopupMenu.show(); } }); mCommentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener()); mPopupMenu.inflate(R.menu.menu_dialog_comment); final Menu menu = mPopupMenu.getMenu(); MenuUtils.setMenuItemAvailability(menu, R.id.quote_original_status, status.retweet_id > 0 || status.quote_id > 0); mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.isCheckable()) { item.setChecked(!item.isChecked()); return true; } return false; } }); return builder.create(); }
From source file:com.sanxiongdi.npng.zhangbeibei.stickygridheaders.ItemListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_toggle_sticky: item.setChecked(!item.isChecked()); ((StickyGridHeadersGridView) mGridView) .setAreHeadersSticky(!((StickyGridHeadersGridView) mGridView).areHeadersSticky()); return true; case R.id.menu_use_list_adapter: ToastUtil.makeText(getContext(), "coming soon", Toast.LENGTH_LONG); // Toast.makeText(getContext(), "coming soon", Toast.LENGTH_LONG).show(); // getResources().getStringArray(R.array.countries))); // mMenu.findItem(R.id.menu_use_list_adapter).setVisible(false); // mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(true); // mMenu.findItem(R.id.menu_toggle_sticky).setVisible(false); return true; case R.id.menu_use_sticky_adapter: // mGridView.setAdapter(new StickyGridHeadersSimpleArrayAdapter<String>(getActivity() // .getApplicationContext(), getResources().getStringArray(R.array.countries), // R.layout.header, R.layout.item)); // mMenu.findItem(R.id.menu_use_list_adapter).setVisible(true); // mMenu.findItem(R.id.menu_toggle_sticky).setVisible(true); // mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(false); return true; default:/*from w w w.jav a 2 s .c o m*/ break; } return super.onOptionsItemSelected(item); }
From source file:se.eliga.aves.birdlist.BirdListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.isCheckable()) { if (R.id.filtering_group == item.getGroupId()) { item.setChecked(!item.isChecked()); } else if (R.id.sort_order_group == item.getGroupId()) { swedishSortItem.setChecked(false); englishSortItem.setChecked(false); latinSortItem.setChecked(false); phylogeneticSortItem.setChecked(false); populationSortItem.setChecked(false); item.setChecked(true);//from w w w . java 2 s .c o m } BirdListAdapter birdListAdapter = (BirdListAdapter) getListAdapter(); switch (item.getItemId()) { case R.id.alphabetic_latin: birdListAdapter.setSortOption(BirdListAdapter.SortOption.SCIENTIFIC); break; case R.id.alphabetic_swedish: birdListAdapter.setSortOption(BirdListAdapter.SortOption.SWEDISH); break; case R.id.alphabetic_english: birdListAdapter.setSortOption(BirdListAdapter.SortOption.ENGLISH); break; case R.id.phylogenic_sort: birdListAdapter.setSortOption(BirdListAdapter.SortOption.PHYLOGENETIC); break; case R.id.population_sort: birdListAdapter.setSortOption(BirdListAdapter.SortOption.POPULATION); break; } birdListAdapter.setShowBreeding(breedingItem.isChecked()); birdListAdapter.setShowBreedingUnclear(breedingUnclearItem.isChecked()); birdListAdapter.setShowMigrant(migrantItem.isChecked()); birdListAdapter.setShowRare(rareItem.isChecked()); birdListAdapter.setShowRegularVisitor(regularVisitorItem.isChecked()); birdListAdapter.setShowUnseen(unseenItem.isChecked()); birdListAdapter.setShowUnclassified(unclassifiedItem.isChecked()); birdListAdapter.setShowNonSpontaneous(nonSpontaneousItem.isChecked()); birdListAdapter.refresh(); birdListAdapter.notifyDataSetChanged(); } SharedPreferences settings = getActivity().getSharedPreferences(Constants.BIRD_APP_SETTINGS, 0); saveFilterPreferences(settings); return true; }