Home | History | Annotate | Download | only in clock
      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 
     24 /**
     25  * Computes preferred position of clock by considering height of status bar and lock icon.
     26  */
     27 class 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
     70         int aodY = mStatusBarHeight + mKeyguardLockPadding + mBurnInOffsetY;
     71         // On lock screen, clock needs to appear below the lock icon
     72         int lockY =  mStatusBarHeight + mKeyguardLockHeight + 2 * mKeyguardLockPadding;
     73         return (int) MathUtils.lerp(lockY, aodY, mDarkAmount);
     74     }
     75 }
     76