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:org.brandroid.openmanager.fragments.ContentFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    Logger.LogVerbose("ContentFragment.onPrepareOptionsMenu");
    if (getActivity() == null)
        return;/*from   ww  w  . java 2  s  .co m*/
    if (menu == null)
        return;
    if (isDetached() || !isVisible())
        return;
    super.onPrepareOptionsMenu(menu);
    if (OpenExplorer.BEFORE_HONEYCOMB)
        MenuUtils.setMenuVisible(menu, false, R.id.menu_view_carousel);

    MenuUtils.setMenuVisible(menu, mPath instanceof OpenNetworkPath, R.id.menu_context_download);
    MenuUtils.setMenuVisible(menu, !(mPath instanceof OpenNetworkPath), R.id.menu_context_edit,
            R.id.menu_context_view);

    MenuUtils.setMenuChecked(menu, getSorting().foldersFirst(), R.id.menu_sort_folders_first);

    if (mPath != null)
        MenuUtils.setMenuEnabled(menu, !mPath.requiresThread() && mPath.canWrite(), R.id.menu_multi_all_copy,
                R.id.menu_multi_all_move);

    SortType.Type st = getSorting().getType();
    int sti = Utils.getArrayIndex(sortTypes, st);
    if (sti > -1)
        MenuUtils.setMenuChecked(menu, true, sortMenuOpts[sti], sortMenuOpts);

    if (getClipboard() == null || getClipboard().size() == 0) {
        MenuUtils.setMenuVisible(menu, false, R.id.content_paste);
    } else {
        MenuItem mPaste = menu.findItem(R.id.content_paste);
        if (mPaste != null && getClipboard() != null && !isDetached())
            mPaste.setTitle(getString(R.string.s_menu_paste) + " (" + getClipboard().size() + ")");
        if (getClipboard().isMultiselect()) {
            LayerDrawable d = (LayerDrawable) getResources().getDrawable(R.drawable.ic_menu_paste_multi);
            d.getDrawable(1).setAlpha(127);
            if (menu.findItem(R.id.content_paste) != null)
                menu.findItem(R.id.content_paste).setIcon(d);
        }
        if (mPaste != null)
            mPaste.setVisible(true);
    }

    MenuUtils.setMenuEnabled(menu, true, R.id.menu_view, R.id.menu_sort, R.id.menu_content_ops);

    int mViewMode = getViewMode();
    MenuUtils.setMenuChecked(menu, true, 0, R.id.menu_view_grid, R.id.menu_view_list, R.id.menu_view_carousel);
    if (mViewMode == OpenExplorer.VIEW_GRID)
        MenuUtils.setMenuChecked(menu, true, R.id.menu_view_grid, R.id.menu_view_list, R.id.menu_view_carousel);
    else if (mViewMode == OpenExplorer.VIEW_LIST)
        MenuUtils.setMenuChecked(menu, true, R.id.menu_view_list, R.id.menu_view_grid, R.id.menu_view_carousel);
    else if (mViewMode == OpenExplorer.VIEW_CAROUSEL)
        MenuUtils.setMenuChecked(menu, true, R.id.menu_view_carousel, R.id.menu_view_grid, R.id.menu_view_list);

    MenuUtils.setMenuChecked(menu, getShowHiddenFiles(), R.id.menu_view_hidden);
    MenuUtils.setMenuChecked(menu, getShowThumbnails(), R.id.menu_view_thumbs);
    MenuUtils.setMenuVisible(menu, OpenExplorer.CAN_DO_CAROUSEL, R.id.menu_view_carousel);

}

From source file:github.daneren2005.dsub.activity.SubsonicActivity.java

private void populateTabs() {
    drawerList.getMenu().clear();/*from w  w  w . j  a  va 2  s  .  c  om*/
    drawerList.inflateMenu(R.menu.drawer_navigation);

    SharedPreferences prefs = Util.getPreferences(this);
    boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true);
    boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true)
            && !Util.isOffline(this) && ServerInfo.canBookmark(this);
    boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true)
            && !Util.isOffline(this);
    boolean chatEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true)
            && !Util.isOffline(this);
    boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true)
            && !Util.isOffline(this);

    MenuItem offlineMenuItem = drawerList.getMenu().findItem(R.id.drawer_offline);
    if (Util.isOffline(this)) {
        setDrawerItemVisible(R.id.drawer_home, false);

        if (lastSelectedPosition == 0 || lastSelectedPosition == R.id.drawer_home) {
            String newFragment = Util.openToTab(this);
            if (newFragment == null || "Home".equals(newFragment)) {
                newFragment = "Artist";
            }

            lastSelectedPosition = getDrawerItemId(newFragment);
            drawerItemSelected(newFragment);
        }

        offlineMenuItem.setTitle(R.string.main_online);
    } else {
        offlineMenuItem.setTitle(R.string.main_offline);
    }

    if (!podcastsEnabled) {
        setDrawerItemVisible(R.id.drawer_podcasts, false);
    }
    if (!bookmarksEnabled) {
        setDrawerItemVisible(R.id.drawer_bookmarks, false);
    }
    if (!sharedEnabled) {
        setDrawerItemVisible(R.id.drawer_shares, false);
    }
    if (!chatEnabled) {
        setDrawerItemVisible(R.id.drawer_chat, false);
    }
    if (!adminEnabled) {
        setDrawerItemVisible(R.id.drawer_admin, false);
    }

    if (lastSelectedPosition != 0) {
        MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
        if (item != null) {
            item.setChecked(true);
        }
    }
    drawerHeaderToggle.setImageResource(R.drawable.main_select_server_dark);

    showingTabs = true;
}

