Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 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 | |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 19 | import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInOffset; |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 20 | import static com.android.systemui.statusbar.notification.NotificationUtils.interpolate; |
| 21 | |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 22 | import android.content.res.Resources; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 23 | import android.util.MathUtils; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 24 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 25 | import com.android.keyguard.KeyguardStatusView; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 26 | import com.android.systemui.Interpolators; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 27 | import com.android.systemui.R; |
| 28 | |
| 29 | /** |
| 30 | * Utility class to calculate the clock position and top padding of notifications on Keyguard. |
| 31 | */ |
| 32 | public class KeyguardClockPositionAlgorithm { |
| 33 | |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 34 | /** |
| 35 | * How much the clock height influences the shade position. |
| 36 | * 0 means nothing, 1 means move the shade up by the height of the clock |
| 37 | * 0.5f means move the shade up by half of the size of the clock. |
| 38 | */ |
| 39 | private static float CLOCK_HEIGHT_WEIGHT = 0.7f; |
| 40 | |
| 41 | /** |
| 42 | * Margin between the bottom of the clock and the notification shade. |
| 43 | */ |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 44 | private int mClockNotificationsMargin; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 47 | * Height of the parent view - display size in px. |
| 48 | */ |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 49 | private int mHeight; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Height of {@link KeyguardStatusView}. |
| 53 | */ |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 54 | private int mKeyguardStatusHeight; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
Robert Snoeberger | 6995680 | 2019-04-16 16:55:21 -0400 | [diff] [blame] | 57 | * Preferred Y position of clock. |
| 58 | */ |
| 59 | private int mClockPreferredY; |
| 60 | |
| 61 | /** |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 62 | * Whether or not there is a custom clock face on keyguard. |
| 63 | */ |
| 64 | private boolean mHasCustomClock; |
| 65 | |
| 66 | /** |
| 67 | * Whether or not the NSSL contains any visible notifications. |
| 68 | */ |
| 69 | private boolean mHasVisibleNotifs; |
| 70 | |
| 71 | /** |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 72 | * Height of notification stack: Sum of height of each notification. |
| 73 | */ |
| 74 | private int mNotificationStackHeight; |
| 75 | |
| 76 | /** |
| 77 | * Minimum top margin to avoid overlap with status bar. |
| 78 | */ |
| 79 | private int mMinTopMargin; |
| 80 | |
| 81 | /** |
| 82 | * Maximum bottom padding to avoid overlap with {@link KeyguardBottomAreaView} or |
| 83 | * the ambient indication. |
| 84 | */ |
| 85 | private int mMaxShadeBottom; |
| 86 | |
| 87 | /** |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 88 | * Minimum distance from the status bar. |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 89 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 90 | private int mContainerTopPadding; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 93 | * @see NotificationPanelView#getExpandedFraction() |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 94 | */ |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 95 | private float mPanelExpansion; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Burn-in prevention x translation. |
| 99 | */ |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 100 | private int mBurnInPreventionOffsetX; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Burn-in prevention y translation. |
| 104 | */ |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 105 | private int mBurnInPreventionOffsetY; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 106 | |
| 107 | /** |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 108 | * Doze/AOD transition amount. |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 109 | */ |
Adrian Roos | 52414e3 | 2017-04-28 09:23:19 -0700 | [diff] [blame] | 110 | private float mDarkAmount; |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 111 | |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 112 | private float mEmptyDragAmount; |
Lucas Dupin | 4c2aa39 | 2018-03-28 18:00:45 -0700 | [diff] [blame] | 113 | |
| 114 | /** |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 115 | * Refreshes the dimension values. |
| 116 | */ |
| 117 | public void loadDimens(Resources res) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 118 | mClockNotificationsMargin = res.getDimensionPixelSize( |
| 119 | R.dimen.keyguard_clock_notifications_margin); |
Robert Snoeberger | 69969c2 | 2019-05-02 16:44:11 -0400 | [diff] [blame] | 120 | // Consider the lock icon when determining the minimum top padding between the status bar |
| 121 | // and top of the clock. |
| 122 | mContainerTopPadding = Math.max(res.getDimensionPixelSize( |
| 123 | R.dimen.keyguard_clock_top_margin), |
| 124 | res.getDimensionPixelSize(R.dimen.keyguard_lock_height) |
| 125 | + res.getDimensionPixelSize(R.dimen.keyguard_lock_padding) |
| 126 | + res.getDimensionPixelSize(R.dimen.keyguard_clock_lock_margin)); |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 127 | mBurnInPreventionOffsetX = res.getDimensionPixelSize( |
| 128 | R.dimen.burn_in_prevention_offset_x); |
| 129 | mBurnInPreventionOffsetY = res.getDimensionPixelSize( |
| 130 | R.dimen.burn_in_prevention_offset_y); |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 133 | public void setup(int minTopMargin, int maxShadeBottom, int notificationStackHeight, |
Robert Snoeberger | 6995680 | 2019-04-16 16:55:21 -0400 | [diff] [blame] | 134 | float panelExpansion, int parentHeight, int keyguardStatusHeight, int clockPreferredY, |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 135 | boolean hasCustomClock, boolean hasVisibleNotifs, float dark, float emptyDragAmount) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 136 | mMinTopMargin = minTopMargin + mContainerTopPadding; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 137 | mMaxShadeBottom = maxShadeBottom; |
| 138 | mNotificationStackHeight = notificationStackHeight; |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 139 | mPanelExpansion = panelExpansion; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 140 | mHeight = parentHeight; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 141 | mKeyguardStatusHeight = keyguardStatusHeight; |
Robert Snoeberger | 6995680 | 2019-04-16 16:55:21 -0400 | [diff] [blame] | 142 | mClockPreferredY = clockPreferredY; |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 143 | mHasCustomClock = hasCustomClock; |
| 144 | mHasVisibleNotifs = hasVisibleNotifs; |
Adrian Roos | 52414e3 | 2017-04-28 09:23:19 -0700 | [diff] [blame] | 145 | mDarkAmount = dark; |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 146 | mEmptyDragAmount = emptyDragAmount; |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 149 | public void run(Result result) { |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 150 | final int y = getClockY(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 151 | result.clockY = y; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 152 | result.clockAlpha = getClockAlpha(y); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 153 | result.stackScrollerPadding = y + mKeyguardStatusHeight; |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 154 | result.clockX = (int) interpolate(0, burnInPreventionOffsetX(), mDarkAmount); |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 157 | public float getMinStackScrollerPadding() { |
| 158 | return mMinTopMargin + mKeyguardStatusHeight + mClockNotificationsMargin; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 161 | private int getMaxClockY() { |
| 162 | return mHeight / 2 - mKeyguardStatusHeight - mClockNotificationsMargin; |
| 163 | } |
| 164 | |
Robert Snoeberger | 6995680 | 2019-04-16 16:55:21 -0400 | [diff] [blame] | 165 | private int getPreferredClockY() { |
Robert Snoeberger | 4cbd159 | 2019-04-24 14:20:38 -0400 | [diff] [blame] | 166 | return mClockPreferredY; |
| 167 | } |
| 168 | |
| 169 | private int getExpandedPreferredClockY() { |
| 170 | return (mHasCustomClock && !mHasVisibleNotifs) ? getPreferredClockY() |
| 171 | : getExpandedClockPosition(); |
Robert Snoeberger | 6995680 | 2019-04-16 16:55:21 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 174 | /** |
| 175 | * Vertically align the clock and the shade in the available space considering only |
| 176 | * a percentage of the clock height defined by {@code CLOCK_HEIGHT_WEIGHT}. |
| 177 | * @return Clock Y in pixels. |
| 178 | */ |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 179 | public int getExpandedClockPosition() { |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 180 | final int availableHeight = mMaxShadeBottom - mMinTopMargin; |
| 181 | final int containerCenter = mMinTopMargin + availableHeight / 2; |
| 182 | |
| 183 | float y = containerCenter - mKeyguardStatusHeight * CLOCK_HEIGHT_WEIGHT |
| 184 | - mClockNotificationsMargin - mNotificationStackHeight / 2; |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 185 | if (y < mMinTopMargin) { |
| 186 | y = mMinTopMargin; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | // Don't allow the clock base to be under half of the screen |
| 190 | final float maxClockY = getMaxClockY(); |
| 191 | if (y > maxClockY) { |
| 192 | y = maxClockY; |
| 193 | } |
| 194 | |
| 195 | return (int) y; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | private int getClockY() { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 199 | // Dark: Align the bottom edge of the clock at about half of the screen: |
Robert Snoeberger | 4cbd159 | 2019-04-24 14:20:38 -0400 | [diff] [blame] | 200 | float clockYDark = (mHasCustomClock ? getPreferredClockY() : getMaxClockY()) |
| 201 | + burnInPreventionOffsetY(); |
Robert Snoeberger | 10b6353 | 2018-11-07 16:14:11 -0500 | [diff] [blame] | 202 | clockYDark = MathUtils.max(0, clockYDark); |
Lucas Dupin | 5605734 | 2018-04-10 11:49:18 -0700 | [diff] [blame] | 203 | |
Robert Snoeberger | 4cbd159 | 2019-04-24 14:20:38 -0400 | [diff] [blame] | 204 | float clockYRegular = getExpandedPreferredClockY(); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 205 | float clockYBouncer = -mKeyguardStatusHeight; |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 206 | |
| 207 | // Move clock up while collapsing the shade |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 208 | float shadeExpansion = Interpolators.FAST_OUT_LINEAR_IN.getInterpolation(mPanelExpansion); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 209 | float clockY = MathUtils.lerp(clockYBouncer, clockYRegular, shadeExpansion); |
| 210 | clockYDark = MathUtils.lerp(clockYBouncer, clockYDark, shadeExpansion); |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 211 | |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 212 | return (int) (MathUtils.lerp(clockY, clockYDark, mDarkAmount) + mEmptyDragAmount); |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 215 | /** |
| 216 | * We might want to fade out the clock when the user is swiping up. |
| 217 | * One exception is when the bouncer will become visible, in this cause the clock |
| 218 | * should always persist. |
| 219 | * |
| 220 | * @param y Current clock Y. |
| 221 | * @return Alpha from 0 to 1. |
| 222 | */ |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 223 | private float getClockAlpha(int y) { |
Robert Snoeberger | 4cbd159 | 2019-04-24 14:20:38 -0400 | [diff] [blame] | 224 | float alphaKeyguard = Math.max(0, y / Math.max(1f, getExpandedPreferredClockY())); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 225 | alphaKeyguard = Interpolators.ACCELERATE.getInterpolation(alphaKeyguard); |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 226 | return MathUtils.lerp(alphaKeyguard, 1f, mDarkAmount); |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | private float burnInPreventionOffsetY() { |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 230 | return getBurnInOffset(mBurnInPreventionOffsetY * 2, false /* xAxis */) |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 231 | - mBurnInPreventionOffsetY; |
| 232 | } |
| 233 | |
| 234 | private float burnInPreventionOffsetX() { |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 235 | return getBurnInOffset(mBurnInPreventionOffsetX * 2, true /* xAxis */) |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 236 | - mBurnInPreventionOffsetX; |
| 237 | } |
| 238 | |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 239 | public static class Result { |
| 240 | |
| 241 | /** |
Lucas Dupin | 41ff695 | 2018-02-18 19:39:32 -0800 | [diff] [blame] | 242 | * The x translation of the clock. |
| 243 | */ |
| 244 | public int clockX; |
| 245 | |
| 246 | /** |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 247 | * The y translation of the clock. |
| 248 | */ |
| 249 | public int clockY; |
| 250 | |
| 251 | /** |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 252 | * The alpha value of the clock. |
| 253 | */ |
| 254 | public float clockAlpha; |
| 255 | |
| 256 | /** |
| 257 | * The top padding of the stack scroller, in pixels. |
| 258 | */ |
| 259 | public int stackScrollerPadding; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 260 | } |
| 261 | } |