-
Notifications
You must be signed in to change notification settings - Fork 415
Expand file tree
/
Copy pathTitleView.java
More file actions
99 lines (80 loc) · 2.99 KB
/
TitleView.java
File metadata and controls
99 lines (80 loc) · 2.99 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package cn.aigestudio.datepicker.views;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.aigestudio.datepicker.entities.Language;
import cn.aigestudio.datepicker.interfaces.OnDateSelected;
/**
* 日期选择器的标题视图
*
* @author AigeStudio 2015-05-21
*/
public class TitleView extends LinearLayout implements MonthView.OnPageChangeListener, MonthView.OnSizeChangedListener {
private String[] monthTitles;
private TextView tvYear, tvMonth, tvConfirm;
private OnDateSelected mOnDateSelected;
private MonthView monthView;
public TitleView(Context context) {
super(context);
setColor(0xFFE95344);
setOrientation(HORIZONTAL);
monthTitles = Language.getLanguage(context).monthTitles();
LayoutParams llParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
tvYear = new TextView(context);
tvYear.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
tvYear.setTextColor(Color.WHITE);
tvMonth = new TextView(context);
tvMonth.setGravity(Gravity.CENTER);
tvMonth.setTextColor(Color.WHITE);
tvConfirm = new TextView(context);
tvConfirm.setGravity(Gravity.CENTER_VERTICAL | Gravity.END);
tvConfirm.setText(Language.getLanguage(context).ensureTitle());
tvConfirm.setTextColor(Color.WHITE);
tvConfirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (null != mOnDateSelected && null != monthView)
mOnDateSelected.selected(monthView.getDateSelected());
}
});
addView(tvYear, llParams);
addView(tvMonth, llParams);
addView(tvConfirm, llParams);
}
public void setOnDateSelected(OnDateSelected onDateSelected, MonthView monthView) {
mOnDateSelected = onDateSelected;
this.monthView = monthView;
}
public void setColor(int color) {
setBackgroundColor(color);
}
@Override
public void onMonthChange(int month) {
tvMonth.setText(monthTitles[month - 1]);
}
@Override
public void onYearChange(int year) {
tvYear.setText(String.valueOf(year));
}
@Override
public void onSizeChanged(int size) {
int padding = (int) (size * 1F / 50F);
int textSizeSmall = (int) (size * 1F / 25F);
int textSizeLarge = (int) (size * 1F / 18F);
tvYear.setPadding(padding, padding, 0, padding);
tvYear.getPaint().setTextSize(textSizeSmall);
tvMonth.setPadding(0, padding, 0, padding);
tvMonth.getPaint().setTextSize(textSizeLarge);
tvConfirm.setPadding(0, padding, padding, padding);
tvConfirm.getPaint().setTextSize(textSizeSmall);
}
/**
* 隐藏确定按钮
*/
public void hideEnsureButton() {
tvConfirm.setVisibility(View.INVISIBLE);
}
}