List of usage examples for android.view MenuItem getTitle
public CharSequence getTitle();
From source file:com.joeyturczak.jtscanner.ui.MainActivity.java
public void selectDrawerItem(MenuItem menuItem) { // Create a new fragment and specify the planet to show based on // position//from w w w . j a v a2 s.com if (!menuItem.isChecked()) { switch (menuItem.getItemId()) { case R.id.scanner_fragment: startScannerFragment(); break; case R.id.scan_list_fragment: startScanListFragment(); break; case R.id.settings_fragment: startSettingsFragment(); break; case R.id.file_list_fragment: startFileListFragment(); break; case R.id.about: startAboutFragment(); break; default: startScannerFragment(); } // Highlight the selected item, update the title, and close the drawer setTitle(menuItem.getTitle()); menuItem.setChecked(true); } mDrawerLayout.closeDrawers(); }
From source file:io.hypertrack.sendeta.view.Home.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.tracking_toogle: // Check if clicked item is Resume tracking if (getString(R.string.action_resume_tracking).equalsIgnoreCase(item.getTitle().toString())) { // Start Tracking the user startHyperTrackTracking(true); item.setTitle(R.string.action_pause_tracking); } else {// www . j a v a 2 s . c o m // Stop Tracking the user stopHyperTrackTracking(); item.setTitle(R.string.action_resume_tracking); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:fragments.IoTStarterPagerFragment.java
/** * Process the selected iot_menu item./*from ww w.jav a 2 s . c o m*/ * * @param item The selected iot_menu item. * @return true in all cases. */ @Override public boolean onOptionsItemSelected(MenuItem item) { Log.d(TAG, ".onOptionsItemSelected() entered"); /* if (((MainPagerActivity) getActivity()).getCurrentItem() == 0) { app.setDeviceId(((EditText) getActivity().findViewById(R.id.deviceIDValue)).getText().toString()); app.setOrganization(((EditText) getActivity().findViewById(R.id.organizationValue)).getText().toString()); app.setAuthToken(((EditText) getActivity().findViewById(R.id.authTokenValue)).getText().toString()); }*/ // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_accel: app.toggleAccel(); return true; case R.id.action_profiles: openProfiles(); return true; case R.id.action_tutorial: openTutorial(); return true; case R.id.action_web: openWeb(); return true; case R.id.action_clear_profiles: app.clearProfiles(); return true; case R.id.clear: app.setUnreadCount(0); app.getMessageLog().clear(); updateViewStrings(); return true; default: if (item.getTitle().equals(getResources().getString(R.string.app_name))) { getActivity().openOptionsMenu(); return true; } else { return super.onOptionsItemSelected(item); } } }
From source file:nyc.c4q.jordansmith.finefree.ActivityMain.java
public void addCarstoNav() { final Menu menu = navDrawerView.getMenu(); if (submenu == null) { submenu = menu.addSubMenu("Your Cars"); for (int i = 0; i < cars.size(); i++) { submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString()) .setIcon(R.drawable.ic_car_black_36dp); System.out.println(submenu.getItem(i).getItemId() + " " + submenu.getItem(i).getTitle()); final MenuItem item = submenu.getItem(i); Button button = new Button(this); button.setText("Remove"); button.setTextColor(ContextCompat.getColor(this, R.color.white)); item.setActionView(button);/*from www . j av a 2 s . co m*/ button.setBackground(getDrawable(R.drawable.button_shape)); item.getActionView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new AlertDialog.Builder(ActivityMain.this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Delete Car").setMessage("Are you sure you want to remove car?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { System.out.println("CLICKED " + item.getTitle()); cupboard().withDatabase(db).delete(Car.class, "name = ?", (String) item.getTitle()); updateSubmenu(); } }).setNegativeButton("Cancel", null).show(); } }); } } else { // for (int i = 0; i < cars.size(); i++) { // submenu.clear(); // submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString()) // .setIcon(R.drawable.ic_car_black_36dp); // // final MenuItem item = submenu.getItem(i); // Button button = new Button(this); // button.setText("Remove"); // item.setActionView(button); // item.getActionView().setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // // System.out.println("CLICKED " + item.getTitle()); // cupboard().withDatabase(db).delete(Car.class, "name = ?", (String) item.getTitle()); // // updateSubmenu(); // } // }); // // } setupCarMenu(); } }
From source file:com.ibm.iot.android.iotstarter.fragments.IoTStarterPagerFragment.java
/** * Process the selected iot_menu item./*from w w w . jav a 2s. c o m*/ * * @param item The selected iot_menu item. * @return true in all cases. */ @Override public boolean onOptionsItemSelected(MenuItem item) { Log.d(TAG, ".onOptionsItemSelected() entered"); if (((MainPagerActivity) getActivity()).getCurrentItem() == 0) { app.setDeviceId(((EditText) getActivity().findViewById(R.id.deviceIDValue)).getText().toString()); app.setOrganization( ((EditText) getActivity().findViewById(R.id.organizationValue)).getText().toString()); app.setAuthToken(((EditText) getActivity().findViewById(R.id.authTokenValue)).getText().toString()); } // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_accel: app.toggleAccel(); return true; case R.id.action_profiles: openProfiles(); return true; case R.id.action_tutorial: openTutorial(); return true; case R.id.action_web: openWeb(); return true; case R.id.action_clear_profiles: app.clearProfiles(); return true; case R.id.clear: app.setUnreadCount(0); app.getMessageLog().clear(); updateViewStrings(); return true; default: if (item.getTitle().equals(getResources().getString(R.string.app_name))) { getActivity().openOptionsMenu(); return true; } else { return super.onOptionsItemSelected(item); } } }
From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java
private View createFabMenuItem(MenuItem menuItem) { ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext()).inflate(getMenuItemLayoutId(), this, false);/* w w w .j a v a2s .com*/ FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab); CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view); TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view); fabMenuItemMap.put(miniFab, menuItem); cardViewMenuItemMap.put(cardView, menuItem); miniFab.setImageDrawable(menuItem.getIcon()); miniFab.setOnClickListener(this); cardView.setOnClickListener(this); ViewCompat.setAlpha(miniFab, 0f); ViewCompat.setAlpha(cardView, 0f); final CharSequence title = menuItem.getTitle(); if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) { cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor()); titleView.setText(title); titleView.setTypeface(null, Typeface.BOLD); titleView.setTextColor(miniFabTitleTextColor); if (miniFabTitleTextColorArray != null) { titleView.setTextColor(ContextCompat.getColorStateList(getContext(), miniFabTitleTextColorArray[menuItem.getOrder()])); } } else { fabMenuItem.removeView(cardView); } miniFab.setBackgroundTintList(miniFabBackgroundTint); if (miniFabBackgroundTintArray != null) { miniFab.setBackgroundTintList( ContextCompat.getColorStateList(getContext(), miniFabBackgroundTintArray[menuItem.getOrder()])); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { miniFab.setImageTintList(miniFabDrawableTint); } return fabMenuItem; }
From source file:ru.orangesoftware.financisto.activity.MainActivity.java
@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.isCheckable()) { menuItem.setChecked(true);//from w w w .j a v a2s.c o m } //Closing drawer on item click mDrawerLayout.closeDrawers(); if (menuItem.isChecked()) { ActionBar actionBar = getSupportActionBar(); actionBar.setTitle(menuItem.getTitle()); actionBar.setIcon(menuItem.getIcon()); } FragmentManager fm = getSupportFragmentManager(); navMenuItemId = menuItem.getItemId(); //Check to see which item was being clicked and perform appropriate action switch (navMenuItemId) { //Replacing the main content with ContentFragment Which is our Inbox View; case R.id.accounts: selectedAccountId = -1; android.support.v4.app.FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.main_content_frame, AccountListFragment.newInstance(), "accounts"); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); fab.show(); break; case R.id.blotter: android.support.v4.app.FragmentTransaction blotterFragmentTransaction = fm.beginTransaction(); blotterFragmentTransaction.replace(R.id.main_content_frame, BlotterFragment.newInstance(true, selectedAccountId), "blotter"); blotterFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); blotterFragmentTransaction.addToBackStack(null); blotterFragmentTransaction.commit(); fab.show(); break; case R.id.scheduled_transactions: startActivity(new Intent(this, ScheduledListActivity.class)); break; case R.id.budgets: android.support.v4.app.FragmentTransaction budgetFragmentTransaction = fm.beginTransaction(); budgetFragmentTransaction.replace(R.id.main_content_frame, new BudgetListFragment()); budgetFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); budgetFragmentTransaction.addToBackStack(null); budgetFragmentTransaction.commit(); fab.show(); break; case R.id.reports: android.support.v4.app.FragmentTransaction reportsFragmentTransaction = fm.beginTransaction(); reportsFragmentTransaction.replace(R.id.main_content_frame, new ReportListFragment()); reportsFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); reportsFragmentTransaction.addToBackStack(null); reportsFragmentTransaction.commit(); fab.hide(); break; case R.id.planner: startActivity(new Intent(this, PlannerActivity.class)); break; case R.id.entities: final MenuEntities[] entities = MenuEntities.values(); ListAdapter adapter = EnumUtils.createEntityEnumAdapter(this, entities); final AlertDialog d = new AlertDialog.Builder(this) .setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); MenuEntities e = entities[which]; startActivity(new Intent(MainActivity.this, e.getActivityClass())); } }).create(); d.setTitle(R.string.entities); d.show(); break; case R.id.menu_sync_online: doOnlineSync(); break; // case R.id.menu_sync_flowzr: // doFlowzrSync(); // break; case R.id.menu_mass_operations: startActivity(new Intent(this, MassOpActivity.class)); break; case R.id.menu_restore_database: doImport(); break; case R.id.menu_backup_database: doBackup(); break; case R.id.menu_backup_database_to: doBackupTo(); break; case R.id.menu_backup_restore_database_online: showPickOneDialog(this, R.string.backup_restore_database_online, BackupRestoreEntities.values(), this); break; case R.id.menu_import_export: showPickOneDialog(this, R.string.import_export, ImportExportEntities.values(), this); break; case R.id.menu_settings: startActivityForResult(new Intent(this, PreferencesActivity.class), CHANGE_PREFERENCES_RESULT); break; case R.id.menu_integrity_fix: doIntegrityFix(); break; case R.id.menu_donate: openBrowser("market://search?q=pname:ru.orangesoftware.financisto.support"); break; case R.id.menu_about: startActivity(new Intent(this, AboutActivity.class)); break; default: Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); fab.hide(); break; } fm.executePendingTransactions(); return true; }
From source file:com.fullmeadalchemist.mustwatch.MainActivity.java
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { // Handle navigation view item clicks here. switch (item.getItemId()) { case R.id.nav_batches: Log.i(TAG, "nav_batches selected from Drawer"); navigationController.navigateToBatches(); break;// ww w . jav a 2 s . c o m case R.id.nav_recipes: Log.i(TAG, "nav_recipes selected from Drawer"); navigationController.navigateToRecipes(); break; // case R.id.nav_groups: // Log.i(TAG, "nav_groups selected from Drawer"); // Log.w(TAG, "Groups view not yet implemented"); // navigationController.navigateToBatches(); // break; // case R.id.nav_settings: // Log.i(TAG, "nav_settings selected from Drawer"); // Log.w(TAG, "Settings view not yet implemented"); // navigationController.navigateToBatches(); // break; case R.id.nav_about: Log.i(TAG, "nav_about selected from Drawer"); navigationController.navigateToAbout(); break; default: Log.w(TAG, String.format("unknown selected from Drawer: %s", item.getTitle())); break; } DrawerLayout drawer = findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
private void showManehMenu() { View p = findViewById(R.id.anchorer); progressbar.setVisibility(View.GONE); final PopupMenu popup = new PopupMenu(this, p); //Inflating the Popup using xml file for (ManehCode m : CommonPlace.manehCodes) { if (!m.Maneh_fldCode.equals("0")) { int cnt = ReadingListDetailDA.getInstance(this).getCount("HeaderID=? and fldManehCodeNow=?", "", new String[] { CommonPlace.currentReadingList.id + "", m.Maneh_fldCode }); popup.getMenu().add(0, Integer.parseInt(m.Maneh_fldCode), 0, m.fldTiltle + "\t" + cnt); }//from w ww. j av a 2 s . c om } popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { filterManeh(item.getItemId(), item.getTitle().toString()); return true; } }); final Handler handler1 = new Handler(); progressbar.setVisibility(View.GONE); //android.R.attr.progressBarStyleLarge handler1.postDelayed(new Runnable() { @Override public void run() { popup.show(); } }, 100); }