androidx.test.core.view


Classes

Extension functions summary

ListenableFuture<Bitmap>

Asynchronously captures an image of the underlying window into a Bitmap.

ListenableFuture<Bitmap>

Asynchronously captures an image of the underlying view into a Bitmap.

ListenableFuture<Void>

Trigger a redraw of the given view.

Extension functions

captureRegionToBitmap

@ExperimentalTestApi
fun Window.captureRegionToBitmap(boundsInWindow: Rect? = null): ListenableFuture<Bitmap>

Asynchronously captures an image of the underlying window into a Bitmap.

For devices below Build.VERSION_CODES#O the image is obtained using View#draw on the windows decorView. Otherwise, PixelCopy is used.

This method will also enable HardwareRendererCompat#setDrawingEnabled(boolean) if required.

This API is primarily intended for use in lower layer libraries or frameworks. For test authors, its recommended to use espresso or compose's captureToImage.

This API is currently experimental and subject to change or removal.

captureToBitmap

@ExperimentalTestApi
fun View.captureToBitmap(rect: Rect? = null): ListenableFuture<Bitmap>

Asynchronously captures an image of the underlying view into a Bitmap.

For devices below Build.VERSION_CODES#O (or if the view's window cannot be determined), the image is obtained using View#draw. Otherwise, PixelCopy is used.

This method will also enable HardwareRendererCompat#setDrawingEnabled(boolean) if required.

This API is primarily intended for use in lower layer libraries or frameworks. For test authors, its recommended to use espresso or compose's captureToImage.

If a rect is supplied, this will further crop locally from the bounds of the given view. For example, if the given view is at (10, 10 - 30, 30) and the rect is (5, 5 - 10, 10), the final bitmap will be a 5x5 bitmap that spans (15, 15 - 20, 20). This is particularly useful for Compose, which only has a singular view that contains a hierarchy of nodes.

This API is currently experimental and subject to change or removal.

forceRedraw

@ExperimentalTestApi
fun View.forceRedraw(): ListenableFuture<Void>

Trigger a redraw of the given view.

Should only be called on UI thread.

Returns
ListenableFuture<Void>

a ListenableFuture that will be complete once ui drawing is complete