• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 android.animation.AnimatorSet
20 import android.content.Context
21 import com.android.launcher3.Flags
22 import com.android.launcher3.LauncherAnimationRunner.AnimationResult
23 import com.android.launcher3.anim.AnimatorListeners.forEndCallback
24 import com.android.launcher3.util.RunnableList
25 
26 /** Interface to represent animation for back to Launcher transition */
27 interface BackAnimState {
28 
addOnAnimCompleteCallbacknull29     fun addOnAnimCompleteCallback(r: Runnable)
30 
31     fun applyToAnimationResult(result: AnimationResult, c: Context)
32 
33     fun start()
34 }
35 
36 class AnimatorBackState(private val springAnim: RectFSpringAnim?, private val anim: AnimatorSet?) :
37     BackAnimState {
38 
39     override fun addOnAnimCompleteCallback(r: Runnable) {
40         val animWait = RunnableList()
41         if (Flags.predictiveBackToHomePolish()) {
42             springAnim?.addAnimatorListener(forEndCallback(animWait::executeAllAndDestroy))
43                 ?: anim?.addListener(forEndCallback(animWait::executeAllAndDestroy))
44                 ?: animWait.executeAllAndDestroy()
45         } else {
46             val springAnimWait = RunnableList()
47             springAnim?.addAnimatorListener(forEndCallback(springAnimWait::executeAllAndDestroy))
48                 ?: springAnimWait.executeAllAndDestroy()
49 
50             anim?.addListener(
51                 forEndCallback(Runnable { springAnimWait.add(animWait::executeAllAndDestroy) })
52             ) ?: springAnimWait.add(animWait::executeAllAndDestroy)
53         }
54         animWait.add(r)
55     }
56 
57     override fun applyToAnimationResult(result: AnimationResult, c: Context) {
58         result.setAnimation(anim, c)
59     }
60 
61     override fun start() {
62         anim?.start()
63     }
64 }
65 
66 class AlreadyStartedBackAnimState(private val onEndCallback: RunnableList) : BackAnimState {
67 
addOnAnimCompleteCallbacknull68     override fun addOnAnimCompleteCallback(r: Runnable) {
69         onEndCallback.add(r)
70     }
71 
applyToAnimationResultnull72     override fun applyToAnimationResult(result: AnimationResult, c: Context) {
73         addOnAnimCompleteCallback(result::onAnimationFinished)
74     }
75 
startnull76     override fun start() {}
77 }
78