[go: nahoru, domu]

Removal of Px usages part 1 of n

Relnote: "Replaced usage of Px class in various
compose classes as part of the large
refactoring effort to only rely on Dp
and primitive types for pixel parameters"

Bug: 156681014
Test: re-ran compose tests

Change-Id: Iede0b310a8a8f4a39ba6ae4a99c753f7f590d8ed
diff --git a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerBasedShapeTest.kt b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerBasedShapeTest.kt
index cac90d8..bb48fb2 100644
--- a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerBasedShapeTest.kt
+++ b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerBasedShapeTest.kt
@@ -20,10 +20,8 @@
 import androidx.ui.geometry.RRect
 import androidx.ui.graphics.Outline
 import androidx.ui.unit.Density
-import androidx.ui.unit.Px
 import androidx.ui.unit.PxSize
 import androidx.ui.unit.dp
-import androidx.ui.unit.px
 import androidx.ui.unit.toRect
 import com.google.common.truth.Truth.assertThat
 import org.junit.Test
@@ -37,23 +35,23 @@
     @Test
     fun createOutlineCalledWithCorrectParams() {
         val density = Density(2f, 1f)
-        val passedSize = PxSize(100.px, 50.px)
+        val passedSize = PxSize(100.0f, 50.0f)
         var assertionExecuted = false
         val assertSizes = { size: PxSize,
-                            topLeft: Px,
-                            topRight: Px,
-                            bottomRight: Px,
-                            bottomLeft: Px ->
+                            topLeft: Float,
+                            topRight: Float,
+                            bottomRight: Float,
+                            bottomLeft: Float ->
             assertThat(size).isEqualTo(passedSize)
-            assertThat(topLeft).isEqualTo(4.px)
-            assertThat(topRight).isEqualTo(3.px)
-            assertThat(bottomRight).isEqualTo(6.px)
-            assertThat(bottomLeft).isEqualTo(25.px)
+            assertThat(topLeft).isEqualTo(4.0f)
+            assertThat(topRight).isEqualTo(3.0f)
+            assertThat(bottomRight).isEqualTo(6.0f)
+            assertThat(bottomLeft).isEqualTo(25.0f)
             assertionExecuted = true
         }
         val impl = Impl(
-            topLeft = CornerSize(4.px),
-            topRight = CornerSize(3.px),
+            topLeft = CornerSize(4.0f),
+            topRight = CornerSize(3.0f),
             bottomRight = CornerSize(3.dp),
             bottomLeft = CornerSize(50),
             >
@@ -68,27 +66,27 @@
     @Test
     fun cornersSizesAreNotLargerThenMinDimension() {
         val density = Density(2f, 1f)
-        val sizeWithLargerWidth = PxSize(6.px, 4.px)
-        val sizeWithLargerHeight = PxSize(4.px, 6.px)
+        val sizeWithLargerWidth = PxSize(6.0f, 4.0f)
+        val sizeWithLargerHeight = PxSize(4.0f, 6.0f)
 
         val sizesList = mutableListOf<PxSize>()
         val assertSizes = { size: PxSize,
-                            topLeft: Px,
-                            topRight: Px,
-                            bottomRight: Px,
-                            bottomLeft: Px ->
+                            topLeft: Float,
+                            topRight: Float,
+                            bottomRight: Float,
+                            bottomLeft: Float ->
             sizesList.add(size)
-            assertThat(topLeft).isEqualTo(2.px)
-            assertThat(topRight).isEqualTo(2.px)
-            assertThat(bottomRight).isEqualTo(1.px)
-            assertThat(bottomLeft).isEqualTo(2.px)
+            assertThat(topLeft).isEqualTo(2.0f)
+            assertThat(topRight).isEqualTo(2.0f)
+            assertThat(bottomRight).isEqualTo(1.0f)
+            assertThat(bottomLeft).isEqualTo(2.0f)
         }
 
         val impl = Impl(
-            topLeft = CornerSize(10.px),
+            topLeft = CornerSize(10.0f),
             topRight = CornerSize(6.dp),
-            bottomRight = CornerSize(1.px),
-            bottomLeft = CornerSize(2.px),
+            bottomRight = CornerSize(1.0f),
+            bottomLeft = CornerSize(2.0f),
             >
         )
 
@@ -103,14 +101,14 @@
         @Suppress("ReplaceCallWithBinaryOperator")
         assertThat(
             Impl2(
-                topLeft = CornerSize(4.px),
-                topRight = CornerSize(3.px),
+                topLeft = CornerSize(4.0f),
+                topRight = CornerSize(3.0f),
                 bottomRight = CornerSize(3.dp),
                 bottomLeft = CornerSize(50)
             ).equals(
                 Impl2(
-                    topLeft = CornerSize(4.px),
-                    topRight = CornerSize(3.px),
+                    topLeft = CornerSize(4.0f),
+                    topRight = CornerSize(3.0f),
                     bottomRight = CornerSize(3.dp),
                     bottomLeft = CornerSize(50)
                 )
@@ -123,14 +121,14 @@
         @Suppress("ReplaceCallWithBinaryOperator")
         assertThat(
             Impl(
-                topLeft = CornerSize(4.px),
-                topRight = CornerSize(3.px),
+                topLeft = CornerSize(4.0f),
+                topRight = CornerSize(3.0f),
                 bottomRight = CornerSize(3.dp),
                 bottomLeft = CornerSize(50)
             ).equals(
                 Impl2(
-                    topLeft = CornerSize(4.px),
-                    topRight = CornerSize(3.px),
+                    topLeft = CornerSize(4.0f),
+                    topRight = CornerSize(3.0f),
                     bottomRight = CornerSize(3.dp),
                     bottomLeft = CornerSize(50)
                 )
@@ -141,8 +139,8 @@
     @Test
     fun copyingUsesCorrectDefaults() {
         val impl = Impl(
-            topLeft = CornerSize(4.px),
-            topRight = CornerSize(3.px),
+            topLeft = CornerSize(4.0f),
+            topRight = CornerSize(3.0f),
             bottomRight = CornerSize(3.dp),
             bottomLeft = CornerSize(50)
         )
@@ -156,15 +154,15 @@
     topRight: CornerSize,
     bottomRight: CornerSize,
     bottomLeft: CornerSize,
-    private val onOutlineRequested: ((PxSize, Px, Px, Px, Px) -> Unit)? = null
+    private val onOutlineRequested: ((PxSize, Float, Float, Float, Float) -> Unit)? = null
 ) : CornerBasedShape(topLeft, topRight, bottomRight, bottomLeft) {
 
     override fun createOutline(
         size: PxSize,
-        topLeft: Px,
-        topRight: Px,
-        bottomRight: Px,
-        bottomLeft: Px
+        topLeft: Float,
+        topRight: Float,
+        bottomRight: Float,
+        bottomLeft: Float
     ): Outline {
         onOutlineRequested?.invoke(size, topLeft, topRight, bottomRight, bottomLeft)
         return Outline.Rectangle(size.toRect())
@@ -187,10 +185,10 @@
 
     override fun createOutline(
         size: PxSize,
-        topLeft: Px,
-        topRight: Px,
-        bottomRight: Px,
-        bottomLeft: Px
+        topLeft: Float,
+        topRight: Float,
+        bottomRight: Float,
+        bottomLeft: Float
     ): Outline {
         return Outline.Rounded(RRect(size.toRect()))
     }
diff --git a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerSizeTest.kt b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerSizeTest.kt
index 637f0d1..f6eea7f 100644
--- a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerSizeTest.kt
+++ b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CornerSizeTest.kt
@@ -35,46 +35,35 @@
 
     @Test
     fun pxCorners() {
-        val corner = CornerSize(24.px)
-        assertThat(corner.toPx(size, density)).isEqualTo(24.px)
+        val corner = CornerSize(24.0f)
+        assertThat(corner.toPx(size, density)).isEqualTo(24.0f)
     }
 
     @Test
     fun dpCorners() {
         val corner = CornerSize(5.dp)
-        assertThat(corner.toPx(size, density)).isEqualTo(12.5.px)
+        assertThat(corner.toPx(size, density)).isEqualTo(12.5f)
     }
 
     @Test
     fun intPercentCorners() {
         val corner = CornerSize(15)
-        assertThat(corner.toPx(size, density)).isEqualTo(22.5.px)
-    }
-
-    @Test
-    fun floatPercentCorners() {
-        val corner = CornerSize(21.6f)
-        assertThat(corner.toPx(PxSize(1000.px, 120.px), density)).isEqualTo(25.92.px)
+        assertThat(corner.toPx(size, density)).isEqualTo(22.5f)
     }
 
     @Test
     fun zeroCorners() {
         val corner = ZeroCornerSize
-        assertThat(corner.toPx(size, density)).isEqualTo(0.px)
+        assertThat(corner.toPx(size, density)).isEqualTo(0.0f)
     }
 
     @Test
     fun pxCornersAreEquals() {
-        assertThat(CornerSize(24.px)).isEqualTo(CornerSize(24.px))
+        assertThat(CornerSize(24.0f)).isEqualTo(CornerSize(24.0f))
     }
 
     @Test
     fun dpCornersAreEquals() {
         assertThat(CornerSize(8.dp)).isEqualTo(CornerSize(8.dp))
     }
-
-    @Test
-    fun percentCornersAreEquals() {
-        assertThat(CornerSize(20f)).isEqualTo(CornerSize(20))
-    }
 }
diff --git a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CutCornerShapeTest.kt b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CutCornerShapeTest.kt
index 2b92be5..a3a034d 100644
--- a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CutCornerShapeTest.kt
+++ b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/CutCornerShapeTest.kt
@@ -41,7 +41,7 @@
 
     @Test
     fun cutCornersUniformCorners() {
-        val cut = CutCornerShape(10.px)
+        val cut = CutCornerShape(10.0f)
 
         val outline = cut.toOutline() as Outline.Generic
         assertPathsEquals(outline.path, Path().apply {
@@ -63,7 +63,7 @@
         val size2 = 22f
         val size3 = 32f
         val size4 = 42f
-        val cut = CutCornerShape(size1.px, size2.px, size3.px, size4.px)
+        val cut = CutCornerShape(size1, size2, size3, size4)
 
         val outline = cut.toOutline() as Outline.Generic
         assertPathsEquals(outline.path, Path().apply {
@@ -81,7 +81,7 @@
 
     @Test
     fun createsRectangleOutlineForZeroSizedCorners() {
-        val rounded = CutCornerShape(0.px, 0.px, 0.px, 0.px)
+        val rounded = CutCornerShape(0.0f, 0.0f, 0.0f, 0.0f)
 
         assertThat(rounded.toOutline())
             .isEqualTo(Outline.Rectangle(size.toRect()))
@@ -89,25 +89,25 @@
 
     @Test
     fun cutCornerShapesAreEquals() {
-        assertThat(CutCornerShape(10.px))
-            .isEqualTo(CutCornerShape(10.px))
+        assertThat(CutCornerShape(10.0f))
+            .isEqualTo(CutCornerShape(10.0f))
     }
 
     @Test
     fun cutCornerUpdateAllCornerSize() {
-        assertThat(CutCornerShape(10.px).copy(CornerSize(5.px)))
-            .isEqualTo(CutCornerShape(5.px))
+        assertThat(CutCornerShape(10.0f).copy(CornerSize(5.0f)))
+            .isEqualTo(CutCornerShape(5.0f))
     }
 
     @Test
     fun cutCornerUpdateTwoCornerSizes() {
-        assertThat(CutCornerShape(10.px).copy(
+        assertThat(CutCornerShape(10.0f).copy(
             topRight = CornerSize(3.dp),
             bottomLeft = CornerSize(50)
         )).isEqualTo(CutCornerShape(
-            topLeft = CornerSize(10.px),
+            topLeft = CornerSize(10.0f),
             topRight = CornerSize(3.dp),
-            bottomRight = CornerSize(10.px),
+            bottomRight = CornerSize(10.0f),
             bottomLeft = CornerSize(50)
         ))
     }
diff --git a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/RoundedCornerShapeTest.kt b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/RoundedCornerShapeTest.kt
index 559b8f5..5195ced 100644
--- a/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/RoundedCornerShapeTest.kt
+++ b/ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/shape/corner/RoundedCornerShapeTest.kt
@@ -27,6 +27,7 @@
 import androidx.ui.unit.px
 import androidx.ui.unit.toRect
 import com.google.common.truth.Truth.assertThat
+import org.junit.Assert.assertEquals
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.junit.runners.JUnit4
@@ -57,7 +58,7 @@
         val radius2 = 22f
         val radius3 = 32f
         val radius4 = 42f
-        val rounded = RoundedCornerShape(radius1.px, radius2.px, radius3.px, radius4.px)
+        val rounded = RoundedCornerShape(radius1, radius2, radius3, radius4)
 
         val outline = rounded.toOutline() as Outline.Rounded
         assertThat(outline.rrect).isEqualTo(
@@ -73,7 +74,7 @@
 
     @Test
     fun createsRectangleOutlineForZeroSizedCorners() {
-        val rounded = RoundedCornerShape(0.px, 0.px, 0.px, 0.px)
+        val rounded = RoundedCornerShape(0.0f, 0.0f, 0.0f, 0.0f)
 
         assertThat(rounded.toOutline())
             .isEqualTo(Outline.Rectangle(size.toRect()))
@@ -87,19 +88,28 @@
 
     @Test
     fun roundedCornerUpdateAllCornerSize() {
-        assertThat(RoundedCornerShape(10.px).copy(CornerSize(5.dp)))
+        assertThat(RoundedCornerShape(10.0f).copy(CornerSize(5.dp)))
             .isEqualTo(RoundedCornerShape(5.dp))
     }
 
     @Test
     fun roundedCornerUpdateTwoCornerSizes() {
-        assertThat(RoundedCornerShape(10.px).copy(
+        val original = RoundedCornerShape(10.0f).copy(
+            topLeft = CornerSize(3.dp),
+            bottomLeft = CornerSize(50)
+        )
+
+        assertEquals(CornerSize(3.dp), original.topLeft)
+        assertEquals(CornerSize(10.0f), original.topRight)
+        assertEquals(CornerSize(10.0f), original.bottomRight)
+        assertEquals(CornerSize(50), original.bottomLeft)
+        assertThat(RoundedCornerShape(10.0f).copy(
             topLeft = CornerSize(3.dp),
             bottomLeft = CornerSize(50)
         )).isEqualTo(RoundedCornerShape(
             topLeft = CornerSize(3.dp),
-            topRight = CornerSize(10.px),
-            bottomRight = CornerSize(10.px),
+            topRight = CornerSize(10.0f),
+            bottomRight = CornerSize(10.0f),
             bottomLeft = CornerSize(50)
         ))
     }