From 13c1e7eff3b468176400ccfa17be8842f3143566 Mon Sep 17 00:00:00 2001 From: Grace Date: Tue, 21 Jun 2022 20:04:17 +0000 Subject: [PATCH] [DO NOT MERGE] Adding Region Sampler to Animatable Clocks A RegionSamplingHelper is used to extract the color of the wallpaper behind an AnimatableClockController. This is used to set the color of the clock to a contrasting hue so that the text is legible. These changes fixes the problem of the clock text blending into the wallpaper. Bug: 202758428 Test: atest AnimatableClockControllerTest Change-Id: I645c2a0b4e68d5ec9165a2eb354f6d814acbf596 Merged-In: I645c2a0b4e68d5ec9165a2eb354f6d814acbf596 --- .../keyguard/AnimatableClockController.java | 69 ++++++++++++++++++- .../AnimatableClockControllerTest.java | 14 +++- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java index dd69f334c783e..6064be94bc0a2 100644 --- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java +++ b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java @@ -22,7 +22,9 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.graphics.Color; +import android.graphics.Rect; import android.icu.text.NumberFormat; +import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; @@ -30,16 +32,24 @@ import androidx.annotation.VisibleForTesting; import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; +import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.flags.FeatureFlags; +import com.android.systemui.flags.Flags; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.clocks.AnimatableClockView; +import com.android.systemui.shared.navigationbar.RegionSamplingHelper; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.util.ViewController; import java.io.PrintWriter; import java.util.Locale; import java.util.Objects; +import java.util.Optional; import java.util.TimeZone; +import java.util.concurrent.Executor; + +import javax.inject.Inject; /** * Controller for an AnimatableClockView on the keyguard. Instantiated by @@ -54,7 +64,10 @@ public class AnimatableClockController extends ViewController mRegionSamplingHelper = Optional.empty(); + private Rect mSamplingBounds = new Rect(); private int mLockScreenColor; + private final boolean mRegionSamplingEnabled; private boolean mIsDozing; private boolean mIsCharging; @@ -67,13 +80,17 @@ public class AnimatableClockController extends ViewController { + regionSamplingHelper.setWindowVisible(true); + }); } private void reset() { @@ -169,6 +220,10 @@ public class AnimatableClockController extends ViewController { + regionSamplingHelper.start(mSamplingBounds); + }); + mView.onTimeZoneChanged(TimeZone.getDefault()); initColors(); mView.animateDoze(mIsDozing, false); @@ -180,6 +235,9 @@ public class AnimatableClockController extends ViewController { + regionSamplingHelper.stop(); + }); } /** Animate the clock appearance */ @@ -223,8 +281,10 @@ public class AnimatableClockController extends ViewController { + regionSamplingHelper.dump(pw); + }); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/AnimatableClockControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/AnimatableClockControllerTest.java index df506b479b88a..b5e9e8decb4c0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/AnimatableClockControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/AnimatableClockControllerTest.java @@ -38,6 +38,7 @@ import com.android.keyguard.KeyguardUpdateMonitor; import com.android.settingslib.Utils; import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; +import com.android.systemui.flags.FeatureFlags; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.clocks.AnimatableClockView; import com.android.systemui.statusbar.policy.BatteryController; @@ -53,6 +54,8 @@ import org.mockito.MockitoAnnotations; import org.mockito.MockitoSession; import org.mockito.quality.Strictness; +import java.util.concurrent.Executor; + @SmallTest @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper @@ -69,6 +72,12 @@ public class AnimatableClockControllerTest extends SysuiTestCase { private KeyguardUpdateMonitor mKeyguardUpdateMonitor; @Mock private Resources mResources; + @Mock + private Executor mMainExecutor; + @Mock + private Executor mBgExecutor; + @Mock + private FeatureFlags mFeatureFlags; private MockitoSession mStaticMockSession; private AnimatableClockController mAnimatableClockController; @@ -96,7 +105,10 @@ public class AnimatableClockControllerTest extends SysuiTestCase { mBroadcastDispatcher, mBatteryController, mKeyguardUpdateMonitor, - mResources + mResources, + mMainExecutor, + mBgExecutor, + mFeatureFlags ); mAnimatableClockController.init(); captureAttachListener();