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:paulscode.android.mupen64plusae.game.GameFragment.java

private void ReloadAllMenus() {
    //Reload currently selected speed setting
    final MenuItem toggleSpeedItem = mGameSidebar.getMenu().findItem(R.id.menuItem_toggle_speed);
    toggleSpeedItem.setTitle(this.getString(R.string.menuItem_toggleSpeed, mCoreFragment.getCurrentSpeed()));

    //Reload currently selected slot
    final MenuItem slotItem = mGameSidebar.getMenu().findItem(R.id.menuItem_set_slot);
    slotItem.setTitle(this.getString(R.string.menuItem_setSlot, mCoreFragment.getSlot()));

    final int resId = mCoreFragment.getFramelimiter() ? R.string.menuItem_enableFramelimiter
            : R.string.menuItem_disableFramelimiter;

    //Reload the menu with the new frame limiter setting
    final MenuItem frameLimiterItem = mGameSidebar.getMenu().findItem(R.id.menuItem_disable_frame_limiter);
    frameLimiterItem.setTitle(this.getString(resId));

    //Reload player pak settings
    UpdateControllerMenu(R.id.menuItem_player_one, mGamePrefs.isPlugged1, 1);
    UpdateControllerMenu(R.id.menuItem_player_two, mGamePrefs.isPlugged2, 2);
    UpdateControllerMenu(R.id.menuItem_player_three, mGamePrefs.isPlugged3, 3);
    UpdateControllerMenu(R.id.menuItem_player_four, mGamePrefs.isPlugged4, 4);

    mGameSidebar.reload();/*from   www  . j  a  v  a  2  s  .  co m*/
}

From source file:com.granita.tasks.TaskListFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*w  w w .  ja  v a 2 s.com*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // create menu
    inflater.inflate(R.menu.task_list_fragment_menu, menu);

    // restore menu state
    MenuItem item = menu.findItem(R.id.menu_show_completed);
    if (item != null) {
        item.setChecked(mSavedCompletedFilter);

        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            if (mSavedCompletedFilter) {
                item.setTitle(R.string.menu_hide_completed);
            } else {
                item.setTitle(R.string.menu_show_completed);
            }
        }
    }
}

From source file:org.catnut.fragment.TweetFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem fav = menu.findItem(R.id.action_toggle_favorite);
    if (mFavorited) {
        fav.setTitle(getString(R.string.cancle_favorite)).setIcon(R.drawable.ic_title_decline);
    } else {/*www.  j  a v a 2s. c  om*/
        fav.setTitle(getString(R.string.favorite)).setIcon(R.drawable.ic_title_favorite);
    }
}

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem savePlaylist = menu.findItem(R.id.menu_save_playlist);
    boolean savePlaylistEnabled = !Util.isOffline(this);
    savePlaylist.setEnabled(savePlaylistEnabled);
    savePlaylist.setVisible(savePlaylistEnabled);
    MenuItem screenOption = menu.findItem(R.id.menu_screen_on_off);
    if (getDownloadService().getKeepScreenOn()) {
        screenOption.setTitle(R.string.download_menu_screen_off);
    } else {/*  w w w . ja  v a 2  s  .  c  o m*/
        screenOption.setTitle(R.string.download_menu_screen_on);
    }
    MenuItem searchOption = menu.findItem(R.id.menu_search);
    searchOption.setVisible(!Util.isOffline(this));

    return super.onPrepareOptionsMenu(menu);
}

From source file:paulscode.android.mupen64plusae.game.GameFragment.java

