Merge "Fix clipping coordinates on RTL" into tm-dev am: 47364ef97d am: 9515f3009e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18819506

Change-Id: Ic80ee6c149a8f9b6be6914ca9e5e17f35d027689
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Fabian Kozynski
2022-06-13 14:22:29 +00:00
committed by Automerger Merge Worker
2 changed files with 105 additions and 24 deletions

View File

@@ -151,15 +151,17 @@ public class QSPanel extends LinearLayout implements Tunable {
mHorizontalContentContainer.setClipChildren(true); mHorizontalContentContainer.setClipChildren(true);
mHorizontalContentContainer.setClipToPadding(false); mHorizontalContentContainer.setClipToPadding(false);
// Don't clip on the top, that way, secondary pages tiles can animate up // 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)
mHorizontalContentContainer.addOnLayoutChangeListener( mHorizontalContentContainer.addOnLayoutChangeListener(
(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
if (left != oldLeft || right != oldRight || bottom != oldBottom) { if ((right - left) != (oldRight - oldLeft)
mClippingRect.left = left; || ((bottom - top) != (oldBottom - oldTop))) {
mClippingRect.right = right; mClippingRect.right = right - left;
mClippingRect.bottom = bottom; mClippingRect.bottom = bottom - top;
mHorizontalContentContainer.setClipBounds(mClippingRect); mHorizontalContentContainer.setClipBounds(mClippingRect);
} }
}); });
mClippingRect.left = 0;
mClippingRect.top = -1000; mClippingRect.top = -1000;
mHorizontalContentContainer.setClipBounds(mClippingRect); mHorizontalContentContainer.setClipBounds(mClippingRect);
} }

View File

