Search in sources :

Example 1 with ColorMatrixColorFilter

use of android.graphics.ColorMatrixColorFilter 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 2 with ColorMatrixColorFilter

use of android.graphics.ColorMatrixColorFilter in project PhotoPicker by donglua.

the class ImagePagerFragment method setSaturation.

/**
   * This is called by the colorizing animator. It sets a saturation factor that is then
   * passed onto a filter on the picture's drawable.
   * @param value saturation
   */
public void setSaturation(float value) {
    colorizerMatrix.setSaturation(value);
    ColorMatrixColorFilter colorizerFilter = new ColorMatrixColorFilter(colorizerMatrix);
    mViewPager.getBackground().setColorFilter(colorizerFilter);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter)

Example 3 with ColorMatrixColorFilter

use of android.graphics.ColorMatrixColorFilter in project plaid by nickbutcher.

the class FeedAdapter method bindDribbbleShotHolder.

private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) {
    final int[] imageSize = shot.images.bestSize();
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                holder.image.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        holder.image.setColorFilter(new ColorMatrixColorFilter(cm));
                    }
                });
                saturation.setDuration(2000L);
                saturation.setInterpolator(getFastOutSlowInInterpolator(host));
                saturation.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.image.clearColorFilter();
                        holder.image.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]).diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1]).into(new DribbbleTarget(holder.image, false));
    // need both placeholder & background to prevent seeing through shot as it fades in
    holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]);
    holder.image.showBadge(shot.animated);
    // need a unique transition name per shot, let's use it's url
    holder.image.setTransitionName(shot.html_url);
}
Also used : DribbbleTarget(io.plaidapp.util.glide.DribbbleTarget) RequestListener(com.bumptech.glide.request.RequestListener) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Target(com.bumptech.glide.request.target.Target) DribbbleTarget(io.plaidapp.util.glide.DribbbleTarget) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ObservableColorMatrix(io.plaidapp.util.ObservableColorMatrix) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 4 with ColorMatrixColorFilter

use of android.graphics.ColorMatrixColorFilter in project android_frameworks_base by ResurrectionRemix.

the class NotificationCustomViewWrapper method updateGrayscale.

protected void updateGrayscale(boolean dark) {
    if (dark) {
        updateGrayscaleMatrix(1f);
        mGreyPaint.setColorFilter(new ColorMatrixColorFilter(mGrayscaleColorMatrix));
        mView.setLayerPaint(mGreyPaint);
    }
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter)

Example 5 with ColorMatrixColorFilter

use of android.graphics.ColorMatrixColorFilter in project android_frameworks_base by ResurrectionRemix.

the class ImageHelper method toGrayscale.

private static Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();
    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorMatrix cm = new ColorMatrix();
    final Rect rect = new Rect(0, 0, width, height);
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, rect, rect, paint);
    return bmpGrayscale;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)130 ColorMatrix (android.graphics.ColorMatrix)86 Paint (android.graphics.Paint)66 Canvas (android.graphics.Canvas)55 Bitmap (android.graphics.Bitmap)53 ImageView (android.widget.ImageView)9 ValueAnimator (android.animation.ValueAnimator)8 View (android.view.View)8 Animator (android.animation.Animator)6 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)6 ObjectAnimator (android.animation.ObjectAnimator)6 Rect (android.graphics.Rect)5 TextView (android.widget.TextView)5 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)5 Resources (android.content.res.Resources)4 BlurMaskFilter (android.graphics.BlurMaskFilter)4 Matrix (android.graphics.Matrix)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 Drawable (android.graphics.drawable.Drawable)4 RecyclerView (android.support.v7.widget.RecyclerView)4