blob: 60ca945278f6faee607e9ec92955dcd27ea8c365 [file] [log] [blame]
Robert Snoeberger4cbd1592019-04-24 14:20:38 -04001/*
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
17package com.android.keyguard.clock;
18
19import android.content.res.Resources;
20import android.util.MathUtils;
21
22import com.android.internal.annotations.VisibleForTesting;
23
24/**
25 * Computes preferred position of clock by considering height of status bar and lock icon.
26 */
27class SmallClockPosition {
28
29 /**
30 * Dimensions used to determine preferred clock position.
31 */
32 private final int mStatusBarHeight;
33 private final int mKeyguardLockPadding;
34 private final int mKeyguardLockHeight;
35 private final int mBurnInOffsetY;
36
37 /**
38 * Amount of transition between AOD and lock screen.
39 */
40 private float mDarkAmount;
41
42 SmallClockPosition(Resources res) {
43 this(res.getDimensionPixelSize(com.android.keyguard.R.dimen.status_bar_height),
44 res.getDimensionPixelSize(com.android.keyguard.R.dimen.keyguard_lock_padding),
45 res.getDimensionPixelSize(com.android.keyguard.R.dimen.keyguard_lock_height),
46 res.getDimensionPixelSize(com.android.keyguard.R.dimen.burn_in_prevention_offset_y)
47 );
48 }
49
50 @VisibleForTesting
51 SmallClockPosition(int statusBarHeight, int lockPadding, int lockHeight, int burnInY) {
52 mStatusBarHeight = statusBarHeight;
53 mKeyguardLockPadding = lockPadding;
54 mKeyguardLockHeight = lockHeight;
55 mBurnInOffsetY = burnInY;
56 }
57
58 /**
59 * See {@link ClockPlugin#setDarkAmount}.
60 */
61 void setDarkAmount(float darkAmount) {
62 mDarkAmount = darkAmount;
63 }
64
65 /**
66 * Gets the preferred Y position accounting for status bar and lock icon heights.
67 */
68 int getPreferredY() {
69 // On AOD, clock needs to appear below the status bar with enough room for pixel shifting
Robert Snoeberger2f33abb2019-06-03 17:33:09 -040070 int aodY = mStatusBarHeight + mKeyguardLockHeight + 2 * mKeyguardLockPadding
71 + mBurnInOffsetY;
Robert Snoeberger4cbd1592019-04-24 14:20:38 -040072 // On lock screen, clock needs to appear below the lock icon
73 int lockY = mStatusBarHeight + mKeyguardLockHeight + 2 * mKeyguardLockPadding;
74 return (int) MathUtils.lerp(lockY, aodY, mDarkAmount);
75 }
76}