Search in sources :

Example 1 with ColorMatrix

use of android.graphics.ColorMatrix in project Launcher3 by chislon.

the class Utilities method initStatics.

private static void initStatics(Context context) {
    final Resources resources = context.getResources();
    final DisplayMetrics metrics = resources.getDisplayMetrics();
    final float density = metrics.density;
    sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size);
    sIconTextureWidth = sIconTextureHeight = sIconWidth;
    sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
    sGlowColorPressedPaint.setColor(0xffffc300);
    sGlowColorFocusedPaint.setColor(0xffff8e00);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0.2f);
    sDisabledPaint.setColorFilter(new ColorMatrixColorFilter(cm));
    sDisabledPaint.setAlpha(0x88);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix) BlurMaskFilter(android.graphics.BlurMaskFilter) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 2 with ColorMatrix

use of android.graphics.ColorMatrix in project Fairphone by Kwamecorp.

the class Utilities method initStatics.

private static void initStatics(Context context) {
    final Resources resources = context.getResources();
    final DisplayMetrics metrics = resources.getDisplayMetrics();
    final float density = metrics.density;
    sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size);
    sIconTextureWidth = sIconTextureHeight = sIconWidth;
    sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
    sGlowColorPressedPaint.setColor(0xffffc300);
    sGlowColorFocusedPaint.setColor(0xffff8e00);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0.2f);
    sDisabledPaint.setColorFilter(new ColorMatrixColorFilter(cm));
    sDisabledPaint.setAlpha(0x88);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix) BlurMaskFilter(android.graphics.BlurMaskFilter) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 3 with ColorMatrix

use of android.graphics.ColorMatrix in project 9GAG by Mixiaoxiao.

the class SquareProgressBar method setImageGrayscale.

/**
	 * You can set the image to b/w with this method. Works fine with the
	 * opacity.
	 * 
	 * @param greyscale
	 *            true if the grayscale should be activated.
	 * @since 1.2.0 / but never used in the example application
	 */
public void setImageGrayscale(boolean greyscale) {
    this.greyscale = greyscale;
    if (greyscale) {
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0);
        imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
    } else {
        imageView.setColorFilter(null);
    }
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix)

Example 4 with ColorMatrix

use of android.graphics.ColorMatrix in project Carbon by ZieIony.

the class AnimUtils method brightnessSaturationFadeIn.

public static ValueAnimator brightnessSaturationFadeIn(final ImageView imageView, Animator.AnimatorListener listener) {
    final ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
    final AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator();
    animator.setInterpolator(interpolator);
    animator.setDuration(800);
    if (listener != null)
        animator.addListener(listener);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        ColorMatrix saturationMatrix = new ColorMatrix();

        ColorMatrix brightnessMatrix = new ColorMatrix();

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float fraction = animator.getAnimatedFraction();
            saturationMatrix.setSaturation((Float) animator.getAnimatedValue());
            float scale = 2 - interpolator.getInterpolation(Math.min(fraction * 4 / 3, 1));
            brightnessMatrix.setScale(scale, scale, scale, interpolator.getInterpolation(Math.min(fraction * 2, 1)));
            saturationMatrix.preConcat(brightnessMatrix);
            imageView.setColorFilter(new ColorMatrixColorFilter(saturationMatrix));
            if (imageView.getParent() != null)
                ((View) imageView.getParent()).postInvalidate();
        }
    });
    animator.start();
    return animator;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ColorMatrix(android.graphics.ColorMatrix) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) ShadowView(carbon.shadow.ShadowView)

Example 5 with ColorMatrix

use of android.graphics.ColorMatrix in project robolectric by robolectric.

the class ShadowBitmapDrawableTest method withColorFilterSet_draw_shouldCopyDescriptionToCanvas.

@Test
public void withColorFilterSet_draw_shouldCopyDescriptionToCanvas() throws Exception {
    BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
    drawable.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix()));
    Canvas canvas = new Canvas();
    drawable.draw(canvas);
    assertThat(shadowOf(canvas).getDescription()).isEqualTo("Bitmap for resource:org.robolectric:drawable/an_image with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>");
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Aggregations

ColorMatrix (android.graphics.ColorMatrix)46 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)46 Paint (android.graphics.Paint)29 Canvas (android.graphics.Canvas)28 Bitmap (android.graphics.Bitmap)27 Resources (android.content.res.Resources)4 BlurMaskFilter (android.graphics.BlurMaskFilter)4 Rect (android.graphics.Rect)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 DisplayMetrics (android.util.DisplayMetrics)4 ImageView (android.widget.ImageView)4 Drawable (android.graphics.drawable.Drawable)3 Matrix (android.graphics.Matrix)2 Path (android.graphics.Path)2 View (android.view.View)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 ShadowView (carbon.shadow.ShadowView)2 ShortcutPickHelper (com.android.settingslib.cm.ShortcutPickHelper)2 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)2 Test (org.junit.Test)2