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..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
@@ -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;
@@ -33,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;
}
}
@@ -69,31 +76,47 @@ 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;
+
+ 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;
}
- }
- // TODO this could be a bit smarter
- public int findRandomAvailablePosition(final int height, final int maxHeight) {
+ if (!(useTop || useTopCenter || useCenter || useCenterBottom || useBottom))
+ {
+ useTop = useTopCenter = useCenter = useCenterBottom = useBottom = true;
+ }
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(bound);
}
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 f270876906..00219735a4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1434,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
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" />
-
-
-
+
+
+
+
+
+
+
+
+
+
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..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,11 +34,9 @@ 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.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