From 0cbcb746a93b0194aa29aa3d2d9c4389eeb6edfd Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Thu, 26 Oct 2023 15:11:07 +0200 Subject: [PATCH 1/7] Select where to show Widget on AOD --- .../dexdrip/utils/math/BlockFinder.java | 45 +++++++++++-------- app/src/main/res/values/strings.xml | 11 +++++ app/src/main/res/xml/xdrip_plus_prefs.xml | 45 +++++++++++++++---- 3 files changed, 75 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java index 07569e5298..9b528ba54b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java @@ -1,6 +1,8 @@ package com.eveningoutpost.dexdrip.utils.math; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -69,31 +71,38 @@ public Block addBlockWithMerge(int top, int bottom) { return b; } + // TODO this could be a bit smarter public int findRandomAvailablePositionWithFailSafe(final int height, final int maxHeight) { - val pos = findRandomAvailablePosition(height, maxHeight); - if (pos < 0) { - return new Random().nextInt(maxHeight - height); - } else { - return pos; - } - } + boolean useTop, useTopCenter, useCenter, useCenterBottom, useBottom; + final int sectionSize = maxHeight / 5; - // TODO this could be a bit smarter - public int findRandomAvailablePosition(final int height, final int maxHeight) { + useTop = Pref.getBooleanDefaultFalse("aod_use_top"); + useTopCenter = Pref.getBooleanDefaultFalse("aod_use_top_center"); + useCenter = Pref.getBooleanDefaultFalse("aod_use_center"); + useCenterBottom = Pref.getBooleanDefaultFalse("aod_use_center_bottom"); + useBottom = Pref.getBooleanDefaultFalse("aod_use_bottom"); final int bound = maxHeight - height; - if (bound < 1) return -2; - - int tries = 200; - val random = new Random(); - while (tries-- > 0) { - val pos = random.nextInt(bound); - if (findOverlappingBlock(pos, pos + height) == null) { - return pos; + if (bound >= 1) { + int tries = 200; + val random = new Random(); + + while (tries-- > 0) { + int pos = random.nextInt(bound); + if (findOverlappingBlock(pos, pos + height) == null) { + if ((pos <= sectionSize && useTop) + || (pos >= sectionSize && pos <= 2 * sectionSize && useTopCenter) + || (pos >= 2 * sectionSize && pos <= 3 * sectionSize && useCenter) + || (pos >= 3 * sectionSize && pos <= 4 * sectionSize && useCenterBottom) + || (pos >= 4 * sectionSize && useBottom)) { + return pos; + } + } } } - return -1; + // FailSafe + return new Random().nextInt(maxHeight); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f270876906..20d6c7ba46 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1413,6 +1413,17 @@ Show notification content on secure lockscreen Public Notifications Number Wall on Lock Screen + Always On Display Settings + Use first fifth of screen for AOD Widget + Use top + Use second fifth of screen for AOD Widget + Use top center + Use third fifth of screen for AOD Widget + Use center + Use fourth fifth of screen for AOD Widget + Use center bottom + Use last fifth of screen for AOD Widget + Use bottom Adjust and preview wall layout Configure Number Wall Show on lock-screen. Android 7 and above only! diff --git a/app/src/main/res/xml/xdrip_plus_prefs.xml b/app/src/main/res/xml/xdrip_plus_prefs.xml index fe9ea7a2ac..eef3023bd8 100644 --- a/app/src/main/res/xml/xdrip_plus_prefs.xml +++ b/app/src/main/res/xml/xdrip_plus_prefs.xml @@ -522,14 +522,43 @@ android:key="plus_show_reminders" android:summary="@string/show_reminder_features" android:title="@string/enable_reminder_features" /> - - - + + + + + + + + + + From d2d3f9515127d154b60b5d94e26bbfdef9c14b1f Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Fri, 27 Oct 2023 07:43:29 +0200 Subject: [PATCH 2/7] Use all areas if none is selected --- .../com/eveningoutpost/dexdrip/utils/math/BlockFinder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java index 9b528ba54b..daa4679324 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java @@ -82,6 +82,11 @@ public int findRandomAvailablePositionWithFailSafe(final int height, final int m useCenterBottom = Pref.getBooleanDefaultFalse("aod_use_center_bottom"); useBottom = Pref.getBooleanDefaultFalse("aod_use_bottom"); + if (!(useTop || useTopCenter || useCenter || useCenterBottom || useBottom)) + { + useTop = useTopCenter = useCenter = useCenterBottom = useBottom = true; + } + final int bound = maxHeight - height; if (bound >= 1) { From da9868cb12d16d2b1c65c89d839ee5372293845d Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Fri, 27 Oct 2023 07:58:10 +0200 Subject: [PATCH 3/7] Add German translations, move strings to better place --- app/src/main/res/values-de/strings-de.xml | 11 +++++++++++ app/src/main/res/values/strings.xml | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/values-de/strings-de.xml b/app/src/main/res/values-de/strings-de.xml index c2d002f01e..d92341c683 100644 --- a/app/src/main/res/values-de/strings-de.xml +++ b/app/src/main/res/values-de/strings-de.xml @@ -1388,6 +1388,17 @@ Verwende großes Nummernsymbol Zeigt den Trendpfeil im großen Symbol an Pfeil in großem Symbol anzeigen + Always-On-Display Einstellungen + Erstes Fünftel des Bildschirms für das AOD-Widget benutzen + Oberen Rand benutzen + Zweites Fünftel des Bildschirms für das AOD-Widget benutzen + Obere Mitte benutzen + Drittes Fünftel des Bildschirms für das AOD-Widget benutzen + Mitte benutzen + Viertes Fünftel des Bildschirms für das AOD-Widget benutzen + Untere Mitte benutzen + Letztes Fünftel des Bildschirms für das AOD-Widget benutzen + Unteren Rand benutzen Zeige den xDrip-Bildschirm automatisch nach dem Start des Geräts Zeige xDrip beim Booten EULA diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 20d6c7ba46..00219735a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1413,17 +1413,6 @@ Show notification content on secure lockscreen Public Notifications Number Wall on Lock Screen - Always On Display Settings - Use first fifth of screen for AOD Widget - Use top - Use second fifth of screen for AOD Widget - Use top center - Use third fifth of screen for AOD Widget - Use center - Use fourth fifth of screen for AOD Widget - Use center bottom - Use last fifth of screen for AOD Widget - Use bottom Adjust and preview wall layout Configure Number Wall Show on lock-screen. Android 7 and above only! @@ -1445,6 +1434,17 @@ Use Large Number Icon Shows the trend arrow in the large icon Show Arrow in Large Icon + Always On Display Settings + Use first fifth of screen for AOD Widget + Use top + Use second fifth of screen for AOD Widget + Use top center + Use third fifth of screen for AOD Widget + Use center + Use fourth fifth of screen for AOD Widget + Use center bottom + Use last fifth of screen for AOD Widget + Use bottom Bring up xDrip screen automatically after device boots Show xDrip on Boot EULA From 6c597ad7eb6fed1b52d6645de090d1b4b31e6e96 Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Fri, 27 Oct 2023 13:27:31 +0200 Subject: [PATCH 4/7] Fix Tests --- .../com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java b/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java index bd11d17897..ca550df0e0 100644 --- a/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java +++ b/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java @@ -38,7 +38,7 @@ public void findRandomAvailablePositionTest() { assertWithMessage("impossible fit").that(b.findRandomAvailablePosition(100, 200)).isEqualTo(-1); for (int i = 0; i < 50; i++) { assertWithMessage("impossible fit failsafe " + i).that(b.findRandomAvailablePositionWithFailSafe(100, 200)).isIn(Range.closed(0, 100)); - assertWithMessage("example fit " + i).that(b.findRandomAvailablePosition(50, 2000)).isIn(Range.closed(50, 2000 - 50)); + assertWithMessage("example fit " + i).that(b.findRandomAvailablePositionWithFailSafe(50, 2000)).isIn(Range.closed(50, 2000 - 50)); } } } \ No newline at end of file From 8bc0d6d7b1f4f34c0e8b3650650fb33988d0d297 Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Wed, 20 Dec 2023 11:53:49 +0100 Subject: [PATCH 5/7] Fix Tests: There is no findRandomAvailablePosition anymore --- .../com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java b/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java index ca550df0e0..29d905e857 100644 --- a/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java +++ b/app/src/test/java/com/eveningoutpost/dexdrip/utils/math/BlockFinderTest.java @@ -34,8 +34,6 @@ public void findRandomAvailablePositionTest() { val b = new BlockFinder(); b.addBlockWithMerge(10, 100); b.addBlockWithMerge(50, 150); - assertWithMessage("invalid bound test").that(b.findRandomAvailablePosition(200, 50)).isEqualTo(-2); - assertWithMessage("impossible fit").that(b.findRandomAvailablePosition(100, 200)).isEqualTo(-1); for (int i = 0; i < 50; i++) { assertWithMessage("impossible fit failsafe " + i).that(b.findRandomAvailablePositionWithFailSafe(100, 200)).isIn(Range.closed(0, 100)); assertWithMessage("example fit " + i).that(b.findRandomAvailablePositionWithFailSafe(50, 2000)).isIn(Range.closed(50, 2000 - 50)); From e9e80310abb1c88f9c2d8375ff51ec28cd1722a8 Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Wed, 20 Dec 2023 12:16:38 +0100 Subject: [PATCH 6/7] Fix Tests: Block.set: Do not return null pointer --- .../dexdrip/utils/math/BlockFinder.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java index daa4679324..51cbe0612b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java @@ -35,9 +35,14 @@ public String toString() { } public Block set(final int top, final int bottom) { - if (top < 0 || bottom < 0) return null; - this.top = top; - this.bottom = bottom; + if (top < 0 || bottom < 0) + { + this.top = 0; + this.bottom = 0; + } else { + this.top = top; + this.bottom = bottom; + } return this; } } @@ -107,7 +112,7 @@ public int findRandomAvailablePositionWithFailSafe(final int height, final int m } } // FailSafe - return new Random().nextInt(maxHeight); + return new Random().nextInt(bound); } From f9884266dc9849e40f4d6a09a61591cdc6145a4e Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Mon, 29 Jan 2024 14:20:09 +0100 Subject: [PATCH 7/7] Catch NPE --- .../dexdrip/utils/math/BlockFinder.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java index 51cbe0612b..cfe540dd6b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java @@ -81,11 +81,15 @@ public int findRandomAvailablePositionWithFailSafe(final int height, final int m boolean useTop, useTopCenter, useCenter, useCenterBottom, useBottom; final int sectionSize = maxHeight / 5; - useTop = Pref.getBooleanDefaultFalse("aod_use_top"); - useTopCenter = Pref.getBooleanDefaultFalse("aod_use_top_center"); - useCenter = Pref.getBooleanDefaultFalse("aod_use_center"); - useCenterBottom = Pref.getBooleanDefaultFalse("aod_use_center_bottom"); - useBottom = Pref.getBooleanDefaultFalse("aod_use_bottom"); + try { + useTop = Pref.getBooleanDefaultFalse("aod_use_top"); + useTopCenter = Pref.getBooleanDefaultFalse("aod_use_top_center"); + useCenter = Pref.getBooleanDefaultFalse("aod_use_center"); + useCenterBottom = Pref.getBooleanDefaultFalse("aod_use_center_bottom"); + useBottom = Pref.getBooleanDefaultFalse("aod_use_bottom"); + } catch (NullPointerException e) { + useTop = useTopCenter = useCenter = useCenterBottom = useBottom = true; + } if (!(useTop || useTopCenter || useCenter || useCenterBottom || useBottom)) {