forked from JustinRoom/WheelViewDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWheelMaskView.java
More file actions
78 lines (66 loc) · 2.29 KB
/
WheelMaskView.java
File metadata and controls
78 lines (66 loc) · 2.29 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
package jsc.kit.wheel.base;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import jsc.kit.wheel.R;
/**
* <br>Email:1006368252@qq.com
* <br>QQ:1006368252
* <br><a href="https://github.com/JustinRoom/WheelViewDemo" target="_blank">https://github.com/JustinRoom/WheelViewDemo</a>
*
* @author jiangshicheng
*/
public class WheelMaskView extends View {
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private int top = 0;
private int bottom = 0;
private int lineColor = 0x8F0000FF;
public WheelMaskView(Context context) {
super(context);
initAttr(context, null, 0);
}
public WheelMaskView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initAttr(context, attrs, 0);
}
public WheelMaskView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initAttr(context, attrs, defStyleAttr);
}
public void initAttr(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelMaskView, defStyleAttr, 0);
lineColor = a.getColor(R.styleable.WheelMaskView_wheelMaskLineColor, 0x8F0000FF);
a.recycle();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(1);
}
public void updateMask(int heightCount, int itemHeight) {
if (heightCount > 0) {
int centerIndex = heightCount / 2;
top = centerIndex * itemHeight;
bottom = top + itemHeight;
} else {
top = 0;
bottom = 0;
}
invalidate();
}
public void setLineColor(@ColorInt int lineColor) {
this.lineColor = lineColor;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
if (top > 0 && bottom > 0) {
paint.setColor(lineColor);
canvas.drawLine(0, top, getWidth(), top, paint);
canvas.drawLine(0, bottom, getWidth(), bottom, paint);
}
}
}