1 /* 2 * Copyright (C) 2018 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 com.android.quickstep.util; 17 18 import android.animation.AnimatorSet; 19 import android.app.ActivityOptions; 20 import android.content.Context; 21 import android.os.Handler; 22 23 import com.android.launcher3.LauncherAnimationRunner; 24 import com.android.launcher3.WrappedLauncherAnimationRunner; 25 import com.android.systemui.shared.system.ActivityOptionsCompat; 26 import com.android.systemui.shared.system.RemoteAnimationAdapterCompat; 27 import com.android.systemui.shared.system.RemoteAnimationTargetCompat; 28 29 public abstract class RemoteAnimationProvider { 30 31 LauncherAnimationRunner mAnimationRunner; 32 createWindowAnimation(RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets)33 public abstract AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] appTargets, 34 RemoteAnimationTargetCompat[] wallpaperTargets); 35 toActivityOptions(Handler handler, long duration, Context context)36 ActivityOptions toActivityOptions(Handler handler, long duration, Context context) { 37 mAnimationRunner = new LauncherAnimationRunner(handler, 38 false /* startAtFrontOfQueue */) { 39 40 @Override 41 public void onCreateAnimation(RemoteAnimationTargetCompat[] appTargets, 42 RemoteAnimationTargetCompat[] wallpaperTargets, AnimationResult result) { 43 result.setAnimation(createWindowAnimation(appTargets, wallpaperTargets), context); 44 } 45 }; 46 final LauncherAnimationRunner wrapper = new WrappedLauncherAnimationRunner( 47 mAnimationRunner, false /* startAtFrontOfQueue */); 48 49 return ActivityOptionsCompat.makeRemoteAnimation( 50 new RemoteAnimationAdapterCompat(wrapper, duration, 0)); 51 } 52 53 /** 54 * @return the target with the lowest opaque layer for a certain app animation, or null. 55 */ findLowestOpaqueLayerTarget( RemoteAnimationTargetCompat[] appTargets, int mode)56 public static RemoteAnimationTargetCompat findLowestOpaqueLayerTarget( 57 RemoteAnimationTargetCompat[] appTargets, int mode) { 58 int lowestLayer = Integer.MAX_VALUE; 59 int lowestLayerIndex = -1; 60 for (int i = appTargets.length - 1; i >= 0; i--) { 61 RemoteAnimationTargetCompat target = appTargets[i]; 62 if (target.mode == mode && !target.isTranslucent) { 63 int layer = target.prefixOrderIndex; 64 if (layer < lowestLayer) { 65 lowestLayer = layer; 66 lowestLayerIndex = i; 67 } 68 } 69 } 70 return lowestLayerIndex != -1 71 ? appTargets[lowestLayerIndex] 72 : null; 73 } 74 } 75