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.LauncherAnimationRunner.RemoteAnimationFactory; 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 RemoteAnimationFactory 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 = (transit, appTargets, wallpaperTargets, nonApps, result) -> 38 result.setAnimation(createWindowAnimation(appTargets, wallpaperTargets), context); 39 final LauncherAnimationRunner wrapper = new LauncherAnimationRunner( 40 handler, mAnimationRunner, false /* startAtFrontOfQueue */); 41 return ActivityOptionsCompat.makeRemoteAnimation( 42 new RemoteAnimationAdapterCompat(wrapper, duration, 0)); 43 } 44 45 /** 46 * @return the target with the lowest opaque layer for a certain app animation, or null. 47 */ findLowestOpaqueLayerTarget( RemoteAnimationTargetCompat[] appTargets, int mode)48 public static RemoteAnimationTargetCompat findLowestOpaqueLayerTarget( 49 RemoteAnimationTargetCompat[] appTargets, int mode) { 50 int lowestLayer = Integer.MAX_VALUE; 51 int lowestLayerIndex = -1; 52 for (int i = appTargets.length - 1; i >= 0; i--) { 53 RemoteAnimationTargetCompat target = appTargets[i]; 54 if (target.mode == mode && !target.isTranslucent) { 55 int layer = target.prefixOrderIndex; 56 if (layer < lowestLayer) { 57 lowestLayer = layer; 58 lowestLayerIndex = i; 59 } 60 } 61 } 62 return lowestLayerIndex != -1 63 ? appTargets[lowestLayerIndex] 64 : null; 65 } 66 } 67