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:io.realm.scanner.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem item = menu.getItem(0);
    if (currentScan != null) {
        final String textScanResult = currentScan.getTextScanResult();
        final String classificationResult = currentScan.getClassificationResult();
        final String faceDetectionResult = currentScan.getFaceDetectionResult();
        if (textScanResult != null && classificationResult != null && faceDetectionResult != null) {
            item.setEnabled(true);
            return true;
        }//w ww.jav  a 2 s  .  c o  m
    }
    item.setEnabled(false);
    return true;
}

From source file:com.darshancomputing.BatteryIndicator.CurrentInfoFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem snItem = menu.findItem(R.id.menu_show_notification);
    MenuItem closeItem = menu.findItem(R.id.menu_close);

    if (activity.sp_store.getBoolean(BatteryInfoService.KEY_SHOW_NOTIFICATION, true)) {
        snItem.setIcon(R.drawable.ic_menu_stop);
        snItem.setTitle(R.string.menu_hide_notification);
    } else {//from  w  w w  .j a  va  2 s . c  o  m
        snItem.setIcon(R.drawable.ic_menu_notifications);
        snItem.setTitle(R.string.menu_show_notification);
    }

    if (serviceCloseable)
        closeItem.setEnabled(true);
    else
        closeItem.setEnabled(false);
}

From source file:com.googlecode.CallerLookup.Main.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    assert ((mLookup.getSelectedItemPosition() == 0)
            || (mLookupEntries.get(mLookup.getSelectedItem().toString()) != null));
    boolean custom = (mLookup.getSelectedItemPosition() == 0);
    boolean saved = (!custom
            && mLookupEntries.get(mLookup.getSelectedItem().toString()).mName.startsWith(SAVED_PREFIX));
    boolean empty = (mURL.getText().toString().length() <= 0);

    MenuItem customize = menu.findItem(MENU_CUSTOMIZE);
    assert (customize != null);
    customize.setEnabled(!custom);

    MenuItem save = menu.findItem(MENU_SAVE);
    assert (save != null);
    save.setEnabled(custom && !empty);

    MenuItem remove = menu.findItem(MENU_REMOVE);
    assert (remove != null);
    remove.setEnabled(saved);//from ww  w.ja v a2s . c  om

    MenuItem submit = menu.findItem(MENU_SUBMIT);
    assert (submit != null);
    submit.setEnabled((custom || saved) && !empty);

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Update a menu item based on the presence of a provider */
private void setProviderMenuEnabled(Menu menu, int id, Uri providerUri) {
    MenuItem item = menu.findItem(id);
    item.setEnabled(providerUri == null);
}

From source file:com.battlelancer.seriesguide.ui.OverviewFragment.java

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

    // If no episode is visible, hide actions related to the episode
    boolean isEpisodeVisible = mCurrentEpisodeCursor != null && mCurrentEpisodeCursor.moveToFirst();

    // enable/disable menu items
    MenuItem itemShare = menu.findItem(R.id.menu_overview_share);
    itemShare.setEnabled(isEpisodeVisible);
    itemShare.setVisible(isEpisodeVisible);
    MenuItem itemCalendar = menu.findItem(R.id.menu_overview_calendar);
    itemCalendar.setEnabled(isEpisodeVisible);
    itemCalendar.setVisible(isEpisodeVisible);
    MenuItem itemManageLists = menu.findItem(R.id.menu_overview_manage_lists);
    if (itemManageLists != null) {
        itemManageLists.setEnabled(isEpisodeVisible);
        itemManageLists.setVisible(isEpisodeVisible);
    }//  w ww. ja v a 2s . c  o  m
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java

/**
 * {@inheritDoc}//from   ww w. ja  v  a 2 s .  c  o  m
 */
