admin
2021-07-06 abce02c7a61820f5d580f87364d542e817be429c
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.wpc.library.widget.TitleBar;
 
import android.graphics.PointF;
 
public class MotionEventIndicator {
 
    private PointF mPtLastMove = new PointF();
    private long mLastTime = 0;
    private float mOffsetX;
    private float mOffsetY;
    private long mOffsetTime;
    private int mCurrentPos = 0;
    private int mLastPos = 0;
    private int mHeaderMaxHeight;
    private int mHeaderMinHeight;
    private int mPressedPos = 0;
    private boolean isFirst = true;
 
    private boolean mIsUnderTouch = false;
    // record the refresh complete position
    private int mRefreshCompleteY = 0;
 
    public boolean isUnderTouch() {
        return mIsUnderTouch;
    }
 
    public void onRelease() {
        mIsUnderTouch = false;
    }
 
    public void onUIRefreshComplete() {
        mRefreshCompleteY = mCurrentPos;
    }
 
    public boolean goDownCrossFinishPosition() {
        return mCurrentPos >= mRefreshCompleteY;
    }
 
    protected void processOnMove(float currentX, float currentY, float offsetX, float offsetY) {
        setOffset(offsetX, offsetY);
    }
 
    public void onPressDown(float x, float y, long time) {
        mIsUnderTouch = true;
        mPressedPos = mCurrentPos;
        mPtLastMove.set(x, y);
        mLastTime = time;
    }
 
    public final void onMove(float x, float y, long time) {
        float offsetX = x - mPtLastMove.x;
        float offsetY = (y - mPtLastMove.y);
        mOffsetTime = time - mLastTime;
        processOnMove(x, y, offsetX, offsetY);
        mPtLastMove.set(x, y);
        mLastTime = time;
    }
 
    public long getOffsetTime() {
        return mOffsetTime;
    }
 
    protected void setOffset(float x, float y) {
        mOffsetX = x;
        mOffsetY = y;
    }
 
    public float getOffsetX() {
        return mOffsetX;
    }
 
    public float getOffsetY() {
        return mOffsetY;
    }
 
    public int getLastPosY() {
        return mLastPos;
    }
 
    public int getCurrentPosY() {
        return mCurrentPos;
    }
 
    /**
     * Update current position before update the UI
     */
    public final void setCurrentPos(int current) {
        mLastPos = mCurrentPos;
        mCurrentPos = current;
    }
 
    public final void setCurrentPosIfFirst(int current) {
        if (isFirst) {
            mCurrentPos = current;
            isFirst = false;
        }
    }
 
    public int getMinHeight() {
        return mHeaderMinHeight;
    }
 
    public int getMaxHeight() {
        return mHeaderMaxHeight;
    }
 
    public void setHeight(int mHeaderMaxHeight, int mHeaderMinHeight) {
        this.mHeaderMaxHeight = mHeaderMaxHeight;
        this.mHeaderMinHeight = mHeaderMinHeight;
    }
 
    public void setHeight(int mHeaderMaxHeight) {
        setHeight(mHeaderMaxHeight, 0);
    }
 
    public boolean reachMinHeight() {
        return mCurrentPos <= mHeaderMinHeight;
    }
 
    public boolean reachMaxHeight() {
        return mCurrentPos >= mHeaderMaxHeight;
    }
 
    public boolean willOverTop(int to) {
        return to <= mHeaderMinHeight;
    }
 
    public boolean willOverBottom(int to) {
        return to >= mHeaderMaxHeight;
    }
 
    public boolean hasMovedAfterPressedDown() {
        return mCurrentPos != mPressedPos;
    }
 
    public boolean isAlreadyHere(int to) {
        return mCurrentPos == to;
    }
 
    public float getLastPercent() {
        final float oldPercent = mHeaderMaxHeight == 0 ? 0 : (mLastPos - mHeaderMinHeight) * 1f / (mHeaderMaxHeight - mHeaderMinHeight);
        return oldPercent;
    }
 
    public float getCurrentPercent() {
        final float currentPercent = mHeaderMaxHeight == 0 ? 0 : (mCurrentPos - mHeaderMinHeight) * 1f / (mHeaderMaxHeight - mHeaderMinHeight);
        return currentPercent;
    }
}