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