List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.looksphere.goindia.activity.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from www . j av a 2 s.c om public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); Fragment fragment = null; switch (menuItem.getItemId()) { case R.id.nav_home: fragment = HomeFragment.newInstance(); fragmentCounter = 0; break; // case R.id.nav_maps: // fragment = SwachhMapFragment.newInstance(); // fragmentCounter = 1; // break; case R.id.nav_volunteering: fragment = VolunteeringFragment.newInstance(); fragmentCounter = 2; break; case R.id.nav_completed: fragment = CompletedFragment.newInstance(); fragmentCounter = 3; break; case R.id.nav_aboutus: fragment = AboutUsFragment.newInstance(); fragmentCounter = 4; break; case R.id.nav_email: fragment = EmailFragment.newInstance(); fragmentCounter = 5; break; case R.id.nav_share: fragment = ShareFragment.newInstance(); fragmentCounter = 6; break; case R.id.nav_settings: fragment = SettingsFragment.newInstance(); fragmentCounter = 7; break; } // update the main content by replacing fragments FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); return true; } }); }
From source file:com.radiofarda.istgah.ui.ActionBarCastActivity.java
private void populateDrawerItems(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from w w w . java2 s.co m public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); mItemToOpenWhenDrawerCloses = menuItem.getItemId(); mDrawerLayout.closeDrawers(); return true; } }); if (PodcastsActivity.class.isAssignableFrom(getClass())) { navigationView.setCheckedItem(R.id.navigation_allmusic); } else if (LiveStreamActivity.class.isAssignableFrom(getClass())) { navigationView.setCheckedItem(R.id.navigation_playlists); } }
From source file:com.cw.litenote.drawer.Drawer.java
public Drawer(AppCompatActivity activity) { drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) activity.findViewById(R.id.nav_view); mNavigationView.setItemIconTintList(null);// use original icon color // set icon for folder draggable: portrait if (Util.isPortraitOrientation(MainAct.mAct) && (MainAct.mPref_show_note_attribute != null)) { if (MainAct.mPref_show_note_attribute.getString("KEY_ENABLE_FOLDER_DRAGGABLE", "no") .equalsIgnoreCase("yes")) mNavigationView.getMenu().findItem(R.id.ENABLE_FOLDER_DRAG_AND_DROP) .setIcon(R.drawable.btn_check_on_holo_light); else/*from w w w. ja v a 2 s . c om*/ mNavigationView.getMenu().findItem(R.id.ENABLE_FOLDER_DRAG_AND_DROP) .setIcon(R.drawable.btn_check_off_holo_light); } mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); switch (menuItem.getItemId()) { case R.id.ADD_NEW_FOLDER: FolderUi.renewFirstAndLast_folderId(); FolderUi.addNewFolder(MainAct.mAct, FolderUi.mLastExist_folderTableId + 1, MainAct.mFolder.getAdapter()); return true; case R.id.ENABLE_FOLDER_DRAG_AND_DROP: if (MainAct.mPref_show_note_attribute.getString("KEY_ENABLE_FOLDER_DRAGGABLE", "no") .equalsIgnoreCase("yes")) { menuItem.setIcon(R.drawable.btn_check_off_holo_light); MainAct.mPref_show_note_attribute.edit().putString("KEY_ENABLE_FOLDER_DRAGGABLE", "no") .apply(); DragSortListView listView = (DragSortListView) act.findViewById(R.id.drawer_listview); listView.setDragEnabled(false); Toast.makeText(act, act.getResources().getString(R.string.drag_folder) + ": " + act.getResources().getString(R.string.set_disable), Toast.LENGTH_SHORT).show(); } else { menuItem.setIcon(R.drawable.btn_check_on_holo_light); MainAct.mPref_show_note_attribute.edit().putString("KEY_ENABLE_FOLDER_DRAGGABLE", "yes") .apply(); DragSortListView listView = (DragSortListView) act.findViewById(R.id.drawer_listview); listView.setDragEnabled(true); Toast.makeText(act, act.getResources().getString(R.string.drag_folder) + ": " + act.getResources().getString(R.string.set_enable), Toast.LENGTH_SHORT).show(); } MainAct.mFolder.getAdapter().notifyDataSetChanged(); act.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() return true; case R.id.DELETE_FOLDERS: DB_drawer dB_drawer = new DB_drawer(act); if (dB_drawer.getFoldersCount(true) > 0) { closeDrawer(); MainAct.mMenu.setGroupVisible(R.id.group_notes, false); //hide the menu DeleteFolders delFoldersFragment = new DeleteFolders(); MainAct.mFragmentTransaction = MainAct.mAct.getSupportFragmentManager().beginTransaction(); MainAct.mFragmentTransaction.setCustomAnimations(R.anim.fragment_slide_in_left, R.anim.fragment_slide_out_left, R.anim.fragment_slide_in_right, R.anim.fragment_slide_out_right); MainAct.mFragmentTransaction.replace(R.id.content_frame, delFoldersFragment) .addToBackStack("delete_folders").commit(); } else { Toast.makeText(act, R.string.config_export_none_toast, Toast.LENGTH_SHORT).show(); } return true; default: return true; } } }); act = activity; listView = (DragSortListView) act.findViewById(R.id.drawer_listview); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon drawerToggle = new ActionBarDrawerToggle(act, /* host Activity */ drawerLayout, /* DrawerLayout object */ MainAct.mToolbar, /* tool bar */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerOpened(View drawerView) { System.out.println("Drawer / _onDrawerOpened "); if (act.getSupportActionBar() != null) { act.getSupportActionBar().setTitle(R.string.app_name); MainAct.mToolbar.setLogo(R.drawable.ic_launcher); } act.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() if (listView.getCount() > 0) { // will call Folder_adapter _getView to update audio playing high light listView.invalidateViews(); } } public void onDrawerClosed(View view) { System.out.println("Drawer / _onDrawerClosed / FolderUi.getFocus_folderPos() = " + FolderUi.getFocus_folderPos()); FragmentManager fragmentManager = act.getSupportFragmentManager(); if (fragmentManager.getBackStackEntryCount() == 0) { act.invalidateOptionsMenu(); // creates a call to onPrepareOptionsMenu() DB_drawer dB_drawer = new DB_drawer(act); if (dB_drawer.getFoldersCount(true) > 0) { int pos = listView.getCheckedItemPosition(); MainAct.mFolderTitle = dB_drawer.getFolderTitle(pos, true); if (act.getSupportActionBar() != null) { act.getSupportActionBar().setTitle(MainAct.mFolderTitle); MainAct.mToolbar.setLogo(null); } } MainAct.openFolder(); } } }; }
From source file:org.digitalcampus.oppia.utils.ui.DrawerMenuManager.java
public void initializeDrawer() { // Initializing Drawer Layout and ActionBarToggle final Toolbar toolbar = (Toolbar) drawerAct.findViewById(R.id.toolbar); final DrawerLayout drawerLayout = (DrawerLayout) drawerAct.findViewById(R.id.drawer); navigationView = (NavigationView) drawerAct.findViewById(R.id.navigation_view); if (drawerLayout == null || navigationView == null) return;/*from www .j a v a2 s. c om*/ View headerView = navigationView.getHeaderView(0); ((TextView) headerView.findViewById(R.id.drawer_user_fullname)) .setText(SessionManager.getUserDisplayName(drawerAct)); ((TextView) headerView.findViewById(R.id.drawer_username)).setText(SessionManager.getUsername(drawerAct)); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { boolean result = onOptionsItemSelected(menuItem); if (result) { menuItem.setChecked(false); drawerLayout.closeDrawers(); } return result; } }); drawerToggle = new ActionBarDrawerToggle(drawerAct, drawerLayout, toolbar, R.string.open, R.string.close); //Setting the actionbarToggle to drawer layout drawerToggle.setDrawerIndicatorEnabled(true); drawerLayout.addDrawerListener(drawerToggle); drawerToggle.syncState(); }
From source file:org.copticchurchlibrary.arabicreader.ui.ActionBarCastActivity.java
private void populateDrawerItems(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*from w w w .j a v a2 s.c o m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); mItemToOpenWhenDrawerCloses = menuItem.getItemId(); mDrawerLayout.closeDrawers(); return true; } }); if (MusicPlayerActivity.class.isAssignableFrom(getClass())) { navigationView.setCheckedItem(R.id.navigation_allmusic); } else if (PlaceholderActivity.class.isAssignableFrom(getClass())) { /*navigationView.setCheckedItem(R.id.navigation_playlists);*/ } }
From source file:com.ixvil.android.BoxBonus.Activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (User.userId == 0) { Intent intent = new Intent(getApplicationContext(), LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);/*from w w w. j a v a 2 s . c o m*/ finish(); } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Setting ViewPager for each Tabs ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); // Set Tabs inside Toolbar TabLayout tabs = (TabLayout) findViewById(R.id.tabs); tabs.setupWithViewPager(viewPager); // Create Navigation drawer and inlfate layout 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); switch (menuItem.getItemId()) { case R.id.navigation_button_sign_out: String creds = " "; SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString("creds", creds); editor.apply(); Intent intent = new Intent(getApplicationContext(), LoginActivity.class); startActivityForResult(intent, 0); finish(); break; default: break; } // TODO: handle navigation // Closing drawer on item click mDrawerLayout.closeDrawers(); return true; } }); // Adding Floating Action Button to bottom right of main view // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); // fab.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Snackbar.make(v, "Hello Snackbar!", // Snackbar.LENGTH_LONG).show(); // } // }); NewsModel.getFromNet(getApplicationContext()); GiftsModel.getFromNet(getApplicationContext()); }
From source file:com.jefftharris.passwdsafe.sync.SyncLogsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_show_all: { itsIsShowAll = !item.isChecked(); item.setChecked(itsIsShowAll); LoaderManager lm = getLoaderManager(); lm.restartLoader(LOADER_LOGS, null, itsLogsCbs); return true; }/*from w w w .j a v a 2s .c o m*/ default: { return super.onOptionsItemSelected(item); } } }
From source file:com.support.android.mauritius.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*w ww . j av a 2s . co m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); mDrawer.closeDrawers(); return true; } }); }
From source file:io.github.hidroh.materialistic.ReadabilityFragment.java
@Override protected void createOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_font_options, menu); mTextSizeOptionValues = getResources().getStringArray(R.array.pref_text_size_values); mFontOptionValues = getResources().getStringArray(R.array.font_values); SubMenu subMenu = menu.findItem(R.id.menu_font_size).getSubMenu(); String[] options = getResources().getStringArray(R.array.text_size_options); String initialTextSize = Preferences.Theme.getPreferredReadabilityTextSize(getActivity()); for (int i = 0; i < options.length; i++) { MenuItem item = subMenu.add(R.id.menu_font_size_group, Menu.NONE, i, options[i]); item.setChecked(TextUtils.equals(initialTextSize, mTextSizeOptionValues[i])); }//from w w w .jav a 2s . co m subMenu.setGroupCheckable(R.id.menu_font_size_group, true, true); subMenu = menu.findItem(R.id.menu_font).getSubMenu(); options = getResources().getStringArray(R.array.font_options); String initialTypeface = Preferences.Theme.getReadabilityTypeface(getActivity()); for (int i = 0; i < options.length; i++) { MenuItem item = subMenu.add(R.id.menu_font_group, Menu.NONE, i, options[i]); item.setChecked(TextUtils.equals(initialTypeface, mFontOptionValues[i])); } subMenu.setGroupCheckable(R.id.menu_font_group, true, 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//from www. ja v a 2s .c o 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); }