This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathTimerView.java
More file actions
167 lines (150 loc) · 5.79 KB
/
TimerView.java
File metadata and controls
167 lines (150 loc) · 5.79 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
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
package com.codetroopers.betterpickers.timepicker;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.codetroopers.betterpickers.R;
import com.codetroopers.betterpickers.widget.ZeroTopPaddingTextView;
public class TimerView extends LinearLayout {
private ZeroTopPaddingTextView mHoursOnes, mMinutesOnes;
private ZeroTopPaddingTextView mHoursTens, mMinutesTens;
private final Typeface mAndroidClockMonoThin;
private Typeface mOriginalHoursTypeface;
private ZeroTopPaddingTextView mHoursSeperator;
private ColorStateList mTextColor;
/**
* Instantiates a TimerView
*
* @param context the Context in which to inflate the View
*/
public TimerView(Context context) {
this(context, null);
}
/**
* Instantiates a TimerView
*
* @param context the Context in which to inflate the View
* @param attrs attributes that define the text color
*/
public TimerView(Context context, AttributeSet attrs) {
super(context, attrs);
mAndroidClockMonoThin =
Typeface.createFromAsset(context.getAssets(), "fonts/AndroidClockMono-Thin.ttf");
// Init defaults
mTextColor = getResources().getColorStateList(R.color.dialog_text_color_holo_dark);
}
/**
* Set a theme and restyle the views. This View will change its title color.
*
* @param themeResId the resource ID for theming
*/
public void setTheme(int themeResId) {
if (themeResId != -1) {
TypedArray a = getContext().obtainStyledAttributes(themeResId, R.styleable.BetterPickersDialogFragment);
mTextColor = a.getColorStateList(R.styleable.BetterPickersDialogFragment_bpTextColor);
a.recycle();
}
restyleViews();
}
private void restyleViews() {
if (mHoursOnes != null) {
mHoursOnes.setTextColor(mTextColor);
}
if (mMinutesOnes != null) {
mMinutesOnes.setTextColor(mTextColor);
}
if (mHoursTens != null) {
mHoursTens.setTextColor(mTextColor);
}
if (mMinutesTens != null) {
mMinutesTens.setTextColor(mTextColor);
}
if (mHoursSeperator != null) {
mHoursSeperator.setTextColor(mTextColor);
}
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mHoursTens = (ZeroTopPaddingTextView) findViewById(R.id.hours_tens);
mMinutesTens = (ZeroTopPaddingTextView) findViewById(R.id.minutes_tens);
mHoursOnes = (ZeroTopPaddingTextView) findViewById(R.id.hours_ones);
mMinutesOnes = (ZeroTopPaddingTextView) findViewById(R.id.minutes_ones);
mHoursSeperator = (ZeroTopPaddingTextView) findViewById(R.id.hours_seperator);
if (mHoursOnes != null) {
mOriginalHoursTypeface = mHoursOnes.getTypeface();
}
// Set the lowest time unit with thin font (excluding hundredths)
if (mMinutesTens != null) {
mMinutesTens.setTypeface(mAndroidClockMonoThin);
mMinutesTens.updatePadding();
}
if (mMinutesOnes != null) {
mMinutesOnes.setTypeface(mAndroidClockMonoThin);
mMinutesOnes.updatePadding();
}
}
/**
* Set the time shown
*
* @param hoursTensDigit the tens digit of the hours
* @param hoursOnesDigit the ones digit of the hours
* @param minutesTensDigit the tens digit of the minutes
* @param minutesOnesDigit the ones digit of the minutes
*/
public void setTime(int hoursTensDigit, int hoursOnesDigit, int minutesTensDigit,
int minutesOnesDigit) {
if (mHoursTens != null) {
// Hide digit
if (hoursTensDigit == -2) {
mHoursTens.setVisibility(View.INVISIBLE);
} else if (hoursTensDigit == -1) {
mHoursTens.setText("-");
mHoursTens.setTypeface(mAndroidClockMonoThin);
mHoursTens.setEnabled(false);
mHoursTens.updatePadding();
mHoursTens.setVisibility(View.VISIBLE);
} else {
mHoursTens.setText(String.format("%d", hoursTensDigit));
mHoursTens.setTypeface(mOriginalHoursTypeface);
mHoursTens.setEnabled(true);
mHoursTens.updatePaddingForBoldDate();
mHoursTens.setVisibility(View.VISIBLE);
}
}
if (mHoursOnes != null) {
if (hoursOnesDigit == -1) {
mHoursOnes.setText("-");
mHoursOnes.setTypeface(mAndroidClockMonoThin);
mHoursOnes.setEnabled(false);
mHoursOnes.updatePadding();
} else {
mHoursOnes.setText(String.format("%d", hoursOnesDigit));
mHoursOnes.setTypeface(mOriginalHoursTypeface);
mHoursOnes.setEnabled(true);
mHoursOnes.updatePaddingForBoldDate();
}
}
if (mMinutesTens != null) {
if (minutesTensDigit == -1) {
mMinutesTens.setText("-");
mMinutesTens.setEnabled(false);
} else {
mMinutesTens.setEnabled(true);
mMinutesTens.setText(String.format("%d", minutesTensDigit));
}
}
if (mMinutesOnes != null) {
if (minutesOnesDigit == -1) {
mMinutesOnes.setText("-");
mMinutesOnes.setEnabled(false);
} else {
mMinutesOnes.setText(String.format("%d", minutesOnesDigit));
mMinutesOnes.setEnabled(true);
}
}
}
}