• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.os.Handler;
21 
22 import com.android.launcher3.LauncherAnimationRunner;
23 import com.android.systemui.shared.system.ActivityOptionsCompat;
24 import com.android.systemui.shared.system.RemoteAnimationAdapterCompat;
25 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
26 import com.android.systemui.shared.system.TransactionCompat;
27 
28 @FunctionalInterface
29 public interface RemoteAnimationProvider {
30 
31     static final int Z_BOOST_BASE = 800570000;
32 
createWindowAnimation(RemoteAnimationTargetCompat[] targets)33     AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] targets);
34 
toActivityOptions(Handler handler, long duration)35     default ActivityOptions toActivityOptions(Handler handler, long duration) {
36         LauncherAnimationRunner runner = new LauncherAnimationRunner(handler,
37                 false /* startAtFrontOfQueue */) {
38 
39             @Override
40             public void onCreateAnimation(RemoteAnimationTargetCompat[] targetCompats,
41                     AnimationResult result) {
42                 result.setAnimation(createWindowAnimation(targetCompats));
43             }
44         };
45         return ActivityOptionsCompat.makeRemoteAnimation(
46                 new RemoteAnimationAdapterCompat(runner, duration, 0));
47     }
48 
49     /**
50      * Prepares the given {@param targets} for a remote animation, and should be called with the
51      * transaction from the first frame of animation.
52      *
53      * @param boostModeTargets The mode indicating which targets to boost in z-order above other
54      *                         targets.
55      */
prepareTargetsForFirstFrame(RemoteAnimationTargetCompat[] targets, TransactionCompat t, int boostModeTargets)56     static void prepareTargetsForFirstFrame(RemoteAnimationTargetCompat[] targets,
57             TransactionCompat t, int boostModeTargets) {
58         for (RemoteAnimationTargetCompat target : targets) {
59             t.setLayer(target.leash, getLayer(target, boostModeTargets));
60             t.show(target.leash);
61         }
62     }
63 
getLayer(RemoteAnimationTargetCompat target, int boostModeTarget)64     static int getLayer(RemoteAnimationTargetCompat target, int boostModeTarget) {
65         return target.mode == boostModeTarget
66                 ? Z_BOOST_BASE + target.prefixOrderIndex
67                 : target.prefixOrderIndex;
68     }
69 }
70