-
Notifications
You must be signed in to change notification settings - Fork 106
/
TimeTextView.java
90 lines (73 loc) · 2.41 KB
/
TimeTextView.java
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
package com.googlecode.android.widgets.DateSlider.timeview;
import android.content.Context;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.TextView;
import com.googlecode.android.widgets.DateSlider.TimeObject;
/**
* This is a simple implementation of a TimeView which is implemented
* as a TextView. It is aware of whether or not it is the center view
* in the ScrollLayout so that it can alter its appearance to indicate
* that it is currently selected.
*/
public class TimeTextView extends TextView implements TimeView {
protected long endTime, startTime;
protected boolean isOutOfBounds = false;
/**
* constructor
* @param context
* @param isCenterView true if the element is the centered view in the ScrollLayout
* @param textSize text size in dps
*/
public TimeTextView(Context context, boolean isCenterView, int textSize) {
super(context);
setupView(isCenterView, textSize);
}
/**
* this method should be overwritten by inheriting classes to define its own look and feel
* @param isCenterView true if the element is in the center of the scrollLayout
* @param textSize textSize in dps
*/
protected void setupView(boolean isCenterView, int textSize) {
setGravity(Gravity.CENTER);
setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
if (isCenterView) {
setTypeface(Typeface.DEFAULT_BOLD);
setTextColor(0xFF333333);
} else {
setTextColor(0xFF666666);
}
}
public void setVals(TimeObject to) {
setText(to.text);
this.startTime = to.startTime;
this.endTime = to.endTime;
}
public void setVals(TimeView other) {
setText(other.getTimeText());
startTime = other.getStartTime();
endTime = other.getEndTime();
}
public long getStartTime() {
return this.startTime;
}
public long getEndTime() {
return this.endTime;
}
public String getTimeText() {
return getText().toString();
}
public boolean isOutOfBounds() {
return isOutOfBounds;
}
public void setOutOfBounds(boolean outOfBounds) {
if (outOfBounds && !isOutOfBounds) {
setTextColor(0x44666666);
}
else if (!outOfBounds && isOutOfBounds) {
setTextColor(0xFF666666);
}
isOutOfBounds = outOfBounds;
}
}