Trying without full path

Change-Id: I5c8941333eef06d8ac93f4b8a13575b2127ddf2c
ben/dropshots
Jose Alcérreca 6 months ago
parent 99faf2e599
commit c28fbac910

@ -297,11 +297,11 @@ jobs:
- name: Download build-tools;35.0.0-rc4 - name: Download build-tools;35.0.0-rc4
run: | run: |
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "build-tools;35.0.0-rc4" sdkmanager --install "build-tools;35.0.0-rc4"
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --list_installed sdkmanager --list_installed
- name: Print debug - name: Print debug
run: $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list run: avdmanager list
- name: Build projects and run instrumented screenshot tests - name: Build projects and run instrumented screenshot tests
id: dropshotsverify id: dropshotsverify

@ -17,7 +17,9 @@
package com.google.samples.apps.nowinandroid.ui package com.google.samples.apps.nowinandroid.ui
import android.graphics.Bitmap import android.graphics.Bitmap
import android.util.Log
import android.view.WindowInsets import android.view.WindowInsets
import androidx.core.view.WindowInsetsCompat
import androidx.test.core.app.takeScreenshot import androidx.test.core.app.takeScreenshot
import androidx.test.espresso.device.DeviceInteraction.Companion.setClosedMode import androidx.test.espresso.device.DeviceInteraction.Companion.setClosedMode
import androidx.test.espresso.device.DeviceInteraction.Companion.setFlatMode import androidx.test.espresso.device.DeviceInteraction.Companion.setFlatMode
@ -33,6 +35,8 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.filters.SdkSuppress import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiDevice
import androidx.window.core.ExperimentalWindowApi
import androidx.window.layout.WindowMetricsCalculator
import com.dropbox.dropshots.Dropshots import com.dropbox.dropshots.Dropshots
import com.google.samples.apps.nowinandroid.MainActivity import com.google.samples.apps.nowinandroid.MainActivity
import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule
@ -51,6 +55,7 @@ import org.junit.rules.TemporaryFolder
* - A foldable on API 33 (pixel_fold) * - A foldable on API 33 (pixel_fold)
* - A foldable on API 35 (pixel_fold) * - A foldable on API 35 (pixel_fold)
*/ */
@OptIn(ExperimentalWindowApi::class)
@HiltAndroidTest @HiltAndroidTest
@InstrumentedScreenshotTests @InstrumentedScreenshotTests
class EdgeToEdgeTest { class EdgeToEdgeTest {
@ -150,11 +155,15 @@ class EdgeToEdgeTest {
var width: Int? = null var width: Int? = null
waitForWindowUpdate() waitForWindowUpdate()
activityScenarioRule.scenario.onActivity { activity -> activityScenarioRule.scenario.onActivity { activity ->
topInset = activity.windowManager.maximumWindowMetrics.windowInsets.getInsets( val metrics = WindowMetricsCalculator.getOrCreate()
WindowInsets.Type.systemBars(), .computeCurrentWindowMetrics(activity)
).top topInset = metrics.getWindowInsets().getInsets(
width = activity.windowManager.maximumWindowMetrics.bounds.width() WindowInsetsCompat.Type.systemBars(),
).bottom
width = metrics.bounds.width()
} }
Log.d("jalc", "width: $width" )
Log.d("jalc", "topInset: $topInset" )
// Crop the top, adding extra pixels to check continuity // Crop the top, adding extra pixels to check continuity
val bitmap = takeScreenshot().let { val bitmap = takeScreenshot().let {
Bitmap.createBitmap(it, 0, 0, width!!, (topInset!! * 2)) Bitmap.createBitmap(it, 0, 0, width!!, (topInset!! * 2))
@ -168,12 +177,17 @@ class EdgeToEdgeTest {
var height: Int? = null var height: Int? = null
waitForWindowUpdate() waitForWindowUpdate()
activityScenarioRule.scenario.onActivity { activity -> activityScenarioRule.scenario.onActivity { activity ->
bottomInset = activity.windowManager.maximumWindowMetrics.windowInsets.getInsets( val metrics = WindowMetricsCalculator.getOrCreate()
WindowInsets.Type.navigationBars(), .computeCurrentWindowMetrics(activity)
bottomInset = metrics.getWindowInsets().getInsets(
WindowInsetsCompat.Type.navigationBars(),
).bottom ).bottom
width = activity.windowManager.maximumWindowMetrics.bounds.width()
height = activity.windowManager.maximumWindowMetrics.bounds.height() width = metrics.bounds.width()
height = metrics.bounds.height()
} }
Log.d("jalc", "height: $height" )
Log.d("jalc", "bottomInset: $bottomInset" )
// Crop the top, adding extra pixels to check continuity // Crop the top, adding extra pixels to check continuity
val bitmap = takeScreenshot().let { val bitmap = takeScreenshot().let {
Bitmap.createBitmap(it, 0, height!! - (bottomInset!! * 2), width!!, (bottomInset!! * 2)) Bitmap.createBitmap(it, 0, height!! - (bottomInset!! * 2), width!!, (bottomInset!! * 2))
@ -197,6 +211,7 @@ class EdgeToEdgeTest {
"com.android.internal.systemui.navbar.gestural", "com.android.internal.systemui.navbar.gestural",
) )
} }
waitForWindowUpdate()
} }
private fun waitForWindowUpdate() { private fun waitForWindowUpdate() {

Loading…
Cancel
Save