admin
2021-06-07 01e23be6118d68d38a71d186296d440eadcaa197
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.tejia.lijin.app.ui.goldtask.view;
 
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.TextView;
 
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.entity.DailySign;
 
/**
 * 金币领取 日期进度
 */
public class ProgressBarTime extends FrameLayout {
    private LayoutInflater mInflater;
    private CheckBox time_1;
    private CheckBox time_1line;
    private TextView time_1txt;
    private CheckBox time_2;
    private CheckBox time_2line;
    private TextView time_2txt;
    private CheckBox time_3;
    private CheckBox time_3line;
    private TextView time_3txt;
    private CheckBox time_4;
    private CheckBox time_4line;
    private TextView time_4txt;
    private CheckBox time_5;
    private CheckBox time_5line;
    private TextView time_5txt;
    private CheckBox time_6;
    private CheckBox time_6line;
    private TextView time_6txt;
    private CheckBox time_7;
    private TextView time_7txt;
 
    public ProgressBarTime(Context context) {
        this(context, null);
    }
 
    public ProgressBarTime(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
 
    public ProgressBarTime(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mInflater = LayoutInflater.from(getContext());
    }
 
    private int mChildViewRes = -1; //子view的资源文件
 
 
    public void setProgressBarTime(DailySign mDailySign) {
        if (isCancelAnimtion || mChildViewRes != -1) {//防止重复加载
            return;
        }
        //子view的资源文件
        mChildViewRes = R.layout.progressbartime_item;
        View view = mInflater.inflate(mChildViewRes, this, false);
        setfindViewById(view);
        addShowViewAnimation(view);
        setShowView(mDailySign);//设置数据
    }
 
    /**
     * 显示签到日期
     *
     * @param mDailySign
     */
    private void setShowView(DailySign mDailySign) {
        if (mDailySign.listDate != null && !isCancelAnimtion) {
            if (mDailySign.listDate.get(0) != null) {
                time_1.setText(mDailySign.listDate.get(0).goldCoin);//金币
                time_1.setChecked(mDailySign.listDate.get(0).lightUp);
                time_1line.setChecked(mDailySign.listDate.get(0).lightUp);
                time_1txt.setText(mDailySign.listDate.get(0).date);
            }
            if (mDailySign.listDate.get(1) != null) {
                time_2.setText(mDailySign.listDate.get(1).goldCoin);//金币
                time_2.setChecked(mDailySign.listDate.get(1).lightUp);
                time_2line.setChecked(mDailySign.listDate.get(1).lightUp);
                time_2txt.setText(mDailySign.listDate.get(1).date);
            }
            if (mDailySign.listDate.get(2) != null) {
                time_3.setText(mDailySign.listDate.get(2).goldCoin);//金币
                time_3.setChecked(mDailySign.listDate.get(2).lightUp);
                time_3line.setChecked(mDailySign.listDate.get(2).lightUp);
                time_3txt.setText(mDailySign.listDate.get(2).date);
            }
            if (mDailySign.listDate.get(3) != null) {
                time_4.setText(mDailySign.listDate.get(3).goldCoin);//金币
                time_4.setChecked(mDailySign.listDate.get(3).lightUp);
                time_4line.setChecked(mDailySign.listDate.get(3).lightUp);
                time_4txt.setText(mDailySign.listDate.get(3).date);
            }
            if (mDailySign.listDate.get(4) != null) {
                time_5.setText(mDailySign.listDate.get(4).goldCoin);//金币
                time_5.setChecked(mDailySign.listDate.get(4).lightUp);
                time_5line.setChecked(mDailySign.listDate.get(4).lightUp);
                time_5txt.setText(mDailySign.listDate.get(4).date);
            }
            if (mDailySign.listDate.get(5) != null) {
                time_6.setText(mDailySign.listDate.get(5).goldCoin);//金币
                time_6.setChecked(mDailySign.listDate.get(5).lightUp);
                time_6line.setChecked(mDailySign.listDate.get(5).lightUp);
                time_6txt.setText(mDailySign.listDate.get(5).date);
            }
            if (mDailySign.listDate.get(6) != null) {
                time_7.setText(mDailySign.listDate.get(6).goldCoin);//金币
                time_7.setChecked(mDailySign.listDate.get(6).lightUp);
                time_7txt.setText(mDailySign.listDate.get(6).date);
            }
        }
    }
 
 
    /**
     * 添加显示动画
     * 缩放动画 从透明到实体
     * --------从0到1缩放
     *
     * @param view
     */
    private void addShowViewAnimation(View view) {
        addView(view);
        view.setAlpha(0);//透明度0
        view.setScaleX(0);//x缩放比例0
        view.setScaleY(0);//y缩放比例0
        view.animate().alpha(1)//透明度1
                .scaleX(1)//x缩放比例1
                .scaleY(1)//y缩放比例1
                .setDuration(300)//持续时间 500
                .start();
    }
 
    /**
     * 绑定控件
     *
     * @param view
     */
    private void setfindViewById(View view) {
        time_1 = view.findViewById(R.id.time_1);
        time_1line = view.findViewById(R.id.time_1line);
        time_1txt = view.findViewById(R.id.time_1txt);
        time_2 = view.findViewById(R.id.time_2);
        time_2line = view.findViewById(R.id.time_2line);
        time_2txt = view.findViewById(R.id.time_2txt);
        time_3 = view.findViewById(R.id.time_3);
        time_3line = view.findViewById(R.id.time_3line);
        time_3txt = view.findViewById(R.id.time_3txt);
        time_4 = view.findViewById(R.id.time_4);
        time_4line = view.findViewById(R.id.time_4line);
        time_4txt = view.findViewById(R.id.time_4txt);
        time_5 = view.findViewById(R.id.time_5);
        time_5line = view.findViewById(R.id.time_5line);
        time_5txt = view.findViewById(R.id.time_5txt);
        time_6 = view.findViewById(R.id.time_6);
        time_6line = view.findViewById(R.id.time_6line);
        time_6txt = view.findViewById(R.id.time_6txt);
        time_7 = view.findViewById(R.id.time_7);
        time_7txt = view.findViewById(R.id.time_7txt);
    }
 
    private boolean isCancelAnimtion = false;
 
    /**
     * 界面销毁时回调
     */
    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        onDestroy();
    }
 
    /**
     * 销毁
     */
    private void onDestroy() {
        isCancelAnimtion = true;//销毁动画
    }
}