blob: 2a22bf2d73988f690bda14e882c2543bb52a31ff [file] [log] [blame]
Selim Cinek281c2022016-10-13 19:14:43 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.systemui.statusbar;
18
Selim Cinek1f624952017-06-08 19:11:50 -070019import static com.android.systemui.statusbar.phone.NotificationIconContainer.IconState.NO_VALUE;
Selim Cinek1f624952017-06-08 19:11:50 -070020
Selim Cinek281c2022016-10-13 19:14:43 -070021import android.content.Context;
22import android.content.res.Configuration;
Anthony Chen9e05d462017-04-07 10:10:21 -070023import android.content.res.Resources;
Selim Cinek6eaacf22017-09-07 18:53:17 -070024import android.graphics.Rect;
Selim Cinek2b549f42016-11-22 16:38:51 -080025import android.os.SystemProperties;
Selim Cinek281c2022016-10-13 19:14:43 -070026import android.util.AttributeSet;
Selim Cinekb7bafbc2017-12-21 11:33:26 -080027import android.util.Log;
Lucas Dupinb561eda2018-04-09 17:25:04 -070028import android.util.MathUtils;
Selim Cinek281c2022016-10-13 19:14:43 -070029import android.view.View;
30import android.view.ViewGroup;
Selim Cinek6eaacf22017-09-07 18:53:17 -070031import android.view.ViewTreeObserver;
Selim Cinekaca84c02017-04-05 16:28:56 -070032import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek1f624952017-06-08 19:11:50 -070033
Selim Cinek9458b192016-10-25 19:02:42 -070034import com.android.systemui.Interpolators;
Selim Cinek281c2022016-10-13 19:14:43 -070035import com.android.systemui.R;
Selim Cinek281c2022016-10-13 19:14:43 -070036import com.android.systemui.statusbar.notification.NotificationUtils;
Rohan Shah20790b82018-07-02 17:21:04 -070037import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
38import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
39import com.android.systemui.statusbar.notification.row.ExpandableView;
Selim Cinek281c2022016-10-13 19:14:43 -070040import com.android.systemui.statusbar.phone.NotificationIconContainer;
Rohan Shah20790b82018-07-02 17:21:04 -070041import com.android.systemui.statusbar.notification.stack.AmbientState;
42import com.android.systemui.statusbar.notification.stack.AnimationProperties;
43import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
44import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
45import com.android.systemui.statusbar.notification.stack.StackScrollState;
46import com.android.systemui.statusbar.notification.stack.ViewState;
Selim Cinek281c2022016-10-13 19:14:43 -070047
Selim Cinek281c2022016-10-13 19:14:43 -070048/**
49 * A notification shelf view that is placed inside the notification scroller. It manages the
50 * overflow icons that don't fit into the regular list anymore.
51 */
Selim Cinek9ef119c2017-03-01 15:13:36 -080052public class NotificationShelf extends ActivatableNotificationView implements
53 View.OnLayoutChangeListener {
Selim Cinek281c2022016-10-13 19:14:43 -070054
Selim Cinek17e1b692016-12-02 18:19:11 -080055 public static final boolean SHOW_AMBIENT_ICONS = true;
Selim Cinek2b549f42016-11-22 16:38:51 -080056 private static final boolean USE_ANIMATIONS_WHEN_OPENING =
57 SystemProperties.getBoolean("debug.icon_opening_animations", true);
Selim Cineka1d97902016-12-14 16:31:40 -080058 private static final boolean ICON_ANMATIONS_WHILE_SCROLLING
59 = SystemProperties.getBoolean("debug.icon_scroll_animations", true);
Selim Cinek6eaacf22017-09-07 18:53:17 -070060 private static final int TAG_CONTINUOUS_CLIPPING = R.id.continuous_clipping_tag;
Selim Cinekb7bafbc2017-12-21 11:33:26 -080061 private static final String TAG = "NotificationShelf";
Lucas Dupin60661a62018-04-12 10:50:13 -070062 private static final long SHELF_IN_TRANSLATION_DURATION = 200;
Lucas Dupinb561eda2018-04-09 17:25:04 -070063
Selim Cinek281c2022016-10-13 19:14:43 -070064 private boolean mDark;
Selim Cinek49014f82016-11-04 14:55:30 -070065 private NotificationIconContainer mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -070066 private ShelfState mShelfState;
67 private int[] mTmp = new int[2];
68 private boolean mHideBackground;
69 private int mIconAppearTopPadding;
Lucas Dupinb561eda2018-04-09 17:25:04 -070070 private int mShelfAppearTranslation;
Selim Cinek48ff9b42016-11-09 19:31:51 -080071 private int mStatusBarHeight;
72 private int mStatusBarPaddingStart;
Selim Cinekc383fd02016-10-21 15:31:26 -070073 private AmbientState mAmbientState;
74 private NotificationStackScrollLayout mHostLayout;
Selim Cinek9458b192016-10-25 19:02:42 -070075 private int mMaxLayoutHeight;
Selim Cineka686b2c2016-10-26 13:58:27 -070076 private int mPaddingBetweenElements;
Selim Cinekeccb5de2016-10-28 15:04:05 -070077 private int mNotGoneIndex;
78 private boolean mHasItemsInStableShelf;
Selim Cinek49014f82016-11-04 14:55:30 -070079 private NotificationIconContainer mCollapsedIcons;
Selim Cinek727903c2016-12-06 17:28:10 -080080 private int mScrollFastThreshold;
Selim Cinekb42698f2017-07-31 17:47:45 -070081 private int mIconSize;
Selim Cinek810bcde2016-12-14 17:29:23 -080082 private int mStatusBarState;
Selim Cineka1d97902016-12-14 16:31:40 -080083 private float mMaxShelfEnd;
Selim Cinekfcff4c62016-12-27 14:26:06 +010084 private int mRelativeOffset;
Selim Cinekc6813462017-01-13 17:10:38 -080085 private boolean mInteractive;
Selim Cinek2fce3c82017-05-08 12:38:09 -070086 private float mOpenedAmount;
87 private boolean mNoAnimationsInThisFrame;
Selim Cinek09bd29d2017-02-03 15:30:28 -080088 private boolean mAnimationsEnabled = true;
Anthony Chen9e05d462017-04-07 10:10:21 -070089 private boolean mShowNotificationShelf;
Selim Cinek515b2032017-11-15 10:20:19 -080090 private float mFirstElementRoundness;
Selim Cinek143672c2018-03-23 20:04:32 -070091 private Rect mClipRect = new Rect();
Selim Cinek281c2022016-10-13 19:14:43 -070092
93 public NotificationShelf(Context context, AttributeSet attrs) {
94 super(context, attrs);
95 }
96
97 @Override
98 protected void onFinishInflate() {
99 super.onFinishInflate();
Alan Viverette51efddb2017-04-05 10:00:01 -0400100 mShelfIcons = findViewById(R.id.content);
Selim Cinek49014f82016-11-04 14:55:30 -0700101 mShelfIcons.setClipChildren(false);
102 mShelfIcons.setClipToPadding(false);
103
Selim Cinek281c2022016-10-13 19:14:43 -0700104 setClipToActualHeight(false);
105 setClipChildren(false);
106 setClipToPadding(false);
Evan Lairdc987fc72017-12-15 10:14:22 -0500107 mShelfIcons.setIsStaticLayout(false);
Selim Cinek281c2022016-10-13 19:14:43 -0700108 mShelfState = new ShelfState();
Selim Cinek2871bef2017-11-22 08:40:00 -0800109 setBottomRoundness(1.0f, false /* animate */);
Selim Cinek281c2022016-10-13 19:14:43 -0700110 initDimens();
111 }
112
Selim Cinekc383fd02016-10-21 15:31:26 -0700113 public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout) {
114 mAmbientState = ambientState;
115 mHostLayout = hostLayout;
116 }
117
Selim Cinek281c2022016-10-13 19:14:43 -0700118 private void initDimens() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700119 Resources res = getResources();
120 mIconAppearTopPadding = res.getDimensionPixelSize(R.dimen.notification_icon_appear_padding);
121 mStatusBarHeight = res.getDimensionPixelOffset(R.dimen.status_bar_height);
122 mStatusBarPaddingStart = res.getDimensionPixelOffset(R.dimen.status_bar_padding_start);
123 mPaddingBetweenElements = res.getDimensionPixelSize(R.dimen.notification_divider_height);
Lucas Dupinb561eda2018-04-09 17:25:04 -0700124 mShelfAppearTranslation = res.getDimensionPixelSize(R.dimen.shelf_appear_translation);
Anthony Chen9e05d462017-04-07 10:10:21 -0700125
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800126 ViewGroup.LayoutParams layoutParams = getLayoutParams();
Anthony Chen9e05d462017-04-07 10:10:21 -0700127 layoutParams.height = res.getDimensionPixelOffset(R.dimen.notification_shelf_height);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800128 setLayoutParams(layoutParams);
Anthony Chen9e05d462017-04-07 10:10:21 -0700129
130 int padding = res.getDimensionPixelOffset(R.dimen.shelf_icon_container_padding);
Selim Cinek0e8d77e2016-11-29 10:35:42 -0800131 mShelfIcons.setPadding(padding, 0, padding, 0);
Anthony Chen9e05d462017-04-07 10:10:21 -0700132 mScrollFastThreshold = res.getDimensionPixelOffset(R.dimen.scroll_fast_threshold);
133 mShowNotificationShelf = res.getBoolean(R.bool.config_showNotificationShelf);
Selim Cinekb42698f2017-07-31 17:47:45 -0700134 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
Anthony Chen9e05d462017-04-07 10:10:21 -0700135
136 if (!mShowNotificationShelf) {
137 setVisibility(GONE);
138 }
Selim Cinek281c2022016-10-13 19:14:43 -0700139 }
140
141 @Override
142 protected void onConfigurationChanged(Configuration newConfig) {
143 super.onConfigurationChanged(newConfig);
144 initDimens();
145 }
146
147 @Override
148 public void setDark(boolean dark, boolean fade, long delay) {
149 super.setDark(dark, fade, delay);
150 if (mDark == dark) return;
151 mDark = dark;
Adrian Roos456e0052017-04-04 16:44:29 -0700152 mShelfIcons.setDark(dark, fade, delay);
Adrian Roos03cf2582017-03-28 17:54:05 -0700153 updateInteractiveness();
Selim Cinek281c2022016-10-13 19:14:43 -0700154 }
155
Lucas Dupinb561eda2018-04-09 17:25:04 -0700156 public void fadeInTranslating() {
157 float translation = mShelfIcons.getTranslationY();
Lucas Dupin60661a62018-04-12 10:50:13 -0700158 mShelfIcons.setTranslationY(translation - mShelfAppearTranslation);
Lucas Dupinb561eda2018-04-09 17:25:04 -0700159 mShelfIcons.setAlpha(0);
160 mShelfIcons.animate()
Lucas Dupin60661a62018-04-12 10:50:13 -0700161 .setInterpolator(Interpolators.DECELERATE_QUINT)
Lucas Dupinb561eda2018-04-09 17:25:04 -0700162 .translationY(translation)
163 .setDuration(SHELF_IN_TRANSLATION_DURATION)
164 .start();
Lucas Dupin60661a62018-04-12 10:50:13 -0700165 mShelfIcons.animate()
166 .alpha(1)
167 .setInterpolator(Interpolators.LINEAR)
168 .setDuration(SHELF_IN_TRANSLATION_DURATION)
169 .start();
Lucas Dupinb561eda2018-04-09 17:25:04 -0700170 }
171
Selim Cinek281c2022016-10-13 19:14:43 -0700172 @Override
173 protected View getContentView() {
Selim Cinek49014f82016-11-04 14:55:30 -0700174 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700175 }
176
Selim Cinek49014f82016-11-04 14:55:30 -0700177 public NotificationIconContainer getShelfIcons() {
178 return mShelfIcons;
Selim Cinek281c2022016-10-13 19:14:43 -0700179 }
180
181 @Override
182 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
183 return mShelfState;
184 }
185
186 public void updateState(StackScrollState resultState,
Selim Cinek281c2022016-10-13 19:14:43 -0700187 AmbientState ambientState) {
Selim Cinekdb167372016-11-17 15:41:17 -0800188 View lastView = ambientState.getLastVisibleBackgroundChild();
Anthony Chen9e05d462017-04-07 10:10:21 -0700189 if (mShowNotificationShelf && lastView != null) {
Selim Cinek281c2022016-10-13 19:14:43 -0700190 float maxShelfEnd = ambientState.getInnerHeight() + ambientState.getTopPadding()
191 + ambientState.getStackTranslation();
Selim Cinek281c2022016-10-13 19:14:43 -0700192 ExpandableViewState lastViewState = resultState.getViewStateForView(lastView);
193 float viewEnd = lastViewState.yTranslation + lastViewState.height;
194 mShelfState.copyFrom(lastViewState);
195 mShelfState.height = getIntrinsicHeight();
Lucas Dupinb561eda2018-04-09 17:25:04 -0700196
197 float awakenTranslation = Math.max(Math.min(viewEnd, maxShelfEnd) - mShelfState.height,
Selim Cinek49014f82016-11-04 14:55:30 -0700198 getFullyClosedTranslation());
Lucas Dupinb561eda2018-04-09 17:25:04 -0700199 float darkTranslation = mAmbientState.getDarkTopPadding();
200 float yRatio = mAmbientState.hasPulsingNotifications() ?
201 0 : mAmbientState.getDarkAmount();
202 mShelfState.yTranslation = MathUtils.lerp(awakenTranslation, darkTranslation, yRatio);
Selim Cinekd127d792016-11-01 19:11:41 -0700203 mShelfState.zTranslation = ambientState.getBaseZHeight();
Selim Cinek48ff9b42016-11-09 19:31:51 -0800204 float openedAmount = (mShelfState.yTranslation - getFullyClosedTranslation())
205 / (getIntrinsicHeight() * 2);
206 openedAmount = Math.min(1.0f, openedAmount);
Selim Cinek49014f82016-11-04 14:55:30 -0700207 mShelfState.openedAmount = openedAmount;
Selim Cinek281c2022016-10-13 19:14:43 -0700208 mShelfState.clipTopAmount = 0;
Selim Cinekbe2c4432017-05-30 12:11:09 -0700209 mShelfState.alpha = mAmbientState.hasPulsingNotifications() ? 0 : 1;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800210 mShelfState.belowSpeedBump = mAmbientState.getSpeedBumpIndex() == 0;
Selim Cinek281c2022016-10-13 19:14:43 -0700211 mShelfState.shadowAlpha = 1.0f;
Selim Cinek281c2022016-10-13 19:14:43 -0700212 mShelfState.hideSensitive = false;
Selim Cinek5b5beb012016-11-08 18:11:58 -0800213 mShelfState.xTranslation = getTranslationX();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700214 if (mNotGoneIndex != -1) {
215 mShelfState.notGoneIndex = Math.min(mShelfState.notGoneIndex, mNotGoneIndex);
216 }
217 mShelfState.hasItemsInStableShelf = lastViewState.inShelf;
Selim Cinek5cf1d052017-06-01 17:36:46 -0700218 mShelfState.hidden = !mAmbientState.isShadeExpanded()
219 || mAmbientState.isQsCustomizerShowing();
Selim Cineka1d97902016-12-14 16:31:40 -0800220 mShelfState.maxShelfEnd = maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700221 } else {
Selim Cinek281c2022016-10-13 19:14:43 -0700222 mShelfState.hidden = true;
223 mShelfState.location = ExpandableViewState.LOCATION_GONE;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700224 mShelfState.hasItemsInStableShelf = false;
Selim Cinek281c2022016-10-13 19:14:43 -0700225 }
226 }
227
Selim Cinekc383fd02016-10-21 15:31:26 -0700228 /**
229 * Update the shelf appearance based on the other notifications around it. This transforms
230 * the icons from the notification area into the shelf.
231 */
232 public void updateAppearance() {
Anthony Chen9e05d462017-04-07 10:10:21 -0700233 // If the shelf should not be shown, then there is no need to update anything.
234 if (!mShowNotificationShelf) {
235 return;
236 }
237
Selim Cinek65d418e2016-11-29 15:42:34 -0800238 mShelfIcons.resetViewStates();
239 float shelfStart = getTranslationY();
Selim Cinekdb167372016-11-17 15:41:17 -0800240 float numViewsInShelf = 0.0f;
241 View lastChild = mAmbientState.getLastVisibleBackgroundChild();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700242 mNotGoneIndex = -1;
Selim Cinek49014f82016-11-04 14:55:30 -0700243 float interpolationStart = mMaxLayoutHeight - getIntrinsicHeight() * 2;
244 float expandAmount = 0.0f;
Selim Cinek65d418e2016-11-29 15:42:34 -0800245 if (shelfStart >= interpolationStart) {
246 expandAmount = (shelfStart - interpolationStart) / getIntrinsicHeight();
Selim Cinek49014f82016-11-04 14:55:30 -0700247 expandAmount = Math.min(1.0f, expandAmount);
248 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700249 // find the first view that doesn't overlap with the shelf
Selim Cinekdb167372016-11-17 15:41:17 -0800250 int notGoneIndex = 0;
Selim Cinekec29d342017-05-05 18:31:49 -0700251 int colorOfViewBeforeLast = NO_COLOR;
Selim Cinekdb167372016-11-17 15:41:17 -0800252 boolean backgroundForceHidden = false;
253 if (mHideBackground && !mShelfState.hasItemsInStableShelf) {
254 backgroundForceHidden = true;
255 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800256 int colorTwoBefore = NO_COLOR;
257 int previousColor = NO_COLOR;
258 float transitionAmount = 0.0f;
Selim Cineka1d97902016-12-14 16:31:40 -0800259 float currentScrollVelocity = mAmbientState.getCurrentScrollVelocity();
260 boolean scrollingFast = currentScrollVelocity > mScrollFastThreshold
Selim Cinekd5ab6452016-12-08 16:34:00 -0800261 || (mAmbientState.isExpansionChanging()
262 && Math.abs(mAmbientState.getExpandingVelocity()) > mScrollFastThreshold);
Selim Cineka1d97902016-12-14 16:31:40 -0800263 boolean scrolling = currentScrollVelocity > 0;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800264 boolean expandingAnimated = mAmbientState.isExpansionChanging()
265 && !mAmbientState.isPanelTracking();
Selim Cinek65d418e2016-11-29 15:42:34 -0800266 int baseZHeight = mAmbientState.getBaseZHeight();
Selim Cinek515b2032017-11-15 10:20:19 -0800267 int backgroundTop = 0;
268 float firstElementRoundness = 0.0f;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700269
270 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
271 ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i);
272
Selim Cinekc383fd02016-10-21 15:31:26 -0700273 if (!(child instanceof ExpandableNotificationRow)
274 || child.getVisibility() == GONE) {
275 continue;
276 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700277
Selim Cinekc383fd02016-10-21 15:31:26 -0700278 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cineka686b2c2016-10-26 13:58:27 -0700279 float notificationClipEnd;
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800280 boolean aboveShelf = ViewState.getFinalTranslationZ(row) > baseZHeight
281 || row.isPinned();
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800282 boolean isLastChild = child == lastChild;
Selim Cinek65d418e2016-11-29 15:42:34 -0800283 float rowTranslationY = row.getTranslationY();
Selim Cinek3ff9fba2017-07-20 10:47:48 -0700284 if ((isLastChild && !child.isInShelf()) || aboveShelf || backgroundForceHidden) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700285 notificationClipEnd = shelfStart + getIntrinsicHeight();
286 } else {
Selim Cineka686b2c2016-10-26 13:58:27 -0700287 notificationClipEnd = shelfStart - mPaddingBetweenElements;
Selim Cinek65d418e2016-11-29 15:42:34 -0800288 float height = notificationClipEnd - rowTranslationY;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800289 if (!row.isBelowSpeedBump() && height <= getNotificationMergeSize()) {
Selim Cineka686b2c2016-10-26 13:58:27 -0700290 // We want the gap to close when we reached the minimum size and only shrink
291 // before
292 notificationClipEnd = Math.min(shelfStart,
Selim Cinek65d418e2016-11-29 15:42:34 -0800293 rowTranslationY + getNotificationMergeSize());
Selim Cineka686b2c2016-10-26 13:58:27 -0700294 }
295 }
296 updateNotificationClipHeight(row, notificationClipEnd);
Selim Cineka1d97902016-12-14 16:31:40 -0800297 float inShelfAmount = updateIconAppearance(row, expandAmount, scrolling, scrollingFast,
Selim Cinekd5ab6452016-12-08 16:34:00 -0800298 expandingAnimated, isLastChild);
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800299 numViewsInShelf += inShelfAmount;
300 int ownColorUntinted = row.getBackgroundColorWithoutTint();
Selim Cinek65d418e2016-11-29 15:42:34 -0800301 if (rowTranslationY >= shelfStart && mNotGoneIndex == -1) {
Selim Cinekdb167372016-11-17 15:41:17 -0800302 mNotGoneIndex = notGoneIndex;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800303 setTintColor(previousColor);
304 setOverrideTintColor(colorTwoBefore, transitionAmount);
305
306 } else if (mNotGoneIndex == -1) {
307 colorTwoBefore = previousColor;
308 transitionAmount = inShelfAmount;
309 }
Selim Cinekec29d342017-05-05 18:31:49 -0700310 if (isLastChild) {
311 if (colorOfViewBeforeLast == NO_COLOR) {
312 colorOfViewBeforeLast = ownColorUntinted;
313 }
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800314 row.setOverrideTintColor(colorOfViewBeforeLast, inShelfAmount);
315 } else {
316 colorOfViewBeforeLast = ownColorUntinted;
317 row.setOverrideTintColor(NO_COLOR, 0 /* overrideAmount */);
Selim Cinekeccb5de2016-10-28 15:04:05 -0700318 }
Selim Cinekdb167372016-11-17 15:41:17 -0800319 if (notGoneIndex != 0 || !aboveShelf) {
Selim Cinekd127d792016-11-01 19:11:41 -0700320 row.setAboveShelf(false);
321 }
Selim Cinek0fe07392017-11-09 13:26:34 -0800322 if (notGoneIndex == 0) {
323 StatusBarIconView icon = row.getEntry().expandedIcon;
324 NotificationIconContainer.IconState iconState = getIconState(icon);
Selim Cinekb7bafbc2017-12-21 11:33:26 -0800325 if (iconState != null && iconState.clampedAppearAmount == 1.0f) {
Selim Cinek0fe07392017-11-09 13:26:34 -0800326 // only if the first icon is fully in the shelf we want to clip to it!
Selim Cinek515b2032017-11-15 10:20:19 -0800327 backgroundTop = (int) (row.getTranslationY() - getTranslationY());
328 firstElementRoundness = row.getCurrentTopRoundness();
Selim Cinekb7bafbc2017-12-21 11:33:26 -0800329 } else if (iconState == null) {
330 Log.wtf(TAG, "iconState is null. ExpandedIcon: " + row.getEntry().expandedIcon
331 + (row.getEntry().expandedIcon != null
332 ? "\n icon parent: " + row.getEntry().expandedIcon.getParent() : "")
333 + " \n number of notifications: " + mHostLayout.getChildCount() );
Selim Cinek0fe07392017-11-09 13:26:34 -0800334 }
335 }
Selim Cinekdb167372016-11-17 15:41:17 -0800336 notGoneIndex++;
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800337 previousColor = ownColorUntinted;
Selim Cineka686b2c2016-10-26 13:58:27 -0700338 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700339
340 clipTransientViews();
341
Selim Cinek515b2032017-11-15 10:20:19 -0800342 setBackgroundTop(backgroundTop);
343 setFirstElementRoundness(firstElementRoundness);
Selim Cinek17e1b692016-12-02 18:19:11 -0800344 mShelfIcons.setSpeedBumpIndex(mAmbientState.getSpeedBumpIndex());
Selim Cinek49014f82016-11-04 14:55:30 -0700345 mShelfIcons.calculateIconTranslations();
346 mShelfIcons.applyIconStates();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700347 for (int i = 0; i < mHostLayout.getChildCount(); i++) {
348 View child = mHostLayout.getChildAt(i);
349 if (!(child instanceof ExpandableNotificationRow)
350 || child.getVisibility() == GONE) {
351 continue;
352 }
353 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
354 updateIconClipAmount(row);
355 updateContinuousClipping(row);
356 }
Selim Cinekdb167372016-11-17 15:41:17 -0800357 boolean hideBackground = numViewsInShelf < 1.0f;
358 setHideBackground(hideBackground || backgroundForceHidden);
359 if (mNotGoneIndex == -1) {
360 mNotGoneIndex = notGoneIndex;
361 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800362 }
363
Rohan Shah524cf7b2018-03-15 14:40:02 -0700364 /**
365 * Clips transient views to the top of the shelf - Transient views are only used for
366 * disappearing views/animations and need to be clipped correctly by the shelf to ensure they
367 * don't show underneath the notification stack when something is animating and the user
368 * swipes quickly.
369 */
370 private void clipTransientViews() {
371 for (int i = 0; i < mHostLayout.getTransientViewCount(); i++) {
372 View transientView = mHostLayout.getTransientView(i);
373 if (transientView instanceof ExpandableNotificationRow) {
374 ExpandableNotificationRow transientRow = (ExpandableNotificationRow) transientView;
375 updateNotificationClipHeight(transientRow, getTranslationY());
376 } else {
377 Log.e(TAG, "NotificationShelf.clipTransientViews(): "
378 + "Trying to clip non-row transient view");
379 }
380 }
381 }
382
Selim Cinek515b2032017-11-15 10:20:19 -0800383 private void setFirstElementRoundness(float firstElementRoundness) {
384 if (mFirstElementRoundness != firstElementRoundness) {
385 mFirstElementRoundness = firstElementRoundness;
386 setTopRoundness(firstElementRoundness, false /* animate */);
Selim Cinek0fe07392017-11-09 13:26:34 -0800387 }
388 }
389
Selim Cinek6eaacf22017-09-07 18:53:17 -0700390 private void updateIconClipAmount(ExpandableNotificationRow row) {
391 float maxTop = row.getTranslationY();
392 StatusBarIconView icon = row.getEntry().expandedIcon;
393 float shelfIconPosition = getTranslationY() + icon.getTop() + icon.getTranslationY();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800394 if (shelfIconPosition < maxTop && !mAmbientState.isDark()) {
Selim Cinek6eaacf22017-09-07 18:53:17 -0700395 int top = (int) (maxTop - shelfIconPosition);
396 Rect clipRect = new Rect(0, top, icon.getWidth(), Math.max(top, icon.getHeight()));
397 icon.setClipBounds(clipRect);
398 } else {
399 icon.setClipBounds(null);
400 }
401 }
402
403 private void updateContinuousClipping(final ExpandableNotificationRow row) {
404 StatusBarIconView icon = row.getEntry().expandedIcon;
Lucas Dupin16cfe452018-02-08 13:14:50 -0800405 boolean needsContinuousClipping = ViewState.isAnimatingY(icon) && !mAmbientState.isDark();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700406 boolean isContinuousClipping = icon.getTag(TAG_CONTINUOUS_CLIPPING) != null;
407 if (needsContinuousClipping && !isContinuousClipping) {
Selim Cinek85845b82018-04-25 13:10:57 +0800408 final ViewTreeObserver observer = icon.getViewTreeObserver();
Selim Cinek6eaacf22017-09-07 18:53:17 -0700409 ViewTreeObserver.OnPreDrawListener predrawListener =
410 new ViewTreeObserver.OnPreDrawListener() {
411 @Override
412 public boolean onPreDraw() {
413 boolean animatingY = ViewState.isAnimatingY(icon);
Selim Cinek85845b82018-04-25 13:10:57 +0800414 if (!animatingY) {
415 observer.removeOnPreDrawListener(this);
Selim Cinek6eaacf22017-09-07 18:53:17 -0700416 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
417 return true;
418 }
419 updateIconClipAmount(row);
420 return true;
421 }
422 };
Selim Cinek85845b82018-04-25 13:10:57 +0800423 observer.addOnPreDrawListener(predrawListener);
424 icon.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
425 @Override
426 public void onViewAttachedToWindow(View v) {
427 }
428
429 @Override
430 public void onViewDetachedFromWindow(View v) {
431 if (v == icon) {
432 observer.removeOnPreDrawListener(predrawListener);
433 icon.setTag(TAG_CONTINUOUS_CLIPPING, null);
434 }
435 }
436 });
Selim Cinek6eaacf22017-09-07 18:53:17 -0700437 icon.setTag(TAG_CONTINUOUS_CLIPPING, predrawListener);
438 }
439 }
440
Selim Cineka686b2c2016-10-26 13:58:27 -0700441 private void updateNotificationClipHeight(ExpandableNotificationRow row,
442 float notificationClipEnd) {
443 float viewEnd = row.getTranslationY() + row.getActualHeight();
Selim Cinekebf42342017-07-13 15:46:10 +0200444 boolean isPinned = (row.isPinned() || row.isHeadsUpAnimatingAway())
445 && !mAmbientState.isDozingAndNotPulsing(row);
Selim Cinekd127d792016-11-01 19:11:41 -0700446 if (viewEnd > notificationClipEnd
Selim Cinek7e0f9482017-05-22 20:00:56 -0700447 && (mAmbientState.isShadeExpanded() || !isPinned)) {
448 int clipBottomAmount = (int) (viewEnd - notificationClipEnd);
449 if (isPinned) {
450 clipBottomAmount = Math.min(row.getIntrinsicHeight() - row.getCollapsedHeight(),
451 clipBottomAmount);
452 }
453 row.setClipBottomAmount(clipBottomAmount);
Selim Cineka686b2c2016-10-26 13:58:27 -0700454 } else {
455 row.setClipBottomAmount(0);
456 }
457 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700458
Selim Cinekc8c4cf92017-09-08 15:30:09 -0700459 @Override
460 public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd,
461 int outlineTranslation) {
462 if (!mHasItemsInStableShelf) {
463 shadowIntensity = 0.0f;
464 }
465 super.setFakeShadowIntensity(shadowIntensity, outlineAlpha, shadowYEnd, outlineTranslation);
466 }
467
Selim Cinekf9bba0b2016-11-18 15:08:21 -0800468 /**
469 * @return the icon amount how much this notification is in the shelf;
470 */
Selim Cinek2b549f42016-11-22 16:38:51 -0800471 private float updateIconAppearance(ExpandableNotificationRow row, float expandAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800472 boolean scrolling, boolean scrollingFast, boolean expandingAnimated,
473 boolean isLastChild) {
Selim Cinek1f624952017-06-08 19:11:50 -0700474 StatusBarIconView icon = row.getEntry().expandedIcon;
475 NotificationIconContainer.IconState iconState = getIconState(icon);
476 if (iconState == null) {
477 return 0.0f;
478 }
479
Selim Cinekc383fd02016-10-21 15:31:26 -0700480 // Let calculate how much the view is in the shelf
481 float viewStart = row.getTranslationY();
Selim Cinek2b549f42016-11-22 16:38:51 -0800482 int fullHeight = row.getActualHeight() + mPaddingBetweenElements;
483 float iconTransformDistance = getIntrinsicHeight() * 1.5f;
Selim Cineka1d97902016-12-14 16:31:40 -0800484 iconTransformDistance *= NotificationUtils.interpolate(1.f, 1.5f, expandAmount);
Selim Cinek1f624952017-06-08 19:11:50 -0700485 iconTransformDistance = Math.min(iconTransformDistance, fullHeight);
Selim Cinek938bdaa2016-11-18 16:31:09 -0800486 if (isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800487 fullHeight = Math.min(fullHeight, row.getMinHeight() - getIntrinsicHeight());
Bill Line6065e32018-06-08 17:07:13 +0800488 iconTransformDistance = Math.min(iconTransformDistance, row.getMinHeight()
489 - getIntrinsicHeight());
Selim Cinek938bdaa2016-11-18 16:31:09 -0800490 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800491 float viewEnd = viewStart + fullHeight;
Selim Cinek1f624952017-06-08 19:11:50 -0700492 if (expandingAnimated && mAmbientState.getScrollY() == 0
493 && !mAmbientState.isOnKeyguard() && !iconState.isLastExpandIcon) {
494 // We are expanding animated. Because we switch to a linear interpolation in this case,
495 // the last icon may be stuck in between the shelf position and the notification
496 // position, which looks pretty bad. We therefore optimize this case by applying a
497 // shorter transition such that the icon is either fully in the notification or we clamp
498 // it into the shelf if it's close enough.
499 // We need to persist this, since after the expansion, the behavior should still be the
500 // same.
501 float position = mAmbientState.getIntrinsicPadding()
502 + mHostLayout.getPositionInLinearLayout(row);
503 int maxShelfStart = mMaxLayoutHeight - getIntrinsicHeight();
504 if (position < maxShelfStart && position + row.getIntrinsicHeight() >= maxShelfStart
505 && row.getTranslationY() < position) {
506 iconState.isLastExpandIcon = true;
507 iconState.customTransformHeight = NO_VALUE;
508 // Let's check if we're close enough to snap into the shelf
509 boolean forceInShelf = mMaxLayoutHeight - getIntrinsicHeight() - position
510 < getIntrinsicHeight();
511 if (!forceInShelf) {
512 // We are overlapping the shelf but not enough, so the icon needs to be
513 // repositioned
514 iconState.customTransformHeight = (int) (mMaxLayoutHeight
515 - getIntrinsicHeight() - position);
516 }
517 }
518 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800519 float fullTransitionAmount;
Selim Cinek01a73f92016-12-06 16:13:42 -0800520 float iconTransitionAmount;
521 float shelfStart = getTranslationY();
Selim Cinek1f624952017-06-08 19:11:50 -0700522 if (iconState.hasCustomTransformHeight()) {
523 fullHeight = iconState.customTransformHeight;
524 iconTransformDistance = iconState.customTransformHeight;
525 }
526 boolean fullyInOrOut = true;
Selim Cinekec29d342017-05-05 18:31:49 -0700527 if (viewEnd >= shelfStart && (!mAmbientState.isUnlockHintRunning() || row.isInShelf())
528 && (mAmbientState.isShadeExpanded()
529 || (!row.isPinned() && !row.isHeadsUpAnimatingAway()))) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800530 if (viewStart < shelfStart) {
Selim Cinek01a73f92016-12-06 16:13:42 -0800531 float fullAmount = (shelfStart - viewStart) / fullHeight;
Selim Cinek1f624952017-06-08 19:11:50 -0700532 fullAmount = Math.min(1.0f, fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700533 float interpolatedAmount = Interpolators.ACCELERATE_DECELERATE.getInterpolation(
Selim Cinek2b549f42016-11-22 16:38:51 -0800534 fullAmount);
Selim Cinek9458b192016-10-25 19:02:42 -0700535 interpolatedAmount = NotificationUtils.interpolate(
Selim Cinek2b549f42016-11-22 16:38:51 -0800536 interpolatedAmount, fullAmount, expandAmount);
537 fullTransitionAmount = 1.0f - interpolatedAmount;
538
Selim Cinek01a73f92016-12-06 16:13:42 -0800539 iconTransitionAmount = (shelfStart - viewStart) / iconTransformDistance;
540 iconTransitionAmount = Math.min(1.0f, iconTransitionAmount);
541 iconTransitionAmount = 1.0f - iconTransitionAmount;
Selim Cinek1f624952017-06-08 19:11:50 -0700542 fullyInOrOut = false;
Selim Cinekc383fd02016-10-21 15:31:26 -0700543 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800544 fullTransitionAmount = 1.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800545 iconTransitionAmount = 1.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700546 }
547 } else {
Selim Cinek2b549f42016-11-22 16:38:51 -0800548 fullTransitionAmount = 0.0f;
Selim Cinek01a73f92016-12-06 16:13:42 -0800549 iconTransitionAmount = 0.0f;
Selim Cinekc383fd02016-10-21 15:31:26 -0700550 }
Selim Cinek1f624952017-06-08 19:11:50 -0700551 if (fullyInOrOut && !expandingAnimated && iconState.isLastExpandIcon) {
552 iconState.isLastExpandIcon = false;
553 iconState.customTransformHeight = NO_VALUE;
554 }
Selim Cineka1d97902016-12-14 16:31:40 -0800555 updateIconPositioning(row, iconTransitionAmount, fullTransitionAmount,
556 iconTransformDistance, scrolling, scrollingFast, expandingAnimated, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800557 return fullTransitionAmount;
558 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700559
Selim Cinek2b549f42016-11-22 16:38:51 -0800560 private void updateIconPositioning(ExpandableNotificationRow row, float iconTransitionAmount,
Selim Cineka1d97902016-12-14 16:31:40 -0800561 float fullTransitionAmount, float iconTransformDistance, boolean scrolling,
562 boolean scrollingFast, boolean expandingAnimated, boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800563 StatusBarIconView icon = row.getEntry().expandedIcon;
564 NotificationIconContainer.IconState iconState = getIconState(icon);
565 if (iconState == null) {
566 return;
567 }
Selim Cinek1f624952017-06-08 19:11:50 -0700568 boolean forceInShelf = iconState.isLastExpandIcon && !iconState.hasCustomTransformHeight();
Selim Cinek2b549f42016-11-22 16:38:51 -0800569 float clampedAmount = iconTransitionAmount > 0.5f ? 1.0f : 0.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800570 if (clampedAmount == fullTransitionAmount) {
Selim Cinek1f624952017-06-08 19:11:50 -0700571 iconState.noAnimations = (scrollingFast || expandingAnimated) && !forceInShelf;
Selim Cinek44d81a62017-05-08 19:45:40 -0700572 iconState.useFullTransitionAmount = iconState.noAnimations
Selim Cineka1d97902016-12-14 16:31:40 -0800573 || (!ICON_ANMATIONS_WHILE_SCROLLING && fullTransitionAmount == 0.0f && scrolling);
574 iconState.useLinearTransitionAmount = !ICON_ANMATIONS_WHILE_SCROLLING
575 && fullTransitionAmount == 0.0f && !mAmbientState.isExpansionChanging();
Selim Cinek01a73f92016-12-06 16:13:42 -0800576 iconState.translateContent = mMaxLayoutHeight - getTranslationY()
577 - getIntrinsicHeight() > 0;
Selim Cinek2b549f42016-11-22 16:38:51 -0800578 }
Selim Cinek1f624952017-06-08 19:11:50 -0700579 if (!forceInShelf && (scrollingFast || (expandingAnimated
580 && iconState.useFullTransitionAmount && !ViewState.isAnimatingY(icon)))) {
Selim Cinekd5ab6452016-12-08 16:34:00 -0800581 iconState.cancelAnimations(icon);
582 iconState.useFullTransitionAmount = true;
Selim Cinek44d81a62017-05-08 19:45:40 -0700583 iconState.noAnimations = true;
Selim Cinekd5ab6452016-12-08 16:34:00 -0800584 }
Selim Cinek1f624952017-06-08 19:11:50 -0700585 if (iconState.hasCustomTransformHeight()) {
586 iconState.useFullTransitionAmount = true;
587 }
588 if (iconState.isLastExpandIcon) {
589 iconState.translateContent = false;
590 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800591 float transitionAmount;
Lucas Dupinb561eda2018-04-09 17:25:04 -0700592 if (mAmbientState.getDarkAmount() > 0 && !row.isInShelf()) {
593 transitionAmount = mAmbientState.isFullyDark() ? 1 : 0;
594 } else if (isLastChild || !USE_ANIMATIONS_WHEN_OPENING || iconState.useFullTransitionAmount
Selim Cineka1d97902016-12-14 16:31:40 -0800595 || iconState.useLinearTransitionAmount) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800596 transitionAmount = iconTransitionAmount;
Selim Cinek2b549f42016-11-22 16:38:51 -0800597 } else {
Selim Cineka1d97902016-12-14 16:31:40 -0800598 // We take the clamped position instead
599 transitionAmount = clampedAmount;
Selim Cinek2fce3c82017-05-08 12:38:09 -0700600 iconState.needsCannedAnimation = iconState.clampedAppearAmount != clampedAmount
601 && !mNoAnimationsInThisFrame;
Selim Cinek2b549f42016-11-22 16:38:51 -0800602 }
603 iconState.iconAppearAmount = !USE_ANIMATIONS_WHEN_OPENING
604 || iconState.useFullTransitionAmount
605 ? fullTransitionAmount
606 : transitionAmount;
607 iconState.clampedAppearAmount = clampedAmount;
Selim Cinekebf42342017-07-13 15:46:10 +0200608 float contentTransformationAmount = !mAmbientState.isAboveShelf(row)
Selim Cinek7e0f9482017-05-22 20:00:56 -0700609 && (isLastChild || iconState.translateContent)
Selim Cinek01a73f92016-12-06 16:13:42 -0800610 ? iconTransitionAmount
611 : 0.0f;
612 row.setContentTransformationAmount(contentTransformationAmount, isLastChild);
Selim Cineka1d97902016-12-14 16:31:40 -0800613 setIconTransformationAmount(row, transitionAmount, iconTransformDistance,
Mady Mellor434180c2017-02-13 11:29:42 -0800614 clampedAmount != transitionAmount, isLastChild);
Selim Cinek2b549f42016-11-22 16:38:51 -0800615 }
616
617 private void setIconTransformationAmount(ExpandableNotificationRow row,
Mady Mellor434180c2017-02-13 11:29:42 -0800618 float transitionAmount, float iconTransformDistance, boolean usingLinearInterpolation,
619 boolean isLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800620 StatusBarIconView icon = row.getEntry().expandedIcon;
621 NotificationIconContainer.IconState iconState = getIconState(icon);
622
Selim Cinekc383fd02016-10-21 15:31:26 -0700623 View rowIcon = row.getNotificationIcon();
Selim Cineka1d97902016-12-14 16:31:40 -0800624 float notificationIconPosition = row.getTranslationY() + row.getContentTranslation();
Selim Cinekf20254c2017-02-03 10:09:33 -0800625 boolean stayingInShelf = row.isInShelf() && !row.isTransformingIntoShelf();
626 if (usingLinearInterpolation && !stayingInShelf) {
Selim Cineka1d97902016-12-14 16:31:40 -0800627 // If we interpolate from the notification position, this might lead to a slightly
628 // odd interpolation, since the notification position changes as well. Let's interpolate
629 // from a fixed distance. We can only do this if we don't animate and the icon is
630 // always in the interpolated positon.
Selim Cinekf20254c2017-02-03 10:09:33 -0800631 notificationIconPosition = getTranslationY() - iconTransformDistance;
Selim Cineka1d97902016-12-14 16:31:40 -0800632 }
Selim Cinek281c2022016-10-13 19:14:43 -0700633 float notificationIconSize = 0.0f;
634 int iconTopPadding;
635 if (rowIcon != null) {
Selim Cinek875a3a12016-11-18 17:52:16 -0800636 iconTopPadding = row.getRelativeTopPadding(rowIcon);
Selim Cinek281c2022016-10-13 19:14:43 -0700637 notificationIconSize = rowIcon.getHeight();
638 } else {
639 iconTopPadding = mIconAppearTopPadding;
640 }
641 notificationIconPosition += iconTopPadding;
Selim Cinekc383fd02016-10-21 15:31:26 -0700642 float shelfIconPosition = getTranslationY() + icon.getTop();
Selim Cinekb42698f2017-07-31 17:47:45 -0700643 shelfIconPosition += (icon.getHeight() - icon.getIconScale() * mIconSize) / 2.0f;
Selim Cinek2b549f42016-11-22 16:38:51 -0800644 float iconYTranslation = NotificationUtils.interpolate(
Selim Cineka1d97902016-12-14 16:31:40 -0800645 notificationIconPosition - shelfIconPosition,
Selim Cinek2b549f42016-11-22 16:38:51 -0800646 0,
647 transitionAmount);
Selim Cinekb42698f2017-07-31 17:47:45 -0700648 float shelfIconSize = mIconSize * icon.getIconScale();
Selim Cinek2b549f42016-11-22 16:38:51 -0800649 float alpha = 1.0f;
Selim Cinek875ba9b2017-02-13 16:20:17 -0800650 boolean noIcon = !row.isShowingIcon();
651 if (noIcon) {
Selim Cinekc383fd02016-10-21 15:31:26 -0700652 // The view currently doesn't have an icon, lets transform it in!
Selim Cinekdb167372016-11-17 15:41:17 -0800653 alpha = transitionAmount;
Selim Cinekc383fd02016-10-21 15:31:26 -0700654 notificationIconSize = shelfIconSize / 2.0f;
655 }
656 // The notification size is different from the size in the shelf / statusbar
657 float newSize = NotificationUtils.interpolate(notificationIconSize, shelfIconSize,
Selim Cinek281c2022016-10-13 19:14:43 -0700658 transitionAmount);
Selim Cinekdb167372016-11-17 15:41:17 -0800659 if (iconState != null) {
Selim Cinekb42698f2017-07-31 17:47:45 -0700660 iconState.scaleX = newSize / shelfIconSize;
Selim Cinekdb167372016-11-17 15:41:17 -0800661 iconState.scaleY = iconState.scaleX;
Adrian Roos28f90c72017-05-08 17:24:26 -0700662 iconState.hidden = transitionAmount == 0.0f && !iconState.isAnimating(icon);
Selim Cinekf38d6c32017-06-28 15:44:02 +0200663 boolean isAppearing = row.isDrawingAppearAnimation() && !row.isInShelf();
664 if (isAppearing) {
665 iconState.hidden = true;
666 iconState.iconAppearAmount = 0.0f;
667 }
Selim Cinekdb167372016-11-17 15:41:17 -0800668 iconState.alpha = alpha;
Selim Cinek2b549f42016-11-22 16:38:51 -0800669 iconState.yTranslation = iconYTranslation;
Selim Cinekf20254c2017-02-03 10:09:33 -0800670 if (stayingInShelf) {
Selim Cinekdb167372016-11-17 15:41:17 -0800671 iconState.iconAppearAmount = 1.0f;
672 iconState.alpha = 1.0f;
673 iconState.scaleX = 1.0f;
674 iconState.scaleY = 1.0f;
675 iconState.hidden = false;
676 }
Selim Cinekebf42342017-07-13 15:46:10 +0200677 if (mAmbientState.isAboveShelf(row) || (!row.isInShelf() && (isLastChild && row.areGutsExposed()
Selim Cinek47374632017-03-17 16:07:17 -0700678 || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) {
Selim Cinek5ea19572016-11-29 15:34:48 -0800679 iconState.hidden = true;
680 }
Lucas Dupin83519da2017-06-21 11:58:31 -0700681 int backgroundColor = getBackgroundColorWithoutTint();
682 int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor);
Selim Cinek875ba9b2017-02-13 16:20:17 -0800683 if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) {
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700684 int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor();
685 shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor,
Selim Cinek875ba9b2017-02-13 16:20:17 -0800686 iconState.iconAppearAmount);
687 }
688 iconState.iconColor = shelfColor;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700689 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800690 }
691
692 private NotificationIconContainer.IconState getIconState(StatusBarIconView icon) {
693 return mShelfIcons.getIconState(icon);
Selim Cinekc383fd02016-10-21 15:31:26 -0700694 }
695
696 private float getFullyClosedTranslation() {
697 return - (getIntrinsicHeight() - mStatusBarHeight) / 2;
Selim Cinek281c2022016-10-13 19:14:43 -0700698 }
699
Selim Cinek281c2022016-10-13 19:14:43 -0700700 public int getNotificationMergeSize() {
701 return getIntrinsicHeight();
702 }
703
704 @Override
705 public boolean hasNoContentHeight() {
706 return true;
707 }
Selim Cineka686b2c2016-10-26 13:58:27 -0700708
Selim Cinek281c2022016-10-13 19:14:43 -0700709 private void setHideBackground(boolean hideBackground) {
Selim Cinek65d418e2016-11-29 15:42:34 -0800710 if (mHideBackground != hideBackground) {
711 mHideBackground = hideBackground;
712 updateBackground();
713 updateOutline();
714 }
Selim Cinekad7fac02016-10-18 17:09:15 -0700715 }
716
Selim Cinekeccb5de2016-10-28 15:04:05 -0700717 public boolean hidesBackground() {
718 return mHideBackground;
719 }
720
Selim Cinekad7fac02016-10-18 17:09:15 -0700721 @Override
722 protected boolean needsOutline() {
723 return !mHideBackground && super.needsOutline();
Selim Cinek281c2022016-10-13 19:14:43 -0700724 }
725
726 @Override
727 protected boolean shouldHideBackground() {
728 return super.shouldHideBackground() || mHideBackground;
729 }
730
Selim Cinekfcff4c62016-12-27 14:26:06 +0100731 @Override
732 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
733 super.onLayout(changed, left, top, right, bottom);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800734 updateRelativeOffset();
Selim Cinek143672c2018-03-23 20:04:32 -0700735
736 // we always want to clip to our sides, such that nothing can draw outside of these bounds
737 int height = getResources().getDisplayMetrics().heightPixels;
738 mClipRect.set(0, -height, getWidth(), height);
739 mShelfIcons.setClipBounds(mClipRect);
Selim Cinek9ef119c2017-03-01 15:13:36 -0800740 }
741
742 private void updateRelativeOffset() {
Selim Cinek49014f82016-11-04 14:55:30 -0700743 mCollapsedIcons.getLocationOnScreen(mTmp);
Selim Cinekfcff4c62016-12-27 14:26:06 +0100744 mRelativeOffset = mTmp[0];
745 getLocationOnScreen(mTmp);
746 mRelativeOffset -= mTmp[0];
747 }
748
749 private void setOpenedAmount(float openedAmount) {
Selim Cinek2fce3c82017-05-08 12:38:09 -0700750 mNoAnimationsInThisFrame = openedAmount == 1.0f && mOpenedAmount == 0.0f;
751 mOpenedAmount = openedAmount;
Selim Cinekfcff4c62016-12-27 14:26:06 +0100752 if (!mAmbientState.isPanelFullWidth()) {
753 // We don't do a transformation at all, lets just assume we are fully opened
754 openedAmount = 1.0f;
755 }
756 int start = mRelativeOffset;
Selim Cinek49014f82016-11-04 14:55:30 -0700757 if (isLayoutRtl()) {
758 start = getWidth() - start - mCollapsedIcons.getWidth();
759 }
Evan Lairdc987fc72017-12-15 10:14:22 -0500760 int width = (int) NotificationUtils.interpolate(
761 start + mCollapsedIcons.getFinalTranslationX(),
Selim Cinek49014f82016-11-04 14:55:30 -0700762 mShelfIcons.getWidth(),
763 openedAmount);
764 mShelfIcons.setActualLayoutWidth(width);
Selim Cinek932005d2016-12-05 17:12:09 -0800765 boolean hasOverflow = mCollapsedIcons.hasOverflow();
766 int collapsedPadding = mCollapsedIcons.getPaddingEnd();
767 if (!hasOverflow) {
768 // we have to ensure that adding the low priority notification won't lead to an
769 // overflow
Evan Laird8cf0de42018-02-06 18:34:55 -0500770 collapsedPadding -= mCollapsedIcons.getNoOverflowExtraPadding();
Evan Lairdc987fc72017-12-15 10:14:22 -0500771 } else {
772 // Partial overflow padding will fill enough space to add extra dots
773 collapsedPadding -= mCollapsedIcons.getPartialOverflowExtraPadding();
Selim Cinek932005d2016-12-05 17:12:09 -0800774 }
775 float padding = NotificationUtils.interpolate(collapsedPadding,
Selim Cinek49014f82016-11-04 14:55:30 -0700776 mShelfIcons.getPaddingEnd(),
777 openedAmount);
778 mShelfIcons.setActualPaddingEnd(padding);
779 float paddingStart = NotificationUtils.interpolate(start,
780 mShelfIcons.getPaddingStart(), openedAmount);
781 mShelfIcons.setActualPaddingStart(paddingStart);
Selim Cinek17e1b692016-12-02 18:19:11 -0800782 mShelfIcons.setOpenedAmount(openedAmount);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800783 }
784
Selim Cinek9458b192016-10-25 19:02:42 -0700785 public void setMaxLayoutHeight(int maxLayoutHeight) {
786 mMaxLayoutHeight = maxLayoutHeight;
787 }
788
Selim Cinekeccb5de2016-10-28 15:04:05 -0700789 /**
790 * @return the index of the notification at which the shelf visually resides
791 */
792 public int getNotGoneIndex() {
793 return mNotGoneIndex;
794 }
795
796 private void setHasItemsInStableShelf(boolean hasItemsInStableShelf) {
Selim Cinek810bcde2016-12-14 17:29:23 -0800797 if (mHasItemsInStableShelf != hasItemsInStableShelf) {
798 mHasItemsInStableShelf = hasItemsInStableShelf;
799 updateInteractiveness();
800 }
Selim Cinekeccb5de2016-10-28 15:04:05 -0700801 }
802
803 /**
804 * @return whether the shelf has any icons in it when a potential animation has finished, i.e
805 * if the current state would be applied right now
806 */
807 public boolean hasItemsInStableShelf() {
808 return mHasItemsInStableShelf;
809 }
810
Selim Cinek49014f82016-11-04 14:55:30 -0700811 public void setCollapsedIcons(NotificationIconContainer collapsedIcons) {
812 mCollapsedIcons = collapsedIcons;
Selim Cinek9ef119c2017-03-01 15:13:36 -0800813 mCollapsedIcons.addOnLayoutChangeListener(this);
Selim Cinek49014f82016-11-04 14:55:30 -0700814 }
815
Selim Cinek810bcde2016-12-14 17:29:23 -0800816 public void setStatusBarState(int statusBarState) {
817 if (mStatusBarState != statusBarState) {
818 mStatusBarState = statusBarState;
819 updateInteractiveness();
820 }
821 }
822
823 private void updateInteractiveness() {
Adrian Roos03cf2582017-03-28 17:54:05 -0700824 mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf
825 && !mDark;
Selim Cinekc6813462017-01-13 17:10:38 -0800826 setClickable(mInteractive);
827 setFocusable(mInteractive);
828 setImportantForAccessibility(mInteractive ? View.IMPORTANT_FOR_ACCESSIBILITY_YES
Selim Cinekaca84c02017-04-05 16:28:56 -0700829 : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
Selim Cinek810bcde2016-12-14 17:29:23 -0800830 }
831
Selim Cinekc6813462017-01-13 17:10:38 -0800832 @Override
833 protected boolean isInteractive() {
834 return mInteractive;
835 }
836
Selim Cineka1d97902016-12-14 16:31:40 -0800837 public void setMaxShelfEnd(float maxShelfEnd) {
838 mMaxShelfEnd = maxShelfEnd;
839 }
840
Selim Cinek09bd29d2017-02-03 15:30:28 -0800841 public void setAnimationsEnabled(boolean enabled) {
842 mAnimationsEnabled = enabled;
843 mCollapsedIcons.setAnimationsEnabled(enabled);
844 if (!enabled) {
845 // we need to wait with enabling the animations until the first frame has passed
846 mShelfIcons.setAnimationsEnabled(false);
847 }
848 }
849
Selim Cinek9ef119c2017-03-01 15:13:36 -0800850 @Override
Adrian Roosd83e9992017-03-16 15:17:57 -0700851 public boolean hasOverlappingRendering() {
852 return false; // Shelf only uses alpha for transitions where the difference can't be seen.
853 }
854
855 @Override
Selim Cinekaca84c02017-04-05 16:28:56 -0700856 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
857 super.onInitializeAccessibilityNodeInfo(info);
858 if (mInteractive) {
859 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
860 AccessibilityNodeInfo.AccessibilityAction unlock
861 = new AccessibilityNodeInfo.AccessibilityAction(
862 AccessibilityNodeInfo.ACTION_CLICK,
863 getContext().getString(R.string.accessibility_overflow_action));
864 info.addAction(unlock);
865 }
866 }
867
868 @Override
Selim Cinek9ef119c2017-03-01 15:13:36 -0800869 public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
870 int oldTop, int oldRight, int oldBottom) {
871 updateRelativeOffset();
872 }
873
Selim Cinek281c2022016-10-13 19:14:43 -0700874 private class ShelfState extends ExpandableViewState {
Selim Cinek49014f82016-11-04 14:55:30 -0700875 private float openedAmount;
Selim Cinekeccb5de2016-10-28 15:04:05 -0700876 private boolean hasItemsInStableShelf;
Selim Cineka1d97902016-12-14 16:31:40 -0800877 private float maxShelfEnd;
Selim Cinek281c2022016-10-13 19:14:43 -0700878
879 @Override
880 public void applyToView(View view) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700881 if (!mShowNotificationShelf) {
882 return;
883 }
884
Selim Cinek281c2022016-10-13 19:14:43 -0700885 super.applyToView(view);
Selim Cineka1d97902016-12-14 16:31:40 -0800886 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700887 setOpenedAmount(openedAmount);
Selim Cineka1d97902016-12-14 16:31:40 -0800888 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700889 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800890 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek281c2022016-10-13 19:14:43 -0700891 }
Selim Cinek0cfbef42016-11-09 19:06:36 -0800892
893 @Override
894 public void animateTo(View child, AnimationProperties properties) {
Anthony Chen9e05d462017-04-07 10:10:21 -0700895 if (!mShowNotificationShelf) {
896 return;
897 }
898
Selim Cinek0cfbef42016-11-09 19:06:36 -0800899 super.animateTo(child, properties);
Selim Cineka1d97902016-12-14 16:31:40 -0800900 setMaxShelfEnd(maxShelfEnd);
Selim Cinek49014f82016-11-04 14:55:30 -0700901 setOpenedAmount(openedAmount);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800902 updateAppearance();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700903 setHasItemsInStableShelf(hasItemsInStableShelf);
Selim Cinek09bd29d2017-02-03 15:30:28 -0800904 mShelfIcons.setAnimationsEnabled(mAnimationsEnabled);
Selim Cinek0cfbef42016-11-09 19:06:36 -0800905 }
Selim Cinek281c2022016-10-13 19:14:43 -0700906 }
907}