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

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

Merge "Fix custom clock face showing up outside of lock screen."

parents 30e984ca 60854080
Loading
Loading
Loading
Loading
+27 −0
Original line number Original line Diff line number Diff line
@@ -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;
@@ -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);
@@ -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);
    }
    }


    /**
    /**
@@ -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;
    }
}
}
+30 −0
Original line number Original line Diff line number Diff line
@@ -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;


@@ -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;
@@ -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;
@@ -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
@@ -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);
    }
}
}