List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:org.csploit.android.plugins.PortScanner.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.scanner_custom_parameters: if (item.isChecked()) hideParametersField();/* w w w. j av a2 s .c o m*/ else displayParametersField(); item.setChecked(!item.isChecked()); return true; case R.id.select_ports: new InputDialog(getString(R.string.select_ports), getString(R.string.enter_ports_list), this, new InputDialogListener() { @Override public void onInputEntered(String input) { input = input.trim(); if (!input.isEmpty()) { String[] ports = input.split("[^\\d]+"); for (String port : ports) { try { if (port.isEmpty()) throw new Exception(getString(R.string.invalid_port_) + port + "'."); else { int iport = Integer.parseInt(port); if (iport <= 0 || iport > 65535) throw new Exception(getString(R.string.port_must_be_greater)); } } catch (Exception e) { new ErrorDialog("Error", e.toString(), PortScanner.this).show(); return; } } mCustomPorts = ""; for (int i = 0, last = ports.length - 1; i < ports.length; i++) { mCustomPorts += ports[i]; if (i != last) mCustomPorts += ","; } if (mCustomPorts.isEmpty()) { mCustomPorts = null; new ErrorDialog(getString(R.string.error), getString(R.string.invalid_ports), PortScanner.this).show(); } hideParametersField(); mMenu.findItem(R.id.scanner_custom_parameters).setChecked(false); Logger.debug("mCustomPorts = " + mCustomPorts); } else new ErrorDialog(getString(R.string.error), getString(R.string.empty_port_list), PortScanner.this).show(); } }).show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.dmfs.tasks.TaskListActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.task_list_activity_menu, menu); // restore menu state MenuItem item = menu.findItem(R.id.menu_alarms); if (item != null) { item.setChecked(AlarmBroadcastReceiver.getAlarmPreference(this)); }//ww w . ja v a 2 s . c om // search setupSearch(menu); return true; }
From source file:com.microhealthllc.mbmicalc.BmiChartRed.java
private void setUpNavigationDrawer() { /*// www . jav a2 s .com Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); try { assert actionBar != null; actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setSubtitle(getString(R.string.subtitle)); actionBar.setDisplayShowTitleEnabled(true); } catch (Exception ignored) { } */ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); switch (menuItem.getItemId()) { case R.id.navigation_item_1: // mCurrentSelectedPosition = 0; break; case R.id.navigation_item_2: // mCurrentSelectedPosition = 1; Intent i = new Intent(BmiChartRed.this, BasicSettings.class); startActivity(i); break; case R.id.navigation_item_3: // mCurrentSelectedPosition = 2; Intent j = new Intent(BmiChartRed.this, LogActivity.class); startActivity(j); break; case R.id.navigation_item_4: // mCurrentSelectedPosition = 3; new LovelyStandardDialog(BmiChartRed.this).setTopColorRes(R.color.accent) .setButtonsColorRes(R.color.accent) .setTitle("Warning!!") .setMessage(" This will delete all stored data,This cannot be undone") .setPositiveButton(android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(BmiChartRed.this, "positive clicked", Toast.LENGTH_SHORT).show(); Intent i = new Intent(BmiChartRed.this, BmiChartRed.class); startActivity(i); } }).setNegativeButton(android.R.string.no, null).show(); break; case R.id.navigation_item_5: Intent about = new Intent(BmiChartRed.this, About.class); startActivity(about); break; case R.id.navigation_item_6: Intent js = new Intent(BmiChartRed.this, LineColumnDependencyActivity.class); startActivity(js); break; case R.id.bmi_info: startActivity(new Intent(BmiChartRed.this, AdditionalBMIinfo.class)); } // setTabs(mCurrentSelectedPosition + 1); mDrawerLayout.closeDrawer(mNavigationView); return true; } }); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); //getSupportActionBar().setTitle(getString(R.string.drawer_opened)); invalidateOptionsMenu(); } public void onDrawerClosed(View view) { super.onDrawerClosed(view); //getSupportActionBar().setTitle(mActivityTitle); invalidateOptionsMenu(); } }; mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); }
From source file:com.microhealthllc.mbmicalc.BmiChartBloodRed.java
private void setUpNavigationDrawer() { /*/* w w w . java 2 s . c o m*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); try { assert actionBar != null; actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setSubtitle(getString(R.string.subtitle)); actionBar.setDisplayShowTitleEnabled(true); } catch (Exception ignored) { } */ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); switch (menuItem.getItemId()) { case R.id.navigation_item_1: // mCurrentSelectedPosition = 0; break; case R.id.navigation_item_2: // mCurrentSelectedPosition = 1; Intent i = new Intent(BmiChartBloodRed.this, BasicSettings.class); startActivity(i); break; case R.id.navigation_item_3: // mCurrentSelectedPosition = 2; Intent j = new Intent(BmiChartBloodRed.this, LogActivity.class); startActivity(j); break; case R.id.navigation_item_4: // mCurrentSelectedPosition = 3; new LovelyStandardDialog(BmiChartBloodRed.this).setTopColorRes(R.color.accent) .setButtonsColorRes(R.color.accent) .setTitle("Warning!!") .setMessage(" This will delete all stored data,This cannot be undone") .setPositiveButton(android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(BmiChartBloodRed.this, "positive clicked", Toast.LENGTH_SHORT) .show(); Intent i = new Intent(BmiChartBloodRed.this, BmiChartBloodRed.class); startActivity(i); } }).setNegativeButton(android.R.string.no, null).show(); break; case R.id.navigation_item_5: Intent about = new Intent(BmiChartBloodRed.this, About.class); startActivity(about); break; case R.id.navigation_item_6: Intent js = new Intent(BmiChartBloodRed.this, LineColumnDependencyActivity.class); startActivity(js); break; case R.id.bmi_info: startActivity(new Intent(BmiChartBloodRed.this, AdditionalBMIinfo.class)); } // setTabs(mCurrentSelectedPosition + 1); mDrawerLayout.closeDrawer(mNavigationView); return true; } }); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); //getSupportActionBar().setTitle(getString(R.string.drawer_opened)); invalidateOptionsMenu(); } public void onDrawerClosed(View view) { super.onDrawerClosed(view); //getSupportActionBar().setTitle(mActivityTitle); invalidateOptionsMenu(); } }; mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); }
From source file:com.microhealthllc.mbmicalc.BmiChartOrange.java
private void setUpNavigationDrawer() { /*/*from w w w . j av a 2s . c om*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); try { assert actionBar != null; actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setSubtitle(getString(R.string.subtitle)); actionBar.setDisplayShowTitleEnabled(true); } catch (Exception ignored) { } */ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); switch (menuItem.getItemId()) { case R.id.navigation_item_1: // mCurrentSelectedPosition = 0; break; case R.id.navigation_item_2: // mCurrentSelectedPosition = 1; Intent i = new Intent(BmiChartOrange.this, BasicSettings.class); startActivity(i); break; case R.id.navigation_item_3: // mCurrentSelectedPosition = 2; Intent j = new Intent(BmiChartOrange.this, LogActivity.class); startActivity(j); break; case R.id.navigation_item_4: // mCurrentSelectedPosition = 3; new LovelyStandardDialog(BmiChartOrange.this).setTopColorRes(R.color.accent) .setButtonsColorRes(R.color.accent) .setTitle("Warning!!") .setMessage(" This will delete all stored data,This cannot be undone") .setPositiveButton(android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(BmiChartOrange.this, "positive clicked", Toast.LENGTH_SHORT) .show(); Intent i = new Intent(BmiChartOrange.this, BmiChartOrange.class); startActivity(i); } }).setNegativeButton(android.R.string.no, null).show(); break; case R.id.navigation_item_5: Intent about = new Intent(BmiChartOrange.this, About.class); startActivity(about); break; case R.id.navigation_item_6: Intent js = new Intent(BmiChartOrange.this, LineColumnDependencyActivity.class); startActivity(js); break; case R.id.bmi_info: startActivity(new Intent(BmiChartOrange.this, AdditionalBMIinfo.class)); } // setTabs(mCurrentSelectedPosition + 1); mDrawerLayout.closeDrawer(mNavigationView); return true; } }); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); //getSupportActionBar().setTitle(getString(R.string.drawer_opened)); invalidateOptionsMenu(); } public void onDrawerClosed(View view) { super.onDrawerClosed(view); //getSupportActionBar().setTitle(mActivityTitle); invalidateOptionsMenu(); } }; mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); }
From source file:com.microhealthllc.mbmicalc.BmiChartyellow.java
private void setUpNavigationDrawer() { /*//from w w w.j av a 2 s.c o m Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); try { assert actionBar != null; actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setSubtitle(getString(R.string.subtitle)); actionBar.setDisplayShowTitleEnabled(true); } catch (Exception ignored) { } */ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); switch (menuItem.getItemId()) { case R.id.navigation_item_1: // mCurrentSelectedPosition = 0; break; case R.id.navigation_item_2: // mCurrentSelectedPosition = 1; Intent i = new Intent(BmiChartyellow.this, BasicSettings.class); startActivity(i); break; case R.id.navigation_item_3: // mCurrentSelectedPosition = 2; Intent j = new Intent(BmiChartyellow.this, LogActivity.class); startActivity(j); break; case R.id.navigation_item_4: // mCurrentSelectedPosition = 3; new LovelyStandardDialog(BmiChartyellow.this).setTopColorRes(R.color.accent) .setButtonsColorRes(R.color.accent) .setTitle("Warning!!") .setMessage(" This will delete all stored data,This cannot be undone") .setPositiveButton(android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(BmiChartyellow.this, "positive clicked", Toast.LENGTH_SHORT) .show(); Intent i = new Intent(BmiChartyellow.this, BmiChartyellow.class); startActivity(i); } }).setNegativeButton(android.R.string.no, null).show(); break; case R.id.navigation_item_5: Intent about = new Intent(BmiChartyellow.this, About.class); startActivity(about); break; case R.id.navigation_item_6: Intent js = new Intent(BmiChartyellow.this, LineColumnDependencyActivity.class); startActivity(js); break; case R.id.bmi_info: startActivity(new Intent(BmiChartyellow.this, AdditionalBMIinfo.class)); } // setTabs(mCurrentSelectedPosition + 1); mDrawerLayout.closeDrawer(mNavigationView); return true; } }); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); //getSupportActionBar().setTitle(getString(R.string.drawer_opened)); invalidateOptionsMenu(); } public void onDrawerClosed(View view) { super.onDrawerClosed(view); //getSupportActionBar().setTitle(mActivityTitle); invalidateOptionsMenu(); } }; mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); }
From source file:com.maxwen.wallpaper.board.activities.WallpaperBoardActivity.java
private void setMenuChecked(boolean value) { MenuItem item = mBottomNavigationView.getMenu().findItem(mapPositionToMenuId()); if (item != null) { item.setChecked(value); }/* www . j ava2 s . c o m*/ }
From source file:com.example.ronald.tracle.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new DownloadTask().execute("https://flifo-qa.api.aero/flifo/v3/flight/sin/sq/998/d"); /*// w w w .j a va 2 s .c o m Parsing of data from previous activity */ String username = getIntent().getStringExtra("name"); String password = getIntent().getStringExtra("password"); String alias = getIntent().getStringExtra("alias"); myUser = username; pw = password; /* Declare your layout here */ Button sendBtn = (Button) findViewById(R.id.buttonSendAll); TextView nametv = (TextView) findViewById(R.id.username); TextView emailtv = (TextView) findViewById(R.id.email); emailtv.setText(username); nametv.setText(alias); // Initializing Toolbar and setting it as the actionbar 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 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.home: Intent intent = new Intent(MainActivity.this, MainActivity.class); startActivity(intent); return true; case R.id.explore: Intent intente = new Intent(MainActivity.this, SlideTab.class); startActivity(intente); return true; case R.id.network: Intent intentk = new Intent(MainActivity.this, SlideTab.class); startActivity(intentk); return true; case R.id.announcement: Intent intenti = new Intent(MainActivity.this, AnnounceActivity.class); startActivity(intenti); return true; case R.id.setting: String username = ""; String pw = ""; String PREFS_LOGIN_USERNAME_KEY = ""; String PREFS_LOGIN_PASSWORD_KEY = ""; PrefUtils.saveToPrefs(getApplication(), PREFS_LOGIN_USERNAME_KEY, username); PrefUtils.saveToPrefs(getApplication(), PREFS_LOGIN_PASSWORD_KEY, pw); System.exit(0); return true; // For rest of the options we just show a toast on click default: Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); return true; } } }); // Initializing Drawer Layout and ActionBarToggle 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); } @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); //Toast.makeText(this, "username: "+username+" pw: "+password, Toast.LENGTH_SHORT).show(); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); /* This is the initial step in getting back the token from GCM */ //mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { // mInformationTextView.setText(getString(R.string.gcm_send_message)); } else { // mInformationTextView.setText(getString(R.string.token_error_message)); } } }; //mInformationTextView = (TextView) findViewById(R.id.informationTextView); /* Check play services, if not GCM won't work. */ if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); Bundle localBundle = new Bundle(); localBundle.putString("name", username); localBundle.putString("password", password); intent.putExtras(localBundle); startService(intent); } }
From source file:com.zyascend.RecompileToDo.view.tasks.TasksActivity.java
private void setupDrawerContent(NavigationView navView) { navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from ww w.ja v a 2 s . c om public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.list_navigation_menu_item: break; case R.id.statistics_navigation_menu_item: Intent intent = new Intent(TasksActivity.this, StatisticsActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); break; default: break; } item.setChecked(true); drawerLayout.closeDrawers(); return true; } }); }
From source file:de.msal.shoutemo.fragments.ChatFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Bundle args = new Bundle(); switch (item.getItemId()) { /* filters */ case R.id.menu_filter_all: getLoaderManager().restartLoader(LOADER_ID_MESSAGES, null, this); item.setChecked(true); break;/*w ww . j ava2s.c o m*/ case R.id.menu_filter_shouts: args.putString("WHERE", ChatDb.Messages.COLUMN_NAME_TYPE + " = '" + Message.Type.SHOUT + "'"); getLoaderManager().restartLoader(LOADER_ID_MESSAGES, args, this); item.setChecked(true); break; case R.id.menu_filter_global: args.putString("WHERE", ChatDb.Messages.COLUMN_NAME_TYPE + " = '" + Message.Type.GLOBAL + "'"); getLoaderManager().restartLoader(LOADER_ID_MESSAGES, args, this); item.setChecked(true); break; case R.id.menu_filter_competitions: args.putString("WHERE", ChatDb.Messages.COLUMN_NAME_TYPE + " = '" + Message.Type.COMPETITION + "'"); getLoaderManager().restartLoader(LOADER_ID_MESSAGES, args, this); item.setChecked(true); break; case R.id.menu_filter_awards: args.putString("WHERE", ChatDb.Messages.COLUMN_NAME_TYPE + " = '" + Message.Type.AWARD + "'"); getLoaderManager().restartLoader(LOADER_ID_MESSAGES, args, this); item.setChecked(true); break; case R.id.menu_filter_promotions: args.putString("WHERE", ChatDb.Messages.COLUMN_NAME_TYPE + " = '" + Message.Type.PROMOTION + "'"); getLoaderManager().restartLoader(LOADER_ID_MESSAGES, args, this); item.setChecked(true); break; case R.id.menu_filter_threads: args.putString("WHERE", ChatDb.Messages.COLUMN_NAME_TYPE + " = '" + Message.Type.THREAD + "'"); getLoaderManager().restartLoader(LOADER_ID_MESSAGES, args, this); item.setChecked(true); break; } return super.onOptionsItemSelected(item); }