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