Example usage for android.view MenuItem setVisible

List of usage examples for android.view MenuItem setVisible

Introduction

In this page you can find the example usage for android.view MenuItem setVisible.

Prototype

public MenuItem setVisible(boolean visible);

Source Link

Document

Sets the visibility of the menu item.

Usage

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    if (fileOpened && searchResult != null) {
        MenuItem imReplace = menu.findItem(R.id.im_replace);
        MenuItem imReplaceAll = menu.findItem(R.id.im_replace_all);
        MenuItem imPrev = menu.findItem(R.id.im_previous_item);
        MenuItem imNext = menu.findItem(R.id.im_next_item);

        if (imReplace != null)
            imReplace.setVisible(searchResult.canReplaceSomething());

        if (imReplaceAll != null)
            imReplaceAll.setVisible(searchResult.canReplaceSomething());

        if (imPrev != null)
            imPrev.setVisible(searchResult.hasPrevious());

        if (imNext != null)
            imNext.setVisible(searchResult.hasNext());

    } else if (fileOpened) {
        MenuItem imSave = menu.findItem(R.id.im_save);
        MenuItem imUndo = menu.findItem(R.id.im_undo);
        MenuItem imRedo = menu.findItem(R.id.im_redo);

        if (mEditor != null) {
            if (imSave != null)
                imSave.setVisible(mEditor.canSaveFile());
            if (imUndo != null)
                imUndo.setVisible(mEditor.getCanUndo());
            if (imRedo != null)
                imRedo.setVisible(mEditor.getCanRedo());
        } else {/*from  w  w w  .  j a  v a 2s . co  m*/
            imSave.setVisible(false);
            imUndo.setVisible(false);
            imRedo.setVisible(false);
        }

        MenuItem imMarkdown = menu.findItem(R.id.im_view_markdown);
        boolean isMarkdown = Arrays.asList(MimeTypes.MIME_MARKDOWN)
                .contains(FilenameUtils.getExtension(greatUri.getFileName()));
        if (imMarkdown != null)
            imMarkdown.setVisible(isMarkdown);

        MenuItem imShare = menu.findItem(R.id.im_share);
        if (imMarkdown != null) {
            ShareActionProvider shareAction = (ShareActionProvider) MenuItemCompat.getActionProvider(imShare);
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, greatUri.getUri());
            shareIntent.setType("text/plain");
            shareAction.setShareIntent(shareIntent);
        }
    }

    return true;
}

From source file:com.android.calendar.EventInfoFragment.java

/**
 *
 *///from   ww  w .  ja  v  a  2 s. c o m
private void updateMenu() {
    if (mMenu == null) {
        return;
    }
    MenuItem delete = mMenu.findItem(R.id.info_action_delete);
    MenuItem edit = mMenu.findItem(R.id.info_action_edit);
    MenuItem changeColor = mMenu.findItem(R.id.info_action_change_color);
    if (delete != null) {
        delete.setVisible(mCanModifyCalendar);
        delete.setEnabled(mCanModifyCalendar);
    }
    if (edit != null) {
        edit.setVisible(mCanModifyEvent);
        edit.setEnabled(mCanModifyEvent);
    }
    if (changeColor != null && mColors != null && mColors.length > 0) {
        changeColor.setVisible(mCanModifyCalendar);
        changeColor.setEnabled(mCanModifyCalendar);
    }
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public void onSupportActionModeStarted(final ActionMode mode) {
    if (mSelectionModeActive && selectedTextView != null) {
        mSelectionModeActive = false;/* w  ww  .j a va2 s . com*/
        mActionMode = mode;
        final Menu menu = mode.getMenu();
        mode.getMenuInflater().inflate(R.menu.details_context, menu);
        menu.findItem(R.id.menu_copy).setVisible(false);
        menu.findItem(R.id.menu_cache_share_field).setOnMenuItemClickListener(new TextMenuItemClickListener());
        menu.findItem(R.id.menu_translate_to_sys_lang)
                .setOnMenuItemClickListener(new TextMenuItemClickListener());
        menu.findItem(R.id.menu_translate_to_english)
                .setOnMenuItemClickListener(new TextMenuItemClickListener());
        final MenuItem extWpts = menu.findItem(R.id.menu_extract_waypoints);
        extWpts.setVisible(true);
        extWpts.setOnMenuItemClickListener(new TextMenuItemClickListener());
        buildDetailsContextMenu(mode, menu, res.getString(R.string.cache_description), false);
        selectedTextView.setWindowFocusWait(true);
    }
    super.onSupportActionModeStarted(mode);
}

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;/*  www. jav a 2  s.c om*/
    default:
        if (imagesList != null) {
            imagesList.onCreateContextMenu(menu, view);
        }
        break;
    }
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

