Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 19 | import static com.android.systemui.statusbar.phone.HeadsUpAppearanceController.CONTENT_FADE_DELAY; |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 20 | import static com.android.systemui.statusbar.phone.HeadsUpAppearanceController.CONTENT_FADE_DURATION; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 21 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 23 | import android.content.res.Configuration; |
| 24 | import android.graphics.Canvas; |
| 25 | import android.graphics.Color; |
| 26 | import android.graphics.Paint; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Icon; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
| 30 | import android.view.View; |
| 31 | |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 32 | import androidx.collection.ArrayMap; |
| 33 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 34 | import com.android.internal.statusbar.StatusBarIcon; |
Selim Cinek | 061d907 | 2016-12-20 13:17:03 +0100 | [diff] [blame] | 35 | import com.android.systemui.Interpolators; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 36 | import com.android.systemui.R; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 37 | import com.android.systemui.statusbar.AlphaOptimizedFrameLayout; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 38 | import com.android.systemui.statusbar.StatusBarIconView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 39 | import com.android.systemui.statusbar.notification.stack.AnimationFilter; |
| 40 | import com.android.systemui.statusbar.notification.stack.AnimationProperties; |
| 41 | import com.android.systemui.statusbar.notification.stack.ViewState; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 42 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 43 | import java.util.ArrayList; |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 44 | import java.util.HashMap; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * A container for notification icons. It handles overflowing icons properly and positions them |
| 48 | * correctly on the screen. |
| 49 | */ |
| 50 | public class NotificationIconContainer extends AlphaOptimizedFrameLayout { |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 51 | /** |
| 52 | * A float value indicating how much before the overflow start the icons should transform into |
| 53 | * a dot. A value of 0 means that they are exactly at the end and a value of 1 means it starts |
| 54 | * 1 icon width early. |
| 55 | */ |
| 56 | public static final float OVERFLOW_EARLY_AMOUNT = 0.2f; |
| 57 | private static final int NO_VALUE = Integer.MIN_VALUE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 58 | private static final String TAG = "NotificationIconContainer"; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 59 | private static final boolean DEBUG = false; |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 60 | private static final boolean DEBUG_OVERFLOW = false; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 61 | private static final int CANNED_ANIMATION_DURATION = 100; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 62 | private static final AnimationProperties DOT_ANIMATION_PROPERTIES = new AnimationProperties() { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 63 | private AnimationFilter mAnimationFilter = new AnimationFilter().animateX(); |
| 64 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 65 | @Override |
| 66 | public AnimationFilter getAnimationFilter() { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 67 | return mAnimationFilter; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 68 | } |
| 69 | }.setDuration(200); |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 70 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 71 | private static final AnimationProperties ICON_ANIMATION_PROPERTIES = new AnimationProperties() { |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 72 | private AnimationFilter mAnimationFilter = new AnimationFilter().animateY().animateAlpha() |
| 73 | .animateScale(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 74 | |
| 75 | @Override |
| 76 | public AnimationFilter getAnimationFilter() { |
| 77 | return mAnimationFilter; |
| 78 | } |
Selim Cinek | 061d907 | 2016-12-20 13:17:03 +0100 | [diff] [blame] | 79 | |
| 80 | }.setDuration(CANNED_ANIMATION_DURATION) |
| 81 | .setCustomInterpolator(View.TRANSLATION_Y, Interpolators.ICON_OVERSHOT); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 82 | |
Lucas Dupin | 8274aa9 | 2017-09-13 17:24:09 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Temporary AnimationProperties to avoid unnecessary allocations. |
| 85 | */ |
| 86 | private static final AnimationProperties sTempProperties = new AnimationProperties() { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 87 | private AnimationFilter mAnimationFilter = new AnimationFilter(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 88 | |
| 89 | @Override |
| 90 | public AnimationFilter getAnimationFilter() { |
| 91 | return mAnimationFilter; |
| 92 | } |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 93 | }; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 94 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 95 | private static final AnimationProperties ADD_ICON_PROPERTIES = new AnimationProperties() { |
| 96 | private AnimationFilter mAnimationFilter = new AnimationFilter().animateAlpha(); |
| 97 | |
| 98 | @Override |
| 99 | public AnimationFilter getAnimationFilter() { |
| 100 | return mAnimationFilter; |
| 101 | } |
| 102 | }.setDuration(200).setDelay(50); |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 103 | |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 104 | /** |
| 105 | * The animation property used for all icons that were not isolated, when the isolation ends. |
| 106 | * This just fades the alpha and doesn't affect the movement and has a delay. |
| 107 | */ |
| 108 | private static final AnimationProperties UNISOLATION_PROPERTY_OTHERS |
| 109 | = new AnimationProperties() { |
| 110 | private AnimationFilter mAnimationFilter = new AnimationFilter().animateAlpha(); |
| 111 | |
| 112 | @Override |
| 113 | public AnimationFilter getAnimationFilter() { |
| 114 | return mAnimationFilter; |
| 115 | } |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 116 | }.setDuration(CONTENT_FADE_DURATION); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * The animation property used for the icon when its isolation ends. |
| 120 | * This animates the translation back to the right position. |
| 121 | */ |
| 122 | private static final AnimationProperties UNISOLATION_PROPERTY = new AnimationProperties() { |
| 123 | private AnimationFilter mAnimationFilter = new AnimationFilter().animateX(); |
| 124 | |
| 125 | @Override |
| 126 | public AnimationFilter getAnimationFilter() { |
| 127 | return mAnimationFilter; |
| 128 | } |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 129 | }.setDuration(CONTENT_FADE_DURATION); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 130 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 131 | private static final int MAX_VISIBLE_ICONS_ON_LOCK = 5; |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 132 | public static final int MAX_STATIC_ICONS = 4; |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 133 | private static final int MAX_DOTS = 1; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 134 | |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 135 | private boolean mIsStaticLayout = true; |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 136 | private final HashMap<View, IconState> mIconStates = new HashMap<>(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 137 | private int mDotPadding; |
| 138 | private int mStaticDotRadius; |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 139 | private int mStaticDotDiameter; |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 140 | private int mOverflowWidth; |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 141 | private int mActualLayoutWidth = NO_VALUE; |
| 142 | private float mActualPaddingEnd = NO_VALUE; |
| 143 | private float mActualPaddingStart = NO_VALUE; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 144 | private boolean mDozing; |
| 145 | private boolean mOnLockScreen; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 146 | private boolean mChangingViewPositions; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 147 | private int mAddAnimationStartIndex = -1; |
| 148 | private int mCannedAnimationStartIndex = -1; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 149 | private int mSpeedBumpIndex = -1; |
| 150 | private int mIconSize; |
| 151 | private float mOpenedAmount = 0.0f; |
Adrian Roos | ff160ed | 2017-01-13 17:18:29 -0800 | [diff] [blame] | 152 | private boolean mDisallowNextAnimation; |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 153 | private boolean mAnimationsEnabled = true; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 154 | private ArrayMap<String, ArrayList<StatusBarIcon>> mReplacingIcons; |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 155 | // Keep track of the last visible icon so collapsed container can report on its location |
| 156 | private IconState mLastVisibleIconState; |
Lucas Dupin | 1547570 | 2018-04-04 14:32:53 -0700 | [diff] [blame] | 157 | private IconState mFirstVisibleIconState; |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 158 | private float mVisualOverflowStart; |
| 159 | // Keep track of overflow in range [0, 3] |
| 160 | private int mNumDots; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 161 | private StatusBarIconView mIsolatedIcon; |
| 162 | private Rect mIsolatedIconLocation; |
| 163 | private int[] mAbsolutePosition = new int[2]; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 164 | private View mIsolatedIconForAnimation; |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 165 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 166 | public NotificationIconContainer(Context context, AttributeSet attrs) { |
| 167 | super(context, attrs); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 168 | initDimens(); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 169 | setWillNotDraw(!(DEBUG || DEBUG_OVERFLOW)); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 172 | private void initDimens() { |
| 173 | mDotPadding = getResources().getDimensionPixelSize(R.dimen.overflow_icon_dot_padding); |
| 174 | mStaticDotRadius = getResources().getDimensionPixelSize(R.dimen.overflow_dot_radius); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 175 | mStaticDotDiameter = 2 * mStaticDotRadius; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Override |
| 179 | protected void onDraw(Canvas canvas) { |
| 180 | super.onDraw(canvas); |
| 181 | Paint paint = new Paint(); |
| 182 | paint.setColor(Color.RED); |
| 183 | paint.setStyle(Paint.Style.STROKE); |
| 184 | canvas.drawRect(getActualPaddingStart(), 0, getLayoutEnd(), getHeight(), paint); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 185 | |
| 186 | if (DEBUG_OVERFLOW) { |
| 187 | if (mLastVisibleIconState == null) { |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | int height = getHeight(); |
| 192 | int end = getFinalTranslationX(); |
| 193 | |
| 194 | // Visualize the "end" of the layout |
| 195 | paint.setColor(Color.BLUE); |
| 196 | canvas.drawLine(end, 0, end, height, paint); |
| 197 | |
Lucas Dupin | 1547570 | 2018-04-04 14:32:53 -0700 | [diff] [blame] | 198 | paint.setColor(Color.GREEN); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 199 | int lastIcon = (int) mLastVisibleIconState.xTranslation; |
| 200 | canvas.drawLine(lastIcon, 0, lastIcon, height, paint); |
| 201 | |
Lucas Dupin | 1547570 | 2018-04-04 14:32:53 -0700 | [diff] [blame] | 202 | if (mFirstVisibleIconState != null) { |
| 203 | int firstIcon = (int) mFirstVisibleIconState.xTranslation; |
| 204 | canvas.drawLine(firstIcon, 0, firstIcon, height, paint); |
| 205 | } |
| 206 | |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 207 | paint.setColor(Color.RED); |
| 208 | canvas.drawLine(mVisualOverflowStart, 0, mVisualOverflowStart, height, paint); |
| 209 | |
| 210 | paint.setColor(Color.YELLOW); |
| 211 | float overflow = getMaxOverflowStart(); |
| 212 | canvas.drawLine(overflow, 0, overflow, height, paint); |
| 213 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Override |
| 217 | protected void onConfigurationChanged(Configuration newConfig) { |
| 218 | super.onConfigurationChanged(newConfig); |
| 219 | initDimens(); |
| 220 | } |
Lucas Dupin | 1547570 | 2018-04-04 14:32:53 -0700 | [diff] [blame] | 221 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 222 | @Override |
| 223 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 224 | float centerY = getHeight() / 2.0f; |
| 225 | // we layout all our children on the left at the top |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 226 | mIconSize = 0; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 227 | for (int i = 0; i < getChildCount(); i++) { |
| 228 | View child = getChildAt(i); |
| 229 | // We need to layout all children even the GONE ones, such that the heights are |
| 230 | // calculated correctly as they are used to calculate how many we can fit on the screen |
| 231 | int width = child.getMeasuredWidth(); |
| 232 | int height = child.getMeasuredHeight(); |
| 233 | int top = (int) (centerY - height / 2.0f); |
| 234 | child.layout(0, top, width, top + height); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 235 | if (i == 0) { |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 236 | setIconSize(child.getWidth()); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 237 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 238 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 239 | getLocationOnScreen(mAbsolutePosition); |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 240 | if (mIsStaticLayout) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 241 | updateState(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 245 | private void setIconSize(int size) { |
| 246 | mIconSize = size; |
| 247 | mOverflowWidth = mIconSize + (MAX_DOTS - 1) * (mStaticDotDiameter + mDotPadding); |
| 248 | } |
| 249 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 250 | private void updateState() { |
| 251 | resetViewStates(); |
| 252 | calculateIconTranslations(); |
| 253 | applyIconStates(); |
| 254 | } |
| 255 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 256 | public void applyIconStates() { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 257 | for (int i = 0; i < getChildCount(); i++) { |
| 258 | View child = getChildAt(i); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 259 | ViewState childState = mIconStates.get(child); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 260 | if (childState != null) { |
| 261 | childState.applyToView(child); |
| 262 | } |
| 263 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 264 | mAddAnimationStartIndex = -1; |
| 265 | mCannedAnimationStartIndex = -1; |
Adrian Roos | ff160ed | 2017-01-13 17:18:29 -0800 | [diff] [blame] | 266 | mDisallowNextAnimation = false; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 267 | mIsolatedIconForAnimation = null; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public void onViewAdded(View child) { |
| 272 | super.onViewAdded(child); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 273 | boolean isReplacingIcon = isReplacingIcon(child); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 274 | if (!mChangingViewPositions) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 275 | IconState v = new IconState(); |
| 276 | if (isReplacingIcon) { |
| 277 | v.justAdded = false; |
| 278 | v.justReplaced = true; |
| 279 | } |
| 280 | mIconStates.put(child, v); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 281 | } |
| 282 | int childIndex = indexOfChild(child); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 283 | if (childIndex < getChildCount() - 1 && !isReplacingIcon |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 284 | && mIconStates.get(getChildAt(childIndex + 1)).iconAppearAmount > 0.0f) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 285 | if (mAddAnimationStartIndex < 0) { |
| 286 | mAddAnimationStartIndex = childIndex; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 287 | } else { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 288 | mAddAnimationStartIndex = Math.min(mAddAnimationStartIndex, childIndex); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 289 | } |
| 290 | } |
Selim Cinek | 04adab5 | 2017-11-28 18:22:12 +0100 | [diff] [blame] | 291 | if (child instanceof StatusBarIconView) { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 292 | ((StatusBarIconView) child).setDozing(mDozing, false, 0); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 293 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 296 | private boolean isReplacingIcon(View child) { |
| 297 | if (mReplacingIcons == null) { |
| 298 | return false; |
| 299 | } |
| 300 | if (!(child instanceof StatusBarIconView)) { |
| 301 | return false; |
| 302 | } |
| 303 | StatusBarIconView iconView = (StatusBarIconView) child; |
| 304 | Icon sourceIcon = iconView.getSourceIcon(); |
| 305 | String groupKey = iconView.getNotification().getGroupKey(); |
| 306 | ArrayList<StatusBarIcon> statusBarIcons = mReplacingIcons.get(groupKey); |
| 307 | if (statusBarIcons != null) { |
| 308 | StatusBarIcon replacedIcon = statusBarIcons.get(0); |
| 309 | if (sourceIcon.sameAs(replacedIcon.icon)) { |
| 310 | return true; |
| 311 | } |
| 312 | } |
| 313 | return false; |
| 314 | } |
| 315 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 316 | @Override |
| 317 | public void onViewRemoved(View child) { |
| 318 | super.onViewRemoved(child); |
Evan Laird | fab3416 | 2019-06-13 16:29:20 -0400 | [diff] [blame] | 319 | |
| 320 | if (child instanceof StatusBarIconView) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 321 | boolean isReplacingIcon = isReplacingIcon(child); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 322 | final StatusBarIconView icon = (StatusBarIconView) child; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 323 | if (areAnimationsEnabled(icon) && icon.getVisibleState() != StatusBarIconView.STATE_HIDDEN |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 324 | && child.getVisibility() == VISIBLE && isReplacingIcon) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 325 | int animationStartIndex = findFirstViewIndexAfter(icon.getTranslationX()); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 326 | if (mAddAnimationStartIndex < 0) { |
| 327 | mAddAnimationStartIndex = animationStartIndex; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 328 | } else { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 329 | mAddAnimationStartIndex = Math.min(mAddAnimationStartIndex, animationStartIndex); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | if (!mChangingViewPositions) { |
| 333 | mIconStates.remove(child); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 334 | if (areAnimationsEnabled(icon) && !isReplacingIcon) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 335 | addTransientView(icon, 0); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 336 | boolean isIsolatedIcon = child == mIsolatedIcon; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 337 | icon.setVisibleState(StatusBarIconView.STATE_HIDDEN, true /* animate */, |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 338 | () -> removeTransientView(icon), |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 339 | isIsolatedIcon ? CONTENT_FADE_DURATION : 0); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 340 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 345 | private boolean areAnimationsEnabled(StatusBarIconView icon) { |
| 346 | return mAnimationsEnabled || icon == mIsolatedIcon; |
| 347 | } |
| 348 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 349 | /** |
| 350 | * Finds the first view with a translation bigger then a given value |
| 351 | */ |
| 352 | private int findFirstViewIndexAfter(float translationX) { |
| 353 | for (int i = 0; i < getChildCount(); i++) { |
| 354 | View view = getChildAt(i); |
| 355 | if (view.getTranslationX() > translationX) { |
| 356 | return i; |
| 357 | } |
| 358 | } |
| 359 | return getChildCount(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 362 | public void resetViewStates() { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 363 | for (int i = 0; i < getChildCount(); i++) { |
| 364 | View view = getChildAt(i); |
| 365 | ViewState iconState = mIconStates.get(view); |
| 366 | iconState.initFrom(view); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 367 | iconState.alpha = mIsolatedIcon == null || view == mIsolatedIcon ? 1.0f : 0.0f; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 368 | iconState.hidden = false; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 369 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 372 | /** |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 373 | * Calculate the horizontal translations for each notification based on how much the icons |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 374 | * are inserted into the notification container. |
| 375 | * If this is not a whole number, the fraction means by how much the icon is appearing. |
| 376 | */ |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 377 | public void calculateIconTranslations() { |
| 378 | float translationX = getActualPaddingStart(); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 379 | int firstOverflowIndex = -1; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 380 | int childCount = getChildCount(); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 381 | int maxVisibleIcons = mOnLockScreen ? MAX_VISIBLE_ICONS_ON_LOCK : |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 382 | mIsStaticLayout ? MAX_STATIC_ICONS : childCount; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 383 | float layoutEnd = getLayoutEnd(); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 384 | float overflowStart = getMaxOverflowStart(); |
| 385 | mVisualOverflowStart = 0; |
Lucas Dupin | e87bf77 | 2018-04-05 12:48:43 -0700 | [diff] [blame] | 386 | mFirstVisibleIconState = null; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 387 | boolean hasAmbient = mSpeedBumpIndex != -1 && mSpeedBumpIndex < getChildCount(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 388 | for (int i = 0; i < childCount; i++) { |
| 389 | View view = getChildAt(i); |
| 390 | IconState iconState = mIconStates.get(view); |
| 391 | iconState.xTranslation = translationX; |
Lucas Dupin | e87bf77 | 2018-04-05 12:48:43 -0700 | [diff] [blame] | 392 | if (mFirstVisibleIconState == null) { |
| 393 | mFirstVisibleIconState = iconState; |
| 394 | } |
Adrian Roos | 14d70cb | 2017-04-25 16:46:49 -0700 | [diff] [blame] | 395 | boolean forceOverflow = mSpeedBumpIndex != -1 && i >= mSpeedBumpIndex |
| 396 | && iconState.iconAppearAmount > 0.0f || i >= maxVisibleIcons; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 397 | boolean noOverflowAfter = i == childCount - 1; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 398 | float drawingScale = mOnLockScreen && view instanceof StatusBarIconView |
| 399 | ? ((StatusBarIconView) view).getIconScaleIncreased() |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 400 | : 1f; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 401 | if (mOpenedAmount != 0.0f) { |
Adrian Roos | 14d70cb | 2017-04-25 16:46:49 -0700 | [diff] [blame] | 402 | noOverflowAfter = noOverflowAfter && !hasAmbient && !forceOverflow; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 403 | } |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 404 | iconState.visibleState = StatusBarIconView.STATE_ICON; |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 405 | |
| 406 | boolean isOverflowing = |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 407 | (translationX > (noOverflowAfter ? layoutEnd - mIconSize |
| 408 | : overflowStart - mIconSize)); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 409 | if (firstOverflowIndex == -1 && (forceOverflow || isOverflowing)) { |
Adrian Roos | 14d70cb | 2017-04-25 16:46:49 -0700 | [diff] [blame] | 410 | firstOverflowIndex = noOverflowAfter && !forceOverflow ? i - 1 : i; |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 411 | mVisualOverflowStart = layoutEnd - mOverflowWidth; |
| 412 | if (forceOverflow || mIsStaticLayout) { |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 413 | mVisualOverflowStart = Math.min(translationX, mVisualOverflowStart); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 414 | } |
| 415 | } |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 416 | translationX += iconState.iconAppearAmount * view.getWidth() * drawingScale; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 417 | } |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 418 | mNumDots = 0; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 419 | if (firstOverflowIndex != -1) { |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 420 | translationX = mVisualOverflowStart; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 421 | for (int i = firstOverflowIndex; i < childCount; i++) { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 422 | View view = getChildAt(i); |
| 423 | IconState iconState = mIconStates.get(view); |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 424 | int dotWidth = mStaticDotDiameter + mDotPadding; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 425 | iconState.xTranslation = translationX; |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 426 | if (mNumDots < MAX_DOTS) { |
| 427 | if (mNumDots == 0 && iconState.iconAppearAmount < 0.8f) { |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 428 | iconState.visibleState = StatusBarIconView.STATE_ICON; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 429 | } else { |
| 430 | iconState.visibleState = StatusBarIconView.STATE_DOT; |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 431 | mNumDots++; |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 432 | } |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 433 | translationX += (mNumDots == MAX_DOTS ? MAX_DOTS * dotWidth : dotWidth) |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 434 | * iconState.iconAppearAmount; |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 435 | mLastVisibleIconState = iconState; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 436 | } else { |
| 437 | iconState.visibleState = StatusBarIconView.STATE_HIDDEN; |
| 438 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 439 | } |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 440 | } else if (childCount > 0) { |
| 441 | View lastChild = getChildAt(childCount - 1); |
| 442 | mLastVisibleIconState = mIconStates.get(lastChild); |
Lucas Dupin | 1547570 | 2018-04-04 14:32:53 -0700 | [diff] [blame] | 443 | mFirstVisibleIconState = mIconStates.get(getChildAt(0)); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 444 | } |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 445 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 446 | boolean center = mOnLockScreen; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 447 | if (center && translationX < getLayoutEnd()) { |
| 448 | float initialTranslation = |
| 449 | mFirstVisibleIconState == null ? 0 : mFirstVisibleIconState.xTranslation; |
| 450 | |
| 451 | float contentWidth = 0; |
| 452 | if (mLastVisibleIconState != null) { |
| 453 | contentWidth = mLastVisibleIconState.xTranslation + mIconSize; |
| 454 | contentWidth = Math.min(getWidth(), contentWidth) - initialTranslation; |
| 455 | } |
| 456 | float availableSpace = getLayoutEnd() - getActualPaddingStart(); |
| 457 | float delta = (availableSpace - contentWidth) / 2; |
| 458 | |
| 459 | if (firstOverflowIndex != -1) { |
| 460 | // If we have an overflow, only count those half for centering because the dots |
| 461 | // don't have a lot of visual weight. |
| 462 | float deltaIgnoringOverflow = (getLayoutEnd() - mVisualOverflowStart) / 2; |
| 463 | delta = (deltaIgnoringOverflow + delta) / 2; |
| 464 | } |
| 465 | for (int i = 0; i < childCount; i++) { |
| 466 | View view = getChildAt(i); |
| 467 | IconState iconState = mIconStates.get(view); |
| 468 | iconState.xTranslation += delta; |
| 469 | } |
| 470 | } |
| 471 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 472 | if (isLayoutRtl()) { |
| 473 | for (int i = 0; i < childCount; i++) { |
| 474 | View view = getChildAt(i); |
| 475 | IconState iconState = mIconStates.get(view); |
| 476 | iconState.xTranslation = getWidth() - iconState.xTranslation - view.getWidth(); |
| 477 | } |
| 478 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 479 | if (mIsolatedIcon != null) { |
| 480 | IconState iconState = mIconStates.get(mIsolatedIcon); |
| 481 | if (iconState != null) { |
| 482 | // Most of the time the icon isn't yet added when this is called but only happening |
| 483 | // later |
| 484 | iconState.xTranslation = mIsolatedIconLocation.left - mAbsolutePosition[0] |
| 485 | - (1 - mIsolatedIcon.getIconScale()) * mIsolatedIcon.getWidth() / 2.0f; |
| 486 | iconState.visibleState = StatusBarIconView.STATE_ICON; |
| 487 | } |
| 488 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | private float getLayoutEnd() { |
| 492 | return getActualWidth() - getActualPaddingEnd(); |
| 493 | } |
| 494 | |
| 495 | private float getActualPaddingEnd() { |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 496 | if (mActualPaddingEnd == NO_VALUE) { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 497 | return getPaddingEnd(); |
| 498 | } |
| 499 | return mActualPaddingEnd; |
| 500 | } |
| 501 | |
| 502 | private float getActualPaddingStart() { |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 503 | if (mActualPaddingStart == NO_VALUE) { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 504 | return getPaddingStart(); |
| 505 | } |
| 506 | return mActualPaddingStart; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 510 | * Sets whether the layout should always show the same number of icons. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 511 | * If this is true, the icon positions will be updated on layout. |
| 512 | * If this if false, the layout is managed from the outside and layouting won't trigger a |
| 513 | * repositioning of the icons. |
| 514 | */ |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 515 | public void setIsStaticLayout(boolean isStaticLayout) { |
| 516 | mIsStaticLayout = isStaticLayout; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 517 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 518 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 519 | public void setActualLayoutWidth(int actualLayoutWidth) { |
| 520 | mActualLayoutWidth = actualLayoutWidth; |
| 521 | if (DEBUG) { |
| 522 | invalidate(); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | public void setActualPaddingEnd(float paddingEnd) { |
| 527 | mActualPaddingEnd = paddingEnd; |
| 528 | if (DEBUG) { |
| 529 | invalidate(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | public void setActualPaddingStart(float paddingStart) { |
| 534 | mActualPaddingStart = paddingStart; |
| 535 | if (DEBUG) { |
| 536 | invalidate(); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | public int getActualWidth() { |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 541 | if (mActualLayoutWidth == NO_VALUE) { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 542 | return getWidth(); |
| 543 | } |
| 544 | return mActualLayoutWidth; |
| 545 | } |
| 546 | |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 547 | public int getFinalTranslationX() { |
| 548 | if (mLastVisibleIconState == null) { |
| 549 | return 0; |
| 550 | } |
| 551 | |
felkachang | b623343 | 2018-07-26 19:06:30 +0800 | [diff] [blame] | 552 | int translation = (int) (isLayoutRtl() ? getWidth() - mLastVisibleIconState.xTranslation |
| 553 | : mLastVisibleIconState.xTranslation + mIconSize); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 554 | // There's a chance that last translation goes beyond the edge maybe |
| 555 | return Math.min(getWidth(), translation); |
| 556 | } |
| 557 | |
| 558 | private float getMaxOverflowStart() { |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 559 | return getLayoutEnd() - mOverflowWidth; |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 560 | } |
| 561 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 562 | public void setChangingViewPositions(boolean changingViewPositions) { |
| 563 | mChangingViewPositions = changingViewPositions; |
| 564 | } |
| 565 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 566 | public void setDozing(boolean dozing, boolean fade, long delay) { |
| 567 | mDozing = dozing; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 568 | mDisallowNextAnimation |= !fade; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 569 | for (int i = 0; i < getChildCount(); i++) { |
| 570 | View view = getChildAt(i); |
| 571 | if (view instanceof StatusBarIconView) { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 572 | ((StatusBarIconView) view).setDozing(dozing, fade, delay); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 573 | } |
| 574 | } |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 575 | } |
| 576 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 577 | public IconState getIconState(StatusBarIconView icon) { |
| 578 | return mIconStates.get(icon); |
| 579 | } |
| 580 | |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 581 | public void setSpeedBumpIndex(int speedBumpIndex) { |
| 582 | mSpeedBumpIndex = speedBumpIndex; |
| 583 | } |
| 584 | |
| 585 | public void setOpenedAmount(float expandAmount) { |
| 586 | mOpenedAmount = expandAmount; |
| 587 | } |
| 588 | |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 589 | public boolean hasOverflow() { |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 590 | return mNumDots > 0; |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 593 | /** |
| 594 | * If the overflow is in the range [1, max_dots - 1) (basically 1 or 2 dots), then |
| 595 | * extra padding will have to be accounted for |
| 596 | * |
| 597 | * This method has no meaning for non-static containers |
| 598 | */ |
| 599 | public boolean hasPartialOverflow() { |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 600 | return mNumDots > 0 && mNumDots < MAX_DOTS; |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Get padding that can account for extra dots up to the max. The only valid values for |
| 605 | * this method are for 1 or 2 dots. |
| 606 | * @return only extraDotPadding or extraDotPadding * 2 |
| 607 | */ |
| 608 | public int getPartialOverflowExtraPadding() { |
| 609 | if (!hasPartialOverflow()) { |
| 610 | return 0; |
| 611 | } |
| 612 | |
Evan Laird | 43c09a9 | 2018-03-06 09:46:49 -0500 | [diff] [blame] | 613 | int partialOverflowAmount = (MAX_DOTS - mNumDots) * (mStaticDotDiameter + mDotPadding); |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 614 | |
| 615 | int adjustedWidth = getFinalTranslationX() + partialOverflowAmount; |
| 616 | // In case we actually give too much padding... |
| 617 | if (adjustedWidth > getWidth()) { |
| 618 | partialOverflowAmount = getWidth() - getFinalTranslationX(); |
| 619 | } |
| 620 | |
| 621 | return partialOverflowAmount; |
| 622 | } |
| 623 | |
| 624 | // Give some extra room for btw notifications if we can |
| 625 | public int getNoOverflowExtraPadding() { |
| 626 | if (mNumDots != 0) { |
| 627 | return 0; |
| 628 | } |
| 629 | |
Evan Laird | 6f9e856 | 2018-05-22 19:14:50 -0400 | [diff] [blame] | 630 | int collapsedPadding = mOverflowWidth; |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 631 | |
| 632 | if (collapsedPadding + getFinalTranslationX() > getWidth()) { |
| 633 | collapsedPadding = getWidth() - getFinalTranslationX(); |
| 634 | } |
| 635 | |
| 636 | return collapsedPadding; |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 637 | } |
| 638 | |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 639 | public int getIconSize() { |
| 640 | return mIconSize; |
| 641 | } |
| 642 | |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 643 | public void setAnimationsEnabled(boolean enabled) { |
| 644 | if (!enabled && mAnimationsEnabled) { |
| 645 | for (int i = 0; i < getChildCount(); i++) { |
| 646 | View child = getChildAt(i); |
| 647 | ViewState childState = mIconStates.get(child); |
| 648 | if (childState != null) { |
| 649 | childState.cancelAnimations(child); |
| 650 | childState.applyToView(child); |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | mAnimationsEnabled = enabled; |
| 655 | } |
| 656 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 657 | public void setReplacingIcons(ArrayMap<String, ArrayList<StatusBarIcon>> replacingIcons) { |
| 658 | mReplacingIcons = replacingIcons; |
| 659 | } |
| 660 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 661 | public void showIconIsolated(StatusBarIconView icon, boolean animated) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 662 | if (animated) { |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 663 | mIsolatedIconForAnimation = icon != null ? icon : mIsolatedIcon; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 664 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 665 | mIsolatedIcon = icon; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 666 | updateState(); |
| 667 | } |
| 668 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 669 | public void setIsolatedIconLocation(Rect isolatedIconLocation, boolean requireUpdate) { |
| 670 | mIsolatedIconLocation = isolatedIconLocation; |
| 671 | if (requireUpdate) { |
| 672 | updateState(); |
| 673 | } |
| 674 | } |
| 675 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 676 | public void setOnLockScreen(boolean onLockScreen) { |
| 677 | mOnLockScreen = onLockScreen; |
| 678 | } |
| 679 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 680 | public class IconState extends ViewState { |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 681 | public static final int NO_VALUE = NotificationIconContainer.NO_VALUE; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 682 | public float iconAppearAmount = 1.0f; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 683 | public float clampedAppearAmount = 1.0f; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 684 | public int visibleState; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 685 | public boolean justAdded = true; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 686 | private boolean justReplaced; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 687 | public boolean needsCannedAnimation; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 688 | public boolean useFullTransitionAmount; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 689 | public boolean useLinearTransitionAmount; |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 690 | public boolean translateContent; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 691 | public int iconColor = StatusBarIconView.NO_COLOR; |
Selim Cinek | 44d81a6 | 2017-05-08 19:45:40 -0700 | [diff] [blame] | 692 | public boolean noAnimations; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 693 | public boolean isLastExpandIcon; |
| 694 | public int customTransformHeight = NO_VALUE; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 695 | |
| 696 | @Override |
| 697 | public void applyToView(View view) { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 698 | if (view instanceof StatusBarIconView) { |
| 699 | StatusBarIconView icon = (StatusBarIconView) view; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 700 | boolean animate = false; |
| 701 | AnimationProperties animationProperties = null; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 702 | boolean animationsAllowed = areAnimationsEnabled(icon) && !mDisallowNextAnimation |
Selim Cinek | 44d81a6 | 2017-05-08 19:45:40 -0700 | [diff] [blame] | 703 | && !noAnimations; |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 704 | if (animationsAllowed) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 705 | if (justAdded || justReplaced) { |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 706 | super.applyToView(icon); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 707 | if (justAdded && iconAppearAmount != 0.0f) { |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 708 | icon.setAlpha(0.0f); |
| 709 | icon.setVisibleState(StatusBarIconView.STATE_HIDDEN, |
| 710 | false /* animate */); |
| 711 | animationProperties = ADD_ICON_PROPERTIES; |
| 712 | animate = true; |
| 713 | } |
| 714 | } else if (visibleState != icon.getVisibleState()) { |
| 715 | animationProperties = DOT_ANIMATION_PROPERTIES; |
Selim Cinek | edebced | 2017-02-03 12:34:16 -0800 | [diff] [blame] | 716 | animate = true; |
| 717 | } |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 718 | if (!animate && mAddAnimationStartIndex >= 0 |
| 719 | && indexOfChild(view) >= mAddAnimationStartIndex |
| 720 | && (icon.getVisibleState() != StatusBarIconView.STATE_HIDDEN |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 721 | || visibleState != StatusBarIconView.STATE_HIDDEN)) { |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 722 | animationProperties = DOT_ANIMATION_PROPERTIES; |
| 723 | animate = true; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 724 | } |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 725 | if (needsCannedAnimation) { |
Lucas Dupin | 8274aa9 | 2017-09-13 17:24:09 -0700 | [diff] [blame] | 726 | AnimationFilter animationFilter = sTempProperties.getAnimationFilter(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 727 | animationFilter.reset(); |
| 728 | animationFilter.combineFilter( |
| 729 | ICON_ANIMATION_PROPERTIES.getAnimationFilter()); |
Lucas Dupin | 8274aa9 | 2017-09-13 17:24:09 -0700 | [diff] [blame] | 730 | sTempProperties.resetCustomInterpolators(); |
| 731 | sTempProperties.combineCustomInterpolators(ICON_ANIMATION_PROPERTIES); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 732 | if (animationProperties != null) { |
| 733 | animationFilter.combineFilter(animationProperties.getAnimationFilter()); |
Lucas Dupin | 8274aa9 | 2017-09-13 17:24:09 -0700 | [diff] [blame] | 734 | sTempProperties.combineCustomInterpolators(animationProperties); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 735 | } |
Lucas Dupin | 8274aa9 | 2017-09-13 17:24:09 -0700 | [diff] [blame] | 736 | animationProperties = sTempProperties; |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 737 | animationProperties.setDuration(CANNED_ANIMATION_DURATION); |
| 738 | animate = true; |
| 739 | mCannedAnimationStartIndex = indexOfChild(view); |
| 740 | } |
| 741 | if (!animate && mCannedAnimationStartIndex >= 0 |
| 742 | && indexOfChild(view) > mCannedAnimationStartIndex |
| 743 | && (icon.getVisibleState() != StatusBarIconView.STATE_HIDDEN |
| 744 | || visibleState != StatusBarIconView.STATE_HIDDEN)) { |
Lucas Dupin | 8274aa9 | 2017-09-13 17:24:09 -0700 | [diff] [blame] | 745 | AnimationFilter animationFilter = sTempProperties.getAnimationFilter(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 746 | animationFilter.reset(); |
| 747 | animationFilter.animateX(); |
Lucas Dupin | 8274aa9 | 2017-09-13 17:24:09 -0700 | [diff] [blame] | 748 | sTempProperties.resetCustomInterpolators(); |
| 749 | animationProperties = sTempProperties; |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 750 | animationProperties.setDuration(CANNED_ANIMATION_DURATION); |
| 751 | animate = true; |
| 752 | } |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 753 | if (mIsolatedIconForAnimation != null) { |
| 754 | if (view == mIsolatedIconForAnimation) { |
| 755 | animationProperties = UNISOLATION_PROPERTY; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 756 | animationProperties.setDelay( |
| 757 | mIsolatedIcon != null ? CONTENT_FADE_DELAY : 0); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 758 | } else { |
| 759 | animationProperties = UNISOLATION_PROPERTY_OTHERS; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 760 | animationProperties.setDelay( |
| 761 | mIsolatedIcon == null ? CONTENT_FADE_DELAY : 0); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 762 | } |
| 763 | animate = true; |
| 764 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 765 | } |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 766 | icon.setVisibleState(visibleState, animationsAllowed); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 767 | icon.setIconColor(iconColor, needsCannedAnimation && animationsAllowed); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 768 | if (animate) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 769 | animateTo(icon, animationProperties); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 770 | } else { |
| 771 | super.applyToView(view); |
| 772 | } |
Selim Cinek | d95ca7c | 2017-07-26 12:20:38 -0700 | [diff] [blame] | 773 | boolean inShelf = iconAppearAmount == 1.0f; |
| 774 | icon.setIsInShelf(inShelf); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 775 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 776 | justAdded = false; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 777 | justReplaced = false; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 778 | needsCannedAnimation = false; |
| 779 | } |
| 780 | |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 781 | public boolean hasCustomTransformHeight() { |
| 782 | return isLastExpandIcon && customTransformHeight != NO_VALUE; |
| 783 | } |
| 784 | |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 785 | @Override |
| 786 | public void initFrom(View view) { |
| 787 | super.initFrom(view); |
| 788 | if (view instanceof StatusBarIconView) { |
| 789 | iconColor = ((StatusBarIconView) view).getStaticDrawableColor(); |
| 790 | } |
| 791 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 792 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 793 | } |