Example usage for android.view MenuItem isEnabled

List of usage examples for android.view MenuItem isEnabled

Introduction

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

Prototype

public boolean isEnabled();

Source Link

Document

Return the enabled state of the menu item.

Usage

From source file:Main.java

/**
 * Android doesn't fade out disabled menu item icons, so do it ourselves
 *//*  ww w .jav a2  s.  c om*/
public static void fixupMenuAlpha(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        Drawable icon = item.getIcon();
        if (icon != null) {
            icon.setAlpha(item.isEnabled() ? 255 : 64);
        }
    }
}

From source file:com.android.screenspeak.contextmenu.ListMenuManager.java

private CharSequence[] getItemsFromMenu(Menu menu) {
    int size = menu.size();
    List<CharSequence> items = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        MenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled() && item.isVisible()) {
            items.add(item.getTitle());/*from w  ww.ja va2s . c o m*/
        }
    }

    return items.toArray(new CharSequence[items.size()]);
}

From source file:us.shandian.blacklight.ui.statuses.NewPostActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable() && item.isEnabled()) {
        item.setChecked(!item.isChecked());
    }//w w w . jav  a 2  s  .c om

    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();
        return true;
    } else if (id == R.id.post_send) {
        try {
            if (!TextUtils.isEmpty(mText.getText().toString())) {
                new Uploader().execute();
            } else {
                Toast.makeText(this, R.string.empty_weibo, Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {

        }
        return true;
    } else if (id == R.id.post_pic) {
        if (mBitmap == null) {
            showPicturePicker();
        } else {
            setPicture(null);
        }
        return true;
    } else if (id == R.id.post_emoticon) {
        if (mDrawer.isDrawerOpen(Gravity.END)) {
            mDrawer.closeDrawer(Gravity.END);
        } else {
            mDrawer.openDrawer(Gravity.END);
        }
        return true;
    } else if (id == R.id.post_at) {
        AtUserSuggestDialog diag = new AtUserSuggestDialog(this);
        diag.setListener(new AtUserSuggestDialog.AtUserListener() {
            @Override
            public void onChooseUser(String name) {
                mText.getText().insert(mText.getSelectionStart(), " @" + name + " ");
            }
        });
        diag.show();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

From source file:app.CT.BTCCalculator.fragments.BreakevenFragment.java

private void enableMenuItems() {
    MenuItem buy = menu.findItem(R.id.editCurrentBuyField);
    MenuItem sell = menu.findItem(R.id.editCurrentSellField);
    MenuItem reset = menu.findItem(R.id.resetAll);

    if (!buy.isEnabled())
        buy.setEnabled(true);/*w  ww  . ja  va 2  s. co m*/
    if (!sell.isEnabled())
        sell.setEnabled(true);
    if (!reset.isEnabled())
        reset.setEnabled(true);
}

From source file:info.papdt.blacklight.ui.statuses.NewPostActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable() && item.isEnabled()) {
        item.setChecked(!item.isChecked());
    }/*from  w  w  w.  j  a  va  2s .  c  om*/

    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_CUSTOMIZE:
        if (item.isEnabled()) {
            doCustomize();//from   w  ww.  j av  a  2 s .c  o m
        }
        return true;
    case MENU_SAVE:
        if (item.isEnabled()) {
            doSave();
        }
        return true;
    case MENU_REMOVE:
        if (item.isEnabled()) {
            doRemove();
        }
        return true;
    case MENU_SUBMIT:
        if (item.isEnabled()) {
            doSubmit();
        }
        return true;
    case MENU_UPDATE:
        if (item.isEnabled()) {
            doUpdate();
        }
        return true;
    case MENU_HELP:
        if (item.isEnabled()) {
            doHelp();
        }
        return true;
    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.wikipedia.edit.EditSectionActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_edit_section, menu);
    MenuItem item = menu.findItem(R.id.menu_save_section);

    if (editSummaryFragment.isActive()) {
        item.setTitle(getString(R.string.edit_next));
    } else if (editPreviewFragment.isActive()) {
        item.setTitle(getString(R.string.edit_done));
    } else {//from ww w  .  j av  a  2s  .  co m
        item.setTitle(getString(R.string.edit_next));
    }

    if (abusefilterEditResult != null) {
        if (abusefilterEditResult.getType() == EditAbuseFilterResult.TYPE_ERROR) {
            item.setEnabled(false);
        } else {
            item.setEnabled(true);
        }
    } else {
        item.setEnabled(sectionTextModified);
    }

    View v = getLayoutInflater().inflate(R.layout.item_edit_actionbar_button, null);
    item.setActionView(v);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    v.setLayoutParams(params);
    TextView txtView = v.findViewById(R.id.edit_actionbar_button_text);
    txtView.setText(item.getTitle());
    txtView.setTypeface(null, item.isEnabled() ? Typeface.BOLD : Typeface.NORMAL);
    v.setTag(item);
    v.setClickable(true);
    v.setEnabled(item.isEnabled());
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onOptionsItemSelected((MenuItem) view.getTag());
        }
    });

    v.setBackgroundColor(ContextCompat.getColor(this,
            item.isEnabled()
                    ? (editPreviewFragment.isActive() ? R.color.accent50
                            : ResourceUtil.getThemedAttributeId(this, R.attr.colorAccent))
                    : R.color.base50));

    return true;
}

From source file:org.mozilla.gecko.BrowserApp.java

private void updateAddonMenuItem(int id, JSONObject options) {
    // Set attribute for the menu item in cache, if available
    if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
        for (MenuItemInfo item : mAddonMenuItemsCache) {
            if (item.id == id) {
                item.label = options.optString("name", item.label);
                item.checkable = options.optBoolean("checkable", item.checkable);
                item.checked = options.optBoolean("checked", item.checked);
                item.enabled = options.optBoolean("enabled", item.enabled);
                item.visible = options.optBoolean("visible", item.visible);
                item.added = (mMenu != null);
                break;
            }//w w  w .j ava2  s  .c  o  m
        }
    }

    if (mMenu == null) {
        return;
    }

    final MenuItem menuItem = mMenu.findItem(id);
    if (menuItem != null) {
        menuItem.setTitle(options.optString("name", menuItem.getTitle().toString()));
        menuItem.setCheckable(options.optBoolean("checkable", menuItem.isCheckable()));
        menuItem.setChecked(options.optBoolean("checked", menuItem.isChecked()));
        menuItem.setEnabled(options.optBoolean("enabled", menuItem.isEnabled()));
        menuItem.setVisible(options.optBoolean("visible", menuItem.isVisible()));
    }
}