Fix reporting folds for relative bounds.
Fix the test fold for reporting coordinates that are relative to the
window instead of absolute.
Clean up some unnecessary qualifiers.
Clean up assert statements since the min sdk has been updated they are
no longer necessary.
Bug: 259649668
Test: ./gradlew window:window-testing:cAT
Change-Id: I4bd1326854b63efe94ce8f02c70e3d0a98093d89
diff --git a/window/window-testing/src/androidTest/java/androidx/window/testing/layout/DisplayFeatureTestingTest.kt b/window/window-testing/src/androidTest/java/androidx/window/testing/layout/DisplayFeatureTestingTest.kt
index 208b05f..5bb1be7 100644
--- a/window/window-testing/src/androidTest/java/androidx/window/testing/layout/DisplayFeatureTestingTest.kt
+++ b/window/window-testing/src/androidTest/java/androidx/window/testing/layout/DisplayFeatureTestingTest.kt
@@ -18,7 +18,6 @@
import android.graphics.Rect
import androidx.test.ext.junit.rules.ActivityScenarioRule
-import androidx.window.core.ExperimentalWindowApi
import androidx.window.layout.FoldingFeature.OcclusionType.Companion.FULL
import androidx.window.layout.FoldingFeature.OcclusionType.Companion.NONE
import androidx.window.layout.FoldingFeature.Orientation.Companion.HORIZONTAL
@@ -26,86 +25,72 @@
import androidx.window.layout.FoldingFeature.State.Companion.FLAT
import androidx.window.layout.WindowMetricsCalculator
import androidx.window.testing.TestActivity
-import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
-public class DisplayFeatureTestingTest {
+class DisplayFeatureTestingTest {
@get:Rule
- public val activityRule: ActivityScenarioRule<TestActivity> =
+ val activityRule: ActivityScenarioRule<TestActivity> =
ActivityScenarioRule(TestActivity::class.java)
private val windowBounds = Rect(0, 0, 320, 640)
- @OptIn(ExperimentalCoroutinesApi::class, ExperimentalWindowApi::class)
@Test
- public fun testFold_emptyWidthIsFold() {
+ fun testFold_emptyWidthIsFold() {
val center = windowBounds.centerX()
val actual =
FoldingFeature(windowBounds = windowBounds, state = FLAT, orientation = VERTICAL)
val expectedBounds = Rect(center, 0, center, windowBounds.height())
- assertEquals(expectedBounds.left, actual.bounds.left)
- assertEquals(expectedBounds.right, actual.bounds.right)
- assertEquals(expectedBounds.top, actual.bounds.top)
- assertEquals(expectedBounds.bottom, actual.bounds.bottom)
+
+ assertEquals(expectedBounds, actual.bounds)
assertFalse(actual.isSeparating)
assertEquals(NONE, actual.occlusionType)
assertEquals(VERTICAL, actual.orientation)
assertEquals(FLAT, actual.state)
}
- @OptIn(ExperimentalCoroutinesApi::class, ExperimentalWindowApi::class)
@Test
- public fun testFold_boundsMatchOrientation() {
+ fun testFold_boundsMatchOrientation() {
val bounds = Rect(0, 0, 320, 640)
val center = bounds.centerY()
val actual = FoldingFeature(windowBounds = bounds, state = FLAT, orientation = HORIZONTAL)
val expectedBounds = Rect(0, center, bounds.width(), center)
- assertEquals(expectedBounds.left, actual.bounds.left)
- assertEquals(expectedBounds.right, actual.bounds.right)
- assertEquals(expectedBounds.top, actual.bounds.top)
- assertEquals(expectedBounds.bottom, actual.bounds.bottom)
+
+ assertEquals(expectedBounds, actual.bounds)
assertFalse(actual.isSeparating)
assertEquals(NONE, actual.occlusionType)
assertEquals(HORIZONTAL, actual.orientation)
assertEquals(FLAT, actual.state)
}
- @OptIn(ExperimentalCoroutinesApi::class, ExperimentalWindowApi::class)
@Test
- public fun testFold_centerMatchOrientation_vertical() {
+ fun testFold_centerMatchOrientation_vertical() {
val center = windowBounds.centerX()
val actual = FoldingFeature(windowBounds = windowBounds, orientation = VERTICAL)
val expectedBounds = Rect(center, 0, center, windowBounds.height())
- assertEquals(expectedBounds.left, actual.bounds.left)
- assertEquals(expectedBounds.right, actual.bounds.right)
- assertEquals(expectedBounds.top, actual.bounds.top)
- assertEquals(expectedBounds.bottom, actual.bounds.bottom)
+
+ assertEquals(expectedBounds, actual.bounds)
assertEquals(NONE, actual.occlusionType)
assertEquals(VERTICAL, actual.orientation)
}
- @OptIn(ExperimentalCoroutinesApi::class, ExperimentalWindowApi::class)
@Test
- public fun testFold_centerMatchOrientation_horizontal() {
+ fun testFold_centerMatchOrientation_horizontal() {
val center = windowBounds.centerY()
val actual = FoldingFeature(windowBounds = windowBounds, orientation = HORIZONTAL)
val expectedBounds = Rect(0, center, windowBounds.width(), center)
- assertEquals(expectedBounds.left, actual.bounds.left)
- assertEquals(expectedBounds.right, actual.bounds.right)
- assertEquals(expectedBounds.top, actual.bounds.top)
- assertEquals(expectedBounds.bottom, actual.bounds.bottom)
+
+ assertEquals(expectedBounds, actual.bounds)
assertEquals(NONE, actual.occlusionType)
assertEquals(HORIZONTAL, actual.orientation)
}
- @OptIn(ExperimentalCoroutinesApi::class, ExperimentalWindowApi::class)
@Test
- public fun testFold_nonEmptyWidthIsFold() {
+ fun testFold_nonEmptyWidthIsFold() {
val center = windowBounds.centerX()
val width = 20
val actual =
@@ -116,33 +101,52 @@
orientation = VERTICAL
)
val expectedBounds = Rect(center - width / 2, 0, center + width / 2, windowBounds.height())
- assertEquals(expectedBounds.left, actual.bounds.left)
- assertEquals(expectedBounds.right, actual.bounds.right)
- assertEquals(expectedBounds.top, actual.bounds.top)
- assertEquals(expectedBounds.bottom, actual.bounds.bottom)
+
+ assertEquals(expectedBounds, actual.bounds)
assertTrue(actual.isSeparating)
assertEquals(FULL, actual.occlusionType)
assertEquals(VERTICAL, actual.orientation)
assertEquals(FLAT, actual.state)
}
- @OptIn(ExperimentalCoroutinesApi::class, ExperimentalWindowApi::class)
@Test
- public fun testFold_windowBoundsFromActivity() {
+ fun testFold_windowBoundsFromActivity() {
activityRule.scenario.onActivity { activity ->
val windowBounds =
WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(activity).bounds
val actual = FoldingFeature(activity = activity)
val expected = FoldingFeature(windowBounds = windowBounds)
val expectedBounds = expected.bounds
- assertEquals(expectedBounds.left, actual.bounds.left)
- assertEquals(expectedBounds.right, actual.bounds.right)
- assertEquals(expectedBounds.top, actual.bounds.top)
- assertEquals(expectedBounds.bottom, actual.bounds.bottom)
+
+ assertEquals(expectedBounds, actual.bounds)
assertEquals(expected.isSeparating, actual.isSeparating)
assertEquals(expected.occlusionType, actual.occlusionType)
assertEquals(expected.orientation, actual.orientation)
assertEquals(expected.state, actual.state)
}
}
+
+ @Test
+ fun testFold_windowBoundsAreRelative_vertical() {
+ val bounds = Rect(200, 300, 400, 600)
+ val center = bounds.centerX()
+ val actual = FoldingFeature(windowBounds = bounds, orientation = VERTICAL)
+ val expectedBounds = Rect(center, bounds.top, center, bounds.bottom)
+
+ assertEquals(expectedBounds, actual.bounds)
+ assertEquals(NONE, actual.occlusionType)
+ assertEquals(VERTICAL, actual.orientation)
+ }
+
+ @Test
+ fun testFold_windowBoundsAreRelative_horizontal() {
+ val bounds = Rect(200, 300, 400, 600)
+ val center = bounds.centerY()
+ val actual = FoldingFeature(windowBounds = bounds, orientation = HORIZONTAL)
+ val expectedBounds = Rect(bounds.left, center, bounds.right, center)
+
+ assertEquals(expectedBounds, actual.bounds)
+ assertEquals(NONE, actual.occlusionType)
+ assertEquals(HORIZONTAL, actual.orientation)
+ }
}
diff --git a/window/window-testing/src/main/java/androidx/window/testing/layout/DisplayFeatureTesting.kt b/window/window-testing/src/main/java/androidx/window/testing/layout/DisplayFeatureTesting.kt
index d104ce4..afa402f 100644
--- a/window/window-testing/src/main/java/androidx/window/testing/layout/DisplayFeatureTesting.kt
+++ b/window/window-testing/src/main/java/androidx/window/testing/layout/DisplayFeatureTesting.kt
@@ -150,11 +150,9 @@
val end = actualCenter + offset
val bounds =
if (orientation == VERTICAL) {
- val windowHeight = windowBounds.height()
- Rect(start, 0, end, windowHeight)
+ Rect(start, windowBounds.top, end, windowBounds.bottom)
} else {
- val windowWidth = windowBounds.width()
- Rect(0, start, windowWidth, end)
+ Rect(windowBounds.left, start, windowBounds.right, end)
}
val occlusionType =
if (shouldTreatAsHinge) {
@@ -180,9 +178,6 @@
) : FoldingFeature {
init {
require(!(bounds.width() == 0 && bounds.height() == 0)) { "Bounds must be non zero" }
- require(!(bounds.left != 0 && bounds.top != 0)) {
- "Bounding rectangle must start at the top or left window edge for folding features"
- }
}
override fun equals(other: Any?): Boolean {