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 17 package android.support.v4.app; 18 19 import android.app.Activity; 20 import android.app.SharedElementCallback; 21 import android.content.Context; 22 import android.graphics.Matrix; 23 import android.graphics.RectF; 24 import android.media.session.MediaController; 25 import android.os.Parcelable; 26 import android.view.View; 27 28 import java.lang.Override; 29 import java.lang.String; 30 import java.util.List; 31 import java.util.Map; 32 33 class ActivityCompatApi21 { 34 setMediaController(Activity activity, Object mediaControllerObj)35 public static void setMediaController(Activity activity, Object mediaControllerObj) { 36 activity.setMediaController((MediaController) mediaControllerObj); 37 } 38 finishAfterTransition(Activity activity)39 public static void finishAfterTransition(Activity activity) { 40 activity.finishAfterTransition(); 41 } 42 setEnterSharedElementCallback(Activity activity, SharedElementCallback21 callback)43 public static void setEnterSharedElementCallback(Activity activity, 44 SharedElementCallback21 callback) { 45 activity.setEnterSharedElementCallback(createCallback(callback)); 46 } 47 setExitSharedElementCallback(Activity activity, SharedElementCallback21 callback)48 public static void setExitSharedElementCallback(Activity activity, 49 SharedElementCallback21 callback) { 50 activity.setExitSharedElementCallback(createCallback(callback)); 51 } 52 postponeEnterTransition(Activity activity)53 public static void postponeEnterTransition(Activity activity) { 54 activity.postponeEnterTransition(); 55 } 56 startPostponedEnterTransition(Activity activity)57 public static void startPostponedEnterTransition(Activity activity) { 58 activity.startPostponedEnterTransition(); 59 } 60 61 public abstract static class SharedElementCallback21 { onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots)62 public abstract void onSharedElementStart(List<String> sharedElementNames, 63 List<View> sharedElements, List<View> sharedElementSnapshots); 64 onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots)65 public abstract void onSharedElementEnd(List<String> sharedElementNames, 66 List<View> sharedElements, List<View> sharedElementSnapshots); 67 onRejectSharedElements(List<View> rejectedSharedElements)68 public abstract void onRejectSharedElements(List<View> rejectedSharedElements); 69 onMapSharedElements(List<String> names, Map<String, View> sharedElements)70 public abstract void onMapSharedElements(List<String> names, 71 Map<String, View> sharedElements); onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds)72 public abstract Parcelable onCaptureSharedElementSnapshot(View sharedElement, 73 Matrix viewToGlobalMatrix, RectF screenBounds); onCreateSnapshotView(Context context, Parcelable snapshot)74 public abstract View onCreateSnapshotView(Context context, Parcelable snapshot); 75 } 76 createCallback(SharedElementCallback21 callback)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 SharedElementCallbackImpl(SharedElementCallback21 callback)88 public SharedElementCallbackImpl(SharedElementCallback21 callback) { 89 mCallback = callback; 90 } 91 92 @Override onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots)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 onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots)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 onRejectSharedElements(List<View> rejectedSharedElements)107 public void onRejectSharedElements(List<View> rejectedSharedElements) { 108 mCallback.onRejectSharedElements(rejectedSharedElements); 109 } 110 111 @Override onMapSharedElements(List<String> names, Map<String, View> sharedElements)112 public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { 113 mCallback.onMapSharedElements(names, sharedElements); 114 } 115 116 @Override onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds)117 public Parcelable onCaptureSharedElementSnapshot(View sharedElement, 118 Matrix viewToGlobalMatrix, 119 RectF screenBounds) { 120 return mCallback.onCaptureSharedElementSnapshot(sharedElement, viewToGlobalMatrix, 121 screenBounds); 122 } 123 124 @Override onCreateSnapshotView(Context context, Parcelable snapshot)125 public View onCreateSnapshotView(Context context, Parcelable snapshot) { 126 return mCallback.onCreateSnapshotView(context, snapshot); 127 } 128 } 129 } 130