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.cypress.cysmart.CommonFragments.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();/*from   w  w w .j a  va2 s .  co m*/
    inflater.inflate(R.menu.global, menu);
    MenuItem item = menu.findItem(R.id.graph);
    MenuItem log = menu.findItem(R.id.log);
    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    item.setVisible(false);
    log.setVisible(true);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconifiedByDefault(false);
    SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered

            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (searchMenuItem != null) {
                searchMenuItem.collapseActionView();
                // this is your adapter that will be filtered
                if (mLeDeviceListAdapter != null) {
                    searchEnabled = true;
                    searchDeviceList(query);
                }
            }
            return false;

        }
    };
    searchView.setOnQueryTextListener(textChangeListener);
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean queryTextFocused) {
            if (!queryTextFocused) {
                searchMenuItem.collapseActionView();
                searchView.setQuery("", false);
            }
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.aimfire.main.MainActivity.java

/**
 * Override Activity lifecycle method.//from  w  ww .j av a2 s . c o m
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem loginItem = menu.findItem(R.id.action_switch_account);
    loginItem.setVisible(Consts.IS_AUTH_ENABLED);

    return true;
}

From source file:org.andstatus.app.account.AccountSettingsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item = menu.findItem(R.id.remove_account_menu_id);
    item.setEnabled(state.builder.isPersistent());
    item.setVisible(state.builder.isPersistent());

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem notificationItem = menu.findItem(R.id.manage_notification);
    if (notificationItem != null) {
        if (mCurrentChatBoxManager.getCurrentChatBox() == null
                || mCurrentChatBoxManager.getCurrentChatBox().getNotificationStatus() == null
                || mUserManager.getCurrentUser() == null) {
            notificationItem.setVisible(false);
        } else {//from   w ww  . j  av  a2  s .co m
            notificationItem.setVisible(true);
        }
    }

    MenuItem shareChatBoxItem = menu.findItem(R.id.share_chat_box);
    MenuItem copyAliasItem = menu.findItem(R.id.copy_alias);
    MenuItem manageBlackListItem = menu.findItem(R.id.manage_blacklist);
    MenuItem bookmarkChatBoxItem = menu.findItem(R.id.bookmark_chat_box);
    MenuItem onlineUsersItem = menu.findItem(R.id.online_users);

    // Invalidate all menu related objects
    onlineUsersItem.setVisible(false);
    mOnlineUsersBadgeView.hide();
    shareChatBoxItem.setVisible(false);
    copyAliasItem.setVisible(false);
    manageBlackListItem.setVisible(false);
    bookmarkChatBoxItem.setVisible(false);
    mediaAddItem.setVisible(false);

    // Now config them
    if (mCurrentChatBoxManager.getCurrentChatBox() != null) {
        // When main view or online users drawer is opened
        // and current chat box is available.
        onlineUsersItem.setVisible(true);
        shareChatBoxItem.setVisible(true && Constants.ALLOW_SHARE_CHATBOX);
        if (mNumOfOnlineUser > 0) {
            mOnlineUsersBadgeView.setText(Integer.toString(mNumOfOnlineUser));
            mOnlineUsersBadgeView.show();
        }

        // Config share intent for share chat box item
        AppCompatActivity activity = mActivityDelegate.getActivity();
        ChatBox chatBox = mCurrentChatBoxManager.getCurrentChatBox();
        String shareText = mApiManager.getChatBoxUrl(chatBox.getKey());
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.message_share_chat_box_subject));
        intent.putExtra(Intent.EXTRA_TEXT, shareText);
        ShareActionProvider shareChatBoxActionProvider = (ShareActionProvider) MenuItemCompat
                .getActionProvider(shareChatBoxItem);
        shareChatBoxActionProvider.setShareIntent(intent);

        if (mBuildManager.isOfficialChatWingApp() && mUserManager.userCanBookmark() && !ChatWingContentProvider
                .hasSyncedBookmarkInDB(activity.getContentResolver(), chatBox.getId())) {
            bookmarkChatBoxItem.setVisible(true);
        }

        if (mBuildManager.isSupportedMusicBox()) {
            mediaAddItem.setVisible(true);
        }

        if (chatBox.getAlias() != null && Constants.ALLOW_SHARE_CHATBOX) {
            copyAliasItem.setVisible(true);
        }
        if (mUserManager.userHasPermission(chatBox, PermissionsValidator.Permission.UNBLOCK_USER)) {
            manageBlackListItem.setVisible(true);
        }

        updateControlUI(chatBox);
    }

    return true;
}

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem savePlaylist = menu.findItem(R.id.menu_save_playlist);
    boolean savePlaylistEnabled = !Util.isOffline(this);
    savePlaylist.setEnabled(savePlaylistEnabled);
    savePlaylist.setVisible(savePlaylistEnabled);
    MenuItem screenOption = menu.findItem(R.id.menu_screen_on_off);
    if (getDownloadService().getKeepScreenOn()) {
        screenOption.setTitle(R.string.download_menu_screen_off);
    } else {//from  ww  w .  jav a 2  s. c  om
        screenOption.setTitle(R.string.download_menu_screen_on);
    }
    MenuItem searchOption = menu.findItem(R.id.menu_search);
    searchOption.setVisible(!Util.isOffline(this));

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.veniosg.dir.android.fragment.SimpleFileListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (getActivity() == null) {
        return;/*w ww  .  j a v  a 2s .c  o  m*/
    }

    boolean showMediaScanMenuItem = getMediaScanFromPreference(getActivity());
    if (hasScanner() && !isScannerRunning() && showMediaScanMenuItem) {
        // We only know about ".nomedia" once scanning is finished.
        boolean noMedia = isMediaScannerDisabledForPath();
        menu.findItem(R.id.menu_media_scan_include).setVisible(noMedia);
        menu.findItem(R.id.menu_media_scan_exclude).setVisible(!noMedia);
    } else {
        menu.findItem(R.id.menu_media_scan_include).setVisible(false);
        menu.findItem(R.id.menu_media_scan_exclude).setVisible(false);
    }

    CopyHelper copyHelper = ((FileManagerApplication) getActivity().getApplication()).getCopyHelper();
    MenuItem pasteAction = menu.findItem(R.id.menu_paste);
    if (copyHelper.canPaste()) {
        int stringResource = (copyHelper.getOperationType() == COPY ? R.plurals.menu_copy_items_to
                : R.plurals.menu_move_items_to);
        pasteAction.setTitle(getResources().getQuantityString(stringResource, copyHelper.getItemCount(),
                copyHelper.getItemCount()));

        pasteAction.getIcon().setLevel(copyHelper.getItemCount());
        pasteAction.setVisible(true);
        menu.findItem(R.id.menu_clear_clipboard).setVisible(true);
    } else {
        pasteAction.setVisible(false);
        menu.findItem(R.id.menu_clear_clipboard).setVisible(false);
    }
}

