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