summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hawkwood Glazier <jglazier@google.com> 2023-04-03 19:17:35 +0000
committer Hawkwood Glazier <jglazier@google.com> 2023-04-04 00:30:51 +0000
commita2cc47dd51a76996ef84f52349a3efca294ebbc2 (patch)
tree601f1622428b21c6e76da60a313870d32b738f50
parent7c41d8e40db235f043a02343a7607039453dde2d (diff)
Refactor various rendering parameters into config structure
Bug: 276770058 Test: Validated clock behavior functioned the same Change-Id: I2cc02ca0d43155eabff614cf883c1d751fb3c974
-rw-r--r--packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt9
-rw-r--r--packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt47
-rw-r--r--packages/SystemUI/src/com/android/keyguard/ClockEventController.kt10
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java12
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java14
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt7
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java8
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewControllerTest.java16
9 files changed, 70 insertions, 63 deletions
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt
index 4df7a44d3e1d..3ec3b5c3f758 100644
--- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt
@@ -25,8 +25,10 @@ import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import com.android.systemui.customization.R
import com.android.systemui.plugins.ClockAnimations
+import com.android.systemui.plugins.ClockConfig
import com.android.systemui.plugins.ClockController
import com.android.systemui.plugins.ClockEvents
+import com.android.systemui.plugins.ClockFaceConfig
import com.android.systemui.plugins.ClockFaceController
import com.android.systemui.plugins.ClockFaceEvents
import com.android.systemui.plugins.ClockSettings
@@ -63,6 +65,8 @@ class DefaultClockController(
override lateinit var animations: DefaultClockAnimations
private set
+ override val config = ClockConfig(hasCustomPositionUpdatedAnimation = true)
+
init {
val parent = FrameLayout(ctx)
smallClock =
@@ -103,6 +107,8 @@ class DefaultClockController(
private var isRegionDark = false
protected var targetRegion: Rect? = null
+ override val config = ClockFaceConfig()
+
override var logBuffer: LogBuffer?
get() = view.logBuffer
set(value) {
@@ -254,9 +260,6 @@ class DefaultClockController(
override fun onPositionUpdated(fromRect: Rect, toRect: Rect, fraction: Float) {
largeClock.moveForSplitShade(fromRect, toRect, fraction)
}
-
- override val hasCustomPositionUpdatedAnimation: Boolean
- get() = true
}
class AnimationState(
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt
index c279053e6daf..322fc774e805 100644
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt
@@ -63,6 +63,9 @@ interface ClockController {
/** A large version of the clock, appropriate when a bigger viewport is available */
val largeClock: ClockFaceController
+ /** Determines the way the hosting app should behave when rendering either clock face */
+ val config: ClockConfig
+
/** Events that clocks may need to respond to */
val events: ClockEvents
@@ -91,6 +94,9 @@ interface ClockFaceController {
/** View that renders the clock face */
val view: View
+ /** Determines the way the hosting app should behave when rendering this clock face */
+ val config: ClockFaceConfig
+
/** Events specific to this clock face */
val events: ClockFaceEvents
@@ -109,9 +115,6 @@ interface ClockEvents {
/** Call whenever the locale changes */
fun onLocaleChanged(locale: Locale) {}
- val isReactiveToTone
- get() = true
-
/** Call whenever the color palette should update */
fun onColorPaletteChanged(resources: Resources) {}
@@ -144,14 +147,6 @@ interface ClockAnimations {
* 0.0 -> clock is scaled down in the shade; previewRatio is previewSize / screenSize
*/
fun onPickerCarouselSwiping(swipingFraction: Float, previewRatio: Float) {}
-
- /**
- * Whether this clock has a custom position update animation. If true, the keyguard will call
- * `onPositionUpdated` to notify the clock of a position update animation. If false, a default
- * animation will be used (e.g. a simple translation).
- */
- val hasCustomPositionUpdatedAnimation
- get() = false
}
/** Events that have specific data about the related face */
@@ -159,14 +154,6 @@ interface ClockFaceEvents {
/** Call every time tick */
fun onTimeTick() {}
- /** Expected interval between calls to onTimeTick. Can always reduce to PER_MINUTE in AOD. */
- val tickRate: ClockTickRate
- get() = ClockTickRate.PER_MINUTE
-
- /** Call to check whether the clock consumes weather data */
- val hasCustomWeatherDataDisplay: Boolean
- get() = false
-
/**
* Region Darkness specific to the clock face.
* - isRegionDark = dark theme -> clock should be light
@@ -203,6 +190,28 @@ data class ClockMetadata(
val name: String,
)
+/** Render configuration for the full clock. Modifies the way systemUI behaves with this clock. */
+data class ClockConfig(
+ /**
+ * Whether this clock has a custom position update animation. If true, the keyguard will call
+ * `onPositionUpdated` to notify the clock of a position update animation. If false, a default
+ * animation will be used (e.g. a simple translation).
+ */
+ val hasCustomPositionUpdatedAnimation: Boolean = false,
+
+ /** True if the clock will react to tone changes in the seed color. */
+ val isReactiveToTone: Boolean = true,
+)
+
+/** Render configuration options for a clock face. Modifies the way SystemUI behaves. */
+data class ClockFaceConfig(
+ /** Expected interval between calls to onTimeTick. Can always reduce to PER_MINUTE in AOD. */
+ val tickRate: ClockTickRate = ClockTickRate.PER_MINUTE,
+
+ /** Call to check whether the clock consumes weather data */
+ val hasCustomWeatherDataDisplay: Boolean = false,
+)
+
/** Structure for keeping clock-specific settings */
@Keep
data class ClockSettings(
diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
index 3b9060ad0ac3..0779653430b2 100644
--- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
+++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
@@ -46,10 +46,10 @@ import com.android.systemui.log.dagger.KeyguardSmallClockLog
import com.android.systemui.plugins.ClockController
import com.android.systemui.plugins.ClockFaceController
import com.android.systemui.plugins.ClockTickRate
+import com.android.systemui.plugins.WeatherData
import com.android.systemui.plugins.log.LogBuffer
import com.android.systemui.plugins.log.LogLevel.DEBUG
import com.android.systemui.shared.regionsampling.RegionSampler
-import com.android.systemui.plugins.WeatherData
import com.android.systemui.statusbar.policy.BatteryController
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback
import com.android.systemui.statusbar.policy.ConfigurationController
@@ -144,8 +144,10 @@ constructor(
val currentViewRect = Rect(left, top, right, bottom)
val oldViewRect = Rect(oldLeft, oldTop, oldRight, oldBottom)
- if (currentViewRect.width() != oldViewRect.width() ||
- currentViewRect.height() != oldViewRect.height()) {
+ if (
+ currentViewRect.width() != oldViewRect.width() ||
+ currentViewRect.height() != oldViewRect.height()
+ ) {
updateRegionSampler(view)
}
}
@@ -425,7 +427,7 @@ constructor(
}
isRunning = true
- when (clockFace.events.tickRate) {
+ when (clockFace.config.tickRate) {
ClockTickRate.PER_MINUTE -> {
/* Handled by KeyguardClockSwitchController */
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
index 07333f79cc94..9290220b8698 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
@@ -40,7 +40,6 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
import com.android.systemui.log.dagger.KeyguardClockLog;
-import com.android.systemui.plugins.ClockAnimations;
import com.android.systemui.plugins.ClockController;
import com.android.systemui.plugins.log.LogBuffer;
import com.android.systemui.plugins.log.LogLevel;
@@ -469,7 +468,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
}
@Nullable
- private ClockController getClock() {
+ public ClockController getClock() {
return mClockEventController.getClock();
}
@@ -535,13 +534,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
}
return ((mCurrentClockSize == LARGE) ? clock.getLargeClock() : clock.getSmallClock())
- .getEvents().getHasCustomWeatherDataDisplay();
- }
-
- /** Gets the animations for the current clock. */
- @Nullable
- public ClockAnimations getClockAnimations() {
- ClockController clock = getClock();
- return clock == null ? null : clock.getAnimations();
+ .getConfig().getHasCustomWeatherDataDisplay();
}
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java
index fd55d69badd1..c4df836e401f 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java
@@ -16,12 +16,13 @@
package com.android.keyguard;
+import android.annotation.Nullable;
import android.graphics.Rect;
import android.util.Slog;
import com.android.keyguard.KeyguardClockSwitch.ClockSize;
import com.android.keyguard.logging.KeyguardLogger;
-import com.android.systemui.plugins.ClockAnimations;
+import com.android.systemui.plugins.ClockController;
import com.android.systemui.statusbar.notification.AnimatableProperty;
import com.android.systemui.statusbar.notification.PropertyAnimator;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
@@ -241,8 +242,9 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
}
}
- /** Gets the animations for the current clock. */
- public ClockAnimations getClockAnimations() {
- return mKeyguardClockSwitchController.getClockAnimations();
+ /** Gets the current clock controller. */
+ @Nullable
+ public ClockController getClockController() {
+ return mKeyguardClockSwitchController.getClock();
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
index 7b4685216111..5adee991e581 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
@@ -160,7 +160,7 @@ import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.NavigationBarController;
import com.android.systemui.navigationbar.NavigationBarView;
import com.android.systemui.navigationbar.NavigationModeController;
-import com.android.systemui.plugins.ClockAnimations;
+import com.android.systemui.plugins.ClockController;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.FalsingManager.FalsingTapListener;
import com.android.systemui.plugins.qs.QS;
@@ -1611,9 +1611,9 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
transition.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
transition.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
- ClockAnimations clockAnims = mKeyguardStatusViewController.getClockAnimations();
- boolean customClockAnimation = clockAnims != null
- && clockAnims.getHasCustomPositionUpdatedAnimation();
+ ClockController clock = mKeyguardStatusViewController.getClockController();
+ boolean customClockAnimation = clock != null
+ && clock.getConfig().getHasCustomPositionUpdatedAnimation();
if (mFeatureFlags.isEnabled(Flags.STEP_CLOCK_ANIMATION) && customClockAnimation) {
// Find the clock, so we can exclude it from this transition.
@@ -5139,12 +5139,12 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
Rect to = (Rect) endValues.values.get(PROP_BOUNDS);
anim.addUpdateListener(animation -> {
- ClockAnimations clockAnims = mController.getClockAnimations();
- if (clockAnims == null) {
+ ClockController clock = mController.getClockController();
+ if (clock == null) {
return;
}
- clockAnims.onPositionUpdated(from, to, animation.getAnimatedFraction());
+ clock.getAnimations().onPositionUpdated(from, to, animation.getAnimatedFraction());
});
return anim;
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt
index 480b8f972b4a..a9920ec77c23 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt
@@ -32,6 +32,7 @@ import com.android.systemui.plugins.ClockAnimations
import com.android.systemui.plugins.ClockController
import com.android.systemui.plugins.ClockEvents
import com.android.systemui.plugins.ClockFaceController
+import com.android.systemui.plugins.ClockFaceConfig
import com.android.systemui.plugins.ClockFaceEvents
import com.android.systemui.plugins.ClockTickRate
import com.android.systemui.plugins.log.LogBuffer
@@ -101,8 +102,10 @@ class ClockEventControllerTest : SysuiTestCase() {
whenever(largeClockController.events).thenReturn(largeClockEvents)
whenever(clock.events).thenReturn(events)
whenever(clock.animations).thenReturn(animations)
- whenever(smallClockEvents.tickRate).thenReturn(ClockTickRate.PER_MINUTE)
- whenever(largeClockEvents.tickRate).thenReturn(ClockTickRate.PER_MINUTE)
+ whenever(smallClockController.config)
+ .thenReturn(ClockFaceConfig(tickRate = ClockTickRate.PER_MINUTE))
+ whenever(largeClockController.config)
+ .thenReturn(ClockFaceConfig(tickRate = ClockTickRate.PER_MINUTE))
repository = FakeKeyguardRepository()
bouncerRepository = FakeKeyguardBouncerRepository()
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
index b15ac39dc57d..2f627cb5d9d7 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
@@ -315,8 +315,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
}
@Test
- public void testGetClockAnimationsForwardsToClock() {
- assertEquals(mClockAnimations, mController.getClockAnimations());
+ public void testGetClock_ForwardsToClock() {
+ assertEquals(mClockController, mController.getClock());
}
@Test
@@ -367,9 +367,9 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
}
@Test
- public void testGetClockAnimations_nullClock_returnsNull() {
+ public void testGetClock_nullClock_returnsNull() {
when(mClockEventController.getClock()).thenReturn(null);
- assertNull(mController.getClockAnimations());
+ assertNull(mController.getClock());
}
private void verifyAttachment(VerificationMode times) {
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewControllerTest.java
index 71449145d668..48f7d924667e 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewControllerTest.java
@@ -16,17 +16,17 @@
package com.android.keyguard;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.graphics.Rect;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import com.android.keyguard.logging.KeyguardLogger;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.plugins.ClockAnimations;
+import com.android.systemui.plugins.ClockController;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
import com.android.systemui.statusbar.policy.ConfigurationController;
@@ -118,14 +118,10 @@ public class KeyguardStatusViewControllerTest extends SysuiTestCase {
}
@Test
- public void getClockAnimations_forwardsToClockSwitch() {
- ClockAnimations mockClockAnimations = mock(ClockAnimations.class);
- when(mKeyguardClockSwitchController.getClockAnimations()).thenReturn(mockClockAnimations);
+ public void getClock_forwardsToClockSwitch() {
+ ClockController mockClock = mock(ClockController.class);
+ when(mKeyguardClockSwitchController.getClock()).thenReturn(mockClock);
- Rect r1 = new Rect(1, 2, 3, 4);
- Rect r2 = new Rect(5, 6, 7, 8);
- mController.getClockAnimations().onPositionUpdated(r1, r2, 0.3f);
-
- verify(mockClockAnimations).onPositionUpdated(r1, r2, 0.3f);
+ assertEquals(mockClock, mController.getClockController());
}
}