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.keyguard 18 19 import android.util.MathUtils 20 21 object BouncerPanelExpansionCalculator { 22 /** 23 * Scale the alpha/position of the host view. 24 */ 25 @JvmStatic showBouncerProgressnull26 fun showBouncerProgress(fraction: Float): Float { 27 return when { 28 fraction >= 0.9f -> 1f 29 fraction < 0.6 -> 0f 30 else -> (fraction - 0.6f) / 0.3f 31 } 32 } 33 34 /** 35 * Scale the alpha/tint of the back scrim. 36 */ 37 @JvmStatic aboutToShowBouncerProgressnull38 fun aboutToShowBouncerProgress(fraction: Float): Float { 39 return MathUtils.constrain((fraction - 0.9f) / 0.1f, 0f, 1f) 40 } 41 42 /** 43 * This will scale the alpha/position of the clock. 44 */ 45 @JvmStatic getKeyguardClockScaledExpansionnull46 fun getKeyguardClockScaledExpansion(fraction: Float): Float { 47 return MathUtils.constrain((fraction - 0.7f) / 0.3f, 0f, 1f) 48 } 49 50 /** 51 * Scale the position of the dream complications. 52 */ 53 @JvmStatic getDreamYPositionScaledExpansionnull54 fun getDreamYPositionScaledExpansion(fraction: Float): Float { 55 return when { 56 fraction >= 0.98f -> 1f 57 fraction < 0.93 -> 0f 58 else -> (fraction - 0.93f) / 0.05f 59 } 60 } 61 62 /** 63 * Scale the alpha of the dream complications. 64 */ 65 @JvmStatic getDreamAlphaScaledExpansionnull66 fun getDreamAlphaScaledExpansion(fraction: Float): Float { 67 return MathUtils.constrain((fraction - 0.94f) / 0.06f, 0f, 1f) 68 } 69 }