Skip to content

Commit

Permalink
fix incorrect bit style during AM
Browse files Browse the repository at this point in the history
also disable alternate dot color (off) preference when
24-hour preference is enabled.

fixes #58
  • Loading branch information
ashutoshgngwr committed Jun 27, 2021
1 parent aee890b commit 95691c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions 10-bitClockWidget/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId "com.github.ashutoshgngwr.tenbitclockwidget"
minSdkVersion 14
targetSdkVersion 30
versionCode 200
versionName "2.0"
versionCode 201
versionName "2.0-1"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
assert pmColor != null;
pmColor.setEnabled(!isTFEnabled);

Preference pmOffColor = findPreference("pm_off_color");
assert pmOffColor != null;
pmOffColor.setEnabled(!isTFEnabled);

Preference sixBitsHour = findPreference("6bits_hour");
assert sixBitsHour != null;
sixBitsHour.setEnabled(isTFEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ private Bitmap render() {
clearClockBitmap();

Calendar calendar = Calendar.getInstance();
final boolean is24Hour = ClockWidgetSettings.shouldUse24HourFormat() || calendar.get(Calendar.AM_PM) == Calendar.AM;
final boolean is24Hour = ClockWidgetSettings.shouldUse24HourFormat();
final int nHourBits = is24Hour ? ClockWidgetSettings.shouldUse6bitsForHour() ? 6 : 5 : 4;
final int hour = calendar.get(is24Hour ? Calendar.HOUR_OF_DAY : Calendar.HOUR);
final int minute = calendar.get(Calendar.MINUTE);
final int onBitColor = is24Hour || calendar.get(Calendar.AM_PM) == Calendar.AM
? ClockWidgetSettings.getClockAMOnColor() : ClockWidgetSettings.getClockPMOnColor();

final int offBitColor = is24Hour || calendar.get(Calendar.AM_PM) == Calendar.AM
? ClockWidgetSettings.getClockAMOffColor() : ClockWidgetSettings.getClockPMOffColor();

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

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

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

if (ClockWidgetSettings.shouldDisplaySeparator()) {
mPaint.setAlpha(SEPARATOR_LINE_ALPHA);
Expand All @@ -84,7 +89,7 @@ private Bitmap render() {
}

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

if ((bits >> ((i * cols) + j) & 1) == 1) {
mPaint.setColor(
is24Hour ? ClockWidgetSettings.getClockAMOnColor() : ClockWidgetSettings.getClockPMOnColor()
);
mPaint.setColor(onColor);
} else {
mPaint.setColor(
is24Hour ? ClockWidgetSettings.getClockAMOffColor() : ClockWidgetSettings.getClockPMOffColor()
);
mPaint.setColor(offColor);
}

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

0 comments on commit 95691c2

Please sign in to comment.