1 /* <lambda>null2 * 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.View 21 import com.android.systemui.keyguard.MigrateClocksToBlueprint 22 import com.android.systemui.keyguard.ui.view.KeyguardRootView 23 import com.android.systemui.plugins.statusbar.StatusBarStateController 24 import com.android.systemui.res.R 25 import com.android.systemui.shared.R as sharedR 26 import com.android.systemui.shade.NotificationShadeWindowView 27 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator 28 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END 29 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START 30 import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate 31 import com.android.systemui.statusbar.StatusBarState.KEYGUARD 32 import com.android.systemui.unfold.SysUIUnfoldScope 33 import com.android.systemui.unfold.UnfoldTransitionProgressProvider 34 import com.android.systemui.unfold.dagger.NaturalRotation 35 import javax.inject.Inject 36 37 /** 38 * Translates items away/towards the hinge when the device is opened/closed. This is controlled by 39 * the set of ids, which also dictate which direction to move and when, via a filter function. 40 */ 41 @SysUIUnfoldScope 42 class KeyguardUnfoldTransition 43 @Inject 44 constructor( 45 private val context: Context, 46 private val keyguardRootView: KeyguardRootView, 47 private val shadeWindowView: NotificationShadeWindowView, 48 statusBarStateController: StatusBarStateController, 49 @NaturalRotation unfoldProgressProvider: UnfoldTransitionProgressProvider, 50 ) { 51 52 /** Certain views only need to move if they are not currently centered */ 53 var statusViewCentered = false 54 55 private val filterKeyguardAndSplitShadeOnly: () -> Boolean = { 56 statusBarStateController.getState() == KEYGUARD && !statusViewCentered } 57 private val filterKeyguard: () -> Boolean = { statusBarStateController.getState() == KEYGUARD } 58 59 private val translateAnimator by lazy { 60 val smartSpaceViews = if (MigrateClocksToBlueprint.isEnabled) { 61 // Use scrollX instead of translationX as translation is already set by [AodBurnInLayer] 62 val scrollXTranslation = { view: View, translation: Float -> 63 view.scrollX = -translation.toInt() 64 } 65 66 setOf( 67 ViewIdToTranslate( 68 viewId = sharedR.id.date_smartspace_view, 69 direction = START, 70 shouldBeAnimated = filterKeyguard, 71 translateFunc = scrollXTranslation, 72 ), 73 ViewIdToTranslate( 74 viewId = sharedR.id.bc_smartspace_view, 75 direction = START, 76 shouldBeAnimated = filterKeyguard, 77 translateFunc = scrollXTranslation, 78 ), 79 ViewIdToTranslate( 80 viewId = sharedR.id.weather_smartspace_view, 81 direction = START, 82 shouldBeAnimated = filterKeyguard, 83 translateFunc = scrollXTranslation, 84 ) 85 ) 86 } else { 87 setOf(ViewIdToTranslate( 88 viewId = R.id.keyguard_status_area, 89 direction = START, 90 shouldBeAnimated = filterKeyguard, 91 translateFunc = { view, value -> 92 (view as? KeyguardStatusAreaView)?.translateXFromUnfold = value 93 } 94 )) 95 } 96 97 UnfoldConstantTranslateAnimator( 98 viewsIdToTranslate = 99 setOf( 100 ViewIdToTranslate( 101 viewId = R.id.lockscreen_clock_view_large, 102 direction = START, 103 shouldBeAnimated = filterKeyguardAndSplitShadeOnly 104 ), 105 ViewIdToTranslate( 106 viewId = R.id.lockscreen_clock_view, 107 direction = START, 108 shouldBeAnimated = filterKeyguard 109 ), 110 ViewIdToTranslate( 111 viewId = R.id.notification_stack_scroller, 112 direction = END, 113 shouldBeAnimated = filterKeyguardAndSplitShadeOnly 114 ) 115 ) + smartSpaceViews, 116 progressProvider = unfoldProgressProvider 117 ) 118 } 119 120 private val shortcutButtonsAnimator by lazy { 121 UnfoldConstantTranslateAnimator( 122 viewsIdToTranslate = 123 setOf( 124 ViewIdToTranslate( 125 viewId = R.id.start_button, 126 direction = START, 127 shouldBeAnimated = filterKeyguard 128 ), 129 ViewIdToTranslate( 130 viewId = R.id.end_button, 131 direction = END, 132 shouldBeAnimated = filterKeyguard 133 ) 134 ), 135 progressProvider = unfoldProgressProvider 136 ) 137 } 138 139 /** Initializes the keyguard fold/unfold transition */ 140 fun setup() { 141 val translationMax = 142 context.resources.getDimensionPixelSize(R.dimen.keyguard_unfold_translation_x).toFloat() 143 144 translateAnimator.init(shadeWindowView, translationMax) 145 146 // Use keyguard root view as there is another instance of start/end buttons with the same ID 147 // outside of the keyguard root view 148 shortcutButtonsAnimator.init(keyguardRootView, translationMax) 149 } 150 } 151