Hunter0x7c7
2024-11-21 979ae7c9ffb06359a15b633ab009773f5c964dd5
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
package com.codbking.widget;
 
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
 
import com.codbking.widget.view.OnWheelChangedListener;
import com.codbking.widget.view.OnWheelScrollListener;
import com.codbking.widget.view.WheelView;
import com.codbking.widget.genview.GenWheelText;
import com.codbking.widget.genview.WheelGeneralAdapter;
 
/**
 * Created by codbking on 2016/8/11.
 */
 abstract class BaseWheelPick
        extends LinearLayout
        implements OnWheelChangedListener
        , OnWheelScrollListener
         {
 
    protected int textColor = 0xffdddddd;
    protected int selectColor = 0xff444444;
    protected int split = 0xffdddddd;
    protected int splitHeight = 1;
    protected Context ctx;
    private GenWheelText genView;
 
    public BaseWheelPick(Context context) {
        super(context);
        init(context);
    }
 
    public BaseWheelPick(Context context, AttributeSet attrs) {
        super(context, attrs);
 
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker);
        textColor = a.getColor(R.styleable.DatePicker_picker_text_color, 0xffdddddd);
        selectColor = a.getColor(R.styleable.DatePicker_picker_select_textColor, 0xff444444);
        split = a.getColor(R.styleable.DatePicker_picker_split, 0xffdddddd);
        splitHeight = (int) a.getDimension(R.styleable.DatePicker_picker_split_height, 0.5f);
 
        a.recycle();
        init(context);
    }
 
    private void init(Context context) {
        genView = new GenWheelText(textColor);
        this.ctx = context;
        LayoutInflater.from(context).inflate(getLayout(), this);
    }
 
    protected void setWheelListener(WheelView wheelView, Object[] data, boolean isCyclic) {
        WheelGeneralAdapter viewAdapter = new WheelGeneralAdapter(ctx, genView);
        if (data[0] instanceof Integer) {
            viewAdapter.setData(convertData(wheelView, (Integer[]) data));
        } else {
            viewAdapter.setData(data);
        }
        wheelView.setSelectTextColor(textColor, selectColor);
        wheelView.setCyclic(isCyclic);
        wheelView.setViewAdapter(viewAdapter);
        wheelView.addChangingListener(this);
        wheelView.addScrollingListener(this);
    }
 
    protected String[] convertData(WheelView wheelView, Integer[] data) {
        return new String[0];
    }
 
    protected abstract int getLayout();
 
    protected abstract int getItemHeight();
 
    protected abstract void setData(Object[] datas);
 
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setStrokeWidth(splitHeight);
        paint.setColor(split);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL);
        int itemHeight = getItemHeight();
 
        for (int i = 0; i < 5; i++) {
            canvas.drawLine(0, (i + 1) * itemHeight, getWidth(), (i + 1) * itemHeight, paint);
        }
    }
 
    @Override
    public void onChanged(WheelView wheel, int oldValue, int newValue) {
 
    }
 
}