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:android_network.hetnet.vpn_service.AdapterRule.java

private void markPro(MenuItem menu, String sku) {
    if (true) {/*from   w ww .  j  ava  2 s . c  om*/
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(
                new ImageSpan(context,
                        dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp),
                0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}

From source file:org.mariotaku.twidere.fragment.UserProfileFragment.java

@Override
public void onClick(final View view) {
    if (getActivity() == null)
        return;/*from   w  w w.ja va2  s . c  o  m*/
    switch (view.getId()) {
    case R.id.edit_follow: {
        if (mUser == null || mAccountId <= 0)
            return;
        if (mAccountId == mUserId) {
            final Bundle bundle = getArguments();
            final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
            intent.setClass(getActivity(), EditUserProfileActivity.class);
            if (bundle != null) {
                intent.putExtras(bundle);
            }
            startActivity(intent);
        } else {
            if (mUser.is_follow_request_sent)
                return;
            if (mFriendship.isSourceFollowingTarget()) {
                mPopupMenu = PopupMenu.getInstance(getActivity(), view);
                mPopupMenu.inflate(R.menu.action_user_profile_follow);
                mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(final MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.unfollow: {
                            mFollowProgress.setVisibility(View.VISIBLE);
                            mEditFollowButton.setVisibility(View.GONE);
                            mTwitterWrapper.destroyFriendship(mAccountId, mUser.user_id);
                            return true;
                        }
                        }
                        return false;
                    }
                });
                mPopupMenu.show();
            } else {
                mFollowProgress.setVisibility(View.VISIBLE);
                mEditFollowButton.setVisibility(View.GONE);
                mTwitterWrapper.createFriendship(mAccountId, mUser.user_id);
            }
        }
        break;
    }
    case R.id.retry: {
        getUserInfo(true);
        break;
    }
    case R.id.profile_image_container: {
        final Uri uri = Uri.parse(getOriginalTwitterProfileImage(mUser.profile_image_url));
        openImage(getActivity(), uri, false);
        break;
    }
    case R.id.tweets_container: {
        if (mUser == null)
            return;
        openUserTimeline(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.followers_container: {
        if (mUser == null)
            return;
        openUserFollowers(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.friends_container: {
        if (mUser == null)
            return;
        openUserFriends(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.more_options: {
        if (mUser == null)
            return;
        mPopupMenu = PopupMenu.getInstance(getActivity(), view);
        mPopupMenu.inflate(R.menu.action_user_profile);
        final Menu menu = mPopupMenu.getMenu();
        if (mUser.user_id != mAccountId) {
            if (mFriendship == null)
                return;
            final MenuItem blockItem = menu.findItem(MENU_BLOCK);
            if (blockItem != null) {
                final Drawable blockIcon = blockItem.getIcon();
                if (mFriendship.isSourceBlockingTarget()) {
                    blockItem.setTitle(R.string.unblock);
                    blockIcon.mutate().setColorFilter(getResources().getColor(R.color.holo_blue_bright),
                            PorterDuff.Mode.MULTIPLY);
                } else {
                    blockItem.setTitle(R.string.block);
                    blockIcon.clearColorFilter();
                }
            }
            final MenuItem sendDirectMessageItem = menu.findItem(MENU_SEND_DIRECT_MESSAGE);
            if (sendDirectMessageItem != null) {
                sendDirectMessageItem.setVisible(mFriendship.isTargetFollowingSource());
            }
        } else {
            final int size = menu.size();
            for (int i = 0; i < size; i++) {
                final MenuItem item = menu.getItem(i);
                final int id = item.getItemId();
                item.setVisible(id == R.id.set_color_submenu || id == MENU_EXTENSIONS_SUBMENU);
            }
        }
        final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
        if (extensions != null) {
            final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
            final Bundle extras = new Bundle();
            extras.putParcelable(INTENT_KEY_USER, mUser);
            intent.putExtras(extras);
            addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent);
        }
        mPopupMenu.setOnMenuItemClickListener(this);
        mPopupMenu.show();
        break;
    }
    case R.id.name_container: {
        if (mUser == null || mAccountId != mUserId)
            return;
        startActivity(new Intent(getActivity(), EditUserProfileActivity.class));
        break;
    }
    }

}

From source file:com.velli.passwordmanager.FragmentPasswordDetails.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final MenuItem starred = menu.findItem(R.id.menu_starred);
    final MenuItem passwordVisibility = menu.findItem(R.id.menu_view_hide_password);

    if (starred != null) {
        if (mEntry == null) {
            starred.setIcon(R.drawable.ic_action_starred_off);
        } else {/*from  ww  w  .  ja v  a  2 s . c  o m*/
            final int res = mEntry.isStarred() ? R.drawable.ic_action_starred_on
                    : R.drawable.ic_action_starred_off;
            starred.setIcon(res);
        }

    }

    if (passwordVisibility != null) {
        passwordVisibility.setIcon(mShowingPassword ? R.drawable.ic_action_view : R.drawable.ic_action_hide);
        passwordVisibility.setTitle(
                mShowingPassword ? R.string.menu_action_view_password : R.string.menu_action_hide_password);
    }
}

From source file:com.sbgapps.scoreit.ScoreItActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (null != mLap)
        return true;

    int lapCnt = mGameManager.getLaps().size();
    int game = mGameManager.getPlayedGame();

    MenuItem item;
    item = menu.findItem(R.id.menu_chart);
    item.setVisible(isPhone() && 0 != lapCnt);

    item = menu.findItem(R.id.menu_clear);
    item.setVisible(0 != lapCnt);//w  w w  .ja  v  a 2  s .com

    item = menu.findItem(R.id.menu_round);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    boolean round;
    switch (game) {
    default:
        item.setVisible(false);
        break;
    case Game.BELOTE:
        round = sp.getBoolean(GameManager.KEY_BELOTE_ROUND, false);
        item.setTitle(round ? R.string.menu_action_actual_scores : R.string.menu_action_round_scores);
        break;
    case Game.COINCHE:
        round = sp.getBoolean(GameManager.KEY_COINCHE_ROUND, false);
        item.setTitle(round ? R.string.menu_action_actual_scores : R.string.menu_action_round_scores);
        break;
    }

    item = menu.findItem(R.id.menu_count);
    item.setVisible(Game.UNIVERSAL == game || Game.TAROT == game);

    item = menu.findItem(R.id.menu_save);
    List<String> files = mGameManager.getFileHelper().getSavedFiles();
    item.setVisible(0 != files.size());

    item = menu.findItem(R.id.menu_total);
    item.setVisible(Game.UNIVERSAL == game);

    return true;
}

From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getTitle().equals("Start")) {
        if (!recording) {
            Log.d(TAG, "attemptHandshaking");
            attemptHandshake();/*from   w  w w .j a v a  2 s  .  c  o  m*/
            Log.w(LOG_TAG, "Start Button Pushed");
            item.setTitle("Stop");
        }

    } else if (item.getTitle().equals("Stop")) {
        stopRecording();
        Log.w(LOG_TAG, "Stop Button Pushed");
        item.setTitle("Start");
    }
    return super.onOptionsItemSelected(item);
}

