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.spydiko.rotationmanager.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings: // Refresh button
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "action_settings");
        packageManager = getPackageManager();
        UpdateData updateData = new UpdateData();
        this.adapter = new InteractiveArrayAdapter(this, activities, (AppSpecificOrientation) getApplication());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            updateData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
        else//from   www .  j a va2  s .c  o  m
            updateData.execute((Void[]) null);
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "execute");
        lv.setAdapter(adapter);
        break;
    case R.id.itemToggleService: // Play - Stop Service
        //                if(AppSpecificOrientation.LOG) Log.d(TAG, "entered");
        if (AppSpecificOrientation.isServiceRunning()) {
            item.setTitle(R.string.titleServiceStop);
            //               item.setIcon(android.R.drawable.ic_media_play);
            stopService(new Intent(this, NewOrieService.class));
            AppSpecificOrientation.setServiceRunning(false);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "if");
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_off_button_rotation_manager);
        } else {
            item.setTitle(R.string.titleServiceStart);
            //               item.setIcon(android.R.drawable.ic_media_pause);
            startService(new Intent(this, NewOrieService.class));
            Toast toast = Toast.makeText(this, getString(R.string.notification_text), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
            toast.show();
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_on_button_rotation_manager);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "else");
        }
        break;

    case R.id.setOnBoot: // Set broadcast receiver on or off
        if (AppSpecificOrientation.getBoot()) {
            item.setChecked(false);
            AppSpecificOrientation.setBoot(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setBoot(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
        }

        break;
    case R.id.howTo: // Open How To Activity
        startActivityForResult((new Intent(this, HowToActivity.class)), 1);
        break;
    case R.id.about: // Open About Activity
        startActivityForResult((new Intent(this, AboutActivity.class)), 1);
        break;
    case R.id.donate:
        startActivity(new Intent(this, DonateActivity.class));
        break;
    case R.id.permNotification:
        if (AppSpecificOrientation.isPermNotification()) {
            item.setChecked(false);
            AppSpecificOrientation.setPermNotification(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setPermNotification(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        }

        break;
    case R.id.license:
        startActivity(new Intent(this, License.class));
        break;
    case android.R.id.home:
        menu.toggle();
        return true;
    }
    return true;
}

From source file:com.androzic.MapFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    boolean fixed = map != null && map.isFixed();

    MenuItem follow = menu.findItem(R.id.action_follow);
    if (!fixed || following && map != null && !map.getStrictUnfollow()) {
        follow.setVisible(false);//from   w w  w .j av  a  2  s.  c om
    } else if (following) {
        follow.setIcon(R.drawable.ic_lock_outline_white_24dp);
        follow.setTitle(R.string.action_unfollow);
    } else {
        follow.setVisible(true);
        follow.setIcon(R.drawable.ic_lock_open_white_24dp);
        follow.setTitle(R.string.action_follow);
    }

    menu.findItem(R.id.action_locate).setVisible(!fixed);

    menu.findItem(R.id.action_locating).setChecked(application.isLocating());
    menu.findItem(R.id.action_tracking).setChecked(application.isTracking());

    boolean navigating = application.isNavigating();
    boolean viaRoute = application.isNavigatingViaRoute();

    menu.findItem(R.id.action_stop_navigation).setVisible(navigating);
    menu.findItem(R.id.action_next_nav_point).setVisible(viaRoute);
    menu.findItem(R.id.action_prev_nav_point).setVisible(viaRoute);
    if (viaRoute) {
        menu.findItem(R.id.action_next_nav_point)
                .setEnabled(application.navigationService.hasNextRouteWaypoint());
        menu.findItem(R.id.action_prev_nav_point)
                .setEnabled(application.navigationService.hasPrevRouteWaypoint());
    }
}

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

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    if (!shouldUseNativeMenu() || !menu.hasVisibleItems())
        return;/*from  w ww  .  j  a va 2  s  .  c  om*/
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = getUser();
    final Relationship relationship = mRelationship;
    if (twitter == null || user == null)
        return;
    final boolean isMyself = user.account_id == user.id;
    final MenuItem mentionItem = menu.findItem(MENU_MENTION);
    if (mentionItem != null) {
        mentionItem.setTitle(
                getString(R.string.mention_user_name, UserColorNameUtils.getDisplayName(getActivity(), user)));
    }
    Utils.setMenuItemAvailability(menu, MENU_MENTION, !isMyself);
    Utils.setMenuItemAvailability(menu, R.id.incoming_friendships, 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_action_cancel : R.drawable.ic_action_add);
    //        } else {
    //            followItem.setTitle(null);
    //            followItem.setIcon(null);
    //        }
    if (!isMyself && relationship != null) {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget());
        setMenuItemAvailability(menu, MENU_BLOCK, true);
        setMenuItemAvailability(menu, MENU_MUTE_USER, true);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (blockItem != null) {
            final boolean blocking = relationship.isSourceBlockingTarget();
            ActionIconDrawable.setMenuHighlight(blockItem, new FiretweetMenuInfo(blocking));
            blockItem.setTitle(blocking ? R.string.unblock : R.string.block);
        }
        final MenuItem muteItem = menu.findItem(MENU_MUTE_USER);
        if (muteItem != null) {
            final boolean muting = relationship.isSourceMutingTarget();
            ActionIconDrawable.setMenuHighlight(muteItem, new FiretweetMenuInfo(muting));
            muteItem.setTitle(muting ? R.string.unmute : R.string.mute);
        }
        final MenuItem filterItem = menu.findItem(MENU_ADD_TO_FILTER);
        if (filterItem != null) {
            final boolean filtering = Utils.isFilteringUser(getActivity(), user.id);
            ActionIconDrawable.setMenuHighlight(filterItem, new FiretweetMenuInfo(filtering));
            filterItem.setTitle(filtering ? R.string.remove_from_filter : R.string.add_to_filter);
        }
    } else {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_MUTE_USER, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
    setMenuItemAvailability(menu, R.id.muted_users, isMyself);
    setMenuItemAvailability(menu, R.id.blocked_users, isMyself);
    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);
}

