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:app.sunstreak.yourpisd.ClassSwipeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.class_swipe_actions, menu);

    if (termIndex == 0)
        menu.findItem(R.id.previous_six_weeks).setEnabled(false);
    else if (termIndex == 7)
        menu.findItem(R.id.next_six_weeks).setEnabled(false);

    // Create list of students in Menu.
    if (session.MULTIPLE_STUDENTS) {
        for (int i = 0; i < session.getStudents().size(); i++) {
            String name = session.getStudents().get(i).name;
            MenuItem item = menu.add(name);

            // Set the currently enabled student un-clickable.
            if (i == studentIndex)
                item.setEnabled(false);

            item.setOnMenuItemClickListener(new StudentSelectListener(i));
            item.setVisible(true);/*from   w  w w.  ja  va 2 s .com*/
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:org.getlantern.firetweet.fragment.support.UserListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUserList userList = mUserList;
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    if (followItem != null) {
        followItem.setEnabled(userList != null);
        if (userList == null) {
            followItem.setIcon(android.R.color.transparent);
        }//from   w  ww. ja v  a2 s.  c om
    }
    if (twitter == null || userList == null)
        return;
    final boolean isMyList = userList.user_id == userList.account_id;
    setMenuItemAvailability(menu, MENU_EDIT, isMyList);
    setMenuItemAvailability(menu, MENU_ADD, isMyList);
    setMenuItemAvailability(menu, MENU_DELETE, isMyList);
    final boolean isFollowing = userList.is_following;
    if (followItem != null) {
        followItem.setVisible(!isMyList);
        if (isFollowing) {
            followItem.setIcon(R.drawable.ic_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {
            followItem.setIcon(R.drawable.ic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
    }
    menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION);
    final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST);
    extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader());
    extensionsIntent.putExtra(EXTRA_USER_LIST, mUserList);
    addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION);
}

From source file:de.vanita5.twittnuker.activity.support.UserProfileEditorActivity.java

@Override
public void onClick(final View view) {
    if (mUser == null)
        return;//from  www.j  ava  2 s . c o  m
    if (mPopupMenu != null) {
        mPopupMenu.dismiss();
    }
    switch (view.getId()) {
    case ProfileImageBannerLayout.VIEW_ID_PROFILE_IMAGE: {
        mPopupMenu = PopupMenu.getInstance(this, view);
        mPopupMenu.inflate(R.menu.action_profile_image);
        mPopupMenu.setOnMenuItemClickListener(mProfileImageMenuListener);
        break;
    }
    case ProfileImageBannerLayout.VIEW_ID_PROFILE_BANNER: {
        mPopupMenu = PopupMenu.getInstance(this, view);
        mPopupMenu.inflate(R.menu.action_profile_banner_image);
        final Menu menu = mPopupMenu.getMenu();
        final MenuItem delete_submenu = menu.findItem(MENU_DELETE_SUBMENU);
        final boolean has_profile_banner = !isEmpty(mUser.profile_banner_url);
        delete_submenu.setVisible(has_profile_banner);
        delete_submenu.setEnabled(has_profile_banner);
        mPopupMenu.setOnMenuItemClickListener(mProfileBannerImageMenuListener);
        break;
    }
    default: {
        return;
    }
    }
    mPopupMenu.show();

}

From source file:net.zorgblub.typhon.fragment.CatalogFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    Option<Feed> feed = adapter.getFeed();

    boolean searchEnabled = !isEmpty(feed.flatMap(Feed::getSearchLink));

    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);

        boolean enabled;

        switch (item.getItemId()) {

        case R.id.search:
            enabled = searchEnabled;// www. j  a  va  2  s  . c o m
            break;
        default:
            enabled = true;
        }

        item.setEnabled(enabled);
        item.setVisible(enabled);
    }

    LOG.debug("Adapter has feed: " + adapter.getFeed());
}

From source file:com.zion.htf.ui.fragment.ArtistDetailsFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem addAlarmItem = menu.findItem(R.id.action_addAlarm);
    MenuItem editAlarmItem = menu.findItem(R.id.action_editAlarm);
    MenuItem toggleFavorite = menu.findItem(R.id.action_toggle_favorite);

    boolean areAlarmsEnabled = 0 != this.setId;
    boolean hasAlarm = null != this.alarm;

    // Add / edit alarm button
    if (null != addAlarmItem) {
        addAlarmItem.setVisible(areAlarmsEnabled && !hasAlarm);
        addAlarmItem.setEnabled(areAlarmsEnabled && !hasAlarm);
    }/*  www .  j  av  a2  s . c  o  m*/
    if (null != editAlarmItem) {
        editAlarmItem.setVisible(areAlarmsEnabled && hasAlarm);
        editAlarmItem.setEnabled(areAlarmsEnabled && hasAlarm);
    }

    // Favorite button
    if (this.artist.isFavorite()) {
        toggleFavorite.setTitle(R.string.action_unset_favorite);
        toggleFavorite.setIcon(R.drawable.ic_menu_favorite);
    } else {
        toggleFavorite.setTitle(R.string.action_set_favorite);
        toggleFavorite.setIcon(R.drawable.ic_menu_not_favorite);
    }
}

