Example usage for android.graphics.drawable Drawable setColorFilter

List of usage examples for android.graphics.drawable Drawable setColorFilter

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setColorFilter.

Prototype

public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) 

Source Link

Document

Specify a color and Porter-Duff mode to be the color filter for this drawable.

Usage

From source file:de.luhmer.owncloudnewsreader.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    ThemeChooser.chooseTheme(this);

    super.onCreate(savedInstanceState);

    //getActionBar().setDisplayHomeAsUpEnabled(true);

    AppBarLayout appBarLayout;/*from  w  ww. jav a  2 s . c om*/

    // get the root container of the preferences list
    LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
    if (root != null) { //Some legacy devices may not be supported
        appBarLayout = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_layout, root, false);
        root.addView(appBarLayout, 0); // insert at top

        Toolbar toolbar = (Toolbar) appBarLayout.getChildAt(0);

        final Drawable backarrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        backarrow.setColorFilter(ContextCompat.getColor(this, R.color.tintColorDark), PorterDuff.Mode.SRC_ATOP);
        toolbar.setNavigationIcon(backarrow);
        toolbar.setTitle(R.string.title_activity_settings);
        toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.tintColorDark));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout InActivateColorize(LinearLayout ll, String text, Drawable dr) {

    // text/*from  w  w  w .j  a v  a  2 s  .  c  o m*/
    TextView v = (TextView) ll.findViewWithTag("tv");

    v.setText(text);
    v.setTextSize(10);
    v.setTextColor(Color.GRAY);
    v.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    dr.setColorFilter(0xFF888888, android.graphics.PorterDuff.Mode.SRC_ATOP);
    v.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null);
    v.setPadding(0, 5, 0, 2);

    v.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_tabs));

    // hbar
    View hbar = ll.findViewWithTag("hbar");
    hbar.setBackgroundDrawable(null);
    hbar.setBackgroundColor(resources.getColor(R.color.graylight));
    return ll;
}

From source file:com.nttec.everychan.ui.theme.CustomThemeHelper.java

private static void setLollipopMenuOverflowIconColor(final ViewGroup toolbar, final int color) {
    try {/*w ww  . j a  va  2s. c o  m*/
        //for API 23 (Android 6): at this point method Toolbar.setOverflowIcon(Drawable) has no effect
        toolbar.getClass().getMethod("getMenu").invoke(toolbar);
        AppearanceUtils.callWhenLoaded(toolbar, new Runnable() {
            @Override
            public void run() {
                try {
                    final ViewGroup actionMenuView = (ViewGroup) findViewByClassName(toolbar,
                            "android.widget.ActionMenuView");

                    Runnable setOverflowIcon = new Runnable() {
                        @Override
                        public void run() {
                            try {
                                Class<?> toolbarClass = toolbar.getClass();
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                    Drawable overflowIcon = (Drawable) toolbarClass.getMethod("getOverflowIcon")
                                            .invoke(toolbar);
                                    setColorFilter(overflowIcon);
                                    toolbarClass.getMethod("setOverflowIcon", Drawable.class).invoke(toolbar,
                                            overflowIcon);
                                } else {
                                    ImageView overflowButton = (ImageView) findViewByClassName(actionMenuView,
                                            "android.widget.ActionMenuPresenter$OverflowMenuButton");
                                    if (overflowButton != null) {
                                        Drawable overflowIcon = overflowButton.getDrawable();
                                        setColorFilter(overflowIcon);
                                        overflowButton.setImageDrawable(overflowIcon);
                                    }
                                }
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        }

                        private void setColorFilter(Drawable overflowIcon) {
                            overflowIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                        }
                    };

                    if (actionMenuView.getChildCount() == 0) {
                        AppearanceUtils.callWhenLoaded(actionMenuView == null ? toolbar : actionMenuView,
                                setOverflowIcon);
                    } else {
                        setOverflowIcon.run();
                    }
                } catch (Exception e) {
                    Logger.e(TAG, e);
                }
            }

            private View findViewByClassName(ViewGroup group, String className) {
                for (int i = 0, size = group.getChildCount(); i < size; ++i) {
                    View child = group.getChildAt(i);
                    if (child.getClass().getName().equals(className)) {
                        return child;
                    }
                }
                return null;
            }
        });
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
}

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 a  2 s. c o m*/
            d.setColorFilter(ColorScheme.getInstance().navBarSubheadingColor, PorterDuff.Mode.SRC_ATOP);
        }
    }
}

