blob: 38d266dccc680d88bf821b2807ee09bb6296eabb [file] [log] [blame]
Selim Cinek281c2022016-10-13 19:14:43 -07001/*
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
17package com.android.systemui.statusbar;
18
Selim Cinek1f624952017-06-08 19:11:50 -070019import static com.android.systemui.statusbar.phone.NotificationIconContainer.IconState.NO_VALUE;
Selim Cinek1f624952017-06-08 19:11:50 -070020
Selim Cinek281c2022016-10-13 19:14:43 -070021import android.content.Context;
22import android.content.res.Configuration;
Anthony Chen9e05d462017-04-07 10:10:21 -070023import android.content.res.Resources;
Selim Cinek6eaacf22017-09-07 18:53:17 -070024import android.graphics.Rect;
Selim Cinek2b549f42016-11-22 16:38:51 -080025import android.os.SystemProperties;
Selim Cinek281c2022016-10-13 19:14:43 -070026import android.util.AttributeSet;
Selim Cinekb7bafbc2017-12-21 11:33:26 -080027import android.util.Log;
Lucas Dupinb561eda2018-04-09 17:25:04 -070028import android.util.MathUtils;
Selim Cinek281c2022016-10-13 19:14:43 -070029import android.view.View;
30import android.view.ViewGroup;
Selim Cinek6eaacf22017-09-07 18:53:17 -070031import android.view.ViewTreeObserver;
Selim Cinekaca84c02017-04-05 16:28:56 -070032import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek1f624952017-06-08 19:11:50 -070033
Selim Cinek9458b192016-10-25 19:02:42 -070034import com.android.systemui.Interpolators;
Selim Cinek281c2022016-10-13 19:14:43 -070035import com.android.systemui.R;
Selim Cinek281c2022016-10-13 19:14:43 -070036import com.android.systemui.statusbar.notification.NotificationUtils;
Rohan Shah20790b82018-07-02 17:21:04 -070037import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
38import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
39import com.android.systemui.statusbar.notification.row.ExpandableView;
Selim Cinek281c2022016-10-13 19:14:43 -070040import com.android.systemui.statusbar.phone.NotificationIconContainer;
Rohan Shah20790b82018-07-02 17:21:04 -070041import com.android.systemui.statusbar.notification.stack.AmbientState;
42import com.android.systemui.statusbar.notification.stack.AnimationProperties;
43import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
44import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
45import com.android.systemui.statusbar.notification.stack.StackScrollState;
46import com.android.systemui.statusbar.notification.stack.ViewState;
Selim Cinek281c2022016-10-13 19:14:43 -070047
Selim Cinek281c2022016-10-13 19:14:43 -070048/**
49 * A notification shelf view that is placed inside the notification scroller. It manages the
50 * overflow icons that don't fit into the regular list anymore.
51 */
Selim Cinek9ef119c2017-03-01 15:13:36 -080052public class NotificationShelf extends ActivatableNotificationView implements
53 View.OnLayoutChangeListener {
Selim Cinek281c2022016-10-13 19:14:43 -070054
Selim Cinek17e1b692016-12-02 18:19:11 -080055 public static final boolean SHOW_AMBIENT_ICONS = true;
Selim Cinek2b549f42016-11-22 16:38:51 -080056 private static final boolean USE_ANIMATIONS_WHEN_OPENING =
57 SystemProperties.getBoolean("debug.icon_opening_animations", true);
Selim Cineka1d97902016-12-14 16:31:40 -080058 private static final boolean ICON_ANMATIONS_WHILE_SCROLLING
59 = SystemProperties.getBoolean("debug.icon_scroll_animations", true);
Selim Cinek6eaacf22017-09-07 18:53:17 -070060 private static final int TAG_CONTINUOUS_CLIPPING = R.id.continuous_clipping_tag;
Selim Cinekb7bafbc2017-12-21 11:33:26 -080061 private static final String TAG = "NotificationShelf";
Lucas Dupin60661a62018-04-12 10:50:13 -070062 private static final long SHELF_IN_TRANSLATION_DURATION = 200;
Lucas Dupinb561eda2018-04-09 17:25:04 -070063
Selim Cinek281c2022016-10-13 19:14:43 -070064 private boolean mDark;
Selim Cinek49014f82016-11-04 14:55:30 -070065 private NotificationIconContainer mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -070066 private ShelfState mShelfState;
67 private int[] mTmp = new int[2];
68 private boolean mHideBackground;
69 private int mIconAppearTopPadding;
Lucas Dupinb561eda2018-04-09 17:25:04 -070070 private int mShelfAppearTranslation;
Selim Cinek48ff9b42016-11-09 19:31:51 -080071 private int mStatusBarHeight;
72 private int mStatusBarPaddingStart;
Selim Cinekc383fd02016-10-21 15:31:26 -070073 private AmbientState mAmbientState;
74 private NotificationStackScrollLayout mHostLayout;
Selim Cinek9458b192016-10-25 19:02:42 -070075 private int mMaxLayoutHeight;
Selim Cineka686b2c2016-10-26 13:58:27 -070076 private int mPaddingBetweenElements;
Selim Cinekeccb5de2016-10-28 15:04:05 -070077 private int mNotGoneIndex;
78 private boolean mHasItemsInStableShelf;
Selim Cinek49014f82016-11-04 14:55:30 -070079 private NotificationIconContainer mCollapsedIcons;
Selim Cinek727903c2016-12-06 17:28:10 -080080 private int mScrollFastThreshold;
Selim Cinekb42698f2017-07-31 17:47:45 -070081 private int mIconSize;
Selim Cinek810bcde2016-12-14 17:29:23 -080082 private int mStatusBarState;
Selim Cineka1d97902016-12-14 16:31:40 -080083 private float mMaxShelfEnd;
Selim Cinekfcff4c62016-12-27 14:26:06 +010084 private int mRelativeOffset;
Selim Cinekc6813462017-01-13 17:10:38 -080085 private boolean mInteractive;
Selim Cinek2fce3c82017-05-08 12:38:09 -070086 private float mOpenedAmount;
87 private boolean mNoAnimationsInThisFrame;
Selim Cinek09bd29d2017-02-03 15:30:28 -080088 private boolean mAnimationsEnabled = true;
Anthony Chen9e05d462017-04-07 10:10:21 -070089 private boolean mShowNotificationShelf;
Selim Cinek515b2032017-11-15 10:20:19 -080090 private float mFirstElementRoundness;
Selim Cinek143672c2018-03-23 20:04:32 -070091 private Rect mClipRect = new Rect();
Selim Cinek281c2022016-10-13 19:14:43 -070092
93 public NotificationShelf(Context context, AttributeSet attrs) {
94 super(context, attrs);
95 }
96
97 @Override
98 protected void onFinishInflate() {
99 super.onFinishInflate();
Alan Viverette51efddb2017-04-05 10:00:01 -0400100 mShelfIcons = findViewById(R.id.content);
Selim Cinek49014f82016-11-04 14:55:30 -0700101 mShelfIcons.setClipChildren(false);
102 mShelfIcons.setClipToPadding(false);
103
Selim Cinek281c2022016-10-13 19:14:43 -0700104 setClipToActualHeight(false);
105 setClipChildren(false);
106 setClipToPadding(false);
Evan Lairdc987fc72017-12-15 10:14:22 -0500107 mShelfIcons.setIsStaticLayout(false);
Selim Cinek281c2022016-10-13 19:14:43 -0700108 mShelfState = new ShelfState();
Selim Cinek2871bef2017-11-22 08:40:00 -0800109 setBottomRoundness(1.0f, false /* animate */);
Selim Cinek281c2022016-10-13 19:14:43 -0700110 initDimens();
111 }
112
Selim Cinekc383fd02016-10-21 15:31:26 -0700113 public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout) {
114 mAmbientState = ambientState;
115 mHostLayout = hostLayout;
116 }
117
Selim Cinek281c2022016-10-13 19:14:43 -0700118 private void initDimens() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700119 Resources res = getResources();
120 mIconAppearTopPadding = res.getDimensionPixelSize(R.dimen.notification_icon_appear_padding);
121 mStatusBarHeight = res.getDimensionPixelOffset(R.dimen.status_bar_height);
122 mStatusBarPaddingStart = res.getDimensionPixelOffset(R.dimen.status_bar_padding_start);
123 mPaddingBetweenElements = res.getDimensionPixelSize(R.dimen.notification_divider_height);
Lucas Dupinb561eda2018-04-09 17:25:04 -0700124 mShelfAppearTranslation = res.getDimensionPixelSize(R.dimen.shelf_appear_translation);
Anthony Chen9e05d462017-04-07 10:10:21 -0700125
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800126 ViewGroup.LayoutParams layoutParams = getLayoutParams();
Anthony Chen9e05d462017-04-07 10:10:21 -0700127 layoutParams.height = res.getDimensionPixelOffset(R.dimen.notification_shelf_height);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800128 setLayoutParams(layoutParams);
Anthony Chen9e05d462017-04-07 10:10:21 -0700129
130 int padding = res.getDimensionPixelOffset(R.dimen.shelf_icon_container_padding);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800131 mShelfIcons.setPadding(padding, 0, padding, 0);
Anthony Chen9e05d462017-04-07 10:10:21 -0700132 mScrollFastThreshold = res.getDimensionPixelOffset(R.dimen.scroll_fast_threshold);
133 mShowNotificationShelf = res.getBoolean(R.bool.config_showNotificationShelf);
Selim Cinekb42698f2017-07-31 17:47:45 -0700134 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
Anthony Chen9e05d462017-04-07 10:10:21 -0700135
136 if (!mShowNotificationShelf) {
137 setVisibility(GONE);
138 }
Selim Cinek281c2022016-10-13 19:14:43 -0700139 }
140
141 @Override
142 protected void onConfigurationChanged(Configuration newConfig) {
143 super.onConfigurationChanged(newConfig);
144 initDimens();
145 }
146
147 @Override
148 public void setDark(boolean dark, boolean fade, long delay) {
149 super.setDark(dark, fade, delay);
150 if (mDark == dark) return;
151 mDark = dark;
Adrian Roos456e0052017-04-04 16:44:29 -0700152 mShelfIcons.setDark(dark, fade, delay);
Adrian Roos03cf2582017-03-28 17:54:05 -0700153 updateInteractiveness();
Selim Cinek281c2022016-10-13 19:14:43 -0700154 }
155
Lucas Dupinb561eda2018-04-09 17:25:04 -0700156 public void fadeInTranslating() {
Selim Cinek51810d52018-07-20 17:54:48 -0700157 mShelfIcons.setTranslationY(-mShelfAppearTranslation);
Lucas Dupinb561eda2018-04-09 17:25:04 -0700158 mShelfIcons.setAlpha(0);
159 mShelfIcons.animate()
Lucas Dupin60661a62018-04-12 10:50:13 -0700160 .setInterpolator(Interpolators.DECELERATE_QUINT)
Selim Cinek51810d52018-07-20 17:54:48 -0700161 .translationY(0)
Lucas Dupinb561eda2018-04-09 17:25:04 -0700162 .setDuration(SHELF_IN_TRANSLATION_DURATION)
163 .start();
Lucas Dupin60661a62018-04-12 10:50:13 -0700164 mShelfIcons.animate()
165 .alpha(1)
166 .setInterpolator(Interpolators.LINEAR)
167 .setDuration(SHELF_IN_TRANSLATION_DURATION)
168 .start();
Lucas Dupinb561eda2018-04-09 17:25:04 -0700169 }
170
Selim Cinek281c2022016-10-13 19:14:43 -0700171 @Override
172 protected View getContentView() {
Selim Cinek49014f82016-11-04 14:55:30 -0700173 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700174 }
175
Selim Cinek49014f82016-11-04 14:55:30 -0700176 public NotificationIconContainer getShelfIcons() {
177 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700178 }
179
180 @Override
181 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
182 return mShelfState;
183 }
184
185 public void updateState(StackScrollState resultState,
Selim Cinek281c2022016-10-13 19:14:43 -0700186 AmbientState ambientState) {
Selim Cinekdb167372016-11-17 15:41:17 -0800187 View lastView = ambientState.getLastVisibleBackgroundChild();
Anthony Chen9e05d462017-04-07 10:10:21 -0700188 if (mShowNotificationShelf && lastView != null) {
Selim Cinek281c2022016-10-13 19:14:43 -0700189 float maxShelfEnd = ambientState.getInnerHeight() + ambientState.getTopPadding()
190 + ambientState.getStackTranslation();
Selim Cinek281c2022016-10-13 19:14:43 -0700191 ExpandableViewState lastViewState = resultState.getViewStateForView(lastView);
192 float viewEnd = lastViewState.yTranslation + lastViewState.height;
193 mShelfState.copyFrom(lastViewState);
194 mShelfState.height = getIntrinsicHeight();
Lucas Dupinb561eda2018-04-09 17:25:04 -0700195
196 float awakenTranslation = Math.max(Math.min(viewEnd, maxShelfEnd) - mShelfState.height,
Selim Cinek49014f82016-11-04 14:55:30 -0700197 getFullyClosedTranslation());
Lucas Dupinb561eda2018-04-09 17:25:04 -0700198 float darkTranslation = mAmbientState.getDarkTopPadding();
199 float yRatio = mAmbientState.hasPulsingNotifications() ?
200 0 : mAmbientState.getDarkAmount();
201 mShelfState.yTranslation = MathUtils.lerp(awakenTranslation, darkTranslation, yRatio);
Selim Cinekd127d792016-11-01 19:11:41 -0700202 mShelfState.zTranslation = ambientState.getBaseZHeight();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800203 float openedAmount = (mShelfState.yTranslation - getFullyClosedTranslation())
204 / (getIntrinsicHeight() * 2);
205 openedAmount = Math.min(1.0f, openedAmount);
Selim Cinek49014f82016-11-04 14:55:30 -0700206 mShelfState.openedAmount = openedAmount;
Selim Cinek281c2022016-10-13 19:14:43 -0700207 mShelfState.clipTopAmount = 0;
Selim Cinekbe2c4432017-05-30 12:11:09 -0700208 mShelfState.alpha = mAmbientState.hasPulsingNotifications() ? 0 : 1;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800209 mShelfState.belowSpeedBump = mAmbientState.getSpeedBumpIndex() == 0;
Selim Cinek281c2022016-10-13 19:14:43 -0700210 mShelfState.shadowAlpha = 1.0f;
Selim Cinek281c2022016-10-13 19:14:43 -0700211 mShelfState.hideSensitive = false;
Selim Cinek5b5beb012016-11-08 18:11:58 -0800212 mShelfState.xTranslation = getTranslationX();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700213 if (mNotGoneIndex != -1) {
214 mShelfState.notGoneIndex = Math.min(mShelfState.notGoneIndex, mNotGoneIndex);
215 }
216 mShelfState.hasItemsInStableShelf = lastViewState.inShelf;
Selim Cinek5cf1d052017-06-01 17:36:46 -0700217 mShelfState.hidden = !mAmbientState.isShadeExpanded()
218 || mAmbientState.isQsCustomizerShowing();
Selim Cineka1d97902016-12-14 16:31:40 -0800219 mShelfState.maxShelfEnd = maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700220 } else {
Selim Cinek281c2022016-10-13 19:14:43 -0700221 mShelfState.hidden = true;
222 mShelfState.location = ExpandableViewState.LOCATION_GONE;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700223 mShelfState.hasItemsInStableShelf = false;
Selim Cinek281c2022016-10-13 19:14:43 -0700224 }
225 }
226
Selim Cinekc383fd02016-10-21 15:31:26 -0700227 /**
228 * Update the shelf appearance based on the other notifications around it. This transforms
229 * the icons from the notification area into the shelf.
230 */
231 public void updateAppearance() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700232 // If the shelf should not be shown, then there is no need to update anything.
233 if (!mShowNotificationShelf) {
234 return;
235 }
236
Selim Cinek65d418e2016-11-29 15:42:34 -0800237 mShelfIcons.resetViewStates();
238 float shelfStart = getTranslationY();
Selim Cinekdb167372016-11-17 15:41:17 -0800239 float numViewsInShelf = 0.0f;
240 View lastChild = mAmbientState.getLastVisibleBackgroundChild();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700241 mNotGoneIndex = -1;
Selim Cinek49014f82016-11-04 14:55:30 -0700242 float interpolationStart = mMaxLayoutHeight - getIntrinsicHeight() * 2;
243 float expandAmount = 0.0f;
Selim Cinek65d418e2016-11-29 15:42:34 -0800244 if (shelfStart >= interpolationStart) {
245 expandAmount = (shelfStart - interpolationStart) / getIntrinsicHeight();
Selim Cinek49014f82016-11-04 14:55:30 -0700246 expandAmount = Math.min(1.0f, expandAmount);
247 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700248 // find the first view that doesn't overlap with the shelf
Selim Cinekdb167372016-11-17 15:41:17 -0800249 int notGoneIndex = 0;
Selim Cinekec29d342017-05-05 18:31:49 -0700250 int colorOfViewBeforeLast = NO_COLOR;
Selim Cinekdb167372016-11-17 15:41:17 -0800251 boolean backgroundForceHidden = false;
252 if (mHideBackground && !mShelfState.hasItemsInStableShelf) {
253 backgroundForceHidden = true;
254 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800255 int colorTwoBefore = NO_COLOR;
256 int previousColor = NO_COLOR;
257 float transitionAmount = 0.0f;
Selim Cineka1d97902016-12-14 16:31:40 -0800258 float currentScrollVelocity = mAmbientState.getCurrentScrollVelocity();
259 boolean scrollingFast = currentScrollVelocity > mScrollFastThreshold
Selim Cinekd5ab6452016-12-08 16:34:00 -0800260 || (mAmbientState.isExpansionChanging()
261 && Math.abs(mAmbientState.getExpandingVelocity()) > mScrollFastThreshold);
Selim Cineka1d97902016-12-14 16:31:40 -0800262 boolean scrolling = currentScrollVelocity > 0;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800263 boolean expandingAnimated = mAmbientState.isExpansionChanging()
264 && !mAmbientState.isPanelTracking();
Selim Cinek65d418e2016-11-29 15:42:34 -0800265 int baseZHeight = mAmbientState.getBaseZHeight();
Selim Cinek515b2032017-11-15 10:20:19 -0800266 int backgroundTop = 0;
267 float firstElementRoundness = 0.0f;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700268
269 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
270 ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i);
271
Selim Cinekc383fd02016-10-21 15:31:26 -0700272 if (!(child instanceof ExpandableNotificationRow)
273 || child.getVisibility() == GONE) {
274 continue;
275 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700276
Selim Cinekc383fd02016-10-21 15:31:26 -0700277 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cineka686b2c2016-10-26 13:58:27 -0700278 float notificationClipEnd;
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800279 boolean aboveShelf = ViewState.getFinalTranslationZ(row) > baseZHeight
280 || row.isPinned();
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800281 boolean isLastChild = child == lastChild;
Selim Cinek65d418e2016-11-29 15:42:34 -0800282 float rowTranslationY = row.getTranslationY();
Selim Cinek3ff9fba2017-07-20 10:47:48 -0700283 if ((isLastChild && !child.isInShelf()) || aboveShelf || backgroundForceHidden) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700284 notificationClipEnd = shelfStart + getIntrinsicHeight();
285 } else {
Selim Cineka686b2c2016-10-26 13:58:27 -0700286 notificationClipEnd = shelfStart - mPaddingBetweenElements;
Selim Cinek65d418e2016-11-29 15:42:34 -0800287 float height = notificationClipEnd - rowTranslationY;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800288 if (!row.isBelowSpeedBump() && height <= getNotificationMergeSize()) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700289 // We want the gap to close when we reached the minimum size and only shrink
290 // before
291 notificationClipEnd = Math.min(shelfStart,
Selim Cinek65d418e2016-11-29 15:42:34 -0800292 rowTranslationY + getNotificationMergeSize());
Selim Cineka686b2c2016-10-26 13:58:27 -0700293 }
294 }
295 updateNotificationClipHeight(row, notificationClipEnd);
Selim Cineka1d97902016-12-14 16:31:40 -0800296 float inShelfAmount = updateIconAppearance(row, expandAmount, scrolling, scrollingFast,
Selim Cinekd5ab6452016-12-08 16:34:00 -0800297 expandingAnimated, isLastChild);
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800298 numViewsInShelf += inShelfAmount;
299 int ownColorUntinted = row.getBackgroundColorWithoutTint();
Selim Cinek65d418e2016-11-29 15:42:34 -0800300 if (rowTranslationY >= shelfStart && mNotGoneIndex == -1) {
Selim Cinekdb167372016-11-17 15:41:17 -0800301 mNotGoneIndex = notGoneIndex;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800302 setTintColor(previousColor);
303 setOverrideTintColor(colorTwoBefore, transitionAmount);
304
305 } else if (mNotGoneIndex == -1) {
306 colorTwoBefore = previousColor;
307 transitionAmount = inShelfAmount;
308 }
Selim Cinekec29d342017-05-05 18:31:49 -0700309 if (isLastChild) {
310 if (colorOfViewBeforeLast == NO_COLOR) {
311 colorOfViewBeforeLast = ownColorUntinted;
312 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800313 row.setOverrideTintColor(colorOfViewBeforeLast, inShelfAmount);
314 } else {
315 colorOfViewBeforeLast = ownColorUntinted;
316 row.setOverrideTintColor(NO_COLOR, 0 /* overrideAmount */);
Selim Cinekeccb5de2016-10-28 15:04:05 -0700317 }
Selim Cinekdb167372016-11-17 15:41:17 -0800318 if (notGoneIndex != 0 || !aboveShelf) {
Selim Cinekd127d792016-11-01 19:11:41 -0700319 row.setAboveShelf(false);
320 }
Selim Cinek0fe07392017-11-09 13:26:34 -0800321 if (notGoneIndex == 0) {
322 StatusBarIconView icon = row.getEntry().expandedIcon;
323 NotificationIconContainer.IconState iconState = getIconState(icon);
Selim Cinekb7bafbc2017-12-21 11:33:26 -0800324 if (iconState != null && iconState.clampedAppearAmount == 1.0f) {
Selim Cinek0fe07392017-11-09 13:26:34 -0800325 // only if the first icon is fully in the shelf we want to clip to it!
Selim Cinek515b2032017-11-15 10:20:19 -0800326 backgroundTop = (int) (row.getTranslationY() - getTranslationY());
327 firstElementRoundness = row.getCurrentTopRoundness();
Selim Cinekb7bafbc2017-12-21 11:33:26 -0800328 } else if (iconState == null) {
329 Log.wtf(TAG, "iconState is null. ExpandedIcon: " + row.getEntry().expandedIcon
330 + (row.getEntry().expandedIcon != null
331 ? "\n icon parent: " + row.getEntry().expandedIcon.getParent() : "")
332 + " \n number of notifications: " + mHostLayout.getChildCount() );
Selim Cinek0fe07392017-11-09 13:26:34 -0800333 }
334 }
Selim Cinekdb167372016-11-17 15:41:17 -0800335 notGoneIndex++;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800336 previousColor = ownColorUntinted;
Selim Cineka686b2c2016-10-26 13:58:27 -0700337 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700338
339 clipTransientViews();
340
Selim Cinek515b2032017-11-15 10:20:19 -0800341 setBackgroundTop(backgroundTop);
342 setFirstElementRoundness(firstElementRoundness);
Selim Cinek17e1b692016-12-02 18:19:11 -0800343 mShelfIcons.setSpeedBumpIndex(mAmbientState.getSpeedBumpIndex());
Selim Cinek49014f82016-11-04 14:55:30 -0700344 mShelfIcons.calculateIconTranslations();
345 mShelfIcons.applyIconStates();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700346 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
347 View child = mHostLayout.getChildAt(i);
348 if (!(child instanceof ExpandableNotificationRow)
349 || child.getVisibility() == GONE) {
350 continue;
351 }
352 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
353 updateIconClipAmount(row);
354 updateContinuousClipping(row);
355 }
Selim Cinekdb167372016-11-17 15:41:17 -0800356 boolean hideBackground = numViewsInShelf < 1.0f;
357 setHideBackground(hideBackground || backgroundForceHidden);
358 if (mNotGoneIndex == -1) {
359 mNotGoneIndex = notGoneIndex;
360 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800361 }
362
Rohan Shah524cf7b2018-03-15 14:40:02 -0700363 /**
364 * Clips transient views to the top of the shelf - Transient views are only used for
365 * disappearing views/animations and need to be clipped correctly by the shelf to ensure they
366 * don't show underneath the notification stack when something is animating and the user
367 * swipes quickly.
368 */
369 private void clipTransientViews() {
370 for (int i = 0; i < mHostLayout.getTransientViewCount(); i++) {
371 View transientView = mHostLayout.getTransientView(i);
372 if (transientView instanceof ExpandableNotificationRow) {
373 ExpandableNotificationRow transientRow = (ExpandableNotificationRow) transientView;
374 updateNotificationClipHeight(transientRow, getTranslationY());
375 } else {
376 Log.e(TAG, "NotificationShelf.clipTransientViews(): "
377 + "Trying to clip non-row transient view");
378 }
379 }
380 }
381
Selim Cinek515b2032017-11-15 10:20:19 -0800382 private void setFirstElementRoundness(float firstElementRoundness) {
383 if (mFirstElementRoundness != firstElementRoundness) {
384 mFirstElementRoundness = firstElementRoundness;
385 setTopRoundness(firstElementRoundness, false /* animate */);
Selim Cinek0fe07392017-11-09 13:26:34 -0800386 }
387 }
388
Selim Cinek6eaacf22017-09-07 18:53:17 -0700389 private void updateIconClipAmount(ExpandableNotificationRow row) {
390 float maxTop = row.getTranslationY();
391 StatusBarIconView icon = row.getEntry().expandedIcon;
392 float shelfIconPosition = getTranslationY() + icon.getTop() + icon.getTranslationY();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800393 if (shelfIconPosition < maxTop && !mAmbientState.isDark()) {
Selim Cinek6eaacf22017-09-07 18:53:17 -0700394 int top = (int) (maxTop - shelfIconPosition);
395 Rect clipRect = new Rect(0, top, icon.getWidth(), Math.max(top, icon.getHeight()));
396 icon.setClipBounds(clipRect);
397 } else {
398 icon.setClipBounds(null);
399 }
400 }
401
402 private void updateContinuousClipping(final ExpandableNotificationRow row) {
403 StatusBarIconView icon = row.getEntry().expandedIcon;
Lucas Dupin16cfe452018-02-08 13:14:50 -0800404 boolean needsContinuousClipping = ViewState.isAnimatingY(icon) && !mAmbientState.isDark();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700405 boolean isContinuousClipping = icon.getTag(TAG_CONTINUOUS_CLIPPING) != null;
406 if (needsContinuousClipping && !isContinuousClipping) {
Selim Cinek85845b82018-04-25 13:10:57 +0800407 final ViewTreeObserver observer = icon.getViewTreeObserver();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700408 ViewTreeObserver.OnPreDrawListener predrawListener =
409 new ViewTreeObserver.OnPreDrawListener() {
410 @Override
411 public boolean onPreDraw() {
412 boolean animatingY = ViewState.isAnimatingY(icon);
Selim Cinek85845b82018-04-25 13:10:57 +0800413 if (!animatingY) {
414 observer.removeOnPreDrawListener(this);
Selim Cinek6eaacf22017-09-07 18:53:17 -0700415 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
416 return true;
417 }
418 updateIconClipAmount(row);
419 return true;
420 }
421 };
Selim Cinek85845b82018-04-25 13:10:57 +0800422 observer.addOnPreDrawListener(predrawListener);
423 icon.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
424 @Override
425 public void onViewAttachedToWindow(View v) {
426 }
427
428 @Override
429 public void onViewDetachedFromWindow(View v) {
430 if (v == icon) {
431 observer.removeOnPreDrawListener(predrawListener);
432 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
433 }
434 }
435 });
Selim Cinek6eaacf22017-09-07 18:53:17 -0700436 icon.setTag(TAG_CONTINUOUS_CLIPPING, predrawListener);
437 }
438 }
439
Selim Cineka686b2c2016-10-26 13:58:27 -0700440 private void updateNotificationClipHeight(ExpandableNotificationRow row,
441 float notificationClipEnd) {
442 float viewEnd = row.getTranslationY() + row.getActualHeight();
Selim Cinekebf42342017-07-13 15:46:10 +0200443 boolean isPinned = (row.isPinned() || row.isHeadsUpAnimatingAway())
444 && !mAmbientState.isDozingAndNotPulsing(row);
Selim Cinekd127d792016-11-01 19:11:41 -0700445 if (viewEnd > notificationClipEnd
Selim Cinek7e0f9482017-05-22 20:00:56 -0700446 && (mAmbientState.isShadeExpanded() || !isPinned)) {
447 int clipBottomAmount = (int) (viewEnd - notificationClipEnd);
448 if (isPinned) {
449 clipBottomAmount = Math.min(row.getIntrinsicHeight() - row.getCollapsedHeight(),
450 clipBottomAmount);
451 }
452 row.setClipBottomAmount(clipBottomAmount);
Selim Cineka686b2c2016-10-26 13:58:27 -0700453 } else {
454 row.setClipBottomAmount(0);
455 }
456 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700457
Selim Cinekc8c4cf92017-09-08 15:30:09 -0700458 @Override
459 public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd,
460 int outlineTranslation) {
461 if (!mHasItemsInStableShelf) {
462 shadowIntensity = 0.0f;
463 }
464 super.setFakeShadowIntensity(shadowIntensity, outlineAlpha, shadowYEnd, outlineTranslation);
465 }
466
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800467 /**
468 * @return the icon amount how much this notification is in the shelf;
469 */
Selim Cinek2b549f42016-11-22 16:38:51 -0800470 private float updateIconAppearance(ExpandableNotificationRow row, float expandAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800471 boolean scrolling, boolean scrollingFast, boolean expandingAnimated,
472 boolean isLastChild) {
Selim Cinek1f624952017-06-08 19:11:50 -0700473 StatusBarIconView icon = row.getEntry().expandedIcon;
474 NotificationIconContainer.IconState iconState = getIconState(icon);
475 if (iconState == null) {
476 return 0.0f;
477 }
478
Selim Cinekc383fd02016-10-21 15:31:26 -0700479 // Let calculate how much the view is in the shelf
480 float viewStart = row.getTranslationY();
Selim Cinek2b549f42016-11-22 16:38:51 -0800481 int fullHeight = row.getActualHeight() + mPaddingBetweenElements;
482 float iconTransformDistance = getIntrinsicHeight() * 1.5f;
Selim Cineka1d97902016-12-14 16:31:40 -0800483 iconTransformDistance *= NotificationUtils.interpolate(1.f, 1.5f, expandAmount);
Selim Cinek1f624952017-06-08 19:11:50 -0700484 iconTransformDistance = Math.min(iconTransformDistance, fullHeight);
Selim Cinek938bdaa2016-11-18 16:31:09 -0800485 if (isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800486 fullHeight = Math.min(fullHeight, row.getMinHeight() - getIntrinsicHeight());
Bill Line6065e32018-06-08 17:07:13 +0800487 iconTransformDistance = Math.min(iconTransformDistance, row.getMinHeight()
488 - getIntrinsicHeight());
Selim Cinek938bdaa2016-11-18 16:31:09 -0800489 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800490 float viewEnd = viewStart + fullHeight;
Selim Cinek1f624952017-06-08 19:11:50 -0700491 if (expandingAnimated && mAmbientState.getScrollY() == 0
492 && !mAmbientState.isOnKeyguard() && !iconState.isLastExpandIcon) {
493 // We are expanding animated. Because we switch to a linear interpolation in this case,
494 // the last icon may be stuck in between the shelf position and the notification
495 // position, which looks pretty bad. We therefore optimize this case by applying a
496 // shorter transition such that the icon is either fully in the notification or we clamp
497 // it into the shelf if it's close enough.
498 // We need to persist this, since after the expansion, the behavior should still be the
499 // same.
500 float position = mAmbientState.getIntrinsicPadding()
501 + mHostLayout.getPositionInLinearLayout(row);
502 int maxShelfStart = mMaxLayoutHeight - getIntrinsicHeight();
503 if (position < maxShelfStart && position + row.getIntrinsicHeight() >= maxShelfStart
504 && row.getTranslationY() < position) {
505 iconState.isLastExpandIcon = true;
506 iconState.customTransformHeight = NO_VALUE;
507 // Let's check if we're close enough to snap into the shelf
508 boolean forceInShelf = mMaxLayoutHeight - getIntrinsicHeight() - position
509 < getIntrinsicHeight();
510 if (!forceInShelf) {
511 // We are overlapping the shelf but not enough, so the icon needs to be
512 // repositioned
513 iconState.customTransformHeight = (int) (mMaxLayoutHeight
514 - getIntrinsicHeight() - position);
515 }
516 }
517 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800518 float fullTransitionAmount;
Selim Cinek01a73f92016-12-06 16:13:42 -0800519 float iconTransitionAmount;
520 float shelfStart = getTranslationY();
Selim Cinek1f624952017-06-08 19:11:50 -0700521 if (iconState.hasCustomTransformHeight()) {
522 fullHeight = iconState.customTransformHeight;
523 iconTransformDistance = iconState.customTransformHeight;
524 }
525 boolean fullyInOrOut = true;
Selim Cinekec29d342017-05-05 18:31:49 -0700526 if (viewEnd >= shelfStart && (!mAmbientState.isUnlockHintRunning() || row.isInShelf())
527 && (mAmbientState.isShadeExpanded()
528 || (!row.isPinned() && !row.isHeadsUpAnimatingAway()))) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800529 if (viewStart < shelfStart) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800530 float fullAmount = (shelfStart - viewStart) / fullHeight;
Selim Cinek1f624952017-06-08 19:11:50 -0700531 fullAmount = Math.min(1.0f, fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700532 float interpolatedAmount = Interpolators.ACCELERATE_DECELERATE.getInterpolation(
Selim Cinek2b549f42016-11-22 16:38:51 -0800533 fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700534 interpolatedAmount = NotificationUtils.interpolate(
Selim Cinek2b549f42016-11-22 16:38:51 -0800535 interpolatedAmount, fullAmount, expandAmount);
536 fullTransitionAmount = 1.0f - interpolatedAmount;
537
Selim Cinek01a73f92016-12-06 16:13:42 -0800538 iconTransitionAmount = (shelfStart - viewStart) / iconTransformDistance;
539 iconTransitionAmount = Math.min(1.0f, iconTransitionAmount);
540 iconTransitionAmount = 1.0f - iconTransitionAmount;
Selim Cinek1f624952017-06-08 19:11:50 -0700541 fullyInOrOut = false;
Selim Cinekc383fd02016-10-21 15:31:26 -0700542 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800543 fullTransitionAmount = 1.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800544 iconTransitionAmount = 1.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700545 }
546 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800547 fullTransitionAmount = 0.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800548 iconTransitionAmount = 0.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700549 }
Selim Cinek1f624952017-06-08 19:11:50 -0700550 if (fullyInOrOut && !expandingAnimated && iconState.isLastExpandIcon) {
551 iconState.isLastExpandIcon = false;
552 iconState.customTransformHeight = NO_VALUE;
553 }
Selim Cineka1d97902016-12-14 16:31:40 -0800554 updateIconPositioning(row, iconTransitionAmount, fullTransitionAmount,
555 iconTransformDistance, scrolling, scrollingFast, expandingAnimated, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800556 return fullTransitionAmount;
557 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700558
Selim Cinek2b549f42016-11-22 16:38:51 -0800559 private void updateIconPositioning(ExpandableNotificationRow row, float iconTransitionAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800560 float fullTransitionAmount, float iconTransformDistance, boolean scrolling,
561 boolean scrollingFast, boolean expandingAnimated, boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800562 StatusBarIconView icon = row.getEntry().expandedIcon;
563 NotificationIconContainer.IconState iconState = getIconState(icon);
564 if (iconState == null) {
565 return;
566 }
Selim Cinek1f624952017-06-08 19:11:50 -0700567 boolean forceInShelf = iconState.isLastExpandIcon && !iconState.hasCustomTransformHeight();
Selim Cinek2b549f42016-11-22 16:38:51 -0800568 float clampedAmount = iconTransitionAmount > 0.5f ? 1.0f : 0.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800569 if (clampedAmount == fullTransitionAmount) {
Selim Cinek1f624952017-06-08 19:11:50 -0700570 iconState.noAnimations = (scrollingFast || expandingAnimated) && !forceInShelf;
Selim Cinek44d81a62017-05-08 19:45:40 -0700571 iconState.useFullTransitionAmount = iconState.noAnimations
Selim Cineka1d97902016-12-14 16:31:40 -0800572 || (!ICON_ANMATIONS_WHILE_SCROLLING && fullTransitionAmount == 0.0f && scrolling);
573 iconState.useLinearTransitionAmount = !ICON_ANMATIONS_WHILE_SCROLLING
574 && fullTransitionAmount == 0.0f && !mAmbientState.isExpansionChanging();
Selim Cinek01a73f92016-12-06 16:13:42 -0800575 iconState.translateContent = mMaxLayoutHeight - getTranslationY()
576 - getIntrinsicHeight() > 0;
Selim Cinek2b549f42016-11-22 16:38:51 -0800577 }
Selim Cinek1f624952017-06-08 19:11:50 -0700578 if (!forceInShelf && (scrollingFast || (expandingAnimated
579 && iconState.useFullTransitionAmount && !ViewState.isAnimatingY(icon)))) {
Selim Cinekd5ab6452016-12-08 16:34:00 -0800580 iconState.cancelAnimations(icon);
581 iconState.useFullTransitionAmount = true;
Selim Cinek44d81a62017-05-08 19:45:40 -0700582 iconState.noAnimations = true;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800583 }
Selim Cinek1f624952017-06-08 19:11:50 -0700584 if (iconState.hasCustomTransformHeight()) {
585 iconState.useFullTransitionAmount = true;
586 }
587 if (iconState.isLastExpandIcon) {
588 iconState.translateContent = false;
589 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800590 float transitionAmount;
Lucas Dupinb561eda2018-04-09 17:25:04 -0700591 if (mAmbientState.getDarkAmount() > 0 && !row.isInShelf()) {
592 transitionAmount = mAmbientState.isFullyDark() ? 1 : 0;
593 } else if (isLastChild || !USE_ANIMATIONS_WHEN_OPENING || iconState.useFullTransitionAmount
Selim Cineka1d97902016-12-14 16:31:40 -0800594 || iconState.useLinearTransitionAmount) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800595 transitionAmount = iconTransitionAmount;
Selim Cinek2b549f42016-11-22 16:38:51 -0800596 } else {
Selim Cineka1d97902016-12-14 16:31:40 -0800597 // We take the clamped position instead
598 transitionAmount = clampedAmount;
Selim Cinek2fce3c82017-05-08 12:38:09 -0700599 iconState.needsCannedAnimation = iconState.clampedAppearAmount != clampedAmount
600 && !mNoAnimationsInThisFrame;
Selim Cinek2b549f42016-11-22 16:38:51 -0800601 }
602 iconState.iconAppearAmount = !USE_ANIMATIONS_WHEN_OPENING
603 || iconState.useFullTransitionAmount
604 ? fullTransitionAmount
605 : transitionAmount;
606 iconState.clampedAppearAmount = clampedAmount;
Selim Cinekebf42342017-07-13 15:46:10 +0200607 float contentTransformationAmount = !mAmbientState.isAboveShelf(row)
Selim Cinek7e0f9482017-05-22 20:00:56 -0700608 && (isLastChild || iconState.translateContent)
Selim Cinek01a73f92016-12-06 16:13:42 -0800609 ? iconTransitionAmount
610 : 0.0f;
611 row.setContentTransformationAmount(contentTransformationAmount, isLastChild);
Selim Cineka1d97902016-12-14 16:31:40 -0800612 setIconTransformationAmount(row, transitionAmount, iconTransformDistance,
Mady Mellor434180c2017-02-13 11:29:42 -0800613 clampedAmount != transitionAmount, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800614 }
615
616 private void setIconTransformationAmount(ExpandableNotificationRow row,
Mady Mellor434180c2017-02-13 11:29:42 -0800617 float transitionAmount, float iconTransformDistance, boolean usingLinearInterpolation,
618 boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800619 StatusBarIconView icon = row.getEntry().expandedIcon;
620 NotificationIconContainer.IconState iconState = getIconState(icon);
621
Selim Cinekc383fd02016-10-21 15:31:26 -0700622 View rowIcon = row.getNotificationIcon();
Selim Cineka1d97902016-12-14 16:31:40 -0800623 float notificationIconPosition = row.getTranslationY() + row.getContentTranslation();
Selim Cinekf20254c2017-02-03 10:09:33 -0800624 boolean stayingInShelf = row.isInShelf() && !row.isTransformingIntoShelf();
625 if (usingLinearInterpolation && !stayingInShelf) {
Selim Cineka1d97902016-12-14 16:31:40 -0800626 // If we interpolate from the notification position, this might lead to a slightly
627 // odd interpolation, since the notification position changes as well. Let's interpolate
628 // from a fixed distance. We can only do this if we don't animate and the icon is
629 // always in the interpolated positon.
Selim Cinekf20254c2017-02-03 10:09:33 -0800630 notificationIconPosition = getTranslationY() - iconTransformDistance;
Selim Cineka1d97902016-12-14 16:31:40 -0800631 }
Selim Cinek281c2022016-10-13 19:14:43 -0700632 float notificationIconSize = 0.0f;
633 int iconTopPadding;
634 if (rowIcon != null) {
Selim Cinek875a3a12016-11-18 17:52:16 -0800635 iconTopPadding = row.getRelativeTopPadding(rowIcon);
Selim Cinek281c2022016-10-13 19:14:43 -0700636 notificationIconSize = rowIcon.getHeight();
637 } else {
638 iconTopPadding = mIconAppearTopPadding;
639 }
640 notificationIconPosition += iconTopPadding;
Selim Cinekc383fd02016-10-21 15:31:26 -0700641 float shelfIconPosition = getTranslationY() + icon.getTop();
Selim Cinekb42698f2017-07-31 17:47:45 -0700642 shelfIconPosition += (icon.getHeight() - icon.getIconScale() * mIconSize) / 2.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800643 float iconYTranslation = NotificationUtils.interpolate(
Selim Cineka1d97902016-12-14 16:31:40 -0800644 notificationIconPosition - shelfIconPosition,
Selim Cinek2b549f42016-11-22 16:38:51 -0800645 0,
646 transitionAmount);
Selim Cinekb42698f2017-07-31 17:47:45 -0700647 float shelfIconSize = mIconSize * icon.getIconScale();
Selim Cinek2b549f42016-11-22 16:38:51 -0800648 float alpha = 1.0f;
Selim Cinek875ba9b2017-02-13 16:20:17 -0800649 boolean noIcon = !row.isShowingIcon();
650 if (noIcon) {
Selim Cinekc383fd02016-10-21 15:31:26 -0700651 // The view currently doesn't have an icon, lets transform it in!
Selim Cinekdb167372016-11-17 15:41:17 -0800652 alpha = transitionAmount;
Selim Cinekc383fd02016-10-21 15:31:26 -0700653 notificationIconSize = shelfIconSize / 2.0f;
654 }
655 // The notification size is different from the size in the shelf / statusbar
656 float newSize = NotificationUtils.interpolate(notificationIconSize, shelfIconSize,
Selim Cinek281c2022016-10-13 19:14:43 -0700657 transitionAmount);
Selim Cinekdb167372016-11-17 15:41:17 -0800658 if (iconState != null) {
Selim Cinekb42698f2017-07-31 17:47:45 -0700659 iconState.scaleX = newSize / shelfIconSize;
Selim Cinekdb167372016-11-17 15:41:17 -0800660 iconState.scaleY = iconState.scaleX;
Adrian Roos28f90c72017-05-08 17:24:26 -0700661 iconState.hidden = transitionAmount == 0.0f && !iconState.isAnimating(icon);
Selim Cinekf38d6c32017-06-28 15:44:02 +0200662 boolean isAppearing = row.isDrawingAppearAnimation() && !row.isInShelf();
663 if (isAppearing) {
664 iconState.hidden = true;
665 iconState.iconAppearAmount = 0.0f;
666 }
Selim Cinekdb167372016-11-17 15:41:17 -0800667 iconState.alpha = alpha;
Selim Cinek2b549f42016-11-22 16:38:51 -0800668 iconState.yTranslation = iconYTranslation;
Selim Cinekf20254c2017-02-03 10:09:33 -0800669 if (stayingInShelf) {
Selim Cinekdb167372016-11-17 15:41:17 -0800670 iconState.iconAppearAmount = 1.0f;
671 iconState.alpha = 1.0f;
672 iconState.scaleX = 1.0f;
673 iconState.scaleY = 1.0f;
674 iconState.hidden = false;
675 }
Selim Cinekebf42342017-07-13 15:46:10 +0200676 if (mAmbientState.isAboveShelf(row) || (!row.isInShelf() && (isLastChild && row.areGutsExposed()
Selim Cinek47374632017-03-17 16:07:17 -0700677 || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) {
Selim Cinek5ea19572016-11-29 15:34:48 -0800678 iconState.hidden = true;
679 }
Lucas Dupin83519da2017-06-21 11:58:31 -0700680 int backgroundColor = getBackgroundColorWithoutTint();
681 int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor);
Selim Cinek875ba9b2017-02-13 16:20:17 -0800682 if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) {
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700683 int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor();
684 shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor,
Selim Cinek875ba9b2017-02-13 16:20:17 -0800685 iconState.iconAppearAmount);
686 }
687 iconState.iconColor = shelfColor;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700688 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800689 }
690
691 private NotificationIconContainer.IconState getIconState(StatusBarIconView icon) {
692 return mShelfIcons.getIconState(icon);
Selim Cinekc383fd02016-10-21 15:31:26 -0700693 }
694
695 private float getFullyClosedTranslation() {
696 return - (getIntrinsicHeight() - mStatusBarHeight) / 2;
Selim Cinek281c2022016-10-13 19:14:43 -0700697 }
698
Selim Cinek281c2022016-10-13 19:14:43 -0700699 public int getNotificationMergeSize() {
700 return getIntrinsicHeight();
701 }
702
703 @Override
704 public boolean hasNoContentHeight() {
705 return true;
706 }
Selim Cineka686b2c2016-10-26 13:58:27 -0700707
Selim Cinek281c2022016-10-13 19:14:43 -0700708 private void setHideBackground(boolean hideBackground) {
Selim Cinek65d418e2016-11-29 15:42:34 -0800709 if (mHideBackground != hideBackground) {
710 mHideBackground = hideBackground;
711 updateBackground();
712 updateOutline();
713 }
Selim Cinekad7fac02016-10-18 17:09:15 -0700714 }
715
Selim Cinekeccb5de2016-10-28 15:04:05 -0700716 public boolean hidesBackground() {
717 return mHideBackground;
718 }
719
Selim Cinekad7fac02016-10-18 17:09:15 -0700720 @Override
721 protected boolean needsOutline() {
722 return !mHideBackground && super.needsOutline();
Selim Cinek281c2022016-10-13 19:14:43 -0700723 }
724
725 @Override
726 protected boolean shouldHideBackground() {
727 return super.shouldHideBackground() || mHideBackground;
728 }
729
Selim Cinekfcff4c62016-12-27 14:26:06 +0100730 @Override
731 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
732 super.onLayout(changed, left, top, right, bottom);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800733 updateRelativeOffset();
Selim Cinek143672c2018-03-23 20:04:32 -0700734
735 // we always want to clip to our sides, such that nothing can draw outside of these bounds
736 int height = getResources().getDisplayMetrics().heightPixels;
737 mClipRect.set(0, -height, getWidth(), height);
738 mShelfIcons.setClipBounds(mClipRect);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800739 }
740
741 private void updateRelativeOffset() {
Selim Cinek49014f82016-11-04 14:55:30 -0700742 mCollapsedIcons.getLocationOnScreen(mTmp);
Selim Cinekfcff4c62016-12-27 14:26:06 +0100743 mRelativeOffset = mTmp[0];
744 getLocationOnScreen(mTmp);
745 mRelativeOffset -= mTmp[0];
746 }
747
748 private void setOpenedAmount(float openedAmount) {
Selim Cinek2fce3c82017-05-08 12:38:09 -0700749 mNoAnimationsInThisFrame = openedAmount == 1.0f && mOpenedAmount == 0.0f;
750 mOpenedAmount = openedAmount;
Selim Cinekfcff4c62016-12-27 14:26:06 +0100751 if (!mAmbientState.isPanelFullWidth()) {
752 // We don't do a transformation at all, lets just assume we are fully opened
753 openedAmount = 1.0f;
754 }
755 int start = mRelativeOffset;
Selim Cinek49014f82016-11-04 14:55:30 -0700756 if (isLayoutRtl()) {
757 start = getWidth() - start - mCollapsedIcons.getWidth();
758 }
Evan Lairdc987fc72017-12-15 10:14:22 -0500759 int width = (int) NotificationUtils.interpolate(
760 start + mCollapsedIcons.getFinalTranslationX(),
Selim Cinek49014f82016-11-04 14:55:30 -0700761 mShelfIcons.getWidth(),
762 openedAmount);
763 mShelfIcons.setActualLayoutWidth(width);
Selim Cinek932005d2016-12-05 17:12:09 -0800764 boolean hasOverflow = mCollapsedIcons.hasOverflow();
765 int collapsedPadding = mCollapsedIcons.getPaddingEnd();
766 if (!hasOverflow) {
767 // we have to ensure that adding the low priority notification won't lead to an
768 // overflow
Evan Laird8cf0de42018-02-06 18:34:55 -0500769 collapsedPadding -= mCollapsedIcons.getNoOverflowExtraPadding();
Evan Lairdc987fc72017-12-15 10:14:22 -0500770 } else {
771 // Partial overflow padding will fill enough space to add extra dots
772 collapsedPadding -= mCollapsedIcons.getPartialOverflowExtraPadding();
Selim Cinek932005d2016-12-05 17:12:09 -0800773 }
774 float padding = NotificationUtils.interpolate(collapsedPadding,
Selim Cinek49014f82016-11-04 14:55:30 -0700775 mShelfIcons.getPaddingEnd(),
776 openedAmount);
777 mShelfIcons.setActualPaddingEnd(padding);
778 float paddingStart = NotificationUtils.interpolate(start,
779 mShelfIcons.getPaddingStart(), openedAmount);
780 mShelfIcons.setActualPaddingStart(paddingStart);
Selim Cinek17e1b692016-12-02 18:19:11 -0800781 mShelfIcons.setOpenedAmount(openedAmount);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800782 }
783
Selim Cinek9458b192016-10-25 19:02:42 -0700784 public void setMaxLayoutHeight(int maxLayoutHeight) {
785 mMaxLayoutHeight = maxLayoutHeight;
786 }
787
Selim Cinekeccb5de2016-10-28 15:04:05 -0700788 /**
789 * @return the index of the notification at which the shelf visually resides
790 */
791 public int getNotGoneIndex() {
792 return mNotGoneIndex;
793 }
794
795 private void setHasItemsInStableShelf(boolean hasItemsInStableShelf) {
Selim Cinek810bcde2016-12-14 17:29:23 -0800796 if (mHasItemsInStableShelf != hasItemsInStableShelf) {
797 mHasItemsInStableShelf = hasItemsInStableShelf;
798 updateInteractiveness();
799 }
Selim Cinekeccb5de2016-10-28 15:04:05 -0700800 }
801
802 /**
803 * @return whether the shelf has any icons in it when a potential animation has finished, i.e
804 * if the current state would be applied right now
805 */
806 public boolean hasItemsInStableShelf() {
807 return mHasItemsInStableShelf;
808 }
809
Selim Cinek49014f82016-11-04 14:55:30 -0700810 public void setCollapsedIcons(NotificationIconContainer collapsedIcons) {
811 mCollapsedIcons = collapsedIcons;
Selim Cinek9ef119c2017-03-01 15:13:36 -0800812 mCollapsedIcons.addOnLayoutChangeListener(this);
Selim Cinek49014f82016-11-04 14:55:30 -0700813 }
814
Selim Cinek810bcde2016-12-14 17:29:23 -0800815 public void setStatusBarState(int statusBarState) {
816 if (mStatusBarState != statusBarState) {
817 mStatusBarState = statusBarState;
818 updateInteractiveness();
819 }
820 }
821
822 private void updateInteractiveness() {
Adrian Roos03cf2582017-03-28 17:54:05 -0700823 mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf
824 && !mDark;
Selim Cinekc6813462017-01-13 17:10:38 -0800825 setClickable(mInteractive);
826 setFocusable(mInteractive);
827 setImportantForAccessibility(mInteractive ? View.IMPORTANT_FOR_ACCESSIBILITY_YES
Selim Cinekaca84c02017-04-05 16:28:56 -0700828 : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
Selim Cinek810bcde2016-12-14 17:29:23 -0800829 }
830
Selim Cinekc6813462017-01-13 17:10:38 -0800831 @Override
832 protected boolean isInteractive() {
833 return mInteractive;
834 }
835
Selim Cineka1d97902016-12-14 16:31:40 -0800836 public void setMaxShelfEnd(float maxShelfEnd) {
837 mMaxShelfEnd = maxShelfEnd;
838 }
839
Selim Cinek09bd29d2017-02-03 15:30:28 -0800840 public void setAnimationsEnabled(boolean enabled) {
841 mAnimationsEnabled = enabled;
842 mCollapsedIcons.setAnimationsEnabled(enabled);
843 if (!enabled) {
844 // we need to wait with enabling the animations until the first frame has passed
845 mShelfIcons.setAnimationsEnabled(false);
846 }
847 }
848
Selim Cinek9ef119c2017-03-01 15:13:36 -0800849 @Override
Adrian Roosd83e9992017-03-16 15:17:57 -0700850 public boolean hasOverlappingRendering() {
851 return false; // Shelf only uses alpha for transitions where the difference can't be seen.
852 }
853
854 @Override
Selim Cinekaca84c02017-04-05 16:28:56 -0700855 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
856 super.onInitializeAccessibilityNodeInfo(info);
857 if (mInteractive) {
858 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
859 AccessibilityNodeInfo.AccessibilityAction unlock
860 = new AccessibilityNodeInfo.AccessibilityAction(
861 AccessibilityNodeInfo.ACTION_CLICK,
862 getContext().getString(R.string.accessibility_overflow_action));
863 info.addAction(unlock);
864 }
865 }
866
867 @Override
Selim Cinek9ef119c2017-03-01 15:13:36 -0800868 public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
869 int oldTop, int oldRight, int oldBottom) {
870 updateRelativeOffset();
871 }
872
Selim Cinek281c2022016-10-13 19:14:43 -0700873 private class ShelfState extends ExpandableViewState {
Selim Cinek49014f82016-11-04 14:55:30 -0700874 private float openedAmount;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700875 private boolean hasItemsInStableShelf;
Selim Cineka1d97902016-12-14 16:31:40 -0800876 private float maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700877
878 @Override
879 public void applyToView(View view) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700880 if (!mShowNotificationShelf) {
881 return;
882 }
883
Selim Cinek281c2022016-10-13 19:14:43 -0700884 super.applyToView(view);
Selim Cineka1d97902016-12-14 16:31:40 -0800885 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700886 setOpenedAmount(openedAmount);
Selim Cineka1d97902016-12-14 16:31:40 -0800887 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700888 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800889 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek281c2022016-10-13 19:14:43 -0700890 }
Selim Cinek0cfbef42016-11-09 19:06:36 -0800891
892 @Override
893 public void animateTo(View child, AnimationProperties properties) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700894 if (!mShowNotificationShelf) {
895 return;
896 }
897
Selim Cinek0cfbef42016-11-09 19:06:36 -0800898 super.animateTo(child, properties);
Selim Cineka1d97902016-12-14 16:31:40 -0800899 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700900 setOpenedAmount(openedAmount);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800901 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700902 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800903 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800904 }
Selim Cinek281c2022016-10-13 19:14:43 -0700905 }
906}