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:org.getlantern.firetweet.fragment.CustomTabsFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    final Resources res = getResources();
    final boolean hasOfficialKeyAccounts = Utils.hasAccountSignedWithOfficialKeys(getActivity());
    final boolean forcePrivateAPI = mPreferences.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false);
    final long[] accountIds = getAccountIds(getActivity());
    final MenuItem itemAdd = menu.findItem(R.id.add_submenu);
    if (itemAdd != null && itemAdd.hasSubMenu()) {
        final SubMenu subMenu = itemAdd.getSubMenu();
        subMenu.clear();/*from  w  ww  . j a va 2 s.  c om*/
        final HashMap<String, CustomTabConfiguration> map = getConfiguraionMap();
        final List<Entry<String, CustomTabConfiguration>> tabs = new ArrayList<>(map.entrySet());
        Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON);
        for (final Entry<String, CustomTabConfiguration> entry : tabs) {
            final String type = entry.getKey();
            final CustomTabConfiguration conf = entry.getValue();

            final boolean isOfficiakKeyAccountRequired = TAB_TYPE_ACTIVITIES_ABOUT_ME.equals(type)
                    || TAB_TYPE_ACTIVITIES_BY_FRIENDS.equals(type);
            final boolean accountIdRequired = conf
                    .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;

            final Intent intent = new Intent(INTENT_ACTION_ADD_TAB);
            intent.setClass(getActivity(), CustomTabEditorActivity.class);
            intent.putExtra(EXTRA_TYPE, type);
            intent.putExtra(EXTRA_OFFICIAL_KEY_ONLY, isOfficiakKeyAccountRequired);

            final MenuItem subItem = subMenu.add(conf.getDefaultTitle());
            final boolean disabledByNoAccount = accountIdRequired && accountIds.length == 0;
            final boolean disabledByNoOfficialKey = !forcePrivateAPI && isOfficiakKeyAccountRequired
                    && !hasOfficialKeyAccounts;
            final boolean disabledByDuplicateTab = conf.isSingleTab() && isTabAdded(getActivity(), type);
            final boolean shouldDisable = disabledByDuplicateTab || disabledByNoOfficialKey
                    || disabledByNoAccount;
            subItem.setVisible(!shouldDisable);
            subItem.setEnabled(!shouldDisable);
            final Drawable icon = ResourcesCompat.getDrawable(res, conf.getDefaultIcon(), null);
            subItem.setIcon(icon);
            subItem.setIntent(intent);
        }
    }
    ThemeUtils.applyColorFilterToMenuIcon(getActivity(), menu);
}

From source file:com.doplgangr.secrecy.views.FilesListFragment.java

void select(int position) {
    mAdapter.select(position);// w w w  .  jav  a2  s.  co m
    mAdapter.notifyItemChanged(position);

    if (mActionMode == null)
        return;

    mActionMode
            .setTitle(String.format(getString(R.string.Files__number_selected), mAdapter.getSelected().size()));
    MenuItem renameButton = mActionMode.getMenu().findItem(R.id.action_rename);

    if (mAdapter.getSelected().size() == 1)
        renameButton.setVisible(true);
    else
        renameButton.setVisible(false);

    if (mAdapter.getSelected().size() == 0)
        mActionMode.finish();
}

From source file:com.boko.vimusic.ui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}// w w  w  . j ava  2  s  .  c o  m
 */
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    // Hide the EQ option if it can't be opened
    final Intent intent = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
    if (getPackageManager().resolveActivity(intent, 0) == null) {
        final MenuItem effects = menu.findItem(R.id.menu_audio_player_equalizer);
        effects.setVisible(false);
    }
    mResources.setFavoriteIcon(menu);
    return true;
}

From source file:com.sj.android.appusage.activities.UsageListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    MenuItem filterMenu = (MenuItem) menu.findItem(R.id.filter_menu);
    if (UsageSharedPrefernceHelper.isFilterMode(mActivity)) {
        filterMenu.setIcon(R.drawable.ic_select_all_white_24dp);
        filterMenu.setTitle(R.string.string_all);
    } else {/*from w  w w.  j a va 2  s  .c om*/
        filterMenu.setIcon(R.drawable.ic_filter_list_white_24dp);
        filterMenu.setTitle(R.string.string_filter);
    }

    MenuItem menuItemSortBy = menu.findItem(R.id.action_sort_by);
    MenuItem menuItemFilter = (MenuItem) menu.findItem(R.id.filter_menu);

    if (mViewPager != null) {
        switch (mViewPager.getCurrentItem()) {
        case 0:
            if (mAppDataListAdapter != null && !mAppDataListAdapter.isEmpty()) {
                menuItemFilter.setVisible(true);
            }
            break;
        case 1:
            menuItemSortBy.setVisible(false);
            menuItemFilter.setVisible(false);
            break;
        default:
            break;
        }
    }

    super.onPrepareOptionsMenu(menu);
}

From source file:com.sabaibrowser.UI.java