From source file:com.quarterfull.newsAndroid.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    ThemeChooser.chooseTheme(this);

    super.onCreate(savedInstanceState);

    //getActionBar().setDisplayHomeAsUpEnabled(true);

    AppBarLayout appBarLayout;// ww w.  j a v  a2  s.co  m

    // get the root container of the preferences list
    LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
    if (root != null) { //Some legacy devices may not be supported
        appBarLayout = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_layout, root, false);
        root.addView(appBarLayout, 0); // insert at top

        Toolbar toolbar = (Toolbar) appBarLayout.getChildAt(0);

        final Drawable backarrow = AppCompatDrawableManager.get().getDrawable(this,
                R.drawable.ic_arrow_back_black_24dp);
        backarrow.setColorFilter(ContextCompat.getColor(this, R.color.tintColorDark), PorterDuff.Mode.SRC_ATOP);
        toolbar.setNavigationIcon(backarrow);
        toolbar.setTitle(R.string.title_activity_settings);
        toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.tintColorDark));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = getTheme();
    theme.resolveAttribute(R.attr.rssItemListBackground, typedValue, true);
    int color = typedValue.data;
    getWindow().getDecorView().setBackgroundColor(color);
}

From source file:de.dmxcontrol.activity.ControlActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    SWIPE_MIN_VELOCITY = this.getResources().getInteger(R.integer.swipe_min_velocity);
    SWIPE_MIN_DISTANCE = this.getResources().getInteger(R.integer.swipe_min_distance);
    //Change the EdgeEffectColor to our HighlightColor
    int glowDrawableId = this.getResources().getIdentifier("overscroll_glow", "drawable", "android");
    Drawable androidGlow = this.getResources().getDrawable(glowDrawableId);
    androidGlow.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight),
            PorterDuff.Mode.SRC_IN);/*from  w  w w . j a va  2s.c o m*/

    int edgeDrawableId = this.getResources().getIdentifier("overscroll_edge", "drawable", "android");
    Drawable androidEdge = this.getResources().getDrawable(edgeDrawableId);
    androidEdge.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight),
            PorterDuff.Mode.SRC_IN);

    int scrollBarHDrawableId = this.getResources().getIdentifier("scrollbar_handle_horizontal", "drawable",
            "android");
    Drawable androidscrollBarH = this.getResources().getDrawable(scrollBarHDrawableId);
    androidscrollBarH.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight),
            PorterDuff.Mode.SRC_IN);

    int scrollBarVDrawableId = this.getResources().getIdentifier("scrollbar_handle_vertical", "drawable",
            "android");
    Drawable androidscrollBarV = this.getResources().getDrawable(scrollBarVDrawableId);
    androidscrollBarV.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight),
            PorterDuff.Mode.SRC_IN);

    setContentView(R.layout.root_screen_with_selector_drawer);
    gestureDetector = new GestureDetector(this, this);

    edgeEffect = new EdgeEffect(this);

    if (((DMXControlApplication) getApplication()).getJustStarted() && !DISABLE_SPLASH) {
        showDialog(DIALOG_SPLASH);
    }

    ad = new AboutDialogs(this);
}

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

