Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Brightness: down to 1 %, in 1 % steps below 10 %

מקס חיים929e38507a57
diff --git a/addons/brightness/README.md b/addons/brightness/README.md
index 7ff568cd6..3c10ae110 100644
--- a/addons/brightness/README.md
+++ b/addons/brightness/README.md
@@ -12,16 +12,16 @@ Opening it shows one list, worked with the remote alone:
| Row | What it does |
|---|---|
| **Dimming** | The master switch, focused first. **Off puts the screen back to normal at once**; the other settings stay for next time. |
-| **Brightness** | A slider from 100 % down to 5 % in 5 % steps (◀ ▶), used outside night mode. |
+| **Brightness** | A slider from 100 % down to 1 % (◀ ▶): 5 % steps, then 1 % steps below 10 %. Used outside night mode. |
| **Night mode** | Off, On (now, until switched off) or Scheduled (every day between two times). |
-| **Night brightness** | Its own slider, 5 % to 100 %. |
+| **Night brightness** | Its own slider, 1 % to 100 %. |
| **Warmth** | Night mode only: an amber tint that takes blue out of the picture, 0 to 100 %. |
| **Night starts**, **Night ends** | The schedule, in 15 minute steps; a night may run past midnight (21:00 to 07:00 is the default). |
Every change shows at once, over the settings screen too, so you see the result as you move the slider. The
settings are kept, and the layer and the schedule come back after a reboot.
-The screen never goes below 5 %, so the picture and this app stay faintly visible whatever is set. If it is ever too
+The layer never goes below 1 %. Below about 5 % the picture is hard to see, so the switch back is always the first row. If it is ever too
dark to find the way, any of these gives the normal screen back:
- open Brightness and press OK on **Dimming**;
@@ -87,11 +87,11 @@ with your own key if you hand them out; the launcher pins its Show answer to the
MOKA R8G (Android 14), over ADB, with its own home app: the overlay permission granted by ADB, the layer drawn
over the settings screen and over Home, the scheduled night mode taking over at 21:13 inside a 21:00 to 07:00
-window (40 %, then down to 5 %, warm), each slider changing the layer at once, **Dimming** Off and the ADB
+window (40 %, then down to 1 %, warm), each slider changing the layer at once, **Dimming** Off and the ADB
broadcast removing the layer at once and On bringing it back, and the layer back by itself after the app was updated. Memory: about 22 MB with the layer up.
The JVM tests cover the levels, the colour arithmetic, the schedule (past midnight, edges, empty windows), the
-5 % floor and the clamping of stored values.
+1 % floor, the fine steps and the clamping of stored values.
Still to check on a TV running this repo's launcher (the test TV's home app has no module cards):
diff --git a/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/Dimming.java b/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/Dimming.java
index aafcfaaf8..306077e00 100644
--- a/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/Dimming.java
+++ b/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/Dimming.java
@@ -5,10 +5,12 @@ package io.github.maxhayim.brightness;
* at a given minute, the one colour the layer is drawn in, and when the schedule next changes.
*/
final class Dimming {
- /** The darkest the screen goes: 5 % of normal, so menus and this app stay faintly visible whatever is set. */
- static final int MIN_BRIGHTNESS = 5;
+ /** The darkest the layer goes: 1 % of normal, for a TV whose own backlight is already at its lowest. */
+ static final int MIN_BRIGHTNESS = 1;
static final int MAX_BRIGHTNESS = 100;
static final int BRIGHTNESS_STEP = 5;
+ /** Below this the slider moves in 1 % steps, where each step is a large share of what is left. */
+ static final int FINE_BELOW = 10;
static final int WARMTH_STEP = 10;
static final int TIME_STEP = 15;
static final int DAY_MINUTES = 24 * 60;
@@ -31,8 +33,8 @@ final class Dimming {
/** Every value back in range, whatever the stored copy held. */
Settings clamped() {
- brightness = clamp(snap(brightness, BRIGHTNESS_STEP), MIN_BRIGHTNESS, MAX_BRIGHTNESS);
- nightBrightness = clamp(snap(nightBrightness, BRIGHTNESS_STEP), MIN_BRIGHTNESS, MAX_BRIGHTNESS);
+ brightness = clampBrightness(brightness);
+ nightBrightness = clampBrightness(nightBrightness);
warmth = clamp(snap(warmth, WARMTH_STEP), 0, 100);
nightStart = wrap(snap(nightStart, TIME_STEP));
nightEnd = wrap(snap(nightEnd, TIME_STEP));
@@ -125,6 +127,16 @@ final class Dimming {
return String.format(java.util.Locale.ROOT, "%d:%02d %s", h % 12 == 0 ? 12 : h % 12, m, h < 12 ? "AM" : "PM");
}
+ /** One press of ◀ or ▶ on a brightness slider: 5 % steps, 1 % steps below FINE_BELOW. */
+ static int stepBrightness(int v, int direction) {
+ boolean fine = v < FINE_BELOW || (v == FINE_BELOW && direction < 0);
+ return clampBrightness(v + direction * (fine ? 1 : BRIGHTNESS_STEP));
+ }
+
+ static int clampBrightness(int v) {
+ return clamp(v < FINE_BELOW ? v : snap(v, BRIGHTNESS_STEP), MIN_BRIGHTNESS, MAX_BRIGHTNESS);
+ }
+
static int clamp(int v, int lo, int hi) {
return Math.max(lo, Math.min(hi, v));
}
diff --git a/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/MainActivity.java b/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/MainActivity.java
index 7cc0aefb2..dff2c2bb0 100644
--- a/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/MainActivity.java
+++ b/addons/brightness/app/src/main/java/io/github/maxhayim/brightness/MainActivity.java
@@ -87,7 +87,7 @@ public class MainActivity extends Activity {
}));
brightnessRow = add(new Row(this, "Brightness", "How bright the picture is outside night mode.", true, null,
d -> {
- s.brightness += d * Dimming.BRIGHTNESS_STEP;
+ s.brightness = Dimming.stepBrightness(s.brightness, d);
changed();
}));
nightRow = add(new Row(this, "Night mode", null, false, () -> {
@@ -99,7 +99,7 @@ public class MainActivity extends Activity {
}));
nightBrightnessRow = add(new Row(this, "Night brightness", "How bright the picture is in night mode.", true,
null, d -> {
- s.nightBrightness += d * Dimming.BRIGHTNESS_STEP;
+ s.nightBrightness = Dimming.stepBrightness(s.nightBrightness, d);
changed();
}));
warmthRow = add(new Row(this, "Warmth", "Night mode only: less blue, a warmer picture.", true, null, d -> {
diff --git a/addons/brightness/app/src/test/java/io/github/maxhayim/brightness/DimmingTest.java b/addons/brightness/app/src/test/java/io/github/maxhayim/brightness/DimmingTest.java
index 791f2aaaf..b5c43b900 100644
--- a/addons/brightness/app/src/test/java/io/github/maxhayim/brightness/DimmingTest.java
+++ b/addons/brightness/app/src/test/java/io/github/maxhayim/brightness/DimmingTest.java
@@ -80,7 +80,7 @@ public class DimmingTest {
assertEquals(Dimming.MIN_BRIGHTNESS, s.nightBrightness);
assertEquals(100, s.warmth);
int black = alpha(Dimming.color(new Dimming.Level(Dimming.MIN_BRIGHTNESS, 0, false)));
- assertEquals(Math.round(0.95 * 255), black);
+ assertEquals(Math.round(0.99 * 255), black);
}
@Test
@@ -97,6 +97,19 @@ public class DimmingTest {
assertEquals(Dimming.Night.SCHEDULED, s.night);
}
+ @Test
+ public void slidersStepFiveThenOneBelowTen() {
+ assertEquals(15, Dimming.stepBrightness(20, -1));
+ assertEquals(9, Dimming.stepBrightness(10, -1));
+ assertEquals(10, Dimming.stepBrightness(9, 1));
+ assertEquals(15, Dimming.stepBrightness(10, 1));
+ assertEquals(1, Dimming.stepBrightness(1, -1));
+ assertEquals(100, Dimming.stepBrightness(100, 1));
+ Dimming.Settings s = on();
+ s.nightBrightness = 3;
+ assertEquals("fine values survive a reload", 3, s.clamped().nightBrightness);
+ }
+
@Test
public void windowPastMidnight() {
int start = 21 * 60, end = 7 * 60;