From source file:com.openatk.rockapp.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (mCurrentState == STATE_DEFAULT) {
        menu.clear();//ww  w  .  j  a  v a  2s . com
        inflater.inflate(R.menu.main, menu);

        MenuItem showHideItem = menu.findItem(R.id.show_hide);
        MenuItem currentShowHideItem;

        switch (mRockState) {
        case STATE_ROCKS_BOTH:
            currentShowHideItem = menu.findItem(R.id.all_rocks);
            break;

        case STATE_ROCKS_NOT_PICKED_UP:
            currentShowHideItem = menu.findItem(R.id.not_picked_rocks);
            break;

        case STATE_ROCKS_PICKED_UP:
            currentShowHideItem = menu.findItem(R.id.picked_rocks);
            break;
        default:
            // We are some how lost, just revert back to showing everything
            Log.e("MainActivity", "Lost Rock Shown State");
            mRockState = STATE_ROCKS_BOTH;
            currentShowHideItem = menu.findItem(R.id.all_rocks);
            break;
        }

        // Copy the current selection to the action bar
        showHideItem.setTitle(currentShowHideItem.getTitle());

        // Mark the current one as checked
        currentShowHideItem.setChecked(true);

        // The location button changes depending the current state
        // of location

        // TODO
        /*
         * MenuItem gps = menu.findItem(R.id.gps); if(map.ha) {
         * if(mRockLocationManager.haveUserLocation()) {
         * gps.setIcon(R.drawable.gps_found);
         * gps.setTitle(R.string.menu_gps); } else {
         * gps.setIcon(R.drawable.gps_searching);
         * gps.setTitle(R.string.menu_gps_searching); } } else {
         * gps.setIcon(R.drawable.gps_off);
         * gps.setTitle(R.string.menu_gps_off); }
         */
    } else if (mCurrentState == STATE_ROCK_EDIT) {
        menu.clear();
        inflater.inflate(R.menu.rock_edit_menu, menu);
        MenuItem undoButton = menu.findItem(R.id.rock_undo_move);
        if (undoMoves.isEmpty()) {
            undoButton.setVisible(false);
        } else {
            undoButton.setVisible(true);
        }
    }
    return true;
}

