-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathThumbDrawable.java
More file actions
76 lines (63 loc) · 2.2 KB
/
ThumbDrawable.java
File metadata and controls
76 lines (63 loc) · 2.2 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
package com.reactnativecommunity.slider;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.drawee.drawable.ForwardingDrawable;
import java.util.Objects;
public class ThumbDrawable extends ForwardingDrawable {
private final Paint mPaint = new Paint();
private int width = 0;
private int height = 0;
private float rx = 100;
private float ry = 100;
/**
* Constructs a new forwarding drawable.
*
* @param drawable drawable that this forwarding drawable will forward to
*/
public ThumbDrawable(@Nullable Drawable drawable) {
super(drawable);
mPaint.setColor(Color.RED);
}
@Override
public void draw(@NonNull Canvas canvas) {
if (width == 0 || height == 0) {
super.draw(canvas);
return;
}
Rect defaultRect = Objects.requireNonNull(getDrawable()).getBounds();
// LEFT, TOP, RIGHT, BOTTOM. so its actually at (left+(Right - left) / 2, top+(bottom - top) / 2)
// with width = right - left and height = bottom - top
float newLeft = defaultRect.left + (defaultRect.right - defaultRect.left) / 2f - width / 2f;
float newTop = defaultRect.top + (defaultRect.bottom - defaultRect.top) / 2f - height / 2f;
canvas.drawRoundRect(
newLeft,
newTop,
newLeft + width,
newTop + height,
rx, ry, mPaint);
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
mPaint.setColorFilter(colorFilter);
super.setColorFilter(colorFilter);
}
@Override
public void clearColorFilter() {
mPaint.setColorFilter(null);
super.clearColorFilter();
}
public void setDimension(double width, double height) {
this.width = (int) width;
this.height = (int) height;
}
public void setCornerRoundness(double rx, double ry) {
this.rx = (float) rx;
this.ry = (float) ry;
}
}