Merge "Prevent, again, custom clock view from being visible on Home screen."

This commit is contained in:
TreeHugger Robot
2019-03-18 23:26:13 +00:00
committed by Android (Google) Code Review
2 changed files with 56 additions and 46 deletions

View File

@@ -60,8 +60,8 @@ public class KeyguardClockSwitch extends RelativeLayout {
*/
private ViewGroup mBigClockContainer;
/**
* Status area (date and other stuff) shown below the clock. Plugin can decide whether
* or not to show it below the alternate clock.
* Status area (date and other stuff) shown below the clock. Plugin can decide whether or not to
* show it below the alternate clock.
*/
private View mKeyguardStatusArea;
/**
@@ -75,24 +75,19 @@ public class KeyguardClockSwitch extends RelativeLayout {
private boolean mSupportsDarkText;
private int[] mColorPalette;
/**
* Track the state of the status bar to know when to hide the big_clock_container.
*/
private int mStatusBarState;
private final StatusBarStateController.StateListener mStateListener =
new StatusBarStateController.StateListener() {
@Override
public void onStateChanged(int newState) {
if (mBigClockContainer == null) {
return;
}
if (newState == StatusBarState.SHADE) {
if (mBigClockContainer.getVisibility() == View.VISIBLE) {
mBigClockContainer.setVisibility(View.INVISIBLE);
}
} else {
if (mBigClockContainer.getVisibility() == View.INVISIBLE) {
mBigClockContainer.setVisibility(View.VISIBLE);
}
}
mStatusBarState = newState;
updateBigClockVisibility();
}
};
};
private ClockManager.ClockChangedListener mClockChangedListener = this::setClockPlugin;
@@ -139,7 +134,9 @@ public class KeyguardClockSwitch extends RelativeLayout {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Dependency.get(ClockManager.class).addOnClockChangedListener(mClockChangedListener);
Dependency.get(StatusBarStateController.class).addCallback(mStateListener);
StatusBarStateController stateController = Dependency.get(StatusBarStateController.class);
stateController.addCallback(mStateListener);
mStateListener.onStateChanged(stateController.getState());
SysuiColorExtractor colorExtractor = Dependency.get(SysuiColorExtractor.class);
colorExtractor.addOnColorsChangedListener(mColorsListener);
updateColors(colorExtractor);
@@ -151,7 +148,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
Dependency.get(ClockManager.class).removeOnClockChangedListener(mClockChangedListener);
Dependency.get(StatusBarStateController.class).removeCallback(mStateListener);
Dependency.get(SysuiColorExtractor.class)
.removeOnColorsChangedListener(mColorsListener);
.removeOnColorsChangedListener(mColorsListener);
setClockPlugin(null);
}
@@ -164,7 +161,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
}
if (mBigClockContainer != null) {
mBigClockContainer.removeAllViews();
mBigClockContainer.setVisibility(View.GONE);
updateBigClockVisibility();
}
mClockPlugin = null;
}
@@ -184,7 +181,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
View bigClockView = plugin.getBigClockView();
if (bigClockView != null && mBigClockContainer != null) {
mBigClockContainer.addView(bigClockView);
mBigClockContainer.setVisibility(View.VISIBLE);
updateBigClockVisibility();
}
// Hide default clock.
if (!plugin.shouldShowStatusArea()) {
@@ -208,12 +205,10 @@ public class KeyguardClockSwitch extends RelativeLayout {
View bigClockView = mClockPlugin.getBigClockView();
if (bigClockView != null) {
container.addView(bigClockView);
if (container.getVisibility() == View.GONE) {
container.setVisibility(View.VISIBLE);
}
}
}
mBigClockContainer = container;
updateBigClockVisibility();
}
/**
@@ -254,6 +249,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
/**
* Set the amount (ratio) that the device has transitioned to doze.
*
* @param darkAmount Amount of transition to doze: 1f for doze and 0f for awake.
*/
public void setDarkAmount(float darkAmount) {
@@ -307,9 +303,24 @@ public class KeyguardClockSwitch extends RelativeLayout {
}
}
private void updateBigClockVisibility() {
if (mBigClockContainer == null) {
return;
}
final boolean inDisplayState = mStatusBarState == StatusBarState.KEYGUARD
|| mStatusBarState == StatusBarState.SHADE_LOCKED;
final int visibility =
inDisplayState && mBigClockContainer.getChildCount() != 0 ? View.VISIBLE
: View.GONE;
if (mBigClockContainer.getVisibility() != visibility) {
mBigClockContainer.setVisibility(visibility);
}
}
/**
* Sets if the keyguard slice is showing a center-aligned header. We need a smaller clock
* in these cases.
* Sets if the keyguard slice is showing a center-aligned header. We need a smaller clock in
* these
* cases.
*/
public void setKeyguardShowingHeader(boolean hasHeader) {
if (mShowingHeader == hasHeader || hasCustomClock()) {
@@ -327,12 +338,12 @@ public class KeyguardClockSwitch extends RelativeLayout {
mClockView.getPaddingRight(), paddingBottom);
}
@VisibleForTesting (otherwise = VisibleForTesting.NONE)
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
ClockManager.ClockChangedListener getClockChangedListener() {
return mClockChangedListener;
}
@VisibleForTesting (otherwise = VisibleForTesting.NONE)
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
StatusBarStateController.StateListener getStateListener() {
return mStateListener;
}
@@ -352,7 +363,8 @@ public class KeyguardClockSwitch extends RelativeLayout {
/**
* Special layout transition that scales the clock view as its bounds change, to make it look
* like the text is shrinking.
* like
* the text is shrinking.
*/
private class ClockBoundsTransition extends ChangeBounds {

View File

@@ -101,6 +101,8 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
// AND the plugin returns a view for the big clock
ClockPlugin plugin = mock(ClockPlugin.class);
when(plugin.getBigClockView()).thenReturn(mBigClock);
// AND in the keyguard state
mStateListener.onStateChanged(StatusBarState.KEYGUARD);
// WHEN the plugin is connected
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
// THEN the big clock container is visible and it is the parent of the
@@ -166,6 +168,8 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
ClockPlugin plugin = mock(ClockPlugin.class);
TextClock pluginView = new TextClock(getContext());
when(plugin.getBigClockView()).thenReturn(pluginView);
// AND in the keyguard state
mStateListener.onStateChanged(StatusBarState.KEYGUARD);
// WHEN the plugin is connected and then disconnected
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(null);
@@ -245,21 +249,25 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
}
@Test
public void onStateChanged_InvisibleInShade() {
public void onStateChanged_GoneInShade() {
// GIVEN that the big clock container is visible
mBigClockContainer.setVisibility(View.VISIBLE);
mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// WHEN transitioned to SHADE state
mStateListener.onStateChanged(StatusBarState.SHADE);
// THEN the container is invisible.
assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.INVISIBLE);
// THEN the container is gone.
assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void onStateChanged_VisibleInKeyguard() {
// GIVEN that the big clock container is invisible
mBigClockContainer.setVisibility(View.INVISIBLE);
// GIVEN that the big clock container is gone
mBigClockContainer.setVisibility(View.GONE);
mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// AND GIVEN that a plugin is active.
ClockPlugin plugin = mock(ClockPlugin.class);
when(plugin.getBigClockView()).thenReturn(mBigClock);
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
// WHEN transitioned to KEYGUARD state
mStateListener.onStateChanged(StatusBarState.KEYGUARD);
// THEN the container is visible.
@@ -274,26 +282,14 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
ClockPlugin plugin = mock(ClockPlugin.class);
when(plugin.getBigClockView()).thenReturn(mBigClock);
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
// AND in the keyguard state
mStateListener.onStateChanged(StatusBarState.KEYGUARD);
// WHEN the container is associated with the clock switch
mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// THEN the container remains visible.
assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE);
}
@Test
public void setBigClockContainer_invisible() {
// GIVEN that the big clock container is invisible
mBigClockContainer.setVisibility(View.INVISIBLE);
// AND GIVEN that a plugin is active.
ClockPlugin plugin = mock(ClockPlugin.class);
when(plugin.getBigClockView()).thenReturn(mBigClock);
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
// WHEN the container is associated with the clock switch
mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// THEN the container remains invisible.
assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.INVISIBLE);
}
@Test
public void setBigClockContainer_gone() {
// GIVEN that the big clock container is gone
@@ -302,6 +298,8 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
ClockPlugin plugin = mock(ClockPlugin.class);
when(plugin.getBigClockView()).thenReturn(mBigClock);
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
// AND in the keyguard state
mStateListener.onStateChanged(StatusBarState.KEYGUARD);
// WHEN the container is associated with the clock switch
mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// THEN the container is made visible.