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.systemui.shade
18 
19 import android.content.Context
20 import android.view.ViewGroup
21 import com.android.systemui.res.R
22 import com.android.systemui.plugins.statusbar.StatusBarStateController
23 import com.android.systemui.statusbar.StatusBarState.SHADE
24 import com.android.systemui.statusbar.StatusBarState.SHADE_LOCKED
25 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
26 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END
27 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START
28 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
29 import com.android.systemui.unfold.SysUIUnfoldScope
30 import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
31 import javax.inject.Inject
32 
33 @SysUIUnfoldScope
34 class NotificationPanelUnfoldAnimationController
35 @Inject
36 constructor(
37     private val context: Context,
38     statusBarStateController: StatusBarStateController,
39     progressProvider: NaturalRotationUnfoldProgressProvider,
40 ) {
41 
<lambda>null42     private val filterShade: () -> Boolean = { statusBarStateController.getState() == SHADE ||
43         statusBarStateController.getState() == SHADE_LOCKED }
44 
<lambda>null45     private val translateAnimator by lazy {
46         UnfoldConstantTranslateAnimator(
47             viewsIdToTranslate =
48                 setOf(
49                     ViewIdToTranslate(R.id.quick_settings_panel, START, filterShade),
50                     ViewIdToTranslate(R.id.qs_footer_actions, START, filterShade),
51                     ViewIdToTranslate(R.id.notification_stack_scroller, END, filterShade)),
52             progressProvider = progressProvider)
53     }
54 
<lambda>null55     private val translateAnimatorStatusBar by lazy {
56         UnfoldConstantTranslateAnimator(
57             viewsIdToTranslate =
58             setOf(
59                 ViewIdToTranslate(R.id.shade_header_system_icons, END, filterShade),
60                 ViewIdToTranslate(R.id.privacy_container, END, filterShade),
61                 ViewIdToTranslate(R.id.carrier_group, END, filterShade),
62                 ViewIdToTranslate(R.id.clock, START, filterShade),
63                 ViewIdToTranslate(R.id.date, START, filterShade)
64             ),
65             progressProvider = progressProvider
66         )
67     }
68 
setupnull69     fun setup(root: ViewGroup) {
70         val translationMax =
71             context.resources.getDimensionPixelSize(R.dimen.notification_side_paddings).toFloat()
72         translateAnimator.init(root, translationMax)
73         val splitShadeStatusBarViewGroup: ViewGroup? =
74             root.findViewById(R.id.split_shade_status_bar)
75         if (splitShadeStatusBarViewGroup != null) {
76             translateAnimatorStatusBar.init(
77                 splitShadeStatusBarViewGroup,
78                 translationMax
79             )
80         }
81     }
82 }
83