Example usage for android.view MenuItem setTitle

List of usage examples for android.view MenuItem setTitle

Introduction

In this page you can find the example usage for android.view MenuItem setTitle.

Prototype


public MenuItem setTitle(@StringRes int title);

Source Link

Document

Change the title associated with this item.

Usage

From source file:com.pepperonas.showcase.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getTitle().equals("About")) {
        new MaterialDialog.Builder(this).title("MaterialDialog library").customView(R.layout.dialog_lib_info)
                .positiveText("OK").positiveColor(R.color.grey_700).icon(R.drawable.ic_launcher)
                .showListener(new MaterialDialog.ShowListener() {
                    @Override//from  w w w  . j  a v  a  2  s  .co m
                    public void onShow(AlertDialog d) {
                        super.onShow(d);
                        TextView tvLibInfo = (TextView) d.findViewById(R.id.tv_lib_info);
                        tvLibInfo.setText(Html.fromHtml(getString(R.string.web_presentation_info)));
                        tvLibInfo.setMovementMethod(LinkMovementMethod.getInstance());
                    }
                }).show();
    } else if (item.getTitle().equals(Const.HIDE_TOASTS)) {
        mSharedPreferences.edit().putBoolean("SHOW_TOASTS", false).apply();
        item.setTitle(Const.SHOW_TOASTS);
    } else if (item.getTitle().equals(Const.SHOW_TOASTS)) {
        mSharedPreferences.edit().putBoolean("SHOW_TOASTS", true).apply();
        item.setTitle(Const.HIDE_TOASTS);
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.vanita5.twittnuker.fragment.support.UserListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUserList userList = mUserList;
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    if (followItem != null) {
        followItem.setEnabled(userList != null);
        if (userList == null) {
            followItem.setIcon(android.R.color.transparent);
        }//from   w w  w . j a  v  a2s  . com
    }
    if (twitter == null || userList == null)
        return;
    final boolean isMyList = userList.user_id == userList.account_id;
    setMenuItemAvailability(menu, MENU_EDIT, isMyList);
    setMenuItemAvailability(menu, MENU_ADD, isMyList);
    setMenuItemAvailability(menu, MENU_DELETE, isMyList);
    final boolean isFollowing = userList.is_following;
    if (followItem != null) {
        followItem.setVisible(!isMyList);
        if (isFollowing) {
            followItem.setIcon(R.drawable.ic_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {
            followItem.setIcon(R.drawable.ic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
    }
}

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 {//from  w  ww. ja  v a 2s.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:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java

private void toggleStar(MenuItem item) {
    Snackbar added_snackbar = Snackbar.make(findViewById(R.id.activity_with_tabs), R.string.add_favorite,
            Snackbar.LENGTH_SHORT);//w  w w  .  j  a  v a  2s  . c  om

    Snackbar removed_snackbar = Snackbar.make(findViewById(R.id.activity_with_tabs), R.string.remove_favorite,
            Snackbar.LENGTH_SHORT);

    added_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("added to favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    removed_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("removed from favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    if (mIsStarred) {
        item.setIcon(R.drawable.ic_menu_star);
        item.setTitle("Favorite checkbox, not checked");
        viewModel.setIsStarredFor(mId, 0);
        removed_snackbar.show();
        mIsStarred = false;
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        item.setTitle("Favorite checkbox, checked");
        viewModel.setIsStarredFor(mId, 1);
        added_snackbar.show();
        mIsStarred = true;
    }
}

From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mRelationship;
    if (twitter == null || user == null)
        return;/* w w  w.  j  a v  a2s  .  c  om*/
    final int activatedColor = ThemeUtils.getUserThemeColor(getActivity());
    final boolean isMyself = user.account_id == user.id;
    final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget();
    final boolean isProtected = user.is_protected;
    final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
    final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
    setMenuItemAvailability(menu, MENU_EDIT, isMyself);
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    followItem.setVisible(!isMyself);
    final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself
            && relationship != null;
    followItem.setEnabled(shouldShowFollowItem);
    if (shouldShowFollowItem) {
        followItem.setTitle(
                isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow);
        followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add);
    } else {
        followItem.setTitle(null);
        followItem.setIcon(null);
    }
    if (user.id != user.account_id && relationship != null) {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget());
        setMenuItemAvailability(menu, MENU_BLOCK, true);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (blockItem != null) {
            final Drawable blockIcon = blockItem.getIcon();
            if (relationship.isSourceBlockingTarget()) {
                blockItem.setTitle(R.string.unblock);
                blockIcon.mutate();
                blockIcon.setColorFilter(activatedColor, PorterDuff.Mode.SRC_ATOP);
            } else {
                blockItem.setTitle(R.string.block);
                blockIcon.clearColorFilter();
            }
        }
    } else {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
}

From source file:org.getlantern.firetweet.fragment.support.UserListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUserList userList = mUserList;
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    if (followItem != null) {
        followItem.setEnabled(userList != null);
        if (userList == null) {
            followItem.setIcon(android.R.color.transparent);
        }//from  w w w .  j a  v a2 s  . com
    }
    if (twitter == null || userList == null)
        return;
    final boolean isMyList = userList.user_id == userList.account_id;
    setMenuItemAvailability(menu, MENU_EDIT, isMyList);
    setMenuItemAvailability(menu, MENU_ADD, isMyList);
    setMenuItemAvailability(menu, MENU_DELETE, isMyList);
    final boolean isFollowing = userList.is_following;
    if (followItem != null) {
        followItem.setVisible(!isMyList);
        if (isFollowing) {
            followItem.setIcon(R.drawable.ic_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {
            followItem.setIcon(R.drawable.ic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
    }
    menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION);
    final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST);
    extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader());
    extensionsIntent.putExtra(EXTRA_USER_LIST, mUserList);
    addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION);
}

From source file:org.totschnig.myexpenses.fragment.CategoryList.java

@Override
protected void configureMenu(Menu menu, int count, int listId) {
    ManageCategories ctx = (ManageCategories) getActivity();
    if (ctx == null) {
        return;//from   w  w w.  ja  va 2s  . c  o m
    }
    boolean inGroup = expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP;
    boolean inFilterOrDistribution = ctx.helpVariant.equals(HelpVariant.select_filter)
            || ctx.helpVariant.equals(HelpVariant.distribution);
    menu.findItem(R.id.EDIT_COMMAND).setVisible(count == 1 && !inFilterOrDistribution);
    menu.findItem(R.id.DELETE_COMMAND).setVisible(!inFilterOrDistribution);
    menu.findItem(R.id.MOVE_COMMAND).setVisible(!inFilterOrDistribution);
    MenuItem menuItem = menu.findItem(R.id.SELECT_COMMAND);
    menuItem.setVisible(count == 1 && (ctx.helpVariant.equals(HelpVariant.distribution)
            || ctx.helpVariant.equals(HelpVariant.select_mapping)));
    if (ctx.helpVariant.equals(HelpVariant.distribution)) {
        menuItem.setTitle(R.string.menu_show_transactions);
    }
    menu.findItem(R.id.SELECT_COMMAND_MULTIPLE).setVisible(ctx.helpVariant.equals(HelpVariant.select_filter));
    menu.findItem(R.id.CREATE_COMMAND).setVisible(inGroup && count == 1 && !inFilterOrDistribution);
}

From source file:com.msopentech.applicationgateway.EnterpriseBrowserActivity.java

public void showSettingsPopup(View v) {
    try {//w w w. j  a v  a2  s. c om
        PopupMenu popup = new PopupMenu(this, v);
        MenuInflater inflater = popup.getMenuInflater();
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                case R.id.menu_connection: {
                    showAgentsList();
                    return true;
                }
                case R.id.menu_sign_in_or_out: {
                    if (mIsSigninRequired) {
                        // Menu item in sign in mode.
                        //TODO: 
                        showSignIn(null, true);
                        return true;
                    }

                    // Clean up the session.
                    mTraits.sessionID = null;
                    mTraits.token = null;
                    mTraits.agent = null;

                    // Indicate the condition.
                    mIsSigninRequired = true;

                    //Remove all tabs except one.
                    mCustomTabHost.resetTabs();

                    mUrlEditTextView.setText("");

                    mProgressBarView.setProgress(0);

                    // Disable the reload button and set the right image for it.
                    mReloadButtonView.setEnabled(false);
                    mReloadButtonView.setImageResource(R.drawable.reload_button);

                    mStatusButtonView.setImageResource(R.drawable.connection_red);

                    // Since it's the user's intention to sign out, his
                    // history must be dropped.
                    PersistenceManager.dropContent(PersistenceManager.ContentType.HISTORY);

                    return true;
                }
                // Removed from RELEASE version. Should be active for development ONLY.                       
                //                        case R.id.menu_advanced_router_settings: {
                //                            showAdvancedRouterSettings(null);
                //                        }
                default: {
                    return false;
                }
                }
            }
        });
        inflater.inflate(R.menu.settings_menu, popup.getMenu());

        if (mIsSigninRequired) {
            MenuItem signItem = popup.getMenu().findItem(R.id.menu_sign_in_or_out);
            signItem.setTitle(getResources().getString(R.string.browser_menu_item_sign_in));
        }

        // Assumes that agent always has a display name. If display name is not present agent is considered to be not connected.
        MenuItem agentItem = popup.getMenu().findItem(R.id.menu_connection);
        String status = getResources().getString(R.string.browser_menu_item_choose_connection_not_connected);
        if (mTraits != null && mTraits.agent != null && !TextUtils.isEmpty(mTraits.agent.getDisplayName())) {
            status = mTraits.agent.getDisplayName();
        }
        Spannable span = new SpannableString(
                getResources().getString(R.string.browser_menu_item_choose_connection, status));
        span.setSpan(new RelativeSizeSpan(0.8f), 18, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        span.setSpan(new ForegroundColorSpan(Color.GRAY), 18, span.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        agentItem.setTitle(span);

        popup.show();
    } catch (final Exception e) {
        Utility.showAlertDialog(EnterpriseBrowserActivity.class.getSimpleName()
                + ".showSettingsPopup(): Failed. " + e.toString(), EnterpriseBrowserActivity.this);
    }
}

From source file:com.android.gallery3d.filtershow.FilterShowActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu);
    MenuItem showState = menu.findItem(R.id.showImageStateButton);
    if (mShowingImageStatePanel) {
        showState.setTitle(R.string.hide_imagestate_panel);
    } else {/*from  w w  w.jav a2 s. c  om*/
        showState.setTitle(R.string.show_imagestate_panel);
    }
    mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share).getActionProvider();
    mShareActionProvider.setShareIntent(getDefaultShareIntent());
    mShareActionProvider.setOnShareTargetSelectedListener(this);
    mMenu = menu;
    setupMenu();
    return true;
}

