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

Commit 39609b56 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 35fd7c90 98312398
Loading
Loading
Loading
Loading
+39 −27
Original line number Original line Diff line number Diff line
@@ -60,8 +60,8 @@ public class KeyguardClockSwitch extends RelativeLayout {
     */
     */
    private ViewGroup mBigClockContainer;
    private ViewGroup mBigClockContainer;
    /**
    /**
     * Status area (date and other stuff) shown below the clock. Plugin can decide whether
     * Status area (date and other stuff) shown below the clock. Plugin can decide whether or not to
     * or not to show it below the alternate clock.
     * show it below the alternate clock.
     */
     */
    private View mKeyguardStatusArea;
    private View mKeyguardStatusArea;
    /**
    /**
@@ -75,22 +75,17 @@ public class KeyguardClockSwitch extends RelativeLayout {
    private boolean mSupportsDarkText;
    private boolean mSupportsDarkText;
    private int[] mColorPalette;
    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 =
    private final StatusBarStateController.StateListener mStateListener =
            new StatusBarStateController.StateListener() {
            new StatusBarStateController.StateListener() {
                @Override
                @Override
                public void onStateChanged(int newState) {
                public void onStateChanged(int newState) {
                    if (mBigClockContainer == null) {
                    mStatusBarState = newState;
                        return;
                    updateBigClockVisibility();
                    }
                    if (newState == StatusBarState.SHADE) {
                        if (mBigClockContainer.getVisibility() == View.VISIBLE) {
                            mBigClockContainer.setVisibility(View.INVISIBLE);
                        }
                    } else {
                        if (mBigClockContainer.getVisibility() == View.INVISIBLE) {
                            mBigClockContainer.setVisibility(View.VISIBLE);
                        }
                    }
                }
                }
            };
            };


@@ -139,7 +134,9 @@ public class KeyguardClockSwitch extends RelativeLayout {
    protected void onAttachedToWindow() {
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        super.onAttachedToWindow();
        Dependency.get(ClockManager.class).addOnClockChangedListener(mClockChangedListener);
        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);
        SysuiColorExtractor colorExtractor = Dependency.get(SysuiColorExtractor.class);
        colorExtractor.addOnColorsChangedListener(mColorsListener);
        colorExtractor.addOnColorsChangedListener(mColorsListener);
        updateColors(colorExtractor);
        updateColors(colorExtractor);
@@ -164,7 +161,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
            }
            }
            if (mBigClockContainer != null) {
            if (mBigClockContainer != null) {
                mBigClockContainer.removeAllViews();
                mBigClockContainer.removeAllViews();
                mBigClockContainer.setVisibility(View.GONE);
                updateBigClockVisibility();
            }
            }
            mClockPlugin = null;
            mClockPlugin = null;
        }
        }
@@ -184,7 +181,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
        View bigClockView = plugin.getBigClockView();
        View bigClockView = plugin.getBigClockView();
        if (bigClockView != null && mBigClockContainer != null) {
        if (bigClockView != null && mBigClockContainer != null) {
            mBigClockContainer.addView(bigClockView);
            mBigClockContainer.addView(bigClockView);
            mBigClockContainer.setVisibility(View.VISIBLE);
            updateBigClockVisibility();
        }
        }
        // Hide default clock.
        // Hide default clock.
        if (!plugin.shouldShowStatusArea()) {
        if (!plugin.shouldShowStatusArea()) {
@@ -208,12 +205,10 @@ public class KeyguardClockSwitch extends RelativeLayout {
            View bigClockView = mClockPlugin.getBigClockView();
            View bigClockView = mClockPlugin.getBigClockView();
            if (bigClockView != null) {
            if (bigClockView != null) {
                container.addView(bigClockView);
                container.addView(bigClockView);
                if (container.getVisibility() == View.GONE) {
                    container.setVisibility(View.VISIBLE);
                }
            }
            }
        }
        }
        mBigClockContainer = container;
        mBigClockContainer = container;
        updateBigClockVisibility();
    }
    }


    /**
    /**
@@ -254,6 +249,7 @@ public class KeyguardClockSwitch extends RelativeLayout {


    /**
    /**
     * Set the amount (ratio) that the device has transitioned to doze.
     * 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.
     * @param darkAmount Amount of transition to doze: 1f for doze and 0f for awake.
     */
     */
    public void setDarkAmount(float darkAmount) {
    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
     * Sets if the keyguard slice is showing a center-aligned header. We need a smaller clock in
     * in these cases.
     * these
     * cases.
     */
     */
    public void setKeyguardShowingHeader(boolean hasHeader) {
    public void setKeyguardShowingHeader(boolean hasHeader) {
        if (mShowingHeader == hasHeader || hasCustomClock()) {
        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
     * 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 {
    private class ClockBoundsTransition extends ChangeBounds {


+17 −19
Original line number Original line Diff line number Diff line
@@ -101,6 +101,8 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        // AND the plugin returns a view for the big clock
        // AND the plugin returns a view for the big clock
        ClockPlugin plugin = mock(ClockPlugin.class);
        ClockPlugin plugin = mock(ClockPlugin.class);
        when(plugin.getBigClockView()).thenReturn(mBigClock);
        when(plugin.getBigClockView()).thenReturn(mBigClock);
        // AND in the keyguard state
        mStateListener.onStateChanged(StatusBarState.KEYGUARD);
        // WHEN the plugin is connected
        // WHEN the plugin is connected
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        // THEN the big clock container is visible and it is the parent of the
        // 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);
        ClockPlugin plugin = mock(ClockPlugin.class);
        TextClock pluginView = new TextClock(getContext());
        TextClock pluginView = new TextClock(getContext());
        when(plugin.getBigClockView()).thenReturn(pluginView);
        when(plugin.getBigClockView()).thenReturn(pluginView);
        // AND in the keyguard state
        mStateListener.onStateChanged(StatusBarState.KEYGUARD);
        // WHEN the plugin is connected and then disconnected
        // WHEN the plugin is connected and then disconnected
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(null);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(null);
@@ -245,21 +249,25 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
    }
    }


    @Test
    @Test
    public void onStateChanged_InvisibleInShade() {
    public void onStateChanged_GoneInShade() {
        // GIVEN that the big clock container is visible
        // GIVEN that the big clock container is visible
        mBigClockContainer.setVisibility(View.VISIBLE);
        mBigClockContainer.setVisibility(View.VISIBLE);
        mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
        mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
        // WHEN transitioned to SHADE state
        // WHEN transitioned to SHADE state
        mStateListener.onStateChanged(StatusBarState.SHADE);
        mStateListener.onStateChanged(StatusBarState.SHADE);
        // THEN the container is invisible.
        // THEN the container is gone.
        assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.INVISIBLE);
        assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.GONE);
    }
    }


    @Test
    @Test
    public void onStateChanged_VisibleInKeyguard() {
    public void onStateChanged_VisibleInKeyguard() {
        // GIVEN that the big clock container is invisible
        // GIVEN that the big clock container is gone
        mBigClockContainer.setVisibility(View.INVISIBLE);
        mBigClockContainer.setVisibility(View.GONE);
        mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
        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
        // WHEN transitioned to KEYGUARD state
        mStateListener.onStateChanged(StatusBarState.KEYGUARD);
        mStateListener.onStateChanged(StatusBarState.KEYGUARD);
        // THEN the container is visible.
        // THEN the container is visible.
@@ -274,26 +282,14 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        ClockPlugin plugin = mock(ClockPlugin.class);
        ClockPlugin plugin = mock(ClockPlugin.class);
        when(plugin.getBigClockView()).thenReturn(mBigClock);
        when(plugin.getBigClockView()).thenReturn(mBigClock);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        // AND in the keyguard state
        mStateListener.onStateChanged(StatusBarState.KEYGUARD);
        // WHEN the container is associated with the clock switch
        // WHEN the container is associated with the clock switch
        mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
        mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
        // THEN the container remains visible.
        // THEN the container remains visible.
        assertThat(mBigClockContainer.getVisibility()).isEqualTo(View.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
    @Test
    public void setBigClockContainer_gone() {
    public void setBigClockContainer_gone() {
        // GIVEN that the big clock container is gone
        // GIVEN that the big clock container is gone
@@ -302,6 +298,8 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        ClockPlugin plugin = mock(ClockPlugin.class);
        ClockPlugin plugin = mock(ClockPlugin.class);
        when(plugin.getBigClockView()).thenReturn(mBigClock);
        when(plugin.getBigClockView()).thenReturn(mBigClock);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        mKeyguardClockSwitch.getClockChangedListener().onClockChanged(plugin);
        // AND in the keyguard state
        mStateListener.onStateChanged(StatusBarState.KEYGUARD);
        // WHEN the container is associated with the clock switch
        // WHEN the container is associated with the clock switch
        mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
        mKeyguardClockSwitch.setBigClockContainer(mBigClockContainer);
        // THEN the container is made visible.
        // THEN the container is made visible.