Skip to content

Commit 95691c2

Browse files
committed
fix incorrect bit style during AM
also disable alternate dot color (off) preference when 24-hour preference is enabled. fixes #58
1 parent aee890b commit 95691c2

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
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 200
28-
versionName "2.0"
27+
versionCode 201
28+
versionName "2.0-1"
2929
}
3030
buildTypes {
3131
release {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
7676
assert pmColor != null;
7777
pmColor.setEnabled(!isTFEnabled);
7878

79+
Preference pmOffColor = findPreference("pm_off_color");
80+
assert pmOffColor != null;
81+
pmOffColor.setEnabled(!isTFEnabled);
82+
7983
Preference sixBitsHour = findPreference("6bits_hour");
8084
assert sixBitsHour != null;
8185
sixBitsHour.setEnabled(isTFEnabled);

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ private Bitmap render() {
5757
clearClockBitmap();
5858

5959
Calendar calendar = Calendar.getInstance();
60-
final boolean is24Hour = ClockWidgetSettings.shouldUse24HourFormat() || calendar.get(Calendar.AM_PM) == Calendar.AM;
60+
final boolean is24Hour = ClockWidgetSettings.shouldUse24HourFormat();
6161
final int nHourBits = is24Hour ? ClockWidgetSettings.shouldUse6bitsForHour() ? 6 : 5 : 4;
6262
final int hour = calendar.get(is24Hour ? Calendar.HOUR_OF_DAY : Calendar.HOUR);
6363
final int minute = calendar.get(Calendar.MINUTE);
64+
final int onBitColor = is24Hour || calendar.get(Calendar.AM_PM) == Calendar.AM
65+
? ClockWidgetSettings.getClockAMOnColor() : ClockWidgetSettings.getClockPMOnColor();
66+
67+
final int offBitColor = is24Hour || calendar.get(Calendar.AM_PM) == Calendar.AM
68+
? ClockWidgetSettings.getClockAMOffColor() : ClockWidgetSettings.getClockPMOffColor();
6469

6570
final float sx = width * (is24Hour ? 0.5f : 0.4f);
6671
final float sp = px(5);
@@ -70,10 +75,10 @@ private Bitmap render() {
7075
canvas.drawRoundRect(new RectF(0, 0, width, height), px(5), px(5), mPaint);
7176

7277
RectF bounds = new RectF(padding, padding, sx - sp, height - padding);
73-
renderBits(is24Hour, bounds, 2, is24Hour ? 3 : 2, nHourBits, hour);
78+
renderBits(onBitColor, offBitColor, bounds, 2, is24Hour ? 3 : 2, nHourBits, hour);
7479

7580
bounds.set(sx + sp, padding, width - padding, height - padding);
76-
renderBits(is24Hour, bounds, 2, 3, 6, minute);
81+
renderBits(onBitColor, offBitColor, bounds, 2, 3, 6, minute);
7782

7883
if (ClockWidgetSettings.shouldDisplaySeparator()) {
7984
mPaint.setAlpha(SEPARATOR_LINE_ALPHA);
@@ -84,7 +89,7 @@ private Bitmap render() {
8489
}
8590

8691
@SuppressWarnings("SameParameterValue")
87-
private void renderBits(boolean is24Hour, RectF bounds, int rows, int cols, int nBits, int bits) {
92+
private void renderBits(int onColor, int offColor, RectF bounds, int rows, int cols, int nBits, int bits) {
8893
final float dr = px(ClockWidgetSettings.getDotSize());
8994
final float cw = bounds.width() / cols;
9095
final float ch = bounds.height() / rows;
@@ -100,13 +105,9 @@ private void renderBits(boolean is24Hour, RectF bounds, int rows, int cols, int
100105
}
101106

102107
if ((bits >> ((i * cols) + j) & 1) == 1) {
103-
mPaint.setColor(
104-
is24Hour ? ClockWidgetSettings.getClockAMOnColor() : ClockWidgetSettings.getClockPMOnColor()
105-
);
108+
mPaint.setColor(onColor);
106109
} else {
107-
mPaint.setColor(
108-
is24Hour ? ClockWidgetSettings.getClockAMOffColor() : ClockWidgetSettings.getClockPMOffColor()
109-
);
110+
mPaint.setColor(offColor);
110111
}
111112

112113
canvas.drawCircle(x - cpx - dr, y - cpy - dr, dr, mPaint);

0 commit comments

Comments
 (0)