@Override
public void updateUserPage(User user) {
    //Download avatar if needed.
    Glide.with(this).load(mUser.getAvatarUrl()).diskCacheStrategy(DiskCacheStrategy.ALL).into(avatar);

    //Set the player name
    String name = mUser.getName();
    mCollapsingToolbarLayout.setTitle(name);

    if (mUser.isBanned()) {
        //Set player name to red and cross name out if banned
        // TODO: 2015. 10. 22.
    }//from   www .j  a v  a2s . c  om

    //Set the player reputation.
    playerReputation.setText(String.valueOf(mUser.getReputation()));

    //Set the 'user since' text
    long profileCreated = mUser.getProfileCreated();
    if (profileCreated == -1) {
        userSinceText.setText(getString(R.string.filler_unknown));
    } else {
        userSinceText.setText(Utility.formatUnixTimeStamp(profileCreated));
    }

    //Switch for the player's state
    switch (mUser.getState()) {
    case 0:
        long lastOnline = mUser.getLastOnline();
        if (lastOnline == -1) {
            //Weird
            lastOnlineText.setText(String.format("%s %s", getString(R.string.user_page_last_online),
                    getString(R.string.filler_unknown)));
        } else {
            //Player is offline, show how long was it since the player was last online
            lastOnlineText.setText(String.format("%s %s", getString(R.string.user_page_last_online),
                    Utility.formatLastOnlineTime(mContext, System.currentTimeMillis() - lastOnline * 1000L)));
        }
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.text_primary));
        break;
    case 1:
        lastOnlineText.setText(getString(R.string.user_page_status_online));
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.player_online));
        break;
    case 2:
        lastOnlineText.setText(getString(R.string.user_page_status_busy));
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.player_online));
        break;
    case 3:
        lastOnlineText.setText(getString(R.string.user_page_status_away));
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.player_online));
        break;
    case 4:
        lastOnlineText.setText(getString(R.string.user_page_status_snooze));
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.player_online));
        break;
    case 5:
        lastOnlineText.setText(getString(R.string.user_page_status_trade));
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.player_online));
        break;
    case 6:
        lastOnlineText.setText(getString(R.string.user_page_status_play));
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.player_online));
        break;
    case 7:
        lastOnlineText.setText(getString(R.string.user_page_status_in_game));
        lastOnlineText.setTextColor(ContextCompat.getColor(mContext, R.color.player_in_game));
        break;
    }

    //Load drawables for player statuses
    Drawable statusOk = ContextCompat.getDrawable(getActivity(), R.drawable.ic_done_white_48dp);
    Drawable statusBad = ContextCompat.getDrawable(getActivity(), R.drawable.ic_close_white_48dp);
    if (statusOk != null)
        statusOk.setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
    if (statusBad != null)
        statusBad.setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);

    //Steamrep information
    if (mUser.isScammer()) {
        steamRepStatus.setImageDrawable(statusBad);
    } else {
        steamRepStatus.setImageDrawable(statusOk);
    }

    //Trade status
    if (mUser.isEconomyBanned()) {
        tradeStatus.setImageDrawable(statusBad);
    } else {
        tradeStatus.setImageDrawable(statusOk);
    }

    //VAC status
    if (mUser.isVacBanned()) {
        vacStatus.setImageDrawable(statusBad);
    } else {
        vacStatus.setImageDrawable(statusOk);
    }

    //Community status
    if (mUser.isCommunityBanned()) {
        communityStatus.setImageDrawable(statusBad);
    } else {
        communityStatus.setImageDrawable(statusOk);
    }

    //Backpack value
    double bpValue = mUser.getBackpackValue();

    backpack(privateBackpack);

    if (bpValue == -1) {
        //Value is unknown (probably private)
        backpackValueRefined.setText("?");
        backpackValueUsd.setText("?");
    } else {
        //Properly format the backpack value (is int, does it have a fraction smaller than 0.01)
        backpackValueRefined.setText(String.valueOf(Math.round(bpValue)));

        //Convert the value into USD and format it like above
        double bpValueUsd = bpValue * Utility.getDouble(mPrefs, getString(R.string.pref_metal_raw_usd), 1);
        backpackValueUsd.setText(String.valueOf(Math.round(bpValueUsd)));
    }

    //Set the trust score and color the background according to it.
    trustPositive.setText(String.format(Locale.ENGLISH, "+%d", mUser.getTrustPositive()));
    trustNegative.setText(String.format(Locale.ENGLISH, "-%d", mUser.getTrustNegative()));

    //Raw keys
    int rawKeys = mUser.getRawKeys();
    if (rawKeys >= 0)
        backpackRawKeys.setText(String.valueOf(rawKeys));
    else
        backpackRawKeys.setText("?");

    //Raw metal
    double rawMetal = mUser.getRawMetal();
    if (rawMetal >= 0)
        backpackRawMetal.setText(String.valueOf(Utility.formatDouble(rawMetal)));
    else
        backpackRawMetal.setText("?");

    //Number of slots and slots used
    int itemNumber = mUser.getItemCount();
    int backpackSlotNumber = mUser.getBackpackSlots();
    if (itemNumber >= 0 && backpackSlotNumber >= 0)
        backpackSlots.setText(
                String.format(Locale.ENGLISH, "%s/%d", String.valueOf(itemNumber), backpackSlotNumber));
    else
        backpackSlots.setText("?/?");
}

