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