Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates captureToBitmap in ViewCapture to treat API 34 the same way that all previous API works. #2074

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@

**Bug Fixes**

* ViewCapture.captureToBitmap API 34 now uses the surface directly to take the screenshot.

**New Features**

**Breaking Changes**
Expand Down
3 changes: 0 additions & 3 deletions core/java/androidx/test/core/view/ViewCapture.kt
Expand Up @@ -60,7 +60,6 @@ import java.util.function.Consumer
* This API is currently experimental and subject to change or removal.
*/
@ExperimentalTestApi
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
fun View.captureToBitmap(rect: Rect? = null): ListenableFuture<Bitmap> {
val bitmapFuture: ResolvableFuture<Bitmap> = ResolvableFuture.create()
val mainExecutor = HandlerExecutor(Handler(Looper.getMainLooper()))
Expand Down Expand Up @@ -91,7 +90,6 @@ fun View.captureToBitmap(rect: Rect? = null): ListenableFuture<Bitmap> {
* @return a [ListenableFuture] that will be complete once ui drawing is complete
*/
// NoClassDefFoundError occurs on API 15
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
// @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@ExperimentalTestApi
fun View.forceRedraw(): ListenableFuture<Void> {
Expand Down Expand Up @@ -128,7 +126,6 @@ private fun View.generateBitmap(bitmapFuture: ResolvableFuture<Bitmap>, rect: Re
val destBitmap = Bitmap.createBitmap(rectWidth, rectHeight, Bitmap.Config.ARGB_8888)
when {
Build.VERSION.SDK_INT < 26 -> generateBitmapFromDraw(destBitmap, bitmapFuture, rect)
Build.VERSION.SDK_INT >= 34 -> generateBitmapFromPixelCopy(destBitmap, bitmapFuture, rect)
this is SurfaceView -> generateBitmapFromSurfaceViewPixelCopy(destBitmap, bitmapFuture, rect)
else -> generateBitmapFromPixelCopy(this.getSurface(), destBitmap, bitmapFuture, rect)
}
Expand Down