LinearSmoothScroller.java
6.59 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package android.support.v7.widget;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.PointF;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
public class LinearSmoothScroller
extends RecyclerView.SmoothScroller
{
public static final int SNAP_TO_ANY = 0;
public static final int SNAP_TO_END = 1;
public static final int SNAP_TO_START = -1;
private final float a = calculateSpeedPerPixel(paramContext.getResources().getDisplayMetrics());
protected final DecelerateInterpolator mDecelerateInterpolator = new DecelerateInterpolator();
protected int mInterimTargetDx = 0;
protected int mInterimTargetDy = 0;
protected final LinearInterpolator mLinearInterpolator = new LinearInterpolator();
protected PointF mTargetVector;
public LinearSmoothScroller(Context paramContext) {}
private static int a(int paramInt1, int paramInt2)
{
int i = paramInt1 - paramInt2;
paramInt2 = i;
if (paramInt1 * i <= 0) {
paramInt2 = 0;
}
return paramInt2;
}
public int calculateDtToFit(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5)
{
switch (paramInt5)
{
default:
throw new IllegalArgumentException("snap preference should be one of the constants defined in SmoothScroller, starting with SNAP_");
case -1:
paramInt1 = paramInt3 - paramInt1;
}
do
{
do
{
return paramInt1;
return paramInt4 - paramInt2;
paramInt3 -= paramInt1;
paramInt1 = paramInt3;
} while (paramInt3 > 0);
paramInt2 = paramInt4 - paramInt2;
paramInt1 = paramInt2;
} while (paramInt2 < 0);
return 0;
}
public int calculateDxToMakeVisible(View paramView, int paramInt)
{
RecyclerView.LayoutManager localLayoutManager = getLayoutManager();
if ((localLayoutManager == null) || (!localLayoutManager.canScrollHorizontally())) {
return 0;
}
RecyclerView.LayoutParams localLayoutParams = (RecyclerView.LayoutParams)paramView.getLayoutParams();
return calculateDtToFit(localLayoutManager.getDecoratedLeft(paramView) - localLayoutParams.leftMargin, localLayoutManager.getDecoratedRight(paramView) + localLayoutParams.rightMargin, localLayoutManager.getPaddingLeft(), localLayoutManager.getWidth() - localLayoutManager.getPaddingRight(), paramInt);
}
public int calculateDyToMakeVisible(View paramView, int paramInt)
{
RecyclerView.LayoutManager localLayoutManager = getLayoutManager();
if ((localLayoutManager == null) || (!localLayoutManager.canScrollVertically())) {
return 0;
}
RecyclerView.LayoutParams localLayoutParams = (RecyclerView.LayoutParams)paramView.getLayoutParams();
return calculateDtToFit(localLayoutManager.getDecoratedTop(paramView) - localLayoutParams.topMargin, localLayoutManager.getDecoratedBottom(paramView) + localLayoutParams.bottomMargin, localLayoutManager.getPaddingTop(), localLayoutManager.getHeight() - localLayoutManager.getPaddingBottom(), paramInt);
}
protected float calculateSpeedPerPixel(DisplayMetrics paramDisplayMetrics)
{
return 25.0F / paramDisplayMetrics.densityDpi;
}
protected int calculateTimeForDeceleration(int paramInt)
{
return (int)Math.ceil(calculateTimeForScrolling(paramInt) / 0.3356D);
}
protected int calculateTimeForScrolling(int paramInt)
{
return (int)Math.ceil(Math.abs(paramInt) * this.a);
}
@Nullable
public PointF computeScrollVectorForPosition(int paramInt)
{
RecyclerView.LayoutManager localLayoutManager = getLayoutManager();
if ((localLayoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return ((RecyclerView.SmoothScroller.ScrollVectorProvider)localLayoutManager).computeScrollVectorForPosition(paramInt);
}
Log.w("LinearSmoothScroller", "You should override computeScrollVectorForPosition when the LayoutManager does not implement " + RecyclerView.SmoothScroller.ScrollVectorProvider.class.getCanonicalName());
return null;
}
protected int getHorizontalSnapPreference()
{
if ((this.mTargetVector == null) || (this.mTargetVector.x == 0.0F)) {
return 0;
}
if (this.mTargetVector.x > 0.0F) {
return 1;
}
return -1;
}
protected int getVerticalSnapPreference()
{
if ((this.mTargetVector == null) || (this.mTargetVector.y == 0.0F)) {
return 0;
}
if (this.mTargetVector.y > 0.0F) {
return 1;
}
return -1;
}
protected void onSeekTargetStep(int paramInt1, int paramInt2, RecyclerView.State paramState, RecyclerView.SmoothScroller.Action paramAction)
{
if (getChildCount() == 0) {
stop();
}
do
{
return;
this.mInterimTargetDx = a(this.mInterimTargetDx, paramInt1);
this.mInterimTargetDy = a(this.mInterimTargetDy, paramInt2);
} while ((this.mInterimTargetDx != 0) || (this.mInterimTargetDy != 0));
updateActionForInterimTarget(paramAction);
}
protected void onStart() {}
protected void onStop()
{
this.mInterimTargetDy = 0;
this.mInterimTargetDx = 0;
this.mTargetVector = null;
}
protected void onTargetFound(View paramView, RecyclerView.State paramState, RecyclerView.SmoothScroller.Action paramAction)
{
int i = calculateDxToMakeVisible(paramView, getHorizontalSnapPreference());
int j = calculateDyToMakeVisible(paramView, getVerticalSnapPreference());
int k = calculateTimeForDeceleration((int)Math.sqrt(i * i + j * j));
if (k > 0) {
paramAction.update(-i, -j, k, this.mDecelerateInterpolator);
}
}
protected void updateActionForInterimTarget(RecyclerView.SmoothScroller.Action paramAction)
{
PointF localPointF = computeScrollVectorForPosition(getTargetPosition());
if ((localPointF == null) || ((localPointF.x == 0.0F) && (localPointF.y == 0.0F)))
{
paramAction.jumpTo(getTargetPosition());
stop();
return;
}
normalize(localPointF);
this.mTargetVector = localPointF;
this.mInterimTargetDx = ((int)(localPointF.x * 10000.0F));
this.mInterimTargetDy = ((int)(localPointF.y * 10000.0F));
int i = calculateTimeForScrolling(10000);
paramAction.update((int)(this.mInterimTargetDx * 1.2F), (int)(this.mInterimTargetDy * 1.2F), (int)(i * 1.2F), this.mLinearInterpolator);
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/android/support/v7/widget/LinearSmoothScroller.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/