Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 19 | import static com.android.systemui.Interpolators.FAST_OUT_SLOW_IN_REVERSE; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 20 | import static com.android.systemui.statusbar.phone.NotificationIconContainer.IconState.NO_VALUE; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 21 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.res.Configuration; |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 24 | import android.content.res.Resources; |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 25 | import android.graphics.Rect; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 26 | import android.os.SystemProperties; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
Selim Cinek | b7bafbc | 2017-12-21 11:33:26 -0800 | [diff] [blame] | 28 | import android.util.Log; |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 29 | import android.view.DisplayCutout; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 30 | import android.view.View; |
| 31 | import android.view.ViewGroup; |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 32 | import android.view.ViewTreeObserver; |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 33 | import android.view.WindowInsets; |
Selim Cinek | aca84c0 | 2017-04-05 16:28:56 -0700 | [diff] [blame] | 34 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 35 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 36 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 37 | import com.android.systemui.Dependency; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 38 | import com.android.systemui.Interpolators; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 39 | import com.android.systemui.R; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 40 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 41 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 42 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 43 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
| 44 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 45 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 46 | import com.android.systemui.statusbar.notification.stack.AmbientState; |
| 47 | import com.android.systemui.statusbar.notification.stack.AnimationProperties; |
| 48 | import com.android.systemui.statusbar.notification.stack.ExpandableViewState; |
| 49 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 50 | import com.android.systemui.statusbar.notification.stack.ViewState; |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 51 | import com.android.systemui.statusbar.phone.NotificationIconContainer; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 52 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 53 | /** |
| 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 Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 57 | public class NotificationShelf extends ActivatableNotificationView implements |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 58 | View.OnLayoutChangeListener, StateListener { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 59 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 60 | private static final boolean USE_ANIMATIONS_WHEN_OPENING = |
| 61 | SystemProperties.getBoolean("debug.icon_opening_animations", true); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 62 | private static final boolean ICON_ANMATIONS_WHILE_SCROLLING |
| 63 | = SystemProperties.getBoolean("debug.icon_scroll_animations", true); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 64 | private static final int TAG_CONTINUOUS_CLIPPING = R.id.continuous_clipping_tag; |
Selim Cinek | b7bafbc | 2017-12-21 11:33:26 -0800 | [diff] [blame] | 65 | private static final String TAG = "NotificationShelf"; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 66 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 67 | private NotificationIconContainer mShelfIcons; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 68 | private int[] mTmp = new int[2]; |
| 69 | private boolean mHideBackground; |
| 70 | private int mIconAppearTopPadding; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 71 | private float mHiddenShelfIconSize; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 72 | private int mStatusBarHeight; |
| 73 | private int mStatusBarPaddingStart; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 74 | private AmbientState mAmbientState; |
| 75 | private NotificationStackScrollLayout mHostLayout; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 76 | private int mMaxLayoutHeight; |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 77 | private int mPaddingBetweenElements; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 78 | private int mNotGoneIndex; |
| 79 | private boolean mHasItemsInStableShelf; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 80 | private NotificationIconContainer mCollapsedIcons; |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 81 | private int mScrollFastThreshold; |
Selim Cinek | b42698f | 2017-07-31 17:47:45 -0700 | [diff] [blame] | 82 | private int mIconSize; |
Selim Cinek | 810bcde | 2016-12-14 17:29:23 -0800 | [diff] [blame] | 83 | private int mStatusBarState; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 84 | private float mMaxShelfEnd; |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 85 | private int mRelativeOffset; |
Selim Cinek | c681346 | 2017-01-13 17:10:38 -0800 | [diff] [blame] | 86 | private boolean mInteractive; |
Selim Cinek | 2fce3c8 | 2017-05-08 12:38:09 -0700 | [diff] [blame] | 87 | private float mOpenedAmount; |
| 88 | private boolean mNoAnimationsInThisFrame; |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 89 | private boolean mAnimationsEnabled = true; |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 90 | private boolean mShowNotificationShelf; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 91 | private float mFirstElementRoundness; |
Selim Cinek | 143672c | 2018-03-23 20:04:32 -0700 | [diff] [blame] | 92 | private Rect mClipRect = new Rect(); |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 93 | private int mCutoutHeight; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 94 | private int mGapHeight; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 95 | |
| 96 | public NotificationShelf(Context context, AttributeSet attrs) { |
| 97 | super(context, attrs); |
| 98 | } |
| 99 | |
| 100 | @Override |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 101 | @VisibleForTesting |
| 102 | public void onFinishInflate() { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 103 | super.onFinishInflate(); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 104 | mShelfIcons = findViewById(R.id.content); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 105 | mShelfIcons.setClipChildren(false); |
| 106 | mShelfIcons.setClipToPadding(false); |
| 107 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 108 | setClipToActualHeight(false); |
| 109 | setClipChildren(false); |
| 110 | setClipToPadding(false); |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 111 | mShelfIcons.setIsStaticLayout(false); |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 112 | setBottomRoundness(1.0f, false /* animate */); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 113 | initDimens(); |
| 114 | } |
| 115 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 116 | @Override |
| 117 | protected void onAttachedToWindow() { |
| 118 | super.onAttachedToWindow(); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 119 | ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class)) |
| 120 | .addCallback(this, SysuiStatusBarStateController.RANK_SHELF); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
| 124 | protected void onDetachedFromWindow() { |
| 125 | super.onDetachedFromWindow(); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 126 | Dependency.get(StatusBarStateController.class).removeCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 129 | public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout) { |
| 130 | mAmbientState = ambientState; |
| 131 | mHostLayout = hostLayout; |
| 132 | } |
| 133 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 134 | private void initDimens() { |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 135 | Resources res = getResources(); |
| 136 | mIconAppearTopPadding = res.getDimensionPixelSize(R.dimen.notification_icon_appear_padding); |
| 137 | mStatusBarHeight = res.getDimensionPixelOffset(R.dimen.status_bar_height); |
| 138 | mStatusBarPaddingStart = res.getDimensionPixelOffset(R.dimen.status_bar_padding_start); |
| 139 | mPaddingBetweenElements = res.getDimensionPixelSize(R.dimen.notification_divider_height); |
| 140 | |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 141 | ViewGroup.LayoutParams layoutParams = getLayoutParams(); |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 142 | layoutParams.height = res.getDimensionPixelOffset(R.dimen.notification_shelf_height); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 143 | setLayoutParams(layoutParams); |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 144 | |
| 145 | int padding = res.getDimensionPixelOffset(R.dimen.shelf_icon_container_padding); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 146 | mShelfIcons.setPadding(padding, 0, padding, 0); |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 147 | mScrollFastThreshold = res.getDimensionPixelOffset(R.dimen.scroll_fast_threshold); |
| 148 | mShowNotificationShelf = res.getBoolean(R.bool.config_showNotificationShelf); |
Selim Cinek | b42698f | 2017-07-31 17:47:45 -0700 | [diff] [blame] | 149 | mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 150 | mHiddenShelfIconSize = res.getDimensionPixelOffset(R.dimen.hidden_shelf_icon_size); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 151 | mGapHeight = res.getDimensionPixelSize(R.dimen.qs_notification_padding); |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 152 | |
| 153 | if (!mShowNotificationShelf) { |
| 154 | setVisibility(GONE); |
| 155 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Override |
| 159 | protected void onConfigurationChanged(Configuration newConfig) { |
| 160 | super.onConfigurationChanged(newConfig); |
| 161 | initDimens(); |
| 162 | } |
| 163 | |
| 164 | @Override |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 165 | protected View getContentView() { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 166 | return mShelfIcons; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 169 | public NotificationIconContainer getShelfIcons() { |
| 170 | return mShelfIcons; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | @Override |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 174 | public ExpandableViewState createExpandableViewState() { |
| 175 | return new ShelfState(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 178 | /** Update the state of the shelf. */ |
| 179 | public void updateState(AmbientState ambientState) { |
| 180 | ExpandableView lastView = ambientState.getLastVisibleBackgroundChild(); |
| 181 | ShelfState viewState = (ShelfState) getViewState(); |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 182 | if (mShowNotificationShelf && lastView != null) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 183 | float maxShelfEnd = ambientState.getInnerHeight() + ambientState.getTopPadding() |
| 184 | + ambientState.getStackTranslation(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 185 | ExpandableViewState lastViewState = lastView.getViewState(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 186 | float viewEnd = lastViewState.yTranslation + lastViewState.height; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 187 | viewState.copyFrom(lastViewState); |
| 188 | viewState.height = getIntrinsicHeight(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 189 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 190 | viewState.yTranslation = Math.max(Math.min(viewEnd, maxShelfEnd) - viewState.height, |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 191 | getFullyClosedTranslation()); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 192 | viewState.zTranslation = ambientState.getBaseZHeight(); |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 193 | // For the small display size, it's not enough to make the icon not covered by |
| 194 | // the top cutout so the denominator add the height of cutout. |
| 195 | // Totally, (getIntrinsicHeight() * 2 + mCutoutHeight) should be smaller then |
| 196 | // mAmbientState.getTopPadding(). |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 197 | float openedAmount = (viewState.yTranslation - getFullyClosedTranslation()) |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 198 | / (getIntrinsicHeight() * 2 + mCutoutHeight); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 199 | openedAmount = Math.min(1.0f, openedAmount); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 200 | viewState.openedAmount = openedAmount; |
| 201 | viewState.clipTopAmount = 0; |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 202 | viewState.alpha = 1; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 203 | viewState.belowSpeedBump = mAmbientState.getSpeedBumpIndex() == 0; |
| 204 | viewState.hideSensitive = false; |
| 205 | viewState.xTranslation = getTranslationX(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 206 | if (mNotGoneIndex != -1) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 207 | viewState.notGoneIndex = Math.min(viewState.notGoneIndex, mNotGoneIndex); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 208 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 209 | viewState.hasItemsInStableShelf = lastViewState.inShelf; |
| 210 | viewState.hidden = !mAmbientState.isShadeExpanded() |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 211 | || mAmbientState.isQsCustomizerShowing(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 212 | viewState.maxShelfEnd = maxShelfEnd; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 213 | } else { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 214 | viewState.hidden = true; |
| 215 | viewState.location = ExpandableViewState.LOCATION_GONE; |
| 216 | viewState.hasItemsInStableShelf = false; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 220 | /** |
| 221 | * Update the shelf appearance based on the other notifications around it. This transforms |
| 222 | * the icons from the notification area into the shelf. |
| 223 | */ |
| 224 | public void updateAppearance() { |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 225 | // If the shelf should not be shown, then there is no need to update anything. |
| 226 | if (!mShowNotificationShelf) { |
| 227 | return; |
| 228 | } |
| 229 | |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 230 | mShelfIcons.resetViewStates(); |
| 231 | float shelfStart = getTranslationY(); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 232 | float numViewsInShelf = 0.0f; |
| 233 | View lastChild = mAmbientState.getLastVisibleBackgroundChild(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 234 | mNotGoneIndex = -1; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 235 | float interpolationStart = mMaxLayoutHeight - getIntrinsicHeight() * 2; |
| 236 | float expandAmount = 0.0f; |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 237 | if (shelfStart >= interpolationStart) { |
| 238 | expandAmount = (shelfStart - interpolationStart) / getIntrinsicHeight(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 239 | expandAmount = Math.min(1.0f, expandAmount); |
| 240 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 241 | // find the first view that doesn't overlap with the shelf |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 242 | int notGoneIndex = 0; |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 243 | int colorOfViewBeforeLast = NO_COLOR; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 244 | boolean backgroundForceHidden = false; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 245 | if (mHideBackground && !((ShelfState) getViewState()).hasItemsInStableShelf) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 246 | backgroundForceHidden = true; |
| 247 | } |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 248 | int colorTwoBefore = NO_COLOR; |
| 249 | int previousColor = NO_COLOR; |
| 250 | float transitionAmount = 0.0f; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 251 | float currentScrollVelocity = mAmbientState.getCurrentScrollVelocity(); |
| 252 | boolean scrollingFast = currentScrollVelocity > mScrollFastThreshold |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 253 | || (mAmbientState.isExpansionChanging() |
| 254 | && Math.abs(mAmbientState.getExpandingVelocity()) > mScrollFastThreshold); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 255 | boolean scrolling = currentScrollVelocity > 0; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 256 | boolean expandingAnimated = mAmbientState.isExpansionChanging() |
| 257 | && !mAmbientState.isPanelTracking(); |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 258 | int baseZHeight = mAmbientState.getBaseZHeight(); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 259 | int backgroundTop = 0; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 260 | int clipTopAmount = 0; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 261 | float firstElementRoundness = 0.0f; |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 262 | ActivatableNotificationView previousRow = null; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 263 | |
| 264 | for (int i = 0; i < mHostLayout.getChildCount(); i++) { |
| 265 | ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i); |
| 266 | |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 267 | if (!(child instanceof ActivatableNotificationView) |
| 268 | || child.getVisibility() == GONE || child == this) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 269 | continue; |
| 270 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 271 | |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 272 | ActivatableNotificationView row = (ActivatableNotificationView) child; |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 273 | float notificationClipEnd; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 274 | boolean aboveShelf = ViewState.getFinalTranslationZ(row) > baseZHeight |
| 275 | || row.isPinned(); |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 276 | boolean isLastChild = child == lastChild; |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 277 | float rowTranslationY = row.getTranslationY(); |
Selim Cinek | 3ff9fba | 2017-07-20 10:47:48 -0700 | [diff] [blame] | 278 | if ((isLastChild && !child.isInShelf()) || aboveShelf || backgroundForceHidden) { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 279 | notificationClipEnd = shelfStart + getIntrinsicHeight(); |
| 280 | } else { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 281 | notificationClipEnd = shelfStart - mPaddingBetweenElements; |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 282 | float height = notificationClipEnd - rowTranslationY; |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 283 | if (!row.isBelowSpeedBump() && height <= getNotificationMergeSize()) { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 284 | // We want the gap to close when we reached the minimum size and only shrink |
| 285 | // before |
| 286 | notificationClipEnd = Math.min(shelfStart, |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 287 | rowTranslationY + getNotificationMergeSize()); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 290 | int clipTop = updateNotificationClipHeight(row, notificationClipEnd, notGoneIndex); |
| 291 | clipTopAmount = Math.max(clipTop, clipTopAmount); |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 292 | |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 293 | // If the current row is an ExpandableNotificationRow, update its color, roundedness, |
| 294 | // and icon state. |
| 295 | if (row instanceof ExpandableNotificationRow) { |
| 296 | ExpandableNotificationRow expandableRow = (ExpandableNotificationRow) row; |
| 297 | |
| 298 | float inShelfAmount = updateIconAppearance(expandableRow, expandAmount, scrolling, |
| 299 | scrollingFast, |
| 300 | expandingAnimated, isLastChild); |
| 301 | numViewsInShelf += inShelfAmount; |
| 302 | int ownColorUntinted = row.getBackgroundColorWithoutTint(); |
| 303 | if (rowTranslationY >= shelfStart && mNotGoneIndex == -1) { |
| 304 | mNotGoneIndex = notGoneIndex; |
| 305 | setTintColor(previousColor); |
| 306 | setOverrideTintColor(colorTwoBefore, transitionAmount); |
| 307 | |
| 308 | } else if (mNotGoneIndex == -1) { |
| 309 | colorTwoBefore = previousColor; |
| 310 | transitionAmount = inShelfAmount; |
| 311 | } |
| 312 | if (isLastChild) { |
| 313 | if (colorOfViewBeforeLast == NO_COLOR) { |
| 314 | colorOfViewBeforeLast = ownColorUntinted; |
| 315 | } |
| 316 | row.setOverrideTintColor(colorOfViewBeforeLast, inShelfAmount); |
| 317 | } else { |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 318 | colorOfViewBeforeLast = ownColorUntinted; |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 319 | row.setOverrideTintColor(NO_COLOR, 0 /* overrideAmount */); |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 320 | } |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 321 | if (notGoneIndex != 0 || !aboveShelf) { |
| 322 | expandableRow.setAboveShelf(false); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 323 | } |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 324 | if (notGoneIndex == 0) { |
| 325 | StatusBarIconView icon = expandableRow.getEntry().expandedIcon; |
| 326 | NotificationIconContainer.IconState iconState = getIconState(icon); |
| 327 | // The icon state might be null in rare cases where the notification is actually |
| 328 | // added to the layout, but not to the shelf. An example are replied messages, |
| 329 | // since they don't show up on AOD |
| 330 | if (iconState != null && iconState.clampedAppearAmount == 1.0f) { |
| 331 | // only if the first icon is fully in the shelf we want to clip to it! |
| 332 | backgroundTop = (int) (row.getTranslationY() - getTranslationY()); |
| 333 | firstElementRoundness = row.getCurrentTopRoundness(); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | previousColor = ownColorUntinted; |
| 338 | notGoneIndex++; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 339 | } |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 340 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 341 | if (row.isFirstInSection() && previousRow != null && previousRow.isLastInSection()) { |
| 342 | // If the top of the shelf is between the view before a gap and the view after a gap |
| 343 | // then we need to adjust the shelf's top roundness. |
| 344 | float distanceToGapBottom = row.getTranslationY() - getTranslationY(); |
| 345 | float distanceToGapTop = getTranslationY() |
| 346 | - (previousRow.getTranslationY() + previousRow.getActualHeight()); |
| 347 | if (distanceToGapTop > 0) { |
| 348 | // We interpolate our top roundness so that it's fully rounded if we're at the |
| 349 | // bottom of the gap, and not rounded at all if we're at the top of the gap |
| 350 | // (directly up against the bottom of previousRow) |
| 351 | // Then we apply the same roundness to the bottom of previousRow so that the |
| 352 | // corners join together as the shelf approaches previousRow. |
| 353 | firstElementRoundness = (float) Math.min(1.0, distanceToGapTop / mGapHeight); |
| 354 | previousRow.setBottomRoundness(firstElementRoundness, |
| 355 | false /* don't animate */); |
| 356 | backgroundTop = (int) distanceToGapBottom; |
| 357 | } |
| 358 | } |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 359 | previousRow = row; |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 360 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 361 | clipTransientViews(); |
| 362 | |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 363 | setClipTopAmount(clipTopAmount); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 364 | setBackgroundTop(backgroundTop); |
| 365 | setFirstElementRoundness(firstElementRoundness); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 366 | mShelfIcons.setSpeedBumpIndex(mAmbientState.getSpeedBumpIndex()); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 367 | mShelfIcons.calculateIconTranslations(); |
| 368 | mShelfIcons.applyIconStates(); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 369 | for (int i = 0; i < mHostLayout.getChildCount(); i++) { |
| 370 | View child = mHostLayout.getChildAt(i); |
| 371 | if (!(child instanceof ExpandableNotificationRow) |
| 372 | || child.getVisibility() == GONE) { |
| 373 | continue; |
| 374 | } |
| 375 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 376 | updateIconClipAmount(row); |
| 377 | updateContinuousClipping(row); |
| 378 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 379 | boolean hideBackground = numViewsInShelf < 1.0f; |
| 380 | setHideBackground(hideBackground || backgroundForceHidden); |
| 381 | if (mNotGoneIndex == -1) { |
| 382 | mNotGoneIndex = notGoneIndex; |
| 383 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 386 | /** |
| 387 | * Clips transient views to the top of the shelf - Transient views are only used for |
| 388 | * disappearing views/animations and need to be clipped correctly by the shelf to ensure they |
| 389 | * don't show underneath the notification stack when something is animating and the user |
| 390 | * swipes quickly. |
| 391 | */ |
| 392 | private void clipTransientViews() { |
| 393 | for (int i = 0; i < mHostLayout.getTransientViewCount(); i++) { |
| 394 | View transientView = mHostLayout.getTransientView(i); |
| 395 | if (transientView instanceof ExpandableNotificationRow) { |
| 396 | ExpandableNotificationRow transientRow = (ExpandableNotificationRow) transientView; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 397 | updateNotificationClipHeight(transientRow, getTranslationY(), -1); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 398 | } else { |
| 399 | Log.e(TAG, "NotificationShelf.clipTransientViews(): " |
| 400 | + "Trying to clip non-row transient view"); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 405 | private void setFirstElementRoundness(float firstElementRoundness) { |
| 406 | if (mFirstElementRoundness != firstElementRoundness) { |
| 407 | mFirstElementRoundness = firstElementRoundness; |
| 408 | setTopRoundness(firstElementRoundness, false /* animate */); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 412 | private void updateIconClipAmount(ExpandableNotificationRow row) { |
| 413 | float maxTop = row.getTranslationY(); |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 414 | if (getClipTopAmount() != 0) { |
| 415 | // if the shelf is clipped, lets make sure we also clip the icon |
| 416 | maxTop = Math.max(maxTop, getTranslationY() + getClipTopAmount()); |
| 417 | } |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 418 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 419 | float shelfIconPosition = getTranslationY() + icon.getTop() + icon.getTranslationY(); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 420 | if (shelfIconPosition < maxTop && !mAmbientState.isFullyHidden()) { |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 421 | int top = (int) (maxTop - shelfIconPosition); |
| 422 | Rect clipRect = new Rect(0, top, icon.getWidth(), Math.max(top, icon.getHeight())); |
| 423 | icon.setClipBounds(clipRect); |
Gus Prevas | ab3ad1d | 2018-11-01 17:11:59 -0400 | [diff] [blame] | 424 | } else { |
| 425 | icon.setClipBounds(null); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | private void updateContinuousClipping(final ExpandableNotificationRow row) { |
| 430 | StatusBarIconView icon = row.getEntry().expandedIcon; |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 431 | boolean needsContinuousClipping = ViewState.isAnimatingY(icon) && !mAmbientState.isDozing(); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 432 | boolean isContinuousClipping = icon.getTag(TAG_CONTINUOUS_CLIPPING) != null; |
| 433 | if (needsContinuousClipping && !isContinuousClipping) { |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 434 | final ViewTreeObserver observer = icon.getViewTreeObserver(); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 435 | ViewTreeObserver.OnPreDrawListener predrawListener = |
| 436 | new ViewTreeObserver.OnPreDrawListener() { |
| 437 | @Override |
| 438 | public boolean onPreDraw() { |
| 439 | boolean animatingY = ViewState.isAnimatingY(icon); |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 440 | if (!animatingY) { |
Robert Snoeberger | ed77b45 | 2018-10-12 17:22:06 +0000 | [diff] [blame] | 441 | if (observer.isAlive()) { |
| 442 | observer.removeOnPreDrawListener(this); |
| 443 | } |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 444 | icon.setTag(TAG_CONTINUOUS_CLIPPING, null); |
| 445 | return true; |
| 446 | } |
| 447 | updateIconClipAmount(row); |
| 448 | return true; |
| 449 | } |
| 450 | }; |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 451 | observer.addOnPreDrawListener(predrawListener); |
| 452 | icon.addOnAttachStateChangeListener(new OnAttachStateChangeListener() { |
| 453 | @Override |
| 454 | public void onViewAttachedToWindow(View v) { |
| 455 | } |
| 456 | |
| 457 | @Override |
| 458 | public void onViewDetachedFromWindow(View v) { |
| 459 | if (v == icon) { |
Robert Snoeberger | ed77b45 | 2018-10-12 17:22:06 +0000 | [diff] [blame] | 460 | if (observer.isAlive()) { |
| 461 | observer.removeOnPreDrawListener(predrawListener); |
| 462 | } |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 463 | icon.setTag(TAG_CONTINUOUS_CLIPPING, null); |
| 464 | } |
| 465 | } |
| 466 | }); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 467 | icon.setTag(TAG_CONTINUOUS_CLIPPING, predrawListener); |
| 468 | } |
| 469 | } |
| 470 | |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 471 | /** |
| 472 | * Update the clipping of this view. |
| 473 | * @return the amount that our own top should be clipped |
| 474 | */ |
Aran Ink | c8d943e | 2019-05-30 15:44:12 -0400 | [diff] [blame] | 475 | private int updateNotificationClipHeight(ActivatableNotificationView row, |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 476 | float notificationClipEnd, int childIndex) { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 477 | float viewEnd = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 478 | boolean isPinned = (row.isPinned() || row.isHeadsUpAnimatingAway()) |
| 479 | && !mAmbientState.isDozingAndNotPulsing(row); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 480 | boolean shouldClipOwnTop; |
| 481 | if (mAmbientState.isPulseExpanding()) { |
| 482 | shouldClipOwnTop = childIndex == 0; |
| 483 | } else { |
| 484 | shouldClipOwnTop = row.showingPulsing(); |
| 485 | } |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 486 | if (viewEnd > notificationClipEnd && !shouldClipOwnTop |
Selim Cinek | 7e0f948 | 2017-05-22 20:00:56 -0700 | [diff] [blame] | 487 | && (mAmbientState.isShadeExpanded() || !isPinned)) { |
| 488 | int clipBottomAmount = (int) (viewEnd - notificationClipEnd); |
| 489 | if (isPinned) { |
| 490 | clipBottomAmount = Math.min(row.getIntrinsicHeight() - row.getCollapsedHeight(), |
| 491 | clipBottomAmount); |
| 492 | } |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 493 | row.setClipBottomAmount(clipBottomAmount); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 494 | } else { |
| 495 | row.setClipBottomAmount(0); |
| 496 | } |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 497 | if (shouldClipOwnTop) { |
| 498 | return (int) (viewEnd - getTranslationY()); |
| 499 | } else { |
| 500 | return 0; |
| 501 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 502 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 503 | |
Selim Cinek | c8c4cf9 | 2017-09-08 15:30:09 -0700 | [diff] [blame] | 504 | @Override |
| 505 | public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd, |
| 506 | int outlineTranslation) { |
| 507 | if (!mHasItemsInStableShelf) { |
| 508 | shadowIntensity = 0.0f; |
| 509 | } |
| 510 | super.setFakeShadowIntensity(shadowIntensity, outlineAlpha, shadowYEnd, outlineTranslation); |
| 511 | } |
| 512 | |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 513 | /** |
| 514 | * @return the icon amount how much this notification is in the shelf; |
| 515 | */ |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 516 | private float updateIconAppearance(ExpandableNotificationRow row, float expandAmount, |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 517 | boolean scrolling, boolean scrollingFast, boolean expandingAnimated, |
| 518 | boolean isLastChild) { |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 519 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 520 | NotificationIconContainer.IconState iconState = getIconState(icon); |
| 521 | if (iconState == null) { |
| 522 | return 0.0f; |
| 523 | } |
| 524 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 525 | // Let calculate how much the view is in the shelf |
| 526 | float viewStart = row.getTranslationY(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 527 | int fullHeight = row.getActualHeight() + mPaddingBetweenElements; |
| 528 | float iconTransformDistance = getIntrinsicHeight() * 1.5f; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 529 | iconTransformDistance *= NotificationUtils.interpolate(1.f, 1.5f, expandAmount); |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 530 | iconTransformDistance = Math.min(iconTransformDistance, fullHeight); |
Selim Cinek | 938bdaa | 2016-11-18 16:31:09 -0800 | [diff] [blame] | 531 | if (isLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 532 | fullHeight = Math.min(fullHeight, row.getMinHeight() - getIntrinsicHeight()); |
Bill Lin | e6065e3 | 2018-06-08 17:07:13 +0800 | [diff] [blame] | 533 | iconTransformDistance = Math.min(iconTransformDistance, row.getMinHeight() |
| 534 | - getIntrinsicHeight()); |
Selim Cinek | 938bdaa | 2016-11-18 16:31:09 -0800 | [diff] [blame] | 535 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 536 | float viewEnd = viewStart + fullHeight; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 537 | // TODO: fix this check for anchor scrolling. |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 538 | if (expandingAnimated && mAmbientState.getScrollY() == 0 |
| 539 | && !mAmbientState.isOnKeyguard() && !iconState.isLastExpandIcon) { |
| 540 | // We are expanding animated. Because we switch to a linear interpolation in this case, |
| 541 | // the last icon may be stuck in between the shelf position and the notification |
| 542 | // position, which looks pretty bad. We therefore optimize this case by applying a |
| 543 | // shorter transition such that the icon is either fully in the notification or we clamp |
| 544 | // it into the shelf if it's close enough. |
| 545 | // We need to persist this, since after the expansion, the behavior should still be the |
| 546 | // same. |
| 547 | float position = mAmbientState.getIntrinsicPadding() |
| 548 | + mHostLayout.getPositionInLinearLayout(row); |
| 549 | int maxShelfStart = mMaxLayoutHeight - getIntrinsicHeight(); |
| 550 | if (position < maxShelfStart && position + row.getIntrinsicHeight() >= maxShelfStart |
| 551 | && row.getTranslationY() < position) { |
| 552 | iconState.isLastExpandIcon = true; |
| 553 | iconState.customTransformHeight = NO_VALUE; |
| 554 | // Let's check if we're close enough to snap into the shelf |
| 555 | boolean forceInShelf = mMaxLayoutHeight - getIntrinsicHeight() - position |
| 556 | < getIntrinsicHeight(); |
| 557 | if (!forceInShelf) { |
| 558 | // We are overlapping the shelf but not enough, so the icon needs to be |
| 559 | // repositioned |
| 560 | iconState.customTransformHeight = (int) (mMaxLayoutHeight |
| 561 | - getIntrinsicHeight() - position); |
| 562 | } |
| 563 | } |
| 564 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 565 | float fullTransitionAmount; |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 566 | float iconTransitionAmount; |
| 567 | float shelfStart = getTranslationY(); |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 568 | if (iconState.hasCustomTransformHeight()) { |
| 569 | fullHeight = iconState.customTransformHeight; |
| 570 | iconTransformDistance = iconState.customTransformHeight; |
| 571 | } |
| 572 | boolean fullyInOrOut = true; |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 573 | if (viewEnd >= shelfStart && (!mAmbientState.isUnlockHintRunning() || row.isInShelf()) |
| 574 | && (mAmbientState.isShadeExpanded() |
| 575 | || (!row.isPinned() && !row.isHeadsUpAnimatingAway()))) { |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 576 | if (viewStart < shelfStart) { |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 577 | float fullAmount = (shelfStart - viewStart) / fullHeight; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 578 | fullAmount = Math.min(1.0f, fullAmount); |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 579 | float interpolatedAmount = Interpolators.ACCELERATE_DECELERATE.getInterpolation( |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 580 | fullAmount); |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 581 | interpolatedAmount = NotificationUtils.interpolate( |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 582 | interpolatedAmount, fullAmount, expandAmount); |
| 583 | fullTransitionAmount = 1.0f - interpolatedAmount; |
| 584 | |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 585 | iconTransitionAmount = (shelfStart - viewStart) / iconTransformDistance; |
| 586 | iconTransitionAmount = Math.min(1.0f, iconTransitionAmount); |
| 587 | iconTransitionAmount = 1.0f - iconTransitionAmount; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 588 | fullyInOrOut = false; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 589 | } else { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 590 | fullTransitionAmount = 1.0f; |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 591 | iconTransitionAmount = 1.0f; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 592 | } |
| 593 | } else { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 594 | fullTransitionAmount = 0.0f; |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 595 | iconTransitionAmount = 0.0f; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 596 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 597 | if (fullyInOrOut && !expandingAnimated && iconState.isLastExpandIcon) { |
| 598 | iconState.isLastExpandIcon = false; |
| 599 | iconState.customTransformHeight = NO_VALUE; |
| 600 | } |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 601 | updateIconPositioning(row, iconTransitionAmount, fullTransitionAmount, |
| 602 | iconTransformDistance, scrolling, scrollingFast, expandingAnimated, isLastChild); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 603 | return fullTransitionAmount; |
| 604 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 605 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 606 | private void updateIconPositioning(ExpandableNotificationRow row, float iconTransitionAmount, |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 607 | float fullTransitionAmount, float iconTransformDistance, boolean scrolling, |
| 608 | boolean scrollingFast, boolean expandingAnimated, boolean isLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 609 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 610 | NotificationIconContainer.IconState iconState = getIconState(icon); |
| 611 | if (iconState == null) { |
| 612 | return; |
| 613 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 614 | boolean forceInShelf = iconState.isLastExpandIcon && !iconState.hasCustomTransformHeight(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 615 | float clampedAmount = iconTransitionAmount > 0.5f ? 1.0f : 0.0f; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 616 | if (clampedAmount == fullTransitionAmount) { |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 617 | iconState.noAnimations = (scrollingFast || expandingAnimated) && !forceInShelf; |
Selim Cinek | 44d81a6 | 2017-05-08 19:45:40 -0700 | [diff] [blame] | 618 | iconState.useFullTransitionAmount = iconState.noAnimations |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 619 | || (!ICON_ANMATIONS_WHILE_SCROLLING && fullTransitionAmount == 0.0f && scrolling); |
| 620 | iconState.useLinearTransitionAmount = !ICON_ANMATIONS_WHILE_SCROLLING |
| 621 | && fullTransitionAmount == 0.0f && !mAmbientState.isExpansionChanging(); |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 622 | iconState.translateContent = mMaxLayoutHeight - getTranslationY() |
| 623 | - getIntrinsicHeight() > 0; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 624 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 625 | if (!forceInShelf && (scrollingFast || (expandingAnimated |
| 626 | && iconState.useFullTransitionAmount && !ViewState.isAnimatingY(icon)))) { |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 627 | iconState.cancelAnimations(icon); |
| 628 | iconState.useFullTransitionAmount = true; |
Selim Cinek | 44d81a6 | 2017-05-08 19:45:40 -0700 | [diff] [blame] | 629 | iconState.noAnimations = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 630 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 631 | if (iconState.hasCustomTransformHeight()) { |
| 632 | iconState.useFullTransitionAmount = true; |
| 633 | } |
| 634 | if (iconState.isLastExpandIcon) { |
| 635 | iconState.translateContent = false; |
| 636 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 637 | float transitionAmount; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 638 | if (mAmbientState.isHiddenAtAll() && !row.isInShelf()) { |
| 639 | transitionAmount = mAmbientState.isFullyHidden() ? 1 : 0; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 640 | } else if (isLastChild || !USE_ANIMATIONS_WHEN_OPENING || iconState.useFullTransitionAmount |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 641 | || iconState.useLinearTransitionAmount) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 642 | transitionAmount = iconTransitionAmount; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 643 | } else { |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 644 | // We take the clamped position instead |
| 645 | transitionAmount = clampedAmount; |
Selim Cinek | 2fce3c8 | 2017-05-08 12:38:09 -0700 | [diff] [blame] | 646 | iconState.needsCannedAnimation = iconState.clampedAppearAmount != clampedAmount |
| 647 | && !mNoAnimationsInThisFrame; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 648 | } |
| 649 | iconState.iconAppearAmount = !USE_ANIMATIONS_WHEN_OPENING |
| 650 | || iconState.useFullTransitionAmount |
| 651 | ? fullTransitionAmount |
| 652 | : transitionAmount; |
| 653 | iconState.clampedAppearAmount = clampedAmount; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 654 | float contentTransformationAmount = !row.isAboveShelf() && !row.showingPulsing() |
Selim Cinek | 7e0f948 | 2017-05-22 20:00:56 -0700 | [diff] [blame] | 655 | && (isLastChild || iconState.translateContent) |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 656 | ? iconTransitionAmount |
| 657 | : 0.0f; |
| 658 | row.setContentTransformationAmount(contentTransformationAmount, isLastChild); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 659 | setIconTransformationAmount(row, transitionAmount, iconTransformDistance, |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 660 | clampedAmount != transitionAmount, isLastChild); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | private void setIconTransformationAmount(ExpandableNotificationRow row, |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 664 | float transitionAmount, float iconTransformDistance, boolean usingLinearInterpolation, |
| 665 | boolean isLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 666 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 667 | NotificationIconContainer.IconState iconState = getIconState(icon); |
| 668 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 669 | View rowIcon = row.getNotificationIcon(); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 670 | float notificationIconPosition = row.getTranslationY() + row.getContentTranslation(); |
Selim Cinek | f20254c | 2017-02-03 10:09:33 -0800 | [diff] [blame] | 671 | boolean stayingInShelf = row.isInShelf() && !row.isTransformingIntoShelf(); |
| 672 | if (usingLinearInterpolation && !stayingInShelf) { |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 673 | // If we interpolate from the notification position, this might lead to a slightly |
| 674 | // odd interpolation, since the notification position changes as well. Let's interpolate |
| 675 | // from a fixed distance. We can only do this if we don't animate and the icon is |
| 676 | // always in the interpolated positon. |
Selim Cinek | f20254c | 2017-02-03 10:09:33 -0800 | [diff] [blame] | 677 | notificationIconPosition = getTranslationY() - iconTransformDistance; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 678 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 679 | float notificationIconSize = 0.0f; |
| 680 | int iconTopPadding; |
| 681 | if (rowIcon != null) { |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 682 | iconTopPadding = row.getRelativeTopPadding(rowIcon); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 683 | notificationIconSize = rowIcon.getHeight(); |
| 684 | } else { |
| 685 | iconTopPadding = mIconAppearTopPadding; |
| 686 | } |
| 687 | notificationIconPosition += iconTopPadding; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 688 | float shelfIconPosition = getTranslationY() + icon.getTop(); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 689 | float iconSize = mAmbientState.isFullyHidden() ? mHiddenShelfIconSize : mIconSize; |
Lucas Dupin | c104cd6 | 2019-05-13 14:22:30 -0700 | [diff] [blame] | 690 | shelfIconPosition += (icon.getHeight() - icon.getIconScale() * iconSize) / 2.0f; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 691 | float iconYTranslation = NotificationUtils.interpolate( |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 692 | notificationIconPosition - shelfIconPosition, |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 693 | 0, |
| 694 | transitionAmount); |
Lucas Dupin | c104cd6 | 2019-05-13 14:22:30 -0700 | [diff] [blame] | 695 | float shelfIconSize = iconSize * icon.getIconScale(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 696 | float alpha = 1.0f; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 697 | boolean noIcon = !row.isShowingIcon(); |
| 698 | if (noIcon) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 699 | // The view currently doesn't have an icon, lets transform it in! |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 700 | alpha = transitionAmount; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 701 | notificationIconSize = shelfIconSize / 2.0f; |
| 702 | } |
| 703 | // The notification size is different from the size in the shelf / statusbar |
| 704 | float newSize = NotificationUtils.interpolate(notificationIconSize, shelfIconSize, |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 705 | transitionAmount); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 706 | if (iconState != null) { |
Selim Cinek | b42698f | 2017-07-31 17:47:45 -0700 | [diff] [blame] | 707 | iconState.scaleX = newSize / shelfIconSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 708 | iconState.scaleY = iconState.scaleX; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 709 | iconState.hidden = transitionAmount == 0.0f && !iconState.isAnimating(icon); |
Selim Cinek | f38d6c3 | 2017-06-28 15:44:02 +0200 | [diff] [blame] | 710 | boolean isAppearing = row.isDrawingAppearAnimation() && !row.isInShelf(); |
| 711 | if (isAppearing) { |
| 712 | iconState.hidden = true; |
| 713 | iconState.iconAppearAmount = 0.0f; |
| 714 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 715 | iconState.alpha = alpha; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 716 | iconState.yTranslation = iconYTranslation; |
Selim Cinek | f20254c | 2017-02-03 10:09:33 -0800 | [diff] [blame] | 717 | if (stayingInShelf) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 718 | iconState.iconAppearAmount = 1.0f; |
| 719 | iconState.alpha = 1.0f; |
| 720 | iconState.scaleX = 1.0f; |
| 721 | iconState.scaleY = 1.0f; |
| 722 | iconState.hidden = false; |
| 723 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 724 | if (row.isAboveShelf() |
| 725 | || row.showingPulsing() |
| 726 | || (!row.isInShelf() && (isLastChild && row.areGutsExposed() |
Selim Cinek | 4737463 | 2017-03-17 16:07:17 -0700 | [diff] [blame] | 727 | || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) { |
Selim Cinek | 5ea1957 | 2016-11-29 15:34:48 -0800 | [diff] [blame] | 728 | iconState.hidden = true; |
| 729 | } |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 730 | int backgroundColor = getBackgroundColorWithoutTint(); |
| 731 | int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 732 | if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) { |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 733 | int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor(); |
| 734 | shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor, |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 735 | iconState.iconAppearAmount); |
| 736 | } |
| 737 | iconState.iconColor = shelfColor; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 738 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | private NotificationIconContainer.IconState getIconState(StatusBarIconView icon) { |
| 742 | return mShelfIcons.getIconState(icon); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | private float getFullyClosedTranslation() { |
| 746 | return - (getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 749 | public int getNotificationMergeSize() { |
| 750 | return getIntrinsicHeight(); |
| 751 | } |
| 752 | |
| 753 | @Override |
| 754 | public boolean hasNoContentHeight() { |
| 755 | return true; |
| 756 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 757 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 758 | private void setHideBackground(boolean hideBackground) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 759 | if (mHideBackground != hideBackground) { |
| 760 | mHideBackground = hideBackground; |
| 761 | updateBackground(); |
| 762 | updateOutline(); |
| 763 | } |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | @Override |
| 767 | protected boolean needsOutline() { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 768 | return !mHideBackground && super.needsOutline(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | @Override |
| 772 | protected boolean shouldHideBackground() { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 773 | return super.shouldHideBackground() || mHideBackground; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 776 | @Override |
| 777 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 778 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 779 | updateRelativeOffset(); |
Selim Cinek | 143672c | 2018-03-23 20:04:32 -0700 | [diff] [blame] | 780 | |
| 781 | // we always want to clip to our sides, such that nothing can draw outside of these bounds |
| 782 | int height = getResources().getDisplayMetrics().heightPixels; |
| 783 | mClipRect.set(0, -height, getWidth(), height); |
| 784 | mShelfIcons.setClipBounds(mClipRect); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | private void updateRelativeOffset() { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 788 | mCollapsedIcons.getLocationOnScreen(mTmp); |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 789 | mRelativeOffset = mTmp[0]; |
| 790 | getLocationOnScreen(mTmp); |
| 791 | mRelativeOffset -= mTmp[0]; |
| 792 | } |
| 793 | |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 794 | @Override |
| 795 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 796 | WindowInsets ret = super.onApplyWindowInsets(insets); |
| 797 | |
| 798 | // NotificationShelf drag from the status bar and the status bar dock on the top |
| 799 | // of the display for current design so just focus on the top of ScreenDecorations. |
| 800 | // In landscape or multiple window split mode, the NotificationShelf still drag from |
| 801 | // the top and the physical notch/cutout goes to the right, left, or both side of the |
| 802 | // display so it doesn't matter for the NotificationSelf in landscape. |
| 803 | DisplayCutout displayCutout = insets.getDisplayCutout(); |
| 804 | mCutoutHeight = displayCutout == null || displayCutout.getSafeInsetTop() < 0 |
| 805 | ? 0 : displayCutout.getSafeInsetTop(); |
| 806 | |
| 807 | return ret; |
| 808 | } |
| 809 | |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 810 | private void setOpenedAmount(float openedAmount) { |
Selim Cinek | 2fce3c8 | 2017-05-08 12:38:09 -0700 | [diff] [blame] | 811 | mNoAnimationsInThisFrame = openedAmount == 1.0f && mOpenedAmount == 0.0f; |
| 812 | mOpenedAmount = openedAmount; |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 813 | if (!mAmbientState.isPanelFullWidth() || mAmbientState.isDozing()) { |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 814 | // We don't do a transformation at all, lets just assume we are fully opened |
| 815 | openedAmount = 1.0f; |
| 816 | } |
| 817 | int start = mRelativeOffset; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 818 | if (isLayoutRtl()) { |
| 819 | start = getWidth() - start - mCollapsedIcons.getWidth(); |
| 820 | } |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 821 | int width = (int) NotificationUtils.interpolate( |
| 822 | start + mCollapsedIcons.getFinalTranslationX(), |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 823 | mShelfIcons.getWidth(), |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 824 | FAST_OUT_SLOW_IN_REVERSE.getInterpolation(openedAmount)); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 825 | mShelfIcons.setActualLayoutWidth(width); |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 826 | boolean hasOverflow = mCollapsedIcons.hasOverflow(); |
| 827 | int collapsedPadding = mCollapsedIcons.getPaddingEnd(); |
| 828 | if (!hasOverflow) { |
| 829 | // we have to ensure that adding the low priority notification won't lead to an |
| 830 | // overflow |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 831 | collapsedPadding -= mCollapsedIcons.getNoOverflowExtraPadding(); |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 832 | } else { |
| 833 | // Partial overflow padding will fill enough space to add extra dots |
| 834 | collapsedPadding -= mCollapsedIcons.getPartialOverflowExtraPadding(); |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 835 | } |
| 836 | float padding = NotificationUtils.interpolate(collapsedPadding, |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 837 | mShelfIcons.getPaddingEnd(), |
| 838 | openedAmount); |
| 839 | mShelfIcons.setActualPaddingEnd(padding); |
| 840 | float paddingStart = NotificationUtils.interpolate(start, |
| 841 | mShelfIcons.getPaddingStart(), openedAmount); |
| 842 | mShelfIcons.setActualPaddingStart(paddingStart); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 843 | mShelfIcons.setOpenedAmount(openedAmount); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 846 | public void setMaxLayoutHeight(int maxLayoutHeight) { |
| 847 | mMaxLayoutHeight = maxLayoutHeight; |
| 848 | } |
| 849 | |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 850 | /** |
| 851 | * @return the index of the notification at which the shelf visually resides |
| 852 | */ |
| 853 | public int getNotGoneIndex() { |
| 854 | return mNotGoneIndex; |
| 855 | } |
| 856 | |
| 857 | private void setHasItemsInStableShelf(boolean hasItemsInStableShelf) { |
Selim Cinek | 810bcde | 2016-12-14 17:29:23 -0800 | [diff] [blame] | 858 | if (mHasItemsInStableShelf != hasItemsInStableShelf) { |
| 859 | mHasItemsInStableShelf = hasItemsInStableShelf; |
| 860 | updateInteractiveness(); |
| 861 | } |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | /** |
| 865 | * @return whether the shelf has any icons in it when a potential animation has finished, i.e |
| 866 | * if the current state would be applied right now |
| 867 | */ |
| 868 | public boolean hasItemsInStableShelf() { |
| 869 | return mHasItemsInStableShelf; |
| 870 | } |
| 871 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 872 | public void setCollapsedIcons(NotificationIconContainer collapsedIcons) { |
| 873 | mCollapsedIcons = collapsedIcons; |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 874 | mCollapsedIcons.addOnLayoutChangeListener(this); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 877 | @Override |
| 878 | public void onStateChanged(int newState) { |
| 879 | mStatusBarState = newState; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 880 | updateInteractiveness(); |
Selim Cinek | 810bcde | 2016-12-14 17:29:23 -0800 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | private void updateInteractiveness() { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 884 | mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf; |
Selim Cinek | c681346 | 2017-01-13 17:10:38 -0800 | [diff] [blame] | 885 | setClickable(mInteractive); |
| 886 | setFocusable(mInteractive); |
| 887 | setImportantForAccessibility(mInteractive ? View.IMPORTANT_FOR_ACCESSIBILITY_YES |
Selim Cinek | aca84c0 | 2017-04-05 16:28:56 -0700 | [diff] [blame] | 888 | : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); |
Selim Cinek | 810bcde | 2016-12-14 17:29:23 -0800 | [diff] [blame] | 889 | } |
| 890 | |
Selim Cinek | c681346 | 2017-01-13 17:10:38 -0800 | [diff] [blame] | 891 | @Override |
| 892 | protected boolean isInteractive() { |
| 893 | return mInteractive; |
| 894 | } |
| 895 | |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 896 | public void setMaxShelfEnd(float maxShelfEnd) { |
| 897 | mMaxShelfEnd = maxShelfEnd; |
| 898 | } |
| 899 | |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 900 | public void setAnimationsEnabled(boolean enabled) { |
| 901 | mAnimationsEnabled = enabled; |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 902 | if (!enabled) { |
| 903 | // we need to wait with enabling the animations until the first frame has passed |
| 904 | mShelfIcons.setAnimationsEnabled(false); |
| 905 | } |
| 906 | } |
| 907 | |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 908 | @Override |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 909 | public boolean hasOverlappingRendering() { |
| 910 | return false; // Shelf only uses alpha for transitions where the difference can't be seen. |
| 911 | } |
| 912 | |
| 913 | @Override |
Selim Cinek | aca84c0 | 2017-04-05 16:28:56 -0700 | [diff] [blame] | 914 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 915 | super.onInitializeAccessibilityNodeInfo(info); |
| 916 | if (mInteractive) { |
| 917 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND); |
| 918 | AccessibilityNodeInfo.AccessibilityAction unlock |
| 919 | = new AccessibilityNodeInfo.AccessibilityAction( |
| 920 | AccessibilityNodeInfo.ACTION_CLICK, |
| 921 | getContext().getString(R.string.accessibility_overflow_action)); |
| 922 | info.addAction(unlock); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | @Override |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 927 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, |
| 928 | int oldTop, int oldRight, int oldBottom) { |
| 929 | updateRelativeOffset(); |
| 930 | } |
| 931 | |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 932 | public void onUiModeChanged() { |
| 933 | updateBackgroundColors(); |
| 934 | } |
| 935 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 936 | private class ShelfState extends ExpandableViewState { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 937 | private float openedAmount; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 938 | private boolean hasItemsInStableShelf; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 939 | private float maxShelfEnd; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 940 | |
| 941 | @Override |
| 942 | public void applyToView(View view) { |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 943 | if (!mShowNotificationShelf) { |
| 944 | return; |
| 945 | } |
| 946 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 947 | super.applyToView(view); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 948 | setMaxShelfEnd(maxShelfEnd); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 949 | setOpenedAmount(openedAmount); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 950 | updateAppearance(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 951 | setHasItemsInStableShelf(hasItemsInStableShelf); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 952 | mShelfIcons.setAnimationsEnabled(mAnimationsEnabled); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 953 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 954 | |
| 955 | @Override |
| 956 | public void animateTo(View child, AnimationProperties properties) { |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 957 | if (!mShowNotificationShelf) { |
| 958 | return; |
| 959 | } |
| 960 | |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 961 | super.animateTo(child, properties); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 962 | setMaxShelfEnd(maxShelfEnd); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 963 | setOpenedAmount(openedAmount); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 964 | updateAppearance(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 965 | setHasItemsInStableShelf(hasItemsInStableShelf); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 966 | mShelfIcons.setAnimationsEnabled(mAnimationsEnabled); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 967 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 968 | } |
| 969 | } |