Remove CollectedOwners and restructure bitmap capturing
CollectedOwners was only used for two purposes: retrieving a list of all
SemanticsNodes and getting a reference to an Activity. The Activity
reference was only needed for displayMetrics and a window reference.
Both the displayMetrics and the window reference can be extracted on
demand from a SemanticsNode and doesn't require the CollectedOwners.
The list of all SemanticsNodes is now the only thing left, so
SynchronizedTreeCollector.collectOwners() can now completely bypass the
CollectedOwners and just return the list of SemanticsNodes immediately.
Incidentally, this removes two unnecessary calls to fetch all
SemanticsNodes when capturing a bitmap.
Bug: 155959983
Test: ./gradlew ui:ui-test:cC
Change-Id: I9b66ac72ecef331923e3dd10888ac3e312d8553f
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/Assertions.kt b/ui/ui-test/src/main/java/androidx/ui/test/Assertions.kt
index 077b462..e9dbe65 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/Assertions.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/Assertions.kt
@@ -16,6 +16,7 @@
package androidx.ui.test
+import androidx.ui.core.AndroidOwner
import androidx.ui.core.LayoutNode
import androidx.ui.core.findClosestParentNode
import androidx.ui.core.semantics.SemanticsNode
@@ -23,9 +24,9 @@
import androidx.ui.geometry.Rect
import androidx.ui.semantics.AccessibilityRangeInfo
import androidx.ui.semantics.SemanticsProperties
-import androidx.ui.test.android.SynchronizedTreeCollector
import androidx.ui.unit.PxBounds
import androidx.ui.unit.PxPosition
+import androidx.ui.unit.PxSize
import androidx.ui.unit.height
import androidx.ui.unit.px
import androidx.ui.unit.toPx
@@ -296,30 +297,29 @@
// check node doesn't clip unintentionally (e.g. row too small for content)
val globalRect = node.globalBounds
- if (!isInScreenBounds(globalRect)) {
+ if (!node.isInScreenBounds()) {
return false
}
return (globalRect.width > 0.px && globalRect.height > 0.px)
}
-internal fun isInScreenBounds(rectangle: PxBounds): Boolean {
- if (rectangle.width == 0.px && rectangle.height == 0.px) {
+private fun SemanticsNode.isInScreenBounds(): Boolean {
+ val nodeBounds = globalBounds
+ if (nodeBounds.width == 0.px && nodeBounds.height == 0.px) {
return false
}
- val displayMetrics = SynchronizedTreeCollector.collectOwners()
- .findActivity()
- .resources
- .displayMetrics
- val bottomRight = PxPosition(
- displayMetrics.widthPixels.px,
- displayMetrics.heightPixels.px
+ val displayMetrics = (componentNode.owner as AndroidOwner).view.resources.displayMetrics
+ val screenBounds = PxBounds(
+ PxPosition.Origin,
+ PxSize(displayMetrics.widthPixels.px, displayMetrics.heightPixels.px)
)
- return rectangle.top >= 0.px &&
- rectangle.left >= 0.px &&
- rectangle.right <= bottomRight.x &&
- rectangle.bottom <= bottomRight.y
+
+ return nodeBounds.top >= screenBounds.top &&
+ nodeBounds.left >= screenBounds.left &&
+ nodeBounds.right <= screenBounds.right &&
+ nodeBounds.bottom <= screenBounds.bottom
}
/**