Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98312398 authored by Robert Snoeberger's avatar Robert Snoeberger
Browse files

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

Bug: 124133570
Test: manual testing, and created b/128691778 to add regression tests.
Change-Id: I00dcb8b2a8acf6adfbcc77a1e6987824027d300c
parent 289cd11c
Loading
Loading
Loading
Loading
+39 −27
Original line number Diff line number Diff line
@@ -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,22 +75,17 @@ 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();
                }
            };

@@ -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);
@@ -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()) {
@@ -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 {

+17 −19
Original line number Diff line number Diff line
@@ -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.