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.vuze.android.remote.fragment.TorrentListFragment.java

protected void prepareContextMenu(Menu menu) {
    boolean isLocalHost = sessionInfo != null && sessionInfo.getRemoteProfile().isLocalHost();
    boolean isOnlineOrLocal = VuzeRemoteApp.getNetworkState().isOnline() || isLocalHost;

    MenuItem menuMove = menu.findItem(R.id.action_sel_move);
    if (menuMove != null) {
        boolean enabled = isOnlineOrLocal && (torrentListAdapter.getCheckedItemCount() > 0
                || torrentListAdapter.getSelectedPosition() >= 0);
        menuMove.setEnabled(enabled);/*www.jav  a2 s.c  o m*/
    }

    Map<?, ?>[] checkedTorrentMaps = getCheckedTorrentMaps(torrentListAdapter);
    boolean canStart = false;
    boolean canStop = false;
    if (isOnlineOrLocal) {
        for (Map<?, ?> mapTorrent : checkedTorrentMaps) {
            int status = MapUtils.getMapInt(mapTorrent, TransmissionVars.FIELD_TORRENT_STATUS,
                    TransmissionVars.TR_STATUS_STOPPED);
            canStart |= status == TransmissionVars.TR_STATUS_STOPPED;
            canStop |= status != TransmissionVars.TR_STATUS_STOPPED;
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "prepareContextMenu: " + canStart + "/" + canStop + "/" + status);
            }
        }
    }
    if (AndroidUtils.DEBUG_MENU) {
        Log.d(TAG, "prepareContextMenu: " + canStart + "/" + canStop);
    }

    MenuItem menuStart = menu.findItem(R.id.action_sel_start);
    if (menuStart != null) {
        menuStart.setVisible(canStart);
        menuStart.setEnabled(canStart);
    } else {
        Log.d(TAG, "prepareContextMenu: No Start Menu!");
    }

    MenuItem menuStop = menu.findItem(R.id.action_sel_stop);
    if (menuStop != null) {
        menuStop.setVisible(canStop);
        menuStop.setEnabled(canStop);
    }

    AndroidUtilsUI.setManyMenuItemsEnabled(isOnlineOrLocal, menu, new int[] { R.id.action_sel_remove,
            R.id.action_sel_forcestart, R.id.action_sel_move, R.id.action_sel_relocate });
}

From source file:com.fsck.k9.activity.Accounts.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(R.string.accounts_context_menu_title);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    BaseAccount account = mAdapter.getItem(info.position);

    if ((account instanceof Account) && !((Account) account).isEnabled()) {
        getMenuInflater().inflate(R.menu.disabled_accounts_context, menu);
    } else {/* www  .ja v  a 2  s .c  o  m*/
        getMenuInflater().inflate(R.menu.accounts_context, menu);
    }

    if (account instanceof SearchAccount) {
        for (int i = 0; i < menu.size(); i++) {
            android.view.MenuItem item = menu.getItem(i);
            item.setVisible(false);
        }
    } else {
        EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account);
        if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
            menu.findItem(R.id.move_up).setEnabled(false);
        } else {
            menu.findItem(R.id.move_up).setEnabled(true);
        }
        if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) {
            menu.findItem(R.id.move_down).setEnabled(false);
        } else {
            menu.findItem(R.id.move_down).setEnabled(true);
        }
    }
}

From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java

/**
 * update actionbar items; shouldn't be called until after the menu is inflated.
 *//*from w  w  w  .j  a va  2  s .  co  m*/
private void updateActionBar(Context context) {
    if (actionBarMenu != null) {
        MenuItem refreshItem = actionBarMenu.findItem(R.id.action_location_refresh);
        if (refreshItem != null) {
            WidgetSettings.LocationMode mode = WidgetSettings.loadLocationModePref(context, 0);
            if (mode != WidgetSettings.LocationMode.CURRENT_LOCATION) {
                refreshItem.setVisible(false);

            } else {
                refreshItem.setIcon((getFixHelper.isLocationEnabled() ? GetFixUI.ICON_GPS_FOUND
                        : GetFixUI.ICON_GPS_DISABLED));
                refreshItem.setVisible(true);
            }
        }
    }
}

From source file:maimeng.yodian.app.client.android.chat.activity.ChatActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (menu != null) {
        menu.findItem(R.id.menu_chat_clear).setVisible(true);
        MenuItem item = menu.findItem(R.id.menu_chat_clear);
        item.setVisible(false);
    }/*from www.  ja v a2 s . c  o  m*/
    return super.onPrepareOptionsMenu(menu);
}

