From 95691c28d576d63385a84968f0605b3f2947c9c8 Mon Sep 17 00:00:00 2001 From: Ashutosh Gangwar Date: Sun, 27 Jun 2021 19:34:28 +0530 Subject: [PATCH] fix incorrect bit style during AM also disable alternate dot color (off) preference when 24-hour preference is enabled. fixes #58 --- 10-bitClockWidget/app/build.gradle | 4 ++-- .../ClockWidgetPreferenceFragment.java | 4 ++++ .../ClockWidgetRenderer.java | 21 ++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/10-bitClockWidget/app/build.gradle b/10-bitClockWidget/app/build.gradle index e173636..8fcf573 100644 --- a/10-bitClockWidget/app/build.gradle +++ b/10-bitClockWidget/app/build.gradle @@ -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 { diff --git a/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetPreferenceFragment.java b/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetPreferenceFragment.java index 54935fb..c752b5d 100644 --- a/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetPreferenceFragment.java +++ b/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetPreferenceFragment.java @@ -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); diff --git a/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetRenderer.java b/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetRenderer.java index 6952759..f0e6798 100644 --- a/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetRenderer.java +++ b/10-bitClockWidget/app/src/main/java/com/github/ashutoshgngwr/tenbitclockwidget/ClockWidgetRenderer.java @@ -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); @@ -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); @@ -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; @@ -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);