summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-02-11 23:18:18 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-02-11 23:18:18 +0000
commitd06756ceae61cc060ddf4142ef9836780ef04c9c (patch)
tree6b26e1eafd3d825f0d5837fbf58b67923cb229a7
parent3ac202db6f4156916f0ac7a4b54345fa29fea8f0 (diff)
parenta1df7fb8f34b32e9ee0db96baabb4b681cd6ee40 (diff)
Merge "Prevent, again, custom clock view from being visible on Home screen."
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java73
2 files changed, 60 insertions, 17 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
index fc1843ba982a..822920e63460 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
@@ -187,7 +187,9 @@ public class KeyguardClockSwitch extends RelativeLayout {
View bigClockView = mClockPlugin.getBigClockView();
if (bigClockView != null) {
container.addView(bigClockView);
- container.setVisibility(View.VISIBLE);
+ if (container.getVisibility() == View.GONE) {
+ container.setVisibility(View.VISIBLE);
+ }
}
}
mBigClockContainer = container;
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
index 5d03f19f4655..b0d1106ecb24 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
@@ -35,7 +35,6 @@ 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;
@@ -60,6 +59,8 @@ import org.mockito.MockitoAnnotations;
@RunWithLooper(setAsMainLooper = true)
public class KeyguardClockSwitchTest extends SysuiTestCase {
private FrameLayout mClockContainer;
+ private FrameLayout mBigClockContainer;
+ private TextClock mBigClock;
private StatusBarStateController.StateListener mStateListener;
@Mock
@@ -73,6 +74,8 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
mKeyguardClockSwitch =
(KeyguardClockSwitch) layoutInflater.inflate(R.layout.keyguard_clock_switch, null);
mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view);
+ mBigClockContainer = new FrameLayout(getContext());
+ mBigClock = new TextClock(getContext());
MockitoAnnotations.initMocks(this);
when(mClockView.getPaint()).thenReturn(mock(TextPaint.class));
mStateListener = mKeyguardClockSwitch.getStateListener();
@@ -93,19 +96,17 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
@Test
public void onPluginConnected_showPluginBigClock() {
// GIVEN that the container for the big clock has visibility GONE
- FrameLayout bigClockContainer = new FrameLayout(getContext());
- bigClockContainer.setVisibility(GONE);
- mKeyguardClockSwitch.setBigClockContainer(bigClockContainer);
+ mBigClockContainer.setVisibility(GONE);
+ mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// AND the plugin returns a view for the big clock
ClockPlugin plugin = mock(ClockPlugin.class);
- TextClock pluginView = new TextClock(getContext());
- when(plugin.getBigClockView()).thenReturn(pluginView);
+ when(plugin.getBigClockView()).thenReturn(mBigClock);
// WHEN the plugin is connected
mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
// THEN the big clock container is visible and it is the parent of the
// big clock view.
- assertThat(bigClockContainer.getVisibility()).isEqualTo(VISIBLE);
- assertThat(pluginView.getParent()).isEqualTo(bigClockContainer);
+ assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBigClock.getParent()).isEqualTo(mBigClockContainer);
}
@Test
@@ -246,24 +247,64 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
@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);
+ mBigClockContainer.setVisibility(View.VISIBLE);
+ mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// WHEN transitioned to SHADE state
mStateListener.onStateChanged(StatusBarState.SHADE);
// THEN the container is invisible.
- verify(container).setVisibility(View.INVISIBLE);
+ assertThat(mBigClockContainer.getVisibility()).isEqualTo(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);
+ mBigClockContainer.setVisibility(View.INVISIBLE);
+ mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
// WHEN transitioned to KEYGUARD state
mStateListener.onStateChanged(StatusBarState.KEYGUARD);
// THEN the container is visible.
- verify(container).setVisibility(View.VISIBLE);
+ assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE);
+ }
+
+ @Test
+ public void setBigClockContainer_visible() {
+ // GIVEN that the big clock container is visible
+ mBigClockContainer.setVisibility(View.VISIBLE);
+ // 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 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
+ mBigClockContainer.setVisibility(View.GONE);
+ // 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 is made visible.
+ assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.VISIBLE);
}
}