1 /*
2  * Copyright (C) 2022 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 com.android.quickstep.util;
18 
19 import static com.android.app.animation.Interpolators.clampToProgress;
20 import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
21 
22 import android.os.Bundle;
23 import android.os.IRemoteCallback;
24 import android.view.animation.Interpolator;
25 
26 import com.android.launcher3.util.RunnableList;
27 
28 /**
29  * Utility class containing methods to help manage animations, interpolators, and timings.
30  */
31 public class AnimUtils {
32     /**
33      * Fetches device-specific timings for the Overview > Split animation
34      * (splitscreen initiated from Overview).
35      */
getDeviceOverviewToSplitTimings(boolean isTablet)36     public static SplitAnimationTimings getDeviceOverviewToSplitTimings(boolean isTablet) {
37         return isTablet
38                 ? SplitAnimationTimings.TABLET_OVERVIEW_TO_SPLIT
39                 : SplitAnimationTimings.PHONE_OVERVIEW_TO_SPLIT;
40     }
41 
42     /**
43      * Fetches device-specific timings for the Split > Confirm animation
44      * (splitscreen confirmed by selecting a second app).
45      */
getDeviceSplitToConfirmTimings(boolean isTablet)46     public static SplitAnimationTimings getDeviceSplitToConfirmTimings(boolean isTablet) {
47         return isTablet
48                 ? SplitAnimationTimings.TABLET_SPLIT_TO_CONFIRM
49                 : SplitAnimationTimings.PHONE_SPLIT_TO_CONFIRM;
50     }
51 
52     /**
53      * Fetches device-specific timings for the app pair launch animation.
54      */
getDeviceAppPairLaunchTimings(boolean isTablet)55     public static SplitAnimationTimings getDeviceAppPairLaunchTimings(boolean isTablet) {
56         return isTablet
57                 ? SplitAnimationTimings.TABLET_APP_PAIR_LAUNCH
58                 : SplitAnimationTimings.PHONE_APP_PAIR_LAUNCH;
59     }
60 
61     /**
62      * Returns a IRemoteCallback which completes the provided list as a result
63      */
completeRunnableListCallback(RunnableList list)64     public static IRemoteCallback completeRunnableListCallback(RunnableList list) {
65         return new IRemoteCallback.Stub() {
66             @Override
67             public void sendResult(Bundle bundle) {
68                 MAIN_EXECUTOR.execute(list::executeAllAndDestroy);
69             }
70         };
71     }
72 
73     /**
74      * Returns a function that runs the given interpolator such that the entire progress is set
75      * between the given duration. That is, we set the interpolation to 0 until startDelay and reach
76      * 1 by (startDelay + duration).
77      */
78     public static Interpolator clampToDuration(Interpolator interpolator, float startDelay,
79             float duration, float totalDuration) {
80         return clampToProgress(interpolator, startDelay / totalDuration,
81                 (startDelay + duration) / totalDuration);
82     }
83 }
84