From source file:im.vector.activity.VectorHomeActivity.java

private void refreshSlidingMenu() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // use a dedicated view
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);

    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            mToolbar, R.string.action_open, /* "open drawer" description */
            R.string.action_close /* "close drawer" description */
    ) {//from w ww. j  ava 2s  .  c o m

        public void onDrawerClosed(View view) {
            switch (VectorHomeActivity.this.mSlidingMenuIndex) {
            case R.id.sliding_menu_settings: {
                // launch the settings activity
                final Intent settingsIntent = new Intent(VectorHomeActivity.this, VectorSettingsActivity.class);
                settingsIntent.putExtra(MXCActionBarActivity.EXTRA_MATRIX_ID, mSession.getMyUserId());
                VectorHomeActivity.this.startActivity(settingsIntent);
                break;
            }

            case R.id.sliding_menu_send_bug_report: {
                BugReporter.sendBugReport();
                break;
            }

            case R.id.sliding_menu_logout: {
                VectorHomeActivity.this.showWaitingView();
                CommonActivityUtils.logout(VectorHomeActivity.this);
                break;
            }

            case R.id.sliding_copyright_terms: {
                VectorUtils.displayAppCopyright(VectorHomeActivity.this);
                break;
            }

            case R.id.sliding_menu_app_tac: {
                VectorUtils.displayAppTac(VectorHomeActivity.this);
                break;
            }

            case R.id.sliding_menu_privacy_policy: {
                VectorUtils.displayAppPrivacyPolicy(VectorHomeActivity.this);
                break;
            }

            case R.id.sliding_menu_third_party_notices: {
                VectorUtils.displayThirdPartyLicenses(VectorHomeActivity.this);
                break;
            }
            }

            VectorHomeActivity.this.mSlidingMenuIndex = -1;
        }

        public void onDrawerOpened(View drawerView) {
        }
    };

    NavigationView.OnNavigationItemSelectedListener listener = new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            mDrawerLayout.closeDrawers();
            VectorHomeActivity.this.mSlidingMenuIndex = menuItem.getItemId();
            return true;
        }
    };

    navigationView.setNavigationItemSelectedListener(listener);
    mDrawerLayout.setDrawerListener(drawerToggle);

    // display the home and title button
    if (null != getSupportActionBar()) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar()
                .setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_material_menu_white));
    }

    Menu menuNav = navigationView.getMenu();
    MenuItem aboutMenuItem = menuNav.findItem(R.id.sliding_menu_version);

    if (null != aboutMenuItem) {
        String version = this.getString(R.string.room_sliding_menu_version) + " "
                + VectorUtils.getApplicationVersion(this);
        aboutMenuItem.setTitle(version);
    }

    // init the main menu
    TextView displayNameTextView = (TextView) navigationView.findViewById(R.id.home_menu_main_displayname);

    if (null != displayNameTextView) {
        displayNameTextView.setText(mSession.getMyUser().displayname);
    }

    TextView userIdTextView = (TextView) navigationView.findViewById(R.id.home_menu_main_matrix_id);
    if (null != userIdTextView) {
        userIdTextView.setText(mSession.getMyUserId());
    }

    ImageView mainAvatarView = (ImageView) navigationView.findViewById(R.id.home_menu_main_avatar);

    if (null != mainAvatarView) {
        VectorUtils.loadUserAvatar(this, mSession, mainAvatarView, mSession.getMyUser());
    } else {
        // on Android M, the mNavigationView is not loaded at launch
        // so launch asap it is rendered.
        navigationView.post(new Runnable() {
            @Override
            public void run() {
                refreshSlidingMenu();
            }
        });
    }
}

