List of usage examples for android.view MenuItem getTitle
public CharSequence getTitle();
From source file:no.hiof.anl.laundrybooking.MainActivity.java
private void setupDrawerLayout() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); NavigationView view = (NavigationView) findViewById(R.id.navigation_view); view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from www. j a v a 2 s. co m public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(false); switch (menuItem.getItemId()) { case R.id.drawer_home: menuItem.setChecked(false); drawerLayout.closeDrawers(); return true; case R.id.drawer_statistics: Intent i = new Intent(getApplicationContext(), StatisticsActivity.class); startActivity(i); return true; case R.id.drawer_booking: i = new Intent(getApplicationContext(), BookingActivity.class); startActivity(i); drawerLayout.closeDrawers(); return true; case R.id.drawer_observation: i = new Intent(getApplicationContext(), ObservationActivity.class); startActivity(i); drawerLayout.closeDrawers(); return true; case R.id.drawer_setting: i = new Intent(getApplicationContext(), NotificationActivity.class); startActivity(i); drawerLayout.closeDrawers(); return true; case R.id.drawer_about: Snackbar.make(content, menuItem.getTitle() + " pressed", Snackbar.LENGTH_LONG).show(); menuItem.setChecked(false); drawerLayout.closeDrawers(); return true; case R.id.drawer_my_booking: i = new Intent(getApplicationContext(), MyBookingActivity.class); startActivity(i); drawerLayout.closeDrawers(); return true; default: Snackbar.make(content, menuItem.getTitle() + " pressed", Snackbar.LENGTH_LONG).show(); menuItem.setChecked(false); drawerLayout.closeDrawers(); return true; } } }); drawerName = (TextView) drawerLayout.findViewById(R.id.drawer_name); //drawerEmail = (TextView) drawerLayout.findViewById(R.id.drawer_email); }
From source file:org.wikipedia.edit.EditSectionActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_edit_section, menu); MenuItem item = menu.findItem(R.id.menu_save_section); if (editSummaryFragment.isActive()) { item.setTitle(getString(R.string.edit_next)); } else if (editPreviewFragment.isActive()) { item.setTitle(getString(R.string.edit_done)); } else {// ww w. j a va 2 s. c o m item.setTitle(getString(R.string.edit_next)); } if (abusefilterEditResult != null) { if (abusefilterEditResult.getType() == EditAbuseFilterResult.TYPE_ERROR) { item.setEnabled(false); } else { item.setEnabled(true); } } else { item.setEnabled(sectionTextModified); } View v = getLayoutInflater().inflate(R.layout.item_edit_actionbar_button, null); item.setActionView(v); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); v.setLayoutParams(params); TextView txtView = v.findViewById(R.id.edit_actionbar_button_text); txtView.setText(item.getTitle()); txtView.setTypeface(null, item.isEnabled() ? Typeface.BOLD : Typeface.NORMAL); v.setTag(item); v.setClickable(true); v.setEnabled(item.isEnabled()); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onOptionsItemSelected((MenuItem) view.getTag()); } }); v.setBackgroundColor(ContextCompat.getColor(this, item.isEnabled() ? (editPreviewFragment.isActive() ? R.color.accent50 : ResourceUtil.getThemedAttributeId(this, R.attr.colorAccent)) : R.color.base50)); return true; }
From source file:org.brandroid.openmanager.fragments.ContentFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.content_layout, container, false); mGrid = (GridView) v.findViewById(R.id.content_grid); final OpenFragment me = this; mGrid.setOnKeyListener(new OnKeyListener() { @Override//from w w w . ja va2 s. com public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) return false; int col = 0; int cols = 1; try { if (!OpenExplorer.BEFORE_HONEYCOMB) { Method m = GridView.class.getMethod("getNumColumns", new Class[0]); Object tmp = m.invoke(mGrid, new Object[0]); if (tmp instanceof Integer) { cols = (Integer) tmp; col = mGrid.getSelectedItemPosition() % cols; } } } catch (Exception e) { } Logger.LogDebug("ContentFragment.mGrid.onKey(" + keyCode + "," + event + ")@" + col); if (!OpenExplorer.BEFORE_HONEYCOMB) cols = (Integer) mGrid.getNumColumns(); if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && col == 0) return onFragmentDPAD(me, false); else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && col == cols - 1) return onFragmentDPAD(me, true); else if (MenuUtils.getMenuShortcut(event) != null) { MenuItem item = MenuUtils.getMenuShortcut(event); if (onOptionsItemSelected(item)) { Toast.makeText(v.getContext(), item.getTitle(), Toast.LENGTH_SHORT).show(); return true; } } return false; } }); v.setOnLongClickListener(this); mGrid.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { getMenuInflater().inflate(R.menu.context_file, menu); onPrepareOptionsMenu(menu); } }); //if(mProgressBarLoading == null) // mProgressBarLoading = v.findViewById(R.id.content_progress); setProgressVisibility(false); super.onCreateView(inflater, container, savedInstanceState); //v.setBackgroundResource(R.color.lightgray); /* if (savedInstanceState != null && savedInstanceState.containsKey("location")) { String location = savedInstanceState.getString("location"); if(location != null && !location.equals("") && location.startsWith("/")) { Logger.LogDebug("Content location restoring to " + location); mPath = new OpenFile(location); mData = getManager().getChildren(mPath); updateData(mData); } //setContentPath(path, false); } */ return v; }
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();// w ww .j av a 2s.c o m 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.audiokernel.euphonyrmt.fragments.BrowseFragment.java
private void addToPlaylist(final MenuItem item) { final EditText input = new EditText(getActivity()); final int id = item.getOrder(); if (item.getItemId() == 0) { new AlertDialog.Builder(getActivity()).setTitle(R.string.playlistName) .setMessage(R.string.newPlaylistPrompt).setView(input) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override/* w w w. ja va2 s. c o m*/ public void onClick(final DialogInterface dialog, final int which) { final String name = input.getText().toString().trim(); if (!name.isEmpty()) { mApp.oMPDAsyncHelper.execAsync(new Runnable() { @Override public void run() { add(mItems.get(id), name); } }); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { // Do nothing. } }).show(); } else { add(mItems.get(id), item.getTitle().toString()); } }
From source file:com.google.android.apps.forscience.whistlepunk.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem == null) { return false; }//from w w w. j a v a 2s . co m if (menuItem.getGroupId() == R.id.navigation_top) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); Fragment fragment; int itemId = menuItem.getItemId(); final String tag = String.valueOf(itemId); fragment = getFragmentManager().findFragmentByTag(tag); if (fragment == null) { fragment = createNewFragment(itemId); } adjustActivityForSelectedItem(itemId); mTitleToRestore = getTitleToRestore(menuItem); transaction.replace(R.id.content_container, fragment, tag).commit(); if (menuItem.isCheckable()) { menuItem.setChecked(true); } mDrawerLayout.closeDrawers(); restoreActionBar(); mSelectedItemId = itemId; } else if (menuItem.getGroupId() == R.id.navigation_bottom) { mDrawerLayout.closeDrawers(); // Launch intents Intent intent = null; int itemId = menuItem.getItemId(); if (itemId == R.id.navigation_item_website) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website_url))); } else if (itemId == R.id.navigation_item_settings) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_SETTINGS); } else if (itemId == R.id.navigation_item_about) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_ABOUT); } else if (itemId == R.id.dev_testing_options) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_DEV_OPTIONS); } else if (itemId == R.id.navigation_item_feedback) { mFeedbackProvider.sendFeedback(new LoggingConsumer<Boolean>(TAG, "Send feedback") { @Override public void success(Boolean value) { if (!value) { showFeedbackError(); } } @Override public void fail(Exception e) { super.fail(e); showFeedbackError(); } }); } if (intent != null) { startActivity(intent); } } return false; }
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
@SuppressWarnings("deprecation") @Override/* www. j av a 2 s . c om*/ public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case MENU_TAKE_PHOTO: { if (item.getTitle().equals(getString(R.string.remove_photo))) { if (mImageUri == null) return false; removeAttachments(); } else { takePhoto(); } break; } case MENU_LAST_PHOTO: { String[] projection = new String[] { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, MediaStore.Images.ImageColumns.DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE }; final Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"); if (cursor.moveToFirst()) { String imageLocation = cursor.getString(1); File imageFile = new File(imageLocation); if (imageFile != null && imageFile.exists()) { // TODO: is there a better way to do this? mImageUri = Uri.fromFile(imageFile); mIsPhotoAttached = false; mIsImageAttached = true; mImageThumbnailPreview.setVisibility(View.VISIBLE); reloadAttachedImageThumbnail(imageFile); } else { mIsImageAttached = false; } setMenu(); boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false); if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached && isAutoUpload) { postMedia(); } } break; } case MENU_ADD_IMAGE: { if (item.getTitle().equals(getString(R.string.remove_image))) { if (mImageUri == null) return false; removeAttachments(); } else { pickImage(); } break; } case MENU_SHORTEN_LINKS: { String s = parseString(mEditText.getText()); new UrlShortenerTask().execute(s); break; } case MENU_ADD_TO_BUFFER: { if (mIsBuffer) { mIsBuffer = false; } else { mIsBuffer = true; } setMenu(); break; } case MENU_SCHEDULE_TWEET: { if (mScheduleDate != null) { mScheduleDate = null; setMenu(); } else { Intent intent = new Intent(INTENT_ACTION_SCHEDULE_TWEET); if (mScheduleDate != null) { Bundle bundle = new Bundle(); bundle.putString(INTENT_KEY_SCHEDULE_DATE_TIME, mScheduleDate); intent.putExtras(bundle); } startActivityForResult(intent, REQUEST_SCHEDULE_DATE); } break; } case MENU_UPLOAD: { if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached) { postMedia(true); } break; } case MENU_ADD_LOCATION: { final boolean attach_location = mPreferences.getBoolean(PREFERENCE_KEY_ATTACH_LOCATION, false); if (!attach_location) { getLocation(); } mPreferences.edit().putBoolean(PREFERENCE_KEY_ATTACH_LOCATION, !attach_location).commit(); setMenu(); break; } case MENU_DRAFTS: { startActivity(new Intent(INTENT_ACTION_DRAFTS)); break; } case MENU_DELETE: { if (mImageUri == null) return false; removeAttachments(); break; } case MENU_EDIT: { if (mImageUri == null) return false; final Intent intent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE); intent.setData(mImageUri); startActivityForResult(Intent.createChooser(intent, getString(R.string.open_with_extensions)), REQUEST_EDIT_IMAGE); // Create the intent needed to start feather /*Intent newIntent = new Intent( this, FeatherActivity.class ); // set the source image uri newIntent.setData( mImageUri ); // pass the required api key ( http://developers.aviary.com/ ) newIntent.putExtra( "API_KEY", AVIARY_SDK_API_KEY ); // pass the uri of the destination image file (optional) // This will be the same uri you will receive in the onActivityResult //newIntent.putExtra( "output", mImageUri); // format of the destination image (optional) newIntent.putExtra( "output-format", Bitmap.CompressFormat.JPEG.name() ); // output format quality (optional) newIntent.putExtra( "output-quality", 85 ); // you can force feather to display only a certain tools // newIntent.putExtra( "tools-list", new String[]{"ADJUST", "BRIGHTNESS" } ); // enable fast rendering preview newIntent.putExtra( "effect-enable-fast-preview", true ); // limit the image size // You can pass the current display size as max image size because after // the execution of Aviary you can save the HI-RES image so you don't need a big // image for the preview // newIntent.putExtra( "max-image-size", 800 ); // you want to hide the exit alert dialog shown when back is pressed // without saving image first // newIntent.putExtra( "hide-exit-unsave-confirmation", true ); // ..and start feather startActivityForResult( newIntent, ACTION_REQUEST_FEATHER );*/ break; } case MENU_VIEW: { openImage(this, mImageUri, false); break; } case MENU_TOGGLE_SENSITIVE: { final boolean has_media = (mIsImageAttached || mIsPhotoAttached) && mImageUri != null; if (!has_media) return false; mIsPossiblySensitive = !mIsPossiblySensitive; setMenu(); break; } } return true; }
From source file:com.teitsmch.hearthmaker.MainActivity.java
public void selectItem(MenuItem currentItem) { // Reset Spinner positions mClassSpinner.setSelection(0);/*from w ww .j a va 2s .c om*/ for (Spinner spinner : spinners) { spinner.setSelection(0); } // Reset Search View if (mFragment != null) { searchView.setQuery("", true); searchView.onActionViewCollapsed(); } // Reset Subtitle updateSubtitle(null); // update the main content by replacing fragments switch (currentItem.getItemId()) { case CATALOG_FRAGMENT_ID: mMainActivityPresenter.resetFilter(); mFragment = CardViewFragment.newInstance(); if (mSpinnerView.getVisibility() == View.VISIBLE) { mSpinnerView.setVisibility(View.GONE); } currentClasses.clear(); currentClasses.add("CLEAR"); currentClasses.addAll(Arrays.asList(dialogClasses)); mClassSpinnerAdapter.notifyDataSetChanged(); break; case R.id.nav_new_deck: createNewDeckDialog(); return; default: if (currentItem.getGroupId() == R.id.navigation_deck_group) { mFragment = DeckFragment.newInstance(currentDeckClass, currentItem.getItemId(), (String) currentItem.getTitle()); currentDeckClass = ""; if (mSpinnerView.getVisibility() == View.VISIBLE) { mSpinnerView.setVisibility(View.GONE); updateSubtitle(cardCount); } } break; } FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.replace(R.id.content_frame, mFragment); ft.commit(); // Close the drawer setTitle(currentItem.getTitle()); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.akhbulatov.wordkeeper.ui.activity.MainActivity.java
private void selectDrawerItem(MenuItem item) { Class fragmentClass = null;//from ww w .ja v a 2 s . c o m Fragment fragment = null; switch (item.getItemId()) { case R.id.menu_drawer_all_words: fragmentClass = WordListFragment.class; break; case R.id.menu_drawer_categories: fragmentClass = CategoryListFragment.class; break; case R.id.menu_drawer_rate_app: showRateApp(); break; case R.id.menu_drawer_about: showAbout(); break; default: fragmentClass = WordListFragment.class; } // Block is executed only if the selected item is a fragment, // otherwise was the selected activity and the replacement fragment is not executed if (fragmentClass != null) { try { fragment = (Fragment) fragmentClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (fragmentClass == WordListFragment.class) { getSupportFragmentManager().popBackStack(); transaction.replace(R.id.layout_root_container, fragment, WORD_LIST_FRAGMENT_TAG); mWordListFragment = (WordListFragment) fragment; } else { transaction.replace(R.id.layout_root_container, fragment, CATEGORY_LIST_FRAGMENT_TAG); transaction.addToBackStack(null); mCategoryListFragment = (CategoryListFragment) fragment; } transaction.commit(); // Not required for activity. Only for a fragment item.setChecked(true); setTitle(item.getTitle()); } mDrawerLayout.closeDrawers(); }
From source file:org.voidsink.anewjkuapp.activity.MainActivity.java
private Fragment attachFragment(MenuItem menuItem, boolean saveLastFragment) { if (menuItem == null) { return null; }// w ww . ja v a 2 s . co m Class<? extends Fragment> startFragment = null; switch (menuItem.getItemId()) { case R.id.nav_cal: startFragment = CalendarFragment.class; break; case R.id.nav_exams: startFragment = ExamFragment.class; break; case R.id.nav_grades: startFragment = AssessmentFragment.class; break; case R.id.nav_courses: startFragment = LvaFragment.class; break; case R.id.nav_stats: startFragment = StatFragment.class; break; case R.id.nav_mensa: startFragment = MensaFragment.class; break; case R.id.nav_map: startFragment = MapFragment.class; break; case R.id.nav_oeh_news: startFragment = OehNewsFragment.class; break; case R.id.nav_oeh_info: startFragment = OehInfoFragment.class; break; case R.id.nav_oeh_rigths: startFragment = OehRightsFragment.class; break; case R.id.nav_curricula: startFragment = CurriculaFragment.class; break; default: break; } if (startFragment != null) { try { menuItem.setChecked(true); Fragment f = startFragment.newInstance(); Bundle b = new Bundle(); b.putCharSequence(Consts.ARG_FRAGMENT_TITLE, menuItem.getTitle()); f.setArguments(b); final Fragment oldFragment = getSupportFragmentManager().findFragmentByTag(Consts.ARG_FRAGMENT_TAG); final boolean addToBackstack = (oldFragment != null) && (!oldFragment.getClass().equals(f.getClass())); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.container, f, Consts.ARG_FRAGMENT_TAG); if (addToBackstack) { ft.addToBackStack(f.getClass().getCanonicalName()); } ft.commit(); if (saveLastFragment) { PreferenceWrapper.setLastFragment(this, menuItem.getItemId()); } initActionBar(); return f; } catch (Exception e) { Log.w(TAG, "fragment instantiation failed", e); Analytics.sendException(this, e, false); if (saveLastFragment) { PreferenceWrapper.setLastFragment(this, PreferenceWrapper.PREF_LAST_FRAGMENT_DEFAULT); } return null; } } return null; }