use of io.plaidapp.util.ObservableColorMatrix 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);
}
Aggregations