• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.res.Resources;
20 import android.util.MathUtils;
21 
22 import com.android.internal.annotations.VisibleForTesting;
23 import com.android.systemui.R;
24 
25 /**
26  * Computes preferred position of clock by considering height of status bar and lock icon.
27  */
28 class 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 
SmallClockPosition(Resources res)43     SmallClockPosition(Resources res) {
44         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)
48         );
49     }
50 
51     @VisibleForTesting
SmallClockPosition(int statusBarHeight, int lockPadding, int lockHeight, int burnInY)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      */
setDarkAmount(float darkAmount)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      */
getPreferredY()69     int getPreferredY() {
70         // On AOD, clock needs to appear below the status bar with enough room for pixel shifting
71         int aodY = mStatusBarHeight + mKeyguardLockHeight + 2 * mKeyguardLockPadding
72                 + mBurnInOffsetY;
73         // 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 }
78