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
This commit is contained in:
@@ -73,9 +73,6 @@ fun Float.atLeast(n: Number): Float = max(this, n.toFloat())
|
|||||||
* position. In practice the origin will be the upper-left coordinate of the primary display.
|
* 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 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
|
* @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
|
* on accessibility requirements, but also accounting for padding that appears
|
||||||
* around each button.
|
* around each button.
|
||||||
@@ -85,7 +82,7 @@ fun Float.atLeast(n: Number): Float = max(this, n.toFloat())
|
|||||||
* @param displaysPos the absolute topology coordinates for each display in the topology.
|
* @param displaysPos the absolute topology coordinates for each display in the topology.
|
||||||
*/
|
*/
|
||||||
class TopologyScale(
|
class TopologyScale(
|
||||||
paneWidth: Int, minPaneHeight: Float, minEdgeLength: Float, maxEdgeLength: Float,
|
paneWidth: Int, minEdgeLength: Float, maxEdgeLength: Float,
|
||||||
displaysPos: Collection<RectF>) {
|
displaysPos: Collection<RectF>) {
|
||||||
/** Scale of block sizes to real-world display sizes. Should be less than 1. */
|
/** Scale of block sizes to real-world display sizes. Should be less than 1. */
|
||||||
val blockRatio: Float
|
val blockRatio: Float
|
||||||
@@ -124,12 +121,11 @@ class TopologyScale(
|
|||||||
// requirements.
|
// requirements.
|
||||||
.atLeast(minEdgeLength / smallestDisplayDim)
|
.atLeast(minEdgeLength / smallestDisplayDim)
|
||||||
|
|
||||||
paneHeight = minPaneHeight
|
// A tall pane is likely to result in more scrolling. So we
|
||||||
// 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
|
||||||
// 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
|
||||||
// 1.5x of the minEdgeLength on each side. This keeps a comfortable amount of
|
// padding without it resulting in too much deadspace.
|
||||||
// padding without it resulting in too much deadspace.
|
paneHeight = blockRatio * displayBounds.height() + minEdgeLength * 3f
|
||||||
.atLeast(blockRatio * displayBounds.height() + minEdgeLength * 3f)
|
|
||||||
|
|
||||||
// Set originPaneXY (the location of 0,0 in display space in the pane's coordinate system)
|
// 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.
|
// such that the display bounds rect is centered in the pane.
|
||||||
@@ -404,7 +400,7 @@ class DisplayTopologyPreference(context : Context)
|
|||||||
// pixels, and the display coordinates are in density-independent pixels.
|
// pixels, and the display coordinates are in density-independent pixels.
|
||||||
val dpi = injector.densityDpi
|
val dpi = injector.densityDpi
|
||||||
val scaling = TopologyScale(
|
val scaling = TopologyScale(
|
||||||
mPaneContent.width, minPaneHeight = mTopologyInfo?.scaling?.paneHeight ?: 0f,
|
mPaneContent.width,
|
||||||
minEdgeLength = DisplayTopology.dpToPx(60f, dpi),
|
minEdgeLength = DisplayTopology.dpToPx(60f, dpi),
|
||||||
maxEdgeLength = DisplayTopology.dpToPx(256f, dpi),
|
maxEdgeLength = DisplayTopology.dpToPx(256f, dpi),
|
||||||
newBounds.map { it.second }.toList())
|
newBounds.map { it.second }.toList())
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ class TopologyScaleTest {
|
|||||||
@Test
|
@Test
|
||||||
fun oneDisplay4to3Aspect() {
|
fun oneDisplay4to3Aspect() {
|
||||||
val scale = TopologyScale(
|
val scale = TopologyScale(
|
||||||
/* paneWidth= */ 640, minPaneHeight = 0f,
|
paneWidth = 640, minEdgeLength = 48f, maxEdgeLength = 64f,
|
||||||
minEdgeLength = 48f, maxEdgeLength = 64f,
|
|
||||||
listOf(RectF(0f, 0f, 640f, 480f)))
|
listOf(RectF(0f, 0f, 640f, 480f)))
|
||||||
|
|
||||||
// blockRatio is is set in order to make the smallest display edge (480 dp) 48dp
|
// blockRatio is is set in order to make the smallest display edge (480 dp) 48dp
|
||||||
@@ -62,24 +61,12 @@ class TopologyScaleTest {
|
|||||||
PointF(640f, 240f) to scale.paneToDisplayCoor(352f, 96f),
|
PointF(640f, 240f) to scale.paneToDisplayCoor(352f, 96f),
|
||||||
),
|
),
|
||||||
0.001f)
|
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
|
@Test
|
||||||
fun twoUnalignedDisplays() {
|
fun twoUnalignedDisplays() {
|
||||||
val scale = TopologyScale(
|
val scale = TopologyScale(
|
||||||
/* paneWidth= */ 300, minPaneHeight = 0f,
|
paneWidth = 300, minEdgeLength = 48f, maxEdgeLength = 96f,
|
||||||
minEdgeLength = 48f, maxEdgeLength = 96f,
|
|
||||||
listOf(RectF(0f, 0f, 1920f, 1200f), RectF(1920f, -300f, 3840f, 900f)))
|
listOf(RectF(0f, 0f, 1920f, 1200f), RectF(1920f, -300f, 3840f, 900f)))
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@@ -97,8 +84,7 @@ class TopologyScaleTest {
|
|||||||
@Test
|
@Test
|
||||||
fun twoDisplaysBlockRatioBumpedForGarSizeMinimumHorizontal() {
|
fun twoDisplaysBlockRatioBumpedForGarSizeMinimumHorizontal() {
|
||||||
val scale = TopologyScale(
|
val scale = TopologyScale(
|
||||||
/* paneWidth= */ 192, minPaneHeight = 0f,
|
paneWidth = 192, minEdgeLength = 48f, maxEdgeLength = 64f,
|
||||||
minEdgeLength = 48f, maxEdgeLength = 64f,
|
|
||||||
listOf(RectF(0f, 0f, 240f, 320f), RectF(-240f, -320f, 0f, 0f)))
|
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
|
// blockRatio is higher than 0.05 in order to make the smallest display edge (240 dp) 48dp
|
||||||
@@ -118,8 +104,7 @@ class TopologyScaleTest {
|
|||||||
@Test
|
@Test
|
||||||
fun paneVerticalPaddingSetByMinEdgeLength() {
|
fun paneVerticalPaddingSetByMinEdgeLength() {
|
||||||
val scale = TopologyScale(
|
val scale = TopologyScale(
|
||||||
/* paneWidth= */ 300, minPaneHeight = 0f,
|
paneWidth = 300, minEdgeLength = 48f, maxEdgeLength = 80f,
|
||||||
minEdgeLength = 48f, maxEdgeLength = 80f,
|
|
||||||
listOf(
|
listOf(
|
||||||
RectF(0f, 0f, 640f, 480f),
|
RectF(0f, 0f, 640f, 480f),
|
||||||
RectF(0f, 480f, 640f, 960f),
|
RectF(0f, 480f, 640f, 960f),
|
||||||
@@ -141,8 +126,7 @@ class TopologyScaleTest {
|
|||||||
@Test
|
@Test
|
||||||
fun limitedByCustomMaxBlockRatio() {
|
fun limitedByCustomMaxBlockRatio() {
|
||||||
val scale = TopologyScale(
|
val scale = TopologyScale(
|
||||||
/* paneWidth= */ 300, minPaneHeight = 0f,
|
paneWidth = 300, minEdgeLength = 24f, maxEdgeLength = 77f,
|
||||||
minEdgeLength = 24f, maxEdgeLength = 77f,
|
|
||||||
listOf(
|
listOf(
|
||||||
RectF(0f, 0f, 640f, 480f),
|
RectF(0f, 0f, 640f, 480f),
|
||||||
RectF(0f, 480f, 640f, 960f)))
|
RectF(0f, 480f, 640f, 960f)))
|
||||||
@@ -161,8 +145,7 @@ class TopologyScaleTest {
|
|||||||
fun largeCustomMinEdgeLength() {
|
fun largeCustomMinEdgeLength() {
|
||||||
// minBlockEdgeLength/minDisplayEdgeLength = 80/480 = 1/6, so the block ratio will be 1/6
|
// minBlockEdgeLength/minDisplayEdgeLength = 80/480 = 1/6, so the block ratio will be 1/6
|
||||||
val scale = TopologyScale(
|
val scale = TopologyScale(
|
||||||
/* paneWidth= */ 300, minPaneHeight = 0f,
|
paneWidth = 300, minEdgeLength = 80f, maxEdgeLength = 100f,
|
||||||
minEdgeLength = 80f, maxEdgeLength = 100f,
|
|
||||||
listOf(
|
listOf(
|
||||||
RectF(0f, 0f, 640f, 480f),
|
RectF(0f, 0f, 640f, 480f),
|
||||||
RectF(0f, 480f, 640f, 960f)))
|
RectF(0f, 480f, 640f, 960f)))
|
||||||
|
|||||||
Reference in New Issue
Block a user