162ab9b78b77b7dd851c47115f4d8d7611d657585George Mount/*
262ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * Copyright (C) 2014 The Android Open Source Project
362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount *
462ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * Licensed under the Apache License, Version 2.0 (the "License");
562ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * you may not use this file except in compliance with the License.
662ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * You may obtain a copy of the License at
762ab9b78b77b7dd851c47115f4d8d7611d657585George Mount *
862ab9b78b77b7dd851c47115f4d8d7611d657585George Mount *      http://www.apache.org/licenses/LICENSE-2.0
962ab9b78b77b7dd851c47115f4d8d7611d657585George Mount *
1062ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * Unless required by applicable law or agreed to in writing, software
1162ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * distributed under the License is distributed on an "AS IS" BASIS,
1262ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * See the License for the specific language governing permissions and
1462ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * limitations under the License.
1562ab9b78b77b7dd851c47115f4d8d7611d657585George Mount */
1662ab9b78b77b7dd851c47115f4d8d7611d657585George Mountpackage android.app;
1762ab9b78b77b7dd851c47115f4d8d7611d657585George Mount
18480ca829e2d3313740b4d14d30afbea6c98ff965George Mountimport android.content.Context;
19480ca829e2d3313740b4d14d30afbea6c98ff965George Mountimport android.content.res.Resources;
20480ca829e2d3313740b4d14d30afbea6c98ff965George Mountimport android.graphics.Bitmap;
21480ca829e2d3313740b4d14d30afbea6c98ff965George Mountimport android.graphics.Matrix;
22480ca829e2d3313740b4d14d30afbea6c98ff965George Mountimport android.graphics.RectF;
23480ca829e2d3313740b4d14d30afbea6c98ff965George Mountimport android.graphics.drawable.BitmapDrawable;
24017b13a50c1225ca338357dc1315befa38dc3e33Dake Guimport android.graphics.drawable.Drawable;
25017b13a50c1225ca338357dc1315befa38dc3e33Dake Guimport android.os.Bundle;
26480ca829e2d3313740b4d14d30afbea6c98ff965George Mountimport android.os.Parcelable;
2779b2781aa763cbd770f690c16af4448139f37061George Mountimport android.transition.TransitionUtils;
2862ab9b78b77b7dd851c47115f4d8d7611d657585George Mountimport android.view.View;
29017b13a50c1225ca338357dc1315befa38dc3e33Dake Guimport android.widget.ImageView;
30017b13a50c1225ca338357dc1315befa38dc3e33Dake Guimport android.widget.ImageView.ScaleType;
3162ab9b78b77b7dd851c47115f4d8d7611d657585George Mount
3262ab9b78b77b7dd851c47115f4d8d7611d657585George Mountimport java.util.List;
3362ab9b78b77b7dd851c47115f4d8d7611d657585George Mountimport java.util.Map;
3462ab9b78b77b7dd851c47115f4d8d7611d657585George Mount
3562ab9b78b77b7dd851c47115f4d8d7611d657585George Mount/**
3662ab9b78b77b7dd851c47115f4d8d7611d657585George Mount * Listener provided in
376558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount * {@link Activity#setEnterSharedElementCallback(SharedElementCallback)} and
386558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount * {@link Activity#setExitSharedElementCallback(SharedElementCallback)} as well as
3985ea498d86b35ea9baf4e5ef96927bea17209636George Mount * {@link Fragment#setEnterSharedElementCallback(SharedElementCallback)} and
4085ea498d86b35ea9baf4e5ef96927bea17209636George Mount * {@link Fragment#setExitSharedElementCallback(SharedElementCallback)}
416558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount * to monitor the Shared element transitions. The events can be used to customize Activity
426558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount * and Fragment Transition behavior.
4362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount */
446558056e8fccc32f9e1dc59e46d09f8d916b7538George Mountpublic abstract class SharedElementCallback {
45480ca829e2d3313740b4d14d30afbea6c98ff965George Mount    private Matrix mTempMatrix;
46017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu    private static final String BUNDLE_SNAPSHOT_BITMAP = "sharedElement:snapshot:bitmap";
47017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu    private static final String BUNDLE_SNAPSHOT_IMAGE_SCALETYPE = "sharedElement:snapshot:imageScaleType";
48017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu    private static final String BUNDLE_SNAPSHOT_IMAGE_MATRIX = "sharedElement:snapshot:imageMatrix";
49800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount
506558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount    static final SharedElementCallback NULL_CALLBACK = new SharedElementCallback() {
51800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount    };
52800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount
5362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount    /**
546558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * Called immediately after the start state is set for the shared element.
556558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * The shared element will start at the size and position of the shared element
566558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * in the launching Activity or Fragment.
5762ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *
5862ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param sharedElementNames The names of the shared elements that were accepted into
5962ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                           the View hierarchy.
6062ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param sharedElements The shared elements that are part of the View hierarchy.
6162ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param sharedElementSnapshots The Views containing snap shots of the shared element
6262ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               from the launching Window. These elements will not
6362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               be part of the scene, but will be positioned relative
646558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *                               to the Window decor View. This list is null for Fragment
656558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *                               Transitions.
6662ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     */
676558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount    public void onSharedElementStart(List<String> sharedElementNames,
6862ab9b78b77b7dd851c47115f4d8d7611d657585George Mount            List<View> sharedElements, List<View> sharedElementSnapshots) {}
6962ab9b78b77b7dd851c47115f4d8d7611d657585George Mount
7062ab9b78b77b7dd851c47115f4d8d7611d657585George Mount    /**
716558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * Called after the end state is set for the shared element, but before the end state
726558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * is captured by the shared element transition.
73800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * <p>
74800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     *     Any customization done in
756558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *     {@link #onSharedElementStart(java.util.List, java.util.List, java.util.List)}
76800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     *     may need to be modified to the final state of the shared element if it is not
77800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     *     automatically corrected by layout. For example, rotation or scale will not
786558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *     be affected by layout and if changed in {@link #onSharedElementStart(java.util.List,
79800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     *     java.util.List, java.util.List)}, it will also have to be set here again to correct
80800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     *     the end state.
81800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * </p>
8262ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *
8362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param sharedElementNames The names of the shared elements that were accepted into
8462ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                           the View hierarchy.
8562ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param sharedElements The shared elements that are part of the View hierarchy.
8662ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param sharedElementSnapshots The Views containing snap shots of the shared element
8762ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               from the launching Window. These elements will not
8862ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               be part of the scene, but will be positioned relative
896558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *                               to the Window decor View. This list will be null for
906558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *                               Fragment Transitions.
9162ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     */
926558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount    public void onSharedElementEnd(List<String> sharedElementNames,
9362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount            List<View> sharedElements, List<View> sharedElementSnapshots) {}
9462ab9b78b77b7dd851c47115f4d8d7611d657585George Mount
9562ab9b78b77b7dd851c47115f4d8d7611d657585George Mount    /**
966558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * Called after {@link #onMapSharedElements(java.util.List, java.util.Map)} when
97800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * transferring shared elements in. Any shared elements that have no mapping will be in
98800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * <var>rejectedSharedElements</var>. The elements remaining in
99800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * <var>rejectedSharedElements</var> will be transitioned out of the Scene. If a
100800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * View is removed from <var>rejectedSharedElements</var>, it must be handled by the
1016558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * <code>SharedElementCallback</code>.
102800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * <p>
103800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * Views in rejectedSharedElements will have their position and size set to the
104800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * position of the calling shared element, relative to the Window decor View and contain
105800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * snapshots of the View from the calling Activity or Fragment. This
106800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * view may be safely added to the decor View's overlay to remain in position.
107800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     * </p>
1086558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * <p>This method is not called for Fragment Transitions. All rejected shared elements
1096558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * will be handled by the exit transition.</p>
11062ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *
11162ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param rejectedSharedElements Views containing visual information of shared elements
11262ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               that are not part of the entering scene. These Views
11362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               are positioned relative to the Window decor View. A
11462ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               View removed from this list will not be transitioned
11562ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     *                               automatically.
11662ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     */
1176558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount    public void onRejectSharedElements(List<View> rejectedSharedElements) {}
11862ab9b78b77b7dd851c47115f4d8d7611d657585George Mount
11962ab9b78b77b7dd851c47115f4d8d7611d657585George Mount    /**
1206558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * Lets the SharedElementCallback adjust the mapping of shared element names to
12162ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * Views.
122800d72b0e05049e4a8f90ea96ec165fc975264ceGeorge Mount     *
12362ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param names The names of all shared elements transferred from the calling Activity
1246558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *              or Fragment in the order they were provided.
12562ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     * @param sharedElements The mapping of shared element names to Views. The best guess
1260a2ae002e60f7ea9b6bea282086b5eb0ae3c6e51George Mount     *                       will be filled into sharedElements based on the transitionNames.
12762ab9b78b77b7dd851c47115f4d8d7611d657585George Mount     */
1286558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount    public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {}
129480ca829e2d3313740b4d14d30afbea6c98ff965George Mount
130480ca829e2d3313740b4d14d30afbea6c98ff965George Mount    /**
131480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * Creates a snapshot of a shared element to be used by the remote Activity and reconstituted
1326558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * with {@link #onCreateSnapshotView(android.content.Context, android.os.Parcelable)}. A
133480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * null return value will mean that the remote Activity will have a null snapshot View in
1346558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * {@link #onSharedElementStart(java.util.List, java.util.List, java.util.List)} and
1356558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * {@link #onSharedElementEnd(java.util.List, java.util.List, java.util.List)}.
1366558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *
1376558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * <p>This is not called for Fragment Transitions.</p>
138480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     *
139480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * @param sharedElement The shared element View to create a snapshot for.
140480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * @param viewToGlobalMatrix A matrix containing a transform from the view to the screen
141480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     *                           coordinates.
142480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * @param screenBounds The bounds of shared element in screen coordinate space. This is
143480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     *                     the bounds of the view with the viewToGlobalMatrix applied.
144480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * @return A snapshot to send to the remote Activity to be reconstituted with
1456558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * {@link #onCreateSnapshotView(android.content.Context, android.os.Parcelable)} and passed
1466558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * into {@link #onSharedElementStart(java.util.List, java.util.List, java.util.List)} and
1476558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * {@link #onSharedElementEnd(java.util.List, java.util.List, java.util.List)}.
148480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     */
1496558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount    public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix,
150480ca829e2d3313740b4d14d30afbea6c98ff965George Mount            RectF screenBounds) {
151017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu        if (sharedElement instanceof ImageView) {
152017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            ImageView imageView = ((ImageView) sharedElement);
153017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            Drawable d = imageView.getDrawable();
154017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            Drawable bg = imageView.getBackground();
155017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            if (d != null && (bg == null || bg.getAlpha() == 0)) {
156017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                Bitmap bitmap = TransitionUtils.createDrawableBitmap(d);
157017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                if (bitmap != null) {
158017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                    Bundle bundle = new Bundle();
159017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                    bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap);
160017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                    bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE,
161017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                            imageView.getScaleType().toString());
162017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                    if (imageView.getScaleType() == ScaleType.MATRIX) {
163017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                        Matrix matrix = imageView.getImageMatrix();
164017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                        float[] values = new float[9];
165017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                        matrix.getValues(values);
166017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                        bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values);
167017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                    }
168017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                    return bundle;
169017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                }
170017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            }
171017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu        }
17279b2781aa763cbd770f690c16af4448139f37061George Mount        if (mTempMatrix == null) {
17379b2781aa763cbd770f690c16af4448139f37061George Mount            mTempMatrix = new Matrix(viewToGlobalMatrix);
17479b2781aa763cbd770f690c16af4448139f37061George Mount        } else {
175480ca829e2d3313740b4d14d30afbea6c98ff965George Mount            mTempMatrix.set(viewToGlobalMatrix);
176480ca829e2d3313740b4d14d30afbea6c98ff965George Mount        }
17779b2781aa763cbd770f690c16af4448139f37061George Mount        return TransitionUtils.createViewBitmap(sharedElement, mTempMatrix, screenBounds);
178480ca829e2d3313740b4d14d30afbea6c98ff965George Mount    }
179480ca829e2d3313740b4d14d30afbea6c98ff965George Mount
180480ca829e2d3313740b4d14d30afbea6c98ff965George Mount    /**
181480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * Reconstitutes a snapshot View from a Parcelable returned in
1826558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * {@link #onCaptureSharedElementSnapshot(android.view.View, android.graphics.Matrix,
1836558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * android.graphics.RectF)} to be used in {@link #onSharedElementStart(java.util.List,
1846558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * java.util.List, java.util.List)} and {@link #onSharedElementEnd(java.util.List,
185480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * java.util.List, java.util.List)}. The returned View will be sized and positioned after
186480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * this call so that it is ready to be added to the decor View's overlay.
187480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     *
1886558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * <p>This is not called for Fragment Transitions.</p>
1896558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     *
190480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * @param context The Context used to create the snapshot View.
1916558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * @param snapshot The Parcelable returned by {@link #onCaptureSharedElementSnapshot(
192480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * android.view.View, android.graphics.Matrix, android.graphics.RectF)}.
1936558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * @return A View to be sent in {@link #onSharedElementStart(java.util.List, java.util.List,
1946558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount     * java.util.List)} and {@link #onSharedElementEnd(java.util.List, java.util.List,
195480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     * java.util.List)}. A null value will produce a null snapshot value for those two methods.
196480ca829e2d3313740b4d14d30afbea6c98ff965George Mount     */
1976558056e8fccc32f9e1dc59e46d09f8d916b7538George Mount    public View onCreateSnapshotView(Context context, Parcelable snapshot) {
198480ca829e2d3313740b4d14d30afbea6c98ff965George Mount        View view = null;
199017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu        if (snapshot instanceof Bundle) {
200017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            Bundle bundle = (Bundle) snapshot;
201017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            Bitmap bitmap = (Bitmap) bundle.getParcelable(BUNDLE_SNAPSHOT_BITMAP);
202017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            if (bitmap == null) {
203017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                return null;
204017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            }
205017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            ImageView imageView = new ImageView(context);
206017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            view = imageView;
207017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            imageView.setImageBitmap(bitmap);
208017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            imageView.setScaleType(
209017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                    ScaleType.valueOf(bundle.getString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE)));
210017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            if (imageView.getScaleType() == ScaleType.MATRIX) {
211017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                float[] values = bundle.getFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX);
212017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                Matrix matrix = new Matrix();
213017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                matrix.setValues(values);
214017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu                imageView.setImageMatrix(matrix);
215017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu            }
216017b13a50c1225ca338357dc1315befa38dc3e33Dake Gu        } else if (snapshot instanceof Bitmap) {
217480ca829e2d3313740b4d14d30afbea6c98ff965George Mount            Bitmap bitmap = (Bitmap) snapshot;
218480ca829e2d3313740b4d14d30afbea6c98ff965George Mount            view = new View(context);
219480ca829e2d3313740b4d14d30afbea6c98ff965George Mount            Resources resources = context.getResources();
220480ca829e2d3313740b4d14d30afbea6c98ff965George Mount            view.setBackground(new BitmapDrawable(resources, bitmap));
221480ca829e2d3313740b4d14d30afbea6c98ff965George Mount        }
222480ca829e2d3313740b4d14d30afbea6c98ff965George Mount        return view;
223480ca829e2d3313740b4d14d30afbea6c98ff965George Mount    }
22462ab9b78b77b7dd851c47115f4d8d7611d657585George Mount}
225