From source file:com.evandroid.musica.fragment.LyricsViewFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.lyrics, menu);
    MenuItem saveMenuItem = menu.findItem(R.id.save_action);
    if (saveMenuItem != null) {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
        if (mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT
                && sharedPref.getBoolean("pref_auto_save", true)) {
            String[] metadata = new String[] { mLyrics.getArtist(), mLyrics.getTrack(),
                    mLyrics.getOriginalArtist(), mLyrics.getOriginalTrack() };
            if (!DatabaseHelper.presenceCheck(((MainLyricActivity) getActivity()).database, metadata)) {
                lyricsPresentInDB = true;
                new WriteToDatabaseTask().execute(this, saveMenuItem, mLyrics);
            }// ww w  . jav  a  2  s  .com
            saveMenuItem.setVisible(false);
        } else {
            saveMenuItem.setIcon(lyricsPresentInDB ? R.drawable.ic_trash : R.drawable.ic_save);
            saveMenuItem.setTitle(lyricsPresentInDB ? R.string.remove_action : R.string.save_action);
        }
    }
    MenuItem resyncMenuItem = menu.findItem(R.id.resync_action);
    MenuItem convertMenuItem = menu.findItem(R.id.convert_action);
    if (mLyrics != null) {
        resyncMenuItem.setVisible(mLyrics.isLRC());
        convertMenuItem.setVisible(mLyrics.isLRC());
    }
}