-
Notifications
You must be signed in to change notification settings - Fork 106
/
CustomScrollerViewProvider.java
93 lines (81 loc) · 3.75 KB
/
CustomScrollerViewProvider.java
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
package com.futuremind.recyclerviewfastscroll.example.customview;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.futuremind.recyclerviewfastscroll.viewprovider.DefaultBubbleBehavior;
import com.futuremind.recyclerviewfastscroll.RecyclerViewScrollListener;
import com.futuremind.recyclerviewfastscroll.viewprovider.ScrollerViewProvider;
import com.futuremind.recyclerviewfastscroll.Utils;
import com.futuremind.recyclerviewfastscroll.viewprovider.ViewBehavior;
import com.futuremind.recyclerviewfastscroll.viewprovider.VisibilityAnimationManager;
import com.futuremind.recyclerviewfastscroll.example.R;
/**
* Created by Michal on 05/08/16.
*/
public class CustomScrollerViewProvider extends ScrollerViewProvider {
private TextView bubble;
private View handle;
@Override
public View provideHandleView(ViewGroup container) {
handle = new View(getContext());
int dimen = getContext().getResources().getDimensionPixelSize(R.dimen.custom_handle_size);
handle.setLayoutParams(new ViewGroup.LayoutParams(dimen, dimen));
Utils.setBackground(handle, drawCircle(dimen, dimen, ContextCompat.getColor(getContext(), R.color.custom_handle_color)));
handle.setVisibility(View.INVISIBLE);
return handle;
}
@Override
public View provideBubbleView(ViewGroup container) {
bubble = new TextView(getContext());
int dimen = getContext().getResources().getDimensionPixelSize(R.dimen.custom_bubble_size);
bubble.setLayoutParams(new ViewGroup.LayoutParams(dimen, dimen));
Utils.setBackground(bubble, drawCircle(dimen, dimen, ContextCompat.getColor(getContext(), R.color.custom_bubble_color)));
bubble.setVisibility(View.INVISIBLE);
bubble.setGravity(Gravity.CENTER);
bubble.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
getScroller().addScrollerListener(new RecyclerViewScrollListener.ScrollerListener() {
@Override
public void onScroll(float relativePos) {
//Yeah, yeah, but we were so preoccupied with whether or not we could,
//that we didn't stop to think if we should.
bubble.setRotation(relativePos*360f);
}
});
return bubble;
}
@Override
public TextView provideBubbleTextView() {
return bubble;
}
@Override
public int getBubbleOffset() {
return (int) (getScroller().isVertical() ? (float)handle.getHeight()/2f-(float)bubble.getHeight()/2f : (float)handle.getWidth()/2f-(float)bubble.getWidth()/2);
}
@Override
protected ViewBehavior provideHandleBehavior() {
return new CustomHandleBehavior(
new VisibilityAnimationManager.Builder(handle)
.withHideDelay(2000)
.build(),
new CustomHandleBehavior.HandleAnimationManager.Builder(handle)
.withGrabAnimator(R.animator.custom_grab)
.withReleaseAnimator(R.animator.custom_release)
.build()
);
}
@Override
protected ViewBehavior provideBubbleBehavior() {
return new DefaultBubbleBehavior(new VisibilityAnimationManager.Builder(bubble).withHideDelay(0).build());
}
private static ShapeDrawable drawCircle (int width, int height, int color) {
ShapeDrawable oval = new ShapeDrawable (new OvalShape());
oval.setIntrinsicHeight(height);
oval.setIntrinsicWidth(width);
oval.getPaint().setColor(color);
return oval;
}
}