List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:pl.bcichecki.rms.client.android.fragments.InboxMessagesListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); getActivity().getMenuInflater().inflate(R.menu.fragment_inbox_messages_list, menu); MenuItem showArchivedMenuItem = menu.findItem(R.id.fragment_inbox_messages_list_menu_show_archived); showArchivedMenuItem.setChecked(showArchivedMessages); showArchivedMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override// ww w .j av a 2 s . co m public boolean onMenuItemClick(MenuItem item) { item.setChecked(!item.isChecked()); showArchivedMessages = item.isChecked(); downloadData(); downloadArchivedData(); return false; } }); }
From source file:com.xfininity.m.modest_account_man.MainActivity.java
private void setupDrawerContent(NavigationView navigationView, ViewPager viewPager) { final ViewPager vp = viewPager; navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*from w w w .j a va 2s . c o m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { Adapter adapter = new Adapter(getSupportFragmentManager()); //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 mDrawerLayout.closeDrawers(); //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.screen: Toast.makeText(getApplicationContext(), "Inbox Selected", Toast.LENGTH_SHORT).show(); return true; // For rest of the options we just show a toast on click case R.id.nav_overview: toolbar.setTitle("Overview"); adapter.addFragment(new DashBoard_Fragment(), "DashBoard"); adapter.addFragment(new DashBoard_Fragment(), "Billing"); adapter.addFragment(new DashBoard_Fragment(), "Manage"); vp.setAdapter(adapter); tabLayout.setupWithViewPager(vp); return true; case R.id.nav_shop: toolbar.setTitle("Shop"); adapter.addFragment(new DashBoard_Fragment(), "Category 4"); adapter.addFragment(new DashBoard_Fragment(), "Category 5"); adapter.addFragment(new DashBoard_Fragment(), "Category 6"); vp.setAdapter(adapter); tabLayout.setupWithViewPager(vp); return true; case R.id.nav_support: toolbar.setTitle("Support"); Toast.makeText(getApplicationContext(), "Drafts Selected", Toast.LENGTH_SHORT).show(); return true; case R.id.nav_account: toolbar.setTitle("Account"); Toast.makeText(getApplicationContext(), "All Mail Selected", Toast.LENGTH_SHORT).show(); adapter.addFragment(new DashBoard_Fragment(), "DashBoard"); adapter.addFragment(new Billing_Fragment(), "Billing"); adapter.addFragment(new Manage_Fragment(), "Manage"); vp.setAdapter(adapter); tabLayout.setupWithViewPager(vp); return true; case R.id.nav_search: toolbar.setTitle("Search"); Toast.makeText(getApplicationContext(), "Trash Selected", Toast.LENGTH_SHORT).show(); return true; case R.id.nav_l_chat: toolbar.setTitle("Live Chat"); Toast.makeText(getApplicationContext(), "Spam Selected", Toast.LENGTH_SHORT).show(); return true; default: toolbar.setTitle("My Account"); Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); return true; } // return true; } }); }
From source file:com.frostwire.android.gui.activities.internal.NavigationMenu.java
private void onMenuItemSelected(MenuItem menuItem) { if (controller.getActivity() == null) { return;//from ww w.j av a2 s .c om } checkedNavViewMenuItemId = menuItem.getItemId(); Engine.instance().getVibrator().hapticFeedback(); controller.syncNavigationMenu(); menuItem.setChecked(true); controller.setTitle(menuItem.getTitle()); int menuActionId = menuItem.getItemId(); Fragment fragment = controller.getFragmentByNavMenuId(menuItem.getItemId()); if (fragment != null) { controller.switchContent(fragment); } else { switch (menuActionId) { case R.id.menu_main_my_music: controller.launchMyMusic(); break; case R.id.menu_main_library: controller.showMyFiles(); break; case R.id.menu_main_transfers: controller.showTransfers(TransfersFragment.TransferStatus.ALL); break; case R.id.menu_main_support: UIUtils.openURL(controller.getActivity(), Constants.SUPPORT_URL); break; case R.id.menu_main_settings: controller.showPreferences(); break; case R.id.menu_main_shutdown: controller.showShutdownDialog(); break; default: break; } } hide(); if ((menuActionId == R.id.menu_main_my_music || menuActionId == R.id.menu_main_search || menuActionId == R.id.menu_main_library) && controller.getActivity() != null) { Offers.showInterstitialOfferIfNecessary(controller.getActivity(), Offers.PLACEMENT_INTERSTITIAL_MAIN, false, false, true); } }
From source file:com.joeyturczak.jtscanner.ui.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { Menu menu = navigationView.getMenu(); MenuItem menuItem = menu.findItem(R.id.scanner_fragment); menuItem.setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*w w w. j av a2 s .c om*/ public boolean onNavigationItemSelected(MenuItem menuItem) { selectDrawerItem(menuItem); return true; } }); }
From source file:com.google.android.apps.forscience.whistlepunk.project.ProjectTabsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_include_archived) { item.setChecked(!item.isChecked()); mIncludeArchived = item.isChecked(); loadProjects();/*from w w w . j a va 2 s . c o m*/ } return super.onOptionsItemSelected(item); }
From source file:edu.nd.darts.cimon.NDroidAdmin.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.startup: SharedPreferences appPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = appPrefs.edit(); if (item.isChecked()) { item.setChecked(false); editor.putBoolean(PREF_STARTUP, false); } else {//from w w w . j a v a 2 s. co m item.setChecked(true); editor.putBoolean(PREF_STARTUP, true); } editor.commit(); return true; case R.id.exit: stopService(new Intent(this, NDroidService.class)); if (DebugLog.DEBUG) Log.d(TAG, "CIMON service stopped - exiting"); finish(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.sherdle.universal.MainActivity.java
@Override public void menuItemClicked(List<NavItem> actions, MenuItem item, boolean requiresPurchase) { //Close the drawer if (drawer != null) drawer.closeDrawer(GravityCompat.START); //Check if the user is allowed to open item if (requiresPurchase && !isPurchased()) return; //isPurchased will handle this. if (!checkPermissionsHandleIfNeeded(actions, item)) return; //checkPermissions will handle. if (isCustomIntent(actions)) return;/*from ww w .j a v a2s . c o m*/ //Uncheck all other items, check the current item if (item != null) { for (MenuItem menuItem : menu.getMenuItems()) menuItem.setChecked(false); item.setChecked(true); } //Load the new tabs adapter = new TabAdapter(getSupportFragmentManager(), actions, this); viewPager.setAdapter(adapter); //Show or hide the tab bar depending on if we need it if (actions.size() == 1) tabLayout.setVisibility(View.GONE); else tabLayout.setVisibility(View.VISIBLE); //Show in interstitial showInterstitial(false); onTabBecomesActive(0); }
From source file:com.example.sans.myapplication.Login.OnlineActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_online); shares = getSharedPreferences("SHARES", 0); Fragment newFragment = new OnlineBotFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.login_bot, newFragment); transaction.addToBackStack(null);//from ww w. ja va 2s . c om transaction.commit(); transaction = getFragmentManager().beginTransaction(); newFragment = new LoginTopFragment(); transaction.replace(R.id.login_top, newFragment); transaction.commit(); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //Initializing NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view); //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu header = navigationView.inflateHeaderView(R.layout.header); JSONObject driver_data = null; try { driver_data = new JSONObject(shares.getString("DRIVER_DATA", "ERROR")); } catch (JSONException e) { e.printStackTrace(); } TextView driver_name_header = (TextView) header.findViewById(R.id.username); TextView car_id_header = (TextView) header.findViewById(R.id.car_id); final ImageView pp_header = (ImageView) header.findViewById(R.id.profile_image); try { car_id_header.setText(driver_data.getString("license")); driver_name_header.setText(driver_data.getString("name")); Client client = new Client(); client.get(driver_data.getString("image"), new FileAsyncHttpResponseHandler(OnlineActivity.this.getApplicationContext()) { @Override public void onFailure(int i, Header[] headers, Throwable throwable, File file) { } @Override public void onSuccess(int statusCode, Header[] headers, final File response) { OnlineActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Bitmap image = BitmapFactory.decodeFile(response.getPath()); pp_header.setImageBitmap(image); } }); } }); } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { SharedPreferences.Editor editor = shares.edit(); final Client client1 = new Client(); RequestParams params1 = new RequestParams(); editor.putBoolean("ONLINE", false); editor.putBoolean("LOGIN", false); editor.commit(); Intent intent = getApplicationContext().getPackageManager() .getLaunchIntentForPackage(getApplicationContext().getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(OnlineActivity.this, MenuItemActivity.class); i.putExtra("MENU_ITEM", 0); OnlineActivity.this.startActivity(i); drawerLayout.closeDrawers(); } }); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { //Checking if the item is in checked state or not, if not make it in checked state nav = true; menuItem.setChecked(false); //Closing drawer on item click drawerLayout.closeDrawers(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Fragment fragment; //Check to see which item was being clicked and perform appropriate action switch (menuItem.getItemId()) { case R.id.timetable: case R.id.service: case R.id.history: case R.id.mission: case R.id.points: case R.id.notice: Intent i = new Intent(OnlineActivity.this, MenuItemActivity.class); i.putExtra("MENU_ITEM", menuItem.getItemId()); OnlineActivity.this.startActivity(i); break; case R.id.login: Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show(); SharedPreferences.Editor editor = shares.edit(); final Client client = new Client(); RequestParams params = new RequestParams(); params.put("id", shares.getInt("ID", 0)); params.put("status", 999); client.post("driver/setStatus", params, new JsonHttpResponseHandler()); editor.putBoolean("ONLINE", false); editor.putBoolean("LOGIN", false); editor.commit(); Intent intent = getApplicationContext().getPackageManager() .getLaunchIntentForPackage(getApplicationContext().getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; default: Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); break; } return false; } }); drawerLayout = (DrawerLayout) findViewById(R.id.drawer); 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); drawerLayout.setSelected(false); } @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); } }; drawerLayout.setDrawerListener(actionBarDrawerToggle); actionBarDrawerToggle.syncState(); }
From source file:com.example.george.sharedelementimplementation.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_slow) { sAnimatorScale = item.isChecked() ? 1 : 5; item.setChecked(!item.isChecked()); }/*from w w w . ja va 2 s .c o m*/ return super.onOptionsItemSelected(item); }
From source file:com.ota.updates.activities.MainActivity.java
/** * Setup listeners for the NavigationView drawer so that when items are selected some actions * can be take/*from w ww . j av a 2 s . c om*/ * * @param navigationView The NavigationView we are listening for * @param drawerLayout The Drawer Layout containing the items */ private void setupNavigationViewOnItemSelected(NavigationView navigationView, final DrawerLayout drawerLayout) { //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 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(); //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.ota_updates: checkForUpdate(); return true; // For rest of the options we just show a toast on click case R.id.ota_versions: loadFragment(new AddonsFragment()); return true; case R.id.ota_addons: loadFragment(new AddonsFragment()); return true; case R.id.rom_donate: Toast.makeText(getApplicationContext(), "Drafts Selected", Toast.LENGTH_SHORT).show(); return true; case R.id.app_about: loadFragment(new AboutFragment()); return true; case R.id.app_github: String appGitHubUrl = mContext.getResources().getString(R.string.app_github_url); Utils.openWebsite(mContext, appGitHubUrl); default: return true; } } }); }