@Override
public void onClick(final View view) {
    switch (view.getId()) {
    case R.id.follow: {
        if (mUser != null && mAccountId != mUser.getId()) {
            mFollowProgress.setVisibility(View.VISIBLE);
            mFollowButton.setVisibility(View.GONE);
            if (mFriendship.isSourceFollowingTarget()) {
                mService.destroyFriendship(mAccountId, mUser.getId());
            } else {
                mService.createFriendship(mAccountId, mUser.getId());
            }/*  w  w  w  .j a  va2s.c  o  m*/
        }
        break;
    }
    case R.id.retry: {
        reloadUserInfo();
        break;
    }
    case R.id.name_container: {
        if (mUser != null) {
        }
        break;
    }
    case R.id.profile_image_container: {
        final String profile_image_url_string = getOriginalTwitterProfileImage(
                parseString(mUser.getProfileImageURL()));
        if (profile_image_url_string == null)
            return;
        final Uri uri = Uri.parse(profile_image_url_string);
        openImage(getActivity(), uri, false);
        break;
    }
    case R.id.tweets_container: {
        if (mUser == null)
            return;
        openUserTimeline(getActivity(), mAccountId, mUser.getId(), mUser.getScreenName());
        break;
    }
    case R.id.followers_container: {
        if (mUser == null)
            return;
        openUserFollowers(getActivity(), mAccountId, mUser.getId(), mUser.getScreenName());
        break;
    }
    case R.id.friends_container: {
        if (mUser == null)
            return;
        openUserFriends(getActivity(), mAccountId, mUser.getId(), mUser.getScreenName());
        break;
    }
    case R.id.more_options: {
        if (mUser == null || mFriendship == null)
            return;
        if (!isMyActivatedAccount(getActivity(), mUser.getId())) {
            mPopupMenu = PopupMenu.getInstance(getActivity(), view);
            mPopupMenu.inflate(R.menu.action_user_profile);
            final Menu menu = mPopupMenu.getMenu();
            final MenuItem blockItem = menu.findItem(MENU_BLOCK);
            final MenuItem trackItem = menu.findItem(MENU_TRACKING);
            if (blockItem != null) {
                final Drawable blockIcon = blockItem.getIcon();
                if (mFriendship.isSourceBlockingTarget()) {
                    blockItem.setTitle(R.string.unblock);
                    blockIcon.mutate().setColorFilter(getResources().getColor(R.color.holo_blue_bright),
                            PorterDuff.Mode.MULTIPLY);
                } else {
                    blockItem.setTitle(R.string.block);
                    blockIcon.clearColorFilter();
                }
            }
            if (trackItem != null) {
                if (mPreferences.getBoolean(com.dwdesign.tweetings.Constants.PREFERENCE_KEY_PUSH_NOTIFICATIONS,
                        false) == false) {
                    trackItem.setVisible(false);
                } else {
                    if (tracking == true) {
                        trackItem.setTitle(R.string.untrack_user);
                    } else {
                        trackItem.setTitle(R.string.track_user);
                    }
                }
            }
            final MenuItem sendDirectMessageItem = menu.findItem(MENU_SEND_DIRECT_MESSAGE);
            if (sendDirectMessageItem != null) {
                sendDirectMessageItem.setVisible(mFriendship.isTargetFollowingSource());
            }
            final MenuItem wantRetweetsItem = menu.findItem(MENU_WANT_RETWEETS);
            if (mFriendship.wantRetweets() == true) {
                wantRetweetsItem.setTitle(R.string.disable_retweet);
            } else {
                wantRetweetsItem.setTitle(R.string.enable_retweet);
            }
            mPopupMenu.setOnMenuItemClickListener(this);
            mPopupMenu.show();
        }
        break;
    }
    }

}

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);
        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 {// w ww.  j  av a2  s. c om
            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:com.eveningoutpost.dexdrip.Home.java

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

    //wear integration
    if (!prefs.getBoolean("wear_sync", false)) {
        menu.removeItem(R.id.action_open_watch_settings);
        menu.removeItem(R.id.action_resend_last_bg);
        menu.removeItem(R.id.action_sync_watch_db);//KS
    }/*from   w  w  w . ja va  2 s.  co  m*/

    //speak readings
    MenuItem menuItem = menu.findItem(R.id.action_toggle_speakreadings);
    if (prefs.getBoolean("bg_to_speech_shortcut", false)) {

        menuItem.setVisible(true);
        if (prefs.getBoolean("bg_to_speech", false)) {
            menuItem.setChecked(true);
        } else {
            menuItem.setChecked(false);
        }
    } else {
        menuItem.setVisible(false);
    }

    menu.findItem(R.id.showmap).setVisible(prefs.getBoolean("plus_extra_features", false));
    menu.findItem(R.id.parakeetsetup).setVisible(prefs.getBoolean("plus_extra_features", false));

    boolean result = super.onCreateOptionsMenu(menu);

    return result;
}

