Skip to content

Commit aee890b

Browse files
committed
add option to specify off bit colors
1 parent 40782be commit aee890b

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
lines changed

10-bitClockWidget/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ android {
2424
applicationId "com.github.ashutoshgngwr.tenbitclockwidget"
2525
minSdkVersion 14
2626
targetSdkVersion 30
27-
versionCode 190
28-
versionName "1.9"
27+
versionCode 200
28+
versionName "2.0"
2929
}
3030
buildTypes {
3131
release {

10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetRenderer.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class ClockWidgetRenderer {
1616

1717
private static final String TAG = ClockWidgetRenderer.class.getSimpleName();
1818

19-
private static final int BIT_ALPHA_ACTIVE = 0xFF;
20-
private static final int BIT_ALPHA_INACTIVE = 0x80;
2119
private static final int SEPARATOR_LINE_ALPHA = 0x70;
2220

2321
private static ClockWidgetRenderer mInstance;
@@ -59,11 +57,10 @@ private Bitmap render() {
5957
clearClockBitmap();
6058

6159
Calendar calendar = Calendar.getInstance();
62-
final boolean is24Hour = ClockWidgetSettings.shouldUse24HourFormat();
60+
final boolean is24Hour = ClockWidgetSettings.shouldUse24HourFormat() || calendar.get(Calendar.AM_PM) == Calendar.AM;
6361
final int nHourBits = is24Hour ? ClockWidgetSettings.shouldUse6bitsForHour() ? 6 : 5 : 4;
6462
final int hour = calendar.get(is24Hour ? Calendar.HOUR_OF_DAY : Calendar.HOUR);
6563
final int minute = calendar.get(Calendar.MINUTE);
66-
final int period = calendar.get(Calendar.AM_PM);
6764

6865
final float sx = width * (is24Hour ? 0.5f : 0.4f);
6966
final float sp = px(5);
@@ -72,15 +69,11 @@ private Bitmap render() {
7269
mPaint.setColor(ClockWidgetSettings.getClockBackgroundColor());
7370
canvas.drawRoundRect(new RectF(0, 0, width, height), px(5), px(5), mPaint);
7471

75-
// set clock's color based on time.
76-
mPaint.setColor(is24Hour || period == Calendar.AM
77-
? ClockWidgetSettings.getClockAMColor() : ClockWidgetSettings.getClockPMColor());
78-
7972
RectF bounds = new RectF(padding, padding, sx - sp, height - padding);
80-
renderBits(bounds, 2, is24Hour ? 3 : 2, nHourBits, hour);
73+
renderBits(is24Hour, bounds, 2, is24Hour ? 3 : 2, nHourBits, hour);
8174

8275
bounds.set(sx + sp, padding, width - padding, height - padding);
83-
renderBits(bounds, 2, 3, 6, minute);
76+
renderBits(is24Hour, bounds, 2, 3, 6, minute);
8477

8578
if (ClockWidgetSettings.shouldDisplaySeparator()) {
8679
mPaint.setAlpha(SEPARATOR_LINE_ALPHA);
@@ -91,7 +84,7 @@ private Bitmap render() {
9184
}
9285

9386
@SuppressWarnings("SameParameterValue")
94-
private void renderBits(RectF bounds, int rows, int cols, int nBits, int bits) {
87+
private void renderBits(boolean is24Hour, RectF bounds, int rows, int cols, int nBits, int bits) {
9588
final float dr = px(ClockWidgetSettings.getDotSize());
9689
final float cw = bounds.width() / cols;
9790
final float ch = bounds.height() / rows;
@@ -106,7 +99,16 @@ private void renderBits(RectF bounds, int rows, int cols, int nBits, int bits) {
10699
continue;
107100
}
108101

109-
mPaint.setAlpha((bits >> ((i * cols) + j) & 1) == 1 ? BIT_ALPHA_ACTIVE : BIT_ALPHA_INACTIVE);
102+
if ((bits >> ((i * cols) + j) & 1) == 1) {
103+
mPaint.setColor(
104+
is24Hour ? ClockWidgetSettings.getClockAMOnColor() : ClockWidgetSettings.getClockPMOnColor()
105+
);
106+
} else {
107+
mPaint.setColor(
108+
is24Hour ? ClockWidgetSettings.getClockAMOffColor() : ClockWidgetSettings.getClockPMOffColor()
109+
);
110+
}
111+
110112
canvas.drawCircle(x - cpx - dr, y - cpy - dr, dr, mPaint);
111113
x -= cw;
112114
}

10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetSettings.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,22 @@ static boolean shouldUse6bitsForHour() {
5050
return getPreferences().getBoolean("6bits_hour", false);
5151
}
5252

53-
static int getClockAMColor() {
53+
static int getClockAMOnColor() {
5454
return getPreferences().getInt("am_color", 0);
5555
}
5656

57-
static int getClockPMColor() {
57+
static int getClockAMOffColor() {
58+
return getPreferences().getInt("am_off_color", 0);
59+
}
60+
61+
static int getClockPMOnColor() {
5862
return getPreferences().getInt("pm_color", 0);
5963
}
6064

65+
static int getClockPMOffColor() {
66+
return getPreferences().getInt("pm_off_color", 0);
67+
}
68+
6169
static int getClockBackgroundColor() {
6270
return getPreferences().getInt("background_color", 0);
6371
}

10-bitClockWidget/app/src/main/res/values/strings.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@
2424
<string name="dot_size">Dot size</string>
2525
<string name="display_separator">Display separator</string>
2626
<string name="summary_display_separator">Display a line separating hours and minutes.</string>
27-
<string name="am_time_color">Dot color</string>
28-
<string name="pm_time_color">Alternate dot color</string>
27+
<string name="am_time_color">Dot color (on bit)</string>
28+
<string name="am_time_off_color">Dot color (off bit)</string>
29+
<string name="pm_time_color">Alternate dot color (on bit)</string>
30+
<string name="pm_time_off_color">Alternate dot color (off bit)</string>
2931
<string name="summary_pm_time_color">Color used post midday to distinguish between AM and PM time.</string>
3032
<string name="clock_background_color">Background color</string>
3133
<string name="service_notification__description">Background service is running to update the clock widget. Long press to hide this notification forever!</string>
3234
<string name="notification_channel_default__name">Clock Update Service</string>
3335
<string name="notification_channel_default__description">Notifications to keep the background service alive for updating the clock. You may disable notifications from this channel permanently.</string>
3436
<string name="twenty_four_hour_format">Use 24-hour format</string>
35-
<string name="summary_twenty_four_hour_format">The widget will need at least 11 bits on enabling 24-hour format.</string>
36-
<string name="six_bits_hour">Use 6 bits for hour</string>
37-
<string name="summary_six_bits_hour">To fill empty space, the widget will use 6 bits to represent hour instead of 5.</string>
37+
<string name="summary_twenty_four_hour_format">The widget will need at least 11 dots on enabling 24-hour format.</string>
38+
<string name="six_bits_hour">Use 6 dots for hour</string>
39+
<string name="summary_six_bits_hour">To fill empty space, the widget will use 6 dots to represent hour instead of 5.</string>
3840
<string name="about_page_url">file:///android_asset/about.html</string>
3941
<string name="help_page_url">file:///android_asset/help.html</string>
4042
</resources>

10-bitClockWidget/app/src/main/res/xml/widget_preference.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,35 @@
4343
app:title="@string/six_bits_hour" />
4444

4545
<com.github.ashutoshgngwr.tenbitclockwidget.ColorPickerPreference
46+
alphaSlider="true"
4647
app:defaultValue="#FF0F0F0F"
4748
app:iconSpaceReserved="false"
4849
app:key="am_color"
4950
app:title="@string/am_time_color" />
5051

5152
<com.github.ashutoshgngwr.tenbitclockwidget.ColorPickerPreference
53+
alphaSlider="true"
54+
app:defaultValue="#770F0F0F"
55+
app:iconSpaceReserved="false"
56+
app:key="am_off_color"
57+
app:title="@string/am_time_off_color" />
58+
59+
<com.github.ashutoshgngwr.tenbitclockwidget.ColorPickerPreference
60+
alphaSlider="true"
5261
app:defaultValue="#FFFCFCFC"
5362
app:iconSpaceReserved="false"
5463
app:key="pm_color"
5564
app:summary="@string/summary_pm_time_color"
5665
app:title="@string/pm_time_color" />
5766

67+
<com.github.ashutoshgngwr.tenbitclockwidget.ColorPickerPreference
68+
alphaSlider="true"
69+
app:defaultValue="#77FCFCFC"
70+
app:iconSpaceReserved="false"
71+
app:key="pm_off_color"
72+
app:summary="@string/summary_pm_time_color"
73+
app:title="@string/pm_time_off_color" />
74+
5875
<com.github.ashutoshgngwr.tenbitclockwidget.ColorPickerPreference
5976
alphaSlider="true"
6077
app:defaultValue="#00000000"

0 commit comments

Comments
 (0)