From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java

private void updateSelectedItem(com.google.android.apps.muzei.room.Source selectedSource,
        boolean allowAnimate) {
    ComponentName previousSelectedSource = mSelectedSource;
    if (selectedSource != null) {
        mSelectedSource = selectedSource.componentName;
    }/*from www . ja  va  2 s. c om*/
    if (previousSelectedSource != null && previousSelectedSource.equals(mSelectedSource)) {
        // Only update status
        for (final Source source : mSources) {
            if (!source.componentName.equals(mSelectedSource) || source.rootView == null) {
                continue;
            }
            updateSourceStatusUi(source);
        }
        return;
    }

    // This is a newly selected source.
    boolean selected;
    int index = -1;
    for (final Source source : mSources) {
        ++index;
        if (source.componentName.equals(previousSelectedSource)) {
            selected = false;
        } else if (source.componentName.equals(mSelectedSource)) {
            mSelectedSourceIndex = index;
            selected = true;
        } else {
            continue;
        }

        if (source.rootView == null) {
            continue;
        }

        View sourceImageButton = source.rootView.findViewById(R.id.source_image);
        Drawable drawable = selected ? mSelectedSourceImage : source.icon;
        drawable.setColorFilter(source.color, PorterDuff.Mode.SRC_ATOP);
        sourceImageButton.setBackground(drawable);

        float alpha = selected ? 1f
                : Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                        && source.targetSdkVersion >= Build.VERSION_CODES.O ? ALPHA_DISABLED : ALPHA_UNSELECTED;
        source.rootView.animate().alpha(alpha).setDuration(mAnimationDuration);

        if (selected) {
            updateSourceStatusUi(source);
        }

        animateSettingsButton(source.settingsButton, selected && source.settingsActivity != null, allowAnimate);
    }

    if (mSelectedSourceIndex >= 0 && allowAnimate) {
        if (mCurrentScroller != null) {
            mCurrentScroller.cancel();
        }

        // For some reason smoothScrollTo isn't very smooth..
        mCurrentScroller = ObjectAnimator.ofInt(mSourceScrollerView, "scrollX",
                mItemWidth * mSelectedSourceIndex);
        mCurrentScroller.setDuration(mAnimationDuration);
        mCurrentScroller.start();
    }
}

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

private void openMenu(final View view, final ParcelableStatus status) {
    mSelectedStatus = status;/* www  . j  a  va  2 s.  c om*/
    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:it.ndorigatti.android.view.MulticolorProgressBar.java

/**
 * Update the progress colors// ww w  . j a va2  s  .  c  om
 *
 * @param id
 * @param color
 */
private void doUpdateProgressColor(int id, int color) {
    LayerDrawable layerDrawable = (LayerDrawable) mStraightDrawable;
    LayerDrawable reverseLayerDrawable = (LayerDrawable) mReversedDrawable;
    Drawable mOverlayProgressDrawable = layerDrawable.findDrawableByLayerId(id);
    mOverlayProgressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    mOverlayProgressDrawable = reverseLayerDrawable.findDrawableByLayerId(id);
    mOverlayProgressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}