Example usage for android.view MenuItem setEnabled

List of usage examples for android.view MenuItem setEnabled

Introduction

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

Prototype

public MenuItem setEnabled(boolean enabled);

Source Link

Document

Sets whether the menu item is enabled.

Usage

From source file:Main.java

public static void setMenuItemEnabled(final Menu menu, final boolean enabled, final int viewId,
        final int enabledResId, final int disabledResId) {
    final MenuItem v = menu.findItem(viewId);
    if (v != null) {
        v.setIcon(enabled ? enabledResId : disabledResId);
        v.setEnabled(enabled);
    }/*from  w w  w .java 2 s .c  om*/
}

From source file:com.laevatein.internal.ui.helper.PhotoSelectionViewHelper.java

public static void updateSelectMenuState(MenuItem item, SelectedUriCollection collection, boolean drawerOpen) {
    if (item == null) {
        return;/*w  w w  .  j  a  va 2s .  c  o  m*/
    }
    item.setVisible(!drawerOpen);
    item.setEnabled(!collection.isEmpty() && collection.isCountInRange());
}

From source file:com.oliversride.wordryo.Utils.java

public static void setItemEnabled(Menu menu, int id, boolean enabled) {
    MenuItem item = menu.findItem(id);
    item.setEnabled(enabled);
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static void setEnabled(MenuItem item, boolean state) {
    if (null == item)
        return;//from w  ww  . ja  va 2  s .co m
    item.setEnabled(state);
    item.getIcon().setAlpha(state ? 255 : 160);
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static void setManyMenuItemsEnabled(boolean enabled, Menu menu, int[] ids) {
    for (int id : ids) {
        MenuItem menuItem = menu.findItem(id);
        if (menuItem != null) {
            menuItem.setEnabled(enabled);
        }//from w  w  w .  j  a  v  a2 s.  c o m
    }
}

From source file:at.bitfire.davdroid.syncadapter.AccountDetailsFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean ok = false;
    ok = editAccountName.getText().length() > 0;
    MenuItem item = menu.findItem(R.id.add_account);
    item.setEnabled(ok);
}

From source file:at.bitfire.davdroid.syncadapter.SelectCollectionsFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean ok = false;
    try {//  ww w  .  j a v a 2 s .  c  om
        ListView listView = getListView();
        for (int i = listView.getCount() - 1; i >= 0; i--) {
            if (listView.isItemChecked(i)) {
                ok = true;
                break;
            }
        }
    } catch (IllegalStateException e) {
    }
    MenuItem item = menu.findItem(R.id.next);
    item.setEnabled(ok);
}

From source file:com.justplay1.shoppist.features.currency.CurrencyActivity.java

@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
    MenuItem delete = menu.findItem(R.id.menu_delete);
    delete.setVisible(fragment.isDeleteButtonEnable());

    MenuItem checkAll = menu.findItem(R.id.menu_check_all);
    checkAll.setEnabled(fragment.isCheckAllButtonEnable());
    return true;//from   w w w.j  a  v  a 2s .  c o  m
}

From source file:com.justplay1.shoppist.features.units.UnitsActivity.java

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    super.onPrepareActionMode(mode, menu);
    MenuItem delete = menu.findItem(R.id.menu_delete);
    delete.setVisible(fragment.isDeleteButtonEnable());

    MenuItem checkAll = menu.findItem(R.id.menu_check_all);
    checkAll.setEnabled(fragment.isCheckAllButtonEnable());
    return true;/*  w  w w  .  ja  v  a 2 s  . c o  m*/
}

From source file:com.vuze.android.remote.activity.TorrentViewActivity.java

public static void prepareGlobalMenu(Menu menu, SessionInfo sessionInfo) {
    SessionSettings sessionSettings = sessionInfo == null ? null : sessionInfo.getSessionSettings();

    boolean isLocalHost = sessionInfo != null && sessionInfo.getRemoteProfile().isLocalHost();
    boolean isOnline = VuzeRemoteApp.getNetworkState().isOnline();

    MenuItem menuSessionSettings = menu.findItem(R.id.action_settings);
    if (menuSessionSettings != null) {
        menuSessionSettings.setEnabled(sessionSettings != null);
    }//  ww  w . j a  va2  s  . c o m

    MenuItem menuRefresh = menu.findItem(R.id.action_refresh);
    if (menuRefresh != null) {
        boolean refreshVisible = TorrentUtils.isAllowRefresh(sessionInfo);
        menuRefresh.setVisible(refreshVisible);
        menuRefresh.setEnabled(sessionInfo == null ? false : !sessionInfo.isRefreshingTorrentList());
    }

    MenuItem menuSearch = menu.findItem(R.id.action_search);
    if (menuSearch != null) {
        if (AndroidUtils.isTV()) {
            menuSearch.setVisible(false);
        } else {
            menuSearch.setEnabled(isOnline);
        }
    }

    MenuItem menuStartAll = menu.findItem(R.id.action_start_all);
    if (menuStartAll != null) {
        menuStartAll.setEnabled(isOnline || isLocalHost);
    }

    MenuItem menuStopAll = menu.findItem(R.id.action_stop_all);
    if (menuStopAll != null) {
        menuStopAll.setEnabled(isOnline || isLocalHost);
    }

    MenuItem itemSocial = menu.findItem(R.id.action_social);
    if (itemSocial != null) {

        MenuItem menuVote = menu.findItem(R.id.action_vote);
        if (menuVote != null) {
            menuVote.setVisible(!AndroidUtils.isTV());
        }

        MenuItem menuForum = menu.findItem(R.id.action_forum);
        if (menuForum != null) {
            menuForum.setVisible(!AndroidUtils.isTV());
        }
    }

    MenuItem menuShutdownCore = menu.findItem(R.id.action_shutdown);
    if (menuShutdownCore != null) {
        boolean visible = sessionInfo != null && sessionInfo.getRemoteProfile() != null
                && sessionInfo.getRemoteProfile().getRemoteType() == RemoteProfile.TYPE_CORE;
        menuShutdownCore.setVisible(visible);
    }
}