Allow pane height to shrink when setting topology
A recent CL added a feature to prevent the pane height from shrinking to
stop widgets from moving around. This is actually not a great experience
because a temporary state can keep the pane height very tall and
increase scrolling.
Flag: com.android.settings.flags.display_topology_pane_in_display_list
Bug: b/352648432
Test: change topology to be vertically shorter and verify the pane height shrinks
Change-Id: Ic48bfecea083a45c702c8719e3c93ceba55ae872
diff --git a/src/com/android/settings/connecteddevice/display/DisplayTopology.kt b/src/com/android/settings/connecteddevice/display/DisplayTopology.kt
index 50ad5d1..c30d98a 100644
--- a/src/com/android/settings/connecteddevice/display/DisplayTopology.kt
+++ b/src/com/android/settings/connecteddevice/display/DisplayTopology.kt
@@ -73,9 +73,6 @@
* position. In practice the origin will be the upper-left coordinate of the primary display.
*
* @param paneWidth width of the pane in view coordinates
- * @param minPaneHeight smallest allowed height of the pane in view coordinates. This will not
- * affect the block ratio, but only the final height of the pane and the
- * position of the display bounds' center.
* @param minEdgeLength the smallest length permitted of a display block. This should be set based
* on accessibility requirements, but also accounting for padding that appears
* around each button.
@@ -85,7 +82,7 @@
* @param displaysPos the absolute topology coordinates for each display in the topology.
*/
class TopologyScale(
- paneWidth: Int, minPaneHeight: Float, minEdgeLength: Float, maxEdgeLength: Float,
+ paneWidth: Int, minEdgeLength: Float, maxEdgeLength: Float,
displaysPos: Collection<RectF>) {
/** Scale of block sizes to real-world display sizes. Should be less than 1. */
val blockRatio: Float
@@ -124,12 +121,11 @@
// requirements.
.atLeast(minEdgeLength / smallestDisplayDim)
- paneHeight = minPaneHeight
- // A tall pane is likely to result in more scrolling. So we
- // prevent the height from growing too large here, by limiting vertical padding to
- // 1.5x of the minEdgeLength on each side. This keeps a comfortable amount of
- // padding without it resulting in too much deadspace.
- .atLeast(blockRatio * displayBounds.height() + minEdgeLength * 3f)
+ // A tall pane is likely to result in more scrolling. So we
+ // prevent the height from growing too large here, by limiting vertical padding to
+ // 1.5x of the minEdgeLength on each side. This keeps a comfortable amount of
+ // padding without it resulting in too much deadspace.
+ paneHeight = blockRatio * displayBounds.height() + minEdgeLength * 3f
// Set originPaneXY (the location of 0,0 in display space in the pane's coordinate system)
// such that the display bounds rect is centered in the pane.
@@ -404,7 +400,7 @@
// pixels, and the display coordinates are in density-independent pixels.
val dpi = injector.densityDpi
val scaling = TopologyScale(
- mPaneContent.width, minPaneHeight = mTopologyInfo?.scaling?.paneHeight ?: 0f,
+ mPaneContent.width,
minEdgeLength = DisplayTopology.dpToPx(60f, dpi),
maxEdgeLength = DisplayTopology.dpToPx(256f, dpi),
newBounds.map { it.second }.toList())
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/display/TopologyScaleTest.kt b/tests/robotests/src/com/android/settings/connecteddevice/display/TopologyScaleTest.kt
index e88939b..9e0aeac 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/display/TopologyScaleTest.kt
+++ b/tests/robotests/src/com/android/settings/connecteddevice/display/TopologyScaleTest.kt
@@ -45,8 +45,7 @@
@Test
fun oneDisplay4to3Aspect() {
val scale = TopologyScale(
- /* paneWidth= */ 640, minPaneHeight = 0f,
- minEdgeLength = 48f, maxEdgeLength = 64f,
+ paneWidth = 640, minEdgeLength = 48f, maxEdgeLength = 64f,
listOf(RectF(0f, 0f, 640f, 480f)))
// blockRatio is is set in order to make the smallest display edge (480 dp) 48dp
@@ -62,24 +61,12 @@
PointF(640f, 240f) to scale.paneToDisplayCoor(352f, 96f),
),
0.001f)
-
- // Same as original scale but made taller with minPaneHeight.
- // The paneHeight and origin coordinates are changed but the block ratio is the same.
- val taller = TopologyScale(
- /* paneWidth= */ 640, minPaneHeight = 155.0f,
- minEdgeLength = 48f, maxEdgeLength = 64f,
- listOf(RectF(0f, 0f, 640f, 480f)))
-
- assertEquals(
- "{TopologyScale blockRatio=0.100000 originPaneXY=288.0,72.0 paneHeight=192.0}",
- "" + taller)
}
@Test
fun twoUnalignedDisplays() {
val scale = TopologyScale(
- /* paneWidth= */ 300, minPaneHeight = 0f,
- minEdgeLength = 48f, maxEdgeLength = 96f,
+ paneWidth = 300, minEdgeLength = 48f, maxEdgeLength = 96f,
listOf(RectF(0f, 0f, 1920f, 1200f), RectF(1920f, -300f, 3840f, 900f)))
assertEquals(
@@ -97,8 +84,7 @@
@Test
fun twoDisplaysBlockRatioBumpedForGarSizeMinimumHorizontal() {
val scale = TopologyScale(
- /* paneWidth= */ 192, minPaneHeight = 0f,
- minEdgeLength = 48f, maxEdgeLength = 64f,
+ paneWidth = 192, minEdgeLength = 48f, maxEdgeLength = 64f,
listOf(RectF(0f, 0f, 240f, 320f), RectF(-240f, -320f, 0f, 0f)))
// blockRatio is higher than 0.05 in order to make the smallest display edge (240 dp) 48dp
@@ -118,8 +104,7 @@
@Test
fun paneVerticalPaddingSetByMinEdgeLength() {
val scale = TopologyScale(
- /* paneWidth= */ 300, minPaneHeight = 0f,
- minEdgeLength = 48f, maxEdgeLength = 80f,
+ paneWidth = 300, minEdgeLength = 48f, maxEdgeLength = 80f,
listOf(
RectF(0f, 0f, 640f, 480f),
RectF(0f, 480f, 640f, 960f),
@@ -141,8 +126,7 @@
@Test
fun limitedByCustomMaxBlockRatio() {
val scale = TopologyScale(
- /* paneWidth= */ 300, minPaneHeight = 0f,
- minEdgeLength = 24f, maxEdgeLength = 77f,
+ paneWidth = 300, minEdgeLength = 24f, maxEdgeLength = 77f,
listOf(
RectF(0f, 0f, 640f, 480f),
RectF(0f, 480f, 640f, 960f)))
@@ -161,8 +145,7 @@
fun largeCustomMinEdgeLength() {
// minBlockEdgeLength/minDisplayEdgeLength = 80/480 = 1/6, so the block ratio will be 1/6
val scale = TopologyScale(
- /* paneWidth= */ 300, minPaneHeight = 0f,
- minEdgeLength = 80f, maxEdgeLength = 100f,
+ paneWidth = 300, minEdgeLength = 80f, maxEdgeLength = 100f,
listOf(
RectF(0f, 0f, 640f, 480f),
RectF(0f, 480f, 640f, 960f)))