Replace PxPosition with Offset
Relnote: "In order to consolidate the
number of classes used to represent
positioning information, standardize
on usage of the Offset class instead
of PxPosition. This provides the benefits
of an inline class to leverage a long
to pack 2 float values to represent x
and y offsets represented as floats."
Bug: 157948366
Test: re-ran compose tests
Change-Id: I3ad983207bc37af20afac03e2cd09b4240777687
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/LayoutCoordinatesHelperTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/LayoutCoordinatesHelperTest.kt
index 65a8f4a..a8eb8f3 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/LayoutCoordinatesHelperTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/LayoutCoordinatesHelperTest.kt
@@ -27,7 +27,7 @@
import androidx.ui.layout.Column
import androidx.ui.layout.preferredSize
import androidx.ui.layout.preferredWidth
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import androidx.ui.unit.dp
import androidx.ui.unit.ipx
import org.junit.Assert.assertEquals
@@ -69,8 +69,8 @@
assertTrue(latch.await(1, TimeUnit.SECONDS))
assertEquals(
- PxPosition.Origin,
- parentCoordinates!!.childToLocal(childCoordinates!!, PxPosition.Origin)
+ Offset.Zero,
+ parentCoordinates!!.childToLocal(childCoordinates!!, Offset.Zero)
)
}
@@ -104,8 +104,8 @@
assertTrue(latch.await(1, TimeUnit.SECONDS))
assertEquals(
- PxPosition(5f, 0f),
- parentCoordinates!!.childToLocal(childCoordinates!!, PxPosition.Origin)
+ Offset(5f, 0f),
+ parentCoordinates!!.childToLocal(childCoordinates!!, Offset.Zero)
)
}
}
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendClickTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendClickTest.kt
index fb07256..dfb2ab0 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendClickTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendClickTest.kt
@@ -34,7 +34,7 @@
import androidx.ui.test.sendClick
import androidx.ui.test.util.ClickableTestBox
import androidx.ui.test.util.RecordingFilter
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -45,7 +45,7 @@
@RunWith(Parameterized::class)
class SendClickTest(private val config: TestConfig) {
data class TestConfig(
- val position: PxPosition?,
+ val position: Offset?,
val activityClass: Class<out ComponentActivity>
)
@@ -59,8 +59,8 @@
return mutableListOf<TestConfig>().apply {
for (x in listOf(0.0f, squareSize - 1.0f)) {
for (y in listOf(0.0f, squareSize - 1.0f)) {
- add(TestConfig(PxPosition(x, y), ComponentActivity::class.java))
- add(TestConfig(PxPosition(x, y), ActivityWithActionBar::class.java))
+ add(TestConfig(Offset(x, y), ComponentActivity::class.java))
+ add(TestConfig(Offset(x, y), ActivityWithActionBar::class.java))
}
}
add(TestConfig(null, ComponentActivity::class.java))
@@ -71,7 +71,7 @@
private data class ClickData(
val componentIndex: Int,
- val position: PxPosition
+ val position: Offset
)
private class ClickRecorder(
@@ -95,7 +95,7 @@
private val recordedClicks = mutableListOf<ClickData>()
private val expectedClickPosition =
- config.position ?: PxPosition(squareSize / 2, squareSize / 2)
+ config.position ?: Offset(squareSize / 2, squareSize / 2)
@Test
fun testClick() {
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendDoubleClickTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendDoubleClickTest.kt
index 4531879..fff7ddc 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendDoubleClickTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendDoubleClickTest.kt
@@ -28,7 +28,7 @@
import androidx.ui.test.util.ClickableTestBox
import androidx.ui.test.util.ClickableTestBox.defaultSize
import androidx.ui.test.util.ClickableTestBox.defaultTag
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -39,7 +39,7 @@
@MediumTest
@RunWith(Parameterized::class)
class SendDoubleClickTest(private val config: TestConfig) {
- data class TestConfig(val position: PxPosition?)
+ data class TestConfig(val position: Offset?)
companion object {
@JvmStatic
@@ -48,7 +48,7 @@
return mutableListOf<TestConfig>().apply {
for (x in listOf(1.0f, 33.0f, 99.0f)) {
for (y in listOf(1.0f, 33.0f, 99.0f)) {
- add(TestConfig(PxPosition(x, y)))
+ add(TestConfig(Offset(x, y)))
}
}
add(TestConfig(null))
@@ -64,11 +64,11 @@
disableDispatchInRealTime = true
)
- private val recordedDoubleClicks = mutableListOf<PxPosition>()
+ private val recordedDoubleClicks = mutableListOf<Offset>()
private val expectedClickPosition =
- config.position ?: PxPosition(defaultSize / 2, defaultSize / 2)
+ config.position ?: Offset(defaultSize / 2, defaultSize / 2)
- private fun recordDoubleClick(position: PxPosition) {
+ private fun recordDoubleClick(position: Offset) {
recordedDoubleClicks.add(position)
}
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendLongClickTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendLongClickTest.kt
index 4cb42d1..def81a7 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendLongClickTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendLongClickTest.kt
@@ -31,7 +31,7 @@
import androidx.ui.test.util.ClickableTestBox.defaultSize
import androidx.ui.test.util.ClickableTestBox.defaultTag
import androidx.ui.test.util.isAlmostEqualTo
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -46,7 +46,7 @@
@MediumTest
@RunWith(Parameterized::class)
class SendLongClickTest(private val config: TestConfig) {
- data class TestConfig(val position: PxPosition?)
+ data class TestConfig(val position: Offset?)
companion object {
@JvmStatic
@@ -55,7 +55,7 @@
return mutableListOf<TestConfig>().apply {
for (x in listOf(1.0f, defaultSize / 4)) {
for (y in listOf(1.0f, defaultSize / 3)) {
- add(TestConfig(PxPosition(x, y)))
+ add(TestConfig(Offset(x, y)))
}
}
add(TestConfig(null))
@@ -66,11 +66,11 @@
@get:Rule
val composeTestRule = createComposeRule(disableTransitions = true)
- private val recordedLongClicks = mutableListOf<PxPosition>()
+ private val recordedLongClicks = mutableListOf<Offset>()
private val expectedClickPosition =
- config.position ?: PxPosition(defaultSize / 2, defaultSize / 2)
+ config.position ?: Offset(defaultSize / 2, defaultSize / 2)
- private fun recordLongPress(position: PxPosition) {
+ private fun recordLongPress(position: Offset) {
recordedLongClicks.add(position)
}
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendPinchTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendPinchTest.kt
index 08ad767..8b1a4e0 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendPinchTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendPinchTest.kt
@@ -30,7 +30,7 @@
import androidx.ui.test.util.MultiPointerInputRecorder
import androidx.ui.test.util.assertTimestampsAreIncreasing
import androidx.ui.test.util.isMonotonicBetween
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import androidx.ui.unit.inMilliseconds
import androidx.ui.unit.milliseconds
import com.google.common.truth.Truth.assertThat
@@ -60,10 +60,10 @@
}
}
- val start0 = PxPosition(40f, 50f)
- val end0 = PxPosition(8f, 50f)
- val start1 = PxPosition(60f, 50f)
- val end1 = PxPosition(92f, 50f)
+ val start0 = Offset(40f, 50f)
+ val end0 = Offset(8f, 50f)
+ val start1 = Offset(60f, 50f)
+ val end1 = Offset(92f, 50f)
val duration = 400.milliseconds
findByTag(TAG).doGesture {
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendSwipeVelocityTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendSwipeVelocityTest.kt
index 97d662f..4575b06 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendSwipeVelocityTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/gesturescope/SendSwipeVelocityTest.kt
@@ -37,8 +37,7 @@
import androidx.ui.test.util.isMonotonicBetween
import androidx.ui.test.util.recordedDuration
import androidx.ui.unit.Duration
-import androidx.ui.unit.PxPosition
-import androidx.ui.unit.getDistance
+import androidx.ui.geometry.Offset
import androidx.ui.unit.inMilliseconds
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
@@ -61,11 +60,11 @@
val eventPeriod: Long
)
- enum class Direction(val from: PxPosition, val to: PxPosition) {
- LeftToRight(PxPosition(boxStart, boxMiddle), PxPosition(boxEnd, boxMiddle)),
- RightToLeft(PxPosition(boxEnd, boxMiddle), PxPosition(boxStart, boxMiddle)),
- TopToBottom(PxPosition(boxMiddle, boxStart), PxPosition(boxMiddle, boxEnd)),
- BottomToTop(PxPosition(boxMiddle, boxEnd), PxPosition(boxMiddle, boxStart))
+ enum class Direction(val from: Offset, val to: Offset) {
+ LeftToRight(Offset(boxStart, boxMiddle), Offset(boxEnd, boxMiddle)),
+ RightToLeft(Offset(boxEnd, boxMiddle), Offset(boxStart, boxMiddle)),
+ TopToBottom(Offset(boxMiddle, boxStart), Offset(boxMiddle, boxEnd)),
+ BottomToTop(Offset(boxMiddle, boxEnd), Offset(boxMiddle, boxStart))
}
companion object {
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/Common.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/Common.kt
index 268a078..bcd8bb5 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/Common.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/Common.kt
@@ -16,17 +16,17 @@
package androidx.ui.test.inputdispatcher
+import androidx.ui.geometry.Offset
import androidx.ui.test.InputDispatcher
import androidx.ui.test.android.AndroidInputDispatcher
-import androidx.ui.unit.PxPosition
import com.google.common.truth.Truth.assertThat
-internal fun AndroidInputDispatcher.sendDownAndCheck(pointerId: Int, position: PxPosition) {
+internal fun AndroidInputDispatcher.sendDownAndCheck(pointerId: Int, position: Offset) {
sendDown(pointerId, position)
assertThat(getCurrentPosition(pointerId)).isEqualTo(position)
}
-internal fun AndroidInputDispatcher.movePointerAndCheck(pointerId: Int, position: PxPosition) {
+internal fun AndroidInputDispatcher.movePointerAndCheck(pointerId: Int, position: Offset) {
movePointer(pointerId, position)
assertThat(getCurrentPosition(pointerId)).isEqualTo(position)
}
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/DelayTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/DelayTest.kt
index b6bc3ae..7319164 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/DelayTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/DelayTest.kt
@@ -23,7 +23,7 @@
import androidx.ui.test.android.AndroidInputDispatcher
import androidx.ui.test.util.MotionEventRecorder
import androidx.ui.unit.Duration
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import androidx.ui.unit.inMilliseconds
import androidx.ui.unit.milliseconds
import com.google.common.truth.Truth.assertThat
@@ -55,7 +55,7 @@
}
companion object {
- private val anyPosition = PxPosition.Origin
+ private val anyPosition = Offset.Zero
@JvmStatic
@Parameterized.Parameters(name = "{0}")
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendCancelTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendCancelTest.kt
index 5a7bc27..c7a6aba 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendCancelTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendCancelTest.kt
@@ -20,13 +20,13 @@
import android.view.MotionEvent.ACTION_DOWN
import android.view.MotionEvent.ACTION_POINTER_DOWN
import androidx.test.filters.SmallTest
+import androidx.ui.geometry.Offset
import androidx.ui.test.android.AndroidInputDispatcher
import androidx.ui.test.util.MotionEventRecorder
import androidx.ui.test.util.assertHasValidEventTimes
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verifyEvent
import androidx.ui.test.util.verifyPointer
-import androidx.ui.unit.PxPosition
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Rule
@@ -44,8 +44,8 @@
private const val pointer2 = 22
// positions (used with corresponding pointerId: pointerX with positionX_Y)
- private val position1_1 = PxPosition(11f, 11f)
- private val position2_1 = PxPosition(21f, 21f)
+ private val position1_1 = Offset(11f, 11f)
+ private val position2_1 = Offset(21f, 21f)
}
private val dispatcherRule = AndroidInputDispatcher.TestRule(disableDispatchInRealTime = true)
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendClickTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendClickTest.kt
index ca02532..7b876bf 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendClickTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendClickTest.kt
@@ -22,7 +22,7 @@
import androidx.ui.test.util.MotionEventRecorder
import androidx.ui.test.util.assertHasValidEventTimes
import androidx.ui.test.util.verify
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Rule
@@ -60,7 +60,7 @@
@get:Rule
val inputDispatcherRule: TestRule = dispatcherRule
- private val position = PxPosition(config.x, config.y)
+ private val position = Offset(config.x, config.y)
private val recorder = MotionEventRecorder()
private val subject = AndroidInputDispatcher(recorder::recordEvent)
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendDownTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendDownTest.kt
index 9158540..81b0ea2 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendDownTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendDownTest.kt
@@ -21,13 +21,13 @@
import android.view.MotionEvent.ACTION_POINTER_DOWN
import android.view.MotionEvent.ACTION_POINTER_UP
import androidx.test.filters.SmallTest
+import androidx.ui.geometry.Offset
import androidx.ui.test.android.AndroidInputDispatcher
import androidx.ui.test.util.MotionEventRecorder
import androidx.ui.test.util.assertHasValidEventTimes
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verifyEvent
import androidx.ui.test.util.verifyPointer
-import androidx.ui.unit.PxPosition
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Rule
@@ -47,13 +47,13 @@
private const val pointer4 = 44
// Positions (mostly used with corresponding pointerId: pointerX with positionX)
- private val position1 = PxPosition(1f, 1f)
- private val position2 = PxPosition(2f, 2f)
- private val position3 = PxPosition(3f, 3f)
- private val position4 = PxPosition(4f, 4f)
+ private val position1 = Offset(1f, 1f)
+ private val position2 = Offset(2f, 2f)
+ private val position3 = Offset(3f, 3f)
+ private val position4 = Offset(4f, 4f)
// Single alternative for pointer1
- private val position1_2 = PxPosition(12f, 12f)
+ private val position1_2 = Offset(12f, 12f)
}
private val dispatcherRule = AndroidInputDispatcher.TestRule(disableDispatchInRealTime = true)
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendMoveTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendMoveTest.kt
index e4a9484..c3c573f 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendMoveTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendMoveTest.kt
@@ -28,7 +28,7 @@
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verifyEvent
import androidx.ui.test.util.verifyPointer
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Rule
@@ -47,14 +47,14 @@
private const val pointer3 = 33
// positions (used with corresponding pointerId: pointerX with positionX_Y)
- private val position1_1 = PxPosition(11f, 11f)
- private val position2_1 = PxPosition(21f, 21f)
- private val position3_1 = PxPosition(31f, 31f)
+ private val position1_1 = Offset(11f, 11f)
+ private val position2_1 = Offset(21f, 21f)
+ private val position3_1 = Offset(31f, 31f)
- private val position1_2 = PxPosition(12f, 12f)
- private val position2_2 = PxPosition(22f, 22f)
+ private val position1_2 = Offset(12f, 12f)
+ private val position2_2 = Offset(22f, 22f)
- private val position1_3 = PxPosition(13f, 13f)
+ private val position1_3 = Offset(13f, 13f)
}
private val dispatcherRule = AndroidInputDispatcher.TestRule(disableDispatchInRealTime = true)
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeLineTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeLineTest.kt
index ffd3ead..f7b4ead 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeLineTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeLineTest.kt
@@ -25,8 +25,8 @@
import androidx.ui.test.util.moveEvents
import androidx.ui.test.util.splitsDurationEquallyInto
import androidx.ui.test.util.verify
-import androidx.ui.unit.PxPosition
import androidx.ui.unit.milliseconds
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Rule
@@ -49,8 +49,8 @@
)
companion object {
- private val start = PxPosition(5f, 7f)
- private val end = PxPosition(23f, 29f)
+ private val start = Offset(5f, 7f)
+ private val end = Offset(23f, 29f)
@JvmStatic
@Parameterized.Parameters(name = "{0}")
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithDurationTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithDurationTest.kt
index a3441dc..b69b16a 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithDurationTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithDurationTest.kt
@@ -20,12 +20,12 @@
import android.view.MotionEvent.ACTION_MOVE
import android.view.MotionEvent.ACTION_UP
import androidx.test.filters.SmallTest
+import androidx.ui.geometry.Offset
import androidx.ui.test.android.AndroidInputDispatcher
import androidx.ui.test.util.MotionEventRecorder
import androidx.ui.test.util.assertHasValidEventTimes
import androidx.ui.test.util.verify
import androidx.ui.unit.Duration
-import androidx.ui.unit.PxPosition
import androidx.ui.unit.inMilliseconds
import androidx.ui.unit.milliseconds
import com.google.common.truth.Truth.assertThat
@@ -53,7 +53,7 @@
companion object {
private val curve = { t: Long ->
- PxPosition(t.toFloat(), (-t).toFloat())
+ Offset(t.toFloat(), (-t).toFloat())
}
@JvmStatic
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesAndEventPeriodTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesAndEventPeriodTest.kt
index 8e7d131..3b2432c 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesAndEventPeriodTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesAndEventPeriodTest.kt
@@ -19,6 +19,7 @@
import android.view.MotionEvent.ACTION_DOWN
import android.view.MotionEvent.ACTION_UP
import androidx.test.filters.SmallTest
+import androidx.ui.geometry.Offset
import androidx.ui.test.android.AndroidInputDispatcher
import androidx.ui.test.util.MotionEventRecorder
import androidx.ui.test.util.assertHasValidEventTimes
@@ -29,7 +30,6 @@
import androidx.ui.test.util.splitsDurationEquallyInto
import androidx.ui.test.util.verify
import androidx.ui.unit.Duration
-import androidx.ui.unit.PxPosition
import androidx.ui.unit.inMilliseconds
import com.google.common.truth.Truth.assertThat
import org.junit.After
@@ -65,7 +65,7 @@
companion object {
private val curve = { t: Long ->
- PxPosition(t.toFloat(), (-t).toFloat())
+ Offset(t.toFloat(), (-t).toFloat())
}
@JvmStatic
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesTest.kt
index 15646c9..13379bc 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendSwipeWithKeyTimesTest.kt
@@ -25,7 +25,6 @@
import androidx.ui.test.util.assertHasValidEventTimes
import androidx.ui.test.util.verify
import androidx.ui.unit.Duration
-import androidx.ui.unit.PxPosition
import androidx.ui.unit.inMilliseconds
import androidx.ui.unit.milliseconds
import com.google.common.truth.Truth.assertThat
@@ -55,7 +54,7 @@
companion object {
private val curve = { t: Long ->
- PxPosition(t.toFloat(), (-t).toFloat())
+ androidx.ui.geometry.Offset(t.toFloat(), (-t).toFloat())
}
@JvmStatic
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendUpTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendUpTest.kt
index ad3bd69..95f1e95 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendUpTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/inputdispatcher/SendUpTest.kt
@@ -27,7 +27,7 @@
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verifyEvent
import androidx.ui.test.util.verifyPointer
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Rule
@@ -45,8 +45,8 @@
private const val pointer2 = 22
// positions (used with corresponding pointerId: pointerX with positionX_Y)
- private val position1_1 = PxPosition(11f, 11f)
- private val position2_1 = PxPosition(21f, 21f)
+ private val position1_1 = Offset(11f, 11f)
+ private val position2_1 = Offset(21f, 21f)
}
@get:Rule
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendCancelTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendCancelTest.kt
index 25fe407..40c0df0 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendCancelTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendCancelTest.kt
@@ -29,7 +29,7 @@
import androidx.ui.test.util.MultiPointerInputRecorder
import androidx.ui.test.util.assertTimestampsAreIncreasing
import androidx.ui.test.util.expectError
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
@@ -42,8 +42,8 @@
@MediumTest
class SendCancelTest {
companion object {
- private val downPosition1 = PxPosition(10f, 10f)
- private val downPosition2 = PxPosition(20f, 20f)
+ private val downPosition1 = Offset(10f, 10f)
+ private val downPosition2 = Offset(20f, 20f)
}
@get:Rule
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendDownTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendDownTest.kt
index b4aa5d1..3ae7a1b 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendDownTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendDownTest.kt
@@ -28,7 +28,7 @@
import androidx.ui.test.util.assertTimestampsAreIncreasing
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verify
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
@@ -41,8 +41,8 @@
@MediumTest
class SendDownTest {
companion object {
- private val position1 = PxPosition(5f, 5f)
- private val position2 = PxPosition(7f, 7f)
+ private val position1 = Offset(5f, 5f)
+ private val position2 = Offset(7f, 7f)
}
@get:Rule
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveByTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveByTest.kt
index 32bf84b..20894e8 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveByTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveByTest.kt
@@ -33,7 +33,7 @@
import androidx.ui.test.util.assertTimestampsAreIncreasing
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verify
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import androidx.ui.unit.milliseconds
import com.google.common.truth.Truth.assertThat
import org.junit.Before
@@ -47,10 +47,10 @@
@MediumTest
class SendMoveByTest {
companion object {
- private val downPosition1 = PxPosition(10f, 10f)
- private val downPosition2 = PxPosition(20f, 20f)
- private val delta1 = PxPosition(11f, 11f)
- private val delta2 = PxPosition(21f, 21f)
+ private val downPosition1 = Offset(10f, 10f)
+ private val downPosition2 = Offset(20f, 20f)
+ private val delta1 = Offset(11f, 11f)
+ private val delta2 = Offset(21f, 21f)
}
@get:Rule
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveTest.kt
index 8c3fb88..4d7b032 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveTest.kt
@@ -26,7 +26,7 @@
import androidx.ui.test.sendUp
import androidx.ui.test.util.ClickableTestBox
import androidx.ui.test.util.expectError
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -38,7 +38,7 @@
@MediumTest
class SendMoveTest() {
companion object {
- private val downPosition1 = PxPosition(10f, 10f)
+ private val downPosition1 = Offset(10f, 10f)
}
@get:Rule
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveToTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveToTest.kt
index 91baaca..c71d822 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveToTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendMoveToTest.kt
@@ -33,7 +33,7 @@
import androidx.ui.test.util.assertTimestampsAreIncreasing
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verify
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import androidx.ui.unit.milliseconds
import com.google.common.truth.Truth.assertThat
import org.junit.Before
@@ -47,10 +47,10 @@
@MediumTest
class SendMoveToTest() {
companion object {
- private val downPosition1 = PxPosition(10f, 10f)
- private val downPosition2 = PxPosition(20f, 20f)
- private val moveToPosition1 = PxPosition(11f, 11f)
- private val moveToPosition2 = PxPosition(21f, 21f)
+ private val downPosition1 = Offset(10f, 10f)
+ private val downPosition2 = Offset(20f, 20f)
+ private val moveToPosition1 = Offset(11f, 11f)
+ private val moveToPosition2 = Offset(21f, 21f)
}
@get:Rule
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendUpTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendUpTest.kt
index dc99005..38cdceb 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendUpTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/partialgesturescope/SendUpTest.kt
@@ -31,7 +31,7 @@
import androidx.ui.test.util.assertTimestampsAreIncreasing
import androidx.ui.test.util.expectError
import androidx.ui.test.util.verify
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
@@ -44,8 +44,8 @@
@MediumTest
class SendUpTest {
companion object {
- private val downPosition1 = PxPosition(10f, 10f)
- private val downPosition2 = PxPosition(20f, 20f)
+ private val downPosition1 = Offset(10f, 10f)
+ private val downPosition2 = Offset(20f, 20f)
}
@get:Rule
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/util/MotionEvents.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/util/MotionEvents.kt
index 3764a54..8a47c046 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/util/MotionEvents.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/util/MotionEvents.kt
@@ -17,7 +17,7 @@
package androidx.ui.test.util
import android.view.MotionEvent
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.truth.Truth.assertThat
import kotlin.math.abs
@@ -54,7 +54,7 @@
}
internal fun MotionEvent.verify(
- curve: (Long) -> PxPosition,
+ curve: (Long) -> Offset,
expectedAction: Int,
expectedRelativeTime: Long
) {
@@ -65,7 +65,7 @@
}
internal fun MotionEvent.verify(
- expectedPosition: PxPosition,
+ expectedPosition: Offset,
expectedAction: Int,
expectedRelativeTime: Long
) {
@@ -87,7 +87,7 @@
internal fun MotionEvent.verifyPointer(
expectedPointerId: Int,
- expectedPosition: PxPosition
+ expectedPosition: Offset
) {
var index = -1
for (i in 0 until pointerCount) {
@@ -111,7 +111,7 @@
/**
* Checks that the coordinates are progressing in a monotonous direction
*/
-fun List<MotionEvent>.isMonotonicBetween(start: PxPosition, end: PxPosition) {
+fun List<MotionEvent>.isMonotonicBetween(start: Offset, end: Offset) {
map { it.x }.isMonotonicBetween(start.x, end.x, 1e-6f)
map { it.y }.isMonotonicBetween(start.y, end.y, 1e-6f)
}
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/util/PointerInputs.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/util/PointerInputs.kt
index 2837bf5..52acf8b 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/util/PointerInputs.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/util/PointerInputs.kt
@@ -23,9 +23,9 @@
import androidx.ui.core.gesture.util.VelocityTracker
import androidx.ui.core.pointerinput.PointerInputFilter
import androidx.ui.core.pointerinput.PointerInputModifier
+import androidx.ui.geometry.Offset
import androidx.ui.unit.Duration
import androidx.ui.unit.IntPxSize
-import androidx.ui.unit.PxPosition
import androidx.ui.unit.Uptime
import com.google.common.truth.Truth.assertThat
@@ -125,7 +125,7 @@
expectedTimestamp: Uptime?,
expectedId: PointerId?,
expectedDown: Boolean,
- expectedPosition: PxPosition
+ expectedPosition: Offset
) {
if (expectedTimestamp != null) {
assertThat(timestamp).isEqualTo(expectedTimestamp)
@@ -140,7 +140,7 @@
/**
* Checks that the coordinates are progressing in a monotonous direction
*/
-fun List<DataPoint>.isMonotonicBetween(start: PxPosition, end: PxPosition) {
+fun List<DataPoint>.isMonotonicBetween(start: Offset, end: Offset) {
map { it.x }.isMonotonicBetween(start.x, end.x, 1e-3f)
map { it.y }.isMonotonicBetween(start.y, end.y, 1e-3f)
}
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/util/Truth.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/util/Truth.kt
index ab6d5b3..1cc2dea 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/util/Truth.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/util/Truth.kt
@@ -16,7 +16,7 @@
package androidx.ui.test.util
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import com.google.common.collect.Ordering
import com.google.common.truth.FloatSubject
import com.google.common.truth.Truth.assertThat
@@ -31,10 +31,10 @@
}
/**
- * Verifies that the [PxPosition] is equal to the given position with some tolerance. The default
+ * Verifies that the [Offset] is equal to the given position with some tolerance. The default
* tolerance is 0.001.
*/
-fun PxPosition.isAlmostEqualTo(position: PxPosition, tolerance: Float = 1e-3f) {
+fun Offset.isAlmostEqualTo(position: Offset, tolerance: Float = 1e-3f) {
assertThat(x).isAlmostEqualTo(position.x, tolerance)
assertThat(y).isAlmostEqualTo(position.y, tolerance)
}
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt b/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt
index 1f1ceb8..b3a4257 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt
@@ -20,7 +20,7 @@
import androidx.ui.semantics.AccessibilityAction
import androidx.ui.semantics.SemanticsActions
import androidx.ui.semantics.SemanticsPropertyKey
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
/**
* Performs a click action on the given component.
@@ -66,7 +66,7 @@
"No Layout Node found!"
)
- val position = layoutNode.coordinates.localToGlobal(PxPosition(0.0f, 0.0f))
+ val position = layoutNode.coordinates.localToGlobal(Offset(0.0f, 0.0f))
runOnUiThread {
scrollableSemanticsNode.config[SemanticsActions.ScrollTo].action(
@@ -113,7 +113,7 @@
*
* Example usage:
* ```
- * val position = PxPosition(10.px, 10.px)
+ * val position = Offset(10f, 10f)
* findByTag("myWidget")
* .doPartialGesture { sendDown(position) }
* .assertHasClickAction()
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/BitmapHelpers.kt b/ui/ui-test/src/main/java/androidx/ui/test/BitmapHelpers.kt
index 8d65ad2..2cd3a56 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/BitmapHelpers.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/BitmapHelpers.kt
@@ -129,10 +129,10 @@
fun Path.contains(offset: Offset): Boolean {
val path = android.graphics.Path()
path.addRect(
- offset.dx - 0.01f,
- offset.dy - 0.01f,
- offset.dx + 0.01f,
- offset.dy + 0.01f,
+ offset.x - 0.01f,
+ offset.y - 0.01f,
+ offset.x + 0.01f,
+ offset.y + 0.01f,
android.graphics.Path.Direction.CW
)
if (path.op(asAndroidPath(), android.graphics.Path.Op.INTERSECT)) {
@@ -281,14 +281,14 @@
val centerY = shapeSizeY / 2f
val d = delta
val x = when {
- offset.dx > centerX -> offset.dx - d
- offset.dx < centerX -> offset.dx + d
- else -> offset.dx
+ offset.x > centerX -> offset.x - d
+ offset.x < centerX -> offset.x + d
+ else -> offset.x
}
val y = when {
- offset.dy > centerY -> offset.dy - d
- offset.dy < centerY -> offset.dy + d
- else -> offset.dy
+ offset.y > centerY -> offset.y - d
+ offset.y < centerY -> offset.y + d
+ else -> offset.y
}
return Offset(x, y)
}
@@ -303,14 +303,14 @@
val centerY = shapeSizeY / 2f
val d = delta
val x = when {
- offset.dx > centerX -> offset.dx + d
- offset.dx < centerX -> offset.dx - d
- else -> offset.dx
+ offset.x > centerX -> offset.x + d
+ offset.x < centerX -> offset.x - d
+ else -> offset.x
}
val y = when {
- offset.dy > centerY -> offset.dy + d
- offset.dy < centerY -> offset.dy - d
- else -> offset.dy
+ offset.y > centerY -> offset.y + d
+ offset.y < centerY -> offset.y - d
+ else -> offset.y
}
return Offset(x, y)
}
\ No newline at end of file
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt b/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt
index 152f7d9..e62f3f8 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt
@@ -22,7 +22,8 @@
import androidx.ui.unit.Duration
import androidx.ui.unit.IntPxSize
import androidx.ui.unit.PxBounds
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
+import androidx.ui.geometry.lerp
import androidx.ui.unit.inMilliseconds
import androidx.ui.unit.milliseconds
import androidx.ui.util.lerp
@@ -80,9 +81,9 @@
* Returns the center of the component we're interacting with, in the component's local
* coordinate system, where (0.px, 0.px) is the top left corner of the component.
*/
-val BaseGestureScope.center: PxPosition
+val BaseGestureScope.center: Offset
get() {
- return PxPosition(size.width / 2, size.height / 2)
+ return Offset(size.width.value / 2f, size.height.value / 2f)
}
/**
@@ -96,9 +97,9 @@
*
* @param position A position in local coordinates
*/
-fun BaseGestureScope.localToGlobal(position: PxPosition): PxPosition {
+fun BaseGestureScope.localToGlobal(position: Offset): Offset {
val bounds = globalBounds
- return position + PxPosition(bounds.left, bounds.top)
+ return position + Offset(bounds.left, bounds.top)
}
/**
@@ -130,7 +131,7 @@
* @param position The position where to click, in the component's local coordinate system. If
* omitted, the center position will be used.
*/
-fun GestureScope.sendClick(position: PxPosition = center) {
+fun GestureScope.sendClick(position: Offset = center) {
inputDispatcher.sendClick(localToGlobal(position))
}
@@ -145,7 +146,7 @@
* @param position The position of the long click, in the component's local coordinate system. If
* omitted, the center position will be used.
*/
-fun GestureScope.sendLongClick(position: PxPosition = center) {
+fun GestureScope.sendLongClick(position: Offset = center) {
// Keep down for 100ms more than needed, to allow the long press logic to trigger
sendSwipe(position, position, LongPressTimeout + 100.milliseconds)
}
@@ -160,7 +161,7 @@
* @param position The position of the double click, in the component's local coordinate system.
* If omitted, the center position will be used.
*/
-fun GestureScope.sendDoubleClick(position: PxPosition = center) {
+fun GestureScope.sendDoubleClick(position: Offset = center) {
val globalPosition = localToGlobal(position)
inputDispatcher.sendClick(globalPosition)
inputDispatcher.delay(doubleClickDelay)
@@ -180,8 +181,8 @@
* @param duration The duration of the gesture
*/
fun GestureScope.sendSwipe(
- start: PxPosition,
- end: PxPosition,
+ start: Offset,
+ end: Offset,
duration: Duration = 200.milliseconds
) {
val globalStart = localToGlobal(start)
@@ -192,7 +193,7 @@
/**
* Performs a pinch gesture on the associated component.
*
- * For each pair of start and end [PxPosition]s, the motion events are linearly interpolated. The
+ * For each pair of start and end [Offset]s, the motion events are linearly interpolated. The
* coordinates are in the component's local coordinate system where (0.px, 0.px) is the top left
* corner of the component. The default duration is 400 milliseconds.
*
@@ -203,10 +204,10 @@
* @param duration the duration of the gesture
*/
fun GestureScope.sendPinch(
- start0: PxPosition,
- end0: PxPosition,
- start1: PxPosition,
- end1: PxPosition,
+ start0: Offset,
+ end0: Offset,
+ start1: Offset,
+ end1: Offset,
duration: Duration = 400.milliseconds
) {
val globalStart0 = localToGlobal(start0)
@@ -216,9 +217,9 @@
val durationFloat = duration.inMilliseconds().toFloat()
inputDispatcher.sendSwipes(
- listOf<(Long) -> PxPosition>(
- { androidx.ui.unit.lerp(globalStart0, globalEnd0, it / durationFloat) },
- { androidx.ui.unit.lerp(globalStart1, globalEnd1, it / durationFloat) }
+ listOf<(Long) -> Offset>(
+ { lerp(globalStart0, globalEnd0, it / durationFloat) },
+ { lerp(globalStart1, globalEnd1, it / durationFloat) }
),
duration
)
@@ -243,8 +244,8 @@
* are generated, which happens with a duration of 25ms or more.
*/
fun GestureScope.sendSwipeWithVelocity(
- start: PxPosition,
- end: PxPosition,
+ start: Offset,
+ end: Offset,
@FloatRange(from = 0.0) endVelocity: Float,
duration: Duration = 200.milliseconds
) {
@@ -280,7 +281,7 @@
val fx = createFunctionForVelocity(durationMs, globalStart.x, globalEnd.x, vx)
val fy = createFunctionForVelocity(durationMs, globalStart.y, globalEnd.y, vy)
- inputDispatcher.sendSwipe({ t -> PxPosition(fx(t), fy(t)) }, duration)
+ inputDispatcher.sendSwipe({ t -> Offset(fx(t), fy(t)) }, duration)
}
/**
@@ -293,8 +294,8 @@
val x = center.x
val y0 = (size.height * (1 - edgeFuzzFactor)).value.toFloat()
val y1 = 0.0f
- val start = PxPosition(x, y0)
- val end = PxPosition(x, y1)
+ val start = Offset(x, y0)
+ val end = Offset(x, y1)
sendSwipe(start, end, 200.milliseconds)
}
@@ -308,8 +309,8 @@
val x = center.x
val y0 = (size.height * edgeFuzzFactor).value.toFloat()
val y1 = size.height.value.toFloat()
- val start = PxPosition(x, y0)
- val end = PxPosition(x, y1)
+ val start = Offset(x, y0)
+ val end = Offset(x, y1)
sendSwipe(start, end, 200.milliseconds)
}
@@ -323,8 +324,8 @@
val x0 = (size.width * (1 - edgeFuzzFactor)).value.toFloat()
val x1 = 0.0f
val y = center.y
- val start = PxPosition(x0, y)
- val end = PxPosition(x1, y)
+ val start = Offset(x0, y)
+ val end = Offset(x1, y)
sendSwipe(start, end, 200.milliseconds)
}
@@ -338,8 +339,8 @@
val x0 = (size.width * edgeFuzzFactor).value.toFloat()
val x1 = size.width.value.toFloat()
val y = center.y
- val start = PxPosition(x0, y)
- val end = PxPosition(x1, y)
+ val start = Offset(x0, y)
+ val end = Offset(x1, y)
sendSwipe(start, end, 200.milliseconds)
}
@@ -413,7 +414,7 @@
*
* Example usage:
* ```
- * val position = PxPosition(10.px, 10.px)
+ * val position = Offset(10.px, 10.px)
* findByTag("myWidget")
* .doPartialGesture { sendDown(position) }
* .assertIsDisplayed()
@@ -459,7 +460,7 @@
* @param pointerId The id of the pointer, can be any number not yet in use by another pointer
* @param position The position of the down event, in the component's local coordinate system
*/
-fun PartialGestureScope.sendDown(pointerId: Int, position: PxPosition) {
+fun PartialGestureScope.sendDown(pointerId: Int, position: Offset) {
val globalPosition = localToGlobal(position)
inputDispatcher.sendDown(pointerId, globalPosition)
}
@@ -475,7 +476,7 @@
*
* @param position The position of the down event, in the component's local coordinate system
*/
-fun PartialGestureScope.sendDown(position: PxPosition) {
+fun PartialGestureScope.sendDown(position: Offset) {
sendDown(0, position)
}
@@ -489,7 +490,7 @@
* @param pointerId The id of the pointer to move, as supplied in [sendDown]
* @param position The new position of the pointer, in the component's local coordinate system
*/
-fun PartialGestureScope.sendMoveTo(pointerId: Int, position: PxPosition) {
+fun PartialGestureScope.sendMoveTo(pointerId: Int, position: Offset) {
movePointerTo(pointerId, position)
sendMove()
}
@@ -503,7 +504,7 @@
*
* @param position The new position of the pointer, in the component's local coordinate system
*/
-fun PartialGestureScope.sendMoveTo(position: PxPosition) {
+fun PartialGestureScope.sendMoveTo(position: Offset) {
sendMoveTo(0, position)
}
@@ -518,7 +519,7 @@
* @param pointerId The id of the pointer to move, as supplied in [sendDown]
* @param position The new position of the pointer, in the component's local coordinate system
*/
-fun PartialGestureScope.movePointerTo(pointerId: Int, position: PxPosition) {
+fun PartialGestureScope.movePointerTo(pointerId: Int, position: Offset) {
val globalPosition = localToGlobal(position)
inputDispatcher.movePointer(pointerId, globalPosition)
}
@@ -531,10 +532,10 @@
*
* @param pointerId The id of the pointer to move, as supplied in [sendDown]
* @param delta The position for this move event, relative to the last sent position of the
- * pointer. For example, `delta = PxPosition(10.px, -10.px) will add 10.px to the pointer's last
+ * pointer. For example, `delta = Offset(10.px, -10.px) will add 10.px to the pointer's last
* x-position, and subtract 10.px from the pointer's last y-position.
*/
-fun PartialGestureScope.sendMoveBy(pointerId: Int, delta: PxPosition) {
+fun PartialGestureScope.sendMoveBy(pointerId: Int, delta: Offset) {
movePointerBy(pointerId, delta)
sendMove()
}
@@ -546,10 +547,10 @@
* If the pointer is not yet down, an [IllegalArgumentException] will be thrown.
*
* @param delta The position for this move event, relative to the last sent position of the
- * pointer. For example, `delta = PxPosition(10.px, -10.px) will add 10.px to the pointer's last
+ * pointer. For example, `delta = Offset(10.px, -10.px) will add 10.px to the pointer's last
* x-position, and subtract 10.px from the pointer's last y-position.
*/
-fun PartialGestureScope.sendMoveBy(delta: PxPosition) {
+fun PartialGestureScope.sendMoveBy(delta: Offset) {
sendMoveBy(0, delta)
}
@@ -561,13 +562,13 @@
*
* @param pointerId The id of the pointer to move, as supplied in [sendDown]
* @param delta The position for this move event, relative to the last sent position of the
- * pointer. For example, `delta = PxPosition(10.px, -10.px) will add 10.px to the pointer's last
+ * pointer. For example, `delta = Offset(10.px, -10.px) will add 10.px to the pointer's last
* x-position, and subtract 10.px from the pointer's last y-position.
*/
-fun PartialGestureScope.movePointerBy(pointerId: Int, delta: PxPosition) {
+fun PartialGestureScope.movePointerBy(pointerId: Int, delta: Offset) {
// Ignore currentPosition of null here, let movePointer generate the error
val globalPosition =
- (inputDispatcher.getCurrentPosition(pointerId) ?: PxPosition.Origin) + delta
+ (inputDispatcher.getCurrentPosition(pointerId) ?: Offset.Zero) + delta
inputDispatcher.movePointer(pointerId, globalPosition)
}
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/InputDispatcher.kt b/ui/ui-test/src/main/java/androidx/ui/test/InputDispatcher.kt
index 9b7606c..b0ce05a 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/InputDispatcher.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/InputDispatcher.kt
@@ -22,7 +22,8 @@
import androidx.ui.test.android.AndroidInputDispatcher
import androidx.ui.test.android.AndroidOwnerRegistry
import androidx.ui.unit.Duration
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
+import androidx.ui.geometry.lerp
import androidx.ui.unit.inMilliseconds
import androidx.ui.unit.lerp
import java.util.WeakHashMap
@@ -86,7 +87,7 @@
*
* @param position The coordinate of the click
*/
- fun sendClick(position: PxPosition) {
+ fun sendClick(position: Offset) {
sendDown(0, position)
sendMove()
sendUp(0)
@@ -100,7 +101,7 @@
* @param end The end position of the gesture
* @param duration The duration of the gesture
*/
- fun sendSwipe(start: PxPosition, end: PxPosition, duration: Duration) {
+ fun sendSwipe(start: Offset, end: Offset, duration: Duration) {
val durationFloat = duration.inMilliseconds().toFloat()
sendSwipe(
curve = { lerp(start, end, it / durationFloat) },
@@ -120,7 +121,7 @@
* be sampled
*/
fun sendSwipe(
- curve: (Long) -> PxPosition,
+ curve: (Long) -> Offset,
duration: Duration,
keyTimes: List<Long> = emptyList()
) {
@@ -140,7 +141,7 @@
* be sampled
*/
fun sendSwipes(
- curves: List<(Long) -> PxPosition>,
+ curves: List<(Long) -> Offset>,
duration: Duration,
keyTimes: List<Long> = emptyList()
)
@@ -167,7 +168,7 @@
* @return The current position of the pointer with the given [pointerId], or `null` if the
* pointer is not currently in use
*/
- fun getCurrentPosition(pointerId: Int): PxPosition?
+ fun getCurrentPosition(pointerId: Int): Offset?
/**
* Sends a down event at [position] for the pointer with the given [pointerId], starting a
@@ -202,7 +203,7 @@
* @see sendUp
* @see sendCancel
*/
- fun sendDown(pointerId: Int, position: PxPosition)
+ fun sendDown(pointerId: Int, position: Offset)
/**
* Updates the position of the pointer with the given [pointerId] to the given [position],
@@ -221,7 +222,7 @@
* @see sendUp
* @see sendCancel
*/
- fun movePointer(pointerId: Int, position: PxPosition)
+ fun movePointer(pointerId: Int, position: Offset)
/**
* Sends a move event 10 milliseconds after the previous injected event of this gesture,
@@ -288,8 +289,8 @@
val partialGesture: PartialGesture?
)
-internal class PartialGesture(val downTime: Long, startPosition: PxPosition, pointerId: Int) {
+internal class PartialGesture(val downTime: Long, startPosition: Offset, pointerId: Int) {
var lastEventTime: Long = downTime
- val lastPositions = SparseArrayCompat<PxPosition>().apply { put(pointerId, startPosition) }
+ val lastPositions = SparseArrayCompat<Offset>().apply { put(pointerId, startPosition) }
var hasPointerUpdates: Boolean = false
}
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidInputDispatcher.kt b/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidInputDispatcher.kt
index 42c915a..59de9f6 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidInputDispatcher.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidInputDispatcher.kt
@@ -30,7 +30,7 @@
import androidx.ui.test.InputDispatcherState
import androidx.ui.test.PartialGesture
import androidx.ui.unit.Duration
-import androidx.ui.unit.PxPosition
+import androidx.ui.geometry.Offset
import androidx.ui.unit.inMilliseconds
import androidx.ui.unit.milliseconds
import androidx.ui.util.lerp
@@ -118,11 +118,11 @@
sleepUntil(nextDownTime)
}
- override fun getCurrentPosition(pointerId: Int): PxPosition? {
+ override fun getCurrentPosition(pointerId: Int): Offset? {
return partialGesture?.lastPositions?.get(pointerId)
}
- override fun sendDown(pointerId: Int, position: PxPosition) {
+ override fun sendDown(pointerId: Int, position: Offset) {
var gesture = partialGesture
// Check if this pointer is not already down
@@ -149,7 +149,7 @@
}
// Move 1 pointer and don't send a move event
- override fun movePointer(pointerId: Int, position: PxPosition) {
+ override fun movePointer(pointerId: Int, position: Offset) {
val gesture = partialGesture
// Check if this pointer is in the gesture
@@ -258,7 +258,7 @@
}
override fun sendSwipes(
- curves: List<(Long) -> PxPosition>,
+ curves: List<(Long) -> Offset>,
duration: Duration,
keyTimes: List<Long>
) {
@@ -314,7 +314,7 @@
* @param tN The end time of this segment of the swipe, in milliseconds relative to downTime
*/
private fun sendPartialSwipes(
- fs: List<(Long) -> PxPosition>,
+ fs: List<(Long) -> Offset>,
t0: Long,
tN: Long
) {
@@ -343,7 +343,7 @@
eventTime: Long,
action: Int,
actionIndex: Int,
- coordinates: List<PxPosition>,
+ coordinates: List<Offset>,
pointerIds: List<Int>
) {
sleepUntil(eventTime)