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.util.proto.ProtoOutputStream; 20 import android.view.SurfaceControl; 21 import android.view.SurfaceControl.Transaction; 22 import android.view.animation.Animation; 23 24 import com.android.server.wm.SurfaceAnimator.AnimationType; 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 show the wallpaper during the animation. 39 * @see Animation#getShowWallpaper() 40 */ getShowWallpaper()41 boolean getShowWallpaper(); 42 43 /** 44 * Requests to start the animation. 45 * 46 * @param animationLeash The surface to run the animation on. See {@link SurfaceAnimator} for an 47 * overview of the mechanism. This surface needs to be released by the 48 * component running the animation after {@code finishCallback} has been 49 * invoked, or after the animation was cancelled. 50 * @param t The Transaction to apply the initial frame of the animation. 51 * @param type The type of the animation. 52 * @param finishCallback The callback to be invoked when the animation has finished. 53 */ startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type, OnAnimationFinishedCallback finishCallback)54 void startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type, 55 OnAnimationFinishedCallback finishCallback); 56 57 /** 58 * Called when the animation that was started with {@link #startAnimation} was cancelled by the 59 * window manager. 60 * 61 * @param animationLeash The leash passed to {@link #startAnimation}. 62 */ onAnimationCancelled(SurfaceControl animationLeash)63 void onAnimationCancelled(SurfaceControl animationLeash); 64 65 /** 66 * @return The approximate duration of the animation, in milliseconds. 67 */ getDurationHint()68 long getDurationHint(); 69 70 /** 71 * If this animation is run as an app opening animation, this calculates the start time for all 72 * status bar transitions that happen as part of the app opening animation, which will be 73 * forwarded to SystemUI. 74 * 75 * @return the desired start time of the status bar transition, in uptime millis 76 */ getStatusBarTransitionsStartTime()77 long getStatusBarTransitionsStartTime(); 78 dump(PrintWriter pw, String prefix)79 void dump(PrintWriter pw, String prefix); 80 dumpDebug(ProtoOutputStream proto, long fieldId)81 default void dumpDebug(ProtoOutputStream proto, long fieldId) { 82 final long token = proto.start(fieldId); 83 dumpDebug(proto); 84 proto.end(token); 85 } 86 dumpDebug(ProtoOutputStream proto)87 void dumpDebug(ProtoOutputStream proto); 88 89 /** 90 * Gets called when the animation is about to finish and gives the client the opportunity to 91 * defer finishing the animation, i.e. it keeps the leash around until the client calls 92 * endDeferFinishCallback. 93 * <p> 94 * This has the same effect as 95 * {@link com.android.server.wm.SurfaceAnimator.Animatable#shouldDeferAnimationFinish(Runnable)} 96 * . The later will be evaluated first and has precedence over this method if it returns true, 97 * which means that if the {@link com.android.server.wm.SurfaceAnimator.Animatable} requests to 98 * defer its finish, this method won't be called so this adapter will never have access to the 99 * finish callback. On the other hand, if the 100 * {@link com.android.server.wm.SurfaceAnimator.Animatable}, doesn't request to defer, this 101 * {@link AnimationAdapter} is responsible for ending the animation. 102 * 103 * @param endDeferFinishCallback The callback to call when defer finishing should be ended. 104 * @return Whether the client would like to defer the animation finish. 105 */ shouldDeferAnimationFinish(Runnable endDeferFinishCallback)106 default boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) { 107 return false; 108 } 109 } 110