From source file:com.dwdesign.tweetings.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 MenuItem itemLibrary = menu.findItem(MENU_LIBRARY_MENU);
    final Drawable iconAddImage = itemAddImage.getIcon().mutate();
    final Drawable iconLibrary = itemLibrary.getIcon().mutate();
    boolean menuSelected = false;
    if (mIsImageAttached && !mIsPhotoAttached) {
        iconAddImage.setColorFilter(activated_color, Mode.MULTIPLY);
        itemAddImage.setTitle(R.string.remove_image);
        menuSelected = true;/*from ww w.  jav a 2 s  .  c o  m*/
    } else {
        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);
        menuSelected = true;
    } else {
        iconTakePhoto.clearColorFilter();
        itemTakePhoto.setTitle(R.string.take_photo);
    }
    if (menuSelected == true) {
        iconLibrary.setColorFilter(activated_color, Mode.MULTIPLY);
    } else {
        iconLibrary.clearColorFilter();
    }
    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);

    boolean moreHighlighted = false;
    if (itemMore != null) {
        final MenuItem itemDrafts = menu.findItem(R.id.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) {
                    moreHighlighted = true;
                    iconDrafts.setColorFilter(activated_color, Mode.MULTIPLY);
                } else {
                    iconDrafts.clearColorFilter();
                }
                drafts_cur.close();
            }
            if (itemToggleSensitive != null) {
                final boolean has_media = (mIsImageAttached || mIsPhotoAttached) && mImageUri != null;
                if (has_media && isNullOrEmpty(mUploadProvider)) {
                    itemToggleSensitive.setVisible(true);
                } else {
                    itemToggleSensitive.setVisible(false);
                }
                if (has_media && isNullOrEmpty(mUploadProvider)) {
                    final Drawable iconToggleSensitive = itemToggleSensitive.getIcon().mutate();
                    if (mIsPossiblySensitive) {
                        moreHighlighted = true;
                        iconToggleSensitive.setColorFilter(activated_color, Mode.MULTIPLY);
                    } else {
                        iconToggleSensitive.clearColorFilter();
                    }
                }
            }
        }
    }
    if (mScheduleDate != null) {
        final MenuItem itemSchedule = menu.findItem(R.id.schedule_tweet);
        final Drawable iconSchedule = itemSchedule.getIcon().mutate();
        iconSchedule.setColorFilter(activated_color, Mode.MULTIPLY);
        moreHighlighted = true;
        itemSchedule.setTitle(getString(R.string.schedule_clear));
    } else {
        final MenuItem itemSchedule = menu.findItem(R.id.schedule_tweet);
        final Drawable iconSchedule = itemSchedule.getIcon().mutate();
        iconSchedule.clearColorFilter();
        itemSchedule.setTitle(getString(R.string.schedule_tweet));
    }

    final String consumer_key = mPreferences.getString(PREFERENCE_KEY_CONSUMER_KEY, null);
    final String consumer_secret = mPreferences.getString(PREFERENCE_KEY_CONSUMER_SECRET, null);

    if (!isNullOrEmpty(consumer_key) && !isNullOrEmpty(consumer_secret)) {
        final MenuItem itemSchedule = menu.findItem(R.id.schedule_tweet);

        itemSchedule.setVisible(false);
    }

    final MenuItem bufferItem = menu.findItem(MENU_ADD_TO_BUFFER);
    if (bufferItem != null) {
        final String buffer_authorised = mPreferences.getString(PREFERENCE_KEY_BUFFERAPP_ACCESS_TOKEN, null);
        final Drawable iconBuffer = bufferItem.getIcon().mutate();
        if (buffer_authorised != null && !buffer_authorised.equals("")) {
            bufferItem.setVisible(true);
            if (mIsBuffer) {
                iconBuffer.setColorFilter(activated_color, Mode.MULTIPLY);
                moreHighlighted = true;
            } else {
                iconBuffer.clearColorFilter();
            }
        } else {
            bufferItem.setVisible(false);
            mIsBuffer = false;
        }
    }
    if (itemMore != null) {
        final Drawable iconMore = itemMore.getIcon().mutate();
        if (moreHighlighted == true) {
            iconMore.setColorFilter(activated_color, Mode.MULTIPLY);
        } else {
            iconMore.clearColorFilter();
        }
    }
    mMenuBar.invalidate();
    invalidateSupportOptionsMenu();
}

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