From source file:com.wanikani.androidnotifier.WebReviewActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem mi;
    int i;/*from   ww  w. jav a2s  .  co m*/

    for (i = 0; i < menu.size(); i++) {
        mi = menu.getItem(i);
        if (mi.getItemId() == R.id.em_fonts) {
            mi.setVisible(keyboard.canOverrideFonts());
            mi.setIcon(keyboard.getOverrideFonts() ? R.drawable.ic_menu_font_enabled : R.drawable.ic_menu_font);
        }
    }

    return true;
}

From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mRelationship;
    if (twitter == null || user == null)
        return;/*from w  ww  . jav  a  2 s. c o m*/
    final int activatedColor = ThemeUtils.getUserThemeColor(getActivity());
    final boolean isMyself = user.account_id == user.id;
    final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget();
    final boolean isProtected = user.is_protected;
    final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
    final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
    setMenuItemAvailability(menu, MENU_EDIT, isMyself);
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    followItem.setVisible(!isMyself);
    final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself
            && relationship != null;
    followItem.setEnabled(shouldShowFollowItem);
    if (shouldShowFollowItem) {
        followItem.setTitle(
                isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow);
        followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add);
    } else {
        followItem.setTitle(null);
        followItem.setIcon(null);
    }
    if (user.id != user.account_id && relationship != null) {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget());
        setMenuItemAvailability(menu, MENU_BLOCK, true);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (blockItem != null) {
            final Drawable blockIcon = blockItem.getIcon();
            if (relationship.isSourceBlockingTarget()) {
                blockItem.setTitle(R.string.unblock);
                blockIcon.mutate();
                blockIcon.setColorFilter(activatedColor, PorterDuff.Mode.SRC_ATOP);
            } else {
                blockItem.setTitle(R.string.block);
                blockIcon.clearColorFilter();
            }
        }
    } else {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

void prepareNowPlayingMenu(final Menu menu) {
    final boolean isStreaming = mApp.isStreamActive();
    final MPD mpd = mApp.oMPDAsyncHelper.oMPD;
    final MPDStatus mpdStatus = mpd.getStatus();

    // Reminder : never disable buttons that are shown as actionbar actions here
    if (mpd.isConnected()) {
        if (menu.findItem(CONNECT) != null) {
            menu.removeItem(CONNECT);//  ww w .ja  v a  2 s. c  o m
        }
    } else {
        if (menu.findItem(CONNECT) == null) {
            menu.add(0, CONNECT, 0, R.string.connect);
        }
    }

    final MenuItem saveItem = menu.findItem(R.id.PLM_Save);
    final MenuItem clearItem = menu.findItem(R.id.PLM_Clear);
    if (!mIsDualPaneMode && mNowPlayingPager != null && mNowPlayingPager.getCurrentItem() == 0) {
        saveItem.setVisible(false);
        clearItem.setVisible(false);
    } else {
        saveItem.setVisible(true);
        clearItem.setVisible(true);
    }

    /** If in streamingMode or persistentNotification don't allow a checkbox in the menu. */
    final MenuItem notificationItem = menu.findItem(R.id.GMM_ShowNotification);
    if (notificationItem != null) {
        if (isStreaming || mApp.isNotificationPersistent()) {
            notificationItem.setVisible(false);
        } else {
            notificationItem.setVisible(true);
        }

        setMenuChecked(notificationItem, mApp.isNotificationActive());
    }

    setMenuChecked(menu.findItem(R.id.GMM_Stream), isStreaming);
    setMenuChecked(menu.findItem(R.id.GMM_Single), mpdStatus.isSingle());
    setMenuChecked(menu.findItem(R.id.GMM_Consume), mpdStatus.isConsume());
}

From source file:com.cerema.cloud2.ui.fragment.OCFileListFragment.java

/**
 * {@inheritDoc}/*from  w  w  w.  j  av a2  s  . c  o m*/
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    Bundle args = getArguments();
    boolean allowContextualActions = (args == null) ? true
            : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
    if (allowContextualActions) {
        MenuInflater inflater = getActivity().getMenuInflater();
        inflater.inflate(R.menu.file_actions_menu, menu);
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        OCFile targetFile = (OCFile) mAdapter.getItem(info.position);

        if (mContainerActivity.getStorageManager() != null) {
            FileMenuFilter mf = new FileMenuFilter(targetFile,
                    mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity());
            mf.filter(menu);
        }

        /// TODO break this direct dependency on FileDisplayActivity... if possible
        MenuItem item = menu.findItem(R.id.action_open_file_with);
        FileFragment frag = ((FileDisplayActivity) getActivity()).getSecondFragment();
        if (frag != null && frag instanceof FileDetailFragment
                && frag.getFile().getFileId() == targetFile.getFileId()) {
            item = menu.findItem(R.id.action_see_details);
            if (item != null) {
                item.setVisible(false);
                item.setEnabled(false);
            }
        }

        //            String.format(mContext.getString(R.string.subject_token),
        //                    getClient().getCredentials().getUsername(), file.getFileName()));

    }
}