1 /*
<lambda>null2  * Copyright (C) 2023 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.systemui.keyguard.ui.view.layout.blueprints.transitions
18 
19 import android.animation.Animator
20 import android.animation.ObjectAnimator
21 import android.transition.ChangeBounds
22 import android.transition.Transition
23 import android.transition.TransitionSet
24 import android.transition.TransitionValues
25 import android.transition.Visibility
26 import android.view.View
27 import android.view.ViewGroup
28 import androidx.constraintlayout.helper.widget.Layer
29 import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
30 import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView
31 
32 class BaseBlueprintTransition(val clockViewModel: KeyguardClockViewModel) : TransitionSet() {
33     init {
34         ordering = ORDERING_SEQUENTIAL
35         addTransition(AlphaOutVisibility())
36             .addTransition(ChangeBounds())
37             .addTransition(AlphaInVisibility())
38         excludeTarget(Layer::class.java, /* exclude= */ true)
39         excludeClockAndSmartspaceViews(this)
40     }
41 
42     private fun excludeClockAndSmartspaceViews(transition: Transition) {
43         transition.excludeTarget(SmartspaceView::class.java, true)
44         clockViewModel.currentClock.value?.let { clock ->
45             clock.largeClock.layout.views.forEach { view -> transition.excludeTarget(view, true) }
46             clock.smallClock.layout.views.forEach { view -> transition.excludeTarget(view, true) }
47         }
48     }
49 
50     class AlphaOutVisibility : Visibility() {
51         override fun onDisappear(
52             sceneRoot: ViewGroup?,
53             view: View,
54             startValues: TransitionValues?,
55             endValues: TransitionValues?
56         ): Animator {
57             return ObjectAnimator.ofFloat(view, "alpha", 0f).apply {
58                 addUpdateListener { view.alpha = it.animatedValue as Float }
59                 start()
60             }
61         }
62     }
63 
64     class AlphaInVisibility : Visibility() {
65         override fun onAppear(
66             sceneRoot: ViewGroup?,
67             view: View,
68             startValues: TransitionValues?,
69             endValues: TransitionValues?
70         ): Animator {
71             return ObjectAnimator.ofFloat(view, "alpha", 1f).apply {
72                 addUpdateListener { view.alpha = it.animatedValue as Float }
73                 start()
74             }
75         }
76     }
77 }
78