@Override
public void onGameSidebarAction(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.menuItem_exit:
        mWaitingOnConfirmation = true;//w  w  w .jav  a 2  s. c om
        mCoreFragment.exit();
        break;
    case R.id.menuItem_toggle_speed:
        mCoreFragment.toggleSpeed();

        //Reload the menu with the new speed
        final MenuItem toggleSpeedItem = mGameSidebar.getMenu().findItem(R.id.menuItem_toggle_speed);
        toggleSpeedItem
                .setTitle(this.getString(R.string.menuItem_toggleSpeed, mCoreFragment.getCurrentSpeed()));
        mGameSidebar.reload();
        break;
    case R.id.menuItem_set_speed:
        mCoreFragment.setCustomSpeedFromPrompt();
        break;
    case R.id.menuItem_screenshot:
        mCoreFragment.screenshot();
        break;
    case R.id.menuItem_set_slot:
        mCoreFragment.setSlotFromPrompt();
        break;
    case R.id.menuItem_slot_load:
        mCoreFragment.loadSlot();
        break;
    case R.id.menuItem_slot_save:
        mCoreFragment.saveSlot();

        if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
            mDrawerLayout.closeDrawer(GravityCompat.START);
        }
        break;
    case R.id.menuItem_file_load:
        mCoreFragment.loadFileFromPrompt();
        break;
    case R.id.menuItem_file_save:
        mCoreFragment.saveFileFromPrompt();
        break;
    case R.id.menuItem_file_load_auto_save:
        mCoreFragment.loadAutoSaveFromPrompt();
        break;
    case R.id.menuItem_disable_frame_limiter:
        mCoreFragment.toggleFramelimiter();

        final int resId = mCoreFragment.getFramelimiter() ? R.string.menuItem_enableFramelimiter
                : R.string.menuItem_disableFramelimiter;

        //Reload the menu with the new speed
        final MenuItem frameLimiterItem = mGameSidebar.getMenu().findItem(R.id.menuItem_disable_frame_limiter);
        frameLimiterItem.setTitle(this.getString(resId));
        mGameSidebar.reload();
        break;
    case R.id.menuItem_player_one:
        setPakTypeFromPrompt(1);
        break;
    case R.id.menuItem_player_two:
        setPakTypeFromPrompt(2);
        break;
    case R.id.menuItem_player_three:
        setPakTypeFromPrompt(3);
        break;
    case R.id.menuItem_player_four:
        setPakTypeFromPrompt(4);
        break;
    case R.id.menuItem_setIme:
        final InputMethodManager imeManager = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imeManager != null)
            imeManager.showInputMethodPicker();
        break;
    case R.id.menuItem_reset:
        mWaitingOnConfirmation = true;
        mCoreFragment.restart();
        break;
    default:
    }
}

From source file:org.catrobat.catroid.ui.MainMenuActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main_menu, menu);
    mainMenu = menu;//from  ww  w .j a  v  a2s  .c o m

    final MenuItem scratchConverterMenuItem = menu.findItem(R.id.menu_scratch_converter);
    if (scratchConverterMenuItem != null) {
        final String title = getString(R.string.main_menu_scratch_converter);
        final String beta = getString(R.string.beta).toUpperCase(Locale.getDefault());
        final SpannableString spanTitle = new SpannableString(title + " " + beta);
        final int begin = title.length() + 1;
        final int end = begin + beta.length();
        final int betaLabelColor = ContextCompat.getColor(this, R.color.beta_label_color);
        spanTitle.setSpan(new ForegroundColorSpan(betaLabelColor), begin, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        scratchConverterMenuItem.setTitle(spanTitle);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:io.hypertrack.sendeta.view.Home.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (ActionManager.getSharedManager(this).getHyperTrackAction() != null)
        return false;

    getMenuInflater().inflate(R.menu.menu_home, menu);
    MenuItem menuItem = menu.findItem(R.id.tracking_toogle);
    if (SharedPreferenceManager.isTrackingON()) {
        menuItem.setTitle("Pause Tracking");
    } else {/*from  w w w.  j a  va 2 s  .com*/
        menuItem.setTitle("Resume Tracking");
    }

    // Hide menu items if user is on an Action
    return true;
}

From source file:com.nononsenseapps.feeder.ui.FeedFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.feed_fragment, menu);

    if (id < 1) {
        menu.findItem(R.id.action_edit_feed).setVisible(false);
        menu.findItem(R.id.action_delete_feed).setVisible(false);
        menu.findItem(R.id.action_add_templated).setVisible(false);
    }/*from   w  w w  .  j a v a2s .  c om*/

    // Set toggleable state
    MenuItem menuItem = menu.findItem(R.id.action_only_unread);
    final boolean onlyUnread = PrefUtils.isShowOnlyUnread(getActivity());
    menuItem.setChecked(onlyUnread);
    menuItem.setTitle(onlyUnread ? R.string.show_unread_items : R.string.show_all_items);
    if (onlyUnread) {
        menuItem.setIcon(R.drawable.ic_action_visibility_off);
    } else {
        menuItem.setIcon(R.drawable.ic_action_visibility);
    }

    // Don't forget super call here
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.mariotaku.twidere.activity.ComposeActivity.java

