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

Commit 6a0140ab authored by Robert Snoeberger's avatar Robert Snoeberger
Browse files

Add container for big clock behind NSSL and KeyguardStatusView.

Bug: 120497585
Test: Added tests to KeyguardClockSwitchTest, pass locally.
Change-Id: Icc1199a67b9a4728e4d0f0b50ea98f5221de904d
parent 6fa14aba
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -35,6 +35,13 @@ public interface ClockPlugin extends Plugin {
     */
    View getView();

    /**
     * Get clock view for a large clock that appears behind NSSL.
     */
    default View getBigClockView() {
        return null;
    }

    /**
     * Set clock paint style.
     * @param style The new style to set in the paint.
+6 −0
Original line number Diff line number Diff line
@@ -25,6 +25,12 @@
    android:layout_height="match_parent"
    android:background="@android:color/transparent" >

    <FrameLayout
        android:id="@+id/big_clock_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" />

    <include
        layout="@layout/keyguard_status_view"
        android:visibility="gone" />
+40 −13
Original line number Diff line number Diff line
@@ -35,7 +35,11 @@ public class KeyguardClockSwitch extends RelativeLayout {
    /**
     * Frame for default and custom clock.
     */
    private FrameLayout mClockFrame;
    private FrameLayout mSmallClockFrame;
    /**
     * Container for big custom clock.
     */
    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.
@@ -46,22 +50,27 @@ public class KeyguardClockSwitch extends RelativeLayout {
            new PluginListener<ClockPlugin>() {
                @Override
                public void onPluginConnected(ClockPlugin plugin, Context pluginContext) {
                    View view = plugin.getView();
                    if (view != null) {
                    disconnectPlugin();
                    View smallClockView = plugin.getView();
                    if (smallClockView != null) {
                        // For now, assume that the most recently connected plugin is the
                        // selected clock face. In the future, the user should be able to
                        // pick a clock face from the available plugins.
                        mClockPlugin = plugin;
                        mClockFrame.addView(view, -1,
                        mSmallClockFrame.addView(smallClockView, -1,
                                new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                        ViewGroup.LayoutParams.WRAP_CONTENT));
                        initPluginParams();
                        mClockView.setVisibility(View.GONE);
                    }
                    View bigClockView = plugin.getBigClockView();
                    if (bigClockView != null && mBigClockContainer != null) {
                        mBigClockContainer.addView(bigClockView);
                        mBigClockContainer.setVisibility(View.VISIBLE);
                    }
                    if (!plugin.shouldShowStatusArea()) {
                        mKeyguardStatusArea.setVisibility(View.GONE);
                    }
                    }
                    mClockPlugin = plugin;
                }

                @Override
@@ -86,7 +95,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
    protected void onFinishInflate() {
        super.onFinishInflate();
        mClockView = findViewById(R.id.default_clock_view);
        mClockFrame = findViewById(R.id.clock_view);
        mSmallClockFrame = findViewById(R.id.clock_view);
        mKeyguardStatusArea = findViewById(R.id.keyguard_status_area);
    }

@@ -103,6 +112,20 @@ public class KeyguardClockSwitch extends RelativeLayout {
        Dependency.get(PluginManager.class).removePluginListener(mClockPluginListener);
    }

    /**
     * Set container for big clock face appearing behind NSSL and KeyguardStatusView.
     */
    public void setBigClockContainer(ViewGroup container) {
        if (mClockPlugin != null && container != null) {
            View bigClockView = mClockPlugin.getBigClockView();
            if (bigClockView != null) {
                container.addView(bigClockView);
                container.setVisibility(View.VISIBLE);
            }
        }
        mBigClockContainer = container;
    }

    /**
     * It will also update plugin setStyle if plugin is connected.
     */
@@ -199,9 +222,13 @@ public class KeyguardClockSwitch extends RelativeLayout {

    private void disconnectPlugin() {
        if (mClockPlugin != null) {
            View view = mClockPlugin.getView();
            if (view != null) {
                mClockFrame.removeView(view);
            View smallClockView = mClockPlugin.getView();
            if (smallClockView != null) {
                mSmallClockFrame.removeView(smallClockView);
            }
            if (mBigClockContainer != null) {
                mBigClockContainer.removeAllViews();
                mBigClockContainer.setVisibility(View.GONE);
            }
            mClockPlugin = null;
        }
+6 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.widget.FrameLayout;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.keyguard.KeyguardClockSwitch;
import com.android.keyguard.KeyguardStatusView;
import com.android.systemui.DejankUtils;
import com.android.systemui.Dependency;
@@ -133,7 +134,7 @@ public class NotificationPanelView extends PanelView implements
    public static final int FLING_COLLAPSE = 1;

    /**
     * Fing until QS is completely hidden.
     * Fling until QS is completely hidden.
     */
    public static final int FLING_HIDE = 2;

@@ -359,6 +360,10 @@ public class NotificationPanelView extends PanelView implements
        mKeyguardStatusBar = findViewById(R.id.keyguard_header);
        mKeyguardStatusView = findViewById(R.id.keyguard_status_view);

        KeyguardClockSwitch keyguardClockSwitch = findViewById(R.id.keyguard_clock_container);
        ViewGroup bigClockContainer = findViewById(R.id.big_clock_container);
        keyguardClockSwitch.setBigClockContainer(bigClockContainer);

        mNotificationContainerParent = findViewById(R.id.notification_container_parent);
        mNotificationStackScroller = findViewById(R.id.notification_stack_scroller);
        mNotificationStackScroller.setOnHeightChangedListener(this);
+39 −0
Original line number Diff line number Diff line
@@ -106,6 +106,25 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        assertThat(plugin.getView().getParent()).isEqualTo(mClockContainer);
    }

    @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);
        // 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);
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        // WHEN the plugin is connected
        listener.onPluginConnected(plugin, null);
        // 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);
    }

    @Test
    public void onPluginConnected_nullView() {
        ClockPlugin plugin = mock(ClockPlugin.class);
@@ -145,6 +164,26 @@ public class KeyguardClockSwitchTest extends SysuiTestCase {
        assertThat(plugin.getView().getParent()).isNull();
    }

    @Test
    public void onPluginDisconnected_hidePluginBigClock() {
        // GIVEN that the big clock container is visible
        FrameLayout bigClockContainer = new FrameLayout(getContext());
        bigClockContainer.setVisibility(VISIBLE);
        mKeyguardClockSwitch.setBigClockContainer(bigClockContainer);
        // 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);
        PluginListener listener = mKeyguardClockSwitch.getClockPluginListener();
        listener.onPluginConnected(plugin, null);
        // WHEN the plugin is disconnected
        listener.onPluginDisconnected(plugin);
        // THEN the big lock container is GONE and the big clock view doesn't have
        // a parent.
        assertThat(bigClockContainer.getVisibility()).isEqualTo(GONE);
        assertThat(pluginView.getParent()).isNull();
    }

    @Test
    public void onPluginDisconnected_nullView() {
        ClockPlugin plugin = mock(ClockPlugin.class);