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:tm.alashow.datmusic.ui.activity.MainActivity.java

/**
 * Set file size and audio bitrate to download menu
 *
 * @param bottomSheet menu where located download button
 * @param audio       file for get info//from   w w w .ja v  a  2 s  . com
 */
private void setSizeAndBitrate(BottomSheet bottomSheet, Audio audio) {
    MenuItem menuItem = bottomSheet.getMenu().findItem(R.id.download);
    long bitrate = audio.getBytes() / audio.getDuration() / 120;
    menuItem.setTitle(String.format(Locale.US, "%s (%s ~ %d kbps)", menuItem.getTitle(),
            U.humanReadableByteCount(audio.getBytes(), false), bitrate));
    bottomSheet.invalidate();
}

From source file:com.nextgis.mobile.activity.MainActivity.java

private void setTrackItem(MenuItem item, int title, int icon) {
    if (null != item) {
        item.setTitle(title);
        item.setIcon(icon);/*  w  ww  . j a va 2 s .c o  m*/
    }
}

From source file:org.namelessrom.devicecontrol.appmanager.AppDetailsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_app_details, menu);

    if (mAppItem != null) {
        if (!AppHelper.isPlayStoreInstalled()) {
            menu.removeItem(R.id.menu_action_play_store);
        }/*from  w  w w.j a va2 s  . c  o  m*/
        // prevent disabling Device Control
        if (Application.get().getPackageName().equals(mAppItem.getPackageName())) {
            menu.removeItem(R.id.menu_app_disable);
        }

        final MenuItem disable = menu.findItem(R.id.menu_app_disable);
        if (disable != null) {
            disable.setTitle(mAppItem.isEnabled() ? R.string.disable : R.string.enable);
        }
    } else {
        menu.removeItem(R.id.menu_action_play_store);
        menu.removeItem(R.id.menu_app_disable);
    }

    return true;
}

From source file:com.barbrdo.app.activities.UserProfileActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem edit = menu.findItem(R.id.action_edit);
    if (isEdit) {
        edit.setIcon(R.drawable.ic_save_white_24dp);
        edit.setTitle(R.string.save);
    } else {/*w  ww.  j a v  a  2 s . c o  m*/
        edit.setIcon(R.drawable.ic_edit_white_24dp);
        edit.setTitle(R.string.edit);
    }
    return true;
}

From source file:org.wikipedia.edit.EditSectionActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_edit_section, menu);
    MenuItem item = menu.findItem(R.id.menu_save_section);

    if (editSummaryFragment.isActive()) {
        item.setTitle(getString(R.string.edit_next));
    } else if (editPreviewFragment.isActive()) {
        item.setTitle(getString(R.string.edit_done));
    } else {/* ww w.j ava 2 s.c  o m*/
        item.setTitle(getString(R.string.edit_next));
    }

    if (abusefilterEditResult != null) {
        if (abusefilterEditResult.getType() == EditAbuseFilterResult.TYPE_ERROR) {
            item.setEnabled(false);
        } else {
            item.setEnabled(true);
        }
    } else {
        item.setEnabled(sectionTextModified);
    }

    View v = getLayoutInflater().inflate(R.layout.item_edit_actionbar_button, null);
    item.setActionView(v);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    v.setLayoutParams(params);
    TextView txtView = v.findViewById(R.id.edit_actionbar_button_text);
    txtView.setText(item.getTitle());
    txtView.setTypeface(null, item.isEnabled() ? Typeface.BOLD : Typeface.NORMAL);
    v.setTag(item);
    v.setClickable(true);
    v.setEnabled(item.isEnabled());
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onOptionsItemSelected((MenuItem) view.getTag());
        }
    });

    v.setBackgroundColor(ContextCompat.getColor(this,
            item.isEnabled()
                    ? (editPreviewFragment.isActive() ? R.color.accent50
                            : ResourceUtil.getThemedAttributeId(this, R.attr.colorAccent))
                    : R.color.base50));

    return true;
}

From source file:locationkitapp.locationkit.locationkitapp.MapsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem notification = menu.findItem(R.id.action_enable_disable_notifications);
    MenuItem tracking = menu.findItem(R.id.action_enable_disable_tracking);
    if (notificationEnabled) {
        notification.setTitle(getResources().getString(R.string.disable_notifications));
    } else {/*  ww w  . jav  a 2s .  co m*/
        notification.setTitle(getResources().getString(R.string.enable_notifications));
    }
    if (trackingEnabled) {
        tracking.setTitle(getResources().getString(R.string.disable_tracking));
    } else {
        tracking.setTitle(getResources().getString(R.string.enable_tracking));
    }

    return true;
}

From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java

