aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Keith <javelinanddart@gmail.com>2018-10-01 03:10:04 +0200
committerPaul Keith <javelinanddart@gmail.com>2019-01-18 23:33:21 +0100
commitbd9f127ef84fb62c48a71c7c0baa00b76e62504c (patch)
tree394a17f8a0809669b6103ae942bb524022065db4
parent0b12914dbf60fd1cac96fadf8e8a2e4db8f567e5 (diff)
downloadlineage-sdk-bd9f127ef84fb62c48a71c7c0baa00b76e62504c.tar.gz
lineage-sdk-bd9f127ef84fb62c48a71c7c0baa00b76e62504c.tar.bz2
lineage-sdk-bd9f127ef84fb62c48a71c7c0baa00b76e62504c.zip
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
-rw-r--r--lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java15
1 files 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;
}