List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.parse.starter1.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { final SharedPreferences sharedPreferences = this.getSharedPreferences("com.parse.starter1", MODE_PRIVATE); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/* ww w . j ava2 s . c o m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.nav_home: break; case R.id.nav_account: ParseUser.getCurrentUser().logOutInBackground(new LogOutCallback() { @Override public void done(ParseException e) { if (e == null) { //b.setClickable(false); sharedPreferences.edit().putString("Hello", "No").apply(); Intent mainIntent = new Intent(getApplicationContext(), ChooseLoginOrSignUp.class); startActivity(mainIntent); finish(); } else { //b.setClickable(true); Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); break; case R.id.nav_notify: startActivity(new Intent(getApplicationContext(), Notifications.class)); break; case R.id.nav_fav: Toast.makeText(getApplicationContext(), "Fav", Toast.LENGTH_SHORT).show(); break; case R.id.nav_subs: startActivity(new Intent(getApplicationContext(), Subscribe.class)); break; } menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:com.secbro.qark.TopLevelActivity.java
public void selectDrawerItem(MenuItem menuItem) { // update the main content by replacing fragments FragmentManager fragmentManager = getSupportFragmentManager(); switch (menuItem.getItemId()) { case R.id.nav_broadcast_intent_sniffer: fragmentManager.beginTransaction().replace(R.id.container, BroadcastIntentSnifferFragment.newInstance()) .commit();/*from w w w . jav a 2 s.com*/ break; case R.id.nav_exported_components: fragmentManager.beginTransaction().replace(R.id.container, new ExportedComponentsFragment()).commit(); break; case R.id.nav_tap_jacking: fragmentManager.beginTransaction().replace(R.id.container, new TapJackingExploitFragment()).commit(); break; case R.id.nav_web_view_tests: fragmentManager.beginTransaction().replace(R.id.container, new WebViewTestsActivityFragment()).commit(); break; case R.id.nav_file_browser: Bundle args = new Bundle(); args.putString(FileBrowserFragment.INTENT_ACTION_SELECT_FILE, FileBrowserFragment.INTENT_ACTION_SELECT_FILE); Fragment instance = FileBrowserFragment.newInstance(); instance.setArguments(args); fragmentManager.beginTransaction().replace(R.id.container, instance).commit(); break; case R.id.nav_custom_intent: Intent createNewIntent = new Intent(this, CreateCustomIntentActivity.class); startActivity(createNewIntent); default: //TODO: } // Highlight the selected item, update the title, and close the drawer menuItem.setChecked(true); setTitle(menuItem.getTitle()); mDrawer.closeDrawers(); }
From source file:com.example.intern01.driverlicense.activity.MainActivity.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/*from w w w . ja v a2s .c o 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.nav_profile: navItemIndex = 0; CURRENT_TAG = TAG_PROFILE; break; case R.id.nav_cars: navItemIndex = 1; CURRENT_TAG = TAG_CARS; break; case R.id.nav_about: navItemIndex = 2; CURRENT_TAG = TAG_ABOUT; break; case R.id.nav_logout: navItemIndex = 3; getSharedPreferences("loginC", MODE_PRIVATE).edit().putString("lc_email", null) .putString("lc_pass", null).apply(); auth.signOut(); LoginManager.getInstance().logOut(); Intent i = new Intent(context, LoginActivity.class); context.startActivity(i); finish(); //CURRENT_TAG = TAG_; break; default: navItemIndex = 0; } //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); loadHomeFragment(); return true; } }); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, 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.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessary or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:io.demiseq.jetreader.activities.MainActivity.java
private void setupDrawerLayout() { NavigationView view = (NavigationView) findViewById(R.id.navigation_view); view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override// ww w.jav a 2 s .c o m public boolean onNavigationItemSelected(MenuItem menuItem) { savedMenuId = menuItem.getItemId(); switch (menuItem.getItemId()) { case R.id.drawer_home: GetHotMangas(); break; case R.id.drawer_favourite: GetFavoriteMangas(); break; case R.id.drawer_recent: GetRecentList(); break; case R.id.drawer_new: GetNewMangas(); break; case R.id.drawer_category: GetCategories(categories.get(0)); break; case R.id.drawer_feeds: GetSubscription(); break; case R.id.drawer_downloaded: GetDownloaded(); break; case R.id.drawer_settings: new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(MainActivity.this, SettingActivity.class); startActivity(intent); } }, 200); break; } menuItem.setChecked(true); drawerLayout.closeDrawers(); return true; } }); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, 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 drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:com.gudong.appkit.ui.activity.MainActivity.java
private void updatePosition(final MenuItem menuItem) { Fragment fragment = null;/*from w ww .j a v a2 s . c om*/ switch (menuItem.getItemId()) { case R.id.nav_recent: fragment = AppListFragment.getInstance(0); break; case R.id.nav_installed: fragment = AppListFragment.getInstance(1); break; case R.id.nav_exported: fragment = new AppFileListFragment(); break; case R.id.nav_donate: showDonateDialog(); MobclickAgent.onEvent(this, "menu_donate"); break; case R.id.nav_settings: mDrawerLayout.closeDrawers(); Intent intentSetting = new Intent(MainActivity.this, SimpleContainerActivity.class); intentSetting.putExtra(SimpleContainerActivity.KEY_TYPE, SimpleContainerActivity.FragmentType.SETTING); startActivity(intentSetting); MobclickAgent.onEvent(this, "setting_entry"); break; case R.id.nav_about: mDrawerLayout.closeDrawers(); Intent intentAbout = new Intent(MainActivity.this, SimpleContainerActivity.class); intentAbout.putExtra(SimpleContainerActivity.KEY_TYPE, SimpleContainerActivity.FragmentType.ABOUT); startActivity(intentAbout); MobclickAgent.onEvent(this, "setting_about"); break; case R.id.nav_opinion: mDrawerLayout.closeDrawers(); NavigationManager.gotoSendOpinion(this); MobclickAgent.onEvent(this, "send_email"); break; } if (fragment != null) { currentFragment = fragment; menuItem.setChecked(true); mDrawerLayout.closeDrawers(); FragmentManager fragmentManager = getSupportFragmentManager(); final android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction() .replace(R.id.fl_container, fragment); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { transaction.commit(); } }, 350); } }
From source file:com.money.manager.ex.account.AccountTransactionListFragment.java
private boolean isStatusSelectionHandled(MenuItem item) { int id = item.getItemId(); boolean result = true; // turn filters on/off TransactionStatuses status = null;/*from www. ja v a 2 s. c o m*/ switch (id) { case R.id.menu_none: status = TransactionStatuses.NONE; break; case R.id.menu_reconciled: status = TransactionStatuses.RECONCILED; break; case R.id.menu_void: status = TransactionStatuses.VOID; break; case R.id.menu_follow_up: status = TransactionStatuses.FOLLOWUP; break; case R.id.menu_duplicate: status = TransactionStatuses.DUPLICATE; break; default: // not handled here. result = false; break; } if (result) { if (item.isChecked()) { // remove filter mFilter.transactionStatus.filter.remove(status.getCode()); item.setChecked(false); } else { // add filter mFilter.transactionStatus.filter.add(status.getCode()); item.setChecked(true); } loadTransactions(); } return result; }
From source file:github.popeen.dsub.activity.SubsonicActivity.java
@Override public void setContentView(int viewId) { if (isTv()) { super.setContentView(R.layout.static_drawer_activity); } else {/*from w w w.j a v a 2 s . co m*/ super.setContentView(R.layout.abstract_activity); } rootView = (ViewGroup) findViewById(R.id.content_frame); if (viewId != 0) { LayoutInflater layoutInflater = getLayoutInflater(); layoutInflater.inflate(viewId, rootView); } drawerList = (NavigationView) findViewById(R.id.left_drawer); drawerList.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(final MenuItem menuItem) { if (showingTabs) { // Settings are on a different selectable track if (menuItem.getItemId() != R.id.drawer_settings && menuItem.getItemId() != R.id.drawer_admin && menuItem.getItemId() != R.id.drawer_offline) { menuItem.setChecked(true); lastSelectedPosition = menuItem.getItemId(); } switch (menuItem.getItemId()) { case R.id.drawer_home: drawerItemSelected("Home"); return true; case R.id.drawer_library: drawerItemSelected("Artist"); return true; case R.id.drawer_playlists: drawerItemSelected("Playlist"); return true; case R.id.drawer_podcasts: drawerItemSelected("Podcast"); return true; case R.id.drawer_bookmarks: drawerItemSelected("Bookmark"); return true; case R.id.drawer_internet_radio_stations: drawerItemSelected("Internet Radio"); return true; case R.id.drawer_shares: drawerItemSelected("Share"); return true; case R.id.drawer_chat: drawerItemSelected("Chat"); return true; case R.id.drawer_admin: if (UserUtil.isCurrentAdmin()) { UserUtil.confirmCredentials(SubsonicActivity.this, new Runnable() { @Override public void run() { drawerItemSelected("Admin"); menuItem.setChecked(true); lastSelectedPosition = menuItem.getItemId(); } }); } else { drawerItemSelected("Admin"); menuItem.setChecked(true); lastSelectedPosition = menuItem.getItemId(); } return true; case R.id.drawer_downloading: drawerItemSelected("Download"); return true; case R.id.drawer_offline: toggleOffline(); return true; case R.id.drawer_settings: startActivity(new Intent(SubsonicActivity.this, SettingsActivity.class)); drawer.closeDrawers(); return true; } } else { int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE; SubsonicActivity.this.setActiveServer(activeServer); populateTabs(); return true; } return false; } }); drawerHeader = drawerList.inflateHeaderView(R.layout.drawer_header); drawerHeader.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (showingTabs) { populateServers(); } else { populateTabs(); } } }); drawerHeaderToggle = (ImageView) drawerHeader.findViewById(R.id.header_select_image); drawerServerName = (TextView) drawerHeader.findViewById(R.id.header_server_name); drawerUserName = (TextView) drawerHeader.findViewById(R.id.header_user_name); drawerUserAvatar = (ImageView) drawerHeader.findViewById(R.id.header_user_avatar); updateDrawerHeader(); if (!isTv()) { drawer = (DrawerLayout) findViewById(R.id.drawer_layout); // Pass in toolbar if it exists Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar); drawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.common_appname, R.string.common_appname) { @Override public void onDrawerClosed(View view) { drawerIdle = true; drawerOpen = false; if (!showingTabs) { populateTabs(); } } @Override public void onDrawerOpened(View view) { DownloadService downloadService = getDownloadService(); boolean downloadingVisible = downloadService != null && !downloadService.getBackgroundDownloads().isEmpty(); if (lastSelectedPosition == R.id.drawer_downloading) { downloadingVisible = true; } setDrawerItemVisible(R.id.drawer_downloading, downloadingVisible); drawerIdle = true; drawerOpen = true; } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); drawerIdle = false; } }; drawer.setDrawerListener(drawerToggle); drawerToggle.setDrawerIndicatorEnabled(true); drawer.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (drawerIdle && currentFragment != null && currentFragment.getGestureDetector() != null) { return currentFragment.getGestureDetector().onTouchEvent(event); } else { return false; } } }); } // Check whether this is a tablet or not secondaryContainer = findViewById(R.id.fragment_second_container); if (secondaryContainer != null) { primaryContainer = findViewById(R.id.fragment_container); } checkIfServerOutdated(); }
From source file:com.technologx.blaze.player.activities.MainActivity.java
private void updatePosition(final MenuItem menuItem) { runnable = null;//from w w w.j a va 2 s.co m switch (menuItem.getItemId()) { case R.id.nav_library: runnable = navigateLibrary; break; case R.id.nav_playlists: runnable = navigatePlaylist; break; case R.id.nav_folders: runnable = navigateFolder; break; case R.id.nav_nowplaying: NavigationUtils.navigateToNowplaying(MainActivity.this, false); break; case R.id.nav_queue: runnable = navigateQueue; break; case R.id.nav_settings: NavigationUtils.navigateToSettings(MainActivity.this); break; case R.id.nav_help: Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = Uri.parse("mailto:support@technologx.com"); intent.setData(data); startActivity(intent); break; case R.id.nav_about: mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Helpers.showAbout(MainActivity.this); } }, 350); break; case R.id.nav_donate: startActivity(new Intent(MainActivity.this, DonateActivity.class)); break; } if (runnable != null) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { runnable.run(); } }, 350); } }
From source file:com.naman14.timber.activities.MainActivity.java
private void updatePosition(final MenuItem menuItem) { runnable = null;/*from ww w . j ava 2 s . c om*/ switch (menuItem.getItemId()) { case R.id.nav_library: runnable = navigateLibrary; break; case R.id.nav_playlists: runnable = navigatePlaylist; break; case R.id.nav_folders: runnable = navigateFolder; break; case R.id.nav_nowplaying: NavigationUtils.navigateToNowplaying(MainActivity.this, false); break; case R.id.nav_queue: runnable = navigateQueue; break; case R.id.nav_settings: NavigationUtils.navigateToSettings(MainActivity.this); break; case R.id.nav_help: Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = Uri.parse("mailto:namandwivedi14@gmail.com"); intent.setData(data); startActivity(intent); break; case R.id.nav_about: mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Helpers.showAbout(MainActivity.this); } }, 350); break; case R.id.nav_donate: startActivity(new Intent(MainActivity.this, DonateActivity.class)); break; } if (runnable != null) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { runnable.run(); } }, 350); } }
From source file:com.devalladolid.musictoday.activities.MainActivity.java
private void updatePosition(final MenuItem menuItem) { runnable = null;//from ww w. jav a 2 s. c o m switch (menuItem.getItemId()) { case R.id.nav_library: runnable = navigateLibrary; break; case R.id.nav_playlists: runnable = navigatePlaylist; break; case R.id.nav_folders: runnable = navigateFolder; break; case R.id.nav_nowplaying: NavigationUtils.navigateToNowplaying(MainActivity.this, false); break; case R.id.nav_queue: runnable = navigateQueue; break; case R.id.nav_settings: NavigationUtils.navigateToSettings(MainActivity.this); break; case R.id.nav_help: Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = Uri.parse("mailto:devalladolidoficial@gmail.com"); intent.setData(data); startActivity(intent); break; case R.id.nav_about: mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Helpers.showAbout(MainActivity.this); } }, 350); break; case R.id.nav_donate: startActivity(new Intent(MainActivity.this, DonateActivity.class)); break; } if (runnable != null) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { runnable.run(); } }, 350); } }