1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.app;
18
19import android.app.Activity;
20import android.app.SharedElementCallback;
21import android.content.Context;
22import android.graphics.Matrix;
23import android.graphics.RectF;
24import android.os.Parcelable;
25import android.view.View;
26
27import java.lang.Override;
28import java.lang.String;
29import java.util.List;
30import java.util.Map;
31
32class ActivityCompat21 {
33
34    public static void finishAfterTransition(Activity activity) {
35        activity.finishAfterTransition();
36    }
37
38    public static void setEnterSharedElementCallback(Activity activity,
39            SharedElementCallback21 callback) {
40        activity.setEnterSharedElementCallback(createCallback(callback));
41    }
42
43    public static void setExitSharedElementCallback(Activity activity,
44            SharedElementCallback21 callback) {
45        activity.setExitSharedElementCallback(createCallback(callback));
46    }
47
48    public static void postponeEnterTransition(Activity activity) {
49        activity.postponeEnterTransition();
50    }
51
52    public static void startPostponedEnterTransition(Activity activity) {
53        activity.startPostponedEnterTransition();
54    }
55
56    public abstract static class SharedElementCallback21 {
57        public abstract void onSharedElementStart(List<String> sharedElementNames,
58                List<View> sharedElements, List<View> sharedElementSnapshots);
59
60        public abstract void onSharedElementEnd(List<String> sharedElementNames,
61                List<View> sharedElements, List<View> sharedElementSnapshots);
62
63        public abstract void onRejectSharedElements(List<View> rejectedSharedElements);
64
65        public abstract void onMapSharedElements(List<String> names,
66                Map<String, View> sharedElements);
67        public abstract Parcelable onCaptureSharedElementSnapshot(View sharedElement,
68                Matrix viewToGlobalMatrix, RectF screenBounds);
69        public abstract View onCreateSnapshotView(Context context, Parcelable snapshot);
70    }
71
72    private static SharedElementCallback createCallback(SharedElementCallback21 callback) {
73        SharedElementCallback newListener = null;
74        if (callback != null) {
75            newListener = new SharedElementCallbackImpl(callback);
76        }
77        return newListener;
78    }
79
80    private static class SharedElementCallbackImpl extends SharedElementCallback {
81        private SharedElementCallback21 mCallback;
82
83        public SharedElementCallbackImpl(SharedElementCallback21 callback) {
84            mCallback = callback;
85        }
86
87        @Override
88        public void onSharedElementStart(List<String> sharedElementNames,
89                List<View> sharedElements, List<View> sharedElementSnapshots) {
90            mCallback.onSharedElementStart(sharedElementNames, sharedElements,
91                    sharedElementSnapshots);
92        }
93
94        @Override
95        public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
96                List<View> sharedElementSnapshots) {
97            mCallback.onSharedElementEnd(sharedElementNames, sharedElements,
98                    sharedElementSnapshots);
99        }
100
101        @Override
102        public void onRejectSharedElements(List<View> rejectedSharedElements) {
103            mCallback.onRejectSharedElements(rejectedSharedElements);
104        }
105
106        @Override
107        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
108            mCallback.onMapSharedElements(names, sharedElements);
109        }
110
111        @Override
112        public Parcelable onCaptureSharedElementSnapshot(View sharedElement,
113                Matrix viewToGlobalMatrix,
114                RectF screenBounds) {
115            return mCallback.onCaptureSharedElementSnapshot(sharedElement, viewToGlobalMatrix,
116                            screenBounds);
117        }
118
119        @Override
120        public View onCreateSnapshotView(Context context, Parcelable snapshot) {
121            return mCallback.onCreateSnapshotView(context, snapshot);
122        }
123    }
124}
125