summaryrefslogtreecommitdiffstats
path: root/core/java/android/app/SharedElementCallback.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/app/SharedElementCallback.java')
-rw-r--r--core/java/android/app/SharedElementCallback.java48
1 files changed, 46 insertions, 2 deletions
diff --git a/core/java/android/app/SharedElementCallback.java b/core/java/android/app/SharedElementCallback.java
index 060bbe6..6ac2401 100644
--- a/core/java/android/app/SharedElementCallback.java
+++ b/core/java/android/app/SharedElementCallback.java
@@ -18,13 +18,16 @@ package android.app;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
-import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
import android.os.Parcelable;
import android.transition.TransitionUtils;
import android.view.View;
+import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
import java.util.List;
import java.util.Map;
@@ -40,6 +43,9 @@ import java.util.Map;
*/
public abstract class SharedElementCallback {
private Matrix mTempMatrix;
+ private static final String BUNDLE_SNAPSHOT_BITMAP = "sharedElement:snapshot:bitmap";
+ private static final String BUNDLE_SNAPSHOT_IMAGE_SCALETYPE = "sharedElement:snapshot:imageScaleType";
+ private static final String BUNDLE_SNAPSHOT_IMAGE_MATRIX = "sharedElement:snapshot:imageMatrix";
static final SharedElementCallback NULL_CALLBACK = new SharedElementCallback() {
};
@@ -142,6 +148,27 @@ public abstract class SharedElementCallback {
*/
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix,
RectF screenBounds) {
+ if (sharedElement instanceof ImageView) {
+ ImageView imageView = ((ImageView) sharedElement);
+ Drawable d = imageView.getDrawable();
+ Drawable bg = imageView.getBackground();
+ if (d != null && (bg == null || bg.getAlpha() == 0)) {
+ Bitmap bitmap = TransitionUtils.createDrawableBitmap(d);
+ if (bitmap != null) {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap);
+ bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE,
+ imageView.getScaleType().toString());
+ if (imageView.getScaleType() == ScaleType.MATRIX) {
+ Matrix matrix = imageView.getImageMatrix();
+ float[] values = new float[9];
+ matrix.getValues(values);
+ bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values);
+ }
+ return bundle;
+ }
+ }
+ }
if (mTempMatrix == null) {
mTempMatrix = new Matrix(viewToGlobalMatrix);
} else {
@@ -169,7 +196,24 @@ public abstract class SharedElementCallback {
*/
public View onCreateSnapshotView(Context context, Parcelable snapshot) {
View view = null;
- if (snapshot instanceof Bitmap) {
+ if (snapshot instanceof Bundle) {
+ Bundle bundle = (Bundle) snapshot;
+ Bitmap bitmap = (Bitmap) bundle.getParcelable(BUNDLE_SNAPSHOT_BITMAP);
+ if (bitmap == null) {
+ return null;
+ }
+ ImageView imageView = new ImageView(context);
+ view = imageView;
+ imageView.setImageBitmap(bitmap);
+ imageView.setScaleType(
+ ScaleType.valueOf(bundle.getString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE)));
+ if (imageView.getScaleType() == ScaleType.MATRIX) {
+ float[] values = bundle.getFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX);
+ Matrix matrix = new Matrix();
+ matrix.setValues(values);
+ imageView.setImageMatrix(matrix);
+ }
+ } else if (snapshot instanceof Bitmap) {
Bitmap bitmap = (Bitmap) snapshot;
view = new View(context);
Resources resources = context.getResources();