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