List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.davidmascharka.lips.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_reset: resetDatafile();/*from w ww . j ava2 s . co m*/ break; case R.id.action_select_building: showSelectBuildingDialog(); break; case R.id.action_select_room_size: new SelectRoomSizeDialogFragment().show(getSupportFragmentManager(), "RoomSize"); break; case R.id.action_display_map: displayMap = !displayMap; item.setChecked(displayMap); ((GridView) findViewById(R.id.gridView)).setDisplayMap(displayMap); break; case R.id.action_select_map: // Launch an intent to select the map the user wants to display Intent selectMapIntent = new Intent(); selectMapIntent.setAction(Intent.ACTION_GET_CONTENT); selectMapIntent.setType("image/*"); selectMapIntent.addCategory(Intent.CATEGORY_OPENABLE); if (selectMapIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(selectMapIntent, GET_MAP_REQUEST); } break; case R.id.action_start_tracker: Intent intent = new Intent(this, TrackerActivity.class); startActivity(intent); break; default: super.onOptionsItemSelected(item); break; } return true; }
From source file:androidVNC.VncCanvasActivity.java
/** * Change the input mode sub-menu to reflect change in scaling *//*from w ww .j a v a 2 s . c om*/ void updateInputMenu() { if (inputModeMenuItems == null || vncCanvas.scaling == null) { return; } for (MenuItem item : inputModeMenuItems) { item.setEnabled(vncCanvas.scaling.isValidInputMode(item.getItemId())); if (getInputHandlerById(item.getItemId()) == inputHandler) item.setChecked(true); } }
From source file:com.spit.matrix15.CategoriesActivity.java
private void setupDrawerLayout() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); NavigationView view = (NavigationView) findViewById(R.id.navigation_view); view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override// w w w.j a v a2 s . c o m public boolean onNavigationItemSelected(MenuItem menuItem) { int menuItemId = menuItem.getItemId(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); switch (menuItemId) { case R.id.drawer_favourite: ft.replace(R.id.fragment_container, new AboutUsFragment()); ft.addToBackStack(null); ft.addToBackStack(null); ft.commit(); break; case R.id.drawer_home: ft.replace(R.id.fragment_container, new CategoriesFragment()); ft.addToBackStack(null); ft.commit(); break; case R.id.drawer_downloaded: ft.replace(R.id.fragment_container, new DevelopersFragment()); ft.addToBackStack(null); ft.commit(); break; case R.id.drawer_more: ft.replace(R.id.fragment_container, new AllEventsFragment()); ft.addToBackStack(null); ft.commit(); break; case R.id.drawer_settings: ft.replace(R.id.fragment_container, new FavoritesFragment()); ft.addToBackStack(null); ft.commit(); } // Snackbar.make(content, menuItem.getTitle() + " pressed", Snackbar.LENGTH_LONG).show(); menuItem.setChecked(true); drawerLayout.closeDrawers(); return true; } }); }
From source file:com.google.android.apps.forscience.whistlepunk.project.experiment.ExperimentDetailsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); if (itemId == android.R.id.home) { goToProjectDetails();// w w w.j a v a2 s . c om return true; } else if (itemId == R.id.action_edit_experiment) { UpdateExperimentActivity.launch(getActivity(), mExperimentId, false /* not new */); return true; } else if (itemId == R.id.action_archive_experiment || itemId == R.id.action_unarchive_experiment) { setExperimentArchived(item.getItemId() == R.id.action_archive_experiment); return true; } else if (itemId == R.id.action_experiment_add_note) { launchLabelAdd(); return true; } else if (itemId == R.id.action_include_archived) { item.setChecked(!item.isChecked()); mIncludeArchived = item.isChecked(); loadExperimentData(mExperiment); return true; } else if (itemId == R.id.action_delete_experiment) { confirmDelete(); } return super.onOptionsItemSelected(item); }
From source file:com.akhbulatov.wordkeeper.ui.activity.MainActivity.java
private void selectDrawerItem(MenuItem item) { Class fragmentClass = null;/*www .j av a 2 s. c o m*/ Fragment fragment = null; switch (item.getItemId()) { case R.id.menu_drawer_all_words: fragmentClass = WordListFragment.class; break; case R.id.menu_drawer_categories: fragmentClass = CategoryListFragment.class; break; case R.id.menu_drawer_rate_app: showRateApp(); break; case R.id.menu_drawer_about: showAbout(); break; default: fragmentClass = WordListFragment.class; } // Block is executed only if the selected item is a fragment, // otherwise was the selected activity and the replacement fragment is not executed if (fragmentClass != null) { try { fragment = (Fragment) fragmentClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (fragmentClass == WordListFragment.class) { getSupportFragmentManager().popBackStack(); transaction.replace(R.id.layout_root_container, fragment, WORD_LIST_FRAGMENT_TAG); mWordListFragment = (WordListFragment) fragment; } else { transaction.replace(R.id.layout_root_container, fragment, CATEGORY_LIST_FRAGMENT_TAG); transaction.addToBackStack(null); mCategoryListFragment = (CategoryListFragment) fragment; } transaction.commit(); // Not required for activity. Only for a fragment item.setChecked(true); setTitle(item.getTitle()); } mDrawerLayout.closeDrawers(); }
From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java
private void setCommonMenu(final Menu menu) { final boolean hasMedia = hasMedia(); final int activatedColor = getUserThemeColor(this); final MenuItem itemAddImageSubmenu = menu.findItem(R.id.add_image_submenu); if (itemAddImageSubmenu != null) { final Drawable iconAddImage = itemAddImageSubmenu.getIcon(); iconAddImage.mutate();//from w w w. j a va2s. c o m if (hasMedia) { iconAddImage.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { iconAddImage.clearColorFilter(); } } final MenuItem itemAttachLocation = menu.findItem(MENU_ADD_LOCATION); if (itemAttachLocation != null) { final Drawable iconAttachLocation = itemAttachLocation.getIcon().mutate(); final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false); if (attachLocation && getLocation()) { iconAttachLocation.setColorFilter(activatedColor, Mode.SRC_ATOP); itemAttachLocation.setTitle(R.string.remove_location); itemAttachLocation.setChecked(true); } else { setProgressVisibility(false); mPreferences.edit().putBoolean(KEY_ATTACH_LOCATION, false).commit(); iconAttachLocation.clearColorFilter(); itemAttachLocation.setTitle(R.string.add_location); itemAttachLocation.setChecked(false); } } final MenuItem viewItem = menu.findItem(MENU_VIEW); if (viewItem != null) { viewItem.setVisible(mInReplyToStatus != null); } final MenuItem itemToggleSensitive = menu.findItem(MENU_TOGGLE_SENSITIVE); if (itemToggleSensitive != null) { itemToggleSensitive.setVisible(hasMedia); itemToggleSensitive.setEnabled(hasMedia); itemToggleSensitive.setChecked(hasMedia && mIsPossiblySensitive); if (hasMedia) { final Drawable iconToggleSensitive = itemToggleSensitive.getIcon().mutate(); if (mIsPossiblySensitive) { itemToggleSensitive.setTitle(R.string.remove_sensitive_mark); iconToggleSensitive.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { itemToggleSensitive.setTitle(R.string.mark_as_sensitive); iconToggleSensitive.clearColorFilter(); } } } }
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { canvas.getKeyboard().setAfterMenu(true); switch (item.getItemId()) { case R.id.itemInfo: canvas.showConnectionInfo();/* www. ja v a2 s. co m*/ return true; case R.id.itemSpecialKeys: showDialog(R.layout.metakey); return true; case R.id.itemColorMode: selectColorModel(); return true; // Following sets one of the scaling options case R.id.itemZoomable: case R.id.itemOneToOne: case R.id.itemFitToScreen: AbstractScaling.getById(item.getItemId()).setScaleTypeForActivity(this); item.setChecked(true); showPanningState(false); return true; case R.id.itemCenterMouse: canvas.getPointer().warpMouse(canvas.absoluteXPosition + canvas.getVisibleWidth() / 2, canvas.absoluteYPosition + canvas.getVisibleHeight() / 2); return true; case R.id.itemDisconnect: canvas.closeConnection(); finish(); return true; case R.id.itemEnterText: showDialog(R.layout.entertext); return true; case R.id.itemCtrlAltDel: canvas.getKeyboard().sendMetaKey(MetaKeyBean.keyCtrlAltDel); return true; /* case R.id.itemFollowMouse: boolean newFollow = !connection.getFollowMouse(); item.setChecked(newFollow); connection.setFollowMouse(newFollow); if (newFollow) { vncCanvas.panToMouse(); } connection.save(database.getWritableDatabase()); database.close(); return true; case R.id.itemFollowPan: boolean newFollowPan = !connection.getFollowPan(); item.setChecked(newFollowPan); connection.setFollowPan(newFollowPan); connection.save(database.getWritableDatabase()); database.close(); return true; case R.id.itemArrowLeft: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft); return true; case R.id.itemArrowUp: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowUp); return true; case R.id.itemArrowRight: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowRight); return true; case R.id.itemArrowDown: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowDown); return true; */ case R.id.itemSendKeyAgain: sendSpecialKeyAgain(); return true; // Disabling Manual/Wiki Menu item as the original does not correspond to this project anymore. //case R.id.itemOpenDoc: // Utils.showDocumentation(this); // return true; case R.id.itemExtraKeys: if (connection.getExtraKeysToggleType() == Constants.EXTRA_KEYS_ON) { connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_OFF); item.setTitle(R.string.extra_keys_enable); setExtraKeysVisibility(View.GONE, false); } else { connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_ON); item.setTitle(R.string.extra_keys_disable); setExtraKeysVisibility(View.VISIBLE, false); extraKeysHidden = false; } setKeyStowDrawableAndVisibility(); connection.save(database.getWritableDatabase()); database.close(); return true; case R.id.itemHelpInputMode: showDialog(R.id.itemHelpInputMode); return true; default: AbstractInputHandler input = getInputHandlerById(item.getItemId()); if (input != null) { inputHandler = input; connection.setInputMode(input.getName()); if (input.getName().equals(SimulatedTouchpadInputHandler.TOUCHPAD_MODE)) { connection.setFollowMouse(true); connection.setFollowPan(true); } else { connection.setFollowMouse(false); connection.setFollowPan(false); } item.setChecked(true); showPanningState(true); connection.save(database.getWritableDatabase()); database.close(); return true; } } return super.onOptionsItemSelected(item); }
From source file:io.jawg.osmcontributor.ui.activities.MapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { ((OsmTemplateApplication) getApplication()).init(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); ((OsmTemplateApplication) getApplication()).getOsmTemplateComponent().inject(this); ButterKnife.bind(this); PreferenceManager.setDefaultValues(this, R.xml.pref_accessibility, false); PreferenceManager.setDefaultValues(this, R.xml.pref_connection, false); PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, false); PreferenceManager.setDefaultValues(this, R.xml.pref_general, false); PreferenceManager.setDefaultValues(this, R.xml.pref_notification, false); setSupportActionBar(toolbar);/*from www. j a v a 2 s. c o m*/ eventBus.post(new UpdateFirstConnectionEvent()); checkFirstStart(); 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.getItemId() != R.id.display_yes_accessibility && menuItem.getItemId() != R.id.display_limited_accessibility && menuItem.getItemId() != R.id.display_no_accessibility && menuItem.getItemId() != R.id.display_unknown_accessibility) { menuItem.setChecked(!menuItem.isChecked()); onFilterItemClick(menuItem); } else { menuItem.setChecked(!menuItem.isChecked()); onOtherItemClick(menuItem); } return true; } }); selectAllMenuItem = filterView.getMenu().findItem(R.id.select_all_item); 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) { } }); if (FlavorUtils.isBus()) { eventBus.post(new PleaseApplyNoteFilterEvent(false, false)); List<Poi.AccessibilityType> accessibilityTypesToHide = new ArrayList<>(); eventBus.post(new PleaseApplyAccessibilityFilter(accessibilityTypesToHide)); } 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:ngoc.com.pedometer.ui.Fragment_Overview.java
private void setUpNavigationView() { //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override/*w ww. j a v a 2s. co m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { //Check to see which item was being clicked and perform appropriate action switch (menuItem.getItemId()) { //Replacing the main content with ContentFragment Which is our Inbox View; case R.id.action_settings: drawer.closeDrawers(); ActivityOptionsCompat options = ActivityOptionsCompat.makeCustomAnimation(getActivity(), R.anim.push_in_to_right, R.anim.push_in_to_left); Intent intent = new Intent(getActivity(), SettingActivity.class); ((Activity) getActivity()).startActivity(intent, options.toBundle()); break; case R.id.action_split_count: drawer.closeDrawers(); Dialog_Split.getDialog(getActivity(), total_start + Math.max(todayOffset + since_boot, 0)) .show(); break; case R.id.action_faq: drawer.closeDrawers(); FAQDialog.getInstance().show(getActivity()); break; case R.id.action_about: drawer.closeDrawers(); showAboutDialog(); break; default: } //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); } menuItem.setChecked(true); return true; } }); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) { @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 drawer.addDrawerListener(actionBarDrawerToggle); //calling sync state is necessary or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:com.free.searcher.MainFragment.java
public boolean regex(MenuItem item) { item.setChecked(!item.isChecked()); MainActivity.checkRE = item.isChecked(); Log.d("checkRE", "" + MainActivity.checkRE); ((MainActivity) activity).mSearchView.requestFocus(); return true;//from w w w . ja v a2s. c o m }