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.mariotaku.twidere.util.Utils.java

public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) {
    if (context == null || menu == null || status == null)
        return;/*from  w w  w. j a v  a  2s  .  c  om*/
    final int activated_color = context.getResources().getColor(R.color.holo_blue_bright);
    final MenuItem delete = menu.findItem(R.id.delete_submenu);
    if (delete != null) {
        delete.setVisible(status.account_id == status.user_id && !isMyRetweet(status));
    }
    final MenuItem retweet = menu.findItem(MENU_RETWEET);
    if (retweet != null) {
        final Drawable icon = retweet.getIcon().mutate();
        retweet.setVisible(!status.is_protected || isMyRetweet(status));
        if (isMyRetweet(status)) {
            icon.setColorFilter(activated_color, Mode.MULTIPLY);
            retweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            retweet.setTitle(R.string.retweet);
        }
    }
    final MenuItem favorite = menu.findItem(MENU_FAVORITE);
    if (favorite != null) {
        final Drawable icon = favorite.getIcon().mutate();
        if (status.is_favorite) {
            icon.setColorFilter(activated_color, Mode.MULTIPLY);
            favorite.setTitle(R.string.unfavorite);
        } else {
            icon.clearColorFilter();
            favorite.setTitle(R.string.favorite);
        }
    }
    final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
    if (extensions != null) {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS);
        final Bundle extras = new Bundle();
        extras.putParcelable(INTENT_KEY_STATUS, status);
        intent.putExtras(extras);
        final PackageManager pm = context.getPackageManager();
        final List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
        final boolean has_extension = !activities.isEmpty();
        extensions.setVisible(has_extension);
        if (has_extension) {
            addIntentToSubMenu(context, extensions.getSubMenu(), intent);
        }
    }
}