From source file:im.neon.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 */
    ) {/*w  ww. j av a  2 s .c  om*/

        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_sign_out: {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(VectorHomeActivity.this);
                alertDialogBuilder.setMessage(getString(R.string.action_sign_out_confirmation));

                // set dialog message
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton(R.string.action_sign_out, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                VectorHomeActivity.this.showWaitingView();
                                CommonActivityUtils.logout(VectorHomeActivity.this);
                            }
                        }).setNeutralButton(R.string.encryption_export_export,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.cancel();

                                        VectorHomeActivity.this.runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                exportKeysAndSignOut();
                                            }
                                        });
                                    }
                                })
                        .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });

                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
                // show it
                alertDialog.show();

                break;
            }

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

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

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

            case R.id.sliding_menu_third_party_notices: {
                VectorUtils.displayThirdPartyLicenses();
                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:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mService == null)
        return false;
    MenuItem item = menu.findItem(PARTY_SHUFFLE);
    if (item != null) {
        int shuffle = MusicUtils.getCurrentShuffleMode();
        if (shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle_off);
        } else {//  w w w  .ja  v  a 2s . c  o  m
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle);
        }
    }

    item = menu.findItem(ADD_TO_PLAYLIST);
    if (item != null) {
        SubMenu sub = item.getSubMenu();
        MusicUtils.makePlaylistMenu(this, sub);
    }

    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    menu.setGroupVisible(1, !km.inKeyguardRestrictedInputMode());

    return true;
}

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

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_split_count:
        Dialog_Split.getDialog(getActivity(), total_start + Math.max(todayOffset + since_boot, 0)).show();
        return true;
    case R.id.action_pause:
        SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
        Drawable d;/*from  w  w w.  jav  a  2s  .c  o  m*/
        if (getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE).contains("pauseCount")) { // currently paused -> now resumed
            sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER),
                    SensorManager.SENSOR_DELAY_UI, 0);
            item.setTitle(R.string.pause);
            d = getResources().getDrawable(R.drawable.ic_pause);
        } else {
            sm.unregisterListener(this);
            item.setTitle(R.string.resume);
            d = getResources().getDrawable(R.drawable.ic_resume);
        }
        d.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
        item.setIcon(d);
        getActivity().startService(new Intent(getActivity(), SensorListener.class).putExtra("action",
                SensorListener.ACTION_PAUSE));
        return true;
    default:
        return ((Activity_Main) getActivity()).optionsItemSelected(item);
    }
}

