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