From source file:com.jefftharris.passwdsafe.PasswdSafe.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final BitSet options = new BitSet();
    options.set(MENU_BIT_HAS_CLOSE);//  w w  w  .j a v  a  2  s .  c  o  m

    itsFileDataFrag.useFileData(new PasswdFileDataUser() {
        @Override
        public void useFileData(@NonNull PasswdFileData fileData) {
            boolean fileEditable = fileData.canEdit();

            switch (itsCurrViewMode) {
            case VIEW_LIST: {
                options.set(MENU_BIT_CAN_ADD, fileEditable);
                options.set(MENU_BIT_HAS_SEARCH, true);
                if (fileEditable) {
                    options.set(MENU_BIT_HAS_FILE_OPS, true);
                    options.set(MENU_BIT_HAS_FILE_CHANGE_PASSWORD, fileData.isNotYubikey());
                    options.set(MENU_BIT_HAS_FILE_PROTECT, true);
                    options.set(MENU_BIT_PROTECT_ALL, itsLocation.getGroups().isEmpty());
                }
                if (fileData.canDelete()) {
                    options.set(MENU_BIT_HAS_FILE_OPS, true);
                    options.set(MENU_BIT_HAS_FILE_DELETE, true);
                }
                break;
            }
            case VIEW_RECORD: {
                options.set(MENU_BIT_CAN_ADD, fileEditable);
                break;
            }
            case INIT:
            case FILE_OPEN:
            case FILE_NEW:
            case VIEW_ABOUT:
            case VIEW_EXPIRATION:
            case VIEW_POLICY_LIST:
            case VIEW_PREFERENCES: {
                break;
            }
            case EDIT_RECORD:
            case CHANGING_PASSWORD: {
                options.set(MENU_BIT_HAS_CLOSE, false);
                break;
            }
            }
        }
    });

    MenuItem item = menu.findItem(R.id.menu_add);
    if (item != null) {
        item.setVisible(options.get(MENU_BIT_CAN_ADD));
    }

    item = menu.findItem(R.id.menu_close);
    if (item != null) {
        item.setVisible(options.get(MENU_BIT_HAS_CLOSE));
    }

    item = menu.findItem(R.id.menu_file_ops);
    if (item != null) {
        item.setVisible(options.get(MENU_BIT_HAS_FILE_OPS));
    }

    item = menu.findItem(R.id.menu_file_change_password);
    if (item != null) {
        item.setEnabled(options.get(MENU_BIT_HAS_FILE_CHANGE_PASSWORD));
    }

    if (options.get(MENU_BIT_HAS_FILE_OPS)) {
        boolean hasProtect = options.get(MENU_BIT_HAS_FILE_PROTECT);
        boolean viewProtectAll = options.get(MENU_BIT_PROTECT_ALL);
        item = menu.findItem(R.id.menu_file_protect_records);
        if (item != null) {
            item.setEnabled(hasProtect);
            item.setTitle(viewProtectAll ? R.string.protect_all : R.string.protect_group);
        }
        item = menu.findItem(R.id.menu_file_unprotect_records);
        if (item != null) {
            item.setEnabled(hasProtect);
            item.setTitle(viewProtectAll ? R.string.unprotect_all : R.string.unprotect_group);
        }

        item = menu.findItem(R.id.menu_file_delete);
        if (item != null) {
            item.setEnabled(options.get(MENU_BIT_HAS_FILE_DELETE));
        }
    }

    item = menu.findItem(R.id.menu_search);
    if (item != null) {
        item.setVisible(options.get(MENU_BIT_HAS_SEARCH));
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) {
    if (context == null || menu == null || status == null)
        return;/*  www  .ja  va 2  s. c om*/
    final int activated_color = context.getResources().getColor(R.color.holo_blue_bright);
    final MenuItem itemDelete = menu.findItem(R.id.delete_submenu);
    if (itemDelete != null) {
        itemDelete.setVisible(status.account_id == status.user_id && !isMyRetweet(status));
    }
    final MenuItem itemRetweet = menu.findItem(MENU_RETWEET);
    if (itemRetweet != null) {
        final Drawable icon = itemRetweet.getIcon().mutate();
        itemRetweet.setVisible(
                (!status.is_protected && status.account_id != status.user_id) || isMyRetweet(status));
        if (isMyRetweet(status)) {
            icon.setColorFilter(activated_color, Mode.MULTIPLY);
            itemRetweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            itemRetweet.setTitle(R.string.retweet);
        }
    }
    final MenuItem itemFav = menu.findItem(MENU_FAV);
    if (itemFav != null) {
        final Drawable iconFav = itemFav.getIcon().mutate();
        if (status.is_favorite) {
            iconFav.setColorFilter(activated_color, Mode.MULTIPLY);
            itemFav.setTitle(R.string.unfav);
        } else {
            iconFav.clearColorFilter();
            itemFav.setTitle(R.string.fav);
        }
    }
    final MenuItem itemConversation = menu.findItem(MENU_CONVERSATION);
    if (itemConversation != null) {
        itemConversation.setVisible(status.in_reply_to_status_id > 0);
    }
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public void onCreateContextMenu(final ContextMenu menu, final View view,
        final ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, view, info);
    final int viewId = view.getId();
    switch (viewId) {
    case R.id.waypoint:
        menu.setHeaderTitle(selectedWaypoint.getName() + " (" + res.getString(R.string.waypoint) + ")");
        getMenuInflater().inflate(R.menu.waypoint_options, menu);
        final boolean isOriginalWaypoint = selectedWaypoint.getWaypointType() == WaypointType.ORIGINAL;
        menu.findItem(R.id.menu_waypoint_reset_cache_coords).setVisible(isOriginalWaypoint);
        menu.findItem(R.id.menu_waypoint_edit).setVisible(!isOriginalWaypoint);
        menu.findItem(R.id.menu_waypoint_duplicate).setVisible(!isOriginalWaypoint);
        menu.findItem(R.id.menu_waypoint_delete).setVisible(!isOriginalWaypoint);
        final boolean hasCoords = selectedWaypoint.getCoords() != null;
        final MenuItem defaultNavigationMenu = menu.findItem(R.id.menu_waypoint_navigate_default);
        defaultNavigationMenu.setVisible(hasCoords);
        defaultNavigationMenu.setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName());
        menu.findItem(R.id.menu_waypoint_navigate).setVisible(hasCoords);
        menu.findItem(R.id.menu_waypoint_caches_around).setVisible(hasCoords);
        menu.findItem(R.id.menu_waypoint_copy_coordinates).setVisible(hasCoords);
        final boolean canClearCoords = hasCoords
                && (selectedWaypoint.isUserDefined() || selectedWaypoint.isOriginalCoordsEmpty());
        menu.findItem(R.id.menu_waypoint_clear_coordinates).setVisible(canClearCoords);
        break;/*ww  w  . j av  a2 s.co m*/
    default:
        if (imagesList != null) {
            imagesList.onCreateContextMenu(menu, view);
        }
        break;
    }
}

