1 /*
2  * Copyright (C) 2017 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.server.wm;
18 
19 import android.annotation.ColorInt;
20 import android.util.proto.ProtoOutputStream;
21 import android.view.SurfaceControl;
22 import android.view.SurfaceControl.Transaction;
23 import android.view.animation.Animation;
24 
25 import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
26 
27 import java.io.PrintWriter;
28 
29 /**
30  * Interface that describes an animation and bridges the animation start to the component
31  * responsible for running the animation.
32  */
33 interface AnimationAdapter {
34 
35     long STATUS_BAR_TRANSITION_DURATION = 120L;
36 
37     /**
38      * @return Whether we should detach the wallpaper during the animation.
39      * @see Animation#setDetachWallpaper
40      */
getDetachWallpaper()41     boolean getDetachWallpaper();
42 
43     /**
44      * @return Whether we should show the wallpaper during the animation.
45      * @see Animation#getShowWallpaper()
46      */
getShowWallpaper()47     boolean getShowWallpaper();
48 
49     /**
50      * @return The background color behind the animation.
51      */
getBackgroundColor()52     @ColorInt int getBackgroundColor();
53 
54     /**
55      * Requests to start the animation.
56      *
57      * @param animationLeash The surface to run the animation on. See {@link SurfaceAnimator} for an
58      *                       overview of the mechanism. This surface needs to be released by the
59      *                       component running the animation after {@code finishCallback} has been
60      *                       invoked, or after the animation was cancelled.
61      * @param t The Transaction to apply the initial frame of the animation.
62      * @param finishCallback The callback to be invoked when the animation has finished.
63      */
startAnimation(SurfaceControl animationLeash, Transaction t, OnAnimationFinishedCallback finishCallback)64     void startAnimation(SurfaceControl animationLeash, Transaction t,
65             OnAnimationFinishedCallback finishCallback);
66 
67     /**
68      * Called when the animation that was started with {@link #startAnimation} was cancelled by the
69      * window manager.
70      *
71      * @param animationLeash The leash passed to {@link #startAnimation}.
72      */
onAnimationCancelled(SurfaceControl animationLeash)73     void onAnimationCancelled(SurfaceControl animationLeash);
74 
75     /**
76      * @return The approximate duration of the animation, in milliseconds.
77      */
getDurationHint()78     long getDurationHint();
79 
80     /**
81      * If this animation is run as an app opening animation, this calculates the start time for all
82      * status bar transitions that happen as part of the app opening animation, which will be
83      * forwarded to SystemUI.
84      *
85      * @return the desired start time of the status bar transition, in uptime millis
86      */
getStatusBarTransitionsStartTime()87     long getStatusBarTransitionsStartTime();
88 
dump(PrintWriter pw, String prefix)89     void dump(PrintWriter pw, String prefix);
90 
writeToProto(ProtoOutputStream proto, long fieldId)91     default void writeToProto(ProtoOutputStream proto, long fieldId) {
92         final long token = proto.start(fieldId);
93         writeToProto(proto);
94         proto.end(token);
95     }
96 
writeToProto(ProtoOutputStream proto)97     void writeToProto(ProtoOutputStream proto);
98 }
99