List of usage examples for android.view MenuItem setTitle
public MenuItem setTitle(@StringRes int title);
From source file:com.techno.jay.codingcontests.Home.java
private void applyFontToMenuItem(MenuItem mi) { Typeface font = Typeface.createFromAsset(getAssets(), "ProductSans-Regular.ttf"); SpannableString mNewTitle = new SpannableString(mi.getTitle()); mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); mi.setTitle(mNewTitle); }
From source file:org.mariotaku.twidere.fragment.support.BaseStatusesMultiColumnListFragment.java
private void openMenu(final View view, final ParcelableStatus status) { mSelectedStatus = status;//from ww w. j a v a 2 s.c o m if (view == null || status == null) return; if (mPopupMenu != null && mPopupMenu.isShowing()) { mPopupMenu.dismiss(); } final int activated_color = ThemeUtils.getUserThemeColor(getActivity()); mPopupMenu = PopupMenu.getInstance(getActivity(), view); mPopupMenu.inflate(R.menu.action_status); final boolean separate_retweet_action = mPreferences.getBoolean(PREFERENCE_KEY_SEPARATE_RETWEET_ACTION, PREFERENCE_DEFAULT_SEPARATE_RETWEET_ACTION); final Menu menu = mPopupMenu.getMenu(); setMenuForStatus(getActivity(), menu, status); final MenuItem retweet_submenu = menu.findItem(R.id.retweet_submenu); if (retweet_submenu != null) { retweet_submenu.setVisible(!separate_retweet_action); } final MenuItem direct_quote = menu.findItem(R.id.direct_quote); if (direct_quote != null) { direct_quote.setVisible(separate_retweet_action); } final MenuItem direct_retweet = menu.findItem(R.id.direct_retweet); if (direct_retweet != null) { final Drawable icon = direct_retweet.getIcon().mutate(); direct_retweet .setVisible(separate_retweet_action && (!status.user_is_protected || isMyRetweet(status))); if (isMyRetweet(status)) { icon.setColorFilter(activated_color, PorterDuff.Mode.MULTIPLY); direct_retweet.setTitle(R.string.cancel_retweet); } else { icon.clearColorFilter(); direct_retweet.setTitle(R.string.retweet); } } mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.show(); }
From source file:tw.com.geminihsu.app01.fragment.Fragment_Client_Service_test.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem item = menu.add(Menu.NONE, ACTIONBAR_MENU_ITEM_FIILTER, Menu.NONE, getString(R.string.order_call_taxi_page_title)); SpannableString spanString = new SpannableString(item.getTitle().toString()); spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white item.setTitle(spanString); Utility driver = new Utility(getActivity()); if (isShowOneKey && driver.getAllDriverAccountInfo().isEmpty()) item.setVisible(true);/*from ww w.j av a2s. c o m*/ else item.setVisible(false); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); super.onCreateOptionsMenu(menu, inflater); }
From source file:com.dwdesign.tweetings.fragment.UserListDetailsFragment.java
@Override public void onClick(final View view) { switch (view.getId()) { case R.id.follow_more: { if (mUserList == null) return; /*if (mAccountId != mUserId) { mFollowMoreButton.setVisibility(View.GONE); if (mUserList.isFollowing()) { mService.destroyUserListSubscription(mAccountId, mUserList.getId()); } else {//from w w w. j a va2s . c om mService.createUserListSubscription(mAccountId, mUserList.getId()); } } else {*/ mPopupMenu = PopupMenu.getInstance(getActivity(), view); mPopupMenu.inflate(R.menu.action_user_list_details); if (mUserId == mAccountId) { final MenuItem followItem = mPopupMenu.getMenu().findItem(MENU_FOLLOW); followItem.setVisible(false); } else { final MenuItem followItem = mPopupMenu.getMenu().findItem(MENU_FOLLOW); followItem.setTitle(mUserList.isFollowing() ? R.string.unfollow : R.string.follow); final MenuItem addMemberItem = mPopupMenu.getMenu().findItem(MENU_ADD); addMemberItem.setVisible(false); final MenuItem deleteItem = mPopupMenu.getMenu().findItem(MENU_DELETE_SUBMENU); deleteItem.setVisible(false); } mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.show(); //} break; } case R.id.retry: { reloadUserListInfo(); break; } case R.id.profile_image_container: { if (mAccountId > 0 && (mUserId > 0 || mUserScreenName != null)) { openUserProfile(getActivity(), mAccountId, mUserId, mUserScreenName); } break; } } }
From source file:info.tellmetime.TellmetimeActivity.java
public void showPopupMenu(View view) { PopupMenu popup = new PopupMenu(this, view); popup.setOnMenuItemClickListener(this); popup.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override/*from w w w . jav a2 s . c o m*/ public void onDismiss(PopupMenu popupMenu) { mHider.delayedHide(4000); } }); popup.getMenuInflater().inflate(R.menu.menu, popup.getMenu()); MenuItem toggle = popup.getMenu().findItem(R.id.action_mode); toggle.setTitle(isNightMode ? R.string.action_mode_day : R.string.action_mode_night); toggle.setIcon(isNightMode ? R.drawable.ic_action_brightness_high : R.drawable.ic_action_brightness_low); popup.show(); mHider.showNoAutoHide(); }
From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java
private void setPrefFavFilter(boolean prefFavFilter, boolean restart) { mFavFilter = prefFavFilter;//from ww w . j av a 2 s . c o m if (mMenu != null) { final MenuItem item = mMenu.findItem(R.id.action_fav_filter); item.setIcon(mFavFilter ? R.drawable.ic_favorite_24dp : R.drawable.ic_favorite_outline_24dp); item.setTitle(mFavFilter ? R.string.action_show_all : R.string.action_show_favs); final int color = ContextCompat.getColor(this, R.color.icons); final int alpha = 255; MenuTint.colorMenuItem(item, color, alpha); } if (restart) { getSupportLoaderManager().restartLoader(0, null, this); } }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java
/** * {@inheritDoc}/* w w w . ja va2 s . co m*/ */ @Override public void onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem item = menu.findItem(R.id.busstopmap_option_menu_trafficview); if (map != null && map.isTrafficEnabled()) { item.setTitle(R.string.map_menu_mapoverlay_trafficviewoff); } else { item.setTitle(R.string.map_menu_mapoverlay_trafficviewon); } item.setEnabled(map != null); item = menu.findItem(R.id.busstopmap_option_menu_services); item.setEnabled(services != null && services.length > 0); }
From source file:com.ruesga.rview.MainActivity.java
private void updateAccountStatus() { final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu(); String title = getString(R.string.menu_account_status); if (!TextUtils.isEmpty(mAccount.mAccount.status)) { title += DrawerNavigationView.SEPARATOR + EmojiHelper.resolveEmojiStatus(this, mAccount.mAccount.status); }/*from w w w . ja v a 2 s . c o m*/ MenuItem item = menu.findItem(R.id.menu_account_status); item.setTitle(title); }
From source file:net.etuldan.sparss.fragment.EntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mEntriesIds != null) { final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_star: { mFavorite = !mFavorite;/*from w w w. j a v a 2 s .com*/ if (mFavorite) { item.setTitle(R.string.menu_unstar).setIcon(R.drawable.ic_star); } else { item.setTitle(R.string.menu_star).setIcon(R.drawable.ic_star_border); } final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentValues values = new ContentValues(); values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0); ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, values, null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }.start(); break; } case R.id.menu_share: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); if (cursor != null) { String link = cursor.getString(mLinkPos); if (link != null) { String title = cursor.getString(mTitlePos); startActivity(Intent.createChooser( new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN), getString(R.string.menu_share))); } } break; } case R.id.menu_full_screen: { setImmersiveFullScreen(true); break; } case R.id.menu_copy_clipboard: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", link); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show(); break; } case R.id.menu_mark_as_unread: { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getUnreadContentValues(), null, null); } }.start(); activity.finish(); break; } case R.id.menu_open_in_browser: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); if (cursor != null) { String link = cursor.getString(mLinkPos); if (link != null) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); startActivity(browserIntent); } } break; } case R.id.menu_switch_full_original: { isChecked = !item.isChecked(); item.setChecked(isChecked); if (mPreferFullText) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { mPreferFullText = false; mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true); } }); } else { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos); if (alreadyMobilized) { activity.runOnUiThread(new Runnable() { @Override public void run() { mPreferFullText = true; mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true); } }); } else if (!isRefreshing()) { ConnectivityManager connectivityManager = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); // since we have acquired the networkInfo, we use it for basic checks if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) { FetcherService.addEntriesToMobilize(new long[] { mEntriesIds[mCurrentPagerPos] }); activity.startService(new Intent(activity, FetcherService.class) .setAction(FetcherService.ACTION_MOBILIZE_FEEDS)); activity.runOnUiThread(new Runnable() { @Override public void run() { showSwipeProgress(); } }); } else { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, R.string.network_error, Toast.LENGTH_SHORT).show(); } }); } } } break; } default: break; } } return super.onOptionsItemSelected(item); }
From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); // Make sure the 'Import photos' MenuItem is set up properly based on the number of // activities that handle ACTION_GET_CONTENT // 0 = hide the MenuItem // 1 = show 'Import photos from APP_NAME' to go to the one app that exists // 2 = show 'Import photos...' to have the user pick which app to import photos from Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); List<ResolveInfo> getContentActivities = getPackageManager().queryIntentActivities(intent, 0); mGetContentActivites.clear();//from w ww . j a va 2 s . co m for (ResolveInfo info : getContentActivities) { // Filter out the default system UI if (!TextUtils.equals(info.activityInfo.packageName, "com.android.documentsui")) { mGetContentActivites.add(info.activityInfo); } } // Hide the 'Import photos' action if there are no activities found MenuItem importPhotosMenuItem = menu.findItem(R.id.action_import_photos); importPhotosMenuItem.setVisible(!mGetContentActivites.isEmpty()); // If there's only one app that supports ACTION_GET_CONTENT, tell the user what that app is if (mGetContentActivites.size() == 1) { importPhotosMenuItem.setTitle(getString(R.string.gallery_action_import_photos_from, mGetContentActivites.get(0).loadLabel(getPackageManager()))); } else { importPhotosMenuItem.setTitle(R.string.gallery_action_import_photos); } return true; }