From source file:tv.acfun.video.DetailsActivity.java

private void handleFav(final MenuItem item) {
    if (isFaved) {
        DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {

            @Override/*  w  ww  .j a  v a 2 s  .  c om*/
            public void onClick(DialogInterface dialog, int which) {
                if (which == DialogInterface.BUTTON_POSITIVE) {
                    new Thread() {
                        public void run() {
                            boolean deleteFavourite = MemberUtils.deleteFavourite(
                                    API.getDomainRoot(getApplicationContext()), String.valueOf(mAcId),
                                    mCookies);
                            //TODO ??
                            isFaved = !deleteFavourite;
                            Log.i("Delete", "deleteFavourite::" + mAcId + ":" + deleteFavourite);
                        }
                    }.start();
                    item.setTitle("?");
                    item.setIcon(R.drawable.ic_action_favorite);
                }
            }
        };
        AcApp.showDeleteFavAlert(this, listener);
    } else {
        if (mCookies == null) {
            Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();

        } else {
            new Thread() {
                public void run() {
                    boolean add = MemberUtils.addFavourite(String.valueOf(mAcId),
                            API.getDomainRoot(getApplicationContext()), mCookies);
                    //TODO ??
                    Log.i("add", "addFavourite::" + mAcId + ":" + add);
                }
            }.start();
            item.setTitle("??");
            item.setIcon(R.drawable.ic_action_favorited);
        }
    }
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

private void prepareOptionsMenu(Menu menu) {
    MenuItem pauseResume = menu.findItem(R.id.pause_resume_torrent_menu);

    if (torrent == null || !torrent.isPaused()) {
        pauseResume.setTitle(R.string.pause_torrent);
        if (!Utils.isTwoPane(activity.getApplicationContext())) {
            pauseResume.setIcon(R.drawable.ic_pause_white_24dp);
        }/*from   w  w  w .  j a  va 2 s .  c  o m*/

    } else {
        pauseResume.setTitle(R.string.resume_torrent);
        if (!Utils.isTwoPane(activity.getApplicationContext())) {
            pauseResume.setIcon(R.drawable.ic_play_arrow_white_24dp);
        }
    }
}

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

private void setMenu(final 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 ww .  j a  va  2s  . co  m*/
    }
    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_iconic_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {
            followItem.setIcon(R.drawable.ic_iconic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
    }
}

From source file:org.mariotaku.twidere.fragment.support.UserProfileFragment.java

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mFriendship;
    if (twitter == null || user == null)
        return;//from ww w. ja  va2  s .  c  o m
    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) {
        setMenuItemAvailability(menu, MENU_BLOCK, mFriendship != null);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (mFriendship != null && blockItem != null) {
            final Drawable blockIcon = blockItem.getIcon();
            if (mFriendship.isSourceBlockingTarget()) {
                blockItem.setTitle(R.string.unblock);
                blockIcon.mutate().setColorFilter(ThemeUtils.getUserThemeColor(getActivity()),
                        PorterDuff.Mode.MULTIPLY);
            } else {
                blockItem.setTitle(R.string.block);
                blockIcon.clearColorFilter();
            }
        }
        final boolean is_following_me = mFriendship != null && mFriendship.isTargetFollowingSource();
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, is_following_me);
    } else {
        setMenuItemAvailability(menu, MENU_MENTION, false);
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
    final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
    final Bundle extras = new Bundle();
    extras.putParcelable(EXTRA_USER, user);
    intent.putExtras(extras);
    menu.removeGroup(MENU_GROUP_USER_EXTENSION);
    addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION);
}