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.thelastcrusade.soundstream.CoreActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    getMenuInflater().inflate(R.menu.search_menu, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) searchItem.getActionView();

    if (searchView != null) {
        searchView.setSearchableInfo(/*from  ww  w.  ja va2s.  co m*/
                searchManager.getSearchableInfo(new ComponentName(this, SearchActivity.class)));
        searchView.setIconified(true);
        searchView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setFocusable(true);
                v.requestFocusFromTouch();
            }
        });

        if (isConnectActive()) {
            searchItem.setVisible(false);
        }
    }
    return true;
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    //force show add transaction
    MenuItem itemAddTransaction = menu.findItem(R.id.menu_add_transaction_account);
    if (itemAddTransaction != null)
        itemAddTransaction.setVisible(true);
    //manage dual panel
    if (getActivity() != null && getActivity() instanceof MainActivity) {
        MainActivity activity = (MainActivity) getActivity();
        if (!activity.isDualPanel()) {
            //hide sync toolbar
            MenuItem itemSync = menu.findItem(R.id.menu_sync);
            if (itemSync != null)
                itemSync.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

            // hide menu open database
            MenuItem itemOpenDatabase = menu.findItem(R.id.menu_open_database);
            if (itemOpenDatabase != null) {
                //itemOpenDatabase.setVisible(isShownOpenDatabaseItemMenu());
                itemOpenDatabase.setShowAsAction(
                        !itemSync.isVisible() ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER);
            }//from  www  . ja v a  2 s. c  om

            //hide dash board
            MenuItem itemDashboard = menu.findItem(R.id.menu_dashboard);
            if (itemDashboard != null)
                itemDashboard.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
    }

    selectCurrentPeriod(menu);
    selectCurrentStatus(menu);
}

From source file:de.dreier.mytargets.features.training.input.InputActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem eye = menu.findItem(R.id.action_show);
    final MenuItem keyboard = menu.findItem(R.id.action_keyboard);
    final MenuItem grouping = menu.findItem(R.id.action_grouping);
    final MenuItem timer = menu.findItem(R.id.action_timer);
    final MenuItem newRound = menu.findItem(R.id.action_new_round);
    if (targetView == null || data.getEnds().size() == 0) {
        eye.setVisible(false);
        keyboard.setVisible(false);/* w ww  .  j  a  va  2  s .com*/
        grouping.setVisible(false);
        timer.setVisible(false);
        newRound.setVisible(false);
    } else {
        final boolean plotting = targetView.getInputMode() == EInputMethod.PLOTTING;
        eye.setVisible(plotting);
        grouping.setVisible(plotting);
        keyboard.setIcon(plotting ? R.drawable.ic_keyboard_white_24dp : R.drawable.ic_keyboard_white_off_24dp);
        keyboard.setChecked(!plotting);
        keyboard.setVisible(data.getCurrentEnd().getId() == null);
        timer.setIcon(SettingsManager.getTimerEnabled() ? R.drawable.ic_timer_off_white_24dp
                : R.drawable.ic_timer_white_24dp);
        timer.setVisible(true);
        timer.setChecked(SettingsManager.getTimerEnabled());
        newRound.setVisible(data.training.standardRoundId == null);
    }

    switch (SettingsManager.getShowMode()) {
    case END:
        menu.findItem(R.id.action_show_end).setChecked(true);
        break;
    case ROUND:
        menu.findItem(R.id.action_show_round).setChecked(true);
        break;
    case TRAINING:
        menu.findItem(R.id.action_show_training).setChecked(true);
        break;
    default:
        // Never called: All enum values are checked
        break;
    }
    switch (SettingsManager.getAggregationStrategy()) {
    case NONE:
        menu.findItem(R.id.action_grouping_none).setChecked(true);
        break;
    case AVERAGE:
        menu.findItem(R.id.action_grouping_average).setChecked(true);
        break;
    case CLUSTER:
        menu.findItem(R.id.action_grouping_cluster).setChecked(true);
        break;
    default:
        // Never called: All enum values are checked
        break;
    }
    return true;
}

From source file:org.geometerplus.android.fbreader.FBReader.java

@Override
public void refresh() {
    runOnUiThread(new Runnable() {
        public void run() {
            for (Map.Entry<MenuItem, String> entry : myMenuItemMap.entrySet()) {
                final String actionId = entry.getValue();
                final MenuItem menuItem = entry.getKey();
                menuItem.setVisible(
                        myFBReaderApp.isActionVisible(actionId) && myFBReaderApp.isActionEnabled(actionId));
                switch (myFBReaderApp.isActionChecked(actionId)) {
                case B3_TRUE:
                    menuItem.setCheckable(true);
                    menuItem.setChecked(true);
                    break;
                case B3_FALSE:
                    menuItem.setCheckable(true);
                    menuItem.setChecked(false);
                    break;
                case B3_UNDEFINED:
                    menuItem.setCheckable(false);
                    break;
                }//from   w  w w.ja  v a 2 s . c  o m
            }
        }
    });
}

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

