Merge "Consider the clock detached if the keyguard isn't visible" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-05-17 18:19:40 +00:00
committed by Android (Google) Code Review
2 changed files with 72 additions and 35 deletions

View File

@@ -37,7 +37,8 @@ import java.util.Objects;
import java.util.TimeZone; 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> { public class AnimatableClockController extends ViewController<AnimatableClockView> {
private static final int FORMAT_NUMBER = 1234567890; private static final int FORMAT_NUMBER = 1234567890;
@@ -46,6 +47,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
private final BroadcastDispatcher mBroadcastDispatcher; private final BroadcastDispatcher mBroadcastDispatcher;
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final KeyguardBypassController mBypassController; private final KeyguardBypassController mBypassController;
private final BatteryController mBatteryController;
private final int mDozingColor = Color.WHITE; private final int mDozingColor = Color.WHITE;
private int mLockScreenColor; private int mLockScreenColor;
@@ -53,6 +55,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
private boolean mIsCharging; private boolean mIsCharging;
private float mDozeAmount; private float mDozeAmount;
private Locale mLocale; private Locale mLocale;
private boolean mAttached; // if keyguard isn't showing, mAttached = false
private final NumberFormat mBurmeseNf = NumberFormat.getInstance(Locale.forLanguageTag("my")); private final NumberFormat mBurmeseNf = NumberFormat.getInstance(Locale.forLanguageTag("my"));
private final String mBurmeseNumerals; private final String mBurmeseNumerals;
@@ -73,14 +76,17 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
mBroadcastDispatcher = broadcastDispatcher; mBroadcastDispatcher = broadcastDispatcher;
mKeyguardUpdateMonitor = keyguardUpdateMonitor; mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mBypassController = bypassController; mBypassController = bypassController;
mBatteryController = batteryController;
mBurmeseNumerals = mBurmeseNf.format(FORMAT_NUMBER); mBurmeseNumerals = mBurmeseNf.format(FORMAT_NUMBER);
mBurmeseLineSpacing = getContext().getResources().getFloat( mBurmeseLineSpacing = getContext().getResources().getFloat(
R.dimen.keyguard_clock_line_spacing_scale_burmese); R.dimen.keyguard_clock_line_spacing_scale_burmese);
mDefaultLineSpacing = getContext().getResources().getFloat( mDefaultLineSpacing = getContext().getResources().getFloat(
R.dimen.keyguard_clock_line_spacing_scale); R.dimen.keyguard_clock_line_spacing_scale);
}
batteryController.addCallback(new BatteryController.BatteryStateChangeCallback() { private final BatteryController.BatteryStateChangeCallback mBatteryCallback =
new BatteryController.BatteryStateChangeCallback() {
@Override @Override
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
if (!mIsCharging && charging) { if (!mIsCharging && charging) {
@@ -88,29 +94,29 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
} }
mIsCharging = charging; mIsCharging = charging;
} }
}); };
}
private BroadcastReceiver mLocaleBroadcastReceiver = new BroadcastReceiver() { private final BroadcastReceiver mLocaleBroadcastReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
updateLocale(); updateLocale();
} }
}; };
private final KeyguardUpdateMonitorCallback mKeyguardPersistentCallback =
new KeyguardUpdateMonitorCallback() {
@Override @Override
protected void onViewAttached() { public void onKeyguardVisibilityChanged(boolean showing) {
updateLocale(); // call attached/detached methods on visibility changes. benefits include:
mBroadcastDispatcher.registerReceiver(mLocaleBroadcastReceiver, // - no animations when keyguard/clock view aren't visible
new IntentFilter(Intent.ACTION_LOCALE_CHANGED)); // - resets state when keyguard is visible again (ie: font weight)
mStatusBarStateController.addCallback(mStatusBarStateListener); if (showing) {
mIsDozing = mStatusBarStateController.isDozing(); onViewAttached();
mDozeAmount = mStatusBarStateController.getDozeAmount(); } else {
mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback); onViewDetached();
refreshTime();
initColors();
} }
}
};
private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback = private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
new KeyguardUpdateMonitorCallback() { new KeyguardUpdateMonitorCallback() {
@@ -124,11 +130,42 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
} }
}; };
@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();
}
@Override @Override
protected void onViewDetached() { protected void onViewDetached() {
if (!mAttached) {
return;
}
mAttached = false;
mBroadcastDispatcher.unregisterReceiver(mLocaleBroadcastReceiver); mBroadcastDispatcher.unregisterReceiver(mLocaleBroadcastReceiver);
mStatusBarStateController.removeCallback(mStatusBarStateListener); mStatusBarStateController.removeCallback(mStatusBarStateListener);
mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateMonitorCallback); mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateMonitorCallback);
mBatteryController.removeCallback(mBatteryCallback);
if (!mView.isAttachedToWindow()) {
mKeyguardUpdateMonitor.removeCallback(mKeyguardPersistentCallback);
}
} }
/** Animate the clock appearance */ /** Animate the clock appearance */

View File

@@ -124,16 +124,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
@Override @Override
public void onInit() { public void onInit() {
mKeyguardSliceViewController.init(); 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); mClockFrame = mView.findViewById(R.id.lockscreen_clock_view);
mLargeClockFrame = mView.findViewById(R.id.lockscreen_clock_view_large); mLargeClockFrame = mView.findViewById(R.id.lockscreen_clock_view_large);
@@ -157,6 +147,16 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
mKeyguardUpdateMonitor, mKeyguardUpdateMonitor,
mBypassController); mBypassController);
mLargeClockViewController.init(); mLargeClockViewController.init();
}
@Override
protected void onViewAttached() {
if (CUSTOM_CLOCKS_ENABLED) {
mClockManager.addOnClockChangedListener(mClockChangedListener);
}
mColorExtractor.addOnColorsChangedListener(mColorsListener);
mView.updateColors(getGradientColors());
updateAodIcons();
if (mSmartspaceController.isEnabled()) { if (mSmartspaceController.isEnabled()) {
mSmartspaceView = mSmartspaceController.buildAndConnectView(mView); mSmartspaceView = mSmartspaceController.buildAndConnectView(mView);