From source file:com.tweetlanes.android.view.TweetFeedFragment.java

@Override
public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) {

    if (inflater != null && mContentHandle != null
            && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) {

        if (getBaseLaneActivity() instanceof HomeActivity) {
            inflater.inflate(R.menu.home_tweet_feed_action_bar, menu);
        } else {//from w  ww  .  j  av  a 2 s  .co m
            inflater.inflate(R.menu.tweet_feed_action_bar, menu);
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (menuItem.getItemId() == R.id.action_feed_filter) {
                SubMenu subMenu = menuItem.getSubMenu();
                if (subMenu != null) {
                    SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType();
                    int subMenuSize = subMenu.size();
                    for (int j = 0; j < subMenuSize; j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        switch (subMenuItem.getItemId()) {
                        case R.id.action_replies_visibility:

                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies()
                                            ? R.string.action_hide_replies
                                            : R.string.action_show_replies));
                            break;

                        case R.id.action_retweets_visibility:
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets()
                                            ? socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_hide_retweets
                                                    : R.string.action_hide_retweets_adn
                                            : socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_show_retweets
                                                    : R.string.action_show_retweets_adn));
                            break;

                        default:
                            break;
                        }

                    }
                }
            }
        }

        return true;
    }

    return false;
}

From source file:com.tweetlanes.android.view.TweetFeedFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_replies_visibility:
        getBaseLaneActivity().mStatusesFilter
                .setShowReplies(!getBaseLaneActivity().mStatusesFilter.getShowReplies());
        item.setTitle(
                getString(getBaseLaneActivity().mStatusesFilter.getShowReplies() ? R.string.action_hide_replies
                        : R.string.action_show_replies));
        mTweetFeedListAdapter.notifyDataSetChanged();
        return false;

    case R.id.action_retweets_visibility:
        getBaseLaneActivity().mStatusesFilter
                .setShowRetweets(!getBaseLaneActivity().mStatusesFilter.getShowRetweets());
        item.setTitle(getString(/*from w  w w. j  av a2s  .  c o m*/
                getBaseLaneActivity().mStatusesFilter.getShowRetweets() ? R.string.action_hide_retweets
                        : R.string.action_show_retweets));
        mTweetFeedListAdapter.notifyDataSetChanged();
        return false;
    }

    return false;
}

From source file:com.dsdar.thosearoundme.TeamViewActivity.java

/**
 * Method to get users team information and design action bar accordingly
 *//*from w  w  w  .j a v a  2s .c om*/

@Override
public boolean onCreateOptionsMenu(Menu theMenu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_teamview_menu, theMenu);

    MenuItem myItem = theMenu.findItem(R.id.invitations);
    MenuItem team = theMenu.findItem(R.id.myTeams);
    int invite_cnt = 0;
    if (MyAppConstants.INVITATION_CNT == -1) {
        invite_cnt = 0;
    } else {
        invite_cnt = MyAppConstants.INVITATION_CNT;
    }

    myItem.setTitle(myItem.getTitle() + "(" + invite_cnt + ")");
    if (intSupported == 0) {
        itsAddTeam.setVisibility(View.INVISIBLE);
        team.setVisible(false);
    } else {
        itsAddTeam.setVisibility(View.VISIBLE);
        team.setVisible(true);
    }
    // MenuItem myItem1 = theMenu.findItem(R.id.myFollowers);
    // myItem1.setTitle(myItem1.getTitle() + "("
    // + MyAppConstants.FOLLOWERS_CNT + ")");
    // TextView txtInviteCnt = (TextView) findViewById(R.id.invitations);
    // txtInviteCnt.setText("(" + MyAppConstants.INVITATION_CNT + ")");
    //
    // TextView txtFolowersCnt = (TextView) findViewById(R.id.myFollowers);
    // txtFolowersCnt.setText("(" + MyAppConstants.FOLLOWERS_CNT + ")");

    return super.onCreateOptionsMenu(theMenu);
}

