Add KeyguardStatusViewController
Refactor KeyguardStatusView so that it has a controller that NotificationPanelViewController can use to manipulate the view. This CL untangles some of the logic in KeyguardStatusView that should be in KeyguardClockSwitchController. No functionality changes. Test: atest KeyguardClockSwitchControllerTest Test: atest NotificationPanelViewTest Test: atest KeyguardStatusViewControllerTest Test: atest SystemUITests Change-Id: I52d0d887cb4ce734ec265b6357644ba1d1368460 Bug: 170228350
This commit is contained in:
@@ -17,24 +17,32 @@
|
||||
package com.android.keyguard;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.view.View;
|
||||
import android.content.res.Resources;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.colorextraction.ColorExtractor;
|
||||
import com.android.keyguard.clock.ClockManager;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.colorextraction.SysuiColorExtractor;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.plugins.ClockPlugin;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.util.ViewController;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Injectable controller for {@link KeyguardClockSwitch}.
|
||||
*/
|
||||
public class KeyguardClockSwitchController {
|
||||
public class KeyguardClockSwitchController extends ViewController<KeyguardClockSwitch> {
|
||||
private static final boolean CUSTOM_CLOCKS_ENABLED = true;
|
||||
|
||||
private final KeyguardClockSwitch mView;
|
||||
private final Resources mResources;
|
||||
private final StatusBarStateController mStatusBarStateController;
|
||||
private final SysuiColorExtractor mColorExtractor;
|
||||
private final ClockManager mClockManager;
|
||||
@@ -65,35 +73,15 @@ public class KeyguardClockSwitchController {
|
||||
|
||||
private ClockManager.ClockChangedListener mClockChangedListener = this::setClockPlugin;
|
||||
|
||||
private final View.OnAttachStateChangeListener mOnAttachStateChangeListener =
|
||||
new View.OnAttachStateChangeListener() {
|
||||
@Override
|
||||
public void onViewAttachedToWindow(View v) {
|
||||
if (CUSTOM_CLOCKS_ENABLED) {
|
||||
mClockManager.addOnClockChangedListener(mClockChangedListener);
|
||||
}
|
||||
mStatusBarStateController.addCallback(mStateListener);
|
||||
mColorExtractor.addOnColorsChangedListener(mColorsListener);
|
||||
mView.updateColors(getGradientColors());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewDetachedFromWindow(View v) {
|
||||
if (CUSTOM_CLOCKS_ENABLED) {
|
||||
mClockManager.removeOnClockChangedListener(mClockChangedListener);
|
||||
}
|
||||
mStatusBarStateController.removeCallback(mStateListener);
|
||||
mColorExtractor.removeOnColorsChangedListener(mColorsListener);
|
||||
mView.setClockPlugin(null, mStatusBarStateController.getState());
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public KeyguardClockSwitchController(KeyguardClockSwitch keyguardClockSwitch,
|
||||
public KeyguardClockSwitchController(
|
||||
KeyguardClockSwitch keyguardClockSwitch,
|
||||
@Main Resources resources,
|
||||
StatusBarStateController statusBarStateController,
|
||||
SysuiColorExtractor colorExtractor, ClockManager clockManager,
|
||||
KeyguardSliceViewController keyguardSliceViewController) {
|
||||
mView = keyguardClockSwitch;
|
||||
super(keyguardClockSwitch);
|
||||
mResources = resources;
|
||||
mStatusBarStateController = statusBarStateController;
|
||||
mColorExtractor = colorExtractor;
|
||||
mClockManager = clockManager;
|
||||
@@ -103,15 +91,41 @@ public class KeyguardClockSwitchController {
|
||||
/**
|
||||
* Attach the controller to the view it relates to.
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
if (mView.isAttachedToWindow()) {
|
||||
mOnAttachStateChangeListener.onViewAttachedToWindow(mView);
|
||||
}
|
||||
mView.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
|
||||
|
||||
super.init();
|
||||
mKeyguardSliceViewController.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onViewAttached() {
|
||||
if (CUSTOM_CLOCKS_ENABLED) {
|
||||
mClockManager.addOnClockChangedListener(mClockChangedListener);
|
||||
}
|
||||
refreshFormat();
|
||||
mStatusBarStateController.addCallback(mStateListener);
|
||||
mColorExtractor.addOnColorsChangedListener(mColorsListener);
|
||||
mView.updateColors(getGradientColors());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onViewDetached() {
|
||||
if (CUSTOM_CLOCKS_ENABLED) {
|
||||
mClockManager.removeOnClockChangedListener(mClockChangedListener);
|
||||
}
|
||||
mStatusBarStateController.removeCallback(mStateListener);
|
||||
mColorExtractor.removeOnColorsChangedListener(mColorsListener);
|
||||
mView.setClockPlugin(null, mStatusBarStateController.getState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates clock's text
|
||||
*/
|
||||
public void onDensityOrFontScaleChanged() {
|
||||
mView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
|
||||
mResources.getDimensionPixelSize(R.dimen.widget_big_font_size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set container for big clock face appearing behind NSSL and KeyguardStatusView.
|
||||
*/
|
||||
@@ -119,6 +133,61 @@ public class KeyguardClockSwitchController {
|
||||
mView.setBigClockContainer(bigClockContainer, mStatusBarStateController.getState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the lock screen is showing notifications.
|
||||
*/
|
||||
public void setHasVisibleNotifications(boolean hasVisibleNotifications) {
|
||||
mView.setHasVisibleNotifications(hasVisibleNotifications);
|
||||
}
|
||||
|
||||
/**
|
||||
* If we're presenting a custom clock of just the default one.
|
||||
*/
|
||||
public boolean hasCustomClock() {
|
||||
return mView.hasCustomClock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the clock text size.
|
||||
*/
|
||||
public float getClockTextSize() {
|
||||
return mView.getTextSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preferred Y position of the clock.
|
||||
*
|
||||
* @param totalHeight The height available to position the clock.
|
||||
* @return Y position of clock.
|
||||
*/
|
||||
public int getClockPreferredY(int totalHeight) {
|
||||
return mView.getPreferredY(totalHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh clock. Called in response to TIME_TICK broadcasts.
|
||||
*/
|
||||
void refresh() {
|
||||
mView.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update lockscreen mode that may change clock display.
|
||||
*/
|
||||
void updateLockScreenMode(int mode) {
|
||||
mView.updateLockScreenMode(mode);
|
||||
}
|
||||
|
||||
void updateTimeZone(TimeZone timeZone) {
|
||||
mView.onTimeZoneChanged(timeZone);
|
||||
}
|
||||
|
||||
void refreshFormat() {
|
||||
Patterns.update(mResources);
|
||||
mView.setFormat12Hour(Patterns.sClockView12);
|
||||
mView.setFormat24Hour(Patterns.sClockView24);
|
||||
}
|
||||
|
||||
private void setClockPlugin(ClockPlugin plugin) {
|
||||
mView.setClockPlugin(plugin, mStatusBarStateController.getState());
|
||||
}
|
||||
@@ -126,4 +195,35 @@ public class KeyguardClockSwitchController {
|
||||
private ColorExtractor.GradientColors getGradientColors() {
|
||||
return mColorExtractor.getColors(WallpaperManager.FLAG_LOCK);
|
||||
}
|
||||
|
||||
// DateFormat.getBestDateTimePattern is extremely expensive, and refresh is called often.
|
||||
// This is an optimization to ensure we only recompute the patterns when the inputs change.
|
||||
private static final class Patterns {
|
||||
static String sClockView12;
|
||||
static String sClockView24;
|
||||
static String sCacheKey;
|
||||
|
||||
static void update(Resources res) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
final String clockView12Skel = res.getString(R.string.clock_12hr_format);
|
||||
final String clockView24Skel = res.getString(R.string.clock_24hr_format);
|
||||
final String key = locale.toString() + clockView12Skel + clockView24Skel;
|
||||
if (key.equals(sCacheKey)) return;
|
||||
|
||||
sClockView12 = DateFormat.getBestDateTimePattern(locale, clockView12Skel);
|
||||
// CLDR insists on adding an AM/PM indicator even though it wasn't in the skeleton
|
||||
// format. The following code removes the AM/PM indicator if we didn't want it.
|
||||
if (!clockView12Skel.contains("a")) {
|
||||
sClockView12 = sClockView12.replaceAll("a", "").trim();
|
||||
}
|
||||
|
||||
sClockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel);
|
||||
|
||||
// Use fancy colon.
|
||||
sClockView24 = sClockView24.replace(':', '\uee01');
|
||||
sClockView12 = sClockView12.replace(':', '\uee01');
|
||||
|
||||
sCacheKey = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user