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.dwdesign.tweetings.activity.HomeActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    final boolean bottom_actions = mPreferences.getBoolean(PREFERENCE_KEY_COMPOSE_BUTTON, false);
    final boolean leftside_compose_button = mPreferences.getBoolean(PREFERENCE_KEY_LEFTSIDE_COMPOSE_BUTTON,
            false);/*from ww w .j  av a2 s.  c  om*/
    int icon = R.drawable.ic_menu_tweet, title = R.string.compose;
    if (mViewPager != null && mAdapter != null) {
        final int position = mViewPager.getCurrentItem();
        int messagesPosition = TAB_POSITION_MESSAGES;
        if (mShowHomeTab == false) {
            messagesPosition--;
        }
        if (mShowMentionsTab == false) {
            messagesPosition--;
        }
        if (position == mAdapter.getCount() - 1 && mShowAccountsTab) {
            icon = R.drawable.ic_menu_add;
            title = R.string.add_account;
        } else {
            title = R.string.compose;
            if (mShowMessagesTab && position == messagesPosition) {
                icon = R.drawable.ic_menu_compose;
            } else {
                icon = R.drawable.ic_menu_tweet;
            }
        }
        final MenuItem composeItem = menu.findItem(MENU_COMPOSE);
        if (composeItem != null) {
            composeItem.setIcon(icon);
            composeItem.setTitle(title);
            composeItem.setVisible(!bottom_actions && mViewPager.getVisibility() == View.VISIBLE);
        }
        if (mComposeButton != null) {
            mComposeButton.setImageResource(icon);
            mComposeButton.setVisibility(
                    bottom_actions && mViewPager.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE);
            if (bottom_actions) {
                final FrameLayout.LayoutParams compose_lp = (FrameLayout.LayoutParams) mComposeButton
                        .getLayoutParams();
                compose_lp.gravity = Gravity.BOTTOM | (leftside_compose_button ? Gravity.LEFT : Gravity.RIGHT);
                mComposeButton.setLayoutParams(compose_lp);
            }
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.bt.download.android.gui.activities.AudioPlayerActivity.java

private void setShareText(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_audio_player_share);
    try {/*from  w  ww.j a  v a2s .  c  o m*/
        FileDescriptor fd = Librarian.instance().getFileDescriptor(Constants.FILE_TYPE_AUDIO,
                (int) MusicUtils.getCurrentAudioId());
        if (fd != null) {
            item.setTitle(fd.shared ? R.string.unshare : R.string.share);
            item.setIcon(fd.shared ? R.drawable.contextmenu_icon_unshare : R.drawable.contextmenu_icon_share);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:com.undatech.opaque.RemoteCanvasActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    int itemID = menuItem.getItemId();
    switch (itemID) {
    case R.id.menuExtraKeys:
        if (connection.getExtraKeysToggleType() == Constants.EXTRA_KEYS_ON) {
            connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_OFF);
            menuItem.setTitle(R.string.extra_keys_enable);
            setExtraKeysVisibility(View.GONE, false);
        } else {//from  w  w  w .j av a 2  s . c  om
            connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_ON);
            menuItem.setTitle(R.string.extra_keys_disable);
            setExtraKeysVisibility(View.VISIBLE, false);
            extraKeysHidden = false;
        }
        setKeyStowDrawableAndVisibility();
        connection.saveToSharedPreferences(getApplicationContext());
        return true;
    case R.id.menuDisconnect:
        canvas.disconnectAndCleanUp();
        finish();
        return true;
    case R.id.menuSendCAD:
        canvas.getKeyboard().keyEvent(112, new KeyEvent(KeyEvent.ACTION_DOWN, 112),
                RemoteKeyboard.CTRL_ON_MASK | RemoteKeyboard.ALT_ON_MASK);
        canvas.getKeyboard().keyEvent(112, new KeyEvent(KeyEvent.ACTION_UP, 112));
        return true;
    case R.id.menuHelpInputMethod:
        showDialog(R.id.menuHelpInputMethod);
        return true;
    default:
        InputHandler newInputHandler = inputHandlerIdMap.get(menuItem.getItemId());
        if (newInputHandler != null) {
            inputHandler = newInputHandler;
            connection.setInputMethod(newInputHandler.getId());
            menuItem.setChecked(true);
            displayInputModeInfo(true);
            connection.saveToSharedPreferences(getApplicationContext());
            return true;
        }
    }
    return super.onOptionsItemSelected(menuItem);
}

From source file:de.vanita5.twittnuker.activity.support.HomeActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    if (mViewPager == null || mPagerAdapter == null)
        return false;
    final boolean useBottomActionItems = FlymeUtils.hasSmartBar() && isBottomComposeButton();
    setMenuItemAvailability(menu, MENU_ACTIONS, useBottomActionItems);
    setMenuItemAvailability(menu, MENU_PROGRESS, useBottomActionItems);
    if (useBottomActionItems) {
        final int icon, title;
        final int position = mViewPager.getCurrentItem();
        final SupportTabSpec tab = mPagerAdapter.getTab(position);
        if (tab == null) {
            title = R.string.compose;// w ww .  j  a v  a  2 s.c o  m
            icon = R.drawable.ic_iconic_action_compose;
        } else {
            if (classEquals(DirectMessagesFragment.class, tab.cls)) {
                icon = R.drawable.ic_iconic_action_new_message;
                title = R.string.new_direct_message;
            } else if (classEquals(TrendsSuggectionsFragment.class, tab.cls)) {
                icon = R.drawable.ic_iconic_action_search;
                title = android.R.string.search_go;
            } else {
                icon = R.drawable.ic_iconic_action_compose;
                title = R.string.compose;
            }
        }
        final ActionBar actionBar = getActionBar();
        final MenuItem actionsItem = menu.findItem(MENU_ACTIONS);
        if (actionBar != null) {
            actionsItem.setIcon(actionBar.getThemedContext().getResources().getDrawable(icon));
        }
        actionsItem.setTitle(title);
    }
    return true;
}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Will close the drawer if the home button is pressed
    if (drawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*w  ww.  j a  v a  2  s .  c o  m*/

    switch (item.getItemId()) {
    case android.R.id.home:
        if (!currentDirectory.equals(homeDirectory)) {
            openParentDirectory();
        }
        break;
    case R.id.menu_view_toggle:
        if (viewMode == GRID_VIEW) {
            viewMode = LIST_VIEW;
            item.setTitle(R.string.grid_view); // Button points to next view.
            item.setIcon(R.drawable.light_view_as_grid);
        } else {
            viewMode = GRID_VIEW;
            item.setTitle(R.string.list_view); // Button points to next view.
            item.setIcon(R.drawable.light_view_as_list);
        }
        createUI();
        break;
    case R.id.menu_sort_size:
    case R.id.menu_sort_az:
    case R.id.menu_sort_modified:
        sortFiles(item);
        break;
    case R.id.action_about:
        mAbout.showAbout();
        return true;
    case R.id.action_settings:
        startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
        return true;
    case R.id.menu_storage_preferences:
        startActivity(new Intent(this, DocumentProviderSettingsActivity.class));
        break;

    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.almarsoft.GroundhogReader.MessageListActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem showRead = menu.findItem(R.id.messagelist_menu_showread);
    boolean showReadValue = mPrefs.getBoolean("showRead", false);
    showRead.setChecked(showReadValue);//ww  w .j a  v a  2 s . com

    if (showReadValue)
        showRead.setTitle(R.string.msglist_group_hideread);
    else
        showRead.setTitle(R.string.msglist_group_showread);

    return (super.onPrepareOptionsMenu(menu));
}

From source file:org.ale.scanner.zotero.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem check_all = (MenuItem) menu.findItem(R.id.ctx_check_all);

    int numChecked = mItemAdapter.getChecked().length;
    int groupCount = mItemAdapter.getGroupCount();

    String title = getString(R.string.check_all);
    // Set to "Uncheck All" if all are checked, or we're
    // waiting for db to return bibitems. In the latter case we
    // just assume all items are checked.
    if ((groupCount > 0 && numChecked == groupCount) || (groupCount == 0 && numChecked > 0)) {
        title = getString(R.string.uncheck_all);
    }//  w w  w  . j  a va  2  s . co  m

    check_all.setTitle(title);
    return true;
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem item = menu.add(Menu.NONE, ACTIONBAR_MENU_ITEM_SUMMIT, Menu.NONE, getString(R.string.menu_take));
    SpannableString spanString = new SpannableString(item.getTitle().toString());
    spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white
    item.setTitle(spanString);

    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.coincide.alphafitness.ui.Fragment_Main.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);
    MenuItem pause = menu.getItem(0);
    Drawable d;/*w w  w.  j  ava2  s.  co  m*/
    if (getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE).contains("pauseCount")) { // currently paused
        pause.setTitle(R.string.resume);
        d = getResources().getDrawable(R.drawable.ic_resume);
    } else {
        pause.setTitle(R.string.pause);
        d = getResources().getDrawable(R.drawable.ic_pause);
    }
    d.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    pause.setIcon(d);
}

From source file:io.jawg.osmcontributor.ui.activities.MapActivity.java

private void onOptionsClick(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.profile_load:
        startProfileLoadingActivity();//from   w w w . j a v  a2s.co m
        break;
    case R.id.replay_tuto_menu:
        replayTutorial();
        break;
    case R.id.edit_way:
        eventBus.post(new PleaseSwitchWayEditionModeEvent());
        break;
    case R.id.arpi_view:
        toggleArpiGl();
        break;
    case R.id.switch_style:
        isSatelliteMode = !isSatelliteMode;
        eventBus.post(new PleaseSwitchMapStyleEvent(isSatelliteMode));
        drawerLayout.closeDrawer(navigationView);
        menuItem.setTitle(isSatelliteMode ? R.string.switch_style_mapnik : R.string.switch_style_satellite);
        break;
    case R.id.offline_regions:
        startOfflineRegionsActivity();
        break;
    case R.id.preferences_menu:
        startPreferencesActivity();
        break;
    case R.id.about_menu:
        startAboutActivity();
        break;
    case R.id.contribute_menu:
        startContributeActivity();
        break;
    case R.id.report:
        startNewReportActivity();
        break;

    }
}