Stay organized with collections Save and categorize content based on your preferences.

ViewCapture

public final class ViewCapture


Summary

Public methods

static final @NonNull ListenableFuture<@NonNull Bitmap>

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

static final @NonNull ListenableFuture<@NonNull Void>

Trigger a redraw of the given view.

Public methods

ViewCapture.captureToBitmap

@ExperimentalTestApi
@RequiresApi(value = 16)
public static final @NonNull ListenableFuture<@NonNull BitmapViewCapture.captureToBitmap(@NonNull View receiver)

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.

This API currently does not work for View's hosted in Dialogs on APIs >= 26, as there is no way to find a Dialog's Window. (see b/195673633).

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

ViewCapture.forceRedraw

@RequiresApi(value = 16)
@ExperimentalTestApi
public static final @NonNull ListenableFuture<@NonNull VoidViewCapture.forceRedraw(@NonNull View receiver)

Trigger a redraw of the given view.

Should only be called on UI thread.

Returns
@NonNull ListenableFuture<@NonNull Void>

a ListenableFuture that will be complete once ui drawing is complete