From bd9f127ef84fb62c48a71c7c0baa00b76e62504c Mon Sep 17 00:00:00 2001 From: Paul Keith Date: Mon, 1 Oct 2018 03:10:04 +0200 Subject: [PATCH] sdk: Stop using lerp for night/day mode transitions * This makes it clear what the desired behavior is * In order to make the logic more clear, also start scaling into night mode before civil sunset so that we finish by civil sunset -- this makes sure that by the time there's no light out for practical purposes, we are in night mode * While we're at it, add a few comments about what each return is supposed to do, for the future Change-Id: I4ec0f8eec6b0129a37e99f9e3a2b3f124aeeb4f2 --- .../display/ColorTemperatureController.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java b/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java index 7dbd2874..27b86d9a 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java @@ -293,20 +293,23 @@ public class ColorTemperatureController extends LiveDisplayFeature { */ private static float adj(long now, long sunset, long sunrise) { if (sunset < 0 || sunrise < 0 - || now < sunset || now > (sunrise + TWILIGHT_ADJUSTMENT_TIME)) { + || now < (sunset - TWILIGHT_ADJUSTMENT_TIME) + || now > (sunrise + TWILIGHT_ADJUSTMENT_TIME)) { + // More than 1hr after civil sunrise or before civil sunset return 1.0f; } - if (now <= (sunset + TWILIGHT_ADJUSTMENT_TIME)) { - return MathUtils.lerp(1.0f, 0.0f, - (float) (now - sunset) / TWILIGHT_ADJUSTMENT_TIME); + // Scale the transition into night mode in 1hr before civil sunset + if (now <= sunset) { + return (float) (sunset - now) / TWILIGHT_ADJUSTMENT_TIME; } + // Scale the transition into day mode in 1hr after civil sunrise if (now >= sunrise) { - return MathUtils.lerp(1.0f, 0.0f, - (float) ((sunrise + TWILIGHT_ADJUSTMENT_TIME) - now) / TWILIGHT_ADJUSTMENT_TIME); + return (float) (now - sunrise) / TWILIGHT_ADJUSTMENT_TIME; } + // More than 1hr past civil sunset return 0.0f; }