diff options
author | Justin Klaassen <justinklaassen@google.com> | 2017-10-10 15:20:13 -0400 |
---|---|---|
committer | Justin Klaassen <justinklaassen@google.com> | 2017-10-10 15:20:13 -0400 |
commit | 93b7ee4fce01df52a6607f0b1965cbafdfeaf1a6 (patch) | |
tree | 49f76f879a89c256a4f65b674086be50760bdffb /android/transition/TransitionUtils.java | |
parent | bc81c7ada5aab3806dd0b17498f5c9672c9b33c4 (diff) | |
download | android-28-93b7ee4fce01df52a6607f0b1965cbafdfeaf1a6.tar.gz |
Import Android SDK Platform P [4386628]
/google/data/ro/projects/android/fetch_artifact \
--bid 4386628 \
--target sdk_phone_armv7-win_sdk \
sdk-repo-linux-sources-4386628.zip
AndroidVersion.ApiLevel has been modified to appear as 28
Change-Id: I9b8400ac92116cae4f033d173f7a5682b26ccba9
Diffstat (limited to 'android/transition/TransitionUtils.java')
-rw-r--r-- | android/transition/TransitionUtils.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/android/transition/TransitionUtils.java b/android/transition/TransitionUtils.java index 4951237e..084b79d5 100644 --- a/android/transition/TransitionUtils.java +++ b/android/transition/TransitionUtils.java @@ -101,7 +101,7 @@ public class TransitionUtils { ImageView copy = new ImageView(view.getContext()); copy.setScaleType(ImageView.ScaleType.CENTER_CROP); - Bitmap bitmap = createViewBitmap(view, matrix, bounds); + Bitmap bitmap = createViewBitmap(view, matrix, bounds, sceneRoot); if (bitmap != null) { copy.setImageBitmap(bitmap); } @@ -115,7 +115,7 @@ public class TransitionUtils { /** * Get a copy of bitmap of given drawable, return null if intrinsic size is zero */ - public static Bitmap createDrawableBitmap(Drawable drawable) { + public static Bitmap createDrawableBitmap(Drawable drawable, View hostView) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); if (width <= 0 || height <= 0) { @@ -128,7 +128,7 @@ public class TransitionUtils { } int bitmapWidth = (int) (width * scale); int bitmapHeight = (int) (height * scale); - final RenderNode node = RenderNode.create("TransitionUtils", null); + final RenderNode node = RenderNode.create("TransitionUtils", hostView); node.setLeftTopRightBottom(0, 0, width, height); node.setClipToBounds(false); final DisplayListCanvas canvas = node.start(width, height); @@ -156,20 +156,30 @@ public class TransitionUtils { * returning. * @param bounds The bounds of the bitmap in the destination coordinate system (where the * view should be presented. Typically, this is matrix.mapRect(viewBounds); + * @param sceneRoot A ViewGroup that is attached to the window to temporarily contain the view + * if it isn't attached to the window. * @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) { + public static Bitmap createViewBitmap(View view, Matrix matrix, RectF bounds, + ViewGroup sceneRoot) { + final boolean addToOverlay = !view.isAttachedToWindow(); + if (addToOverlay) { + if (sceneRoot == null || !sceneRoot.isAttachedToWindow()) { + return null; + } + sceneRoot.getOverlay().add(view); + } 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); matrix.postScale(scale, scale); - final RenderNode node = RenderNode.create("TransitionUtils", null); + final RenderNode node = RenderNode.create("TransitionUtils", view); node.setLeftTopRightBottom(0, 0, bitmapWidth, bitmapHeight); node.setClipToBounds(false); final DisplayListCanvas canvas = node.start(bitmapWidth, bitmapHeight); @@ -178,6 +188,9 @@ public class TransitionUtils { node.end(canvas); bitmap = ThreadedRenderer.createHardwareBitmap(node, bitmapWidth, bitmapHeight); } + if (addToOverlay) { + sceneRoot.getOverlay().remove(view); + } return bitmap; } |