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