wxr
2022-11-24 2af932533ef851bf983385244e9912976dbd4daa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.mm.android.deviceaddmodule.mobilecommon.widget.linechart.touch;
 
import android.os.SystemClock;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
 
public class Zoomer {
 
    long _startTime;
    int _duration = 500;// 动画的持续时间
    Interpolator _Interpolator;//校对机
 
    float _endZoom;
    float _currentLevel;
 
    boolean _isFinish = true;
 
 
    public Zoomer() {
        _Interpolator = new LinearInterpolator();
    }
 
    public void startZoom(float endZoom) {
        _startTime = SystemClock.elapsedRealtime();
        _endZoom = endZoom;
        _currentLevel = 1;
        _isFinish = false;
    }
 
    public float getCurrentZoom() {
        return _currentLevel;
    }
 
 
    /**
     * 计算当前的缩放级别
     *
     * @return true:需要计算,false:不需要计算
     */
    public boolean computeZoom() {
        if (_isFinish) {
            return false;
        }
 
        long d = SystemClock.elapsedRealtime() - _startTime;
        if (d > _duration) {
            _currentLevel = _endZoom;
            _isFinish = true;
            return false;
        }
 
        float t = d * 1f / _duration;
        _currentLevel = 1 - (1 - _endZoom) * _Interpolator.getInterpolation(t);
        return true;
    }
 
    public void stop() {
        _isFinish = true;
    }
 
 
    public long get_duration() {
        return _duration;
    }
 
    public void set_duration(int _duration) {
        this._duration = _duration;
    }
}