Example usage for android.view MenuItem getIcon

List of usage examples for android.view MenuItem getIcon

Introduction

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

Prototype

public Drawable getIcon();

Source Link

Document

Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).

Usage

From source file:org.solovyev.android.widget.menu.CustomPopupMenuHelper.java

@Override
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
    if (subMenu.hasVisibleItems()) {
        CustomPopupMenuHelper subPopup = new CustomPopupMenuHelper(mContext, subMenu, mAnchorView, false,
                mPopupStyleAttr, mPopupStyleRes);
        subPopup.setGravity(mGravity);/*from ww  w. ja  v a  2 s  . co m*/
        subPopup.setCallback(mPresenterCallback);
        subPopup.setKeepOnSubMenu(mKeepOnSubMenu);

        boolean preserveIconSpacing = false;
        final int count = subMenu.size();
        for (int i = 0; i < count; i++) {
            MenuItem childItem = subMenu.getItem(i);
            if (childItem.isVisible() && childItem.getIcon() != null) {
                preserveIconSpacing = true;
                break;
            }
        }
        subPopup.setForceShowIcon(preserveIconSpacing);

        if (subPopup.tryShow()) {
            if (mPresenterCallback != null) {
                mPresenterCallback.onOpenSubMenu(subMenu);
            }
            return true;
        }
    }
    return false;
}

From source file:com.ez.gallery.ucrop.UCropActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.ucrop_menu_activity, menu);

    // Change the next menu icon color to match the rest of the UI colors
    MenuItem next = menu.findItem(R.id.menu_crop);

    Drawable defaultIcon = next.getIcon();
    if (defaultIcon != null) {
        defaultIcon.mutate();//www.  ja v a2s  .  com
        defaultIcon.setColorFilter(mToolbarTextColor, PorterDuff.Mode.SRC_ATOP);
        next.setIcon(defaultIcon);
    }

    return true;
}

From source file:ch.kanti_baden.pu_marc_14b.traffictimewaste.SORT_TYPE.java

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

    // Disable create post button if user isn't logged in
    if (DatabaseLink.instance.isLoggedIn()) {
        MenuItem menuItem = menu.findItem(R.id.action_login);
        menuItem.setEnabled(false);//from w w  w  .j a va2 s.c om
    } else {
        MenuItem menuItem = menu.findItem(R.id.action_create);
        menuItem.setEnabled(false);
        Drawable icon = menuItem.getIcon();
        icon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
        menuItem.setIcon(icon);
    }

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchView.setTranslationX(500f);
            searchView.setAlpha(0f);
            searchView.animate().translationX(0);
            searchView.animate().alpha(1f);
        }
    });
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return true;
}

From source file:org.mariotaku.twidere.fragment.BaseStatusesListFragment.java

private void openMenu(final View view, final ParcelableStatus status) {
    if (view == null || status == null)
        return;//from w ww .j  av  a  2 s.c o m
    final int activated_color = getResources().getColor(R.color.holo_blue_bright);
    mPopupMenu = PopupMenu.getInstance(getActivity(), view);
    mPopupMenu.inflate(R.menu.action_status);
    final boolean click_to_open_menu = mPreferences.getBoolean(PREFERENCE_KEY_CLICK_TO_OPEN_MENU, false);
    final boolean seprate_retweet_action = mPreferences.getBoolean(PREFERENCE_KEY_SEPRATE_RETWEET_ACTION,
            false);
    final Menu menu = mPopupMenu.getMenu();
    setMenuForStatus(getActivity(), menu, status);
    final MenuItem view_status = menu.findItem(MENU_VIEW);
    if (view_status != null) {
        view_status.setVisible(click_to_open_menu);
    }
    final MenuItem retweet_submenu = menu.findItem(R.id.retweet_submenu);
    if (retweet_submenu != null) {
        retweet_submenu.setVisible(!seprate_retweet_action);
    }
    final MenuItem direct_quote = menu.findItem(R.id.direct_quote);
    if (direct_quote != null) {
        direct_quote.setVisible(seprate_retweet_action);
    }
    final MenuItem direct_retweet = menu.findItem(R.id.direct_retweet);
    if (direct_retweet != null) {
        final Drawable icon = direct_retweet.getIcon().mutate();
        direct_retweet.setVisible(seprate_retweet_action && (!status.is_protected || isMyRetweet(status)));
        if (isMyRetweet(status)) {
            icon.setColorFilter(activated_color, PorterDuff.Mode.MULTIPLY);
            direct_retweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            direct_retweet.setTitle(R.string.retweet);
        }
    }
    mPopupMenu.setOnMenuItemClickListener(this);
    mPopupMenu.show();
}

From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java

