ImageViewTintUtils.java 文件源码

java
阅读 15 收藏 0 点赞 0 评论 0

项目:revolution-irc 作者:
public static void animateTint(ImageView view, int from, int to, int duration) {
    final float[] fromHSL = new float[3];
    final float[] toHSL = new float[3];
    float[] currentHSL = new float[3];
    ColorUtils.colorToHSL(from, fromHSL);
    ColorUtils.colorToHSL(to, toHSL);
    int fromAlpha = Color.alpha(from);
    int toAlpha = Color.alpha(to);

    final ValueAnimator anim = ObjectAnimator.ofFloat(0f, 1f);
    anim.addUpdateListener((ValueAnimator animation) -> {
        float mul = (Float) animation.getAnimatedValue();
        ColorUtils.blendHSL(fromHSL, toHSL, mul, currentHSL);
        int color = ColorUtils.HSLToColor(currentHSL);
        color = ColorUtils.setAlphaComponent(color, fromAlpha +
                (int) ((toAlpha - fromAlpha) * mul));
        setTint(view, color);
    });
    anim.setDuration(duration);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.start();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号