From source file:com.mobicage.rogerthat.FriendDetailActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (mFriend != null) {
        MenuItem removeFriend = menu.findItem(R.id.remove_friend);
        if (removeFriend != null) {
            Matcher matcher = RegexPatterns.IS_DASHBOARD_ACCOUNT.matcher(mFriend.email);
            removeFriend.setEnabled(!matcher.matches());
        }/*  w  ww.j  a va  2  s.c  o m*/
    }
    return true;
}

From source file:org.bohrmeista.chan.ui.activity.BoardActivity.java

private void setMenuItemEnabled(MenuItem item, boolean enabled) {
    if (item != null) {
        item.setVisible(enabled);/*from   w w w .j ava 2s  .  c  o  m*/
        item.setEnabled(enabled);
    }
}

From source file:com.tlongdev.bktf.ui.fragment.FavoritesFragment.java

@Override
public void onMoreClicked(View view, final Item item) {
    PopupMenu menu = new PopupMenu(getActivity(), view);
    menu.getMenuInflater().inflate(R.menu.popup_item, menu.getMenu());
    menu.getMenu().findItem(R.id.favorite).setTitle("Remove from favorites");
    menu.getMenu().findItem(R.id.calculator).setEnabled(!Utility.isInCalculator(getActivity(), item));
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//  w w w  .ja  va2s  .c  o  m
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.history:
                Intent i = new Intent(getActivity(), PriceHistoryActivity.class);
                i.putExtra(PriceHistoryActivity.EXTRA_ITEM, item);
                startActivity(i);
                break;
            case R.id.favorite:
                Utility.removeFromFavorites(getActivity(), item);
                mAdapter.removeItem(item);
                break;
            case R.id.calculator:
                Utility.addToCalculator(getActivity(), item);
                menuItem.setEnabled(false);
                break;
            case R.id.backpack_tf:
                CustomTabActivityHelper.openCustomTab(getActivity(), new CustomTabsIntent.Builder().build(),
                        Uri.parse(item.getBackpackTfUrl()), new WebViewFallback());
                break;
            case R.id.wiki:
                CustomTabActivityHelper.openCustomTab(getActivity(), new CustomTabsIntent.Builder().build(),
                        Uri.parse(item.getTf2WikiUrl()), new WebViewFallback());
                break;
            }
            return true;
        }
    });

    menu.show();
}

From source file:com.gimranov.zandy.app.ItemActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.zotero_menu, menu);

    // Turn on sort item
    MenuItem sort = menu.findItem(R.id.do_sort);
    sort.setEnabled(true);//www  .j  a  v  a  2s. c om
    sort.setVisible(true);

    // Turn on search item
    MenuItem search = menu.findItem(R.id.do_search);
    search.setEnabled(true);
    search.setVisible(true);

    // Turn on identifier item
    MenuItem identifier = menu.findItem(R.id.do_identifier);
    identifier.setEnabled(true);
    identifier.setVisible(true);

    return true;
}

From source file:org.wheelmap.android.activity.MainMultiPaneActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    ActionBar bar = getSupportActionBar();
    if (bar == null) {
        return true;
    }//from  ww  w. java 2 s .c  o m

    LayoutInflater inflater = LayoutInflater.from(this);
    View customView = inflater.inflate(R.layout.actionbar_tablet, null);
    bar.setCustomView(customView, new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT, Gravity.CENTER_VERTICAL | Gravity.END));

    boolean isPortraitMode = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    if (isPortraitMode) {

        ImageView addItem = (ImageView) customView.findViewById(R.id.menu_new_poi);
        addItem.setVisibility(View.VISIBLE);
        OnClickListener addClickListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                createNewPoi();
            }
        };
        addItem.setOnClickListener(addClickListener);

        LinearLayout l = (LinearLayout) findViewById(R.id.actionbar_bottom);
        for (int i = 0; i < l.getChildCount(); i++) {
            l.getChildAt(i).setOnTouchListener(new PressSelector());
        }

        bar.setDisplayShowCustomEnabled(true);
        View v = findViewById(R.id.menu_filter);
        MapActivityUtils.setAccessFilterOptionDrawable(this, null, v);

        View filterWc = findViewById(R.id.menu_wc);
        MapActivityUtils.setWcFilterOptionsDrawable(this, null, filterWc);

        UserCredentials credentials = new UserCredentials(getApplicationContext());
        ImageView image = (ImageView) findViewById(R.id.menu_login);
        image.setImageResource(
                credentials.isLoggedIn() ? R.drawable.start_icon_logged_in : R.drawable.start_icon_login);
    } else {
        MenuInflater inflaterMenu = getMenuInflater();
        inflaterMenu.inflate(R.menu.ab_multi_activity, menu);
        MenuItem item = menu.findItem(R.id.menu_filter);
        MapActivityUtils.setAccessFilterOptionDrawable(this, item, null);
        item = menu.findItem(R.id.menu_wc);
        MapActivityUtils.setWcFilterOptionsDrawable(this, item, null);

    }

    if (mapModeType == MapModeType.MAP_MODE_ENGAGE) {
        MenuItem itemFilterWheelChairs = menu.findItem(R.id.menu_filter);
        itemFilterWheelChairs.setEnabled(false);
        //TODO Disable it - doesn't work yet
    }

    ImageView listMapToggle = (ImageView) findViewById(R.id.switch_view);
    if (listMapToggle != null) {
        listMapToggle.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                toggleMovableResize();
            }
        });
    }

    return true;
}