List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.jefftharris.passwdsafe.PasswdSafeNavDrawerFragment.java
/** * Update drawer for the fragments displayed in the activity * @param fileNameUpdate If non-null, the file name to set in the view *//*from w w w . j a va 2 s. c o m*/ public void updateView(Mode mode, String fileNameUpdate, boolean fileOpen) { boolean drawerEnabled = false; boolean openDrawer = false; int upIndicator = 0; NavMenuItem selNavItem = null; switch (mode) { case INIT: { drawerEnabled = true; break; } case RECORDS_LIST: { drawerEnabled = true; // If the user hasn't 'learned' about the drawer, open it openDrawer = shouldOpenDrawer(); selNavItem = NavMenuItem.RECORDS; break; } case RECORDS_SINGLE: { selNavItem = NavMenuItem.RECORDS; break; } case RECORDS_ACTION: { upIndicator = R.drawable.ic_action_close_cancel; selNavItem = NavMenuItem.RECORDS; break; } case POLICIES: { drawerEnabled = true; selNavItem = NavMenuItem.PASSWORD_POLICIES; break; } case EXPIRATIONS: { drawerEnabled = true; selNavItem = NavMenuItem.EXPIRED_PASSWORDS; break; } case PREFERENCES: { drawerEnabled = true; selNavItem = NavMenuItem.PREFERENCES; break; } case ABOUT: { drawerEnabled = true; selNavItem = NavMenuItem.ABOUT; break; } } updateDrawerToggle(drawerEnabled, upIndicator); Menu menu = getNavView().getMenu(); for (int i = 0; i < menu.size(); ++i) { MenuItem item = menu.getItem(i); int itemId = item.getItemId(); if (selNavItem == null) { item.setChecked(false); } else if (selNavItem.itsMenuId == itemId) { item.setChecked(true); } if ((itemId == NavMenuItem.RECORDS.itsMenuId) || (itemId == NavMenuItem.PASSWORD_POLICIES.itsMenuId) || (itemId == NavMenuItem.EXPIRED_PASSWORDS.itsMenuId)) { item.setEnabled(fileOpen); } } itsSelNavItem = selNavItem; if (fileNameUpdate != null) { GuiUtils.setVisible(itsFileName, !TextUtils.isEmpty(fileNameUpdate)); itsFileName.setText(fileNameUpdate); } openDrawer(openDrawer); }
From source file:com.dogar.geodesic.activities.MainActivity.java
private void reverseCheck(MenuItem item) { if (item.isChecked()) item.setChecked(false); else//w w w .j av a 2s . c o m item.setChecked(true); }
From source file:org.csploit.android.plugins.Inspector.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.focused_scan: if (item.isChecked()) { item.setChecked(false); mFocusedScan = false;//from w ww.j a va 2 s. c o m } else { item.setChecked(true); mFocusedScan = true; } return true; default: return super.onOptionsItemSelected(item); } }
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 ww .j a v a 2s.com*/ break; } return super.onOptionsItemSelected(item); }
From source file:com.duy.pascal.ui.editor.EditorDelegate.java
public boolean onOptionsItemSelected(MenuItem menuItem) { int id = menuItem.getItemId(); if (menuItem.isCheckable()) menuItem.setChecked(!menuItem.isChecked()); switch (id) { case R.id.action_setting: mAnalytics.logEvent("action_setting", new Bundle()); mActivity.startActivity(new Intent(mActivity, SettingsActivity.class)); break;/*from ww w .j av a 2 s. co m*/ case R.id.action_find: mAnalytics.logEvent("action_find", new Bundle()); mActivity.showDialogFind(); break; case R.id.action_find_and_replace: mAnalytics.logEvent("action_find_and_replace", new Bundle()); mListener.findAndReplace(); break; case R.id.action_doc: mListener.showDocumentActivity(); break; case R.id.action_new_file: mListener.createNewSourceFile(null); break; case R.id.action_code_sample: mAnalytics.logEvent("action_code_sample", new Bundle()); mActivity.startActivity(new Intent(mActivity, CodeSampleActivity.class)); break; case R.id.action_rate: mAnalytics.logEvent("action_rate", new Bundle()); StoreUtil.gotoPlayStore(mActivity, BuildConfig.APPLICATION_ID); break; case R.id.action_more_app: mAnalytics.logEvent("action_more_app", new Bundle()); StoreUtil.moreApp(mActivity); break; case R.id.nav_run: mListener.runProgram(); break; case R.id.action_compile: mListener.doCompile(); break; case R.id.action_save: { EditorFragment fragment = mActivity.getEditorFragment(); if (fragment != null) fragment.saveFile(); break; } case R.id.action_save_as: mListener.saveAs(); break; case R.id.action_goto_line: mAnalytics.logEvent("action_goto_line", new Bundle()); mListener.goToLine(); break; case R.id.action_format: { mAnalytics.logEvent("action_format", new Bundle()); EditorFragment fragment = mActivity.getEditorFragment(); if (fragment != null) fragment.formatCode(); break; } case R.id.action_report_bug: mListener.reportBug(); break; case R.id.action_undo: { EditorFragment fragment = mActivity.getEditorFragment(); if (fragment != null) fragment.undo(); break; } case R.id.action_redo: { EditorFragment fragment = mActivity.getEditorFragment(); if (fragment != null) fragment.redo(); break; } case R.id.action_paste: { EditorFragment fragment = mActivity.getEditorFragment(); if (fragment != null) fragment.paste(); break; } case R.id.action_copy_all: { EditorFragment fragment = mActivity.getEditorFragment(); if (fragment != null) fragment.copyAll(); break; } case R.id.action_select_theme: mAnalytics.logEvent("action_select_theme", new Bundle()); mListener.selectThemeFont(); break; case R.id.action_more_feature: mActivity.openDrawer(GravityCompat.END); break; case R.id.action_translate: mAnalytics.logEvent("action_translate", new Bundle()); startActivityTranslate(); break; case R.id.action_info: mAnalytics.logEvent("action_info", new Bundle()); mActivity.startActivity(new Intent(mActivity, InfoActivity.class)); break; case R.id.action_program_structure: mActivity.showProgramStructure(); break; case R.id.action_debug: mAnalytics.logEvent("action_debug", new Bundle()); mActivity.startDebug(); break; case R.id.action_open_file: mActivity.openDrawer(GravityCompat.START); break; case R.id.action_insert_media_url: selectMediaUrl(); break; case R.id.action_insert_color: mAnalytics.logEvent("action_insert_color", new Bundle()); mActivity.insertColor(); break; } return true; }
From source file:de.grobox.transportr.trips.search.DirectionsFragment.java
private void onViaVisibleChanged(boolean viaVisible) { if (menu == null) throw new IllegalStateException("Menu is null"); MenuItem viaItem = menu.findItem(R.id.action_navigation_expand); viaItem.setChecked(viaVisible); viaCard.setVisibility(viaVisible ? VISIBLE : GONE); }
From source file:net.etechnologic.ismail.bitm_todolist.SingleGroupTaskActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.single_group_recycler_view_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*ww w . j a v a 2 s . co m*/ group_id = getIntent().getLongExtra("group_id", -1); Log.e(MainActivity.TAG, "Group_id Received: " + group_id); if (group_id == -1) { return; } taskRecyclerView = (RecyclerView) findViewById(R.id.task_recycler_view); // addGroupTaskET = (EditText) findViewById(R.id.addGroupTaskET); addTodoListGroupTaskFab = (FloatingActionButton) findViewById(R.id.addTodoListGroupTaskFab); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); // Adding menu icon to Toolbar ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme()); indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme())); supportActionBar.setHomeAsUpIndicator(indicator); supportActionBar.setDisplayHomeAsUpEnabled(true); } // Set behavior of Navigation drawer navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { // Set item in checked state menuItem.setChecked(true); // TODO: handle navigation // Closing drawer on item click mDrawerLayout.closeDrawers(); return true; } }); todoListTaskProvider = new TodoListTaskProvider(SingleGroupTaskActivity.this); todoListTasks = todoListTaskProvider.getAllTodoListTaskGroupWise(group_id); Log.e(MainActivity.TAG, "TodoListTasks: " + todoListTasks.size()); adapter = new ContentAdapter(this, todoListTasks); taskRecyclerView.setAdapter(adapter); taskRecyclerView.setLayoutManager(new LinearLayoutManager(this)); todoListTaskProvider = new TodoListTaskProvider(SingleGroupTaskActivity.this); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); arrayList = new ArrayList<>(); for (TodoListTask todoListTask : todoListTasks) { // arrayList.add("ID:" + todoListGroup.getId() // + "; Name:" + todoListGroup.getName()); arrayList.add("" + todoListTask.getId()); } addTodoListGroupTaskFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SingleGroupTaskActivity.this, AddTodoListTaskActivity.class); intent.putExtra("group_id", group_id); startActivity(intent); finish(); } }); // addGroupTaskET.setOnKeyListener(new View.OnKeyListener() { // @Override // public boolean onKey(View v, int keyCode, KeyEvent event) { // // Log.d(TAG, keyCode+" "+event.getKeyCode()); // if ((event.getAction() == KeyEvent.ACTION_DOWN) && // (KeyEvent.KEYCODE_ENTER == event.getKeyCode() || // keyCode == EditorInfo.IME_ACTION_NONE)) { // // Perform action on key press // TodoListTask todoListTask = new TodoListTask(group_id, // addGroupTaskET.getText().toString()); // long data = todoListTaskProvider.addTodoListTask(todoListTask); // todoListTasks.add(todoListTask); // adapter.notifyDataSetChanged(); // // // return true; // } // return false; // } // }); }
From source file:app.uni.my.myapplication.HeaderActivity.java
private void setupNavigationDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/* ww w. j av a 2 s.co m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.item_navigation_drawer_inbox: menuItem.setChecked(true); StudentFragment myf = new StudentFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.myFrame, myf).commit(); drawerLayout.closeDrawer(GravityCompat.START); return true; case R.id.item_navigation_drawer_starred: menuItem.setChecked(true); ScoreFragment mysc = new ScoreFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.myFrame, mysc).commit(); drawerLayout.closeDrawer(GravityCompat.START); drawerLayout.closeDrawer(GravityCompat.START); return true; case R.id.item_navigation_drawer_sent_mail: menuItem.setChecked(true); ExamFragment myEx = new ExamFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.myFrame, myEx).commit(); drawerLayout.closeDrawer(GravityCompat.START); drawerLayout.closeDrawer(GravityCompat.START); return true; case R.id.item_navigation_drawer_drafts: menuItem.setChecked(true); SubjectFragment mysch = new SubjectFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.myFrame, mysch).commit(); drawerLayout.closeDrawer(GravityCompat.START); return true; case R.id.exit: menuItem.setChecked(true); getApplicationContext().deleteDatabase(db.getDatabaseName()); getApplicationContext().deleteDatabase(dbsc.getDatabaseName()); getApplicationContext().deleteDatabase(dbsub.getDatabaseName()); Toast.makeText(getApplicationContext(), "? ??", Toast.LENGTH_SHORT).show(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = sp.edit(); editor.clear(); editor.commit(); Intent i = new Intent(getApplicationContext(), Main.class); startActivity(i); finish(); return true; } return true; } }); }
From source file:de.grobox.transportr.trips.search.DirectionsFragment.java
private void onIsDepartureChanged(boolean isDeparture) { if (menu == null) throw new IllegalStateException("Menu is null"); if (isDeparture) { MenuItem departureItem = menu.findItem(R.id.action_departure); departureItem.setChecked(true); } else {/*from w w w . j av a 2 s.c om*/ MenuItem arrivalItem = menu.findItem(R.id.action_arrival); arrivalItem.setChecked(true); } }
From source file:io.github.hidroh.materialistic.ReadabilityFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_font_size) { return true; }/* w ww .ja v a 2 s. com*/ if (item.getGroupId() == R.id.menu_font_size_group) { item.setChecked(true); String choice = mTextSizeOptionValues[item.getOrder()]; mTextSize = toHtmlPx(Preferences.Theme.resolveTextSize(choice)); Preferences.Theme.savePreferredReadabilityTextSize(getActivity(), choice); render(); } else if (item.getGroupId() == R.id.menu_font_group) { item.setChecked(true); mTypefaceName = mFontOptionValues[item.getOrder()]; Preferences.Theme.savePreferredReadabilityTypeface(getActivity(), mTypefaceName); render(); } return true; }