Search in sources :

Example 56 with ColorFilter

use of android.graphics.ColorFilter in project Lightning-Browser by anthonycr.

the class ThemeUtils method getThemedBitmap.

/**
     * Gets the icon with an applied color filter
     * for the correct theme.
     *
     * @param context the context to use.
     * @param res     the drawable resource to use.
     * @param dark    true for icon suitable for use with a dark theme,
     *                false for icon suitable for use with a light theme.
     * @return a themed icon.
     */
@NonNull
public static Bitmap getThemedBitmap(@NonNull Context context, @DrawableRes int res, boolean dark) {
    int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
    Bitmap sourceBitmap = getBitmapFromVectorDrawable(context, res);
    Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Paint p = new Paint();
    ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    p.setColorFilter(filter);
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(sourceBitmap, 0, 0, p);
    sourceBitmap.recycle();
    return resultBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) ColorFilter(android.graphics.ColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Canvas(android.graphics.Canvas) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) Paint(android.graphics.Paint) NonNull(android.support.annotation.NonNull)

Example 57 with ColorFilter

use of android.graphics.ColorFilter in project devbricks by dailystudio.

the class GifImageView method setViewAttributes.

@SuppressLint("NewApi")
private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) {
    /**
     * Starting from HONEYCOMB have to turn off HW acceleration to draw
     * Movie on Canvas.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifMovieView, defStyle, 0);
    if (array.hasValue(R.styleable.GifMovieView_tintColor)) {
        mTintColor = array.getColor(R.styleable.GifMovieView_tintColor, ColorHelper.getColorResource(getContext(), R.color.android_blue));
        mHasTintColor = true;
    }
    mMovieResourceId = array.getResourceId(R.styleable.GifMovieView_gif, -1);
    mPaused = array.getBoolean(R.styleable.GifMovieView_paused, false);
    mFillCanvas = array.getBoolean(R.styleable.GifMovieView_fill, false);
    array.recycle();
    if (mMovieResourceId != -1) {
        mMovie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId));
    }
    if (mHasTintColor) {
        mTintPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        ColorFilter filter = new PorterDuffColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
        mTintPaint.setColorFilter(filter);
    }
}
Also used : ColorFilter(android.graphics.ColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) TypedArray(android.content.res.TypedArray) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 58 with ColorFilter

use of android.graphics.ColorFilter in project GzuClassSchedule by mnnyang.

the class WheelView method setBackgroundDrawable.

@Override
public void setBackgroundDrawable(Drawable background) {
    if (viewWidth == 0) {
        viewWidth = ((Activity) context).getWindowManager().getDefaultDisplay().getWidth();
        Log.d(TAG, "viewWidth: " + viewWidth);
    }
    if (null == paint) {
        paint = new Paint();
        paint.setColor(ColorUtil.getColor(context, R.attr.colorPrimary));
        paint.setStrokeWidth(dip2px(1f));
    }
    background = new Drawable() {

        @Override
        public void draw(Canvas canvas) {
            canvas.drawLine(viewWidth * 1 / 6, obtainSelectedAreaBorder()[0], viewWidth * 5 / 6, obtainSelectedAreaBorder()[0], paint);
            canvas.drawLine(viewWidth * 1 / 6, obtainSelectedAreaBorder()[1], viewWidth * 5 / 6, obtainSelectedAreaBorder()[1], paint);
        }

        @Override
        public void setAlpha(int alpha) {
        }

        @Override
        public void setColorFilter(ColorFilter cf) {
        }

        @SuppressLint("WrongConstant")
        @Override
        public int getOpacity() {
            return 0;
        }
    };
    super.setBackgroundDrawable(background);
}
Also used : ColorFilter(android.graphics.ColorFilter) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 59 with ColorFilter

use of android.graphics.ColorFilter in project android_packages_apps_Dialer by LineageOS.

the class PseudoEmergencyAnimator method start.

public void start() {
    if (mPseudoEmergencyColorAnimator == null) {
        Integer colorFrom = Color.BLUE;
        Integer colorTo = Color.RED;
        mPseudoEmergencyColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        mPseudoEmergencyColorAnimator.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                try {
                    int color = (int) animator.getAnimatedValue();
                    ColorFilter colorFilter = new LightingColorFilter(Color.BLACK, color);
                    View floatingActionButtonContainer = getView().findViewById(R.id.floating_action_button);
                    if (floatingActionButtonContainer != null) {
                        floatingActionButtonContainer.getBackground().setColorFilter(colorFilter);
                    }
                } catch (Exception e) {
                    animator.cancel();
                }
            }
        });
        mPseudoEmergencyColorAnimator.addListener(new AnimatorListener() {

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                try {
                    vibrate(VIBRATE_LENGTH_MILLIS);
                } catch (Exception e) {
                    animation.cancel();
                }
            }

            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                try {
                    View floatingActionButtonContainer = getView().findViewById(R.id.floating_action_button);
                    if (floatingActionButtonContainer != null) {
                        floatingActionButtonContainer.getBackground().clearColorFilter();
                    }
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                vibrate(VIBRATE_LENGTH_MILLIS);
                            } catch (Exception e) {
                            // ignored
                            }
                        }
                    }, ITERATION_LENGTH_MILLIS);
                } catch (Exception e) {
                    animation.cancel();
                }
            }
        });
        mPseudoEmergencyColorAnimator.setDuration(VIBRATE_LENGTH_MILLIS);
        mPseudoEmergencyColorAnimator.setRepeatMode(ValueAnimator.REVERSE);
        mPseudoEmergencyColorAnimator.setRepeatCount(ANIMATION_ITERATION_COUNT);
    }
    if (!mPseudoEmergencyColorAnimator.isStarted()) {
        mPseudoEmergencyColorAnimator.start();
    }
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) Handler(android.os.Handler) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) AnimatorListener(android.animation.Animator.AnimatorListener) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LightingColorFilter(android.graphics.LightingColorFilter)

Example 60 with ColorFilter

use of android.graphics.ColorFilter in project PhoneProfiles by henrichg.

the class BitmapManipulator method recolorBitmap.

static Bitmap recolorBitmap(Bitmap bitmap, int color) {
    if (bitmap == null)
        return null;
    Bitmap colorBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    // Config.ARGB_8888);
    Canvas canvas = new Canvas(colorBitmap);
    Paint paint = new Paint();
    Matrix matrix = new Matrix();
    ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    canvas.drawBitmap(bitmap, matrix, paint);
    return colorBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) ColorFilter(android.graphics.ColorFilter) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Canvas(android.graphics.Canvas) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint)

Aggregations

ColorFilter (android.graphics.ColorFilter)75 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)26 LightingColorFilter (android.graphics.LightingColorFilter)25 Paint (android.graphics.Paint)25 Drawable (android.graphics.drawable.Drawable)23 Canvas (android.graphics.Canvas)14 FilterableStateListDrawable (com.simplecity.amp_library.ui.views.FilterableStateListDrawable)14 LayerDrawable (android.graphics.drawable.LayerDrawable)12 Bitmap (android.graphics.Bitmap)11 View (android.view.View)7 Test (org.junit.Test)7 Path (android.graphics.Path)5 Rect (android.graphics.Rect)5 RectF (android.graphics.RectF)5 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Animator (android.animation.Animator)3 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3