From source file:co.nerdart.ourss.fragment.EntriesListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share_starred: {
        String starredList = "";
        Cursor cursor = mEntriesCursorAdapter.getCursor();
        if (cursor != null && !cursor.isClosed()) {
            int titlePos = cursor.getColumnIndex(EntryColumns.TITLE);
            int linkPos = cursor.getColumnIndex(EntryColumns.LINK);
            if (cursor.moveToFirst()) {
                do {
                    starredList += cursor.getString(titlePos) + "\n" + cursor.getString(linkPos) + "\n\n";
                } while (cursor.moveToNext());
            }//from w ww  .  j  av a  2  s  . c om
            startActivity(Intent.createChooser(
                    new Intent(Intent.ACTION_SEND)
                            .putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_favorites_title))
                            .putExtra(Intent.EXTRA_TEXT, starredList).setType(Constants.MIMETYPE_TEXT_PLAIN),
                    getString(R.string.menu_share)));
        }
        return true;
    }
    case R.id.menu_refresh: {
        if (!FetcherService.isRefreshingFeeds) {
            getActivity().startService(
                    new Intent(getActivity(), FetcherService.class).setAction(Constants.ACTION_REFRESH_FEEDS));
        }
        return true;
    }
    case R.id.menu_all_read: {
        mEntriesCursorAdapter.markAllAsRead();
        return true;
    }
    case R.id.menu_hide_read: {
        if (!PrefUtils.getBoolean(PrefUtils.SHOW_READ, true)) {
            PrefUtils.putBoolean(PrefUtils.SHOW_READ, true);
            item.setTitle(R.string.context_menu_hide_read).setIcon(R.drawable.hide_reads);
        } else {
            PrefUtils.putBoolean(PrefUtils.SHOW_READ, false);
            item.setTitle(R.string.context_menu_show_read).setIcon(R.drawable.view_reads);
        }
        return true;
    }
    case R.id.menu_settings: {
        startActivity(new Intent(getActivity(), GeneralPrefsActivity.class));
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java

public boolean onPrepareOptionsMenu(Menu menu) {
    // gps status
    menu.findItem(R.id.action_gps_inactive).setVisible(false);
    menu.findItem(R.id.action_gps_active_has_signal).setVisible(false);
    menu.findItem(R.id.action_gps_active_no_signal).setVisible(false);
    if (gpsDataManager.isExternalGPSStarted() || gpsDataManager.isInternalGPSStarted()) {
        if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) {
            menu.findItem(R.id.action_gps_active_has_signal).setVisible(true);
        } else {//from ww  w  .  jav  a 2  s .co m
            menu.findItem(R.id.action_gps_active_no_signal).setVisible(true);
        }
    } else {
        menu.findItem(R.id.action_gps_inactive).setVisible(true);
    }

    // tracker status
    menu.findItem(R.id.action_tracker_active_no_gps).setVisible(false);
    menu.findItem(R.id.action_tracker_active_has_gps).setVisible(false);
    menu.findItem(R.id.action_tracker_inactive).setVisible(false);
    if (gpsDataManager.isTrackingStarted()) {
        if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) {
            menu.findItem(R.id.action_tracker_active_has_gps).setVisible(true);
        } else {
            menu.findItem(R.id.action_tracker_active_no_gps).setVisible(true);
        }
    } else {
        menu.findItem(R.id.action_tracker_inactive).setVisible(true);
    }

    // sync status
    menu.findItem(R.id.action_sync).setVisible(false);
    menu.findItem(R.id.action_sync_active).setVisible(false);
    menu.findItem(R.id.action_sync_error).setVisible(false);
    menu.findItem(R.id.action_sync_has_changes).setVisible(false);
    menu.findItem(R.id.action_sync_inactive).setVisible(false);

    syncAnimImage.clearAnimation();

    switch (syncStatus) {
    case ACTIVE_SYNCING:
        MenuItem syncItem = menu.findItem(R.id.action_sync_active).setVisible(true);

        syncAnimImage.startAnimation(rotation);

        syncItem.setActionView(syncAnimImage);

        break;
    case ERROR:
        menu.findItem(R.id.action_sync_error).setVisible(true);
        break;
    case ACTIVE_NO_CHANGES:
        menu.findItem(R.id.action_sync).setVisible(true);
        break;
    case ACTIVE_HAS_CHANGES:
        menu.findItem(R.id.action_sync_has_changes).setVisible(true);
        break;
    default:
        menu.findItem(R.id.action_sync_inactive).setVisible(true);
        break;
    }

    // follow status
    MenuItem distance_text = menu.findItem(R.id.distance_text);
    distance_text.setVisible(pathIndicatorVisible);
    String distanceInfo = pathIndex < 0 ? "" : " to point (" + pathIndex + "/" + pathLength + ")";
    if (pathDistance > 1000) {
        distance_text.setTitle(
                MeasurementUtil.displayAsKiloMeters(pathDistance / 1000, "###,###,###,###.0") + distanceInfo);
    } else {
        distance_text.setTitle(MeasurementUtil.displayAsMeters(pathDistance, "###,###,###,###") + distanceInfo);
    }

    MenuItem direction_text = menu.findItem(R.id.direction_text);
    direction_text.setVisible(pathIndicatorVisible);
    direction_text.setTitle(MeasurementUtil.displayAsDegrees(pathBearing, "###"));

    MenuItem direction_indicator = menu.findItem(R.id.direction_indicator);
    direction_indicator.setVisible(pathIndicatorVisible);
    if (pathHeading != null) {
        if (tempBitmap != null) {
            tempBitmap.recycle();
        }
        if (whiteArrow == null) {
            whiteArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(),
                    au.org.intersect.faims.android.R.drawable.white_arrow));
        }
        if (greyArrow == null) {
            greyArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(),
                    au.org.intersect.faims.android.R.drawable.grey_arrow));
        }

        this.tempBitmap = BitmapUtil.rotateBitmap(pathValid ? whiteArrow.getBitmap() : greyArrow.getBitmap(),
                pathBearing - pathHeading);
        direction_indicator.setIcon(new BitmapDrawable(getResources(), tempBitmap));
    } else {
        direction_indicator.setVisible(false);
    }

    return true;
}

