blob: e7b4904a8ba5eba2a1be5a94d670e9a3ad678eae [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
felkachangc02c3882018-07-27 15:32:31 +080019import static com.android.systemui.Interpolators.FAST_OUT_SLOW_IN_REVERSE;
Selim Cinek1f624952017-06-08 19:11:50 -070020import static com.android.systemui.statusbar.phone.NotificationIconContainer.IconState.NO_VALUE;
Selim Cinek1f624952017-06-08 19:11:50 -070021
Selim Cinek281c2022016-10-13 19:14:43 -070022import android.content.Context;
23import android.content.res.Configuration;
Anthony Chen9e05d462017-04-07 10:10:21 -070024import android.content.res.Resources;
Selim Cinek6eaacf22017-09-07 18:53:17 -070025import android.graphics.Rect;
Selim Cinek2b549f42016-11-22 16:38:51 -080026import android.os.SystemProperties;
Selim Cinek281c2022016-10-13 19:14:43 -070027import android.util.AttributeSet;
Selim Cinekb7bafbc2017-12-21 11:33:26 -080028import android.util.Log;
Lucas Dupinb561eda2018-04-09 17:25:04 -070029import android.util.MathUtils;
felkachangc02c3882018-07-27 15:32:31 +080030import android.view.DisplayCutout;
Selim Cinek281c2022016-10-13 19:14:43 -070031import android.view.View;
32import android.view.ViewGroup;
Selim Cinek6eaacf22017-09-07 18:53:17 -070033import android.view.ViewTreeObserver;
felkachangc02c3882018-07-27 15:32:31 +080034import android.view.WindowInsets;
Selim Cinekaca84c02017-04-05 16:28:56 -070035import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek1f624952017-06-08 19:11:50 -070036
Jason Monk297c04e2018-08-23 17:16:59 -040037import com.android.internal.annotations.VisibleForTesting;
Jason Monk1fd3fc32018-08-14 17:20:09 -040038import com.android.systemui.Dependency;
Selim Cinek9458b192016-10-25 19:02:42 -070039import com.android.systemui.Interpolators;
Selim Cinek281c2022016-10-13 19:14:43 -070040import com.android.systemui.R;
Jason Monk1fd3fc32018-08-14 17:20:09 -040041import com.android.systemui.statusbar.StatusBarStateController.StateListener;
Selim Cinek281c2022016-10-13 19:14:43 -070042import com.android.systemui.statusbar.notification.NotificationUtils;
Rohan Shah20790b82018-07-02 17:21:04 -070043import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
44import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
45import com.android.systemui.statusbar.notification.row.ExpandableView;
Rohan Shah20790b82018-07-02 17:21:04 -070046import com.android.systemui.statusbar.notification.stack.AmbientState;
47import com.android.systemui.statusbar.notification.stack.AnimationProperties;
48import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
49import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Rohan Shah20790b82018-07-02 17:21:04 -070050import com.android.systemui.statusbar.notification.stack.ViewState;
Lucas Dupin23a8d3b2018-10-08 20:57:35 -070051import com.android.systemui.statusbar.phone.NotificationIconContainer;
Selim Cinek281c2022016-10-13 19:14:43 -070052
Selim Cinek281c2022016-10-13 19:14:43 -070053/**
54 * A notification shelf view that is placed inside the notification scroller. It manages the
55 * overflow icons that don't fit into the regular list anymore.
56 */
Selim Cinek9ef119c2017-03-01 15:13:36 -080057public class NotificationShelf extends ActivatableNotificationView implements
58 View.OnLayoutChangeListener {
Selim Cinek281c2022016-10-13 19:14:43 -070059
Selim Cinek2b549f42016-11-22 16:38:51 -080060 private static final boolean USE_ANIMATIONS_WHEN_OPENING =
61 SystemProperties.getBoolean("debug.icon_opening_animations", true);
Selim Cineka1d97902016-12-14 16:31:40 -080062 private static final boolean ICON_ANMATIONS_WHILE_SCROLLING
63 = SystemProperties.getBoolean("debug.icon_scroll_animations", true);
Selim Cinek6eaacf22017-09-07 18:53:17 -070064 private static final int TAG_CONTINUOUS_CLIPPING = R.id.continuous_clipping_tag;
Selim Cinekb7bafbc2017-12-21 11:33:26 -080065 private static final String TAG = "NotificationShelf";
Lucas Dupin60661a62018-04-12 10:50:13 -070066 private static final long SHELF_IN_TRANSLATION_DURATION = 200;
Lucas Dupinb561eda2018-04-09 17:25:04 -070067
Selim Cinek281c2022016-10-13 19:14:43 -070068 private boolean mDark;
Selim Cinek49014f82016-11-04 14:55:30 -070069 private NotificationIconContainer mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -070070 private int[] mTmp = new int[2];
71 private boolean mHideBackground;
72 private int mIconAppearTopPadding;
Lucas Dupinb561eda2018-04-09 17:25:04 -070073 private int mShelfAppearTranslation;
Selim Cinek48ff9b42016-11-09 19:31:51 -080074 private int mStatusBarHeight;
75 private int mStatusBarPaddingStart;
Selim Cinekc383fd02016-10-21 15:31:26 -070076 private AmbientState mAmbientState;
77 private NotificationStackScrollLayout mHostLayout;
Selim Cinek9458b192016-10-25 19:02:42 -070078 private int mMaxLayoutHeight;
Selim Cineka686b2c2016-10-26 13:58:27 -070079 private int mPaddingBetweenElements;
Selim Cinekeccb5de2016-10-28 15:04:05 -070080 private int mNotGoneIndex;
81 private boolean mHasItemsInStableShelf;
Selim Cinek49014f82016-11-04 14:55:30 -070082 private NotificationIconContainer mCollapsedIcons;
Selim Cinek727903c2016-12-06 17:28:10 -080083 private int mScrollFastThreshold;
Selim Cinekb42698f2017-07-31 17:47:45 -070084 private int mIconSize;
Selim Cinek810bcde2016-12-14 17:29:23 -080085 private int mStatusBarState;
Selim Cineka1d97902016-12-14 16:31:40 -080086 private float mMaxShelfEnd;
Selim Cinekfcff4c62016-12-27 14:26:06 +010087 private int mRelativeOffset;
Selim Cinekc6813462017-01-13 17:10:38 -080088 private boolean mInteractive;
Selim Cinek2fce3c82017-05-08 12:38:09 -070089 private float mOpenedAmount;
90 private boolean mNoAnimationsInThisFrame;
Selim Cinek09bd29d2017-02-03 15:30:28 -080091 private boolean mAnimationsEnabled = true;
Anthony Chen9e05d462017-04-07 10:10:21 -070092 private boolean mShowNotificationShelf;
Selim Cinek515b2032017-11-15 10:20:19 -080093 private float mFirstElementRoundness;
Selim Cinek143672c2018-03-23 20:04:32 -070094 private Rect mClipRect = new Rect();
felkachangc02c3882018-07-27 15:32:31 +080095 private int mCutoutHeight;
Gus Prevase2d6f042018-10-17 15:25:30 -040096 private int mGapHeight;
Selim Cinek281c2022016-10-13 19:14:43 -070097
Jason Monk1fd3fc32018-08-14 17:20:09 -040098 private final StateListener mStateListener = this::setStatusBarState;
99
Selim Cinek281c2022016-10-13 19:14:43 -0700100 public NotificationShelf(Context context, AttributeSet attrs) {
101 super(context, attrs);
102 }
103
104 @Override
Jason Monk297c04e2018-08-23 17:16:59 -0400105 @VisibleForTesting
106 public void onFinishInflate() {
Selim Cinek281c2022016-10-13 19:14:43 -0700107 super.onFinishInflate();
Alan Viverette51efddb2017-04-05 10:00:01 -0400108 mShelfIcons = findViewById(R.id.content);
Selim Cinek49014f82016-11-04 14:55:30 -0700109 mShelfIcons.setClipChildren(false);
110 mShelfIcons.setClipToPadding(false);
111
Selim Cinek281c2022016-10-13 19:14:43 -0700112 setClipToActualHeight(false);
113 setClipChildren(false);
114 setClipToPadding(false);
Evan Lairdc987fc72017-12-15 10:14:22 -0500115 mShelfIcons.setIsStaticLayout(false);
Selim Cinek2871bef2017-11-22 08:40:00 -0800116 setBottomRoundness(1.0f, false /* animate */);
Selim Cinek281c2022016-10-13 19:14:43 -0700117 initDimens();
118 }
119
Jason Monk1fd3fc32018-08-14 17:20:09 -0400120 @Override
121 protected void onAttachedToWindow() {
122 super.onAttachedToWindow();
Evan Laird91d0f102018-09-18 17:39:55 -0400123 Dependency.get(StatusBarStateController.class)
124 .addListener(mStateListener, StatusBarStateController.RANK_SHELF);
Jason Monk1fd3fc32018-08-14 17:20:09 -0400125 }
126
127 @Override
128 protected void onDetachedFromWindow() {
129 super.onDetachedFromWindow();
130 Dependency.get(StatusBarStateController.class).removeListener(mStateListener);
131 }
132
Selim Cinekc383fd02016-10-21 15:31:26 -0700133 public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout) {
134 mAmbientState = ambientState;
135 mHostLayout = hostLayout;
136 }
137
Selim Cinek281c2022016-10-13 19:14:43 -0700138 private void initDimens() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700139 Resources res = getResources();
140 mIconAppearTopPadding = res.getDimensionPixelSize(R.dimen.notification_icon_appear_padding);
141 mStatusBarHeight = res.getDimensionPixelOffset(R.dimen.status_bar_height);
142 mStatusBarPaddingStart = res.getDimensionPixelOffset(R.dimen.status_bar_padding_start);
143 mPaddingBetweenElements = res.getDimensionPixelSize(R.dimen.notification_divider_height);
Lucas Dupinb561eda2018-04-09 17:25:04 -0700144 mShelfAppearTranslation = res.getDimensionPixelSize(R.dimen.shelf_appear_translation);
Anthony Chen9e05d462017-04-07 10:10:21 -0700145
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800146 ViewGroup.LayoutParams layoutParams = getLayoutParams();
Anthony Chen9e05d462017-04-07 10:10:21 -0700147 layoutParams.height = res.getDimensionPixelOffset(R.dimen.notification_shelf_height);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800148 setLayoutParams(layoutParams);
Anthony Chen9e05d462017-04-07 10:10:21 -0700149
150 int padding = res.getDimensionPixelOffset(R.dimen.shelf_icon_container_padding);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800151 mShelfIcons.setPadding(padding, 0, padding, 0);
Anthony Chen9e05d462017-04-07 10:10:21 -0700152 mScrollFastThreshold = res.getDimensionPixelOffset(R.dimen.scroll_fast_threshold);
153 mShowNotificationShelf = res.getBoolean(R.bool.config_showNotificationShelf);
Selim Cinekb42698f2017-07-31 17:47:45 -0700154 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
Gus Prevase2d6f042018-10-17 15:25:30 -0400155 mGapHeight = res.getDimensionPixelSize(R.dimen.qs_notification_padding);
Anthony Chen9e05d462017-04-07 10:10:21 -0700156
157 if (!mShowNotificationShelf) {
158 setVisibility(GONE);
159 }
Selim Cinek281c2022016-10-13 19:14:43 -0700160 }
161
162 @Override
163 protected void onConfigurationChanged(Configuration newConfig) {
164 super.onConfigurationChanged(newConfig);
165 initDimens();
166 }
167
168 @Override
169 public void setDark(boolean dark, boolean fade, long delay) {
170 super.setDark(dark, fade, delay);
171 if (mDark == dark) return;
172 mDark = dark;
Adrian Roos456e0052017-04-04 16:44:29 -0700173 mShelfIcons.setDark(dark, fade, delay);
Adrian Roos03cf2582017-03-28 17:54:05 -0700174 updateInteractiveness();
Selim Cinek281c2022016-10-13 19:14:43 -0700175 }
176
177 @Override
178 protected View getContentView() {
Selim Cinek49014f82016-11-04 14:55:30 -0700179 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700180 }
181
Selim Cinek49014f82016-11-04 14:55:30 -0700182 public NotificationIconContainer getShelfIcons() {
183 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700184 }
185
186 @Override
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500187 public ExpandableViewState createExpandableViewState() {
188 return new ShelfState();
Selim Cinek281c2022016-10-13 19:14:43 -0700189 }
190
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500191 /** Update the state of the shelf. */
192 public void updateState(AmbientState ambientState) {
193 ExpandableView lastView = ambientState.getLastVisibleBackgroundChild();
194 ShelfState viewState = (ShelfState) getViewState();
Anthony Chen9e05d462017-04-07 10:10:21 -0700195 if (mShowNotificationShelf && lastView != null) {
Selim Cinek281c2022016-10-13 19:14:43 -0700196 float maxShelfEnd = ambientState.getInnerHeight() + ambientState.getTopPadding()
197 + ambientState.getStackTranslation();
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500198 ExpandableViewState lastViewState = lastView.getViewState();
Selim Cinek281c2022016-10-13 19:14:43 -0700199 float viewEnd = lastViewState.yTranslation + lastViewState.height;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500200 viewState.copyFrom(lastViewState);
201 viewState.height = getIntrinsicHeight();
Lucas Dupinb561eda2018-04-09 17:25:04 -0700202
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500203 float awakenTranslation = Math.max(Math.min(viewEnd, maxShelfEnd) - viewState.height,
Selim Cinek49014f82016-11-04 14:55:30 -0700204 getFullyClosedTranslation());
Lucas Dupinb561eda2018-04-09 17:25:04 -0700205 float darkTranslation = mAmbientState.getDarkTopPadding();
206 float yRatio = mAmbientState.hasPulsingNotifications() ?
207 0 : mAmbientState.getDarkAmount();
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500208 viewState.yTranslation = MathUtils.lerp(awakenTranslation, darkTranslation, yRatio);
209 viewState.zTranslation = ambientState.getBaseZHeight();
felkachangc02c3882018-07-27 15:32:31 +0800210 // For the small display size, it's not enough to make the icon not covered by
211 // the top cutout so the denominator add the height of cutout.
212 // Totally, (getIntrinsicHeight() * 2 + mCutoutHeight) should be smaller then
213 // mAmbientState.getTopPadding().
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500214 float openedAmount = (viewState.yTranslation - getFullyClosedTranslation())
felkachangc02c3882018-07-27 15:32:31 +0800215 / (getIntrinsicHeight() * 2 + mCutoutHeight);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800216 openedAmount = Math.min(1.0f, openedAmount);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500217 viewState.openedAmount = openedAmount;
218 viewState.clipTopAmount = 0;
219 viewState.alpha = mAmbientState.hasPulsingNotifications() ? 0 : 1;
220 viewState.belowSpeedBump = mAmbientState.getSpeedBumpIndex() == 0;
221 viewState.hideSensitive = false;
222 viewState.xTranslation = getTranslationX();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700223 if (mNotGoneIndex != -1) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500224 viewState.notGoneIndex = Math.min(viewState.notGoneIndex, mNotGoneIndex);
Selim Cinekeccb5de2016-10-28 15:04:05 -0700225 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500226 viewState.hasItemsInStableShelf = lastViewState.inShelf;
227 viewState.hidden = !mAmbientState.isShadeExpanded()
Selim Cinek5cf1d052017-06-01 17:36:46 -0700228 || mAmbientState.isQsCustomizerShowing();
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500229 viewState.maxShelfEnd = maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700230 } else {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500231 viewState.hidden = true;
232 viewState.location = ExpandableViewState.LOCATION_GONE;
233 viewState.hasItemsInStableShelf = false;
Selim Cinek281c2022016-10-13 19:14:43 -0700234 }
235 }
236
Selim Cinekc383fd02016-10-21 15:31:26 -0700237 /**
238 * Update the shelf appearance based on the other notifications around it. This transforms
239 * the icons from the notification area into the shelf.
240 */
241 public void updateAppearance() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700242 // If the shelf should not be shown, then there is no need to update anything.
243 if (!mShowNotificationShelf) {
244 return;
245 }
246
Selim Cinek65d418e2016-11-29 15:42:34 -0800247 mShelfIcons.resetViewStates();
248 float shelfStart = getTranslationY();
Selim Cinekdb167372016-11-17 15:41:17 -0800249 float numViewsInShelf = 0.0f;
250 View lastChild = mAmbientState.getLastVisibleBackgroundChild();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700251 mNotGoneIndex = -1;
Selim Cinek49014f82016-11-04 14:55:30 -0700252 float interpolationStart = mMaxLayoutHeight - getIntrinsicHeight() * 2;
253 float expandAmount = 0.0f;
Selim Cinek65d418e2016-11-29 15:42:34 -0800254 if (shelfStart >= interpolationStart) {
255 expandAmount = (shelfStart - interpolationStart) / getIntrinsicHeight();
Selim Cinek49014f82016-11-04 14:55:30 -0700256 expandAmount = Math.min(1.0f, expandAmount);
257 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700258 // find the first view that doesn't overlap with the shelf
Selim Cinekdb167372016-11-17 15:41:17 -0800259 int notGoneIndex = 0;
Selim Cinekec29d342017-05-05 18:31:49 -0700260 int colorOfViewBeforeLast = NO_COLOR;
Selim Cinekdb167372016-11-17 15:41:17 -0800261 boolean backgroundForceHidden = false;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500262 if (mHideBackground && !((ShelfState) getViewState()).hasItemsInStableShelf) {
Selim Cinekdb167372016-11-17 15:41:17 -0800263 backgroundForceHidden = true;
264 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800265 int colorTwoBefore = NO_COLOR;
266 int previousColor = NO_COLOR;
267 float transitionAmount = 0.0f;
Selim Cineka1d97902016-12-14 16:31:40 -0800268 float currentScrollVelocity = mAmbientState.getCurrentScrollVelocity();
269 boolean scrollingFast = currentScrollVelocity > mScrollFastThreshold
Selim Cinekd5ab6452016-12-08 16:34:00 -0800270 || (mAmbientState.isExpansionChanging()
271 && Math.abs(mAmbientState.getExpandingVelocity()) > mScrollFastThreshold);
Selim Cineka1d97902016-12-14 16:31:40 -0800272 boolean scrolling = currentScrollVelocity > 0;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800273 boolean expandingAnimated = mAmbientState.isExpansionChanging()
274 && !mAmbientState.isPanelTracking();
Selim Cinek65d418e2016-11-29 15:42:34 -0800275 int baseZHeight = mAmbientState.getBaseZHeight();
Selim Cinek515b2032017-11-15 10:20:19 -0800276 int backgroundTop = 0;
277 float firstElementRoundness = 0.0f;
Gus Prevase2d6f042018-10-17 15:25:30 -0400278 ExpandableNotificationRow previousRow = null;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700279
280 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
281 ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i);
282
Selim Cinekc383fd02016-10-21 15:31:26 -0700283 if (!(child instanceof ExpandableNotificationRow)
284 || child.getVisibility() == GONE) {
285 continue;
286 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700287
Selim Cinekc383fd02016-10-21 15:31:26 -0700288 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cineka686b2c2016-10-26 13:58:27 -0700289 float notificationClipEnd;
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800290 boolean aboveShelf = ViewState.getFinalTranslationZ(row) > baseZHeight
291 || row.isPinned();
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800292 boolean isLastChild = child == lastChild;
Selim Cinek65d418e2016-11-29 15:42:34 -0800293 float rowTranslationY = row.getTranslationY();
Selim Cinek3ff9fba2017-07-20 10:47:48 -0700294 if ((isLastChild && !child.isInShelf()) || aboveShelf || backgroundForceHidden) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700295 notificationClipEnd = shelfStart + getIntrinsicHeight();
296 } else {
Selim Cineka686b2c2016-10-26 13:58:27 -0700297 notificationClipEnd = shelfStart - mPaddingBetweenElements;
Selim Cinek65d418e2016-11-29 15:42:34 -0800298 float height = notificationClipEnd - rowTranslationY;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800299 if (!row.isBelowSpeedBump() && height <= getNotificationMergeSize()) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700300 // We want the gap to close when we reached the minimum size and only shrink
301 // before
302 notificationClipEnd = Math.min(shelfStart,
Selim Cinek65d418e2016-11-29 15:42:34 -0800303 rowTranslationY + getNotificationMergeSize());
Selim Cineka686b2c2016-10-26 13:58:27 -0700304 }
305 }
306 updateNotificationClipHeight(row, notificationClipEnd);
Selim Cineka1d97902016-12-14 16:31:40 -0800307 float inShelfAmount = updateIconAppearance(row, expandAmount, scrolling, scrollingFast,
Selim Cinekd5ab6452016-12-08 16:34:00 -0800308 expandingAnimated, isLastChild);
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800309 numViewsInShelf += inShelfAmount;
310 int ownColorUntinted = row.getBackgroundColorWithoutTint();
Selim Cinek65d418e2016-11-29 15:42:34 -0800311 if (rowTranslationY >= shelfStart && mNotGoneIndex == -1) {
Selim Cinekdb167372016-11-17 15:41:17 -0800312 mNotGoneIndex = notGoneIndex;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800313 setTintColor(previousColor);
314 setOverrideTintColor(colorTwoBefore, transitionAmount);
315
316 } else if (mNotGoneIndex == -1) {
317 colorTwoBefore = previousColor;
318 transitionAmount = inShelfAmount;
319 }
Selim Cinekec29d342017-05-05 18:31:49 -0700320 if (isLastChild) {
321 if (colorOfViewBeforeLast == NO_COLOR) {
322 colorOfViewBeforeLast = ownColorUntinted;
323 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800324 row.setOverrideTintColor(colorOfViewBeforeLast, inShelfAmount);
325 } else {
326 colorOfViewBeforeLast = ownColorUntinted;
327 row.setOverrideTintColor(NO_COLOR, 0 /* overrideAmount */);
Selim Cinekeccb5de2016-10-28 15:04:05 -0700328 }
Selim Cinekdb167372016-11-17 15:41:17 -0800329 if (notGoneIndex != 0 || !aboveShelf) {
Selim Cinekd127d792016-11-01 19:11:41 -0700330 row.setAboveShelf(false);
331 }
Selim Cinek0fe07392017-11-09 13:26:34 -0800332 if (notGoneIndex == 0) {
333 StatusBarIconView icon = row.getEntry().expandedIcon;
334 NotificationIconContainer.IconState iconState = getIconState(icon);
Selim Cinekb7bafbc2017-12-21 11:33:26 -0800335 if (iconState != null && iconState.clampedAppearAmount == 1.0f) {
Selim Cinek0fe07392017-11-09 13:26:34 -0800336 // only if the first icon is fully in the shelf we want to clip to it!
Selim Cinek515b2032017-11-15 10:20:19 -0800337 backgroundTop = (int) (row.getTranslationY() - getTranslationY());
338 firstElementRoundness = row.getCurrentTopRoundness();
Selim Cinekb7bafbc2017-12-21 11:33:26 -0800339 } else if (iconState == null) {
340 Log.wtf(TAG, "iconState is null. ExpandedIcon: " + row.getEntry().expandedIcon
341 + (row.getEntry().expandedIcon != null
342 ? "\n icon parent: " + row.getEntry().expandedIcon.getParent() : "")
343 + " \n number of notifications: " + mHostLayout.getChildCount() );
Selim Cinek0fe07392017-11-09 13:26:34 -0800344 }
345 }
Gus Prevase2d6f042018-10-17 15:25:30 -0400346 if (row.isFirstInSection() && previousRow != null && previousRow.isLastInSection()) {
347 // If the top of the shelf is between the view before a gap and the view after a gap
348 // then we need to adjust the shelf's top roundness.
349 float distanceToGapBottom = row.getTranslationY() - getTranslationY();
350 float distanceToGapTop = getTranslationY()
351 - (previousRow.getTranslationY() + previousRow.getActualHeight());
352 if (distanceToGapTop > 0) {
353 // We interpolate our top roundness so that it's fully rounded if we're at the
354 // bottom of the gap, and not rounded at all if we're at the top of the gap
355 // (directly up against the bottom of previousRow)
356 // Then we apply the same roundness to the bottom of previousRow so that the
357 // corners join together as the shelf approaches previousRow.
358 firstElementRoundness = (float) Math.min(1.0, distanceToGapTop / mGapHeight);
359 previousRow.setBottomRoundness(firstElementRoundness,
360 false /* don't animate */);
361 backgroundTop = (int) distanceToGapBottom;
362 }
363 }
Selim Cinekdb167372016-11-17 15:41:17 -0800364 notGoneIndex++;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800365 previousColor = ownColorUntinted;
Gus Prevase2d6f042018-10-17 15:25:30 -0400366 previousRow = row;
Selim Cineka686b2c2016-10-26 13:58:27 -0700367 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700368
369 clipTransientViews();
370
Selim Cinek515b2032017-11-15 10:20:19 -0800371 setBackgroundTop(backgroundTop);
372 setFirstElementRoundness(firstElementRoundness);
Selim Cinek17e1b692016-12-02 18:19:11 -0800373 mShelfIcons.setSpeedBumpIndex(mAmbientState.getSpeedBumpIndex());
Selim Cinek49014f82016-11-04 14:55:30 -0700374 mShelfIcons.calculateIconTranslations();
375 mShelfIcons.applyIconStates();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700376 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
377 View child = mHostLayout.getChildAt(i);
378 if (!(child instanceof ExpandableNotificationRow)
379 || child.getVisibility() == GONE) {
380 continue;
381 }
382 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
383 updateIconClipAmount(row);
384 updateContinuousClipping(row);
385 }
Selim Cinekdb167372016-11-17 15:41:17 -0800386 boolean hideBackground = numViewsInShelf < 1.0f;
387 setHideBackground(hideBackground || backgroundForceHidden);
388 if (mNotGoneIndex == -1) {
389 mNotGoneIndex = notGoneIndex;
390 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800391 }
392
Rohan Shah524cf7b2018-03-15 14:40:02 -0700393 /**
394 * Clips transient views to the top of the shelf - Transient views are only used for
395 * disappearing views/animations and need to be clipped correctly by the shelf to ensure they
396 * don't show underneath the notification stack when something is animating and the user
397 * swipes quickly.
398 */
399 private void clipTransientViews() {
400 for (int i = 0; i < mHostLayout.getTransientViewCount(); i++) {
401 View transientView = mHostLayout.getTransientView(i);
402 if (transientView instanceof ExpandableNotificationRow) {
403 ExpandableNotificationRow transientRow = (ExpandableNotificationRow) transientView;
404 updateNotificationClipHeight(transientRow, getTranslationY());
405 } else {
406 Log.e(TAG, "NotificationShelf.clipTransientViews(): "
407 + "Trying to clip non-row transient view");
408 }
409 }
410 }
411
Selim Cinek515b2032017-11-15 10:20:19 -0800412 private void setFirstElementRoundness(float firstElementRoundness) {
413 if (mFirstElementRoundness != firstElementRoundness) {
414 mFirstElementRoundness = firstElementRoundness;
415 setTopRoundness(firstElementRoundness, false /* animate */);
Selim Cinek0fe07392017-11-09 13:26:34 -0800416 }
417 }
418
Selim Cinek6eaacf22017-09-07 18:53:17 -0700419 private void updateIconClipAmount(ExpandableNotificationRow row) {
420 float maxTop = row.getTranslationY();
421 StatusBarIconView icon = row.getEntry().expandedIcon;
422 float shelfIconPosition = getTranslationY() + icon.getTop() + icon.getTranslationY();
Lucas Dupin23a8d3b2018-10-08 20:57:35 -0700423 if (shelfIconPosition < maxTop) {
Selim Cinek6eaacf22017-09-07 18:53:17 -0700424 int top = (int) (maxTop - shelfIconPosition);
425 Rect clipRect = new Rect(0, top, icon.getWidth(), Math.max(top, icon.getHeight()));
426 icon.setClipBounds(clipRect);
Gus Prevasab3ad1d2018-11-01 17:11:59 -0400427 } else {
428 icon.setClipBounds(null);
Selim Cinek6eaacf22017-09-07 18:53:17 -0700429 }
430 }
431
432 private void updateContinuousClipping(final ExpandableNotificationRow row) {
433 StatusBarIconView icon = row.getEntry().expandedIcon;
Lucas Dupin23a8d3b2018-10-08 20:57:35 -0700434 boolean needsContinuousClipping = ViewState.isAnimatingY(icon);
Selim Cinek6eaacf22017-09-07 18:53:17 -0700435 boolean isContinuousClipping = icon.getTag(TAG_CONTINUOUS_CLIPPING) != null;
436 if (needsContinuousClipping && !isContinuousClipping) {
Selim Cinek85845b82018-04-25 13:10:57 +0800437 final ViewTreeObserver observer = icon.getViewTreeObserver();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700438 ViewTreeObserver.OnPreDrawListener predrawListener =
439 new ViewTreeObserver.OnPreDrawListener() {
440 @Override
441 public boolean onPreDraw() {
442 boolean animatingY = ViewState.isAnimatingY(icon);
Selim Cinek85845b82018-04-25 13:10:57 +0800443 if (!animatingY) {
Robert Snoebergered77b452018-10-12 17:22:06 +0000444 if (observer.isAlive()) {
445 observer.removeOnPreDrawListener(this);
446 }
Selim Cinek6eaacf22017-09-07 18:53:17 -0700447 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
448 return true;
449 }
450 updateIconClipAmount(row);
451 return true;
452 }
453 };
Selim Cinek85845b82018-04-25 13:10:57 +0800454 observer.addOnPreDrawListener(predrawListener);
455 icon.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
456 @Override
457 public void onViewAttachedToWindow(View v) {
458 }
459
460 @Override
461 public void onViewDetachedFromWindow(View v) {
462 if (v == icon) {
Robert Snoebergered77b452018-10-12 17:22:06 +0000463 if (observer.isAlive()) {
464 observer.removeOnPreDrawListener(predrawListener);
465 }
Selim Cinek85845b82018-04-25 13:10:57 +0800466 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
467 }
468 }
469 });
Selim Cinek6eaacf22017-09-07 18:53:17 -0700470 icon.setTag(TAG_CONTINUOUS_CLIPPING, predrawListener);
471 }
472 }
473
Selim Cineka686b2c2016-10-26 13:58:27 -0700474 private void updateNotificationClipHeight(ExpandableNotificationRow row,
475 float notificationClipEnd) {
476 float viewEnd = row.getTranslationY() + row.getActualHeight();
Selim Cinekebf42342017-07-13 15:46:10 +0200477 boolean isPinned = (row.isPinned() || row.isHeadsUpAnimatingAway())
478 && !mAmbientState.isDozingAndNotPulsing(row);
Selim Cinekd127d792016-11-01 19:11:41 -0700479 if (viewEnd > notificationClipEnd
Selim Cinek7e0f9482017-05-22 20:00:56 -0700480 && (mAmbientState.isShadeExpanded() || !isPinned)) {
481 int clipBottomAmount = (int) (viewEnd - notificationClipEnd);
482 if (isPinned) {
483 clipBottomAmount = Math.min(row.getIntrinsicHeight() - row.getCollapsedHeight(),
484 clipBottomAmount);
485 }
486 row.setClipBottomAmount(clipBottomAmount);
Selim Cineka686b2c2016-10-26 13:58:27 -0700487 } else {
488 row.setClipBottomAmount(0);
489 }
490 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700491
Selim Cinekc8c4cf92017-09-08 15:30:09 -0700492 @Override
493 public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd,
494 int outlineTranslation) {
495 if (!mHasItemsInStableShelf) {
496 shadowIntensity = 0.0f;
497 }
498 super.setFakeShadowIntensity(shadowIntensity, outlineAlpha, shadowYEnd, outlineTranslation);
499 }
500
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800501 /**
502 * @return the icon amount how much this notification is in the shelf;
503 */
Selim Cinek2b549f42016-11-22 16:38:51 -0800504 private float updateIconAppearance(ExpandableNotificationRow row, float expandAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800505 boolean scrolling, boolean scrollingFast, boolean expandingAnimated,
506 boolean isLastChild) {
Selim Cinek1f624952017-06-08 19:11:50 -0700507 StatusBarIconView icon = row.getEntry().expandedIcon;
508 NotificationIconContainer.IconState iconState = getIconState(icon);
509 if (iconState == null) {
510 return 0.0f;
511 }
512
Selim Cinekc383fd02016-10-21 15:31:26 -0700513 // Let calculate how much the view is in the shelf
514 float viewStart = row.getTranslationY();
Selim Cinek2b549f42016-11-22 16:38:51 -0800515 int fullHeight = row.getActualHeight() + mPaddingBetweenElements;
516 float iconTransformDistance = getIntrinsicHeight() * 1.5f;
Selim Cineka1d97902016-12-14 16:31:40 -0800517 iconTransformDistance *= NotificationUtils.interpolate(1.f, 1.5f, expandAmount);
Selim Cinek1f624952017-06-08 19:11:50 -0700518 iconTransformDistance = Math.min(iconTransformDistance, fullHeight);
Selim Cinek938bdaa2016-11-18 16:31:09 -0800519 if (isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800520 fullHeight = Math.min(fullHeight, row.getMinHeight() - getIntrinsicHeight());
Bill Line6065e32018-06-08 17:07:13 +0800521 iconTransformDistance = Math.min(iconTransformDistance, row.getMinHeight()
522 - getIntrinsicHeight());
Selim Cinek938bdaa2016-11-18 16:31:09 -0800523 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800524 float viewEnd = viewStart + fullHeight;
Selim Cinek1f624952017-06-08 19:11:50 -0700525 if (expandingAnimated && mAmbientState.getScrollY() == 0
526 && !mAmbientState.isOnKeyguard() && !iconState.isLastExpandIcon) {
527 // We are expanding animated. Because we switch to a linear interpolation in this case,
528 // the last icon may be stuck in between the shelf position and the notification
529 // position, which looks pretty bad. We therefore optimize this case by applying a
530 // shorter transition such that the icon is either fully in the notification or we clamp
531 // it into the shelf if it's close enough.
532 // We need to persist this, since after the expansion, the behavior should still be the
533 // same.
534 float position = mAmbientState.getIntrinsicPadding()
535 + mHostLayout.getPositionInLinearLayout(row);
536 int maxShelfStart = mMaxLayoutHeight - getIntrinsicHeight();
537 if (position < maxShelfStart && position + row.getIntrinsicHeight() >= maxShelfStart
538 && row.getTranslationY() < position) {
539 iconState.isLastExpandIcon = true;
540 iconState.customTransformHeight = NO_VALUE;
541 // Let's check if we're close enough to snap into the shelf
542 boolean forceInShelf = mMaxLayoutHeight - getIntrinsicHeight() - position
543 < getIntrinsicHeight();
544 if (!forceInShelf) {
545 // We are overlapping the shelf but not enough, so the icon needs to be
546 // repositioned
547 iconState.customTransformHeight = (int) (mMaxLayoutHeight
548 - getIntrinsicHeight() - position);
549 }
550 }
551 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800552 float fullTransitionAmount;
Selim Cinek01a73f92016-12-06 16:13:42 -0800553 float iconTransitionAmount;
554 float shelfStart = getTranslationY();
Selim Cinek1f624952017-06-08 19:11:50 -0700555 if (iconState.hasCustomTransformHeight()) {
556 fullHeight = iconState.customTransformHeight;
557 iconTransformDistance = iconState.customTransformHeight;
558 }
559 boolean fullyInOrOut = true;
Selim Cinekec29d342017-05-05 18:31:49 -0700560 if (viewEnd >= shelfStart && (!mAmbientState.isUnlockHintRunning() || row.isInShelf())
561 && (mAmbientState.isShadeExpanded()
562 || (!row.isPinned() && !row.isHeadsUpAnimatingAway()))) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800563 if (viewStart < shelfStart) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800564 float fullAmount = (shelfStart - viewStart) / fullHeight;
Selim Cinek1f624952017-06-08 19:11:50 -0700565 fullAmount = Math.min(1.0f, fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700566 float interpolatedAmount = Interpolators.ACCELERATE_DECELERATE.getInterpolation(
Selim Cinek2b549f42016-11-22 16:38:51 -0800567 fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700568 interpolatedAmount = NotificationUtils.interpolate(
Selim Cinek2b549f42016-11-22 16:38:51 -0800569 interpolatedAmount, fullAmount, expandAmount);
570 fullTransitionAmount = 1.0f - interpolatedAmount;
571
Selim Cinek01a73f92016-12-06 16:13:42 -0800572 iconTransitionAmount = (shelfStart - viewStart) / iconTransformDistance;
573 iconTransitionAmount = Math.min(1.0f, iconTransitionAmount);
574 iconTransitionAmount = 1.0f - iconTransitionAmount;
Selim Cinek1f624952017-06-08 19:11:50 -0700575 fullyInOrOut = false;
Selim Cinekc383fd02016-10-21 15:31:26 -0700576 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800577 fullTransitionAmount = 1.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800578 iconTransitionAmount = 1.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700579 }
580 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800581 fullTransitionAmount = 0.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800582 iconTransitionAmount = 0.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700583 }
Selim Cinek1f624952017-06-08 19:11:50 -0700584 if (fullyInOrOut && !expandingAnimated && iconState.isLastExpandIcon) {
585 iconState.isLastExpandIcon = false;
586 iconState.customTransformHeight = NO_VALUE;
587 }
Selim Cineka1d97902016-12-14 16:31:40 -0800588 updateIconPositioning(row, iconTransitionAmount, fullTransitionAmount,
589 iconTransformDistance, scrolling, scrollingFast, expandingAnimated, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800590 return fullTransitionAmount;
591 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700592
Selim Cinek2b549f42016-11-22 16:38:51 -0800593 private void updateIconPositioning(ExpandableNotificationRow row, float iconTransitionAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800594 float fullTransitionAmount, float iconTransformDistance, boolean scrolling,
595 boolean scrollingFast, boolean expandingAnimated, boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800596 StatusBarIconView icon = row.getEntry().expandedIcon;
597 NotificationIconContainer.IconState iconState = getIconState(icon);
598 if (iconState == null) {
599 return;
600 }
Selim Cinek1f624952017-06-08 19:11:50 -0700601 boolean forceInShelf = iconState.isLastExpandIcon && !iconState.hasCustomTransformHeight();
Selim Cinek2b549f42016-11-22 16:38:51 -0800602 float clampedAmount = iconTransitionAmount > 0.5f ? 1.0f : 0.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800603 if (clampedAmount == fullTransitionAmount) {
Selim Cinek1f624952017-06-08 19:11:50 -0700604 iconState.noAnimations = (scrollingFast || expandingAnimated) && !forceInShelf;
Selim Cinek44d81a62017-05-08 19:45:40 -0700605 iconState.useFullTransitionAmount = iconState.noAnimations
Selim Cineka1d97902016-12-14 16:31:40 -0800606 || (!ICON_ANMATIONS_WHILE_SCROLLING && fullTransitionAmount == 0.0f && scrolling);
607 iconState.useLinearTransitionAmount = !ICON_ANMATIONS_WHILE_SCROLLING
608 && fullTransitionAmount == 0.0f && !mAmbientState.isExpansionChanging();
Selim Cinek01a73f92016-12-06 16:13:42 -0800609 iconState.translateContent = mMaxLayoutHeight - getTranslationY()
610 - getIntrinsicHeight() > 0;
Selim Cinek2b549f42016-11-22 16:38:51 -0800611 }
Selim Cinek1f624952017-06-08 19:11:50 -0700612 if (!forceInShelf && (scrollingFast || (expandingAnimated
613 && iconState.useFullTransitionAmount && !ViewState.isAnimatingY(icon)))) {
Selim Cinekd5ab6452016-12-08 16:34:00 -0800614 iconState.cancelAnimations(icon);
615 iconState.useFullTransitionAmount = true;
Selim Cinek44d81a62017-05-08 19:45:40 -0700616 iconState.noAnimations = true;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800617 }
Selim Cinek1f624952017-06-08 19:11:50 -0700618 if (iconState.hasCustomTransformHeight()) {
619 iconState.useFullTransitionAmount = true;
620 }
621 if (iconState.isLastExpandIcon) {
622 iconState.translateContent = false;
623 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800624 float transitionAmount;
Lucas Dupin23a8d3b2018-10-08 20:57:35 -0700625 if (isLastChild || !USE_ANIMATIONS_WHEN_OPENING || iconState.useFullTransitionAmount
Selim Cineka1d97902016-12-14 16:31:40 -0800626 || iconState.useLinearTransitionAmount) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800627 transitionAmount = iconTransitionAmount;
Selim Cinek2b549f42016-11-22 16:38:51 -0800628 } else {
Selim Cineka1d97902016-12-14 16:31:40 -0800629 // We take the clamped position instead
630 transitionAmount = clampedAmount;
Selim Cinek2fce3c82017-05-08 12:38:09 -0700631 iconState.needsCannedAnimation = iconState.clampedAppearAmount != clampedAmount
632 && !mNoAnimationsInThisFrame;
Selim Cinek2b549f42016-11-22 16:38:51 -0800633 }
634 iconState.iconAppearAmount = !USE_ANIMATIONS_WHEN_OPENING
635 || iconState.useFullTransitionAmount
636 ? fullTransitionAmount
637 : transitionAmount;
638 iconState.clampedAppearAmount = clampedAmount;
Selim Cinekebf42342017-07-13 15:46:10 +0200639 float contentTransformationAmount = !mAmbientState.isAboveShelf(row)
Selim Cinek7e0f9482017-05-22 20:00:56 -0700640 && (isLastChild || iconState.translateContent)
Selim Cinek01a73f92016-12-06 16:13:42 -0800641 ? iconTransitionAmount
642 : 0.0f;
643 row.setContentTransformationAmount(contentTransformationAmount, isLastChild);
Selim Cineka1d97902016-12-14 16:31:40 -0800644 setIconTransformationAmount(row, transitionAmount, iconTransformDistance,
Mady Mellor434180c2017-02-13 11:29:42 -0800645 clampedAmount != transitionAmount, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800646 }
647
648 private void setIconTransformationAmount(ExpandableNotificationRow row,
Mady Mellor434180c2017-02-13 11:29:42 -0800649 float transitionAmount, float iconTransformDistance, boolean usingLinearInterpolation,
650 boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800651 StatusBarIconView icon = row.getEntry().expandedIcon;
652 NotificationIconContainer.IconState iconState = getIconState(icon);
653
Selim Cinekc383fd02016-10-21 15:31:26 -0700654 View rowIcon = row.getNotificationIcon();
Selim Cineka1d97902016-12-14 16:31:40 -0800655 float notificationIconPosition = row.getTranslationY() + row.getContentTranslation();
Selim Cinekf20254c2017-02-03 10:09:33 -0800656 boolean stayingInShelf = row.isInShelf() && !row.isTransformingIntoShelf();
657 if (usingLinearInterpolation && !stayingInShelf) {
Selim Cineka1d97902016-12-14 16:31:40 -0800658 // If we interpolate from the notification position, this might lead to a slightly
659 // odd interpolation, since the notification position changes as well. Let's interpolate
660 // from a fixed distance. We can only do this if we don't animate and the icon is
661 // always in the interpolated positon.
Selim Cinekf20254c2017-02-03 10:09:33 -0800662 notificationIconPosition = getTranslationY() - iconTransformDistance;
Selim Cineka1d97902016-12-14 16:31:40 -0800663 }
Selim Cinek281c2022016-10-13 19:14:43 -0700664 float notificationIconSize = 0.0f;
665 int iconTopPadding;
666 if (rowIcon != null) {
Selim Cinek875a3a12016-11-18 17:52:16 -0800667 iconTopPadding = row.getRelativeTopPadding(rowIcon);
Selim Cinek281c2022016-10-13 19:14:43 -0700668 notificationIconSize = rowIcon.getHeight();
669 } else {
670 iconTopPadding = mIconAppearTopPadding;
671 }
672 notificationIconPosition += iconTopPadding;
Selim Cinekc383fd02016-10-21 15:31:26 -0700673 float shelfIconPosition = getTranslationY() + icon.getTop();
Selim Cinekb42698f2017-07-31 17:47:45 -0700674 shelfIconPosition += (icon.getHeight() - icon.getIconScale() * mIconSize) / 2.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800675 float iconYTranslation = NotificationUtils.interpolate(
Selim Cineka1d97902016-12-14 16:31:40 -0800676 notificationIconPosition - shelfIconPosition,
Selim Cinek2b549f42016-11-22 16:38:51 -0800677 0,
678 transitionAmount);
Selim Cinekb42698f2017-07-31 17:47:45 -0700679 float shelfIconSize = mIconSize * icon.getIconScale();
Selim Cinek2b549f42016-11-22 16:38:51 -0800680 float alpha = 1.0f;
Selim Cinek875ba9b2017-02-13 16:20:17 -0800681 boolean noIcon = !row.isShowingIcon();
682 if (noIcon) {
Selim Cinekc383fd02016-10-21 15:31:26 -0700683 // The view currently doesn't have an icon, lets transform it in!
Selim Cinekdb167372016-11-17 15:41:17 -0800684 alpha = transitionAmount;
Selim Cinekc383fd02016-10-21 15:31:26 -0700685 notificationIconSize = shelfIconSize / 2.0f;
686 }
687 // The notification size is different from the size in the shelf / statusbar
688 float newSize = NotificationUtils.interpolate(notificationIconSize, shelfIconSize,
Selim Cinek281c2022016-10-13 19:14:43 -0700689 transitionAmount);
Selim Cinekdb167372016-11-17 15:41:17 -0800690 if (iconState != null) {
Selim Cinekb42698f2017-07-31 17:47:45 -0700691 iconState.scaleX = newSize / shelfIconSize;
Selim Cinekdb167372016-11-17 15:41:17 -0800692 iconState.scaleY = iconState.scaleX;
Adrian Roos28f90c72017-05-08 17:24:26 -0700693 iconState.hidden = transitionAmount == 0.0f && !iconState.isAnimating(icon);
Selim Cinekf38d6c32017-06-28 15:44:02 +0200694 boolean isAppearing = row.isDrawingAppearAnimation() && !row.isInShelf();
695 if (isAppearing) {
696 iconState.hidden = true;
697 iconState.iconAppearAmount = 0.0f;
698 }
Selim Cinekdb167372016-11-17 15:41:17 -0800699 iconState.alpha = alpha;
Selim Cinek2b549f42016-11-22 16:38:51 -0800700 iconState.yTranslation = iconYTranslation;
Selim Cinekf20254c2017-02-03 10:09:33 -0800701 if (stayingInShelf) {
Selim Cinekdb167372016-11-17 15:41:17 -0800702 iconState.iconAppearAmount = 1.0f;
703 iconState.alpha = 1.0f;
704 iconState.scaleX = 1.0f;
705 iconState.scaleY = 1.0f;
706 iconState.hidden = false;
707 }
Selim Cinekebf42342017-07-13 15:46:10 +0200708 if (mAmbientState.isAboveShelf(row) || (!row.isInShelf() && (isLastChild && row.areGutsExposed()
Selim Cinek47374632017-03-17 16:07:17 -0700709 || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) {
Selim Cinek5ea19572016-11-29 15:34:48 -0800710 iconState.hidden = true;
711 }
Lucas Dupin83519da2017-06-21 11:58:31 -0700712 int backgroundColor = getBackgroundColorWithoutTint();
713 int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor);
Selim Cinek875ba9b2017-02-13 16:20:17 -0800714 if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) {
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700715 int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor();
716 shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor,
Selim Cinek875ba9b2017-02-13 16:20:17 -0800717 iconState.iconAppearAmount);
718 }
719 iconState.iconColor = shelfColor;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700720 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800721 }
722
723 private NotificationIconContainer.IconState getIconState(StatusBarIconView icon) {
724 return mShelfIcons.getIconState(icon);
Selim Cinekc383fd02016-10-21 15:31:26 -0700725 }
726
727 private float getFullyClosedTranslation() {
728 return - (getIntrinsicHeight() - mStatusBarHeight) / 2;
Selim Cinek281c2022016-10-13 19:14:43 -0700729 }
730
Selim Cinek281c2022016-10-13 19:14:43 -0700731 public int getNotificationMergeSize() {
732 return getIntrinsicHeight();
733 }
734
735 @Override
736 public boolean hasNoContentHeight() {
737 return true;
738 }
Selim Cineka686b2c2016-10-26 13:58:27 -0700739
Selim Cinek281c2022016-10-13 19:14:43 -0700740 private void setHideBackground(boolean hideBackground) {
Selim Cinek65d418e2016-11-29 15:42:34 -0800741 if (mHideBackground != hideBackground) {
742 mHideBackground = hideBackground;
743 updateBackground();
744 updateOutline();
745 }
Selim Cinekad7fac02016-10-18 17:09:15 -0700746 }
747
Selim Cinekeccb5de2016-10-28 15:04:05 -0700748 public boolean hidesBackground() {
749 return mHideBackground;
750 }
751
Selim Cinekad7fac02016-10-18 17:09:15 -0700752 @Override
753 protected boolean needsOutline() {
754 return !mHideBackground && super.needsOutline();
Selim Cinek281c2022016-10-13 19:14:43 -0700755 }
756
757 @Override
758 protected boolean shouldHideBackground() {
759 return super.shouldHideBackground() || mHideBackground;
760 }
761
Selim Cinekfcff4c62016-12-27 14:26:06 +0100762 @Override
763 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
764 super.onLayout(changed, left, top, right, bottom);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800765 updateRelativeOffset();
Selim Cinek143672c2018-03-23 20:04:32 -0700766
767 // we always want to clip to our sides, such that nothing can draw outside of these bounds
768 int height = getResources().getDisplayMetrics().heightPixels;
769 mClipRect.set(0, -height, getWidth(), height);
770 mShelfIcons.setClipBounds(mClipRect);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800771 }
772
773 private void updateRelativeOffset() {
Selim Cinek49014f82016-11-04 14:55:30 -0700774 mCollapsedIcons.getLocationOnScreen(mTmp);
Selim Cinekfcff4c62016-12-27 14:26:06 +0100775 mRelativeOffset = mTmp[0];
776 getLocationOnScreen(mTmp);
777 mRelativeOffset -= mTmp[0];
778 }
779
felkachangc02c3882018-07-27 15:32:31 +0800780 @Override
781 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
782 WindowInsets ret = super.onApplyWindowInsets(insets);
783
784 // NotificationShelf drag from the status bar and the status bar dock on the top
785 // of the display for current design so just focus on the top of ScreenDecorations.
786 // In landscape or multiple window split mode, the NotificationShelf still drag from
787 // the top and the physical notch/cutout goes to the right, left, or both side of the
788 // display so it doesn't matter for the NotificationSelf in landscape.
789 DisplayCutout displayCutout = insets.getDisplayCutout();
790 mCutoutHeight = displayCutout == null || displayCutout.getSafeInsetTop() < 0
791 ? 0 : displayCutout.getSafeInsetTop();
792
793 return ret;
794 }
795
Selim Cinekfcff4c62016-12-27 14:26:06 +0100796 private void setOpenedAmount(float openedAmount) {
Selim Cinek2fce3c82017-05-08 12:38:09 -0700797 mNoAnimationsInThisFrame = openedAmount == 1.0f && mOpenedAmount == 0.0f;
798 mOpenedAmount = openedAmount;
Lucas Dupin55c6e802018-09-27 18:07:36 -0700799 if (!mAmbientState.isPanelFullWidth() || mAmbientState.isDark()) {
Selim Cinekfcff4c62016-12-27 14:26:06 +0100800 // We don't do a transformation at all, lets just assume we are fully opened
801 openedAmount = 1.0f;
802 }
803 int start = mRelativeOffset;
Selim Cinek49014f82016-11-04 14:55:30 -0700804 if (isLayoutRtl()) {
805 start = getWidth() - start - mCollapsedIcons.getWidth();
806 }
Evan Lairdc987fc72017-12-15 10:14:22 -0500807 int width = (int) NotificationUtils.interpolate(
808 start + mCollapsedIcons.getFinalTranslationX(),
Selim Cinek49014f82016-11-04 14:55:30 -0700809 mShelfIcons.getWidth(),
felkachangc02c3882018-07-27 15:32:31 +0800810 FAST_OUT_SLOW_IN_REVERSE.getInterpolation(openedAmount));
Selim Cinek49014f82016-11-04 14:55:30 -0700811 mShelfIcons.setActualLayoutWidth(width);
Selim Cinek932005d2016-12-05 17:12:09 -0800812 boolean hasOverflow = mCollapsedIcons.hasOverflow();
813 int collapsedPadding = mCollapsedIcons.getPaddingEnd();
814 if (!hasOverflow) {
815 // we have to ensure that adding the low priority notification won't lead to an
816 // overflow
Evan Laird8cf0de42018-02-06 18:34:55 -0500817 collapsedPadding -= mCollapsedIcons.getNoOverflowExtraPadding();
Evan Lairdc987fc72017-12-15 10:14:22 -0500818 } else {
819 // Partial overflow padding will fill enough space to add extra dots
820 collapsedPadding -= mCollapsedIcons.getPartialOverflowExtraPadding();
Selim Cinek932005d2016-12-05 17:12:09 -0800821 }
822 float padding = NotificationUtils.interpolate(collapsedPadding,
Selim Cinek49014f82016-11-04 14:55:30 -0700823 mShelfIcons.getPaddingEnd(),
824 openedAmount);
825 mShelfIcons.setActualPaddingEnd(padding);
826 float paddingStart = NotificationUtils.interpolate(start,
827 mShelfIcons.getPaddingStart(), openedAmount);
828 mShelfIcons.setActualPaddingStart(paddingStart);
Selim Cinek17e1b692016-12-02 18:19:11 -0800829 mShelfIcons.setOpenedAmount(openedAmount);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800830 }
831
Selim Cinek9458b192016-10-25 19:02:42 -0700832 public void setMaxLayoutHeight(int maxLayoutHeight) {
833 mMaxLayoutHeight = maxLayoutHeight;
834 }
835
Selim Cinekeccb5de2016-10-28 15:04:05 -0700836 /**
837 * @return the index of the notification at which the shelf visually resides
838 */
839 public int getNotGoneIndex() {
840 return mNotGoneIndex;
841 }
842
843 private void setHasItemsInStableShelf(boolean hasItemsInStableShelf) {
Selim Cinek810bcde2016-12-14 17:29:23 -0800844 if (mHasItemsInStableShelf != hasItemsInStableShelf) {
845 mHasItemsInStableShelf = hasItemsInStableShelf;
846 updateInteractiveness();
847 }
Selim Cinekeccb5de2016-10-28 15:04:05 -0700848 }
849
850 /**
851 * @return whether the shelf has any icons in it when a potential animation has finished, i.e
852 * if the current state would be applied right now
853 */
854 public boolean hasItemsInStableShelf() {
855 return mHasItemsInStableShelf;
856 }
857
Selim Cinek49014f82016-11-04 14:55:30 -0700858 public void setCollapsedIcons(NotificationIconContainer collapsedIcons) {
859 mCollapsedIcons = collapsedIcons;
Selim Cinek9ef119c2017-03-01 15:13:36 -0800860 mCollapsedIcons.addOnLayoutChangeListener(this);
Selim Cinek49014f82016-11-04 14:55:30 -0700861 }
862
Jason Monk1fd3fc32018-08-14 17:20:09 -0400863 private void setStatusBarState(int statusBarState) {
864 mStatusBarState = statusBarState;
865 updateInteractiveness();
Selim Cinek810bcde2016-12-14 17:29:23 -0800866 }
867
868 private void updateInteractiveness() {
Adrian Roos03cf2582017-03-28 17:54:05 -0700869 mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf
870 && !mDark;
Selim Cinekc6813462017-01-13 17:10:38 -0800871 setClickable(mInteractive);
872 setFocusable(mInteractive);
873 setImportantForAccessibility(mInteractive ? View.IMPORTANT_FOR_ACCESSIBILITY_YES
Selim Cinekaca84c02017-04-05 16:28:56 -0700874 : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
Selim Cinek810bcde2016-12-14 17:29:23 -0800875 }
876
Selim Cinekc6813462017-01-13 17:10:38 -0800877 @Override
878 protected boolean isInteractive() {
879 return mInteractive;
880 }
881
Selim Cineka1d97902016-12-14 16:31:40 -0800882 public void setMaxShelfEnd(float maxShelfEnd) {
883 mMaxShelfEnd = maxShelfEnd;
884 }
885
Selim Cinek09bd29d2017-02-03 15:30:28 -0800886 public void setAnimationsEnabled(boolean enabled) {
887 mAnimationsEnabled = enabled;
888 mCollapsedIcons.setAnimationsEnabled(enabled);
889 if (!enabled) {
890 // we need to wait with enabling the animations until the first frame has passed
891 mShelfIcons.setAnimationsEnabled(false);
892 }
893 }
894
Selim Cinek9ef119c2017-03-01 15:13:36 -0800895 @Override
Adrian Roosd83e9992017-03-16 15:17:57 -0700896 public boolean hasOverlappingRendering() {
897 return false; // Shelf only uses alpha for transitions where the difference can't be seen.
898 }
899
900 @Override
Selim Cinekaca84c02017-04-05 16:28:56 -0700901 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
902 super.onInitializeAccessibilityNodeInfo(info);
903 if (mInteractive) {
904 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
905 AccessibilityNodeInfo.AccessibilityAction unlock
906 = new AccessibilityNodeInfo.AccessibilityAction(
907 AccessibilityNodeInfo.ACTION_CLICK,
908 getContext().getString(R.string.accessibility_overflow_action));
909 info.addAction(unlock);
910 }
911 }
912
913 @Override
Selim Cinek9ef119c2017-03-01 15:13:36 -0800914 public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
915 int oldTop, int oldRight, int oldBottom) {
916 updateRelativeOffset();
917 }
918
Selim Cinek281c2022016-10-13 19:14:43 -0700919 private class ShelfState extends ExpandableViewState {
Selim Cinek49014f82016-11-04 14:55:30 -0700920 private float openedAmount;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700921 private boolean hasItemsInStableShelf;
Selim Cineka1d97902016-12-14 16:31:40 -0800922 private float maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700923
924 @Override
925 public void applyToView(View view) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700926 if (!mShowNotificationShelf) {
927 return;
928 }
929
Selim Cinek281c2022016-10-13 19:14:43 -0700930 super.applyToView(view);
Selim Cineka1d97902016-12-14 16:31:40 -0800931 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700932 setOpenedAmount(openedAmount);
Selim Cineka1d97902016-12-14 16:31:40 -0800933 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700934 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800935 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek281c2022016-10-13 19:14:43 -0700936 }
Selim Cinek0cfbef42016-11-09 19:06:36 -0800937
938 @Override
939 public void animateTo(View child, AnimationProperties properties) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700940 if (!mShowNotificationShelf) {
941 return;
942 }
943
Selim Cinek0cfbef42016-11-09 19:06:36 -0800944 super.animateTo(child, properties);
Selim Cineka1d97902016-12-14 16:31:40 -0800945 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700946 setOpenedAmount(openedAmount);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800947 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700948 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800949 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800950 }
Selim Cinek281c2022016-10-13 19:14:43 -0700951 }
952}