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

Commit d4db8588 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Fix spacing of QQS when media is present in scene

When media is present in the scene, it should not be attached to
QSPanel. Make sure that mUsingMediaPlayer from the QSSceneModule is
respected.

Note that this will make it so that QS always has the standard number of
columns. We need some extra treatment in
QSPanelControllerBase.shouldUseHorizontalLayout to determine if we
should use the `horizontal` mode when media is visible in scene even
when the flag is false.

Test: atest QSPanelTest
Test: manual
Fixes: 329662922
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT

Change-Id: I9aec11beffe7b6b7ef8ec7a7338349dbca245e02
parent 42910f6b
Loading
Loading
Loading
Loading
+34 −20
Original line number Diff line number Diff line
@@ -127,8 +127,9 @@ public class QSPanel extends LinearLayout implements Tunable {

    }

    void initialize(QSLogger qsLogger) {
    void initialize(QSLogger qsLogger, boolean usingMediaPlayer) {
        mQsLogger = qsLogger;
        mUsingMediaPlayer = usingMediaPlayer;
        mTileLayout = getOrCreateTileLayout();

        if (mUsingMediaPlayer) {
@@ -163,10 +164,12 @@ public class QSPanel extends LinearLayout implements Tunable {
    }

    protected void setHorizontalContentContainerClipping() {
        if (mHorizontalContentContainer != null) {
            mHorizontalContentContainer.setClipChildren(true);
            mHorizontalContentContainer.setClipToPadding(false);
            // Don't clip on the top, that way, secondary pages tiles can animate up
        // Clipping coordinates should be relative to this view, not absolute (parent coordinates)
            // Clipping coordinates should be relative to this view, not absolute
            // (parent coordinates)
            mHorizontalContentContainer.addOnLayoutChangeListener(
                    (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
                        if ((right - left) != (oldRight - oldLeft)
@@ -180,6 +183,7 @@ public class QSPanel extends LinearLayout implements Tunable {
            mClippingRect.top = -1000;
            mHorizontalContentContainer.setClipBounds(mClippingRect);
        }
    }

    /**
     * Add brightness view above the tile layout.
@@ -412,7 +416,7 @@ public class QSPanel extends LinearLayout implements Tunable {
    }

    private void updateHorizontalLinearLayoutMargins() {
        if (mHorizontalLinearLayout != null && !displayMediaMarginsOnMedia()) {
        if (mUsingMediaPlayer && mHorizontalLinearLayout != null && !displayMediaMarginsOnMedia()) {
            LayoutParams lp = (LayoutParams) mHorizontalLinearLayout.getLayoutParams();
            lp.bottomMargin = Math.max(mMediaTotalBottomMargin - getPaddingBottom(), 0);
            mHorizontalLinearLayout.setLayoutParams(lp);
@@ -461,6 +465,11 @@ public class QSPanel extends LinearLayout implements Tunable {
    /** Call when orientation has changed and MediaHost needs to be adjusted. */
    private void reAttachMediaHost(ViewGroup hostView, boolean horizontal) {
        if (!mUsingMediaPlayer) {
            // If the host view was attached, detach it.
            ViewGroup parent = (ViewGroup) hostView.getParent();
            if (parent != null) {
                parent.removeView(hostView);
            }
            return;
        }
        mMediaHostView = hostView;
@@ -616,7 +625,10 @@ public class QSPanel extends LinearLayout implements Tunable {
        if (horizontal != mUsingHorizontalLayout || force) {
            Log.d(getDumpableTag(), "setUsingHorizontalLayout: " + horizontal + ", " + force);
            mUsingHorizontalLayout = horizontal;
            ViewGroup newParent = horizontal ? mHorizontalContentContainer : this;
            // The tile layout should be reparented if horizontal and we are using media. If not
            // using media, the parent should always be this.
            ViewGroup newParent =
                    horizontal && mUsingMediaPlayer ? mHorizontalContentContainer : this;
            switchAllContentToParent(newParent, mTileLayout);
            reAttachMediaHost(mediaHostView, horizontal);
            if (needsDynamicRowsAndColumns()) {
@@ -624,9 +636,11 @@ public class QSPanel extends LinearLayout implements Tunable {
                mTileLayout.setMaxColumns(horizontal ? 2 : 4);
            }
            updateMargins(mediaHostView);
            if (mHorizontalLinearLayout != null) {
                mHorizontalLinearLayout.setVisibility(horizontal ? View.VISIBLE : View.GONE);
            }
        }
    }

    private void updateMargins(ViewGroup mediaHostView) {
        updateMediaHostContentMargins(mediaHostView);
+1 −1
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr

    @Override
    protected void onInit() {
        mView.initialize(mQSLogger);
        mView.initialize(mQSLogger, mUsingMediaPlayer);
        mQSLogger.logAllTilesChangeListening(mView.isListening(), mView.getDumpableTag(), "");
        mHost.addCallback(mQSHostCallback);
    }
+58 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.testing.TestableLooper.RunWithLooper
import android.testing.ViewUtils
import android.view.ContextThemeWrapper
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.FrameLayout
@@ -71,7 +72,7 @@ class QSPanelTest : SysuiTestCase() {
            qsPanel = QSPanel(themedContext, null)
            qsPanel.mUsingMediaPlayer = true

            qsPanel.initialize(qsLogger)
            qsPanel.initialize(qsLogger, true)
            // QSPanel inflates a footer inside of it, mocking it here
            footer = LinearLayout(themedContext).apply { id = R.id.qs_footer }
            qsPanel.addView(footer, MATCH_PARENT, 100)
@@ -218,6 +219,62 @@ class QSPanelTest : SysuiTestCase() {
        verify(tile).addCallback(record.callback)
    }

    @Test
    fun initializedWithNoMedia_tileLayoutParentIsAlwaysQsPanel() {
        lateinit var panel: QSPanel
        lateinit var tileLayout: View
        testableLooper.runWithLooper {
            panel = QSPanel(themedContext, null)
            panel.mUsingMediaPlayer = true

            panel.initialize(qsLogger, /* usingMediaPlayer= */ false)
            tileLayout = panel.orCreateTileLayout as View
            // QSPanel inflates a footer inside of it, mocking it here
            footer = LinearLayout(themedContext).apply { id = R.id.qs_footer }
            panel.addView(footer, MATCH_PARENT, 100)
            panel.onFinishInflate()
            // Provides a parent with non-zero size for QSPanel
            ViewUtils.attachView(panel)
        }
        val mockMediaHost = mock(ViewGroup::class.java)

        panel.setUsingHorizontalLayout(false, mockMediaHost, true)

        assertThat(tileLayout.parent).isSameInstanceAs(panel)

        panel.setUsingHorizontalLayout(true, mockMediaHost, true)
        assertThat(tileLayout.parent).isSameInstanceAs(panel)

        ViewUtils.detachView(panel)
    }

    @Test
    fun initializeWithNoMedia_mediaNeverAttached() {
        lateinit var panel: QSPanel
        testableLooper.runWithLooper {
            panel = QSPanel(themedContext, null)
            panel.mUsingMediaPlayer = true

            panel.initialize(qsLogger, /* usingMediaPlayer= */ false)
            panel.orCreateTileLayout as View
            // QSPanel inflates a footer inside of it, mocking it here
            footer = LinearLayout(themedContext).apply { id = R.id.qs_footer }
            panel.addView(footer, MATCH_PARENT, 100)
            panel.onFinishInflate()
            // Provides a parent with non-zero size for QSPanel
            ViewUtils.attachView(panel)
        }
        val mockMediaHost = FrameLayout(themedContext)

        panel.setUsingHorizontalLayout(false, mockMediaHost, true)
        assertThat(mockMediaHost.parent).isNull()

        panel.setUsingHorizontalLayout(true, mockMediaHost, true)
        assertThat(mockMediaHost.parent).isNull()

        ViewUtils.detachView(panel)
    }

    private infix fun View.isLeftOf(other: View): Boolean {
        val rect = Rect()
        getBoundsOnScreen(rect)
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class QuickQSPanelTest : SysuiTestCase() {

        testableLooper.runWithLooper {
            quickQSPanel = QuickQSPanel(mContext, null)
            quickQSPanel.initialize(qsLogger)
            quickQSPanel.initialize(qsLogger, true)

            quickQSPanel.onFinishInflate()
            // Provides a parent with non-zero size for QSPanel