Loading packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +27 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ import com.android.systemui.Dependency; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.plugins.PluginManager; 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.Objects; import java.util.TimeZone; import java.util.TimeZone; Loading Loading @@ -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) { public KeyguardClockSwitch(Context context) { this(context, null); this(context, null); Loading @@ -104,12 +124,14 @@ public class KeyguardClockSwitch extends RelativeLayout { super.onAttachedToWindow(); super.onAttachedToWindow(); Dependency.get(PluginManager.class).addPluginListener(mClockPluginListener, Dependency.get(PluginManager.class).addPluginListener(mClockPluginListener, ClockPlugin.class); ClockPlugin.class); Dependency.get(StatusBarStateController.class).addCallback(mStateListener); } } @Override @Override protected void onDetachedFromWindow() { protected void onDetachedFromWindow() { super.onDetachedFromWindow(); super.onDetachedFromWindow(); Dependency.get(PluginManager.class).removePluginListener(mClockPluginListener); Dependency.get(PluginManager.class).removePluginListener(mClockPluginListener); Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); } } /** /** Loading Loading @@ -238,4 +260,9 @@ public class KeyguardClockSwitch extends RelativeLayout { PluginListener getClockPluginListener() { PluginListener getClockPluginListener() { return mClockPluginListener; return mClockPluginListener; } } @VisibleForTesting (otherwise = VisibleForTesting.NONE) StatusBarStateController.StateListener getStateListener() { return mStateListener; } } } packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java +30 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,8 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; import android.testing.TestableLooper.RunWithLooper; import android.text.TextPaint; import android.text.TextPaint; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.FrameLayout; import android.widget.TextClock; import android.widget.TextClock; Loading @@ -42,6 +44,8 @@ import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.plugins.PluginManager; 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.Before; import org.junit.Test; import org.junit.Test; Loading @@ -60,6 +64,7 @@ import org.mockito.MockitoAnnotations; public class KeyguardClockSwitchTest extends SysuiTestCase { public class KeyguardClockSwitchTest extends SysuiTestCase { private PluginManager mPluginManager; private PluginManager mPluginManager; private FrameLayout mClockContainer; private FrameLayout mClockContainer; private StatusBarStateController.StateListener mStateListener; @Mock @Mock TextClock mClockView; TextClock mClockView; Loading @@ -75,6 +80,7 @@ public class KeyguardClockSwitchTest extends SysuiTestCase { mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view); mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view); MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); when(mClockView.getPaint()).thenReturn(mock(TextPaint.class)); when(mClockView.getPaint()).thenReturn(mock(TextPaint.class)); mStateListener = mKeyguardClockSwitch.getStateListener(); } } @Test @Test Loading Loading @@ -272,4 +278,28 @@ public class KeyguardClockSwitchTest extends SysuiTestCase { verify(plugin).setStyle(style); 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); } } } Loading
packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +27 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ import com.android.systemui.Dependency; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.plugins.PluginManager; 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.Objects; import java.util.TimeZone; import java.util.TimeZone; Loading Loading @@ -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) { public KeyguardClockSwitch(Context context) { this(context, null); this(context, null); Loading @@ -104,12 +124,14 @@ public class KeyguardClockSwitch extends RelativeLayout { super.onAttachedToWindow(); super.onAttachedToWindow(); Dependency.get(PluginManager.class).addPluginListener(mClockPluginListener, Dependency.get(PluginManager.class).addPluginListener(mClockPluginListener, ClockPlugin.class); ClockPlugin.class); Dependency.get(StatusBarStateController.class).addCallback(mStateListener); } } @Override @Override protected void onDetachedFromWindow() { protected void onDetachedFromWindow() { super.onDetachedFromWindow(); super.onDetachedFromWindow(); Dependency.get(PluginManager.class).removePluginListener(mClockPluginListener); Dependency.get(PluginManager.class).removePluginListener(mClockPluginListener); Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); } } /** /** Loading Loading @@ -238,4 +260,9 @@ public class KeyguardClockSwitch extends RelativeLayout { PluginListener getClockPluginListener() { PluginListener getClockPluginListener() { return mClockPluginListener; return mClockPluginListener; } } @VisibleForTesting (otherwise = VisibleForTesting.NONE) StatusBarStateController.StateListener getStateListener() { return mStateListener; } } }
packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java +30 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,8 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; import android.testing.TestableLooper.RunWithLooper; import android.text.TextPaint; import android.text.TextPaint; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.FrameLayout; import android.widget.TextClock; import android.widget.TextClock; Loading @@ -42,6 +44,8 @@ import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.plugins.PluginManager; 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.Before; import org.junit.Test; import org.junit.Test; Loading @@ -60,6 +64,7 @@ import org.mockito.MockitoAnnotations; public class KeyguardClockSwitchTest extends SysuiTestCase { public class KeyguardClockSwitchTest extends SysuiTestCase { private PluginManager mPluginManager; private PluginManager mPluginManager; private FrameLayout mClockContainer; private FrameLayout mClockContainer; private StatusBarStateController.StateListener mStateListener; @Mock @Mock TextClock mClockView; TextClock mClockView; Loading @@ -75,6 +80,7 @@ public class KeyguardClockSwitchTest extends SysuiTestCase { mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view); mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view); MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); when(mClockView.getPaint()).thenReturn(mock(TextPaint.class)); when(mClockView.getPaint()).thenReturn(mock(TextPaint.class)); mStateListener = mKeyguardClockSwitch.getStateListener(); } } @Test @Test Loading Loading @@ -272,4 +278,28 @@ public class KeyguardClockSwitchTest extends SysuiTestCase { verify(plugin).setStyle(style); 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); } } }