@Override
public void onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);

    final MenuItem item = menu.findItem(R.id.neareststops_option_menu_filter);
    item.setEnabled(services != null && services.length > 0);
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Prepare the Screen's standard options menu to be displayed. */
@Override/*from   w w w . j  a v a 2  s .  c  o  m*/
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_add);
    item.setEnabled(itsPermissionMgr.hasPerms());

    setProviderMenuEnabled(menu, R.id.menu_add_box, itsBoxUri);
    setProviderMenuEnabled(menu, R.id.menu_add_dropbox, itsDropboxUri);
    setProviderMenuEnabled(menu, R.id.menu_add_google_drive, itsGDrivePlayUri);
    setProviderMenuEnabled(menu, R.id.menu_add_onedrive, itsOnedriveUri);
    setProviderMenuEnabled(menu, R.id.menu_add_owncloud, itsOwncloudUri);
    return super.onPrepareOptionsMenu(menu);
}

From source file:eu.power_switch.api.taskerplugin.EditActivity.java

private void setPositiveButtonVisibility(boolean isValid) {
    if (getOptionsMenu() != null) {
        MenuItem saveButton = getOptionsMenu().findItem(R.id.twofortyfouram_locale_menu_save);
        saveButton.setEnabled(isValid);
        saveButton.setVisible(isValid);//from   ww  w  . jav  a 2s  . c  om

        onPrepareOptionsMenu(getOptionsMenu());
    }
}

From source file:com.jecelyin.editor.v2.ui.MainActivity.java

/**
 *
 * @param menuResId//from ww w. jav  a  2 s.  co m
 * @param status {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_NORMAL}, {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_DISABLED}
 */
public void setMenuStatus(@IdRes int menuResId, int status) {
    MenuItem menuItem = mToolbar.getMenu().findItem(menuResId);
    if (menuItem == null) {
        throw new RuntimeException("Can't find a menu item");
    }
    Drawable icon = menuItem.getIcon();
    if (status == MenuDef.STATUS_DISABLED) {
        menuItem.setEnabled(false);
        menuItem.setIcon(MenuManager.makeToolbarDisabledIcon(icon));
    } else {
        menuItem.setEnabled(true);
        if (menuItem.getGroupId() == MenuDef.GROUP_TOOLBAR) {
            menuItem.setIcon(MenuManager.makeToolbarNormalIcon(icon));
        } else {
            menuItem.setIcon(MenuManager.makeMenuNormalIcon(icon));
        }
    }
}

From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java

/**
 * Initialize the NavigationView/* w w  w  .  j  a v a2  s  . co  m*/
 *
 */
private void setupNavigationView() {
    final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView == null) {
        return;
    }
    navigationView.addOnLayoutChangeListener(this);

    // Handle click on header
    final View hView = navigationView.getHeaderView(0);
    hView.setOnClickListener(this);

    // set Devices menu state
    final Menu menu = navigationView.getMenu();
    final MenuItem deviceItem = menu.findItem(R.id.nav_devices);
    deviceItem.setEnabled(Prefs.isGcmRegistered());

    // set users avatar
    final String photoUri = Prefs.getPersonPhoto();
    final ImageView photo = (ImageView) hView.findViewById(R.id.personPhoto);
    if (!photoUri.isEmpty()) {
        photo.setImageAlpha(255);
        new LoadProfileImage(photo).execute(photoUri);
    } else {
        photo.setImageResource(R.drawable.ic_account_circle_24dp);
        photo.setImageAlpha(75);
    }

    // set users Google+ cover photo
    final String coverPhotoUri = Prefs.getPersonCoverPhoto();
    final LinearLayout coverPhoto = (LinearLayout) hView.findViewById(R.id.navHeader);
    if (!coverPhotoUri.isEmpty()) {
        new LoadCoverImage(coverPhoto).execute(coverPhotoUri);
    } else {
        final Drawable drawable = ContextCompat.getDrawable(this, R.drawable.side_nav_bar);
        coverPhoto.setBackground(drawable);
    }

    // set users account information
    final TextView name = (TextView) hView.findViewById(R.id.personName);
    final TextView email = (TextView) hView.findViewById(R.id.personEmail);
    name.setText(Prefs.getPersonName());
    email.setText(Prefs.getPersonEmail());
}