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.statusbar 18 19 import android.content.Context 20 import android.util.IndentingPrintWriter 21 import android.util.MathUtils 22 import androidx.annotation.FloatRange 23 import androidx.annotation.Px 24 import com.android.systemui.dump.DumpManager 25 import com.android.systemui.plugins.qs.QS 26 import com.android.systemui.res.R 27 import com.android.systemui.shade.ShadeDisplayAware 28 import com.android.systemui.statusbar.policy.ConfigurationController 29 import com.android.systemui.statusbar.policy.SplitShadeStateController 30 import dagger.assisted.Assisted 31 import dagger.assisted.AssistedFactory 32 import dagger.assisted.AssistedInject 33 import kotlin.math.max 34 35 /** Responsible for the QS components during the lockscreen shade transition. */ 36 class LockscreenShadeQsTransitionController 37 @AssistedInject 38 constructor( 39 @ShadeDisplayAware context: Context, 40 configurationController: ConfigurationController, 41 dumpManager: DumpManager, 42 @Assisted private val qsProvider: () -> QS?, 43 splitShadeStateController: SplitShadeStateController 44 ) : 45 AbstractLockscreenShadeTransitionController( 46 context, 47 configurationController, 48 dumpManager, 49 splitShadeStateController 50 ) { 51 52 private val qs: QS? 53 get() = qsProvider() 54 55 /** 56 * The progress fraction of the QS transition during lockscreen shade expansion. 57 * 58 * Note that this value might be 0 for some time when the expansion is already in progress, 59 * since there is a transition start delay for QS on some device configurations. For this 60 * reason, don't use this value to check whether the shade expansion is in progress. 61 */ 62 @FloatRange(from = 0.0, to = 1.0) 63 var qsTransitionFraction = 0f 64 private set 65 66 /** 67 * The fraction of the QS "squish" transition progress during lockscreen shade expansion. 68 * 69 * Note that in some device configurations (large screens) this value can start at a value 70 * greater than 0. For this reason don't use this value to check whether the QS transition has 71 * started or not. 72 */ 73 @FloatRange(from = 0.0, to = 1.0) 74 var qsSquishTransitionFraction = 0f 75 private set 76 77 /** 78 * The drag down amount, in pixels __for the QS transition__, also taking into account the 79 * [qsTransitionStartDelay]. 80 * 81 * Since it takes into account the start delay, it is __not__ the same as the raw drag down 82 * amount from the shade expansion. 83 */ 84 @Px private var qsDragDownAmount = 0f 85 86 /** 87 * Distance it takes for the QS transition to complete during the lockscreen shade expansion. 88 */ 89 @Px private var qsTransitionDistance = 0 90 91 /** Distance delay for the QS transition to start during the lockscreen shade expansion. */ 92 @Px private var qsTransitionStartDelay = 0 93 94 /** 95 * Distance that it takes to complete the QS "squish" transition during the lockscreen shade 96 * expansion. 97 */ 98 @Px private var qsSquishTransitionDistance = 0 99 100 /** 101 * Whether the transition to full shade is in progress. Might be `true` even though 102 * [qsTransitionFraction] is still 0, due to [qsTransitionStartDelay]. 103 */ 104 private var isTransitioningToFullShade = false 105 106 /** 107 * The fraction at which the QS "squish" transition should start during the lockscreen shade 108 * expansion. 109 * 110 * 0 is fully collapsed, 1 is fully expanded. 111 */ 112 @FloatRange(from = 0.0, to = 1.0) private var qsSquishStartFraction = 0f 113 updateResourcesnull114 override fun updateResources() { 115 qsTransitionDistance = 116 context.resources.getDimensionPixelSize(R.dimen.lockscreen_shade_qs_transition_distance) 117 qsTransitionStartDelay = 118 context.resources.getDimensionPixelSize(R.dimen.lockscreen_shade_qs_transition_delay) 119 qsSquishTransitionDistance = 120 context.resources.getDimensionPixelSize( 121 R.dimen.lockscreen_shade_qs_squish_transition_distance 122 ) 123 qsSquishStartFraction = 124 context.resources.getFloat(R.dimen.lockscreen_shade_qs_squish_start_fraction) 125 126 qsSquishTransitionFraction = max(qsSquishTransitionFraction, qsSquishStartFraction) 127 } 128 onDragDownAmountChangednull129 override fun onDragDownAmountChanged(dragDownAmount: Float) { 130 qsDragDownAmount = dragDownAmount - qsTransitionStartDelay 131 qsTransitionFraction = MathUtils.saturate(qsDragDownAmount / qsTransitionDistance) 132 qsSquishTransitionFraction = 133 MathUtils.lerp( 134 /* start= */ qsSquishStartFraction, 135 /* stop= */ 1f, 136 /* amount= */ MathUtils.saturate(qsDragDownAmount / qsSquishTransitionDistance) 137 ) 138 isTransitioningToFullShade = dragDownAmount > 0.0f 139 qs?.setTransitionToFullShadeProgress( 140 isTransitioningToFullShade, 141 qsTransitionFraction, 142 qsSquishTransitionFraction 143 ) 144 } 145 dumpnull146 override fun dump(pw: IndentingPrintWriter) { 147 pw.println( 148 """ 149 Resources: 150 qsTransitionDistance: $qsTransitionDistance 151 qsTransitionStartDelay: $qsTransitionStartDelay 152 qsSquishTransitionDistance: $qsSquishTransitionDistance 153 qsSquishStartFraction: $qsSquishStartFraction 154 State: 155 dragDownAmount: $dragDownAmount 156 qsDragDownAmount: $qsDragDownAmount 157 qsDragFraction: $qsTransitionFraction 158 qsSquishFraction: $qsSquishTransitionFraction 159 isTransitioningToFullShade: $isTransitioningToFullShade 160 """ 161 .trimIndent() 162 ) 163 } 164 165 @AssistedFactory interfacenull166 fun interface Factory { 167 fun create(qsProvider: () -> QS?): LockscreenShadeQsTransitionController 168 } 169 } 170