From source file:gov.wa.wsdot.android.wsdot.ui.ferries.departures.FerriesRouteSchedulesDayDeparturesActivity.java

private void toggleStar(MenuItem item) {
    Snackbar added_snackbar = Snackbar.make(findViewById(R.id.activity_ferry_sailings), R.string.add_favorite,
            Snackbar.LENGTH_SHORT);/*from www.  j  ava 2  s. c  o  m*/

    Snackbar removed_snackbar = Snackbar.make(findViewById(R.id.activity_ferry_sailings),
            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");
        scheduleViewModel.setIsStarredFor(mScheduleId, 0);
        removed_snackbar.show();
        mIsStarred = false;
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        item.setTitle("Favorite checkbox, checked");
        scheduleViewModel.setIsStarredFor(mScheduleId, 1);
        added_snackbar.show();
        mIsStarred = true;
    }
}

From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java

/**
 * Edit frame count text view and refresh adapter
 *///from  w ww.  j a v a  2 s .  com
private void notifyAdapter() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            MenuItem item = toolbar.getMenu().findItem(R.id.packet_number_entry);
            if (item != null) {
                item.setTitle(packetAdapter.getItemCount() + "/" + mPacketCount);
            }
            packetAdapter.notifyDataSetChanged();
        }
    });
}

From source file:org.videolan.vlc.gui.MyFragment.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (menu == null)
        return false;
    Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
    MenuItem item;
    // Disable the sort option if we can't use it on the current fragment.
    if (current == null || !(current instanceof ISortable)) {
        item = menu.findItem(R.id.ml_menu_sortby);
        if (item == null)
            return false;
        item.setEnabled(false);//from ww  w .  jav a2  s.  c  o  m
        item.setVisible(false);
    } else {
        ISortable sortable = (ISortable) current;
        item = menu.findItem(R.id.ml_menu_sortby);
        if (item == null)
            return false;
        item.setEnabled(true);
        item.setVisible(true);
        item = menu.findItem(R.id.ml_menu_sortby_name);
        if (sortable.sortDirection(VideoListAdapter.SORT_BY_TITLE) == 1)
            item.setTitle(R.string.sortby_name_desc);
        //item.setTitle(R.string.sortby_name_desc);
        else
            item.setTitle(R.string.sortby_name);
        item = menu.findItem(R.id.ml_menu_sortby_length);
        if (sortable.sortDirection(VideoListAdapter.SORT_BY_LENGTH) == 1)
            item.setTitle(R.string.sortby_length_desc);
        else
            item.setTitle(R.string.sortby_length);
        item = menu.findItem(R.id.ml_menu_sortby_date);
        if (sortable.sortDirection(VideoListAdapter.SORT_BY_DATE) == 1)
            item.setTitle(R.string.sortby_date_desc);
        else
            item.setTitle(R.string.sortby_date);
    }

    boolean networkSave = current instanceof NetworkBrowserFragment
            && !((NetworkBrowserFragment) current).isRootDirectory();
    if (networkSave) {
        item = menu.findItem(R.id.ml_menu_save);
        item.setVisible(true);
        String mrl = ((BaseBrowserFragment) current).mMrl;
        item.setIcon(
                MediaDatabase.getInstance().networkFavExists(Uri.parse(mrl)) ? R.drawable.ic_menu_bookmark_w
                        : R.drawable.ic_menu_bookmark_outline_w);
    } else
        menu.findItem(R.id.ml_menu_save).setVisible(false);
    if (current instanceof MRLPanelFragment)
        menu.findItem(R.id.ml_menu_clean).setVisible(!((MRLPanelFragment) current).isEmpty());
    boolean showLast = current instanceof AudioBrowserFragment || (current instanceof VideoGridFragment
            && mSettings.getString(PreferencesActivity.VIDEO_LAST, null) != null);
    menu.findItem(R.id.ml_menu_last_playlist).setVisible(showLast);
    return true;
}