lmw
2023-05-12 f67802a41f9e01444d1115f34ecc6e1beb05fc3b
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
package com.fuban.user.views.calendar;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.TextView;
 
import com.haibin.calendarview.WeekBar;
import com.fuban.user.R;
 
/**
 * 自定义英文栏
 * Created by huanghaibin on 2017/11/30.
 */
 
public class SimpleWeekBar extends WeekBar {
 
    public SimpleWeekBar(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.simple_week_bar, this, true);
        setBackgroundResource(R.drawable.bg_orange_16dp);
    }
 
    /**
     * 当周起始发生变化,使用自定义布局需要重写这个方法,避免出问题
     *
     * @param weekStart 周起始
     */
    @Override
    protected void onWeekStartChange(int weekStart) {
        for (int i = 0; i < getChildCount(); i++) {
            ((TextView) getChildAt(i)).setText(getWeekString(i, weekStart));
        }
    }
 
    /**
     * 或者周文本,这个方法仅供父类使用
     *
     * @param index     index
     * @param weekStart weekStart
     * @return 或者周文本
     */
    private String getWeekString(int index, int weekStart) {
        String[] weeks = getContext().getResources().getStringArray(R.array.week_string_array);
 
        if (weekStart == 1) {
            return weeks[index];
        }
        if (weekStart == 2) {
            return weeks[index == 6 ? 0 : index + 1];
        }
        return weeks[index == 0 ? 6 : index - 1];
    }
}