summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeverly <beverlyt@google.com>2021-05-14 16:03:46 -0400
committerBeverly <beverlyt@google.com>2021-05-14 16:22:18 -0400
commitf18b2894e4a4cd1f27ec1026bd13fc84c6a4b15c (patch)
treee742de09fbd0af05bd7f3a239242ca8ac43bd94c
parent66dc0f32ede6e8748564aa5b261cf3ed0d284eaa (diff)
Consider the clock detached if the keyguard isn't visible
Update AnimatableClockController's definition of attached to include whether the keyguard is visible or not. This way, we won't animate if the view isn't actually visible & we'll reset the clock state when the keyguard is newly visible. Only create a new AnimatableClockController onInit instead of in the onAttach method for KeyguardClockSwitchController. Fixes: 188203771 Test: manual Change-Id: Id02132dba8b5392046cb46766aa64fd58e04a4ad
-rw-r--r--packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java83
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java20
2 files changed, 70 insertions, 33 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java
index 4b9bf8c27f8a..e6ec04b4e391 100644
--- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java
+++ b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java
@@ -37,7 +37,8 @@ import java.util.Objects;
import java.util.TimeZone;
/**
- * Controller for an AnimatableClockView. Instantiated by {@link KeyguardClockSwitchController}.
+ * Controller for an AnimatableClockView on the keyguard. Instantiated by
+ * {@link KeyguardClockSwitchController}.
*/
public class AnimatableClockController extends ViewController<AnimatableClockView> {
private static final int FORMAT_NUMBER = 1234567890;
@@ -46,6 +47,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
private final BroadcastDispatcher mBroadcastDispatcher;
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final KeyguardBypassController mBypassController;
+ private final BatteryController mBatteryController;
private final int mDozingColor = Color.WHITE;
private int mLockScreenColor;
@@ -53,6 +55,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
private boolean mIsCharging;
private float mDozeAmount;
private Locale mLocale;
+ private boolean mAttached; // if keyguard isn't showing, mAttached = false
private final NumberFormat mBurmeseNf = NumberFormat.getInstance(Locale.forLanguageTag("my"));
private final String mBurmeseNumerals;
@@ -73,62 +76,96 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
mBroadcastDispatcher = broadcastDispatcher;
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mBypassController = bypassController;
+ mBatteryController = batteryController;
mBurmeseNumerals = mBurmeseNf.format(FORMAT_NUMBER);
mBurmeseLineSpacing = getContext().getResources().getFloat(
R.dimen.keyguard_clock_line_spacing_scale_burmese);
mDefaultLineSpacing = getContext().getResources().getFloat(
R.dimen.keyguard_clock_line_spacing_scale);
+ }
- batteryController.addCallback(new BatteryController.BatteryStateChangeCallback() {
- @Override
- public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
- if (!mIsCharging && charging) {
- mView.animateCharge(mIsDozing);
- }
- mIsCharging = charging;
+ private final BatteryController.BatteryStateChangeCallback mBatteryCallback =
+ new BatteryController.BatteryStateChangeCallback() {
+ @Override
+ public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
+ if (!mIsCharging && charging) {
+ mView.animateCharge(mIsDozing);
}
- });
- }
+ mIsCharging = charging;
+ }
+ };
- private BroadcastReceiver mLocaleBroadcastReceiver = new BroadcastReceiver() {
+ private final BroadcastReceiver mLocaleBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateLocale();
}
};
+ private final KeyguardUpdateMonitorCallback mKeyguardPersistentCallback =
+ new KeyguardUpdateMonitorCallback() {
+ @Override
+ public void onKeyguardVisibilityChanged(boolean showing) {
+ // call attached/detached methods on visibility changes. benefits include:
+ // - no animations when keyguard/clock view aren't visible
+ // - resets state when keyguard is visible again (ie: font weight)
+ if (showing) {
+ onViewAttached();
+ } else {
+ onViewDetached();
+ }
+ }
+ };
+
+ private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
+ new KeyguardUpdateMonitorCallback() {
+ @Override
+ public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType,
+ boolean isStrongBiometric) {
+ if (biometricSourceType == BiometricSourceType.FACE
+ && mBypassController.canBypass()) {
+ mView.animateDisappear();
+ }
+ }
+ };
+
@Override
protected void onViewAttached() {
+ if (mAttached) {
+ return;
+ }
+ mAttached = true;
updateLocale();
mBroadcastDispatcher.registerReceiver(mLocaleBroadcastReceiver,
new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
mStatusBarStateController.addCallback(mStatusBarStateListener);
mIsDozing = mStatusBarStateController.isDozing();
mDozeAmount = mStatusBarStateController.getDozeAmount();
+ mBatteryController.addCallback(mBatteryCallback);
mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);
+ mKeyguardUpdateMonitor.removeCallback(mKeyguardPersistentCallback);
+ mKeyguardUpdateMonitor.registerCallback(mKeyguardPersistentCallback);
+
refreshTime();
initColors();
}
- private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
- new KeyguardUpdateMonitorCallback() {
- @Override
- public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType,
- boolean isStrongBiometric) {
- if (biometricSourceType == BiometricSourceType.FACE
- && mBypassController.canBypass()) {
- mView.animateDisappear();
- }
- }
- };
-
@Override
protected void onViewDetached() {
+ if (!mAttached) {
+ return;
+ }
+
+ mAttached = false;
mBroadcastDispatcher.unregisterReceiver(mLocaleBroadcastReceiver);
mStatusBarStateController.removeCallback(mStatusBarStateListener);
mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateMonitorCallback);
+ mBatteryController.removeCallback(mBatteryCallback);
+ if (!mView.isAttachedToWindow()) {
+ mKeyguardUpdateMonitor.removeCallback(mKeyguardPersistentCallback);
+ }
}
/** Animate the clock appearance */
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
index 4245fbc2c3cd..932860f6c29c 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
@@ -124,16 +124,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
@Override
public void onInit() {
mKeyguardSliceViewController.init();
- }
-
- @Override
- protected void onViewAttached() {
- if (CUSTOM_CLOCKS_ENABLED) {
- mClockManager.addOnClockChangedListener(mClockChangedListener);
- }
- mColorExtractor.addOnColorsChangedListener(mColorsListener);
- mView.updateColors(getGradientColors());
- updateAodIcons();
mClockFrame = mView.findViewById(R.id.lockscreen_clock_view);
mLargeClockFrame = mView.findViewById(R.id.lockscreen_clock_view_large);
@@ -157,6 +147,16 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
mKeyguardUpdateMonitor,
mBypassController);
mLargeClockViewController.init();
+ }
+
+ @Override
+ protected void onViewAttached() {
+ if (CUSTOM_CLOCKS_ENABLED) {
+ mClockManager.addOnClockChangedListener(mClockChangedListener);
+ }
+ mColorExtractor.addOnColorsChangedListener(mColorsListener);
+ mView.updateColors(getGradientColors());
+ updateAodIcons();
if (mSmartspaceController.isEnabled()) {
mSmartspaceView = mSmartspaceController.buildAndConnectView(mView);