@@ -41,6 +41,9 @@ import com.google.common.util.concurrent.ListenableFuture
41
41
* This API is primarily intended for use in lower layer libraries or frameworks. For test authors,
42
42
* its recommended to use espresso or compose's captureToImage.
43
43
*
44
+ * Note: This API will likely change in the future to a kotlin suspend function. If you want a
45
+ * method that returns a ListenableFuture instead, use [captureRegionToBitmapAsync].
46
+ *
44
47
* This API is currently experimental and subject to change or removal.
45
48
*/
46
49
@ExperimentalTestApi
@@ -62,15 +65,24 @@ fun Window.captureRegionToBitmap(boundsInWindow: Rect? = null): ListenableFuture
62
65
return bitmapFuture
63
66
}
64
67
68
+ /* *
69
+ * Equivalent to [captureRegionToBitmap] for now. In the future [captureRegionToBitmap] will be
70
+ * changed to a suspend function.
71
+ */
72
+ @ExperimentalTestApi
73
+ fun Window.captureRegionToBitmapAsync (boundsInWindow : Rect ? = null): ListenableFuture <Bitmap > {
74
+ return captureRegionToBitmap(boundsInWindow)
75
+ }
76
+
65
77
internal fun Window.generateBitmap (
66
78
boundsInWindow : Rect ? = null,
67
- bitmapFuture : ResolvableFuture <Bitmap >
79
+ bitmapFuture : ResolvableFuture <Bitmap >,
68
80
) {
69
81
val destBitmap =
70
82
Bitmap .createBitmap(
71
83
boundsInWindow?.width() ? : decorView.width,
72
84
boundsInWindow?.height() ? : decorView.height,
73
- Bitmap .Config .ARGB_8888
85
+ Bitmap .Config .ARGB_8888 ,
74
86
)
75
87
when {
76
88
Build .VERSION .SDK_INT < 26 ->
@@ -84,7 +96,7 @@ internal fun Window.generateBitmap(
84
96
internal fun Window.generateBitmapFromPixelCopy (
85
97
boundsInWindow : Rect ? = null,
86
98
destBitmap : Bitmap ,
87
- bitmapFuture : ResolvableFuture <Bitmap >
99
+ bitmapFuture : ResolvableFuture <Bitmap >,
88
100
) {
89
101
val onCopyFinished =
90
102
PixelCopy .OnPixelCopyFinishedListener { result ->
@@ -99,6 +111,6 @@ internal fun Window.generateBitmapFromPixelCopy(
99
111
boundsInWindow,
100
112
destBitmap,
101
113
onCopyFinished,
102
- Handler (Looper .getMainLooper())
114
+ Handler (Looper .getMainLooper()),
103
115
)
104
116
}
0 commit comments