public void updateMenuState(Tab tab, Menu menu) {
    MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
    if (bm != null) {
        bm.setVisible(!showingNavScreen());
    }/*from w ww  .j  a v  a 2s .  c  o  m*/
    MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id);
    if (abm != null) {
        abm.setVisible((tab != null) && !tab.isSnapshot() && !showingNavScreen());
    }
    MenuItem info = menu.findItem(R.id.page_info_menu_id);
    if (info != null) {
        info.setVisible(false);
    }
    MenuItem newTab = menu.findItem(R.id.new_tab_menu_id);
    if (newTab != null) {
        newTab.setVisible(false);
    }
    MenuItem newIncognitoTab = menu.findItem(R.id.new_incognito_tab_menu_id);
    if (newIncognitoTab != null) {
        newIncognitoTab.setVisible(false);
    }
    MenuItem closeOthers = menu.findItem(R.id.close_other_tabs_id);
    if (closeOthers != null) {
        boolean isLastTab = true;
        if (tab != null) {
            isLastTab = (mTabControl.getTabCount() <= 1);
        }
        closeOthers.setEnabled(!isLastTab);
    }
    if (showingNavScreen()) {
        menu.setGroupVisible(R.id.LIVE_MENU, false);
        menu.setGroupVisible(R.id.SNAPSHOT_MENU, false);
        menu.setGroupVisible(R.id.NAV_MENU, false);
        menu.setGroupVisible(R.id.COMBO_MENU, true);
    }
}

From source file:de.enlightened.peris.PostsFragment.java

@SuppressLint("NewApi")
@Override//w  w w  . j  av  a2 s.  c om
public final void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.post_n_page, menu);

    final MenuItem itemRefresh = menu.findItem(R.id.menu_refresh);
    final MenuItem itemNew = menu.findItem(R.id.menu_newpost);

    if (ThemeSetter.getForegroundDark(this.background)) {
        itemRefresh.setIcon(R.drawable.ic_action_refresh_dark);
        itemNew.setIcon(R.drawable.ic_action_new_dark);
    }

    if (this.totalPages == null) {
        this.totalPages = 0;
    }

    final MenuItem browserItem = menu.findItem(R.id.posts_menu_browser);
    final MenuItem shareItem = menu.findItem(R.id.posts_menu_share);

    if (this.shareURL != null) {
        browserItem.setVisible(false);
        shareItem.setVisible(false);
    } else {
        browserItem.setVisible(true);
        shareItem.setVisible(true);
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:no.digipost.android.gui.content.ThreadPerTaskExecutor.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem delete = menu.findItem(R.id.pdfmenu_delete);
    MenuItem move = menu.findItem(R.id.pdfmenu_move);
    MenuItem openExternal = menu.findItem(R.id.pdfmenu_open_external);
    MenuItem save = menu.findItem(R.id.pdfmenu_save);
    sendToBank = menu.findItem(R.id.pdfmenu_send_to_bank);

    String openFilepath = intent.getStringExtra(ACTION_OPEN_FILEPATH);

    if (openFilepath != null) {
        delete.setVisible(false);
        move.setVisible(false);/* w  w w .j  a  va2s . c o  m*/
        openExternal.setVisible(false);
        save.setVisible(false);
    }

    boolean sendToBankVisible = intent.getBooleanExtra(ContentFragment.INTENT_SEND_TO_BANK, false);

    if (ApplicationConstants.FEATURE_SEND_TO_BANK_VISIBLE) {
        super.setSendToBankMenuText(sendToBankVisible);
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.nttec.everychan.ui.BoardsListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
    case R.id.menu_update:
        update(true);//  w w  w  .  ja va2 s. c  om
        return true;
    case R.id.menu_quickaccess_add:
        QuickAccess.Entry newEntry = new QuickAccess.Entry();
        newEntry.chan = chan;
        quickAccessList.add(0, newEntry);
        QuickAccess.saveQuickAccessToPreferences(quickAccessList);
        item.setVisible(false);
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:com.mobicage.rogerthat.plugins.messaging.MessagingActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        switch (item.getItemId()) {
        case R.id.select_all:
        case R.id.deselect_all:
            item.setVisible(mEditing);
            break;
        case R.id.delete_messages:
            item.setEnabled(((CursorAdapter) getListAdapter()).getCursor().getCount() > 0);
            //$FALL-THROUGH$
        default://  w  ww .  j  a  v a2  s.  co m
            item.setVisible(!mEditing);
            break;
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:co.carlosandresjimenez.android.gotit.BaseActivity.java

public void reviewDrawerConfiguration() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);

    if (navigationView != null && navigationView.getMenu() != null) {
        String userType = Utility.getUserType(this);

        MenuItem menuItemCheckin = navigationView.getMenu().findItem(R.id.navigation_item_checkin);
        MenuItem menuItemGraph = navigationView.getMenu().findItem(R.id.navigation_item_graph);

        if (userType.equals(getString(R.string.user_type_follower))) {
            menuItemCheckin.setVisible(false);
            menuItemGraph.setVisible(false);
        } else {/*  ww  w  .  j  a  v a  2  s .  c o  m*/
            menuItemCheckin.setVisible(true);
            menuItemGraph.setVisible(true);
        }

        setDrawerItemChecked(navigationView);
    }
}