From 4dc1ec754c5b263b96cddad047f1f99412f08596 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Mon, 25 Sep 2017 15:45:05 -0700 Subject: Fix crash when creating a HW Bitmap on a detached view BUG: 65160121 Test: Unable to repro the crash before or after the fix Change-Id: I84fa28557c67a6672b8d82443d4da7be4f28a50d --- core/java/android/transition/TransitionUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/java/android/transition/TransitionUtils.java b/core/java/android/transition/TransitionUtils.java index 4951237e5cc9..3af7e5d3eaa4 100644 --- a/core/java/android/transition/TransitionUtils.java +++ b/core/java/android/transition/TransitionUtils.java @@ -159,11 +159,14 @@ public class TransitionUtils { * @return A bitmap of the given view or null if bounds has no width or height. */ public static Bitmap createViewBitmap(View view, Matrix matrix, RectF bounds) { + if (!view.isAttachedToWindow()) { + return null; + } Bitmap bitmap = null; int bitmapWidth = Math.round(bounds.width()); int bitmapHeight = Math.round(bounds.height()); if (bitmapWidth > 0 && bitmapHeight > 0) { - float scale = Math.min(1f, ((float)MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight)); + float scale = Math.min(1f, ((float) MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight)); bitmapWidth *= scale; bitmapHeight *= scale; matrix.postTranslate(-bounds.left, -bounds.top); -- cgit v1.2.3-59-g8ed1b