From source file:com.xandy.calendar.AllInOneActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Time t = null;//from   www  .  ja  va2 s.  co m
    int viewType = ViewType.CURRENT;
    long extras = CalendarController.EXTRA_GOTO_TIME;
    final int itemId = item.getItemId();
    if (itemId == R.id.action_refresh) {
        mController.refreshCalendars();
        return true;
    } else if (itemId == R.id.action_today) {
        viewType = ViewType.CURRENT;
        t = new Time(mTimeZone);
        t.setToNow();
        extras |= CalendarController.EXTRA_GOTO_TODAY;
    } else if (itemId == R.id.action_create_event) {
        t = new Time();
        t.set(mController.getTime());
        if (t.minute > 30) {
            t.hour++;
            t.minute = 0;
        } else if (t.minute > 0 && t.minute < 30) {
            t.minute = 30;
        }
        mController.sendEventRelatedEvent(this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
        return true;
    } else if (itemId == R.id.action_select_visible_calendars) {
        mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null, 0, 0);
        return true;
    } else if (itemId == R.id.action_settings) {
        mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
        return true;
    } else if (itemId == R.id.action_hide_controls) {
        mHideControls = !mHideControls;
        Utils.setSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls);
        item.setTitle(mHideControls ? mShowString : mHideString);
        if (!mHideControls) {
            mMiniMonth.setVisibility(View.VISIBLE);
            mCalendarsList.setVisibility(View.VISIBLE);
            mMiniMonthContainer.setVisibility(View.VISIBLE);
        }
        final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                mHideControls ? 0 : mControlsAnimateWidth, mHideControls ? mControlsAnimateWidth : 0);
        slideAnimation.setDuration(mCalendarControlsAnimationTime);
        ObjectAnimator.setFrameDelay(0);
        slideAnimation.start();
        return true;
    } else if (itemId == R.id.action_search) {
        return false;
    } else {
        return mExtensions.handleItemSelected(item, this);
    }
    mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
    return true;
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/* www  . j a  v  a  2s. c o  m*/

    switch (item.getItemId()) {

    case R.id.home:
        mDrawerLayout.openDrawer(GravityCompat.START);
        return true;

    //            Show / hide the debug view
    case R.id.debug_view_item:

        // Create the debug view - if it is not already created:
        if (mDebugViewFragment == null) {
            mDebugViewFragment = new DebugViewFragment();
        }

        // Show the debug view:
        if (getSupportFragmentManager().findFragmentByTag(DEBUG_VIEW_FRAGMENT) == null) {
            mIsDebugViewEnabled = true;
            item.setTitle(R.string.hide_debug_view_text);
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container_layout, mDebugViewFragment, DEBUG_VIEW_FRAGMENT).commit();
        }
        // Hide the debug view:
        else {
            mIsDebugViewEnabled = false;
            item.setTitle(R.string.show_debug_view_text);
            getSupportFragmentManager().beginTransaction().remove(mDebugViewFragment).commit();
        }

        return true;

    // Switch between the two page segmentation methods:
    case R.id.use_lab_item:

        if (NativeWrapper.useLab()) {
            NativeWrapper.setUseLab(false);
            item.setTitle(R.string.precise_page_seg_text);
        } else {
            NativeWrapper.setUseLab(true);
            item.setTitle(R.string.fast_page_seg_text);
        }

        return true;

    // Focus measurement:
    case R.id.show_fm_values_item:

        if (mPaintView.isFocusTextVisible()) {
            item.setTitle(R.string.show_fm_values_text);
            mPaintView.drawFocusText(false);
        } else {
            item.setTitle(R.string.hide_fm_values_text);
            mPaintView.drawFocusText(true);
        }

        break;

    // Guide lines:
    case R.id.show_guide_item:

        if (mPaintView.areGuideLinesDrawn()) {
            mPaintView.drawGuideLines(false);
            item.setTitle(R.string.show_guide_text);
        } else {
            mPaintView.drawGuideLines(true);
            item.setTitle(R.string.hide_guide_text);
        }

        break;

    //            // Threading:
    //            case R.id.threading_item:
    //                if (mCameraPreview.isMultiThreading()) {
    //                    mCameraPreview.setThreading(false);
    //                    item.setTitle(R.string.multi_thread_text);
    //                }
    //                else {
    //                    mCameraPreview.setThreading(true);
    //                    item.setTitle(R.string.single_thread_text);
    //                }

    }

    return super.onOptionsItemSelected(item);
}

