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.wm.shell.unfold.animation;
18 
19 import android.app.TaskInfo;
20 import android.view.SurfaceControl;
21 import android.view.SurfaceControl.Transaction;
22 
23 /**
24  * Interface for classes that handle animations of tasks when folding or unfolding
25  * foldable devices.
26  */
27 public interface UnfoldTaskAnimator {
28     /**
29      * Initializes the animator, this should be called once in the lifetime of the animator
30      */
init()31     default void init() {}
32 
33     /**
34      * Starts the animator, it might start listening for some events from the system.
35      * Applying animation should be done only when animator is started.
36      * Animator could be started/stopped several times.
37      */
start()38     default void start() {}
39 
40     /**
41      * Stops the animator, it could unsubscribe from system events.
42      */
stop()43     default void stop() {}
44 
45     /**
46      * If this method returns true then task updates will be propagated to
47      * the animator using the onTaskAppeared/Changed/Vanished callbacks.
48      * @return true if this task should be animated by this animator
49      */
isApplicableTask(TaskInfo taskInfo)50     default boolean isApplicableTask(TaskInfo taskInfo) {
51         return false;
52     }
53 
54     /**
55      * Called whenever a task applicable to this animator appeared
56      * (isApplicableTask returns true for this task)
57      *
58      * @param taskInfo info of the appeared task
59      * @param leash surface of the task
60      */
onTaskAppeared(TaskInfo taskInfo, SurfaceControl leash)61     default void onTaskAppeared(TaskInfo taskInfo, SurfaceControl leash) {}
62 
63     /**
64      * Called whenever a task applicable to this animator changed
65      * @param taskInfo info of the changed task
66      */
onTaskChanged(TaskInfo taskInfo)67     default void onTaskChanged(TaskInfo taskInfo) {}
68 
69     /**
70      * Called whenever a task applicable to this animator vanished
71      * @param taskInfo info of the vanished task
72      */
onTaskVanished(TaskInfo taskInfo)73     default void onTaskVanished(TaskInfo taskInfo) {}
74 
75     /**
76      * @return true if there tasks that could be potentially animated
77      */
hasActiveTasks()78     default boolean hasActiveTasks() {
79         return false;
80     }
81 
82     /**
83      * Clears all registered tasks in the animator
84      */
clearTasks()85     default void clearTasks() {}
86 
87     /**
88      * Apply task surfaces transformations based on the current unfold progress
89      * @param progress unfold transition progress
90      * @param transaction to write changes to
91      */
applyAnimationProgress(float progress, Transaction transaction)92     default void applyAnimationProgress(float progress, Transaction transaction) {}
93 
94     /**
95      * Apply task surfaces transformations that should be set before starting the animation
96      * @param transaction to write changes to
97      */
prepareStartTransaction(Transaction transaction)98     default void prepareStartTransaction(Transaction transaction) {}
99 
100     /**
101      * Apply task surfaces transformations that should be set after finishing the animation
102      * @param transaction to write changes to
103      */
prepareFinishTransaction(Transaction transaction)104     default void prepareFinishTransaction(Transaction transaction) {}
105 
106     /**
107      * Resets task surface to its initial transformation
108      * @param transaction to write changes to
109      */
resetSurface(TaskInfo taskInfo, Transaction transaction)110     default void resetSurface(TaskInfo taskInfo, Transaction transaction) {}
111 
112     /**
113      * Resets all task surfaces to their initial transformations
114      * @param transaction to write changes to
115      */
resetAllSurfaces(Transaction transaction)116     default void resetAllSurfaces(Transaction transaction) {}
117 }
118