From source file:com.experiment.chickenjohn.materialdemo.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from   w w  w .  j a v a2  s  . c o m
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    switch (id) {
    case R.id.rate_setting:
        rateSettinginEdit = new EditText(this);
        new AlertDialog.Builder(this).setTitle("(Hz)").setView(rateSettinginEdit)
                .setPositiveButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        rateSettinginString = rateSettinginEdit.getText().toString();
                        EcgData.setRecordRate(Double.valueOf(rateSettinginString).doubleValue());
                        Log.v("recordrate", Double.toString(EcgData.getRECORDRATE()));
                    }
                }).show();
        break;
    case R.id.data_output:
        if (ecgDatabaseManager.outputRecord()) {
            Toast.makeText(this, "??", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "???", Toast.LENGTH_LONG).show();
        }
        break;
    case R.id.data_clear:
        if (ecgDatabaseManager.clearRecord()) {
            Toast.makeText(this, "??", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "?", Toast.LENGTH_LONG).show();
        }
        break;
    case R.id.spo2_switch:
        if (receiveSpo2) {
            item.setTitle("SpO2");
            receiveSpo2 = false;
            btManager.setSpo2Receiver(receiveSpo2);
            drawSurfaceView.resetSurfaceViewX();
        } else {
            item.setTitle("SpO2");
            receiveSpo2 = true;
            btManager.setSpo2Receiver(receiveSpo2);
            drawSurfaceView.resetSurfaceViewX();
        }
        drawSurfaceView.resetCanvas();
        break;
    case R.id.btconnection:
        btManager.enableBluetooth();
        break;
    default:
        break;
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

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

private void setCommonMenu(final Menu menu) {
    final boolean hasMedia = hasMedia();
    final int activatedColor = getUserThemeColor(this);
    final MenuItem itemAddImageSubmenu = menu.findItem(R.id.add_image_submenu);
    if (itemAddImageSubmenu != null) {
        final Drawable iconAddImage = itemAddImageSubmenu.getIcon();
        iconAddImage.mutate();//from   www.  j  a v a  2 s  .co m
        if (hasMedia) {
            iconAddImage.setColorFilter(activatedColor, Mode.SRC_ATOP);
        } else {
            iconAddImage.clearColorFilter();
        }
    }
    final MenuItem itemAttachLocation = menu.findItem(MENU_ADD_LOCATION);
    if (itemAttachLocation != null) {
        final Drawable iconAttachLocation = itemAttachLocation.getIcon().mutate();
        final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false);
        if (attachLocation && getLocation()) {
            iconAttachLocation.setColorFilter(activatedColor, Mode.SRC_ATOP);
            itemAttachLocation.setTitle(R.string.remove_location);
            itemAttachLocation.setChecked(true);
        } else {
            setProgressVisibility(false);
            mPreferences.edit().putBoolean(KEY_ATTACH_LOCATION, false).commit();
            iconAttachLocation.clearColorFilter();
            itemAttachLocation.setTitle(R.string.add_location);
            itemAttachLocation.setChecked(false);
        }
    }
    final MenuItem viewItem = menu.findItem(MENU_VIEW);
    if (viewItem != null) {
        viewItem.setVisible(mInReplyToStatus != null);
    }
    final MenuItem itemToggleSensitive = menu.findItem(MENU_TOGGLE_SENSITIVE);
    if (itemToggleSensitive != null) {
        itemToggleSensitive.setVisible(hasMedia);
        itemToggleSensitive.setEnabled(hasMedia);
        itemToggleSensitive.setChecked(hasMedia && mIsPossiblySensitive);
        if (hasMedia) {
            final Drawable iconToggleSensitive = itemToggleSensitive.getIcon().mutate();
            if (mIsPossiblySensitive) {
                itemToggleSensitive.setTitle(R.string.remove_sensitive_mark);
                iconToggleSensitive.setColorFilter(activatedColor, Mode.SRC_ATOP);
            } else {
                itemToggleSensitive.setTitle(R.string.mark_as_sensitive);
                iconToggleSensitive.clearColorFilter();
            }
        }
    }
}

From source file:jackpal.androidterm.Term.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem wakeLockItem = menu.findItem(R.id.menu_toggle_wakelock);
    MenuItem wifiLockItem = menu.findItem(R.id.menu_toggle_wifilock);
    if (mWakeLock.isHeld()) {
        wakeLockItem.setTitle(R.string.disable_wakelock);
    } else {//from w  w  w  .j  a va 2  s. c o  m
        wakeLockItem.setTitle(R.string.enable_wakelock);
    }
    if (mWifiLock.isHeld()) {
        wifiLockItem.setTitle(R.string.disable_wifilock);
    } else {
        wifiLockItem.setTitle(R.string.enable_wifilock);
    }
    return super.onPrepareOptionsMenu(menu);
}