From source file:com.android.gallery3d.app.PhotoPage.java

private void updatePanoramaUI(boolean isPanorama360) {
    Menu menu = mActionBar.getMenu();

    // it could be null if onCreateActionBar has not been called yet
    if (menu == null) {
        return;//from   w w w  .jav a2s .  c  o  m
    }

    MenuExecutor.updateMenuForPanorama(menu, isPanorama360, isPanorama360);

    if (isPanorama360) {
        MenuItem item = menu.findItem(R.id.action_share);
        if (item != null) {
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            item.setTitle(mActivity.getResources().getString(R.string.share_as_photo));
        }
    } else if ((mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_SHARE) != 0) {
        MenuItem item = menu.findItem(R.id.action_share);
        if (item != null) {
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            item.setTitle(mActivity.getResources().getString(R.string.share));
        }
    }
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mContactData != null) {
        final MenuItem starredMenuItem = menu.findItem(R.id.menu_star);
        ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, mContactData.isDirectoryEntry(),
                mContactData.isUserProfile(), mContactData.getStarred());

        // Configure edit MenuItem
        final MenuItem editMenuItem = menu.findItem(R.id.menu_edit);
        editMenuItem.setVisible(true);/*from w ww. j  a  v a 2 s. c  o m*/
        if (DirectoryContactUtil.isDirectoryContact(mContactData)
                || InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) {
            editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp);
            editMenuItem.setTitle(R.string.menu_add_contact);
        } else if (isContactEditable()) {
            editMenuItem.setIcon(R.drawable.ic_create_24dp);
            editMenuItem.setTitle(R.string.menu_editContact);
        } else {
            editMenuItem.setVisible(false);
        }

        final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete);
        deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile());

        final MenuItem shareMenuItem = menu.findItem(R.id.menu_share);
        shareMenuItem.setVisible(isContactShareable());

        final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut);
        shortcutMenuItem.setVisible(isShortcutCreatable());

        final MenuItem helpMenu = menu.findItem(R.id.menu_help);
        helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable());

        return true;
    }
    return false;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void setMenuItemTitle(final Menu menu, final int id, final int icon) {
    if (menu == null)
        return;//from  w  w  w .  j  av  a  2s . co  m
    final MenuItem item = menu.findItem(id);
    if (item == null)
        return;
    item.setTitle(icon);
}

From source file:net.robotmedia.acv.ui.widget.OcrLayout.java

/** Update properties for the text orientation menu item */
public void updateMenuItemTextOrientation(MenuItem menuItem) {
    if (this.textOrientation == this.TEXT_ORIENTATION_HORIZONTAL) {
        menuItem.setTitle(getResources().getString(R.string.menu_item_ocr_text_orientation_horizontal));
    } else if (this.textOrientation == this.TEXT_ORIENTATION_VERTICAL) {
        menuItem.setTitle(getResources().getString(R.string.menu_item_ocr_text_orientation_vertical));
    } else // TEXT_ORIENTATION_AUTO
    {/*  w  w w . ja  v  a 2s . co  m*/
        menuItem.setTitle(getResources().getString(R.string.menu_item_ocr_text_orientation_auto));
    }
}