diff options
author | Scott Lobdell <slobdell@google.com> | 2021-04-25 19:53:32 +0000 |
---|---|---|
committer | Daniel Norman <danielnorman@google.com> | 2021-04-29 09:44:07 -0700 |
commit | 2051462f672b5986ef321bf1de3657e7653864e8 (patch) | |
tree | 1dee6334f2b0a68d3cc2e532e6f89bb16149aa7d /packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java | |
parent | b22baa1593b2ee33200d009f7f56d1c44a75ac6d (diff) | |
parent | ab6136865a519a27d731b4caa3e782bdf02cfd91 (diff) |
Merge SP1A.210425.001
Change-Id: I8d45e47c131320cac5e794fd629fdef84dd3bcfc
Diffstat (limited to 'packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java')
-rw-r--r-- | packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java | 326 |
1 files changed, 161 insertions, 165 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index 24b7cd118ed6..5559a1818b4b 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -19,38 +19,42 @@ package com.android.keyguard; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; +import android.app.PendingIntent; import android.app.WallpaperManager; import android.app.smartspace.SmartspaceConfig; import android.app.smartspace.SmartspaceManager; import android.app.smartspace.SmartspaceSession; -import android.content.ContentResolver; -import android.content.Context; +import android.content.Intent; import android.content.res.Resources; -import android.provider.Settings; import android.text.TextUtils; import android.text.format.DateFormat; import android.view.View; -import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.RelativeLayout; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.colorextraction.ColorExtractor; import com.android.keyguard.clock.ClockManager; +import com.android.settingslib.Utils; import com.android.systemui.R; +import com.android.systemui.SystemUIFactory; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.colorextraction.SysuiColorExtractor; import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.BcSmartspaceDataPlugin; +import com.android.systemui.plugins.BcSmartspaceDataPlugin.IntentStarter; import com.android.systemui.plugins.ClockPlugin; -import com.android.systemui.plugins.PluginListener; +import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.statusbar.StatusBarStateController; -import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.notification.AnimatableProperty; import com.android.systemui.statusbar.notification.PropertyAnimator; import com.android.systemui.statusbar.notification.stack.AnimationProperties; import com.android.systemui.statusbar.phone.NotificationIconAreaController; import com.android.systemui.statusbar.phone.NotificationIconContainer; +import com.android.systemui.statusbar.policy.BatteryController; +import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.ViewController; import java.util.Locale; @@ -65,38 +69,31 @@ import javax.inject.Inject; public class KeyguardClockSwitchController extends ViewController<KeyguardClockSwitch> { private static final boolean CUSTOM_CLOCKS_ENABLED = true; - private final Resources mResources; private final StatusBarStateController mStatusBarStateController; private final SysuiColorExtractor mColorExtractor; private final ClockManager mClockManager; private final KeyguardSliceViewController mKeyguardSliceViewController; private final NotificationIconAreaController mNotificationIconAreaController; private final BroadcastDispatcher mBroadcastDispatcher; + private final Executor mUiExecutor; + private final BatteryController mBatteryController; + private final FeatureFlags mFeatureFlags; + private final SystemUIFactory mSystemUIFactory; /** - * Gradient clock for usage when mode != KeyguardUpdateMonitor.LOCK_SCREEN_MODE_NORMAL. + * Clock for both small and large sizes */ - private AnimatableClockController mNewLockScreenClockViewController; - private FrameLayout mNewLockScreenClockFrame; - private AnimatableClockController mNewLockScreenLargeClockViewController; - private FrameLayout mNewLockScreenLargeClockFrame; - - private PluginManager mPluginManager; - private boolean mIsSmartspaceEnabled; - PluginListener mPluginListener; - private Executor mUiExecutor; - private SmartspaceSession mSmartspaceSession; - private SmartspaceSession.Callback mSmartspaceCallback; - - private int mLockScreenMode = KeyguardUpdateMonitor.LOCK_SCREEN_MODE_NORMAL; + private AnimatableClockController mClockViewController; + private FrameLayout mClockFrame; + private AnimatableClockController mLargeClockViewController; + private FrameLayout mLargeClockFrame; - private final StatusBarStateController.StateListener mStateListener = - new StatusBarStateController.StateListener() { - @Override - public void onStateChanged(int newState) { - mView.updateBigClockVisibility(newState); - } - }; + private SmartspaceSession mSmartspaceSession; + private SmartspaceSession.OnTargetsAvailableListener mSmartspaceCallback; + private int mWallpaperTextColor; + private ConfigurationController mConfigurationController; + private ActivityStarter mActivityStarter; + private FalsingManager mFalsingManager; /** * Listener for changes to the color palette. @@ -113,8 +110,25 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } }; + private final ConfigurationController.ConfigurationListener mConfigurationListener = + new ConfigurationController.ConfigurationListener() { + @Override + public void onThemeChanged() { + updateWallpaperColor(); + } + }; + private ClockManager.ClockChangedListener mClockChangedListener = this::setClockPlugin; - private String mTimeFormat; + + private final StatusBarStateController.StateListener mStatusBarStateListener = + new StatusBarStateController.StateListener() { + @Override + public void onDozeAmountChanged(float linear, float eased) { + if (mSmartspaceView != null) { + mSmartspaceView.setDozeAmount(eased); + } + } + }; // If set, will replace keyguard_status_area private BcSmartspaceDataPlugin.SmartspaceView mSmartspaceView; @@ -122,28 +136,32 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS @Inject public KeyguardClockSwitchController( KeyguardClockSwitch keyguardClockSwitch, - @Main Resources resources, StatusBarStateController statusBarStateController, SysuiColorExtractor colorExtractor, ClockManager clockManager, KeyguardSliceViewController keyguardSliceViewController, NotificationIconAreaController notificationIconAreaController, - ContentResolver contentResolver, BroadcastDispatcher broadcastDispatcher, - PluginManager pluginManager, FeatureFlags featureFlags, - @Main Executor uiExecutor) { + @Main Executor uiExecutor, + BatteryController batteryController, + ConfigurationController configurationController, + SystemUIFactory systemUIFactory, + ActivityStarter activityStarter, + FalsingManager falsingManager) { super(keyguardClockSwitch); - mResources = resources; mStatusBarStateController = statusBarStateController; mColorExtractor = colorExtractor; mClockManager = clockManager; mKeyguardSliceViewController = keyguardSliceViewController; mNotificationIconAreaController = notificationIconAreaController; mBroadcastDispatcher = broadcastDispatcher; - mTimeFormat = Settings.System.getString(contentResolver, Settings.System.TIME_12_24); - mPluginManager = pluginManager; - mIsSmartspaceEnabled = featureFlags.isSmartspaceEnabled(); + mFeatureFlags = featureFlags; mUiExecutor = uiExecutor; + mBatteryController = batteryController; + mConfigurationController = configurationController; + mSystemUIFactory = systemUIFactory; + mActivityStarter = activityStarter; + mFalsingManager = falsingManager; } /** @@ -159,70 +177,91 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS if (CUSTOM_CLOCKS_ENABLED) { mClockManager.addOnClockChangedListener(mClockChangedListener); } - refreshFormat(); - mStatusBarStateController.addCallback(mStateListener); mColorExtractor.addOnColorsChangedListener(mColorsListener); mView.updateColors(getGradientColors()); updateAodIcons(); - mNewLockScreenClockFrame = mView.findViewById(R.id.new_lockscreen_clock_view); - mNewLockScreenLargeClockFrame = mView.findViewById(R.id.new_lockscreen_clock_view_large); - - // If a smartspace plugin is detected, replace the existing smartspace - // (keyguard_status_area), and initialize a new session - mPluginListener = new PluginListener<BcSmartspaceDataPlugin>() { - - @Override - public void onPluginConnected(BcSmartspaceDataPlugin plugin, Context pluginContext) { - if (!mIsSmartspaceEnabled) return; - - View ksa = mView.findViewById(R.id.keyguard_status_area); - int ksaIndex = mView.indexOfChild(ksa); - ksa.setVisibility(View.GONE); - - mSmartspaceView = plugin.getView(mView); - mSmartspaceView.registerDataProvider(plugin); - - RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( - MATCH_PARENT, WRAP_CONTENT); - lp.addRule(RelativeLayout.BELOW, R.id.new_lockscreen_clock_view); - mView.addView((View) mSmartspaceView, ksaIndex, lp); - View nic = mView.findViewById( - com.android.systemui.R.id.left_aligned_notification_icon_container); - lp = (RelativeLayout.LayoutParams) nic.getLayoutParams(); - lp.addRule(RelativeLayout.BELOW, ((View) mSmartspaceView).getId()); - nic.setLayoutParams(lp); - - createSmartspaceSession(plugin); - } - - @Override - public void onPluginDisconnected(BcSmartspaceDataPlugin plugin) { - if (!mIsSmartspaceEnabled) return; - - mView.removeView((View) mSmartspaceView); - mView.findViewById(R.id.keyguard_status_area).setVisibility(View.VISIBLE); + mClockFrame = mView.findViewById(R.id.lockscreen_clock_view); + mLargeClockFrame = mView.findViewById(R.id.lockscreen_clock_view_large); + + mClockViewController = + new AnimatableClockController( + mView.findViewById(R.id.animatable_clock_view), + mStatusBarStateController, + mBroadcastDispatcher, + mBatteryController); + mClockViewController.init(); + + mLargeClockViewController = + new AnimatableClockController( + mView.findViewById(R.id.animatable_clock_view_large), + mStatusBarStateController, + mBroadcastDispatcher, + mBatteryController); + mLargeClockViewController.init(); + + mStatusBarStateController.addCallback(mStatusBarStateListener); + mConfigurationController.addCallback(mConfigurationListener); + + BcSmartspaceDataPlugin smartspaceDataPlugin = mSystemUIFactory.getSmartspaceDataProvider(); + if (mFeatureFlags.isSmartspaceEnabled() && smartspaceDataPlugin != null) { + View ksa = mView.findViewById(R.id.keyguard_status_area); + int ksaIndex = mView.indexOfChild(ksa); + ksa.setVisibility(View.GONE); + + mSmartspaceView = smartspaceDataPlugin.getView(mView); + mSmartspaceView.registerDataProvider(smartspaceDataPlugin); + mSmartspaceView.setIntentStarter(new IntentStarter() { + public void startIntent(View v, Intent i) { + mActivityStarter.startActivity(i, true /* dismissShade */); + } - View nic = mView.findViewById( - com.android.systemui.R.id.left_aligned_notification_icon_container); - RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) - nic.getLayoutParams(); - lp.addRule(RelativeLayout.BELOW, R.id.keyguard_status_area); - nic.setLayoutParams(lp); + public void startPendingIntent(PendingIntent pi) { + mActivityStarter.startPendingIntentDismissingKeyguard(pi); + } + }); + mSmartspaceView.setFalsingManager(mFalsingManager); + updateWallpaperColor(); + View asView = (View) mSmartspaceView; + + // Place smartspace view below normal clock... + RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( + MATCH_PARENT, WRAP_CONTENT); + lp.addRule(RelativeLayout.BELOW, R.id.lockscreen_clock_view); + + mView.addView(asView, ksaIndex, lp); + int padding = getContext().getResources() + .getDimensionPixelSize(R.dimen.below_clock_padding_start); + asView.setPadding(padding, 0, padding, 0); + + // ... but above the large clock + lp = new RelativeLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT); + lp.addRule(RelativeLayout.BELOW, asView.getId()); + mLargeClockFrame.setLayoutParams(lp); + + View nic = mView.findViewById( + R.id.left_aligned_notification_icon_container); + lp = (RelativeLayout.LayoutParams) nic.getLayoutParams(); + lp.addRule(RelativeLayout.BELOW, asView.getId()); + nic.setLayoutParams(lp); + + mSmartspaceSession = getContext().getSystemService(SmartspaceManager.class) + .createSmartspaceSession( + new SmartspaceConfig.Builder(getContext(), "lockscreen").build()); + mSmartspaceCallback = targets -> smartspaceDataPlugin.onTargetsAvailable(targets); + mSmartspaceSession.addOnTargetsAvailableListener(mUiExecutor, mSmartspaceCallback); + mSmartspaceSession.requestSmartspaceUpdate(); + } - mSmartspaceView = null; - } + float dozeAmount = mStatusBarStateController.getDozeAmount(); + mStatusBarStateListener.onDozeAmountChanged(dozeAmount, dozeAmount); + } - private void createSmartspaceSession(BcSmartspaceDataPlugin plugin) { - mSmartspaceSession = getContext().getSystemService(SmartspaceManager.class) - .createSmartspaceSession( - new SmartspaceConfig.Builder(getContext(), "lockscreen").build()); - mSmartspaceCallback = targets -> plugin.onTargetsAvailable(targets); - mSmartspaceSession.registerSmartspaceUpdates(mUiExecutor, mSmartspaceCallback); - mSmartspaceSession.requestSmartspaceUpdate(); - } - }; - mPluginManager.addPluginListener(mPluginListener, BcSmartspaceDataPlugin.class, false); + private void updateWallpaperColor() { + if (mSmartspaceView != null) { + int color = Utils.getColorAttrDefaultColor(getContext(), R.attr.wallpaperTextColor); + mSmartspaceView.setPrimaryTextColor(color); + } } @Override @@ -230,16 +269,16 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS if (CUSTOM_CLOCKS_ENABLED) { mClockManager.removeOnClockChangedListener(mClockChangedListener); } - mStatusBarStateController.removeCallback(mStateListener); mColorExtractor.removeOnColorsChangedListener(mColorsListener); mView.setClockPlugin(null, mStatusBarStateController.getState()); if (mSmartspaceSession != null) { - mSmartspaceSession.unregisterSmartspaceUpdates(mSmartspaceCallback); - mSmartspaceSession.destroy(); + mSmartspaceSession.removeOnTargetsAvailableListener(mSmartspaceCallback); + mSmartspaceSession.close(); mSmartspaceSession = null; } - mPluginManager.removePluginListener(mPluginListener); + mStatusBarStateController.removeCallback(mStatusBarStateListener); + mConfigurationController.removeCallback(mConfigurationListener); } /** @@ -250,13 +289,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } /** - * Set container for big clock face appearing behind NSSL and KeyguardStatusView. - */ - public void setBigClockContainer(ViewGroup bigClockContainer) { - mView.setBigClockContainer(bigClockContainer, mStatusBarStateController.getState()); - } - - /** * Set whether or not the lock screen is showing notifications. */ public void setHasVisibleNotifications(boolean hasVisibleNotifications) { @@ -291,9 +323,9 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS * Refresh clock. Called in response to TIME_TICK broadcasts. */ void refresh() { - if (mNewLockScreenClockViewController != null) { - mNewLockScreenClockViewController.refreshTime(); - mNewLockScreenLargeClockViewController.refreshTime(); + if (mClockViewController != null) { + mClockViewController.refreshTime(); + mLargeClockViewController.refreshTime(); } mView.refresh(); @@ -307,86 +339,45 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS */ void updatePosition(int x, float scale, AnimationProperties props, boolean animate) { x = getCurrentLayoutDirection() == View.LAYOUT_DIRECTION_RTL ? -x : x; - if (mNewLockScreenClockFrame != null) { - PropertyAnimator.setProperty(mNewLockScreenClockFrame, AnimatableProperty.TRANSLATION_X, - x, props, animate); - PropertyAnimator.setProperty(mNewLockScreenLargeClockFrame, AnimatableProperty.SCALE_X, - scale, props, animate); - PropertyAnimator.setProperty(mNewLockScreenLargeClockFrame, AnimatableProperty.SCALE_Y, - scale, props, animate); - } + + PropertyAnimator.setProperty(mClockFrame, AnimatableProperty.TRANSLATION_X, + x, props, animate); + PropertyAnimator.setProperty(mLargeClockFrame, AnimatableProperty.SCALE_X, + scale, props, animate); + PropertyAnimator.setProperty(mLargeClockFrame, AnimatableProperty.SCALE_Y, + scale, props, animate); if (mSmartspaceView != null) { PropertyAnimator.setProperty((View) mSmartspaceView, AnimatableProperty.TRANSLATION_X, x, props, animate); } + mKeyguardSliceViewController.updatePosition(x, props, animate); mNotificationIconAreaController.updatePosition(x, props, animate); } - /** - * Update lockscreen mode that may change clock display. - */ - void updateLockScreenMode(int mode) { - mLockScreenMode = mode; - if (mode == KeyguardUpdateMonitor.LOCK_SCREEN_MODE_LAYOUT_1) { - if (mNewLockScreenClockViewController == null) { - mNewLockScreenClockViewController = - new AnimatableClockController( - mView.findViewById(R.id.animatable_clock_view), - mStatusBarStateController, - mBroadcastDispatcher); - mNewLockScreenClockViewController.init(); - mNewLockScreenLargeClockViewController = - new AnimatableClockController( - mView.findViewById(R.id.animatable_clock_view_large), - mStatusBarStateController, - mBroadcastDispatcher); - mNewLockScreenLargeClockViewController.init(); - } - } else { - mNewLockScreenClockViewController = null; - mNewLockScreenLargeClockViewController = null; - } - mView.updateLockScreenMode(mLockScreenMode); - updateAodIcons(); - } - void updateTimeZone(TimeZone timeZone) { mView.onTimeZoneChanged(timeZone); - if (mNewLockScreenClockViewController != null) { - mNewLockScreenClockViewController.onTimeZoneChanged(timeZone); - mNewLockScreenLargeClockViewController.onTimeZoneChanged(timeZone); + if (mClockViewController != null) { + mClockViewController.onTimeZoneChanged(timeZone); + mLargeClockViewController.onTimeZoneChanged(timeZone); } } void refreshFormat(String timeFormat) { - mTimeFormat = timeFormat; - Patterns.update(mResources); - mView.setFormat12Hour(Patterns.sClockView12); - mView.setFormat24Hour(Patterns.sClockView24); - mView.onTimeFormatChanged(mTimeFormat); - if (mNewLockScreenClockViewController != null) { - mNewLockScreenClockViewController.refreshFormat(); - mNewLockScreenLargeClockViewController.refreshFormat(); + if (mClockViewController != null) { + mClockViewController.refreshFormat(); + mLargeClockViewController.refreshFormat(); } } - void refreshFormat() { - refreshFormat(mTimeFormat); - } - private void updateAodIcons() { NotificationIconContainer nic = (NotificationIconContainer) mView.findViewById( com.android.systemui.R.id.left_aligned_notification_icon_container); - if (mLockScreenMode == KeyguardUpdateMonitor.LOCK_SCREEN_MODE_LAYOUT_1) { - // alt icon area is set in KeyguardClockSwitchController - mNotificationIconAreaController.setupAodIcons(nic, mLockScreenMode); - } else { - nic.setVisibility(View.GONE); - } + // alt icon area is set in KeyguardClockSwitchController + mNotificationIconAreaController.setupAodIcons(nic); } private void setClockPlugin(ClockPlugin plugin) { @@ -431,4 +422,9 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private int getCurrentLayoutDirection() { return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()); } + + @VisibleForTesting + ConfigurationController.ConfigurationListener getConfigurationListener() { + return mConfigurationListener; + } } |