/**
 * This menu contains reverse and refresh buttons
 *
 *//*from   www.  jav  a  2 s.com*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.news_menu_main, menu);
    menu.clear();

    MenuItem menuItem = menu.add("");
    menuItem.setTitle(getString(R.string.news_reverse));
    menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            handler.sendEmptyMessage(REVERSE_LIST);
            return true;
        }
    });

    if (Statics.isRSS) {
        menuItem = menu.add("");
        menuItem.setTitle(R.string.news_refresh);
        menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (isOnline) {
                    handler.sendEmptyMessage(REFRESH_RSS);
                } else {
                    handler.sendEmptyMessage(CANT_REFRESH_RSS);
                }
                return true;
            }
        });
    }

    return false;
}

From source file:com.vadimfrolov.duorem.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem miAdd = (MenuItem) menu.findItem(R.id.action_add_host);
    MenuItem miEdit = (MenuItem) menu.findItem(R.id.action_edit_host);
    MenuItem miDelete = (MenuItem) menu.findItem(R.id.action_delete_host);
    boolean targetIsValid = mTarget != null
            && ((mTarget.ipAddress != null && !mTarget.ipAddress.equals(NetInfo.NOIP))
                    || (mTarget.hardwareAddress != null && !mTarget.hardwareAddress.equals(NetInfo.NOMAC)));

    if (targetIsValid) {
        miAdd.setTitle(getResources().getString(R.string.replace_host));
    } else {/*from w ww  . j a  va 2s . c  o  m*/
        miAdd.setTitle(getResources().getString(R.string.add_host));
    }
    miEdit.setEnabled(targetIsValid);
    miDelete.setEnabled(targetIsValid);

    miEdit.setShowAsAction(targetIsValid ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER);
    miDelete.setShowAsAction(targetIsValid ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER);
    // hide replace menu item under the unfoldable menu
    miAdd.setShowAsAction(targetIsValid ? MenuItem.SHOW_AS_ACTION_NEVER : MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onPrepareOptionsMenu(menu);
}

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

@Override
public void onPromptFinished() {
    //In here we only reload things that are updated through prompts

    //reload menu item with new slot
    final MenuItem slotItem = mGameSidebar.getMenu().findItem(R.id.menuItem_set_slot);
    slotItem.setTitle(this.getString(R.string.menuItem_setSlot, NativeExports.emuGetSlot()));

    //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, NativeExports.emuGetSpeed()));

    mGameSidebar.reload();/*from   w ww .j  av a 2  s. c o m*/
}

From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

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

    MenuItem item;/*from   www  .  ja  v  a  2 s  .c  o m*/
    // Put a checkmark by the currently selected Category + Age combination
    switch (mCategory) {
    case CONTROVERSIAL:
        switch (mAge) {
        case ALL_TIME:
            item = menu.findItem(R.id.category_controversial_all_time);
            item.setChecked(true);
            break;
        case THIS_HOUR:
            item = menu.findItem(R.id.category_controversial_hour);
            item.setChecked(true);
            break;
        case THIS_MONTH:
            item = menu.findItem(R.id.category_controversial_month);
            item.setChecked(true);
            break;
        case THIS_WEEK:
            item = menu.findItem(R.id.category_controversial_week);
            item.setChecked(true);
            break;
        case THIS_YEAR:
            item = menu.findItem(R.id.category_controversial_year);
            item.setChecked(true);
            break;
        case TODAY:
            item = menu.findItem(R.id.category_controversial_today);
            item.setChecked(true);
            break;
        }
        break;
    case HOT:
        menu.findItem(R.id.category_hot).setChecked(true);
        break;
    case NEW:
        menu.findItem(R.id.category_new).setChecked(true);
        break;
    case RISING:
        menu.findItem(R.id.category_rising).setChecked(true);
        break;
    case TOP:
        switch (mAge) {
        case ALL_TIME:
            item = menu.findItem(R.id.category_top_all_time);
            item.setChecked(true);
            break;
        case THIS_HOUR:
            item = menu.findItem(R.id.category_top_hour);
            item.setChecked(true);
            break;
        case THIS_MONTH:
            item = menu.findItem(R.id.category_top_month);
            item.setChecked(true);
            break;
        case THIS_WEEK:
            item = menu.findItem(R.id.category_top_week);
            item.setChecked(true);
            break;
        case THIS_YEAR:
            item = menu.findItem(R.id.category_top_year);
            item.setChecked(true);
            break;
        case TODAY:
            item = menu.findItem(R.id.category_top_today);
            item.setChecked(true);
            break;
        }
        break;
    default:
        mCategory = Category.HOT;
        mAge = Age.TODAY;
        menu.findItem(R.id.category_hot).setChecked(true);
        break;
    }

    MenuItem loginMenuItem = menu.findItem(R.id.login);
    // If the user is logged in, update the Logout menu item to "Log out <username>"
    if (RedditLoginInformation.isLoggedIn()) {
        loginMenuItem.setTitle(getString(R.string.log_out_) + RedditLoginInformation.getUsername());
        loginMenuItem.setIcon(R.drawable.ic_action_exit_dark);
    } else {
        loginMenuItem.setTitle(R.string.log_on);
        loginMenuItem.setIcon(R.drawable.ic_action_key_dark);
    }

    MenuItem activeViewMenuItem = menu.findItem(R.id.change_view);
    switch (mActiveViewType) {
    case LIST:
        activeViewMenuItem.setIcon(R.drawable.ic_action_tiles_small_dark);
        activeViewMenuItem.setTitle(R.string.view_as_grid);
        break;
    case GRID:
        activeViewMenuItem.setIcon(R.drawable.ic_action_list_2_dark);
        activeViewMenuItem.setTitle(R.string.view_as_list);
        break;
    default:
        break;
    }

    return true;
}