ActivityCompatApi21.java revision 1194904b0540cb2043dd047206abf7592f31c2f4
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.media.session.MediaController;
25import android.os.Parcelable;
26import android.view.View;
27
28import java.lang.Override;
29import java.lang.String;
30import java.util.List;
31import java.util.Map;
32
33class ActivityCompatApi21 {
34
35    public static void setMediaController(Activity activity, Object mediaControllerObj) {
36        activity.setMediaController((MediaController) mediaControllerObj);
37    }
38
39    public static void finishAfterTransition(Activity activity) {
40        activity.finishAfterTransition();
41    }
42
43    public static void setEnterSharedElementCallback(Activity activity,
44            SharedElementCallback21 callback) {
45        activity.setEnterSharedElementCallback(createCallback(callback));
46    }
47
48    public static void setExitSharedElementCallback(Activity activity,
49            SharedElementCallback21 callback) {
50        activity.setExitSharedElementCallback(createCallback(callback));
51    }
52
53    public static void postponeEnterTransition(Activity activity) {
54        activity.postponeEnterTransition();
55    }
56
57    public static void startPostponedEnterTransition(Activity activity) {
58        activity.startPostponedEnterTransition();
59    }
60
61    public abstract static class SharedElementCallback21 {
62        public abstract void onSharedElementStart(List<String> sharedElementNames,
63                List<View> sharedElements, List<View> sharedElementSnapshots);
64
65        public abstract void onSharedElementEnd(List<String> sharedElementNames,
66                List<View> sharedElements, List<View> sharedElementSnapshots);
67
68        public abstract void onRejectSharedElements(List<View> rejectedSharedElements);
69
70        public abstract void onMapSharedElements(List<String> names,
71                Map<String, View> sharedElements);
72        public abstract Parcelable onCaptureSharedElementSnapshot(View sharedElement,
73                Matrix viewToGlobalMatrix, RectF screenBounds);
74        public abstract View onCreateSnapshotView(Context context, Parcelable snapshot);
75    }
76
77    private static SharedElementCallback createCallback(SharedElementCallback21 callback) {
78        SharedElementCallback newListener = null;
79        if (callback != null) {
80            newListener = new SharedElementCallbackImpl(callback);
81        }
82        return newListener;
83    }
84
85    private static class SharedElementCallbackImpl extends SharedElementCallback {
86        private SharedElementCallback21 mCallback;
87
88        public SharedElementCallbackImpl(SharedElementCallback21 callback) {
89            mCallback = callback;
90        }
91
92        @Override
93        public void onSharedElementStart(List<String> sharedElementNames,
94                List<View> sharedElements, List<View> sharedElementSnapshots) {
95            mCallback.onSharedElementStart(sharedElementNames, sharedElements,
96                    sharedElementSnapshots);
97        }
98
99        @Override
100        public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
101                List<View> sharedElementSnapshots) {
102            mCallback.onSharedElementEnd(sharedElementNames, sharedElements,
103                    sharedElementSnapshots);
104        }
105
106        @Override
107        public void onRejectSharedElements(List<View> rejectedSharedElements) {
108            mCallback.onRejectSharedElements(rejectedSharedElements);
109        }
110
111        @Override
112        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
113            mCallback.onMapSharedElements(names, sharedElements);
114        }
115
116        @Override
117        public Parcelable onCaptureSharedElementSnapshot(View sharedElement,
118                Matrix viewToGlobalMatrix,
119                RectF screenBounds) {
120            return mCallback.onCaptureSharedElementSnapshot(sharedElement, viewToGlobalMatrix,
121                            screenBounds);
122        }
123
124        @Override
125        public View onCreateSnapshotView(Context context, Parcelable snapshot) {
126            return mCallback.onCreateSnapshotView(context, snapshot);
127        }
128    }
129}
130