-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClockViewPaintFactory.java
65 lines (52 loc) · 2.08 KB
/
ClockViewPaintFactory.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
package study.amadey.customview;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.Size;
final class ClockViewPaintFactory {
private static final String timeLabelColor = "#ffedb8";
private static final String hourHandColor = "#d06383";
private static final String minuteHandColor = "#fff4e2";
private static final String watchFaceColor = "#63367b";
private static final int TEXT_SIZE = 7;
private ClockViewPaintFactory(){}
static Paint produceTimeLabelPaint(){
Paint timeLabelPaint = new Paint();
timeLabelPaint.setColor(Color.parseColor(timeLabelColor));
return timeLabelPaint;
}
static Paint produceHourHandPaint(){
Paint hourHandPaint = new Paint();
hourHandPaint.setColor(Color.parseColor(hourHandColor));
return hourHandPaint;
}
static Paint produceMinuteHandPaint(){
Paint minuteHandPaint = new Paint();
minuteHandPaint.setColor(Color.parseColor(minuteHandColor));
return minuteHandPaint;
}
static Paint produceWatchFacePaint(){
Paint watchFacePaint = new Paint();
watchFacePaint.setColor(Color.parseColor(watchFaceColor));
return watchFacePaint;
}
static Paint produceTextPaintForZoom(float pixelDensity){
Paint textPaint = new Paint();
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setColor(Color.BLACK);
textPaint.setTextSize(pixelDensity * TEXT_SIZE);
return textPaint;
}
static int getHeightOfTextPaint(Paint textPaint, String text){
return calculateHeightOfPaintWithinItsRect(textPaint, text);
}
private static Rect getTextPaintBounds(Paint textPaint, String text) {
Rect bounds = new Rect();
textPaint.getTextBounds(text, 0, text.length(), bounds);
return bounds;
}
private static int calculateHeightOfPaintWithinItsRect(Paint textPaint, String text) {
Rect rect = getTextPaintBounds(textPaint, text);
return Math.abs(rect.top - rect.bottom);
}
}