/** * 动画工具类 * Created by xiaoqiu on 2023/7/1. */ public class AnimationFloatUtil { private long startTs; private int duration; private float floatStartValue; private float floatEndValue; private float floatNowValue; private boolean isData; public void start(int duration, float startValue, float endValue) { this.duration = duration; this.floatStartValue = ((this.duration != 0) && isData) ? floatNowValue : startValue; this.floatEndValue = endValue; this.startTs = System.currentTimeMillis(); } public void reset() { isData = false; } public float getFloatValue() { if (duration == 0) { floatNowValue = floatEndValue; } else { isData = true; long t = System.currentTimeMillis(); long tt = t - startTs; if (tt > 0 && tt < duration) { float d = ((float) tt) / (float) duration; floatNowValue = floatStartValue + ((floatEndValue - floatStartValue) * d); } else { floatNowValue = floatEndValue; } } return floatNowValue; } }
/** * 动画工具类 * Created by xiaoqiu on 2023/7/1. */ public class AnimationUtil { private long startTs; private int duration; private long floatStartValue; private long floatEndValue; private long floatNowValue; private boolean isData; public void start(int duration, long startValue, long endValue) { this.duration = duration; this.floatStartValue = ((this.duration != 0) && isData) ? floatNowValue : startValue; this.floatEndValue = endValue; this.startTs = System.currentTimeMillis(); } public void reset() { isData = false; } public long getFloatValue() { if (duration == 0) { floatNowValue = floatEndValue; } else { isData = true; long t = System.currentTimeMillis(); long tt = t - startTs; if (tt > 0 && tt < duration) { double d = ((double) tt) / (float) duration; floatNowValue = (long) (((double)floatStartValue) + ((((double)floatEndValue) - (double) floatStartValue) * d)); } else { floatNowValue = floatEndValue; } } return floatNowValue; } }