1 /* 2 * Copyright (C) 2014 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.systemui.statusbar.phone; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 22 import com.android.systemui.log.LogBuffer; 23 import com.android.systemui.log.core.Logger; 24 import com.android.systemui.log.dagger.KeyguardClockLog; 25 import com.android.systemui.res.R; 26 import com.android.systemui.shade.LargeScreenHeaderHelper; 27 28 import javax.inject.Inject; 29 30 /** 31 * Utility class to calculate the clock position and top padding of notifications on Keyguard. 32 */ 33 public class KeyguardClockPositionAlgorithm { 34 private static final String TAG = "KeyguardClockPositionAlgorithm"; 35 private static final boolean DEBUG = false; 36 37 /** 38 * Top margin of notifications introduced by presence of split shade header / status bar 39 */ 40 private int mSplitShadeTopNotificationsMargin; 41 42 /** 43 * Target margin for notifications and clock from the top of the screen in split shade 44 */ 45 private int mSplitShadeTargetTopMargin; 46 47 /** 48 * Doze/AOD transition amount. 49 */ 50 private float mDarkAmount; 51 52 private float mOverStretchAmount; 53 54 /** 55 * Setting if bypass is enabled. If true the clock should always be positioned like it's dark 56 * and other minor adjustments. 57 */ 58 private boolean mBypassEnabled; 59 60 /** 61 * The stackscroller padding when unlocked 62 */ 63 private int mUnlockedStackScrollerPadding; 64 65 private boolean mIsSplitShade; 66 67 private Logger mLogger; 68 69 @Inject KeyguardClockPositionAlgorithm(@eyguardClockLog LogBuffer logBuffer)70 public KeyguardClockPositionAlgorithm(@KeyguardClockLog LogBuffer logBuffer) { 71 mLogger = new Logger(logBuffer, TAG); 72 } 73 74 /** Refreshes the dimension values. */ loadDimens(Context context, Resources res)75 public void loadDimens(Context context, Resources res) { 76 mSplitShadeTopNotificationsMargin = 77 LargeScreenHeaderHelper.getLargeScreenHeaderHeight(context); 78 mSplitShadeTargetTopMargin = 79 res.getDimensionPixelSize(R.dimen.keyguard_split_shade_top_margin); 80 } 81 82 /** 83 * Sets up algorithm values. 84 */ setup(float dark, float overStretchAmount, boolean bypassEnabled, int unlockedStackScrollerPadding, boolean isSplitShade)85 public void setup(float dark, float overStretchAmount, boolean bypassEnabled, 86 int unlockedStackScrollerPadding, boolean isSplitShade) { 87 mDarkAmount = dark; 88 mOverStretchAmount = overStretchAmount; 89 mBypassEnabled = bypassEnabled; 90 mUnlockedStackScrollerPadding = unlockedStackScrollerPadding; 91 mIsSplitShade = isSplitShade; 92 } 93 run(Result result)94 public void run(Result result) { 95 result.stackScrollerPadding = getStackScrollerPadding(); 96 result.stackScrollerPaddingExpanded = getStackScrollerPaddingExpanded(); 97 } 98 getStackScrollerPaddingExpanded()99 private int getStackScrollerPaddingExpanded() { 100 if (mBypassEnabled) { 101 return mUnlockedStackScrollerPadding; 102 } else if (mIsSplitShade) { 103 return mSplitShadeTargetTopMargin; 104 } else { 105 return 0; 106 } 107 } 108 getStackScrollerPadding()109 private int getStackScrollerPadding() { 110 if (mBypassEnabled) { 111 return (int) (mUnlockedStackScrollerPadding + mOverStretchAmount); 112 } else if (mIsSplitShade) { 113 // mCurrentBurnInOffsetY is subtracted to make notifications not follow clock adjustment 114 // for burn-in. It can make pulsing notification go too high and it will get clipped 115 return mSplitShadeTargetTopMargin - mSplitShadeTopNotificationsMargin; 116 } else { 117 return 0; 118 } 119 } 120 121 public static class Result { 122 /** 123 * The top padding of the stack scroller, in pixels. 124 */ 125 public int stackScrollerPadding; 126 127 /** 128 * The top padding of the stack scroller, in pixels when fully expanded. 129 */ 130 public int stackScrollerPaddingExpanded; 131 } 132 } 133