private void updateMenuOperations() {
    Menu menu = mActionBar.getMenu();

    // it could be null if onCreateActionBar has not been called yet
    if (menu == null)
        return;//from www. jav a2 s  . c om

    MenuItem item = menu.findItem(R.id.action_slideshow);
    if (item != null) {
        item.setVisible((mSecureAlbum == null) && canDoSlideShow());
    }
    if (mCurrentPhoto == null)
        return;

    int supportedOperations = mCurrentPhoto.getSupportedOperations();
    if (mReadOnlyView) {
        /// M: [BUG.MODIFY] @{
        /*supportedOperations ^= MediaObject.SUPPORT_EDIT;*/
        // when mReadOnlyView == true, set SUPPORT_EDIT as false
        supportedOperations &= ~MediaObject.SUPPORT_EDIT;
        /// @}
    }
    if (mSecureAlbum != null) {
        supportedOperations &= MediaObject.SUPPORT_DELETE;
    } else {
        mCurrentPhoto.getPanoramaSupport(mUpdatePanoramaMenuItemsCallback);
        if (!mHaveImageEditor) {
            supportedOperations &= ~MediaObject.SUPPORT_EDIT;
        }
    }
    /// M: [FEATURE.ADD] @{
    if (MediaObject.MEDIA_TYPE_IMAGE == mCurrentPhoto.getMediaType()) {
        if (true == FeatureConfig.SUPPORT_PQ) {
            supportedOperations |= MediaObject.SUPPORT_PQ;
        }
        if (true == FeatureConfig.SUPPORT_IMAGE_DC_ENHANCE) {
            supportedOperations |= MediaObject.SUPPORT_DC;
            MenuItem dcItem = menu.findItem(R.id.m_action_image_dc);
            ImageDC.setMenuItemTile(dcItem);
        }
    }
    /// @}
    /// M: [BUG.ADD] KK native judge mime type, no need AP judge @{
    if (mCurrentPhoto.getMimeType() == null) {
        supportedOperations &= ~MediaObject.SUPPORT_TRIM;
    }
    /// @}
    /// M: [BUG.ADD] @{
    // reget print system operation
    PrintHelper printHelper = new PrintHelper(mActivity.getAndroidContext());
    if (!printHelper.systemSupportsPrint()) {
        supportedOperations &= ~MediaObject.SUPPORT_PRINT;
    }
    /// @}
    /// M: [BUG.ADD] can not set as wallpaper when no thumbnail @{
    mSupportedOperations = supportedOperations;
    /// @}
    MenuExecutor.updateMenuOperation(menu, supportedOperations);

    /// M: [FEATURE.ADD] HotKnot @{
    boolean canShareByHotKnot = (supportedOperations & MediaObject.SUPPORT_SHARE) != 0;
    mActivity.getHotKnot().updateMenu(menu, R.id.action_share, R.id.action_hotknot, canShareByHotKnot);
    /// @}
    /// M: [BUG.ADD] supported operations is zero(camera preview), close menu @{
    if (supportedOperations == 0) {
        menu.close();
    }
    /// @}
}

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

public static void setMenuItemAvailability(final Menu menu, final int id, final boolean available) {
    if (menu == null)
        return;// w ww  .  j av  a 2s  .c om
    final MenuItem item = menu.findItem(id);
    if (item == null)
        return;
    item.setVisible(available);
    item.setEnabled(available);
}