@Override
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
    if (subMenu.hasVisibleItems()) {
        MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu, mAnchorView);
        subPopup.setCallback(mPresenterCallback);

        boolean preserveIconSpacing = false;
        final int count = subMenu.size();
        for (int i = 0; i < count; i++) {
            MenuItem childItem = subMenu.getItem(i);
            if (childItem.isVisible() && childItem.getIcon() != null) {
                preserveIconSpacing = true;
                break;
            }/*from ww w.  java 2 s  .  com*/
        }
        subPopup.setForceShowIcon(preserveIconSpacing);

        if (subPopup.tryShow()) {
            if (mPresenterCallback != null) {
                mPresenterCallback.onOpenSubMenu(subMenu);
            }
            return true;
        }
    }
    return false;
}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Shows all the menu items that were hidden by hideIfRoomItems(boolean withAnim)
 *
 * @param withAnim//from  ww  w  . j  a v a  2 s . co m
 */
public void showIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    cancelChildAnimListAndClear();

    if (mMenuItems.isEmpty())
        return;

    anims = new ArrayList<>();

    for (int i = 0; i < getChildCount(); i++) {

        final View currentView = getChildAt(i);

        if (i < mActionItems.size()) {
            ImageView action = (ImageView) currentView;
            final MenuItem actionItem = mActionItems.get(i);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

            action.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mMenuCallback != null)
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
                }
            });
        }

        //todo go over logic
        int animDuration = withAnim ? SHOW_IF_ROOM_ITEMS_ANIM_DURATION : 0;

        Interpolator interpolator = new DecelerateInterpolator();

        //todo check logic
        if (i > mActionShowAlwaysItems.size() - 1)
            interpolator = new LinearInterpolator();

        currentView.setClickable(true);
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setTranslationX(0);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).translationX(0).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleX(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleX(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleY(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleY(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setAlpha(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).alpha(1.0f).get());
    }

    AnimatorSet animSet = new AnimatorSet();

    //temporary, from laziness
    if (!withAnim)
        animSet.setDuration(0);
    animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
    animSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

            if (mOnVisibleWidthChanged != null)
                mOnVisibleWidthChanged.onVisibleWidthChanged(
                        (getChildCount() * (int) ACTION_DIMENSION_PX) - (mHasOverflow ? Util.dpToPx(8) : 0));
        }
    });
    animSet.start();

}

From source file:cn.zhangls.android.weibo.ui.details.comment.CommentActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();// w  ww . ja va2 s.  com
        break;
    case R.id.menu_ac_comment_share:
        Drawable drawable = item.getIcon();
        if (drawable instanceof Animatable) {
            ((Animatable) drawable).start();
        }
        break;
    case R.id.menu_ac_comment_open_in_weibo:
        openInWeibo();
        break;
    }
    return true;
}

From source file:com.irccloud.android.activity.BaseActivity.java

public void setMenuColorFilter(final Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        Drawable d = menuItem.getIcon();
        if (d != null) {
            d.mutate();//w  w  w.  j  a  v  a2 s  .  com
            d.setColorFilter(ColorScheme.getInstance().navBarSubheadingColor, PorterDuff.Mode.SRC_ATOP);
        }
    }
}

From source file:org.mariotaku.twidere.fragment.support.BaseStatusesMultiColumnListFragment.java

private void openMenu(final View view, final ParcelableStatus status) {
    mSelectedStatus = status;//w  ww. ja v a2  s . com
    if (view == null || status == null)
        return;
    if (mPopupMenu != null && mPopupMenu.isShowing()) {
        mPopupMenu.dismiss();
    }
    final int activated_color = ThemeUtils.getUserThemeColor(getActivity());
    mPopupMenu = PopupMenu.getInstance(getActivity(), view);
    mPopupMenu.inflate(R.menu.action_status);
    final boolean separate_retweet_action = mPreferences.getBoolean(PREFERENCE_KEY_SEPARATE_RETWEET_ACTION,
            PREFERENCE_DEFAULT_SEPARATE_RETWEET_ACTION);
    final Menu menu = mPopupMenu.getMenu();
    setMenuForStatus(getActivity(), menu, status);
    final MenuItem retweet_submenu = menu.findItem(R.id.retweet_submenu);
    if (retweet_submenu != null) {
        retweet_submenu.setVisible(!separate_retweet_action);
    }
    final MenuItem direct_quote = menu.findItem(R.id.direct_quote);
    if (direct_quote != null) {
        direct_quote.setVisible(separate_retweet_action);
    }
    final MenuItem direct_retweet = menu.findItem(R.id.direct_retweet);
    if (direct_retweet != null) {
        final Drawable icon = direct_retweet.getIcon().mutate();
        direct_retweet
                .setVisible(separate_retweet_action && (!status.user_is_protected || isMyRetweet(status)));
        if (isMyRetweet(status)) {
            icon.setColorFilter(activated_color, PorterDuff.Mode.MULTIPLY);
            direct_retweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            direct_retweet.setTitle(R.string.retweet);
        }
    }
    mPopupMenu.setOnMenuItemClickListener(this);
    mPopupMenu.show();
}

From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment2.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.calendar, menu);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        MenuItem menuItem = menu.findItem(R.id.action_cal_goto_today);
        // replace the default top layer drawable of the today icon with a
        // custom drawable that shows the day of the month of today
        LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
        UIUtils.setTodayIcon(icon, getContext(), "");
    }/*from   ww w.j ava 2s  .  co  m*/
}