From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java

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

    final FragmentManager fm = getFragmentManager();

    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();

    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    //final MenuItem createFile = menu.findItem(R.id.menu_create_file);
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem settings = menu.findItem(R.id.menu_settings);

    // Open drawer means we hide most actions
    if (isRootsDrawerOpen()) {
        createDir.setVisible(false);
        //createFile.setVisible(false);
        search.setVisible(false);//from www.  j  ava  2 s. c  o m
        sort.setVisible(false);
        grid.setVisible(false);
        list.setVisible(false);
        mIgnoreNextCollapse = true;
        search.collapseActionView();
        return true;
    }

    sort.setVisible(cwd != null);
    grid.setVisible(mState.derivedMode != MODE_GRID);
    list.setVisible(mState.derivedMode != MODE_LIST);

    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        sort.setVisible(false);

        search.expandActionView();

        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();

        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }

    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);

    final boolean searchVisible;
    if (mState.action == ACTION_CREATE) {
        createDir.setVisible(cwd != null && cwd.isCreateSupported());
        //createFile.setVisible(cwd != null && cwd.isCreateSupported());
        searchVisible = false;

        // No display options in recent directories
        if (cwd == null) {
            grid.setVisible(false);
            list.setVisible(false);
        }
        if (null != SaveFragment.get(fm))
            SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());
    } else if (mState.action == ACTION_GET_CONTENT) {
        createDir.setVisible(false);
        searchVisible = root != null && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0);
    } else {
        createDir.setVisible(cwd != null && cwd.isCreateSupported());
        //createFile.setVisible(cwd != null && cwd.isCreateSupported());
        //createDir.setVisible(false);

        searchVisible = root != null && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0);

        if (null != SaveFragment.get(fm))
            SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());

        if (null != MoveFragment.get(fm))
            MoveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isEditSupported());
    }

    // TODO: close any search in-progress when hiding
    search.setVisible(searchVisible);

    settings.setVisible(mState.action != ACTION_MANAGE);

    return true;
}