public final boolean onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);

    final String customChatForum = this.application.getSession().getServer().chatForum;
    final String customChatThread = this.application.getSession().getServer().chatThread;

    final MenuItem newMailItem = menu.findItem(R.id.main_menu_new_mail);
    newMailItem.setVisible(false);

    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    if (this.serverUserid == null || !getString(R.string.subforum_id).contentEquals("0")) {
        searchMenuItem.setVisible(false);
    }/*from   w  ww.j a v a 2s  . c o  m*/

    final MenuItem itemLogin = menu.findItem(R.id.main_menu_open_login);
    final MenuItem itemChat = menu.findItem(R.id.main_menu_open_chat);

    if (this.serverUserid == null) {
        itemLogin.setVisible(true);
        itemChat.setVisible(false);
    } else {
        itemLogin.setVisible(false);

        if ((!getString(R.string.chat_thread).contentEquals("0"))
                || (!customChatForum.contentEquals("0") && !customChatThread.contentEquals("0"))) {
            itemChat.setVisible(true);
        }
    }

    if (this.seperator != null) {
        itemLogin.setVisible(false);
        itemChat.setVisible(false);
    }

    if (ThemeSetter.getForegroundDark(this.background)) {
        itemLogin.setIcon(R.drawable.ic_action_accounts_dark);
        itemChat.setIcon(R.drawable.ic_action_group_dark);
        newMailItem.setIcon(R.drawable.ic_action_email_dark);
    }
    return true;
}

From source file:net.reichholf.dreamdroid.fragment.MediaPlayerFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (getMultiPaneHandler().isDrawerOpen())
        return;/* w  w w  .ja  v  a2  s.co m*/
    if (mMedia != null) {
        String rootPath = (String) mMedia.get(Mediaplayer.KEY_ROOT);
        MenuItem homeMenuItem = menu.findItem(Statics.ITEM_MEDIA_HOME);
        MenuItem backMenuItem = menu.findItem(Statics.ITEM_MEDIA_BACK);

        boolean isPaneOpen = true;
        SlidingPaneLayout spl = getSlidingPaneLayout();
        if (spl != null)
            isPaneOpen = spl.isOpen();

        if (!isPaneOpen || rootPath.equals("None")) {
            homeMenuItem.setVisible(false);
            backMenuItem.setVisible(false);
        } else {
            homeMenuItem.setVisible(true);
            backMenuItem.setVisible(true);
        }
    }
}

From source file:com.svpino.longhorn.fragments.StockListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem shareMenuItem = menu.findItem(R.id.menu_item_share);
    shareMenuItem.setVisible(isOverviewVisible());

    super.onPrepareOptionsMenu(menu);
}

From source file:com.gmail.boiledorange73.ut.map.MapActivityBase.java

private void activateMenuItemIfExists(Menu menu, int id) {
    MenuItem item = menu.findItem(id);
    if (item != null) {
        item.setVisible(true);
    }/*ww  w  . ja  v  a 2  s .  c  o  m*/
}

From source file:com.benlinskey.greekreference.MainActivity.java

/**
 * Sets the Lexicon Favorite icon to the appropriate state based on the currently selected
 * lexicon entry./*  ww  w .j a v a 2 s.  c o  m*/
 * @param menu the {@code Menu} containing the Favorite icon
 */
private void setLexiconFavoriteIcon(Menu menu) {
    LexiconListFragment fragment = (LexiconListFragment) getFragmentManager()
            .findFragmentById(R.id.item_list_container);

    MenuItem addFavorite = menu.findItem(R.id.action_add_favorite);
    MenuItem removeFavorite = menu.findItem(R.id.action_remove_favorite);

    if (fragment.nothingIsSelected() || !mTwoPane) {
        addFavorite.setVisible(false);
        removeFavorite.setVisible(false);
    } else if (fragment.selectedWordIsFavorite()) {
        addFavorite.setVisible(false);
        removeFavorite.setVisible(true);
    } else {
        addFavorite.setVisible(true);
        removeFavorite.setVisible(false);
    }
}

From source file:com.benlinskey.greekreference.MainActivity.java

/**
 * Sets the Syntax Bookmark icon to the appropriate state based on the currently selected
 * syntax section.// w w w . j av  a2  s  .co  m
 * @param menu the {@code Menu} containing the Bookmark icon
 */
private void setSyntaxBookmarkIcon(Menu menu) {
    SyntaxListFragment fragment = (SyntaxListFragment) getFragmentManager()
            .findFragmentById(R.id.item_list_container);

    MenuItem addBookmark = menu.findItem(R.id.action_add_bookmark);
    MenuItem removeBookmark = menu.findItem(R.id.action_remove_bookmark);

    if (fragment.nothingIsSelected() || !mTwoPane) {
        addBookmark.setVisible(false);
        removeBookmark.setVisible(false);
    } else if (fragment.selectedSectionIsBookmarked()) {
        addBookmark.setVisible(false);
        removeBookmark.setVisible(true);
    } else {
        addBookmark.setVisible(true);
        removeBookmark.setVisible(false);
    }
}