blob: 110d51563e2ca2fbe0e999d5c3fef48cc25b6cfe [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;
felkachangc02c3882018-07-27 15:32:31 +080029import android.view.DisplayCutout;
Selim Cinek281c2022016-10-13 19:14:43 -070030import android.view.View;
31import android.view.ViewGroup;
Selim Cinek6eaacf22017-09-07 18:53:17 -070032import android.view.ViewTreeObserver;
felkachangc02c3882018-07-27 15:32:31 +080033import android.view.WindowInsets;
Selim Cinekaca84c02017-04-05 16:28:56 -070034import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek1f624952017-06-08 19:11:50 -070035
Jason Monk297c04e2018-08-23 17:16:59 -040036import com.android.internal.annotations.VisibleForTesting;
Jason Monk1fd3fc32018-08-14 17:20:09 -040037import com.android.systemui.Dependency;
Selim Cinek9458b192016-10-25 19:02:42 -070038import com.android.systemui.Interpolators;
Selim Cinek281c2022016-10-13 19:14:43 -070039import com.android.systemui.R;
Beverly8fdb5332019-02-04 14:29:49 -050040import com.android.systemui.plugins.statusbar.StatusBarStateController;
41import com.android.systemui.plugins.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
Lucas Dupin7fc9dc12019-01-03 09:19:43 -080058 View.OnLayoutChangeListener, StateListener {
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 Cinek49014f82016-11-04 14:55:30 -070068 private NotificationIconContainer mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -070069 private int[] mTmp = new int[2];
70 private boolean mHideBackground;
71 private int mIconAppearTopPadding;
Lucas Dupinb561eda2018-04-09 17:25:04 -070072 private int mShelfAppearTranslation;
Lucas Dupin00be88f2019-01-03 17:50:52 -080073 private float mDarkShelfPadding;
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
98 public NotificationShelf(Context context, AttributeSet attrs) {
99 super(context, attrs);
100 }
101
102 @Override
Jason Monk297c04e2018-08-23 17:16:59 -0400103 @VisibleForTesting
104 public void onFinishInflate() {
Selim Cinek281c2022016-10-13 19:14:43 -0700105 super.onFinishInflate();
Alan Viverette51efddb2017-04-05 10:00:01 -0400106 mShelfIcons = findViewById(R.id.content);
Selim Cinek49014f82016-11-04 14:55:30 -0700107 mShelfIcons.setClipChildren(false);
108 mShelfIcons.setClipToPadding(false);
109
Selim Cinek281c2022016-10-13 19:14:43 -0700110 setClipToActualHeight(false);
111 setClipChildren(false);
112 setClipToPadding(false);
Evan Lairdc987fc72017-12-15 10:14:22 -0500113 mShelfIcons.setIsStaticLayout(false);
Selim Cinek2871bef2017-11-22 08:40:00 -0800114 setBottomRoundness(1.0f, false /* animate */);
Selim Cinek281c2022016-10-13 19:14:43 -0700115 initDimens();
116 }
117
Jason Monk1fd3fc32018-08-14 17:20:09 -0400118 @Override
119 protected void onAttachedToWindow() {
120 super.onAttachedToWindow();
Beverly8fdb5332019-02-04 14:29:49 -0500121 ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class))
122 .addCallback(this, SysuiStatusBarStateController.RANK_SHELF);
Jason Monk1fd3fc32018-08-14 17:20:09 -0400123 }
124
125 @Override
126 protected void onDetachedFromWindow() {
127 super.onDetachedFromWindow();
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800128 Dependency.get(StatusBarStateController.class).removeCallback(this);
Jason Monk1fd3fc32018-08-14 17:20:09 -0400129 }
130
Selim Cinekc383fd02016-10-21 15:31:26 -0700131 public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout) {
132 mAmbientState = ambientState;
133 mHostLayout = hostLayout;
134 }
135
Selim Cinek281c2022016-10-13 19:14:43 -0700136 private void initDimens() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700137 Resources res = getResources();
138 mIconAppearTopPadding = res.getDimensionPixelSize(R.dimen.notification_icon_appear_padding);
139 mStatusBarHeight = res.getDimensionPixelOffset(R.dimen.status_bar_height);
140 mStatusBarPaddingStart = res.getDimensionPixelOffset(R.dimen.status_bar_padding_start);
141 mPaddingBetweenElements = res.getDimensionPixelSize(R.dimen.notification_divider_height);
Lucas Dupinb561eda2018-04-09 17:25:04 -0700142 mShelfAppearTranslation = res.getDimensionPixelSize(R.dimen.shelf_appear_translation);
Lucas Dupin00be88f2019-01-03 17:50:52 -0800143 mDarkShelfPadding = res.getDimensionPixelSize(R.dimen.widget_bottom_separator_padding);
Anthony Chen9e05d462017-04-07 10:10:21 -0700144
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800145 ViewGroup.LayoutParams layoutParams = getLayoutParams();
Anthony Chen9e05d462017-04-07 10:10:21 -0700146 layoutParams.height = res.getDimensionPixelOffset(R.dimen.notification_shelf_height);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800147 setLayoutParams(layoutParams);
Anthony Chen9e05d462017-04-07 10:10:21 -0700148
149 int padding = res.getDimensionPixelOffset(R.dimen.shelf_icon_container_padding);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800150 mShelfIcons.setPadding(padding, 0, padding, 0);
Anthony Chen9e05d462017-04-07 10:10:21 -0700151 mScrollFastThreshold = res.getDimensionPixelOffset(R.dimen.scroll_fast_threshold);
152 mShowNotificationShelf = res.getBoolean(R.bool.config_showNotificationShelf);
Selim Cinekb42698f2017-07-31 17:47:45 -0700153 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
Gus Prevase2d6f042018-10-17 15:25:30 -0400154 mGapHeight = res.getDimensionPixelSize(R.dimen.qs_notification_padding);
Anthony Chen9e05d462017-04-07 10:10:21 -0700155
156 if (!mShowNotificationShelf) {
157 setVisibility(GONE);
158 }
Selim Cinek281c2022016-10-13 19:14:43 -0700159 }
160
161 @Override
162 protected void onConfigurationChanged(Configuration newConfig) {
163 super.onConfigurationChanged(newConfig);
164 initDimens();
165 }
166
167 @Override
168 public void setDark(boolean dark, boolean fade, long delay) {
Selim Cinek281c2022016-10-13 19:14:43 -0700169 if (mDark == dark) return;
Lucas Dupin00be88f2019-01-03 17:50:52 -0800170 super.setDark(dark, fade, delay);
Adrian Roos456e0052017-04-04 16:44:29 -0700171 mShelfIcons.setDark(dark, fade, delay);
Adrian Roos03cf2582017-03-28 17:54:05 -0700172 updateInteractiveness();
Lucas Dupin00be88f2019-01-03 17:50:52 -0800173 updateOutline();
Selim Cinek281c2022016-10-13 19:14:43 -0700174 }
175
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800176 /**
177 * Alpha animation with translation played when this view is visible on AOD.
178 */
179 public void fadeInTranslating() {
180 mShelfIcons.setTranslationY(-mShelfAppearTranslation);
181 mShelfIcons.setAlpha(0);
182 mShelfIcons.animate()
183 .setInterpolator(Interpolators.DECELERATE_QUINT)
184 .translationY(0)
185 .setDuration(SHELF_IN_TRANSLATION_DURATION)
186 .start();
187 mShelfIcons.animate()
188 .alpha(1)
189 .setInterpolator(Interpolators.LINEAR)
190 .setDuration(SHELF_IN_TRANSLATION_DURATION)
191 .start();
192 }
193
Selim Cinek281c2022016-10-13 19:14:43 -0700194 @Override
195 protected View getContentView() {
Selim Cinek49014f82016-11-04 14:55:30 -0700196 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700197 }
198
Selim Cinek49014f82016-11-04 14:55:30 -0700199 public NotificationIconContainer getShelfIcons() {
200 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700201 }
202
203 @Override
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500204 public ExpandableViewState createExpandableViewState() {
205 return new ShelfState();
Selim Cinek281c2022016-10-13 19:14:43 -0700206 }
207
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500208 /** Update the state of the shelf. */
209 public void updateState(AmbientState ambientState) {
210 ExpandableView lastView = ambientState.getLastVisibleBackgroundChild();
211 ShelfState viewState = (ShelfState) getViewState();
Anthony Chen9e05d462017-04-07 10:10:21 -0700212 if (mShowNotificationShelf && lastView != null) {
Selim Cinek281c2022016-10-13 19:14:43 -0700213 float maxShelfEnd = ambientState.getInnerHeight() + ambientState.getTopPadding()
214 + ambientState.getStackTranslation();
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500215 ExpandableViewState lastViewState = lastView.getViewState();
Selim Cinek281c2022016-10-13 19:14:43 -0700216 float viewEnd = lastViewState.yTranslation + lastViewState.height;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500217 viewState.copyFrom(lastViewState);
218 viewState.height = getIntrinsicHeight();
Lucas Dupinb561eda2018-04-09 17:25:04 -0700219
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500220 float awakenTranslation = Math.max(Math.min(viewEnd, maxShelfEnd) - viewState.height,
Selim Cinek49014f82016-11-04 14:55:30 -0700221 getFullyClosedTranslation());
Lucas Dupinb561eda2018-04-09 17:25:04 -0700222 float yRatio = mAmbientState.hasPulsingNotifications() ?
223 0 : mAmbientState.getDarkAmount();
Lucas Dupin00be88f2019-01-03 17:50:52 -0800224 viewState.yTranslation = awakenTranslation + mDarkShelfPadding * yRatio;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500225 viewState.zTranslation = ambientState.getBaseZHeight();
felkachangc02c3882018-07-27 15:32:31 +0800226 // For the small display size, it's not enough to make the icon not covered by
227 // the top cutout so the denominator add the height of cutout.
228 // Totally, (getIntrinsicHeight() * 2 + mCutoutHeight) should be smaller then
229 // mAmbientState.getTopPadding().
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500230 float openedAmount = (viewState.yTranslation - getFullyClosedTranslation())
felkachangc02c3882018-07-27 15:32:31 +0800231 / (getIntrinsicHeight() * 2 + mCutoutHeight);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800232 openedAmount = Math.min(1.0f, openedAmount);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500233 viewState.openedAmount = openedAmount;
234 viewState.clipTopAmount = 0;
235 viewState.alpha = mAmbientState.hasPulsingNotifications() ? 0 : 1;
236 viewState.belowSpeedBump = mAmbientState.getSpeedBumpIndex() == 0;
237 viewState.hideSensitive = false;
238 viewState.xTranslation = getTranslationX();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700239 if (mNotGoneIndex != -1) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500240 viewState.notGoneIndex = Math.min(viewState.notGoneIndex, mNotGoneIndex);
Selim Cinekeccb5de2016-10-28 15:04:05 -0700241 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500242 viewState.hasItemsInStableShelf = lastViewState.inShelf;
243 viewState.hidden = !mAmbientState.isShadeExpanded()
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800244 || mAmbientState.isQsCustomizerShowing();
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500245 viewState.maxShelfEnd = maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700246 } else {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500247 viewState.hidden = true;
248 viewState.location = ExpandableViewState.LOCATION_GONE;
249 viewState.hasItemsInStableShelf = false;
Selim Cinek281c2022016-10-13 19:14:43 -0700250 }
251 }
252
Selim Cinekc383fd02016-10-21 15:31:26 -0700253 /**
254 * Update the shelf appearance based on the other notifications around it. This transforms
255 * the icons from the notification area into the shelf.
256 */
257 public void updateAppearance() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700258 // If the shelf should not be shown, then there is no need to update anything.
259 if (!mShowNotificationShelf) {
260 return;
261 }
262
Selim Cinek65d418e2016-11-29 15:42:34 -0800263 mShelfIcons.resetViewStates();
264 float shelfStart = getTranslationY();
Selim Cinekdb167372016-11-17 15:41:17 -0800265 float numViewsInShelf = 0.0f;
266 View lastChild = mAmbientState.getLastVisibleBackgroundChild();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700267 mNotGoneIndex = -1;
Selim Cinek49014f82016-11-04 14:55:30 -0700268 float interpolationStart = mMaxLayoutHeight - getIntrinsicHeight() * 2;
269 float expandAmount = 0.0f;
Selim Cinek65d418e2016-11-29 15:42:34 -0800270 if (shelfStart >= interpolationStart) {
271 expandAmount = (shelfStart - interpolationStart) / getIntrinsicHeight();
Selim Cinek49014f82016-11-04 14:55:30 -0700272 expandAmount = Math.min(1.0f, expandAmount);
273 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700274 // find the first view that doesn't overlap with the shelf
Selim Cinekdb167372016-11-17 15:41:17 -0800275 int notGoneIndex = 0;
Selim Cinekec29d342017-05-05 18:31:49 -0700276 int colorOfViewBeforeLast = NO_COLOR;
Selim Cinekdb167372016-11-17 15:41:17 -0800277 boolean backgroundForceHidden = false;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500278 if (mHideBackground && !((ShelfState) getViewState()).hasItemsInStableShelf) {
Selim Cinekdb167372016-11-17 15:41:17 -0800279 backgroundForceHidden = true;
280 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800281 int colorTwoBefore = NO_COLOR;
282 int previousColor = NO_COLOR;
283 float transitionAmount = 0.0f;
Selim Cineka1d97902016-12-14 16:31:40 -0800284 float currentScrollVelocity = mAmbientState.getCurrentScrollVelocity();
285 boolean scrollingFast = currentScrollVelocity > mScrollFastThreshold
Selim Cinekd5ab6452016-12-08 16:34:00 -0800286 || (mAmbientState.isExpansionChanging()
287 && Math.abs(mAmbientState.getExpandingVelocity()) > mScrollFastThreshold);
Selim Cineka1d97902016-12-14 16:31:40 -0800288 boolean scrolling = currentScrollVelocity > 0;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800289 boolean expandingAnimated = mAmbientState.isExpansionChanging()
290 && !mAmbientState.isPanelTracking();
Selim Cinek65d418e2016-11-29 15:42:34 -0800291 int baseZHeight = mAmbientState.getBaseZHeight();
Selim Cinek515b2032017-11-15 10:20:19 -0800292 int backgroundTop = 0;
293 float firstElementRoundness = 0.0f;
Gus Prevase2d6f042018-10-17 15:25:30 -0400294 ExpandableNotificationRow previousRow = null;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700295
296 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
297 ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i);
298
Selim Cinekc383fd02016-10-21 15:31:26 -0700299 if (!(child instanceof ExpandableNotificationRow)
300 || child.getVisibility() == GONE) {
301 continue;
302 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700303
Selim Cinekc383fd02016-10-21 15:31:26 -0700304 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cineka686b2c2016-10-26 13:58:27 -0700305 float notificationClipEnd;
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800306 boolean aboveShelf = ViewState.getFinalTranslationZ(row) > baseZHeight
307 || row.isPinned();
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800308 boolean isLastChild = child == lastChild;
Selim Cinek65d418e2016-11-29 15:42:34 -0800309 float rowTranslationY = row.getTranslationY();
Selim Cinek3ff9fba2017-07-20 10:47:48 -0700310 if ((isLastChild && !child.isInShelf()) || aboveShelf || backgroundForceHidden) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700311 notificationClipEnd = shelfStart + getIntrinsicHeight();
312 } else {
Selim Cineka686b2c2016-10-26 13:58:27 -0700313 notificationClipEnd = shelfStart - mPaddingBetweenElements;
Selim Cinek65d418e2016-11-29 15:42:34 -0800314 float height = notificationClipEnd - rowTranslationY;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800315 if (!row.isBelowSpeedBump() && height <= getNotificationMergeSize()) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700316 // We want the gap to close when we reached the minimum size and only shrink
317 // before
318 notificationClipEnd = Math.min(shelfStart,
Selim Cinek65d418e2016-11-29 15:42:34 -0800319 rowTranslationY + getNotificationMergeSize());
Selim Cineka686b2c2016-10-26 13:58:27 -0700320 }
321 }
322 updateNotificationClipHeight(row, notificationClipEnd);
Selim Cineka1d97902016-12-14 16:31:40 -0800323 float inShelfAmount = updateIconAppearance(row, expandAmount, scrolling, scrollingFast,
Selim Cinekd5ab6452016-12-08 16:34:00 -0800324 expandingAnimated, isLastChild);
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800325 numViewsInShelf += inShelfAmount;
326 int ownColorUntinted = row.getBackgroundColorWithoutTint();
Selim Cinek65d418e2016-11-29 15:42:34 -0800327 if (rowTranslationY >= shelfStart && mNotGoneIndex == -1) {
Selim Cinekdb167372016-11-17 15:41:17 -0800328 mNotGoneIndex = notGoneIndex;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800329 setTintColor(previousColor);
330 setOverrideTintColor(colorTwoBefore, transitionAmount);
331
332 } else if (mNotGoneIndex == -1) {
333 colorTwoBefore = previousColor;
334 transitionAmount = inShelfAmount;
335 }
Selim Cinekec29d342017-05-05 18:31:49 -0700336 if (isLastChild) {
337 if (colorOfViewBeforeLast == NO_COLOR) {
338 colorOfViewBeforeLast = ownColorUntinted;
339 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800340 row.setOverrideTintColor(colorOfViewBeforeLast, inShelfAmount);
341 } else {
342 colorOfViewBeforeLast = ownColorUntinted;
343 row.setOverrideTintColor(NO_COLOR, 0 /* overrideAmount */);
Selim Cinekeccb5de2016-10-28 15:04:05 -0700344 }
Selim Cinekdb167372016-11-17 15:41:17 -0800345 if (notGoneIndex != 0 || !aboveShelf) {
Selim Cinekd127d792016-11-01 19:11:41 -0700346 row.setAboveShelf(false);
347 }
Selim Cinek0fe07392017-11-09 13:26:34 -0800348 if (notGoneIndex == 0) {
349 StatusBarIconView icon = row.getEntry().expandedIcon;
350 NotificationIconContainer.IconState iconState = getIconState(icon);
Selim Cinekec0c4622019-02-13 12:33:20 -0800351 // The icon state might be null in rare cases where the notification is actually
352 // added to the layout, but not to the shelf. An example are replied messages, since
353 // they don't show up on AOD
Selim Cinekb7bafbc2017-12-21 11:33:26 -0800354 if (iconState != null && iconState.clampedAppearAmount == 1.0f) {
Selim Cinek0fe07392017-11-09 13:26:34 -0800355 // only if the first icon is fully in the shelf we want to clip to it!
Selim Cinek515b2032017-11-15 10:20:19 -0800356 backgroundTop = (int) (row.getTranslationY() - getTranslationY());
357 firstElementRoundness = row.getCurrentTopRoundness();
Selim Cinek0fe07392017-11-09 13:26:34 -0800358 }
359 }
Gus Prevase2d6f042018-10-17 15:25:30 -0400360 if (row.isFirstInSection() && previousRow != null && previousRow.isLastInSection()) {
361 // If the top of the shelf is between the view before a gap and the view after a gap
362 // then we need to adjust the shelf's top roundness.
363 float distanceToGapBottom = row.getTranslationY() - getTranslationY();
364 float distanceToGapTop = getTranslationY()
365 - (previousRow.getTranslationY() + previousRow.getActualHeight());
366 if (distanceToGapTop > 0) {
367 // We interpolate our top roundness so that it's fully rounded if we're at the
368 // bottom of the gap, and not rounded at all if we're at the top of the gap
369 // (directly up against the bottom of previousRow)
370 // Then we apply the same roundness to the bottom of previousRow so that the
371 // corners join together as the shelf approaches previousRow.
372 firstElementRoundness = (float) Math.min(1.0, distanceToGapTop / mGapHeight);
373 previousRow.setBottomRoundness(firstElementRoundness,
374 false /* don't animate */);
375 backgroundTop = (int) distanceToGapBottom;
376 }
377 }
Selim Cinekdb167372016-11-17 15:41:17 -0800378 notGoneIndex++;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800379 previousColor = ownColorUntinted;
Gus Prevase2d6f042018-10-17 15:25:30 -0400380 previousRow = row;
Selim Cineka686b2c2016-10-26 13:58:27 -0700381 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700382
383 clipTransientViews();
384
Selim Cinek515b2032017-11-15 10:20:19 -0800385 setBackgroundTop(backgroundTop);
386 setFirstElementRoundness(firstElementRoundness);
Selim Cinek17e1b692016-12-02 18:19:11 -0800387 mShelfIcons.setSpeedBumpIndex(mAmbientState.getSpeedBumpIndex());
Selim Cinek49014f82016-11-04 14:55:30 -0700388 mShelfIcons.calculateIconTranslations();
389 mShelfIcons.applyIconStates();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700390 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
391 View child = mHostLayout.getChildAt(i);
392 if (!(child instanceof ExpandableNotificationRow)
393 || child.getVisibility() == GONE) {
394 continue;
395 }
396 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
397 updateIconClipAmount(row);
398 updateContinuousClipping(row);
399 }
Selim Cinekdb167372016-11-17 15:41:17 -0800400 boolean hideBackground = numViewsInShelf < 1.0f;
401 setHideBackground(hideBackground || backgroundForceHidden);
402 if (mNotGoneIndex == -1) {
403 mNotGoneIndex = notGoneIndex;
404 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800405 }
406
Rohan Shah524cf7b2018-03-15 14:40:02 -0700407 /**
408 * Clips transient views to the top of the shelf - Transient views are only used for
409 * disappearing views/animations and need to be clipped correctly by the shelf to ensure they
410 * don't show underneath the notification stack when something is animating and the user
411 * swipes quickly.
412 */
413 private void clipTransientViews() {
414 for (int i = 0; i < mHostLayout.getTransientViewCount(); i++) {
415 View transientView = mHostLayout.getTransientView(i);
416 if (transientView instanceof ExpandableNotificationRow) {
417 ExpandableNotificationRow transientRow = (ExpandableNotificationRow) transientView;
418 updateNotificationClipHeight(transientRow, getTranslationY());
419 } else {
420 Log.e(TAG, "NotificationShelf.clipTransientViews(): "
421 + "Trying to clip non-row transient view");
422 }
423 }
424 }
425
Selim Cinek515b2032017-11-15 10:20:19 -0800426 private void setFirstElementRoundness(float firstElementRoundness) {
427 if (mFirstElementRoundness != firstElementRoundness) {
428 mFirstElementRoundness = firstElementRoundness;
429 setTopRoundness(firstElementRoundness, false /* animate */);
Selim Cinek0fe07392017-11-09 13:26:34 -0800430 }
431 }
432
Selim Cinek6eaacf22017-09-07 18:53:17 -0700433 private void updateIconClipAmount(ExpandableNotificationRow row) {
434 float maxTop = row.getTranslationY();
435 StatusBarIconView icon = row.getEntry().expandedIcon;
436 float shelfIconPosition = getTranslationY() + icon.getTop() + icon.getTranslationY();
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800437 if (shelfIconPosition < maxTop && !mAmbientState.isDark()) {
Selim Cinek6eaacf22017-09-07 18:53:17 -0700438 int top = (int) (maxTop - shelfIconPosition);
439 Rect clipRect = new Rect(0, top, icon.getWidth(), Math.max(top, icon.getHeight()));
440 icon.setClipBounds(clipRect);
Gus Prevasab3ad1d2018-11-01 17:11:59 -0400441 } else {
442 icon.setClipBounds(null);
Selim Cinek6eaacf22017-09-07 18:53:17 -0700443 }
444 }
445
446 private void updateContinuousClipping(final ExpandableNotificationRow row) {
447 StatusBarIconView icon = row.getEntry().expandedIcon;
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800448 boolean needsContinuousClipping = ViewState.isAnimatingY(icon) && !mAmbientState.isDark();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700449 boolean isContinuousClipping = icon.getTag(TAG_CONTINUOUS_CLIPPING) != null;
450 if (needsContinuousClipping && !isContinuousClipping) {
Selim Cinek85845b82018-04-25 13:10:57 +0800451 final ViewTreeObserver observer = icon.getViewTreeObserver();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700452 ViewTreeObserver.OnPreDrawListener predrawListener =
453 new ViewTreeObserver.OnPreDrawListener() {
454 @Override
455 public boolean onPreDraw() {
456 boolean animatingY = ViewState.isAnimatingY(icon);
Selim Cinek85845b82018-04-25 13:10:57 +0800457 if (!animatingY) {
Robert Snoebergered77b452018-10-12 17:22:06 +0000458 if (observer.isAlive()) {
459 observer.removeOnPreDrawListener(this);
460 }
Selim Cinek6eaacf22017-09-07 18:53:17 -0700461 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
462 return true;
463 }
464 updateIconClipAmount(row);
465 return true;
466 }
467 };
Selim Cinek85845b82018-04-25 13:10:57 +0800468 observer.addOnPreDrawListener(predrawListener);
469 icon.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
470 @Override
471 public void onViewAttachedToWindow(View v) {
472 }
473
474 @Override
475 public void onViewDetachedFromWindow(View v) {
476 if (v == icon) {
Robert Snoebergered77b452018-10-12 17:22:06 +0000477 if (observer.isAlive()) {
478 observer.removeOnPreDrawListener(predrawListener);
479 }
Selim Cinek85845b82018-04-25 13:10:57 +0800480 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
481 }
482 }
483 });
Selim Cinek6eaacf22017-09-07 18:53:17 -0700484 icon.setTag(TAG_CONTINUOUS_CLIPPING, predrawListener);
485 }
486 }
487
Selim Cineka686b2c2016-10-26 13:58:27 -0700488 private void updateNotificationClipHeight(ExpandableNotificationRow row,
489 float notificationClipEnd) {
490 float viewEnd = row.getTranslationY() + row.getActualHeight();
Selim Cinekebf42342017-07-13 15:46:10 +0200491 boolean isPinned = (row.isPinned() || row.isHeadsUpAnimatingAway())
492 && !mAmbientState.isDozingAndNotPulsing(row);
Selim Cinekd127d792016-11-01 19:11:41 -0700493 if (viewEnd > notificationClipEnd
Selim Cinek7e0f9482017-05-22 20:00:56 -0700494 && (mAmbientState.isShadeExpanded() || !isPinned)) {
495 int clipBottomAmount = (int) (viewEnd - notificationClipEnd);
496 if (isPinned) {
497 clipBottomAmount = Math.min(row.getIntrinsicHeight() - row.getCollapsedHeight(),
498 clipBottomAmount);
499 }
500 row.setClipBottomAmount(clipBottomAmount);
Selim Cineka686b2c2016-10-26 13:58:27 -0700501 } else {
502 row.setClipBottomAmount(0);
503 }
504 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700505
Selim Cinekc8c4cf92017-09-08 15:30:09 -0700506 @Override
507 public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd,
508 int outlineTranslation) {
509 if (!mHasItemsInStableShelf) {
510 shadowIntensity = 0.0f;
511 }
512 super.setFakeShadowIntensity(shadowIntensity, outlineAlpha, shadowYEnd, outlineTranslation);
513 }
514
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800515 /**
516 * @return the icon amount how much this notification is in the shelf;
517 */
Selim Cinek2b549f42016-11-22 16:38:51 -0800518 private float updateIconAppearance(ExpandableNotificationRow row, float expandAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800519 boolean scrolling, boolean scrollingFast, boolean expandingAnimated,
520 boolean isLastChild) {
Selim Cinek1f624952017-06-08 19:11:50 -0700521 StatusBarIconView icon = row.getEntry().expandedIcon;
522 NotificationIconContainer.IconState iconState = getIconState(icon);
523 if (iconState == null) {
524 return 0.0f;
525 }
526
Selim Cinekc383fd02016-10-21 15:31:26 -0700527 // Let calculate how much the view is in the shelf
528 float viewStart = row.getTranslationY();
Selim Cinek2b549f42016-11-22 16:38:51 -0800529 int fullHeight = row.getActualHeight() + mPaddingBetweenElements;
530 float iconTransformDistance = getIntrinsicHeight() * 1.5f;
Selim Cineka1d97902016-12-14 16:31:40 -0800531 iconTransformDistance *= NotificationUtils.interpolate(1.f, 1.5f, expandAmount);
Selim Cinek1f624952017-06-08 19:11:50 -0700532 iconTransformDistance = Math.min(iconTransformDistance, fullHeight);
Selim Cinek938bdaa2016-11-18 16:31:09 -0800533 if (isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800534 fullHeight = Math.min(fullHeight, row.getMinHeight() - getIntrinsicHeight());
Bill Line6065e32018-06-08 17:07:13 +0800535 iconTransformDistance = Math.min(iconTransformDistance, row.getMinHeight()
536 - getIntrinsicHeight());
Selim Cinek938bdaa2016-11-18 16:31:09 -0800537 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800538 float viewEnd = viewStart + fullHeight;
Gus Prevas0fa58d62019-01-11 13:58:40 -0500539 // TODO: fix this check for anchor scrolling.
Selim Cinek1f624952017-06-08 19:11:50 -0700540 if (expandingAnimated && mAmbientState.getScrollY() == 0
541 && !mAmbientState.isOnKeyguard() && !iconState.isLastExpandIcon) {
542 // We are expanding animated. Because we switch to a linear interpolation in this case,
543 // the last icon may be stuck in between the shelf position and the notification
544 // position, which looks pretty bad. We therefore optimize this case by applying a
545 // shorter transition such that the icon is either fully in the notification or we clamp
546 // it into the shelf if it's close enough.
547 // We need to persist this, since after the expansion, the behavior should still be the
548 // same.
549 float position = mAmbientState.getIntrinsicPadding()
550 + mHostLayout.getPositionInLinearLayout(row);
551 int maxShelfStart = mMaxLayoutHeight - getIntrinsicHeight();
552 if (position < maxShelfStart && position + row.getIntrinsicHeight() >= maxShelfStart
553 && row.getTranslationY() < position) {
554 iconState.isLastExpandIcon = true;
555 iconState.customTransformHeight = NO_VALUE;
556 // Let's check if we're close enough to snap into the shelf
557 boolean forceInShelf = mMaxLayoutHeight - getIntrinsicHeight() - position
558 < getIntrinsicHeight();
559 if (!forceInShelf) {
560 // We are overlapping the shelf but not enough, so the icon needs to be
561 // repositioned
562 iconState.customTransformHeight = (int) (mMaxLayoutHeight
563 - getIntrinsicHeight() - position);
564 }
565 }
566 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800567 float fullTransitionAmount;
Selim Cinek01a73f92016-12-06 16:13:42 -0800568 float iconTransitionAmount;
569 float shelfStart = getTranslationY();
Selim Cinek1f624952017-06-08 19:11:50 -0700570 if (iconState.hasCustomTransformHeight()) {
571 fullHeight = iconState.customTransformHeight;
572 iconTransformDistance = iconState.customTransformHeight;
573 }
574 boolean fullyInOrOut = true;
Selim Cinekec29d342017-05-05 18:31:49 -0700575 if (viewEnd >= shelfStart && (!mAmbientState.isUnlockHintRunning() || row.isInShelf())
576 && (mAmbientState.isShadeExpanded()
577 || (!row.isPinned() && !row.isHeadsUpAnimatingAway()))) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800578 if (viewStart < shelfStart) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800579 float fullAmount = (shelfStart - viewStart) / fullHeight;
Selim Cinek1f624952017-06-08 19:11:50 -0700580 fullAmount = Math.min(1.0f, fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700581 float interpolatedAmount = Interpolators.ACCELERATE_DECELERATE.getInterpolation(
Selim Cinek2b549f42016-11-22 16:38:51 -0800582 fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700583 interpolatedAmount = NotificationUtils.interpolate(
Selim Cinek2b549f42016-11-22 16:38:51 -0800584 interpolatedAmount, fullAmount, expandAmount);
585 fullTransitionAmount = 1.0f - interpolatedAmount;
586
Selim Cinek01a73f92016-12-06 16:13:42 -0800587 iconTransitionAmount = (shelfStart - viewStart) / iconTransformDistance;
588 iconTransitionAmount = Math.min(1.0f, iconTransitionAmount);
589 iconTransitionAmount = 1.0f - iconTransitionAmount;
Selim Cinek1f624952017-06-08 19:11:50 -0700590 fullyInOrOut = false;
Selim Cinekc383fd02016-10-21 15:31:26 -0700591 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800592 fullTransitionAmount = 1.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800593 iconTransitionAmount = 1.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700594 }
595 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800596 fullTransitionAmount = 0.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800597 iconTransitionAmount = 0.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700598 }
Selim Cinek1f624952017-06-08 19:11:50 -0700599 if (fullyInOrOut && !expandingAnimated && iconState.isLastExpandIcon) {
600 iconState.isLastExpandIcon = false;
601 iconState.customTransformHeight = NO_VALUE;
602 }
Selim Cineka1d97902016-12-14 16:31:40 -0800603 updateIconPositioning(row, iconTransitionAmount, fullTransitionAmount,
604 iconTransformDistance, scrolling, scrollingFast, expandingAnimated, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800605 return fullTransitionAmount;
606 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700607
Selim Cinek2b549f42016-11-22 16:38:51 -0800608 private void updateIconPositioning(ExpandableNotificationRow row, float iconTransitionAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800609 float fullTransitionAmount, float iconTransformDistance, boolean scrolling,
610 boolean scrollingFast, boolean expandingAnimated, boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800611 StatusBarIconView icon = row.getEntry().expandedIcon;
612 NotificationIconContainer.IconState iconState = getIconState(icon);
613 if (iconState == null) {
614 return;
615 }
Selim Cinek1f624952017-06-08 19:11:50 -0700616 boolean forceInShelf = iconState.isLastExpandIcon && !iconState.hasCustomTransformHeight();
Selim Cinek2b549f42016-11-22 16:38:51 -0800617 float clampedAmount = iconTransitionAmount > 0.5f ? 1.0f : 0.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800618 if (clampedAmount == fullTransitionAmount) {
Selim Cinek1f624952017-06-08 19:11:50 -0700619 iconState.noAnimations = (scrollingFast || expandingAnimated) && !forceInShelf;
Selim Cinek44d81a62017-05-08 19:45:40 -0700620 iconState.useFullTransitionAmount = iconState.noAnimations
Selim Cineka1d97902016-12-14 16:31:40 -0800621 || (!ICON_ANMATIONS_WHILE_SCROLLING && fullTransitionAmount == 0.0f && scrolling);
622 iconState.useLinearTransitionAmount = !ICON_ANMATIONS_WHILE_SCROLLING
623 && fullTransitionAmount == 0.0f && !mAmbientState.isExpansionChanging();
Selim Cinek01a73f92016-12-06 16:13:42 -0800624 iconState.translateContent = mMaxLayoutHeight - getTranslationY()
625 - getIntrinsicHeight() > 0;
Selim Cinek2b549f42016-11-22 16:38:51 -0800626 }
Selim Cinek1f624952017-06-08 19:11:50 -0700627 if (!forceInShelf && (scrollingFast || (expandingAnimated
628 && iconState.useFullTransitionAmount && !ViewState.isAnimatingY(icon)))) {
Selim Cinekd5ab6452016-12-08 16:34:00 -0800629 iconState.cancelAnimations(icon);
630 iconState.useFullTransitionAmount = true;
Selim Cinek44d81a62017-05-08 19:45:40 -0700631 iconState.noAnimations = true;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800632 }
Selim Cinek1f624952017-06-08 19:11:50 -0700633 if (iconState.hasCustomTransformHeight()) {
634 iconState.useFullTransitionAmount = true;
635 }
636 if (iconState.isLastExpandIcon) {
637 iconState.translateContent = false;
638 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800639 float transitionAmount;
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800640 if (mAmbientState.isDarkAtAll() && !row.isInShelf()) {
641 transitionAmount = mAmbientState.isFullyDark() ? 1 : 0;
642 } else if (isLastChild || !USE_ANIMATIONS_WHEN_OPENING || iconState.useFullTransitionAmount
Selim Cineka1d97902016-12-14 16:31:40 -0800643 || iconState.useLinearTransitionAmount) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800644 transitionAmount = iconTransitionAmount;
Selim Cinek2b549f42016-11-22 16:38:51 -0800645 } else {
Selim Cineka1d97902016-12-14 16:31:40 -0800646 // We take the clamped position instead
647 transitionAmount = clampedAmount;
Selim Cinek2fce3c82017-05-08 12:38:09 -0700648 iconState.needsCannedAnimation = iconState.clampedAppearAmount != clampedAmount
649 && !mNoAnimationsInThisFrame;
Selim Cinek2b549f42016-11-22 16:38:51 -0800650 }
651 iconState.iconAppearAmount = !USE_ANIMATIONS_WHEN_OPENING
652 || iconState.useFullTransitionAmount
653 ? fullTransitionAmount
654 : transitionAmount;
655 iconState.clampedAppearAmount = clampedAmount;
Selim Cinekebf42342017-07-13 15:46:10 +0200656 float contentTransformationAmount = !mAmbientState.isAboveShelf(row)
Selim Cinek7e0f9482017-05-22 20:00:56 -0700657 && (isLastChild || iconState.translateContent)
Selim Cinek01a73f92016-12-06 16:13:42 -0800658 ? iconTransitionAmount
659 : 0.0f;
660 row.setContentTransformationAmount(contentTransformationAmount, isLastChild);
Selim Cineka1d97902016-12-14 16:31:40 -0800661 setIconTransformationAmount(row, transitionAmount, iconTransformDistance,
Mady Mellor434180c2017-02-13 11:29:42 -0800662 clampedAmount != transitionAmount, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800663 }
664
665 private void setIconTransformationAmount(ExpandableNotificationRow row,
Mady Mellor434180c2017-02-13 11:29:42 -0800666 float transitionAmount, float iconTransformDistance, boolean usingLinearInterpolation,
667 boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800668 StatusBarIconView icon = row.getEntry().expandedIcon;
669 NotificationIconContainer.IconState iconState = getIconState(icon);
670
Selim Cinekc383fd02016-10-21 15:31:26 -0700671 View rowIcon = row.getNotificationIcon();
Selim Cineka1d97902016-12-14 16:31:40 -0800672 float notificationIconPosition = row.getTranslationY() + row.getContentTranslation();
Selim Cinekf20254c2017-02-03 10:09:33 -0800673 boolean stayingInShelf = row.isInShelf() && !row.isTransformingIntoShelf();
674 if (usingLinearInterpolation && !stayingInShelf) {
Selim Cineka1d97902016-12-14 16:31:40 -0800675 // If we interpolate from the notification position, this might lead to a slightly
676 // odd interpolation, since the notification position changes as well. Let's interpolate
677 // from a fixed distance. We can only do this if we don't animate and the icon is
678 // always in the interpolated positon.
Selim Cinekf20254c2017-02-03 10:09:33 -0800679 notificationIconPosition = getTranslationY() - iconTransformDistance;
Selim Cineka1d97902016-12-14 16:31:40 -0800680 }
Selim Cinek281c2022016-10-13 19:14:43 -0700681 float notificationIconSize = 0.0f;
682 int iconTopPadding;
683 if (rowIcon != null) {
Selim Cinek875a3a12016-11-18 17:52:16 -0800684 iconTopPadding = row.getRelativeTopPadding(rowIcon);
Selim Cinek281c2022016-10-13 19:14:43 -0700685 notificationIconSize = rowIcon.getHeight();
686 } else {
687 iconTopPadding = mIconAppearTopPadding;
688 }
689 notificationIconPosition += iconTopPadding;
Selim Cinekc383fd02016-10-21 15:31:26 -0700690 float shelfIconPosition = getTranslationY() + icon.getTop();
Selim Cinekb42698f2017-07-31 17:47:45 -0700691 shelfIconPosition += (icon.getHeight() - icon.getIconScale() * mIconSize) / 2.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800692 float iconYTranslation = NotificationUtils.interpolate(
Selim Cineka1d97902016-12-14 16:31:40 -0800693 notificationIconPosition - shelfIconPosition,
Selim Cinek2b549f42016-11-22 16:38:51 -0800694 0,
695 transitionAmount);
Selim Cinekb42698f2017-07-31 17:47:45 -0700696 float shelfIconSize = mIconSize * icon.getIconScale();
Selim Cinek2b549f42016-11-22 16:38:51 -0800697 float alpha = 1.0f;
Selim Cinek875ba9b2017-02-13 16:20:17 -0800698 boolean noIcon = !row.isShowingIcon();
699 if (noIcon) {
Selim Cinekc383fd02016-10-21 15:31:26 -0700700 // The view currently doesn't have an icon, lets transform it in!
Selim Cinekdb167372016-11-17 15:41:17 -0800701 alpha = transitionAmount;
Selim Cinekc383fd02016-10-21 15:31:26 -0700702 notificationIconSize = shelfIconSize / 2.0f;
703 }
704 // The notification size is different from the size in the shelf / statusbar
705 float newSize = NotificationUtils.interpolate(notificationIconSize, shelfIconSize,
Selim Cinek281c2022016-10-13 19:14:43 -0700706 transitionAmount);
Selim Cinekdb167372016-11-17 15:41:17 -0800707 if (iconState != null) {
Selim Cinekb42698f2017-07-31 17:47:45 -0700708 iconState.scaleX = newSize / shelfIconSize;
Selim Cinekdb167372016-11-17 15:41:17 -0800709 iconState.scaleY = iconState.scaleX;
Adrian Roos28f90c72017-05-08 17:24:26 -0700710 iconState.hidden = transitionAmount == 0.0f && !iconState.isAnimating(icon);
Selim Cinekf38d6c32017-06-28 15:44:02 +0200711 boolean isAppearing = row.isDrawingAppearAnimation() && !row.isInShelf();
712 if (isAppearing) {
713 iconState.hidden = true;
714 iconState.iconAppearAmount = 0.0f;
715 }
Selim Cinekdb167372016-11-17 15:41:17 -0800716 iconState.alpha = alpha;
Selim Cinek2b549f42016-11-22 16:38:51 -0800717 iconState.yTranslation = iconYTranslation;
Selim Cinekf20254c2017-02-03 10:09:33 -0800718 if (stayingInShelf) {
Selim Cinekdb167372016-11-17 15:41:17 -0800719 iconState.iconAppearAmount = 1.0f;
720 iconState.alpha = 1.0f;
721 iconState.scaleX = 1.0f;
722 iconState.scaleY = 1.0f;
723 iconState.hidden = false;
724 }
Selim Cinekebf42342017-07-13 15:46:10 +0200725 if (mAmbientState.isAboveShelf(row) || (!row.isInShelf() && (isLastChild && row.areGutsExposed()
Selim Cinek47374632017-03-17 16:07:17 -0700726 || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) {
Selim Cinek5ea19572016-11-29 15:34:48 -0800727 iconState.hidden = true;
728 }
Lucas Dupin83519da2017-06-21 11:58:31 -0700729 int backgroundColor = getBackgroundColorWithoutTint();
730 int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor);
Selim Cinek875ba9b2017-02-13 16:20:17 -0800731 if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) {
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700732 int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor();
733 shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor,
Selim Cinek875ba9b2017-02-13 16:20:17 -0800734 iconState.iconAppearAmount);
735 }
736 iconState.iconColor = shelfColor;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700737 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800738 }
739
740 private NotificationIconContainer.IconState getIconState(StatusBarIconView icon) {
741 return mShelfIcons.getIconState(icon);
Selim Cinekc383fd02016-10-21 15:31:26 -0700742 }
743
744 private float getFullyClosedTranslation() {
745 return - (getIntrinsicHeight() - mStatusBarHeight) / 2;
Selim Cinek281c2022016-10-13 19:14:43 -0700746 }
747
Selim Cinek281c2022016-10-13 19:14:43 -0700748 public int getNotificationMergeSize() {
749 return getIntrinsicHeight();
750 }
751
752 @Override
753 public boolean hasNoContentHeight() {
754 return true;
755 }
Selim Cineka686b2c2016-10-26 13:58:27 -0700756
Selim Cinek281c2022016-10-13 19:14:43 -0700757 private void setHideBackground(boolean hideBackground) {
Selim Cinek65d418e2016-11-29 15:42:34 -0800758 if (mHideBackground != hideBackground) {
759 mHideBackground = hideBackground;
760 updateBackground();
761 updateOutline();
762 }
Selim Cinekad7fac02016-10-18 17:09:15 -0700763 }
764
765 @Override
766 protected boolean needsOutline() {
Lucas Dupin00be88f2019-01-03 17:50:52 -0800767 return !mHideBackground && !mDark && super.needsOutline();
Selim Cinek281c2022016-10-13 19:14:43 -0700768 }
769
770 @Override
771 protected boolean shouldHideBackground() {
Lucas Dupin00be88f2019-01-03 17:50:52 -0800772 return super.shouldHideBackground() || mHideBackground || mDark;
Selim Cinek281c2022016-10-13 19:14:43 -0700773 }
774
Selim Cinekfcff4c62016-12-27 14:26:06 +0100775 @Override
776 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
777 super.onLayout(changed, left, top, right, bottom);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800778 updateRelativeOffset();
Selim Cinek143672c2018-03-23 20:04:32 -0700779
780 // we always want to clip to our sides, such that nothing can draw outside of these bounds
781 int height = getResources().getDisplayMetrics().heightPixels;
782 mClipRect.set(0, -height, getWidth(), height);
783 mShelfIcons.setClipBounds(mClipRect);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800784 }
785
786 private void updateRelativeOffset() {
Selim Cinek49014f82016-11-04 14:55:30 -0700787 mCollapsedIcons.getLocationOnScreen(mTmp);
Selim Cinekfcff4c62016-12-27 14:26:06 +0100788 mRelativeOffset = mTmp[0];
789 getLocationOnScreen(mTmp);
790 mRelativeOffset -= mTmp[0];
791 }
792
felkachangc02c3882018-07-27 15:32:31 +0800793 @Override
794 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
795 WindowInsets ret = super.onApplyWindowInsets(insets);
796
797 // NotificationShelf drag from the status bar and the status bar dock on the top
798 // of the display for current design so just focus on the top of ScreenDecorations.
799 // In landscape or multiple window split mode, the NotificationShelf still drag from
800 // the top and the physical notch/cutout goes to the right, left, or both side of the
801 // display so it doesn't matter for the NotificationSelf in landscape.
802 DisplayCutout displayCutout = insets.getDisplayCutout();
803 mCutoutHeight = displayCutout == null || displayCutout.getSafeInsetTop() < 0
804 ? 0 : displayCutout.getSafeInsetTop();
805
806 return ret;
807 }
808
Selim Cinekfcff4c62016-12-27 14:26:06 +0100809 private void setOpenedAmount(float openedAmount) {
Selim Cinek2fce3c82017-05-08 12:38:09 -0700810 mNoAnimationsInThisFrame = openedAmount == 1.0f && mOpenedAmount == 0.0f;
811 mOpenedAmount = openedAmount;
Lucas Dupin55c6e802018-09-27 18:07:36 -0700812 if (!mAmbientState.isPanelFullWidth() || mAmbientState.isDark()) {
Selim Cinekfcff4c62016-12-27 14:26:06 +0100813 // We don't do a transformation at all, lets just assume we are fully opened
814 openedAmount = 1.0f;
815 }
816 int start = mRelativeOffset;
Selim Cinek49014f82016-11-04 14:55:30 -0700817 if (isLayoutRtl()) {
818 start = getWidth() - start - mCollapsedIcons.getWidth();
819 }
Evan Lairdc987fc72017-12-15 10:14:22 -0500820 int width = (int) NotificationUtils.interpolate(
821 start + mCollapsedIcons.getFinalTranslationX(),
Selim Cinek49014f82016-11-04 14:55:30 -0700822 mShelfIcons.getWidth(),
felkachangc02c3882018-07-27 15:32:31 +0800823 FAST_OUT_SLOW_IN_REVERSE.getInterpolation(openedAmount));
Selim Cinek49014f82016-11-04 14:55:30 -0700824 mShelfIcons.setActualLayoutWidth(width);
Selim Cinek932005d2016-12-05 17:12:09 -0800825 boolean hasOverflow = mCollapsedIcons.hasOverflow();
826 int collapsedPadding = mCollapsedIcons.getPaddingEnd();
827 if (!hasOverflow) {
828 // we have to ensure that adding the low priority notification won't lead to an
829 // overflow
Evan Laird8cf0de42018-02-06 18:34:55 -0500830 collapsedPadding -= mCollapsedIcons.getNoOverflowExtraPadding();
Evan Lairdc987fc72017-12-15 10:14:22 -0500831 } else {
832 // Partial overflow padding will fill enough space to add extra dots
833 collapsedPadding -= mCollapsedIcons.getPartialOverflowExtraPadding();
Selim Cinek932005d2016-12-05 17:12:09 -0800834 }
835 float padding = NotificationUtils.interpolate(collapsedPadding,
Selim Cinek49014f82016-11-04 14:55:30 -0700836 mShelfIcons.getPaddingEnd(),
837 openedAmount);
838 mShelfIcons.setActualPaddingEnd(padding);
839 float paddingStart = NotificationUtils.interpolate(start,
840 mShelfIcons.getPaddingStart(), openedAmount);
841 mShelfIcons.setActualPaddingStart(paddingStart);
Selim Cinek17e1b692016-12-02 18:19:11 -0800842 mShelfIcons.setOpenedAmount(openedAmount);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800843 }
844
Selim Cinek9458b192016-10-25 19:02:42 -0700845 public void setMaxLayoutHeight(int maxLayoutHeight) {
846 mMaxLayoutHeight = maxLayoutHeight;
847 }
848
Selim Cinekeccb5de2016-10-28 15:04:05 -0700849 /**
850 * @return the index of the notification at which the shelf visually resides
851 */
852 public int getNotGoneIndex() {
853 return mNotGoneIndex;
854 }
855
856 private void setHasItemsInStableShelf(boolean hasItemsInStableShelf) {
Selim Cinek810bcde2016-12-14 17:29:23 -0800857 if (mHasItemsInStableShelf != hasItemsInStableShelf) {
858 mHasItemsInStableShelf = hasItemsInStableShelf;
859 updateInteractiveness();
860 }
Selim Cinekeccb5de2016-10-28 15:04:05 -0700861 }
862
863 /**
864 * @return whether the shelf has any icons in it when a potential animation has finished, i.e
865 * if the current state would be applied right now
866 */
867 public boolean hasItemsInStableShelf() {
868 return mHasItemsInStableShelf;
869 }
870
Selim Cinek49014f82016-11-04 14:55:30 -0700871 public void setCollapsedIcons(NotificationIconContainer collapsedIcons) {
872 mCollapsedIcons = collapsedIcons;
Selim Cinek9ef119c2017-03-01 15:13:36 -0800873 mCollapsedIcons.addOnLayoutChangeListener(this);
Selim Cinek49014f82016-11-04 14:55:30 -0700874 }
875
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800876 @Override
877 public void onStateChanged(int newState) {
878 mStatusBarState = newState;
Jason Monk1fd3fc32018-08-14 17:20:09 -0400879 updateInteractiveness();
Selim Cinek810bcde2016-12-14 17:29:23 -0800880 }
881
882 private void updateInteractiveness() {
Adrian Roos03cf2582017-03-28 17:54:05 -0700883 mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf
884 && !mDark;
Selim Cinekc6813462017-01-13 17:10:38 -0800885 setClickable(mInteractive);
886 setFocusable(mInteractive);
887 setImportantForAccessibility(mInteractive ? View.IMPORTANT_FOR_ACCESSIBILITY_YES
Selim Cinekaca84c02017-04-05 16:28:56 -0700888 : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
Selim Cinek810bcde2016-12-14 17:29:23 -0800889 }
890
Selim Cinekc6813462017-01-13 17:10:38 -0800891 @Override
892 protected boolean isInteractive() {
893 return mInteractive;
894 }
895
Selim Cineka1d97902016-12-14 16:31:40 -0800896 public void setMaxShelfEnd(float maxShelfEnd) {
897 mMaxShelfEnd = maxShelfEnd;
898 }
899
Selim Cinek09bd29d2017-02-03 15:30:28 -0800900 public void setAnimationsEnabled(boolean enabled) {
901 mAnimationsEnabled = enabled;
902 mCollapsedIcons.setAnimationsEnabled(enabled);
903 if (!enabled) {
904 // we need to wait with enabling the animations until the first frame has passed
905 mShelfIcons.setAnimationsEnabled(false);
906 }
907 }
908
Selim Cinek9ef119c2017-03-01 15:13:36 -0800909 @Override
Adrian Roosd83e9992017-03-16 15:17:57 -0700910 public boolean hasOverlappingRendering() {
911 return false; // Shelf only uses alpha for transitions where the difference can't be seen.
912 }
913
914 @Override
Selim Cinekaca84c02017-04-05 16:28:56 -0700915 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
916 super.onInitializeAccessibilityNodeInfo(info);
917 if (mInteractive) {
918 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
919 AccessibilityNodeInfo.AccessibilityAction unlock
920 = new AccessibilityNodeInfo.AccessibilityAction(
921 AccessibilityNodeInfo.ACTION_CLICK,
922 getContext().getString(R.string.accessibility_overflow_action));
923 info.addAction(unlock);
924 }
925 }
926
927 @Override
Selim Cinek9ef119c2017-03-01 15:13:36 -0800928 public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
929 int oldTop, int oldRight, int oldBottom) {
930 updateRelativeOffset();
931 }
932
Selim Cinekab9c7b22018-12-11 18:15:47 -0800933 public void onUiModeChanged() {
934 updateBackgroundColors();
935 }
936
Selim Cinek281c2022016-10-13 19:14:43 -0700937 private class ShelfState extends ExpandableViewState {
Selim Cinek49014f82016-11-04 14:55:30 -0700938 private float openedAmount;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700939 private boolean hasItemsInStableShelf;
Selim Cineka1d97902016-12-14 16:31:40 -0800940 private float maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700941
942 @Override
943 public void applyToView(View view) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700944 if (!mShowNotificationShelf) {
945 return;
946 }
947
Selim Cinek281c2022016-10-13 19:14:43 -0700948 super.applyToView(view);
Selim Cineka1d97902016-12-14 16:31:40 -0800949 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700950 setOpenedAmount(openedAmount);
Selim Cineka1d97902016-12-14 16:31:40 -0800951 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700952 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800953 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek281c2022016-10-13 19:14:43 -0700954 }
Selim Cinek0cfbef42016-11-09 19:06:36 -0800955
956 @Override
957 public void animateTo(View child, AnimationProperties properties) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700958 if (!mShowNotificationShelf) {
959 return;
960 }
961
Selim Cinek0cfbef42016-11-09 19:06:36 -0800962 super.animateTo(child, properties);
Selim Cineka1d97902016-12-14 16:31:40 -0800963 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700964 setOpenedAmount(openedAmount);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800965 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700966 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800967 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800968 }
Selim Cinek281c2022016-10-13 19:14:43 -0700969 }
970}