• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.keyguard
18 
19 import android.content.Context
20 import android.view.ViewGroup
21 import com.android.systemui.R
22 import com.android.systemui.plugins.statusbar.StatusBarStateController
23 import com.android.systemui.statusbar.StatusBarState.KEYGUARD
24 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
25 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END
26 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START
27 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
28 import com.android.systemui.unfold.SysUIUnfoldScope
29 import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
30 import javax.inject.Inject
31 
32 /**
33  * Translates items away/towards the hinge when the device is opened/closed. This is controlled by
34  * the set of ids, which also dictate which direction to move and when, via a filter function.
35  */
36 @SysUIUnfoldScope
37 class KeyguardUnfoldTransition
38 @Inject
39 constructor(
40     private val context: Context,
41     statusBarStateController: StatusBarStateController,
42     unfoldProgressProvider: NaturalRotationUnfoldProgressProvider,
43 ) {
44 
45     /** Certain views only need to move if they are not currently centered */
46     var statusViewCentered = false
47 
<lambda>null48     private val filterKeyguardAndSplitShadeOnly: () -> Boolean = {
49         statusBarStateController.getState() == KEYGUARD && !statusViewCentered }
<lambda>null50     private val filterKeyguard: () -> Boolean = { statusBarStateController.getState() == KEYGUARD }
51 
<lambda>null52     private val translateAnimator by lazy {
53         UnfoldConstantTranslateAnimator(
54             viewsIdToTranslate =
55                 setOf(
56                     ViewIdToTranslate(R.id.keyguard_status_area, START, filterKeyguard),
57                     ViewIdToTranslate(
58                         R.id.lockscreen_clock_view_large, START, filterKeyguardAndSplitShadeOnly),
59                     ViewIdToTranslate(R.id.lockscreen_clock_view, START, filterKeyguard),
60                     ViewIdToTranslate(
61                         R.id.notification_stack_scroller, END, filterKeyguardAndSplitShadeOnly),
62                     ViewIdToTranslate(R.id.start_button, START, filterKeyguard),
63                     ViewIdToTranslate(R.id.end_button, END, filterKeyguard)),
64             progressProvider = unfoldProgressProvider)
65     }
66 
67     /** Relies on the [parent] to locate views to translate. */
setupnull68     fun setup(parent: ViewGroup) {
69         val translationMax =
70             context.resources.getDimensionPixelSize(R.dimen.keyguard_unfold_translation_x).toFloat()
71         translateAnimator.init(parent, translationMax)
72     }
73 }
74