From source file:com.retroteam.studio.retrostudio.MeasureEditor.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    // make this a switch instead
    if (id == android.R.id.home) {
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        ///* w  w w  . java  2s.  c o m*/
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        // TODO: If Settings has multiple levels, Up should navigate up
        // that hierarchy.
        Intent i = getIntent(); //gets the intent that called this intent
        i.putExtra("Project", theproject);
        if (hasNotes()) {
            i.putExtra("HasNotes", true);
        } else {
            i.putExtra("HasNotes", false);
        }
        i.putExtra("guiSNAP", guiSNAP);
        i.putExtra("measureNum", measureNum);
        i.putExtra("trackNum", trackNum);
        i.putExtra("measureID", measureID);
        i.putExtra("filledNotes", filledNotes);
        this.setResult(Activity.RESULT_OK, i);
        this.finish();
        //NavUtils.navigateUpFromSameTask(this);
        return true;
    }

    if (id == R.id.action_penciloff) {
        //Toast.makeText(this, "Tell Gabe to implement this!", Toast.LENGTH_SHORT).show();
        togglePencilTool(findViewById(R.id.pencilTool));
        item.setVisible(false);
    }

    if (id == R.id.action_togglefs) {
        toggleHideyBar();
    }

    if (id == R.id.action_octave) {
        octavePrompt();
    }

    if (id == R.id.action_play) {
        new Thread(new Runnable() {
            public void run() {
                ThreadedPlayback audioplayer2 = new ThreadedPlayback(theproject.export(measureNum));
                audioplayer = audioplayer2;
                audioplayer.play();
            }
        }).start();
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.brandroid.openmanager.fragments.ContentFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    Logger.LogVerbose("ContentFragment.onPrepareOptionsMenu");
    if (getActivity() == null)
        return;//w w  w .j ava  2s. co m
    if (menu == null)
        return;
    if (isDetached() || !isVisible())
        return;
    super.onPrepareOptionsMenu(menu);
    if (OpenExplorer.BEFORE_HONEYCOMB)
        MenuUtils.setMenuVisible(menu, false, R.id.menu_view_carousel);

    MenuUtils.setMenuVisible(menu, mPath instanceof OpenNetworkPath, R.id.menu_context_download);
    MenuUtils.setMenuVisible(menu, !(mPath instanceof OpenNetworkPath), R.id.menu_context_edit,
            R.id.menu_context_view);

    MenuUtils.setMenuChecked(menu, getSorting().foldersFirst(), R.id.menu_sort_folders_first);

    if (mPath != null)
        MenuUtils.setMenuEnabled(menu, !mPath.requiresThread() && mPath.canWrite(), R.id.menu_multi_all_copy,
                R.id.menu_multi_all_move);

    SortType.Type st = getSorting().getType();
    int sti = Utils.getArrayIndex(sortTypes, st);
    if (sti > -1)
        MenuUtils.setMenuChecked(menu, true, sortMenuOpts[sti], sortMenuOpts);

    if (getClipboard() == null || getClipboard().size() == 0) {
        MenuUtils.setMenuVisible(menu, false, R.id.content_paste);
    } else {
        MenuItem mPaste = menu.findItem(R.id.content_paste);
        if (mPaste != null && getClipboard() != null && !isDetached())
            mPaste.setTitle(getString(R.string.s_menu_paste) + " (" + getClipboard().size() + ")");
        if (getClipboard().isMultiselect()) {
            LayerDrawable d = (LayerDrawable) getResources().getDrawable(R.drawable.ic_menu_paste_multi);
            d.getDrawable(1).setAlpha(127);
            if (menu.findItem(R.id.content_paste) != null)
                menu.findItem(R.id.content_paste).setIcon(d);
        }
        if (mPaste != null)
            mPaste.setVisible(true);
    }

    MenuUtils.setMenuEnabled(menu, true, R.id.menu_view, R.id.menu_sort, R.id.menu_content_ops);

    int mViewMode = getViewMode();
    MenuUtils.setMenuChecked(menu, true, 0, R.id.menu_view_grid, R.id.menu_view_list, R.id.menu_view_carousel);
    if (mViewMode == OpenExplorer.VIEW_GRID)
        MenuUtils.setMenuChecked(menu, true, R.id.menu_view_grid, R.id.menu_view_list, R.id.menu_view_carousel);
    else if (mViewMode == OpenExplorer.VIEW_LIST)
        MenuUtils.setMenuChecked(menu, true, R.id.menu_view_list, R.id.menu_view_grid, R.id.menu_view_carousel);
    else if (mViewMode == OpenExplorer.VIEW_CAROUSEL)
        MenuUtils.setMenuChecked(menu, true, R.id.menu_view_carousel, R.id.menu_view_grid, R.id.menu_view_list);

    MenuUtils.setMenuChecked(menu, getShowHiddenFiles(), R.id.menu_view_hidden);
    MenuUtils.setMenuChecked(menu, getShowThumbnails(), R.id.menu_view_thumbs);
    MenuUtils.setMenuVisible(menu, OpenExplorer.CAN_DO_CAROUSEL, R.id.menu_view_carousel);

}

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;/*from   w w  w  . ja  va  2  s.com*/
    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:de.baumann.browser.Browser.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem saveBookmark = menu.findItem(R.id.action_save_bookmark);
    MenuItem search = menu.findItem(R.id.action_search);
    MenuItem search2 = menu.findItem(R.id.action_search2);
    MenuItem search3 = menu.findItem(R.id.action_search3);
    MenuItem history = menu.findItem(R.id.action_history);
    MenuItem save = menu.findItem(R.id.action_save);
    MenuItem share = menu.findItem(R.id.action_share);
    MenuItem searchSite = menu.findItem(R.id.action_searchSite);
    MenuItem downloads = menu.findItem(R.id.action_downloads);
    MenuItem settings = menu.findItem(R.id.action_settings);
    MenuItem prev = menu.findItem(R.id.action_prev);
    MenuItem next = menu.findItem(R.id.action_next);
    MenuItem cancel = menu.findItem(R.id.action_cancel);
    MenuItem pass = menu.findItem(R.id.action_pass);
    MenuItem help = menu.findItem(R.id.action_help);
    MenuItem toggle = menu.findItem(R.id.action_toggle);

    if (sharedPref.getInt("keyboard", 0) == 0) { //could be button state or..?
        saveBookmark.setVisible(false);
        search.setVisible(true);//from w  ww .j a v  a  2 s  .c  om
        search2.setVisible(false);
        search3.setVisible(false);
        history.setVisible(true);
        save.setVisible(true);
        share.setVisible(true);
        searchSite.setVisible(true);
        downloads.setVisible(true);
        settings.setVisible(false);
        prev.setVisible(false);
        next.setVisible(false);
        cancel.setVisible(false);
        pass.setVisible(true);
        help.setVisible(false);
        toggle.setVisible(true);
    } else if (sharedPref.getInt("keyboard", 0) == 1) {
        saveBookmark.setVisible(false);
        search.setVisible(false);
        search2.setVisible(true);
        search3.setVisible(false);
        history.setVisible(false);
        save.setVisible(false);
        share.setVisible(false);
        searchSite.setVisible(false);
        downloads.setVisible(false);
        settings.setVisible(false);
        prev.setVisible(true);
        next.setVisible(true);
        cancel.setVisible(true);
        pass.setVisible(false);
        help.setVisible(false);
        toggle.setVisible(false);
    } else if (sharedPref.getInt("keyboard", 0) == 2) {
        saveBookmark.setVisible(true);
        search.setVisible(false);
        search2.setVisible(false);
        search3.setVisible(false);
        history.setVisible(false);
        save.setVisible(false);
        share.setVisible(false);
        searchSite.setVisible(false);
        downloads.setVisible(false);
        settings.setVisible(false);
        prev.setVisible(false);
        next.setVisible(false);
        cancel.setVisible(true);
        pass.setVisible(false);
        help.setVisible(false);
        toggle.setVisible(false);
    } else if (sharedPref.getInt("keyboard", 0) == 3) {
        saveBookmark.setVisible(false);
        search.setVisible(true);
        search2.setVisible(false);
        search3.setVisible(true);
        history.setVisible(false);
        save.setVisible(false);
        share.setVisible(false);
        searchSite.setVisible(false);
        downloads.setVisible(false);
        settings.setVisible(false);
        prev.setVisible(false);
        next.setVisible(false);
        cancel.setVisible(true);
        pass.setVisible(false);
        help.setVisible(false);
        toggle.setVisible(false);
    }
    return true; // this is important to call so that new menu is shown
}