@@ -13,18 +13,24 @@
*/ */
package com.android.systemui.qs package com.android.systemui.qs
import android.graphics.Rect
import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner
import android.testing.TestableLooper import android.testing.TestableLooper
import android.testing.TestableLooper.RunWithLooper import android.testing.TestableLooper.RunWithLooper
import android.testing.ViewUtils
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.accessibility.AccessibilityNodeInfo import android.view.accessibility.AccessibilityNodeInfo
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.android.systemui.R import com.android.systemui.R
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.qs.tileimpl.QSIconViewImpl
import com.android.systemui.qs.tileimpl.QSTileViewImpl
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -36,37 +42,40 @@ import org.mockito.MockitoAnnotations
@RunWithLooper @RunWithLooper
@SmallTest @SmallTest
class QSPanelTest : SysuiTestCase() { class QSPanelTest : SysuiTestCase() {
private lateinit var mTestableLooper: TestableLooper private lateinit var testableLooper: TestableLooper
private lateinit var mQsPanel: QSPanel private lateinit var qsPanel: QSPanel
private lateinit var mParentView: ViewGroup private lateinit var footer: View
private lateinit var mFooter: View
@Before @Before
@Throws(Exception::class) @Throws(Exception::class)
fun setup() { fun setup() {
MockitoAnnotations.initMocks(this) MockitoAnnotations.initMocks(this)
mTestableLooper = TestableLooper.get(this) testableLooper = TestableLooper.get(this)
mTestableLooper.runWithLooper { testableLooper.runWithLooper {
mQsPanel = QSPanel(mContext, null) qsPanel = QSPanel(context, null)
mQsPanel.initialize() qsPanel.mUsingMediaPlayer = true
qsPanel.initialize()
// QSPanel inflates a footer inside of it, mocking it here // QSPanel inflates a footer inside of it, mocking it here
mFooter = LinearLayout(mContext).apply { id = R.id.qs_footer } footer = LinearLayout(context).apply { id = R.id.qs_footer }
mQsPanel.addView(mFooter) qsPanel.addView(footer, MATCH_PARENT, 100)
mQsPanel.onFinishInflate() qsPanel.onFinishInflate()
// Provides a parent with non-zero size for QSPanel // Provides a parent with non-zero size for QSPanel
mParentView = FrameLayout(mContext).apply { ViewUtils.attachView(qsPanel)
addView(mQsPanel)
}
} }
} }
@After
fun tearDown() {
ViewUtils.detachView(qsPanel)
}
@Test @Test
fun testHasCollapseAccessibilityAction() { fun testHasCollapseAccessibilityAction() {
val info = AccessibilityNodeInfo(mQsPanel) val info = AccessibilityNodeInfo(qsPanel)
mQsPanel.onInitializeAccessibilityNodeInfo(info) qsPanel.onInitializeAccessibilityNodeInfo(info)
assertThat(info.actions and AccessibilityNodeInfo.ACTION_COLLAPSE).isNotEqualTo(0) assertThat(info.actions and AccessibilityNodeInfo.ACTION_COLLAPSE).isNotEqualTo(0)
assertThat(info.actions and AccessibilityNodeInfo.ACTION_EXPAND).isEqualTo(0) assertThat(info.actions and AccessibilityNodeInfo.ACTION_EXPAND).isEqualTo(0)
@@ -75,9 +84,79 @@ class QSPanelTest : SysuiTestCase() {
@Test @Test
fun testCollapseActionCallsRunnable() { fun testCollapseActionCallsRunnable() {
val mockRunnable = mock(Runnable::class.java) val mockRunnable = mock(Runnable::class.java)
mQsPanel.setCollapseExpandAction(mockRunnable) qsPanel.setCollapseExpandAction(mockRunnable)
mQsPanel.performAccessibilityAction(AccessibilityNodeInfo.ACTION_COLLAPSE, null) qsPanel.performAccessibilityAction(AccessibilityNodeInfo.ACTION_COLLAPSE, null)
verify(mockRunnable).run() verify(mockRunnable).run()
} }
@Test
fun testTilesFooterVisibleRTLLandscapeMedia() {
qsPanel.layoutDirection = View.LAYOUT_DIRECTION_RTL
// We need at least a tile so the layout has a height
qsPanel.tileLayout?.addTile(
QSPanelControllerBase.TileRecord(
mock(QSTile::class.java),
QSTileViewImpl(context, QSIconViewImpl(context))
)
)
val mediaView = FrameLayout(context)
mediaView.addView(View(context), MATCH_PARENT, 800)
qsPanel.setUsingHorizontalLayout(/* horizontal */ true, mediaView, /* force */ true)
qsPanel.measure(
/* width */ View.MeasureSpec.makeMeasureSpec(3000, View.MeasureSpec.EXACTLY),
/* height */ View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY)
)
qsPanel.layout(0, 0, qsPanel.measuredWidth, qsPanel.measuredHeight)
val tiles = qsPanel.tileLayout as View
// Tiles are effectively to the right of media
assertThat(mediaView isLeftOf tiles)
assertThat(tiles.isVisibleToUser).isTrue()
assertThat(mediaView isLeftOf footer)
assertThat(footer.isVisibleToUser).isTrue()
}
@Test
fun testTilesFooterVisibleLandscapeMedia() {
qsPanel.layoutDirection = View.LAYOUT_DIRECTION_LTR
// We need at least a tile so the layout has a height
qsPanel.tileLayout?.addTile(
QSPanelControllerBase.TileRecord(
mock(QSTile::class.java),
QSTileViewImpl(context, QSIconViewImpl(context))
)
)
val mediaView = FrameLayout(context)
mediaView.addView(View(context), MATCH_PARENT, 800)
qsPanel.setUsingHorizontalLayout(/* horizontal */ true, mediaView, /* force */ true)
qsPanel.measure(
/* width */ View.MeasureSpec.makeMeasureSpec(3000, View.MeasureSpec.EXACTLY),
/* height */ View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY)
)
qsPanel.layout(0, 0, qsPanel.measuredWidth, qsPanel.measuredHeight)
val tiles = qsPanel.tileLayout as View
// Tiles are effectively to the left of media
assertThat(tiles isLeftOf mediaView)
assertThat(tiles.isVisibleToUser).isTrue()
assertThat(footer isLeftOf mediaView)
assertThat(footer.isVisibleToUser).isTrue()
}
private infix fun View.isLeftOf(other: View): Boolean {
val rect = Rect()
getBoundsOnScreen(rect)
val thisRight = rect.right
other.getBoundsOnScreen(rect)
return thisRight <= rect.left
}
} }