George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 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 | package android.app; |
| 17 | |
| 18 | import android.animation.Animator; |
| 19 | import android.animation.AnimatorListenerAdapter; |
| 20 | import android.animation.ObjectAnimator; |
George Mount | 4dc668c | 2015-04-09 20:55:59 +0000 | [diff] [blame] | 21 | import android.app.SharedElementCallback.OnSharedElementsReadyListener; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 22 | import android.graphics.drawable.Drawable; |
| 23 | import android.os.Bundle; |
| 24 | import android.os.ResultReceiver; |
Dake Gu | b04b36e | 2014-08-08 11:22:30 -0700 | [diff] [blame] | 25 | import android.text.TextUtils; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 26 | import android.transition.Transition; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 27 | import android.transition.TransitionManager; |
| 28 | import android.util.ArrayMap; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 29 | import android.view.View; |
George Mount | d265bd7 | 2014-06-02 07:22:59 -0700 | [diff] [blame] | 30 | import android.view.ViewGroup; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 31 | import android.view.ViewGroupOverlay; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 32 | import android.view.ViewTreeObserver; |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 33 | import android.view.Window; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 34 | |
| 35 | import java.util.ArrayList; |
| 36 | |
| 37 | /** |
| 38 | * This ActivityTransitionCoordinator is created by the Activity to manage |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 39 | * the enter scene and shared element transfer into the Scene, either during |
| 40 | * launch of an Activity or returning from a launched Activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 41 | */ |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 42 | class EnterTransitionCoordinator extends ActivityTransitionCoordinator { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 43 | private static final String TAG = "EnterTransitionCoordinator"; |
| 44 | |
George Mount | e678ab6 | 2014-06-30 15:28:28 -0700 | [diff] [blame] | 45 | private static final int MIN_ANIMATION_FRAMES = 2; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 46 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 47 | private boolean mSharedElementTransitionStarted; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 48 | private Activity mActivity; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 49 | private boolean mHasStopped; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 50 | private boolean mIsCanceled; |
George Mount | 8cab50a | 2014-05-15 09:57:17 -0700 | [diff] [blame] | 51 | private ObjectAnimator mBackgroundAnimator; |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 52 | private boolean mIsExitTransitionComplete; |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 53 | private boolean mIsReadyForTransition; |
| 54 | private Bundle mSharedElementsBundle; |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 55 | private boolean mWasOpaque; |
George Mount | 82ffc14 | 2014-06-30 16:47:34 -0700 | [diff] [blame] | 56 | private boolean mAreViewsReady; |
George Mount | 8d3cd2c | 2014-07-08 11:07:33 -0700 | [diff] [blame] | 57 | private boolean mIsViewsTransitionStarted; |
George Mount | a2bbbb3 | 2014-08-12 10:16:20 -0700 | [diff] [blame] | 58 | private Transition mEnterViewsTransition; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 59 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 60 | public EnterTransitionCoordinator(Activity activity, ResultReceiver resultReceiver, |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 61 | ArrayList<String> sharedElementNames, boolean isReturning) { |
| 62 | super(activity.getWindow(), sharedElementNames, |
| 63 | getListener(activity, isReturning), isReturning); |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 64 | mActivity = activity; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 65 | setResultReceiver(resultReceiver); |
| 66 | prepareEnter(); |
| 67 | Bundle resultReceiverBundle = new Bundle(); |
| 68 | resultReceiverBundle.putParcelable(KEY_REMOTE_RECEIVER, this); |
| 69 | mResultReceiver.send(MSG_SET_REMOTE_RECEIVER, resultReceiverBundle); |
George Mount | 6e7fb60 | 2014-09-04 16:20:20 -0700 | [diff] [blame] | 70 | final View decorView = getDecor(); |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 71 | if (decorView != null) { |
| 72 | decorView.getViewTreeObserver().addOnPreDrawListener( |
| 73 | new ViewTreeObserver.OnPreDrawListener() { |
| 74 | @Override |
| 75 | public boolean onPreDraw() { |
| 76 | if (mIsReadyForTransition) { |
| 77 | decorView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 78 | } |
| 79 | return mIsReadyForTransition; |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 80 | } |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 81 | }); |
| 82 | } |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Dake Gu | b04b36e | 2014-08-08 11:22:30 -0700 | [diff] [blame] | 85 | public void viewInstancesReady(ArrayList<String> accepted, ArrayList<String> localNames, |
| 86 | ArrayList<View> localViews) { |
| 87 | boolean remap = false; |
| 88 | for (int i = 0; i < localViews.size(); i++) { |
| 89 | View view = localViews.get(i); |
| 90 | if (!TextUtils.equals(view.getTransitionName(), localNames.get(i)) |
| 91 | || !view.isAttachedToWindow()) { |
| 92 | remap = true; |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | if (remap) { |
| 97 | triggerViewsReady(mapNamedElements(accepted, localNames)); |
| 98 | } else { |
| 99 | triggerViewsReady(mapSharedElements(accepted, localViews)); |
| 100 | } |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 101 | } |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 102 | |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 103 | public void namedViewsReady(ArrayList<String> accepted, ArrayList<String> localNames) { |
George Mount | 82ffc14 | 2014-06-30 16:47:34 -0700 | [diff] [blame] | 104 | triggerViewsReady(mapNamedElements(accepted, localNames)); |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 105 | } |
| 106 | |
George Mount | a2bbbb3 | 2014-08-12 10:16:20 -0700 | [diff] [blame] | 107 | public Transition getEnterViewsTransition() { |
| 108 | return mEnterViewsTransition; |
| 109 | } |
| 110 | |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 111 | @Override |
| 112 | protected void viewsReady(ArrayMap<String, View> sharedElements) { |
| 113 | super.viewsReady(sharedElements); |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 114 | mIsReadyForTransition = true; |
George Mount | 0f0c473 | 2014-09-05 13:47:47 -0700 | [diff] [blame] | 115 | hideViews(mSharedElements); |
George Mount | b694e08 | 2014-09-12 07:34:52 -0700 | [diff] [blame] | 116 | if (getViewsTransition() != null && mTransitioningViews != null) { |
George Mount | 0f0c473 | 2014-09-05 13:47:47 -0700 | [diff] [blame] | 117 | hideViews(mTransitioningViews); |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 118 | } |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 119 | if (mIsReturning) { |
| 120 | sendSharedElementDestination(); |
| 121 | } else { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 122 | moveSharedElementsToOverlay(); |
| 123 | } |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 124 | if (mSharedElementsBundle != null) { |
| 125 | onTakeSharedElements(); |
| 126 | } |
George Mount | d265bd7 | 2014-06-02 07:22:59 -0700 | [diff] [blame] | 127 | } |
| 128 | |
George Mount | 82ffc14 | 2014-06-30 16:47:34 -0700 | [diff] [blame] | 129 | private void triggerViewsReady(final ArrayMap<String, View> sharedElements) { |
| 130 | if (mAreViewsReady) { |
| 131 | return; |
| 132 | } |
| 133 | mAreViewsReady = true; |
George Mount | 1fb941d | 2014-10-30 09:15:32 -0700 | [diff] [blame] | 134 | final ViewGroup decor = getDecor(); |
George Mount | 82ffc14 | 2014-06-30 16:47:34 -0700 | [diff] [blame] | 135 | // Ensure the views have been laid out before capturing the views -- we need the epicenter. |
George Mount | 1fb941d | 2014-10-30 09:15:32 -0700 | [diff] [blame] | 136 | if (decor == null || (decor.isAttachedToWindow() && |
| 137 | (sharedElements.isEmpty() || !sharedElements.valueAt(0).isLayoutRequested()))) { |
George Mount | 82ffc14 | 2014-06-30 16:47:34 -0700 | [diff] [blame] | 138 | viewsReady(sharedElements); |
| 139 | } else { |
George Mount | 1fb941d | 2014-10-30 09:15:32 -0700 | [diff] [blame] | 140 | decor.getViewTreeObserver() |
George Mount | 82ffc14 | 2014-06-30 16:47:34 -0700 | [diff] [blame] | 141 | .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { |
George Mount | 4dc668c | 2015-04-09 20:55:59 +0000 | [diff] [blame] | 142 | @Override |
| 143 | public boolean onPreDraw() { |
| 144 | decor.getViewTreeObserver().removeOnPreDrawListener(this); |
| 145 | viewsReady(sharedElements); |
| 146 | return true; |
| 147 | } |
| 148 | }); |
George Mount | 82ffc14 | 2014-06-30 16:47:34 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 152 | private ArrayMap<String, View> mapNamedElements(ArrayList<String> accepted, |
| 153 | ArrayList<String> localNames) { |
| 154 | ArrayMap<String, View> sharedElements = new ArrayMap<String, View>(); |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 155 | ViewGroup decorView = getDecor(); |
| 156 | if (decorView != null) { |
| 157 | decorView.findNamedViews(sharedElements); |
| 158 | } |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 159 | if (accepted != null) { |
| 160 | for (int i = 0; i < localNames.size(); i++) { |
| 161 | String localName = localNames.get(i); |
| 162 | String acceptedName = accepted.get(i); |
| 163 | if (localName != null && !localName.equals(acceptedName)) { |
| 164 | View view = sharedElements.remove(localName); |
| 165 | if (view != null) { |
| 166 | sharedElements.put(acceptedName, view); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | return sharedElements; |
| 172 | } |
| 173 | |
George Mount | d265bd7 | 2014-06-02 07:22:59 -0700 | [diff] [blame] | 174 | private void sendSharedElementDestination() { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 175 | boolean allReady; |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 176 | final View decorView = getDecor(); |
Dake Gu | 872efe4 | 2014-08-29 15:24:58 -0700 | [diff] [blame] | 177 | if (allowOverlappingTransitions() && getEnterViewsTransition() != null) { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 178 | allReady = false; |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 179 | } else if (decorView == null) { |
| 180 | allReady = true; |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 181 | } else { |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 182 | allReady = !decorView.isLayoutRequested(); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 183 | if (allReady) { |
| 184 | for (int i = 0; i < mSharedElements.size(); i++) { |
| 185 | if (mSharedElements.get(i).isLayoutRequested()) { |
| 186 | allReady = false; |
| 187 | break; |
| 188 | } |
George Mount | 67d9243 | 2014-06-06 13:34:20 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | } |
| 192 | if (allReady) { |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 193 | Bundle state = captureSharedElementState(); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 194 | moveSharedElementsToOverlay(); |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 195 | mResultReceiver.send(MSG_SHARED_ELEMENT_DESTINATION, state); |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 196 | } else if (decorView != null) { |
George Mount | 6e7fb60 | 2014-09-04 16:20:20 -0700 | [diff] [blame] | 197 | decorView.getViewTreeObserver() |
George Mount | d265bd7 | 2014-06-02 07:22:59 -0700 | [diff] [blame] | 198 | .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { |
| 199 | @Override |
| 200 | public boolean onPreDraw() { |
George Mount | 6e7fb60 | 2014-09-04 16:20:20 -0700 | [diff] [blame] | 201 | decorView.getViewTreeObserver().removeOnPreDrawListener(this); |
George Mount | f31d83c | 2014-08-29 13:32:20 -0700 | [diff] [blame] | 202 | if (mResultReceiver != null) { |
| 203 | Bundle state = captureSharedElementState(); |
George Mount | f31d83c | 2014-08-29 13:32:20 -0700 | [diff] [blame] | 204 | moveSharedElementsToOverlay(); |
| 205 | mResultReceiver.send(MSG_SHARED_ELEMENT_DESTINATION, state); |
| 206 | } |
George Mount | d265bd7 | 2014-06-02 07:22:59 -0700 | [diff] [blame] | 207 | return true; |
| 208 | } |
| 209 | }); |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 210 | } |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 211 | if (allowOverlappingTransitions()) { |
| 212 | startEnterTransitionOnly(); |
| 213 | } |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 216 | private static SharedElementCallback getListener(Activity activity, boolean isReturning) { |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 217 | return isReturning ? activity.mExitTransitionListener : activity.mEnterTransitionListener; |
| 218 | } |
| 219 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 220 | @Override |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 221 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 222 | switch (resultCode) { |
| 223 | case MSG_TAKE_SHARED_ELEMENTS: |
| 224 | if (!mIsCanceled) { |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 225 | mSharedElementsBundle = resultData; |
| 226 | onTakeSharedElements(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 227 | } |
| 228 | break; |
| 229 | case MSG_EXIT_TRANSITION_COMPLETE: |
| 230 | if (!mIsCanceled) { |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 231 | mIsExitTransitionComplete = true; |
| 232 | if (mSharedElementTransitionStarted) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 233 | onRemoteExitTransitionComplete(); |
| 234 | } |
| 235 | } |
| 236 | break; |
| 237 | case MSG_CANCEL: |
| 238 | cancel(); |
| 239 | break; |
| 240 | } |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 243 | private void cancel() { |
| 244 | if (!mIsCanceled) { |
| 245 | mIsCanceled = true; |
George Mount | 8d3cd2c | 2014-07-08 11:07:33 -0700 | [diff] [blame] | 246 | if (getViewsTransition() == null || mIsViewsTransitionStarted) { |
George Mount | ce2ee3d | 2014-09-09 15:04:31 -0700 | [diff] [blame] | 247 | showViews(mSharedElements, true); |
George Mount | b694e08 | 2014-09-12 07:34:52 -0700 | [diff] [blame] | 248 | } else if (mTransitioningViews != null) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 249 | mTransitioningViews.addAll(mSharedElements); |
| 250 | } |
| 251 | mSharedElementNames.clear(); |
| 252 | mSharedElements.clear(); |
| 253 | mAllSharedElementNames.clear(); |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 254 | startSharedElementTransition(null); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 255 | onRemoteExitTransitionComplete(); |
| 256 | } |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 259 | public boolean isReturning() { |
| 260 | return mIsReturning; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 263 | protected void prepareEnter() { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 264 | ViewGroup decorView = getDecor(); |
| 265 | if (mActivity == null || decorView == null) { |
| 266 | return; |
| 267 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 268 | mActivity.overridePendingTransition(0, 0); |
| 269 | if (!mIsReturning) { |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 270 | mWasOpaque = mActivity.convertToTranslucent(null, null); |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 271 | Drawable background = decorView.getBackground(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 272 | if (background != null) { |
| 273 | getWindow().setBackgroundDrawable(null); |
| 274 | background = background.mutate(); |
| 275 | background.setAlpha(0); |
| 276 | getWindow().setBackgroundDrawable(background); |
| 277 | } |
| 278 | } else { |
| 279 | mActivity = null; // all done with it now. |
| 280 | } |
| 281 | } |
| 282 | |
George Mount | a712e8c | 2014-05-20 15:10:20 -0700 | [diff] [blame] | 283 | @Override |
| 284 | protected Transition getViewsTransition() { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 285 | Window window = getWindow(); |
| 286 | if (window == null) { |
| 287 | return null; |
| 288 | } |
George Mount | a712e8c | 2014-05-20 15:10:20 -0700 | [diff] [blame] | 289 | if (mIsReturning) { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 290 | return window.getReenterTransition(); |
George Mount | a712e8c | 2014-05-20 15:10:20 -0700 | [diff] [blame] | 291 | } else { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 292 | return window.getEnterTransition(); |
George Mount | a712e8c | 2014-05-20 15:10:20 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | protected Transition getSharedElementTransition() { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 297 | Window window = getWindow(); |
| 298 | if (window == null) { |
| 299 | return null; |
| 300 | } |
George Mount | a712e8c | 2014-05-20 15:10:20 -0700 | [diff] [blame] | 301 | if (mIsReturning) { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 302 | return window.getSharedElementReenterTransition(); |
George Mount | a712e8c | 2014-05-20 15:10:20 -0700 | [diff] [blame] | 303 | } else { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 304 | return window.getSharedElementEnterTransition(); |
George Mount | a712e8c | 2014-05-20 15:10:20 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 308 | private void startSharedElementTransition(Bundle sharedElementState) { |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 309 | ViewGroup decorView = getDecor(); |
| 310 | if (decorView == null) { |
| 311 | return; |
| 312 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 313 | // Remove rejected shared elements |
| 314 | ArrayList<String> rejectedNames = new ArrayList<String>(mAllSharedElementNames); |
| 315 | rejectedNames.removeAll(mSharedElementNames); |
| 316 | ArrayList<View> rejectedSnapshots = createSnapshots(sharedElementState, rejectedNames); |
George Mount | 1732f52 | 2014-09-17 16:59:36 -0700 | [diff] [blame] | 317 | if (mListener != null) { |
| 318 | mListener.onRejectSharedElements(rejectedSnapshots); |
| 319 | } |
George Mount | 83c692e | 2014-10-23 11:11:17 -0700 | [diff] [blame] | 320 | removeNullViews(rejectedSnapshots); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 321 | startRejectedAnimations(rejectedSnapshots); |
| 322 | |
| 323 | // Now start shared element transition |
| 324 | ArrayList<View> sharedElementSnapshots = createSnapshots(sharedElementState, |
| 325 | mSharedElementNames); |
George Mount | ce2ee3d | 2014-09-09 15:04:31 -0700 | [diff] [blame] | 326 | showViews(mSharedElements, true); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 327 | scheduleSetSharedElementEnd(sharedElementSnapshots); |
Dake Gu | c18f4cc | 2014-07-11 17:48:37 -0700 | [diff] [blame] | 328 | ArrayList<SharedElementOriginalState> originalImageViewState = |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 329 | setSharedElementState(sharedElementState, sharedElementSnapshots); |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 330 | requestLayoutForSharedElements(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 331 | |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 332 | boolean startEnterTransition = allowOverlappingTransitions() && !mIsReturning; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 333 | boolean startSharedElementTransition = true; |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 334 | setGhostVisibility(View.INVISIBLE); |
| 335 | scheduleGhostVisibilityChange(View.INVISIBLE); |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 336 | Transition transition = beginTransition(decorView, startEnterTransition, |
| 337 | startSharedElementTransition); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 338 | scheduleGhostVisibilityChange(View.VISIBLE); |
| 339 | setGhostVisibility(View.VISIBLE); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 340 | |
| 341 | if (startEnterTransition) { |
| 342 | startEnterTransition(transition); |
| 343 | } |
| 344 | |
Dake Gu | c18f4cc | 2014-07-11 17:48:37 -0700 | [diff] [blame] | 345 | setOriginalSharedElementState(mSharedElements, originalImageViewState); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 346 | |
| 347 | if (mResultReceiver != null) { |
George Mount | e678ab6 | 2014-06-30 15:28:28 -0700 | [diff] [blame] | 348 | // We can't trust that the view will disappear on the same frame that the shared |
| 349 | // element appears here. Assure that we get at least 2 frames for double-buffering. |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 350 | decorView.postOnAnimation(new Runnable() { |
George Mount | e678ab6 | 2014-06-30 15:28:28 -0700 | [diff] [blame] | 351 | int mAnimations; |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 352 | |
George Mount | e678ab6 | 2014-06-30 15:28:28 -0700 | [diff] [blame] | 353 | @Override |
| 354 | public void run() { |
| 355 | if (mAnimations++ < MIN_ANIMATION_FRAMES) { |
George Mount | 4188d0d | 2014-09-11 17:47:11 -0700 | [diff] [blame] | 356 | View decorView = getDecor(); |
| 357 | if (decorView != null) { |
| 358 | decorView.postOnAnimation(this); |
| 359 | } |
George Mount | 407d1fa | 2014-08-28 16:11:49 -0700 | [diff] [blame] | 360 | } else if (mResultReceiver != null) { |
George Mount | e678ab6 | 2014-06-30 15:28:28 -0700 | [diff] [blame] | 361 | mResultReceiver.send(MSG_HIDE_SHARED_ELEMENTS, null); |
| 362 | mResultReceiver = null; // all done sending messages. |
| 363 | } |
| 364 | } |
| 365 | }); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 366 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 367 | } |
| 368 | |
George Mount | 83c692e | 2014-10-23 11:11:17 -0700 | [diff] [blame] | 369 | private static void removeNullViews(ArrayList<View> views) { |
| 370 | if (views != null) { |
| 371 | for (int i = views.size() - 1; i >= 0; i--) { |
| 372 | if (views.get(i) == null) { |
| 373 | views.remove(i); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 379 | private void onTakeSharedElements() { |
| 380 | if (!mIsReadyForTransition || mSharedElementsBundle == null) { |
| 381 | return; |
| 382 | } |
| 383 | final Bundle sharedElementState = mSharedElementsBundle; |
| 384 | mSharedElementsBundle = null; |
George Mount | 4dc668c | 2015-04-09 20:55:59 +0000 | [diff] [blame] | 385 | OnSharedElementsReadyListener listener = new OnSharedElementsReadyListener() { |
| 386 | @Override |
| 387 | public void onSharedElementsReady() { |
| 388 | final View decorView = getDecor(); |
| 389 | if (decorView != null) { |
| 390 | decorView.getViewTreeObserver() |
| 391 | .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 392 | @Override |
George Mount | 4dc668c | 2015-04-09 20:55:59 +0000 | [diff] [blame] | 393 | public boolean onPreDraw() { |
| 394 | decorView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 395 | startTransition(new Runnable() { |
| 396 | @Override |
| 397 | public void run() { |
| 398 | startSharedElementTransition(sharedElementState); |
| 399 | } |
| 400 | }); |
| 401 | return false; |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 402 | } |
| 403 | }); |
George Mount | 4dc668c | 2015-04-09 20:55:59 +0000 | [diff] [blame] | 404 | decorView.invalidate(); |
| 405 | } |
| 406 | } |
| 407 | }; |
| 408 | if (mListener == null) { |
| 409 | listener.onSharedElementsReady(); |
| 410 | } else { |
| 411 | mListener.onSharedElementsArrived(mSharedElementNames, mSharedElements, listener); |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 412 | } |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 413 | } |
| 414 | |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 415 | private void requestLayoutForSharedElements() { |
| 416 | int numSharedElements = mSharedElements.size(); |
| 417 | for (int i = 0; i < numSharedElements; i++) { |
| 418 | mSharedElements.get(i).requestLayout(); |
| 419 | } |
| 420 | } |
| 421 | |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 422 | private Transition beginTransition(ViewGroup decorView, boolean startEnterTransition, |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 423 | boolean startSharedElementTransition) { |
| 424 | Transition sharedElementTransition = null; |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 425 | if (startSharedElementTransition) { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 426 | if (!mSharedElementNames.isEmpty()) { |
| 427 | sharedElementTransition = configureTransition(getSharedElementTransition(), false); |
| 428 | } |
| 429 | if (sharedElementTransition == null) { |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 430 | sharedElementTransitionStarted(); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 431 | sharedElementTransitionComplete(); |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 432 | } else { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 433 | sharedElementTransition.addListener(new Transition.TransitionListenerAdapter() { |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 434 | @Override |
| 435 | public void onTransitionStart(Transition transition) { |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 436 | sharedElementTransitionStarted(); |
| 437 | } |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 438 | |
| 439 | @Override |
| 440 | public void onTransitionEnd(Transition transition) { |
| 441 | transition.removeListener(this); |
| 442 | sharedElementTransitionComplete(); |
| 443 | } |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 444 | }); |
| 445 | } |
| 446 | } |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 447 | Transition viewsTransition = null; |
| 448 | if (startEnterTransition) { |
| 449 | mIsViewsTransitionStarted = true; |
George Mount | b694e08 | 2014-09-12 07:34:52 -0700 | [diff] [blame] | 450 | if (mTransitioningViews != null && !mTransitioningViews.isEmpty()) { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 451 | viewsTransition = configureTransition(getViewsTransition(), true); |
| 452 | if (viewsTransition != null && !mIsReturning) { |
| 453 | stripOffscreenViews(); |
| 454 | } |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 455 | } |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 456 | if (viewsTransition == null) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame^] | 457 | viewsTransitionComplete(); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 458 | } else { |
| 459 | viewsTransition.forceVisibility(View.INVISIBLE, true); |
George Mount | b694e08 | 2014-09-12 07:34:52 -0700 | [diff] [blame] | 460 | final ArrayList<View> transitioningViews = mTransitioningViews; |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 461 | viewsTransition.addListener(new ContinueTransitionListener() { |
| 462 | @Override |
George Mount | a2bbbb3 | 2014-08-12 10:16:20 -0700 | [diff] [blame] | 463 | public void onTransitionStart(Transition transition) { |
| 464 | mEnterViewsTransition = transition; |
George Mount | b694e08 | 2014-09-12 07:34:52 -0700 | [diff] [blame] | 465 | if (transitioningViews != null) { |
| 466 | showViews(transitioningViews, false); |
| 467 | } |
George Mount | a2bbbb3 | 2014-08-12 10:16:20 -0700 | [diff] [blame] | 468 | super.onTransitionStart(transition); |
| 469 | } |
| 470 | |
| 471 | @Override |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 472 | public void onTransitionEnd(Transition transition) { |
George Mount | a2bbbb3 | 2014-08-12 10:16:20 -0700 | [diff] [blame] | 473 | mEnterViewsTransition = null; |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 474 | transition.removeListener(this); |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame^] | 475 | viewsTransitionComplete(); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 476 | super.onTransitionEnd(transition); |
| 477 | } |
| 478 | }); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | Transition transition = mergeTransitions(sharedElementTransition, viewsTransition); |
| 483 | if (transition != null) { |
| 484 | transition.addListener(new ContinueTransitionListener()); |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 485 | TransitionManager.beginDelayedTransition(decorView, transition); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 486 | if (startSharedElementTransition && !mSharedElementNames.isEmpty()) { |
| 487 | mSharedElements.get(0).invalidate(); |
George Mount | b694e08 | 2014-09-12 07:34:52 -0700 | [diff] [blame] | 488 | } else if (startEnterTransition && mTransitioningViews != null && |
| 489 | !mTransitioningViews.isEmpty()) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 490 | mTransitioningViews.get(0).invalidate(); |
| 491 | } |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 492 | } else { |
| 493 | transitionStarted(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 494 | } |
| 495 | return transition; |
| 496 | } |
| 497 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame^] | 498 | @Override |
| 499 | protected void onTransitionsComplete() { |
| 500 | moveSharedElementsFromOverlay(); |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 501 | } |
| 502 | |
George Mount | c93ca16 | 2014-05-23 19:21:36 -0700 | [diff] [blame] | 503 | private void sharedElementTransitionStarted() { |
| 504 | mSharedElementTransitionStarted = true; |
| 505 | if (mIsExitTransitionComplete) { |
| 506 | send(MSG_EXIT_TRANSITION_COMPLETE, null); |
| 507 | } |
| 508 | } |
| 509 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 510 | private void startEnterTransition(Transition transition) { |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 511 | ViewGroup decorView = getDecor(); |
| 512 | if (!mIsReturning && decorView != null) { |
| 513 | Drawable background = decorView.getBackground(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 514 | if (background != null) { |
| 515 | background = background.mutate(); |
George Mount | 99c82fd | 2014-09-03 07:27:47 -0700 | [diff] [blame] | 516 | getWindow().setBackgroundDrawable(background); |
George Mount | 8cab50a | 2014-05-15 09:57:17 -0700 | [diff] [blame] | 517 | mBackgroundAnimator = ObjectAnimator.ofInt(background, "alpha", 255); |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 518 | mBackgroundAnimator.setDuration(getFadeDuration()); |
George Mount | 8cab50a | 2014-05-15 09:57:17 -0700 | [diff] [blame] | 519 | mBackgroundAnimator.addListener(new AnimatorListenerAdapter() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 520 | @Override |
| 521 | public void onAnimationEnd(Animator animation) { |
| 522 | makeOpaque(); |
| 523 | } |
| 524 | }); |
George Mount | 8cab50a | 2014-05-15 09:57:17 -0700 | [diff] [blame] | 525 | mBackgroundAnimator.start(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 526 | } else if (transition != null) { |
| 527 | transition.addListener(new Transition.TransitionListenerAdapter() { |
| 528 | @Override |
| 529 | public void onTransitionEnd(Transition transition) { |
| 530 | transition.removeListener(this); |
| 531 | makeOpaque(); |
| 532 | } |
| 533 | }); |
| 534 | } else { |
| 535 | makeOpaque(); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | public void stop() { |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 541 | // Restore the background to its previous state since the |
| 542 | // Activity is stopping. |
George Mount | 700db2a | 2014-07-07 17:17:49 -0700 | [diff] [blame] | 543 | if (mBackgroundAnimator != null) { |
| 544 | mBackgroundAnimator.end(); |
| 545 | mBackgroundAnimator = null; |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 546 | } else if (mWasOpaque) { |
| 547 | ViewGroup decorView = getDecor(); |
| 548 | if (decorView != null) { |
| 549 | Drawable drawable = decorView.getBackground(); |
| 550 | if (drawable != null) { |
| 551 | drawable.setAlpha(1); |
| 552 | } |
| 553 | } |
George Mount | 700db2a | 2014-07-07 17:17:49 -0700 | [diff] [blame] | 554 | } |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 555 | makeOpaque(); |
| 556 | mIsCanceled = true; |
| 557 | mResultReceiver = null; |
George Mount | 700db2a | 2014-07-07 17:17:49 -0700 | [diff] [blame] | 558 | mActivity = null; |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 559 | moveSharedElementsFromOverlay(); |
George Mount | f1abef6 | 2014-09-22 13:58:21 -0700 | [diff] [blame] | 560 | if (mTransitioningViews != null) { |
| 561 | showViews(mTransitioningViews, true); |
| 562 | } |
| 563 | showViews(mSharedElements, true); |
George Mount | 700db2a | 2014-07-07 17:17:49 -0700 | [diff] [blame] | 564 | clearState(); |
| 565 | } |
| 566 | |
George Mount | fbd4596 | 2015-01-26 14:38:19 -0800 | [diff] [blame] | 567 | /** |
| 568 | * Cancels the enter transition. |
| 569 | * @return True if the enter transition is still pending capturing the target state. If so, |
| 570 | * any transition started on the decor will do nothing. |
| 571 | */ |
| 572 | public boolean cancelEnter() { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 573 | setGhostVisibility(View.INVISIBLE); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 574 | mHasStopped = true; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 575 | mIsCanceled = true; |
| 576 | mResultReceiver = null; |
George Mount | 8cab50a | 2014-05-15 09:57:17 -0700 | [diff] [blame] | 577 | if (mBackgroundAnimator != null) { |
| 578 | mBackgroundAnimator.cancel(); |
| 579 | mBackgroundAnimator = null; |
| 580 | } |
George Mount | 700db2a | 2014-07-07 17:17:49 -0700 | [diff] [blame] | 581 | mActivity = null; |
| 582 | clearState(); |
George Mount | fbd4596 | 2015-01-26 14:38:19 -0800 | [diff] [blame] | 583 | return super.cancelPendingTransitions(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | private void makeOpaque() { |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 587 | if (!mHasStopped && mActivity != null) { |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 588 | if (mWasOpaque) { |
| 589 | mActivity.convertFromTranslucent(); |
| 590 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 591 | mActivity = null; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | private boolean allowOverlappingTransitions() { |
| 596 | return mIsReturning ? getWindow().getAllowExitTransitionOverlap() |
| 597 | : getWindow().getAllowEnterTransitionOverlap(); |
| 598 | } |
| 599 | |
| 600 | private void startRejectedAnimations(final ArrayList<View> rejectedSnapshots) { |
| 601 | if (rejectedSnapshots == null || rejectedSnapshots.isEmpty()) { |
| 602 | return; |
| 603 | } |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 604 | final ViewGroup decorView = getDecor(); |
| 605 | if (decorView != null) { |
| 606 | ViewGroupOverlay overlay = decorView.getOverlay(); |
| 607 | ObjectAnimator animator = null; |
| 608 | int numRejected = rejectedSnapshots.size(); |
| 609 | for (int i = 0; i < numRejected; i++) { |
| 610 | View snapshot = rejectedSnapshots.get(i); |
| 611 | overlay.add(snapshot); |
| 612 | animator = ObjectAnimator.ofFloat(snapshot, View.ALPHA, 1, 0); |
| 613 | animator.start(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 614 | } |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 615 | animator.addListener(new AnimatorListenerAdapter() { |
| 616 | @Override |
| 617 | public void onAnimationEnd(Animator animation) { |
| 618 | ViewGroupOverlay overlay = decorView.getOverlay(); |
| 619 | int numRejected = rejectedSnapshots.size(); |
| 620 | for (int i = 0; i < numRejected; i++) { |
| 621 | overlay.remove(rejectedSnapshots.get(i)); |
| 622 | } |
| 623 | } |
| 624 | }); |
| 625 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | protected void onRemoteExitTransitionComplete() { |
| 629 | if (!allowOverlappingTransitions()) { |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 630 | startEnterTransitionOnly(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 633 | |
| 634 | private void startEnterTransitionOnly() { |
| 635 | startTransition(new Runnable() { |
| 636 | @Override |
| 637 | public void run() { |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 638 | boolean startEnterTransition = true; |
| 639 | boolean startSharedElementTransition = false; |
George Mount | 48bd13c | 2014-09-12 10:54:54 -0700 | [diff] [blame] | 640 | ViewGroup decorView = getDecor(); |
| 641 | if (decorView != null) { |
| 642 | Transition transition = beginTransition(decorView, startEnterTransition, |
| 643 | startSharedElementTransition); |
| 644 | startEnterTransition(transition); |
| 645 | } |
George Mount | 13ccb79 | 2014-06-06 17:02:20 -0700 | [diff] [blame] | 646 | } |
| 647 | }); |
| 648 | } |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 649 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 650 | } |