1 /* 2 * Copyright (C) 2019 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.clock; 18 19 import android.content.Context; 20 import android.util.MathUtils; 21 22 import com.android.internal.annotations.VisibleForTesting; 23 import com.android.internal.policy.SystemBarUtils; 24 import com.android.systemui.R; 25 26 /** 27 * Computes preferred position of clock by considering height of status bar and lock icon. 28 */ 29 class SmallClockPosition { 30 31 /** 32 * Dimensions used to determine preferred clock position. 33 */ 34 private final int mStatusBarHeight; 35 private final int mKeyguardLockPadding; 36 private final int mKeyguardLockHeight; 37 private final int mBurnInOffsetY; 38 39 /** 40 * Amount of transition between AOD and lock screen. 41 */ 42 private float mDarkAmount; 43 SmallClockPosition(Context context)44 SmallClockPosition(Context context) { 45 this(SystemBarUtils.getStatusBarHeight(context), 46 context.getResources().getDimensionPixelSize(R.dimen.keyguard_lock_padding), 47 context.getResources().getDimensionPixelSize(R.dimen.keyguard_lock_height), 48 context.getResources().getDimensionPixelSize(R.dimen.burn_in_prevention_offset_y) 49 ); 50 } 51 52 @VisibleForTesting SmallClockPosition(int statusBarHeight, int lockPadding, int lockHeight, int burnInY)53 SmallClockPosition(int statusBarHeight, int lockPadding, int lockHeight, int burnInY) { 54 mStatusBarHeight = statusBarHeight; 55 mKeyguardLockPadding = lockPadding; 56 mKeyguardLockHeight = lockHeight; 57 mBurnInOffsetY = burnInY; 58 } 59 60 /** 61 * See {@link ClockPlugin#setDarkAmount}. 62 */ setDarkAmount(float darkAmount)63 void setDarkAmount(float darkAmount) { 64 mDarkAmount = darkAmount; 65 } 66 67 /** 68 * Gets the preferred Y position accounting for status bar and lock icon heights. 69 */ getPreferredY()70 int getPreferredY() { 71 // On AOD, clock needs to appear below the status bar with enough room for pixel shifting 72 int aodY = mStatusBarHeight + mKeyguardLockHeight + 2 * mKeyguardLockPadding 73 + mBurnInOffsetY; 74 // On lock screen, clock needs to appear below the lock icon 75 int lockY = mStatusBarHeight + mKeyguardLockHeight + 2 * mKeyguardLockPadding; 76 return (int) MathUtils.lerp(lockY, aodY, mDarkAmount); 77 } 78 } 79