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