private void setMenu() {
    final Menu menu = mMenuBar.getMenu();
    final int activated_color = getResources().getColor(R.color.holo_blue_bright);
    final MenuItem itemAddImage = menu.findItem(MENU_ADD_IMAGE);
    final Drawable iconAddImage = itemAddImage.getIcon().mutate();
    if (mIsImageAttached && !mIsPhotoAttached) {
        iconAddImage.setColorFilter(activated_color, Mode.MULTIPLY);
        itemAddImage.setTitle(R.string.remove_image);
    } else {/*from   w w  w .  j av a 2s .  c  o m*/
        iconAddImage.clearColorFilter();
        itemAddImage.setTitle(R.string.add_image);
    }
    final MenuItem itemTakePhoto = menu.findItem(MENU_TAKE_PHOTO);
    final Drawable iconTakePhoto = itemTakePhoto.getIcon().mutate();
    if (!mIsImageAttached && mIsPhotoAttached) {
        iconTakePhoto.setColorFilter(activated_color, Mode.MULTIPLY);
        itemTakePhoto.setTitle(R.string.remove_photo);
    } else {
        iconTakePhoto.clearColorFilter();
        itemTakePhoto.setTitle(R.string.take_photo);
    }
    final MenuItem itemAttachLocation = menu.findItem(MENU_ADD_LOCATION);
    final Drawable iconAttachLocation = itemAttachLocation.getIcon().mutate();
    final boolean attach_location = mPreferences.getBoolean(PREFERENCE_KEY_ATTACH_LOCATION, false);
    if (attach_location && getLocation()) {
        iconAttachLocation.setColorFilter(activated_color, Mode.MULTIPLY);
        itemAttachLocation.setTitle(R.string.remove_location);
    } else {
        mPreferences.edit().putBoolean(PREFERENCE_KEY_ATTACH_LOCATION, false).commit();
        iconAttachLocation.clearColorFilter();
        itemAttachLocation.setTitle(R.string.add_location);
    }
    final MenuItem itemMore = menu.findItem(R.id.more_submenu);
    final MenuItem itemDrafts = menu.findItem(MENU_DRAFTS);
    final MenuItem itemToggleSensitive = menu.findItem(MENU_TOGGLE_SENSITIVE);
    if (itemMore != null) {
        if (itemDrafts != null) {
            final Cursor drafts_cur = getContentResolver().query(Drafts.CONTENT_URI, new String[0], null, null,
                    null);
            final Drawable iconMore = itemMore.getIcon().mutate();
            final Drawable iconDrafts = itemDrafts.getIcon().mutate();
            if (drafts_cur.getCount() > 0) {
                iconMore.setColorFilter(activated_color, Mode.MULTIPLY);
                iconDrafts.setColorFilter(activated_color, Mode.MULTIPLY);
            } else {
                iconMore.clearColorFilter();
                iconDrafts.clearColorFilter();
            }
            drafts_cur.close();
        }
        if (itemToggleSensitive != null) {
            final boolean has_media = (mIsImageAttached || mIsPhotoAttached) && mImageUri != null;
            itemToggleSensitive.setVisible(has_media);
            if (has_media) {
                final Drawable iconToggleSensitive = itemToggleSensitive.getIcon().mutate();
                if (mIsPossiblySensitive) {
                    itemToggleSensitive.setTitle(R.string.remove_sensitive_mark);
                    iconToggleSensitive.setColorFilter(activated_color, Mode.MULTIPLY);
                } else {
                    itemToggleSensitive.setTitle(R.string.mark_as_sensitive);
                    iconToggleSensitive.clearColorFilter();
                }
            }
        }
    }
    mMenuBar.invalidate();
    invalidateSupportOptionsMenu();
}