diff options
author | 2019-01-07 20:29:18 +0000 | |
---|---|---|
committer | 2019-01-07 20:29:18 +0000 | |
commit | 8b9351ba04eef507d4ff97a84d0c13df60507daf (patch) | |
tree | 63b46158a30b87c0e281a5971d4e59347df43ab8 | |
parent | 30e984ca784e5d3edfe48b827ab0a0ce825adc84 (diff) | |
parent | 60854080d31e10c06785bfaf5879bdf81a471e3b (diff) |
Merge "Fix custom clock face showing up outside of lock screen."
-rw-r--r-- | packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java | 27 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java | 30 |
2 files changed, 57 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java index 570d351a8b71..27d624ab0b58 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java @@ -16,6 +16,8 @@ import com.android.systemui.Dependency; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.plugins.PluginManager; +import com.android.systemui.statusbar.StatusBarState; +import com.android.systemui.statusbar.StatusBarStateController; import java.util.Objects; import java.util.TimeZone; @@ -82,6 +84,24 @@ public class KeyguardClockSwitch extends RelativeLayout { } } }; + 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); + } + } + } + }; public KeyguardClockSwitch(Context context) { this(context, null); @@ -104,12 +124,14 @@ public class KeyguardClockSwitch extends RelativeLayout { super.onAttachedToWindow(); Dependency.get(PluginManager.class).addPluginListener(mClockPluginListener, ClockPlugin.class); + Dependency.get(StatusBarStateController.class).addCallback(mStateListener); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); Dependency.get(PluginManager.class).removePluginListener(mClockPluginListener); + Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); } /** @@ -238,4 +260,9 @@ public class KeyguardClockSwitch extends RelativeLayout { PluginListener getClockPluginListener() { return mClockPluginListener; } + + @VisibleForTesting (otherwise = VisibleForTesting.NONE) + StatusBarStateController.StateListener getStateListener() { + return mStateListener; + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java index 415060244243..1844df5c070a 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java @@ -35,6 +35,8 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; import android.text.TextPaint; import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.TextClock; @@ -42,6 +44,8 @@ import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.plugins.PluginManager; +import com.android.systemui.statusbar.StatusBarState; +import com.android.systemui.statusbar.StatusBarStateController; import org.junit.Before; import org.junit.Test; @@ -60,6 +64,7 @@ import org.mockito.MockitoAnnotations; public class KeyguardClockSwitchTest extends SysuiTestCase { private PluginManager mPluginManager; private FrameLayout mClockContainer; + private StatusBarStateController.StateListener mStateListener; @Mock TextClock mClockView; @@ -75,6 +80,7 @@ public class KeyguardClockSwitchTest extends SysuiTestCase { mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view); MockitoAnnotations.initMocks(this); when(mClockView.getPaint()).thenReturn(mock(TextPaint.class)); + mStateListener = mKeyguardClockSwitch.getStateListener(); } @Test @@ -272,4 +278,28 @@ public class KeyguardClockSwitchTest extends SysuiTestCase { verify(plugin).setStyle(style); } + + @Test + public void onStateChanged_InvisibleInShade() { + // GIVEN that the big clock container is visible + ViewGroup container = mock(ViewGroup.class); + when(container.getVisibility()).thenReturn(View.VISIBLE); + mKeyguardClockSwitch.setBigClockContainer(container); + // WHEN transitioned to SHADE state + mStateListener.onStateChanged(StatusBarState.SHADE); + // THEN the container is invisible. + verify(container).setVisibility(View.INVISIBLE); + } + + @Test + public void onStateChanged_VisibleInKeyguard() { + // GIVEN that the big clock container is invisible + ViewGroup container = mock(ViewGroup.class); + when(container.getVisibility()).thenReturn(View.INVISIBLE); + mKeyguardClockSwitch.setBigClockContainer(container); + // WHEN transitioned to KEYGUARD state + mStateListener.onStateChanged(StatusBarState.KEYGUARD); + // THEN the container is visible. + verify(container).setVisibility(View.VISIBLE); + } } |