From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java

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

    MenuItem mClearHistory = menu.findItem(R.id.clear_history);
    mClearHistory.setVisible(mPulldown.isSliderOpen());

    MenuItem mShowHistory = menu.findItem(R.id.show_history);
    mShowHistory.setVisible(!mPulldown.isSliderOpen());

    MenuItem mHideHistory = menu.findItem(R.id.hide_history);
    mHideHistory.setVisible(mPulldown.isSliderOpen());

    MenuItem mMatrixPanel = menu.findItem(R.id.matrix);
    if (mMatrixPanel != null)
        mMatrixPanel.setVisible(!getMatrixVisibility() && CalculatorSettings.matrixPanel(getContext())
                && !mPulldown.isSliderOpen());

    MenuItem mGraphPanel = menu.findItem(R.id.graph);
    if (mGraphPanel != null)
        mGraphPanel.setVisible(!getGraphVisibility() && CalculatorSettings.graphPanel(getContext())
                && !mPulldown.isSliderOpen());

    MenuItem mFunctionPanel = menu.findItem(R.id.function);
    if (mFunctionPanel != null)
        mFunctionPanel.setVisible(!getFunctionVisibility() && CalculatorSettings.functionPanel(getContext())
                && !mPulldown.isSliderOpen());

    MenuItem mBasicPanel = menu.findItem(R.id.basic);
    if (mBasicPanel != null)
        mBasicPanel.setVisible(!getBasicVisibility() && CalculatorSettings.basicPanel(getContext())
                && !mPulldown.isSliderOpen());

    MenuItem mAdvancedPanel = menu.findItem(R.id.advanced);
    if (mAdvancedPanel != null)
        mAdvancedPanel.setVisible(!getAdvancedVisibility() && CalculatorSettings.advancedPanel(getContext())
                && !mPulldown.isSliderOpen());

    MenuItem mHexPanel = menu.findItem(R.id.hex);
    if (mHexPanel != null)
        mHexPanel.setVisible(//from   w  w  w  .j a  v a 2 s . c o m
                !getHexVisibility() && CalculatorSettings.hexPanel(getContext()) && !mPulldown.isSliderOpen());

    MenuItem mLock = menu.findItem(R.id.lock);
    if (mLock != null)
        mLock.setVisible(getGraphVisibility() && getPagingEnabled());

    MenuItem mUnlock = menu.findItem(R.id.unlock);
    if (mUnlock != null)
        mUnlock.setVisible(getGraphVisibility() && !getPagingEnabled());

    return true;
}