SnapHelper.java
5.46 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
package android.support.v7.widget;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.Scroller;
public abstract class SnapHelper
extends RecyclerView.OnFlingListener
{
RecyclerView a;
private Scroller b;
private final RecyclerView.OnScrollListener c = new RecyclerView.OnScrollListener()
{
boolean a = false;
public final void onScrollStateChanged(RecyclerView paramAnonymousRecyclerView, int paramAnonymousInt)
{
super.onScrollStateChanged(paramAnonymousRecyclerView, paramAnonymousInt);
if ((paramAnonymousInt == 0) && (this.a))
{
this.a = false;
SnapHelper.this.a();
}
}
public final void onScrolled(RecyclerView paramAnonymousRecyclerView, int paramAnonymousInt1, int paramAnonymousInt2)
{
if ((paramAnonymousInt1 != 0) || (paramAnonymousInt2 != 0)) {
this.a = true;
}
}
};
final void a()
{
if (this.a == null) {}
Object localObject;
do
{
View localView;
do
{
do
{
return;
localObject = this.a.getLayoutManager();
} while (localObject == null);
localView = findSnapView((RecyclerView.LayoutManager)localObject);
} while (localView == null);
localObject = calculateDistanceToFinalSnap((RecyclerView.LayoutManager)localObject, localView);
} while ((localObject[0] == 0) && (localObject[1] == 0));
this.a.smoothScrollBy(localObject[0], localObject[1]);
}
public void attachToRecyclerView(@Nullable RecyclerView paramRecyclerView)
throws IllegalStateException
{
if (this.a == paramRecyclerView) {}
do
{
return;
if (this.a != null)
{
this.a.removeOnScrollListener(this.c);
this.a.setOnFlingListener(null);
}
this.a = paramRecyclerView;
} while (this.a == null);
if (this.a.getOnFlingListener() != null) {
throw new IllegalStateException("An instance of OnFlingListener already set.");
}
this.a.addOnScrollListener(this.c);
this.a.setOnFlingListener(this);
this.b = new Scroller(this.a.getContext(), new DecelerateInterpolator());
a();
}
@Nullable
public abstract int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager paramLayoutManager, @NonNull View paramView);
public int[] calculateScrollDistance(int paramInt1, int paramInt2)
{
this.b.fling(0, 0, paramInt1, paramInt2, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
return new int[] { this.b.getFinalX(), this.b.getFinalY() };
}
@Nullable
protected LinearSmoothScroller createSnapScroller(RecyclerView.LayoutManager paramLayoutManager)
{
if (!(paramLayoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return null;
}
new LinearSmoothScroller(this.a.getContext())
{
protected final float calculateSpeedPerPixel(DisplayMetrics paramAnonymousDisplayMetrics)
{
return 100.0F / paramAnonymousDisplayMetrics.densityDpi;
}
protected final void onTargetFound(View paramAnonymousView, RecyclerView.State paramAnonymousState, RecyclerView.SmoothScroller.Action paramAnonymousAction)
{
paramAnonymousView = SnapHelper.this.calculateDistanceToFinalSnap(SnapHelper.this.a.getLayoutManager(), paramAnonymousView);
int i = paramAnonymousView[0];
int j = paramAnonymousView[1];
int k = calculateTimeForDeceleration(Math.max(Math.abs(i), Math.abs(j)));
if (k > 0) {
paramAnonymousAction.update(i, j, k, this.mDecelerateInterpolator);
}
}
};
}
@Nullable
public abstract View findSnapView(RecyclerView.LayoutManager paramLayoutManager);
public abstract int findTargetSnapPosition(RecyclerView.LayoutManager paramLayoutManager, int paramInt1, int paramInt2);
public boolean onFling(int paramInt1, int paramInt2)
{
RecyclerView.LayoutManager localLayoutManager = this.a.getLayoutManager();
if (localLayoutManager == null) {}
for (;;)
{
return false;
if (this.a.getAdapter() != null)
{
int i = this.a.getMinFlingVelocity();
if ((Math.abs(paramInt2) > i) || (Math.abs(paramInt1) > i))
{
if (!(localLayoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
paramInt1 = 0;
}
while (paramInt1 != 0)
{
return true;
LinearSmoothScroller localLinearSmoothScroller = createSnapScroller(localLayoutManager);
if (localLinearSmoothScroller == null)
{
paramInt1 = 0;
}
else
{
paramInt1 = findTargetSnapPosition(localLayoutManager, paramInt1, paramInt2);
if (paramInt1 == -1)
{
paramInt1 = 0;
}
else
{
localLinearSmoothScroller.setTargetPosition(paramInt1);
localLayoutManager.startSmoothScroll(localLinearSmoothScroller);
paramInt1 = 1;
}
}
}
}
}
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/android/support/v7/widget/SnapHelper.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/