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; |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 235 | viewState.alpha = 1; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 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; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 293 | int clipTopAmount = 0; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 294 | float firstElementRoundness = 0.0f; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 295 | ExpandableNotificationRow previousRow = null; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 296 | |
| 297 | for (int i = 0; i < mHostLayout.getChildCount(); i++) { |
| 298 | ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i); |
| 299 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 300 | if (!(child instanceof ExpandableNotificationRow) |
| 301 | || child.getVisibility() == GONE) { |
| 302 | continue; |
| 303 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 304 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 305 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 306 | float notificationClipEnd; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 307 | boolean aboveShelf = ViewState.getFinalTranslationZ(row) > baseZHeight |
| 308 | || row.isPinned(); |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 309 | boolean isLastChild = child == lastChild; |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 310 | float rowTranslationY = row.getTranslationY(); |
Selim Cinek | 3ff9fba | 2017-07-20 10:47:48 -0700 | [diff] [blame] | 311 | if ((isLastChild && !child.isInShelf()) || aboveShelf || backgroundForceHidden) { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 312 | notificationClipEnd = shelfStart + getIntrinsicHeight(); |
| 313 | } else { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 314 | notificationClipEnd = shelfStart - mPaddingBetweenElements; |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 315 | float height = notificationClipEnd - rowTranslationY; |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 316 | if (!row.isBelowSpeedBump() && height <= getNotificationMergeSize()) { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 317 | // We want the gap to close when we reached the minimum size and only shrink |
| 318 | // before |
| 319 | notificationClipEnd = Math.min(shelfStart, |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 320 | rowTranslationY + getNotificationMergeSize()); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 323 | int clipTop = updateNotificationClipHeight(row, notificationClipEnd, notGoneIndex); |
| 324 | clipTopAmount = Math.max(clipTop, clipTopAmount); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 325 | float inShelfAmount = updateIconAppearance(row, expandAmount, scrolling, scrollingFast, |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 326 | expandingAnimated, isLastChild); |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 327 | numViewsInShelf += inShelfAmount; |
| 328 | int ownColorUntinted = row.getBackgroundColorWithoutTint(); |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 329 | if (rowTranslationY >= shelfStart && mNotGoneIndex == -1) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 330 | mNotGoneIndex = notGoneIndex; |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 331 | setTintColor(previousColor); |
| 332 | setOverrideTintColor(colorTwoBefore, transitionAmount); |
| 333 | |
| 334 | } else if (mNotGoneIndex == -1) { |
| 335 | colorTwoBefore = previousColor; |
| 336 | transitionAmount = inShelfAmount; |
| 337 | } |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 338 | if (isLastChild) { |
| 339 | if (colorOfViewBeforeLast == NO_COLOR) { |
| 340 | colorOfViewBeforeLast = ownColorUntinted; |
| 341 | } |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 342 | row.setOverrideTintColor(colorOfViewBeforeLast, inShelfAmount); |
| 343 | } else { |
| 344 | colorOfViewBeforeLast = ownColorUntinted; |
| 345 | row.setOverrideTintColor(NO_COLOR, 0 /* overrideAmount */); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 346 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 347 | if (notGoneIndex != 0 || !aboveShelf) { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 348 | row.setAboveShelf(false); |
| 349 | } |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 350 | if (notGoneIndex == 0) { |
| 351 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 352 | NotificationIconContainer.IconState iconState = getIconState(icon); |
Selim Cinek | ec0c462 | 2019-02-13 12:33:20 -0800 | [diff] [blame] | 353 | // The icon state might be null in rare cases where the notification is actually |
| 354 | // added to the layout, but not to the shelf. An example are replied messages, since |
| 355 | // they don't show up on AOD |
Selim Cinek | b7bafbc | 2017-12-21 11:33:26 -0800 | [diff] [blame] | 356 | if (iconState != null && iconState.clampedAppearAmount == 1.0f) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 357 | // 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] | 358 | backgroundTop = (int) (row.getTranslationY() - getTranslationY()); |
| 359 | firstElementRoundness = row.getCurrentTopRoundness(); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 360 | } |
| 361 | } |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 362 | if (row.isFirstInSection() && previousRow != null && previousRow.isLastInSection()) { |
| 363 | // If the top of the shelf is between the view before a gap and the view after a gap |
| 364 | // then we need to adjust the shelf's top roundness. |
| 365 | float distanceToGapBottom = row.getTranslationY() - getTranslationY(); |
| 366 | float distanceToGapTop = getTranslationY() |
| 367 | - (previousRow.getTranslationY() + previousRow.getActualHeight()); |
| 368 | if (distanceToGapTop > 0) { |
| 369 | // We interpolate our top roundness so that it's fully rounded if we're at the |
| 370 | // bottom of the gap, and not rounded at all if we're at the top of the gap |
| 371 | // (directly up against the bottom of previousRow) |
| 372 | // Then we apply the same roundness to the bottom of previousRow so that the |
| 373 | // corners join together as the shelf approaches previousRow. |
| 374 | firstElementRoundness = (float) Math.min(1.0, distanceToGapTop / mGapHeight); |
| 375 | previousRow.setBottomRoundness(firstElementRoundness, |
| 376 | false /* don't animate */); |
| 377 | backgroundTop = (int) distanceToGapBottom; |
| 378 | } |
| 379 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 380 | notGoneIndex++; |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 381 | previousColor = ownColorUntinted; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 382 | previousRow = row; |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 383 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 384 | clipTransientViews(); |
| 385 | |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 386 | setClipTopAmount(clipTopAmount); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 387 | setBackgroundTop(backgroundTop); |
| 388 | setFirstElementRoundness(firstElementRoundness); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 389 | mShelfIcons.setSpeedBumpIndex(mAmbientState.getSpeedBumpIndex()); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 390 | mShelfIcons.calculateIconTranslations(); |
| 391 | mShelfIcons.applyIconStates(); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 392 | for (int i = 0; i < mHostLayout.getChildCount(); i++) { |
| 393 | View child = mHostLayout.getChildAt(i); |
| 394 | if (!(child instanceof ExpandableNotificationRow) |
| 395 | || child.getVisibility() == GONE) { |
| 396 | continue; |
| 397 | } |
| 398 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 399 | updateIconClipAmount(row); |
| 400 | updateContinuousClipping(row); |
| 401 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 402 | boolean hideBackground = numViewsInShelf < 1.0f; |
| 403 | setHideBackground(hideBackground || backgroundForceHidden); |
| 404 | if (mNotGoneIndex == -1) { |
| 405 | mNotGoneIndex = notGoneIndex; |
| 406 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 409 | /** |
| 410 | * Clips transient views to the top of the shelf - Transient views are only used for |
| 411 | * disappearing views/animations and need to be clipped correctly by the shelf to ensure they |
| 412 | * don't show underneath the notification stack when something is animating and the user |
| 413 | * swipes quickly. |
| 414 | */ |
| 415 | private void clipTransientViews() { |
| 416 | for (int i = 0; i < mHostLayout.getTransientViewCount(); i++) { |
| 417 | View transientView = mHostLayout.getTransientView(i); |
| 418 | if (transientView instanceof ExpandableNotificationRow) { |
| 419 | ExpandableNotificationRow transientRow = (ExpandableNotificationRow) transientView; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 420 | updateNotificationClipHeight(transientRow, getTranslationY(), -1); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 421 | } else { |
| 422 | Log.e(TAG, "NotificationShelf.clipTransientViews(): " |
| 423 | + "Trying to clip non-row transient view"); |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 428 | private void setFirstElementRoundness(float firstElementRoundness) { |
| 429 | if (mFirstElementRoundness != firstElementRoundness) { |
| 430 | mFirstElementRoundness = firstElementRoundness; |
| 431 | setTopRoundness(firstElementRoundness, false /* animate */); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 435 | private void updateIconClipAmount(ExpandableNotificationRow row) { |
| 436 | float maxTop = row.getTranslationY(); |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 437 | if (getClipTopAmount() != 0) { |
| 438 | // if the shelf is clipped, lets make sure we also clip the icon |
| 439 | maxTop = Math.max(maxTop, getTranslationY() + getClipTopAmount()); |
| 440 | } |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 441 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 442 | float shelfIconPosition = getTranslationY() + icon.getTop() + icon.getTranslationY(); |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 443 | if (shelfIconPosition < maxTop && !mAmbientState.isFullyDark()) { |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 444 | int top = (int) (maxTop - shelfIconPosition); |
| 445 | Rect clipRect = new Rect(0, top, icon.getWidth(), Math.max(top, icon.getHeight())); |
| 446 | icon.setClipBounds(clipRect); |
Gus Prevas | ab3ad1d | 2018-11-01 17:11:59 -0400 | [diff] [blame] | 447 | } else { |
| 448 | icon.setClipBounds(null); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
| 452 | private void updateContinuousClipping(final ExpandableNotificationRow row) { |
| 453 | StatusBarIconView icon = row.getEntry().expandedIcon; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 454 | boolean needsContinuousClipping = ViewState.isAnimatingY(icon) && !mAmbientState.isDark(); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 455 | boolean isContinuousClipping = icon.getTag(TAG_CONTINUOUS_CLIPPING) != null; |
| 456 | if (needsContinuousClipping && !isContinuousClipping) { |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 457 | final ViewTreeObserver observer = icon.getViewTreeObserver(); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 458 | ViewTreeObserver.OnPreDrawListener predrawListener = |
| 459 | new ViewTreeObserver.OnPreDrawListener() { |
| 460 | @Override |
| 461 | public boolean onPreDraw() { |
| 462 | boolean animatingY = ViewState.isAnimatingY(icon); |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 463 | if (!animatingY) { |
Robert Snoeberger | ed77b45 | 2018-10-12 17:22:06 +0000 | [diff] [blame] | 464 | if (observer.isAlive()) { |
| 465 | observer.removeOnPreDrawListener(this); |
| 466 | } |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 467 | icon.setTag(TAG_CONTINUOUS_CLIPPING, null); |
| 468 | return true; |
| 469 | } |
| 470 | updateIconClipAmount(row); |
| 471 | return true; |
| 472 | } |
| 473 | }; |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 474 | observer.addOnPreDrawListener(predrawListener); |
| 475 | icon.addOnAttachStateChangeListener(new OnAttachStateChangeListener() { |
| 476 | @Override |
| 477 | public void onViewAttachedToWindow(View v) { |
| 478 | } |
| 479 | |
| 480 | @Override |
| 481 | public void onViewDetachedFromWindow(View v) { |
| 482 | if (v == icon) { |
Robert Snoeberger | ed77b45 | 2018-10-12 17:22:06 +0000 | [diff] [blame] | 483 | if (observer.isAlive()) { |
| 484 | observer.removeOnPreDrawListener(predrawListener); |
| 485 | } |
Selim Cinek | 85845b8 | 2018-04-25 13:10:57 +0800 | [diff] [blame] | 486 | icon.setTag(TAG_CONTINUOUS_CLIPPING, null); |
| 487 | } |
| 488 | } |
| 489 | }); |
Selim Cinek | 6eaacf2 | 2017-09-07 18:53:17 -0700 | [diff] [blame] | 490 | icon.setTag(TAG_CONTINUOUS_CLIPPING, predrawListener); |
| 491 | } |
| 492 | } |
| 493 | |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 494 | /** |
| 495 | * Update the clipping of this view. |
| 496 | * @return the amount that our own top should be clipped |
| 497 | */ |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 498 | private int updateNotificationClipHeight(ExpandableNotificationRow row, |
| 499 | float notificationClipEnd, int childIndex) { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 500 | float viewEnd = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 501 | boolean isPinned = (row.isPinned() || row.isHeadsUpAnimatingAway()) |
| 502 | && !mAmbientState.isDozingAndNotPulsing(row); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 503 | boolean shouldClipOwnTop = row.showingAmbientPulsing() |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 504 | || (mAmbientState.isPulseExpanding() && childIndex == 0); |
| 505 | if (viewEnd > notificationClipEnd && !shouldClipOwnTop |
Selim Cinek | 7e0f948 | 2017-05-22 20:00:56 -0700 | [diff] [blame] | 506 | && (mAmbientState.isShadeExpanded() || !isPinned)) { |
| 507 | int clipBottomAmount = (int) (viewEnd - notificationClipEnd); |
| 508 | if (isPinned) { |
| 509 | clipBottomAmount = Math.min(row.getIntrinsicHeight() - row.getCollapsedHeight(), |
| 510 | clipBottomAmount); |
| 511 | } |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 512 | row.setClipBottomAmount(clipBottomAmount); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 513 | } else { |
| 514 | row.setClipBottomAmount(0); |
| 515 | } |
Selim Cinek | 4fc661e | 2019-02-19 17:42:36 -0800 | [diff] [blame] | 516 | if (shouldClipOwnTop) { |
| 517 | return (int) (viewEnd - getTranslationY()); |
| 518 | } else { |
| 519 | return 0; |
| 520 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 521 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 522 | |
Selim Cinek | c8c4cf9 | 2017-09-08 15:30:09 -0700 | [diff] [blame] | 523 | @Override |
| 524 | public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd, |
| 525 | int outlineTranslation) { |
| 526 | if (!mHasItemsInStableShelf) { |
| 527 | shadowIntensity = 0.0f; |
| 528 | } |
| 529 | super.setFakeShadowIntensity(shadowIntensity, outlineAlpha, shadowYEnd, outlineTranslation); |
| 530 | } |
| 531 | |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 532 | /** |
| 533 | * @return the icon amount how much this notification is in the shelf; |
| 534 | */ |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 535 | private float updateIconAppearance(ExpandableNotificationRow row, float expandAmount, |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 536 | boolean scrolling, boolean scrollingFast, boolean expandingAnimated, |
| 537 | boolean isLastChild) { |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 538 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 539 | NotificationIconContainer.IconState iconState = getIconState(icon); |
| 540 | if (iconState == null) { |
| 541 | return 0.0f; |
| 542 | } |
| 543 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 544 | // Let calculate how much the view is in the shelf |
| 545 | float viewStart = row.getTranslationY(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 546 | int fullHeight = row.getActualHeight() + mPaddingBetweenElements; |
| 547 | float iconTransformDistance = getIntrinsicHeight() * 1.5f; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 548 | iconTransformDistance *= NotificationUtils.interpolate(1.f, 1.5f, expandAmount); |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 549 | iconTransformDistance = Math.min(iconTransformDistance, fullHeight); |
Selim Cinek | 938bdaa | 2016-11-18 16:31:09 -0800 | [diff] [blame] | 550 | if (isLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 551 | fullHeight = Math.min(fullHeight, row.getMinHeight() - getIntrinsicHeight()); |
Bill Lin | e6065e3 | 2018-06-08 17:07:13 +0800 | [diff] [blame] | 552 | iconTransformDistance = Math.min(iconTransformDistance, row.getMinHeight() |
| 553 | - getIntrinsicHeight()); |
Selim Cinek | 938bdaa | 2016-11-18 16:31:09 -0800 | [diff] [blame] | 554 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 555 | float viewEnd = viewStart + fullHeight; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 556 | // TODO: fix this check for anchor scrolling. |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 557 | if (expandingAnimated && mAmbientState.getScrollY() == 0 |
| 558 | && !mAmbientState.isOnKeyguard() && !iconState.isLastExpandIcon) { |
| 559 | // We are expanding animated. Because we switch to a linear interpolation in this case, |
| 560 | // the last icon may be stuck in between the shelf position and the notification |
| 561 | // position, which looks pretty bad. We therefore optimize this case by applying a |
| 562 | // shorter transition such that the icon is either fully in the notification or we clamp |
| 563 | // it into the shelf if it's close enough. |
| 564 | // We need to persist this, since after the expansion, the behavior should still be the |
| 565 | // same. |
| 566 | float position = mAmbientState.getIntrinsicPadding() |
| 567 | + mHostLayout.getPositionInLinearLayout(row); |
| 568 | int maxShelfStart = mMaxLayoutHeight - getIntrinsicHeight(); |
| 569 | if (position < maxShelfStart && position + row.getIntrinsicHeight() >= maxShelfStart |
| 570 | && row.getTranslationY() < position) { |
| 571 | iconState.isLastExpandIcon = true; |
| 572 | iconState.customTransformHeight = NO_VALUE; |
| 573 | // Let's check if we're close enough to snap into the shelf |
| 574 | boolean forceInShelf = mMaxLayoutHeight - getIntrinsicHeight() - position |
| 575 | < getIntrinsicHeight(); |
| 576 | if (!forceInShelf) { |
| 577 | // We are overlapping the shelf but not enough, so the icon needs to be |
| 578 | // repositioned |
| 579 | iconState.customTransformHeight = (int) (mMaxLayoutHeight |
| 580 | - getIntrinsicHeight() - position); |
| 581 | } |
| 582 | } |
| 583 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 584 | float fullTransitionAmount; |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 585 | float iconTransitionAmount; |
| 586 | float shelfStart = getTranslationY(); |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 587 | if (iconState.hasCustomTransformHeight()) { |
| 588 | fullHeight = iconState.customTransformHeight; |
| 589 | iconTransformDistance = iconState.customTransformHeight; |
| 590 | } |
| 591 | boolean fullyInOrOut = true; |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 592 | if (viewEnd >= shelfStart && (!mAmbientState.isUnlockHintRunning() || row.isInShelf()) |
| 593 | && (mAmbientState.isShadeExpanded() |
| 594 | || (!row.isPinned() && !row.isHeadsUpAnimatingAway()))) { |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 595 | if (viewStart < shelfStart) { |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 596 | float fullAmount = (shelfStart - viewStart) / fullHeight; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 597 | fullAmount = Math.min(1.0f, fullAmount); |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 598 | float interpolatedAmount = Interpolators.ACCELERATE_DECELERATE.getInterpolation( |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 599 | fullAmount); |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 600 | interpolatedAmount = NotificationUtils.interpolate( |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 601 | interpolatedAmount, fullAmount, expandAmount); |
| 602 | fullTransitionAmount = 1.0f - interpolatedAmount; |
| 603 | |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 604 | iconTransitionAmount = (shelfStart - viewStart) / iconTransformDistance; |
| 605 | iconTransitionAmount = Math.min(1.0f, iconTransitionAmount); |
| 606 | iconTransitionAmount = 1.0f - iconTransitionAmount; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 607 | fullyInOrOut = false; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 608 | } else { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 609 | fullTransitionAmount = 1.0f; |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 610 | iconTransitionAmount = 1.0f; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 611 | } |
| 612 | } else { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 613 | fullTransitionAmount = 0.0f; |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 614 | iconTransitionAmount = 0.0f; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 615 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 616 | if (fullyInOrOut && !expandingAnimated && iconState.isLastExpandIcon) { |
| 617 | iconState.isLastExpandIcon = false; |
| 618 | iconState.customTransformHeight = NO_VALUE; |
| 619 | } |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 620 | updateIconPositioning(row, iconTransitionAmount, fullTransitionAmount, |
| 621 | iconTransformDistance, scrolling, scrollingFast, expandingAnimated, isLastChild); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 622 | return fullTransitionAmount; |
| 623 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 624 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 625 | private void updateIconPositioning(ExpandableNotificationRow row, float iconTransitionAmount, |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 626 | float fullTransitionAmount, float iconTransformDistance, boolean scrolling, |
| 627 | boolean scrollingFast, boolean expandingAnimated, boolean isLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 628 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 629 | NotificationIconContainer.IconState iconState = getIconState(icon); |
| 630 | if (iconState == null) { |
| 631 | return; |
| 632 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 633 | boolean forceInShelf = iconState.isLastExpandIcon && !iconState.hasCustomTransformHeight(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 634 | float clampedAmount = iconTransitionAmount > 0.5f ? 1.0f : 0.0f; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 635 | if (clampedAmount == fullTransitionAmount) { |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 636 | iconState.noAnimations = (scrollingFast || expandingAnimated) && !forceInShelf; |
Selim Cinek | 44d81a6 | 2017-05-08 19:45:40 -0700 | [diff] [blame] | 637 | iconState.useFullTransitionAmount = iconState.noAnimations |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 638 | || (!ICON_ANMATIONS_WHILE_SCROLLING && fullTransitionAmount == 0.0f && scrolling); |
| 639 | iconState.useLinearTransitionAmount = !ICON_ANMATIONS_WHILE_SCROLLING |
| 640 | && fullTransitionAmount == 0.0f && !mAmbientState.isExpansionChanging(); |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 641 | iconState.translateContent = mMaxLayoutHeight - getTranslationY() |
| 642 | - getIntrinsicHeight() > 0; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 643 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 644 | if (!forceInShelf && (scrollingFast || (expandingAnimated |
| 645 | && iconState.useFullTransitionAmount && !ViewState.isAnimatingY(icon)))) { |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 646 | iconState.cancelAnimations(icon); |
| 647 | iconState.useFullTransitionAmount = true; |
Selim Cinek | 44d81a6 | 2017-05-08 19:45:40 -0700 | [diff] [blame] | 648 | iconState.noAnimations = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 649 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 650 | if (iconState.hasCustomTransformHeight()) { |
| 651 | iconState.useFullTransitionAmount = true; |
| 652 | } |
| 653 | if (iconState.isLastExpandIcon) { |
| 654 | iconState.translateContent = false; |
| 655 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 656 | float transitionAmount; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 657 | if (mAmbientState.isDarkAtAll() && !row.isInShelf()) { |
| 658 | transitionAmount = mAmbientState.isFullyDark() ? 1 : 0; |
| 659 | } else if (isLastChild || !USE_ANIMATIONS_WHEN_OPENING || iconState.useFullTransitionAmount |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 660 | || iconState.useLinearTransitionAmount) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 661 | transitionAmount = iconTransitionAmount; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 662 | } else { |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 663 | // We take the clamped position instead |
| 664 | transitionAmount = clampedAmount; |
Selim Cinek | 2fce3c8 | 2017-05-08 12:38:09 -0700 | [diff] [blame] | 665 | iconState.needsCannedAnimation = iconState.clampedAppearAmount != clampedAmount |
| 666 | && !mNoAnimationsInThisFrame; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 667 | } |
| 668 | iconState.iconAppearAmount = !USE_ANIMATIONS_WHEN_OPENING |
| 669 | || iconState.useFullTransitionAmount |
| 670 | ? fullTransitionAmount |
| 671 | : transitionAmount; |
| 672 | iconState.clampedAppearAmount = clampedAmount; |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 673 | float contentTransformationAmount = !row.isAboveShelf() |
Selim Cinek | 7e0f948 | 2017-05-22 20:00:56 -0700 | [diff] [blame] | 674 | && (isLastChild || iconState.translateContent) |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 675 | ? iconTransitionAmount |
| 676 | : 0.0f; |
| 677 | row.setContentTransformationAmount(contentTransformationAmount, isLastChild); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 678 | setIconTransformationAmount(row, transitionAmount, iconTransformDistance, |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 679 | clampedAmount != transitionAmount, isLastChild); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | private void setIconTransformationAmount(ExpandableNotificationRow row, |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 683 | float transitionAmount, float iconTransformDistance, boolean usingLinearInterpolation, |
| 684 | boolean isLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 685 | StatusBarIconView icon = row.getEntry().expandedIcon; |
| 686 | NotificationIconContainer.IconState iconState = getIconState(icon); |
| 687 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 688 | View rowIcon = row.getNotificationIcon(); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 689 | float notificationIconPosition = row.getTranslationY() + row.getContentTranslation(); |
Selim Cinek | f20254c | 2017-02-03 10:09:33 -0800 | [diff] [blame] | 690 | boolean stayingInShelf = row.isInShelf() && !row.isTransformingIntoShelf(); |
| 691 | if (usingLinearInterpolation && !stayingInShelf) { |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 692 | // If we interpolate from the notification position, this might lead to a slightly |
| 693 | // odd interpolation, since the notification position changes as well. Let's interpolate |
| 694 | // from a fixed distance. We can only do this if we don't animate and the icon is |
| 695 | // always in the interpolated positon. |
Selim Cinek | f20254c | 2017-02-03 10:09:33 -0800 | [diff] [blame] | 696 | notificationIconPosition = getTranslationY() - iconTransformDistance; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 697 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 698 | float notificationIconSize = 0.0f; |
| 699 | int iconTopPadding; |
| 700 | if (rowIcon != null) { |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 701 | iconTopPadding = row.getRelativeTopPadding(rowIcon); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 702 | notificationIconSize = rowIcon.getHeight(); |
| 703 | } else { |
| 704 | iconTopPadding = mIconAppearTopPadding; |
| 705 | } |
| 706 | notificationIconPosition += iconTopPadding; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 707 | float shelfIconPosition = getTranslationY() + icon.getTop(); |
Selim Cinek | b42698f | 2017-07-31 17:47:45 -0700 | [diff] [blame] | 708 | shelfIconPosition += (icon.getHeight() - icon.getIconScale() * mIconSize) / 2.0f; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 709 | float iconYTranslation = NotificationUtils.interpolate( |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 710 | notificationIconPosition - shelfIconPosition, |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 711 | 0, |
| 712 | transitionAmount); |
Selim Cinek | b42698f | 2017-07-31 17:47:45 -0700 | [diff] [blame] | 713 | float shelfIconSize = mIconSize * icon.getIconScale(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 714 | float alpha = 1.0f; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 715 | boolean noIcon = !row.isShowingIcon(); |
| 716 | if (noIcon) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 717 | // The view currently doesn't have an icon, lets transform it in! |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 718 | alpha = transitionAmount; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 719 | notificationIconSize = shelfIconSize / 2.0f; |
| 720 | } |
| 721 | // The notification size is different from the size in the shelf / statusbar |
| 722 | float newSize = NotificationUtils.interpolate(notificationIconSize, shelfIconSize, |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 723 | transitionAmount); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 724 | if (iconState != null) { |
Selim Cinek | b42698f | 2017-07-31 17:47:45 -0700 | [diff] [blame] | 725 | iconState.scaleX = newSize / shelfIconSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 726 | iconState.scaleY = iconState.scaleX; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 727 | iconState.hidden = transitionAmount == 0.0f && !iconState.isAnimating(icon); |
Selim Cinek | f38d6c3 | 2017-06-28 15:44:02 +0200 | [diff] [blame] | 728 | boolean isAppearing = row.isDrawingAppearAnimation() && !row.isInShelf(); |
| 729 | if (isAppearing) { |
| 730 | iconState.hidden = true; |
| 731 | iconState.iconAppearAmount = 0.0f; |
| 732 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 733 | iconState.alpha = alpha; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 734 | iconState.yTranslation = iconYTranslation; |
Selim Cinek | f20254c | 2017-02-03 10:09:33 -0800 | [diff] [blame] | 735 | if (stayingInShelf) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 736 | iconState.iconAppearAmount = 1.0f; |
| 737 | iconState.alpha = 1.0f; |
| 738 | iconState.scaleX = 1.0f; |
| 739 | iconState.scaleY = 1.0f; |
| 740 | iconState.hidden = false; |
| 741 | } |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 742 | if (row.isAboveShelf() || (!row.isInShelf() && (isLastChild && row.areGutsExposed() |
Selim Cinek | 4737463 | 2017-03-17 16:07:17 -0700 | [diff] [blame] | 743 | || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) { |
Selim Cinek | 5ea1957 | 2016-11-29 15:34:48 -0800 | [diff] [blame] | 744 | iconState.hidden = true; |
| 745 | } |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 746 | int backgroundColor = getBackgroundColorWithoutTint(); |
| 747 | int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 748 | if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) { |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 749 | int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor(); |
| 750 | shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor, |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 751 | iconState.iconAppearAmount); |
| 752 | } |
| 753 | iconState.iconColor = shelfColor; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 754 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | private NotificationIconContainer.IconState getIconState(StatusBarIconView icon) { |
| 758 | return mShelfIcons.getIconState(icon); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | private float getFullyClosedTranslation() { |
| 762 | return - (getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 765 | public int getNotificationMergeSize() { |
| 766 | return getIntrinsicHeight(); |
| 767 | } |
| 768 | |
| 769 | @Override |
| 770 | public boolean hasNoContentHeight() { |
| 771 | return true; |
| 772 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 773 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 774 | private void setHideBackground(boolean hideBackground) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 775 | if (mHideBackground != hideBackground) { |
| 776 | mHideBackground = hideBackground; |
| 777 | updateBackground(); |
| 778 | updateOutline(); |
| 779 | } |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | @Override |
| 783 | protected boolean needsOutline() { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 784 | return !mHideBackground && !mDark && super.needsOutline(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Override |
| 788 | protected boolean shouldHideBackground() { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 789 | return super.shouldHideBackground() || mHideBackground || mDark; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 792 | @Override |
| 793 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 794 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 795 | updateRelativeOffset(); |
Selim Cinek | 143672c | 2018-03-23 20:04:32 -0700 | [diff] [blame] | 796 | |
| 797 | // we always want to clip to our sides, such that nothing can draw outside of these bounds |
| 798 | int height = getResources().getDisplayMetrics().heightPixels; |
| 799 | mClipRect.set(0, -height, getWidth(), height); |
| 800 | mShelfIcons.setClipBounds(mClipRect); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | private void updateRelativeOffset() { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 804 | mCollapsedIcons.getLocationOnScreen(mTmp); |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 805 | mRelativeOffset = mTmp[0]; |
| 806 | getLocationOnScreen(mTmp); |
| 807 | mRelativeOffset -= mTmp[0]; |
| 808 | } |
| 809 | |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 810 | @Override |
| 811 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 812 | WindowInsets ret = super.onApplyWindowInsets(insets); |
| 813 | |
| 814 | // NotificationShelf drag from the status bar and the status bar dock on the top |
| 815 | // of the display for current design so just focus on the top of ScreenDecorations. |
| 816 | // In landscape or multiple window split mode, the NotificationShelf still drag from |
| 817 | // the top and the physical notch/cutout goes to the right, left, or both side of the |
| 818 | // display so it doesn't matter for the NotificationSelf in landscape. |
| 819 | DisplayCutout displayCutout = insets.getDisplayCutout(); |
| 820 | mCutoutHeight = displayCutout == null || displayCutout.getSafeInsetTop() < 0 |
| 821 | ? 0 : displayCutout.getSafeInsetTop(); |
| 822 | |
| 823 | return ret; |
| 824 | } |
| 825 | |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 826 | private void setOpenedAmount(float openedAmount) { |
Selim Cinek | 2fce3c8 | 2017-05-08 12:38:09 -0700 | [diff] [blame] | 827 | mNoAnimationsInThisFrame = openedAmount == 1.0f && mOpenedAmount == 0.0f; |
| 828 | mOpenedAmount = openedAmount; |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 829 | if (!mAmbientState.isPanelFullWidth() || mAmbientState.isDark()) { |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 830 | // We don't do a transformation at all, lets just assume we are fully opened |
| 831 | openedAmount = 1.0f; |
| 832 | } |
| 833 | int start = mRelativeOffset; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 834 | if (isLayoutRtl()) { |
| 835 | start = getWidth() - start - mCollapsedIcons.getWidth(); |
| 836 | } |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 837 | int width = (int) NotificationUtils.interpolate( |
| 838 | start + mCollapsedIcons.getFinalTranslationX(), |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 839 | mShelfIcons.getWidth(), |
felkachang | c02c388 | 2018-07-27 15:32:31 +0800 | [diff] [blame] | 840 | FAST_OUT_SLOW_IN_REVERSE.getInterpolation(openedAmount)); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 841 | mShelfIcons.setActualLayoutWidth(width); |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 842 | boolean hasOverflow = mCollapsedIcons.hasOverflow(); |
| 843 | int collapsedPadding = mCollapsedIcons.getPaddingEnd(); |
| 844 | if (!hasOverflow) { |
| 845 | // we have to ensure that adding the low priority notification won't lead to an |
| 846 | // overflow |
Evan Laird | 8cf0de4 | 2018-02-06 18:34:55 -0500 | [diff] [blame] | 847 | collapsedPadding -= mCollapsedIcons.getNoOverflowExtraPadding(); |
Evan Laird | c987fc7 | 2017-12-15 10:14:22 -0500 | [diff] [blame] | 848 | } else { |
| 849 | // Partial overflow padding will fill enough space to add extra dots |
| 850 | collapsedPadding -= mCollapsedIcons.getPartialOverflowExtraPadding(); |
Selim Cinek | 932005d | 2016-12-05 17:12:09 -0800 | [diff] [blame] | 851 | } |
| 852 | float padding = NotificationUtils.interpolate(collapsedPadding, |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 853 | mShelfIcons.getPaddingEnd(), |
| 854 | openedAmount); |
| 855 | mShelfIcons.setActualPaddingEnd(padding); |
| 856 | float paddingStart = NotificationUtils.interpolate(start, |
| 857 | mShelfIcons.getPaddingStart(), openedAmount); |
| 858 | mShelfIcons.setActualPaddingStart(paddingStart); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 859 | mShelfIcons.setOpenedAmount(openedAmount); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 860 | } |
| 861 | |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 862 | public void setMaxLayoutHeight(int maxLayoutHeight) { |
| 863 | mMaxLayoutHeight = maxLayoutHeight; |
| 864 | } |
| 865 | |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 866 | /** |
| 867 | * @return the index of the notification at which the shelf visually resides |
| 868 | */ |
| 869 | public int getNotGoneIndex() { |
| 870 | return mNotGoneIndex; |
| 871 | } |
| 872 | |
| 873 | private void setHasItemsInStableShelf(boolean hasItemsInStableShelf) { |
Selim Cinek | 810bcde | 2016-12-14 17:29:23 -0800 | [diff] [blame] | 874 | if (mHasItemsInStableShelf != hasItemsInStableShelf) { |
| 875 | mHasItemsInStableShelf = hasItemsInStableShelf; |
| 876 | updateInteractiveness(); |
| 877 | } |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /** |
| 881 | * @return whether the shelf has any icons in it when a potential animation has finished, i.e |
| 882 | * if the current state would be applied right now |
| 883 | */ |
| 884 | public boolean hasItemsInStableShelf() { |
| 885 | return mHasItemsInStableShelf; |
| 886 | } |
| 887 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 888 | public void setCollapsedIcons(NotificationIconContainer collapsedIcons) { |
| 889 | mCollapsedIcons = collapsedIcons; |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 890 | mCollapsedIcons.addOnLayoutChangeListener(this); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 893 | @Override |
| 894 | public void onStateChanged(int newState) { |
| 895 | mStatusBarState = newState; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 896 | updateInteractiveness(); |
Selim Cinek | 810bcde | 2016-12-14 17:29:23 -0800 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | private void updateInteractiveness() { |
Adrian Roos | 03cf258 | 2017-03-28 17:54:05 -0700 | [diff] [blame] | 900 | mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf |
| 901 | && !mDark; |
Selim Cinek | c681346 | 2017-01-13 17:10:38 -0800 | [diff] [blame] | 902 | setClickable(mInteractive); |
| 903 | setFocusable(mInteractive); |
| 904 | setImportantForAccessibility(mInteractive ? View.IMPORTANT_FOR_ACCESSIBILITY_YES |
Selim Cinek | aca84c0 | 2017-04-05 16:28:56 -0700 | [diff] [blame] | 905 | : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); |
Selim Cinek | 810bcde | 2016-12-14 17:29:23 -0800 | [diff] [blame] | 906 | } |
| 907 | |
Selim Cinek | c681346 | 2017-01-13 17:10:38 -0800 | [diff] [blame] | 908 | @Override |
| 909 | protected boolean isInteractive() { |
| 910 | return mInteractive; |
| 911 | } |
| 912 | |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 913 | public void setMaxShelfEnd(float maxShelfEnd) { |
| 914 | mMaxShelfEnd = maxShelfEnd; |
| 915 | } |
| 916 | |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 917 | public void setAnimationsEnabled(boolean enabled) { |
| 918 | mAnimationsEnabled = enabled; |
| 919 | mCollapsedIcons.setAnimationsEnabled(enabled); |
| 920 | if (!enabled) { |
| 921 | // we need to wait with enabling the animations until the first frame has passed |
| 922 | mShelfIcons.setAnimationsEnabled(false); |
| 923 | } |
| 924 | } |
| 925 | |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 926 | @Override |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 927 | public boolean hasOverlappingRendering() { |
| 928 | return false; // Shelf only uses alpha for transitions where the difference can't be seen. |
| 929 | } |
| 930 | |
| 931 | @Override |
Selim Cinek | aca84c0 | 2017-04-05 16:28:56 -0700 | [diff] [blame] | 932 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 933 | super.onInitializeAccessibilityNodeInfo(info); |
| 934 | if (mInteractive) { |
| 935 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND); |
| 936 | AccessibilityNodeInfo.AccessibilityAction unlock |
| 937 | = new AccessibilityNodeInfo.AccessibilityAction( |
| 938 | AccessibilityNodeInfo.ACTION_CLICK, |
| 939 | getContext().getString(R.string.accessibility_overflow_action)); |
| 940 | info.addAction(unlock); |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | @Override |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 945 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, |
| 946 | int oldTop, int oldRight, int oldBottom) { |
| 947 | updateRelativeOffset(); |
| 948 | } |
| 949 | |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 950 | public void onUiModeChanged() { |
| 951 | updateBackgroundColors(); |
| 952 | } |
| 953 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 954 | private class ShelfState extends ExpandableViewState { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 955 | private float openedAmount; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 956 | private boolean hasItemsInStableShelf; |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 957 | private float maxShelfEnd; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 958 | |
| 959 | @Override |
| 960 | public void applyToView(View view) { |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 961 | if (!mShowNotificationShelf) { |
| 962 | return; |
| 963 | } |
| 964 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 965 | super.applyToView(view); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 966 | setMaxShelfEnd(maxShelfEnd); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 967 | setOpenedAmount(openedAmount); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 968 | updateAppearance(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 969 | setHasItemsInStableShelf(hasItemsInStableShelf); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 970 | mShelfIcons.setAnimationsEnabled(mAnimationsEnabled); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 971 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 972 | |
| 973 | @Override |
| 974 | public void animateTo(View child, AnimationProperties properties) { |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 975 | if (!mShowNotificationShelf) { |
| 976 | return; |
| 977 | } |
| 978 | |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 979 | super.animateTo(child, properties); |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 980 | setMaxShelfEnd(maxShelfEnd); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 981 | setOpenedAmount(openedAmount); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 982 | updateAppearance(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 983 | setHasItemsInStableShelf(hasItemsInStableShelf); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 984 | mShelfIcons.setAnimationsEnabled(mAnimationsEnabled); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 985 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 986 | } |
| 987 | } |