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;
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations