Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.stack; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 18 | |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 19 | import static android.service.notification.NotificationStats.DISMISSAL_SHADE; |
| 20 | import static android.service.notification.NotificationStats.DISMISS_SENTIMENT_NEUTRAL; |
| 21 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 22 | import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 24 | import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 25 | import static com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.ANCHOR_SCROLLING; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 26 | import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_SWIPE; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 27 | import static com.android.systemui.statusbar.phone.NotificationIconAreaController.HIGH_PRIORITY; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 28 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 29 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 30 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 31 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 32 | import android.animation.Animator; |
| 33 | import android.animation.AnimatorListenerAdapter; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 34 | import android.animation.TimeAnimator; |
| 35 | import android.animation.ValueAnimator; |
Steve Elliott | 577ef79 | 2020-04-02 13:49:36 -0400 | [diff] [blame] | 36 | import android.annotation.ColorInt; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 37 | import android.annotation.IntDef; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 38 | import android.annotation.NonNull; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 39 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 40 | import android.content.Context; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 41 | import android.content.Intent; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 42 | import android.content.res.Configuration; |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 43 | import android.content.res.Resources; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 44 | import android.graphics.Canvas; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 45 | import android.graphics.Color; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 46 | import android.graphics.Outline; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 47 | import android.graphics.Paint; |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 48 | import android.graphics.Point; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 49 | import android.graphics.PointF; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 50 | import android.graphics.PorterDuff; |
| 51 | import android.graphics.PorterDuffXfermode; |
| 52 | import android.graphics.Rect; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 53 | import android.os.Bundle; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 54 | import android.os.ServiceManager; |
Julia Reynolds | 1f94a9d | 2020-05-05 12:40:21 -0400 | [diff] [blame] | 55 | import android.os.UserHandle; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 56 | import android.provider.Settings; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 57 | import android.service.notification.NotificationListenerService; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 58 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 59 | import android.util.AttributeSet; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 60 | import android.util.DisplayMetrics; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 61 | import android.util.Log; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 62 | import android.util.MathUtils; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 63 | import android.util.Pair; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 64 | import android.view.ContextThemeWrapper; |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 65 | import android.view.DisplayCutout; |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 66 | import android.view.InputDevice; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 67 | import android.view.LayoutInflater; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 68 | import android.view.MotionEvent; |
| 69 | import android.view.VelocityTracker; |
| 70 | import android.view.View; |
| 71 | import android.view.ViewConfiguration; |
| 72 | import android.view.ViewGroup; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 73 | import android.view.ViewOutlineProvider; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 74 | import android.view.ViewTreeObserver; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 75 | import android.view.WindowInsets; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 76 | import android.view.accessibility.AccessibilityEvent; |
| 77 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 78 | import android.view.animation.AnimationUtils; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 79 | import android.view.animation.Interpolator; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 80 | import android.widget.OverScroller; |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 81 | import android.widget.ScrollView; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 82 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 83 | import com.android.internal.annotations.VisibleForTesting; |
| 84 | import com.android.internal.graphics.ColorUtils; |
Mady Mellor | a41587b | 2016-02-11 18:43:06 -0800 | [diff] [blame] | 85 | import com.android.internal.logging.MetricsLogger; |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 86 | import com.android.internal.logging.UiEvent; |
| 87 | import com.android.internal.logging.UiEventLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 88 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 89 | import com.android.internal.statusbar.IStatusBarService; |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 90 | import com.android.internal.statusbar.NotificationVisibility; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 91 | import com.android.keyguard.KeyguardSliceView; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 92 | import com.android.settingslib.Utils; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 93 | import com.android.systemui.Dependency; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 94 | import com.android.systemui.Dumpable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 95 | import com.android.systemui.ExpandHelper; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 96 | import com.android.systemui.Interpolators; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 97 | import com.android.systemui.R; |
| 98 | import com.android.systemui.SwipeHelper; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 99 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Dave Mankoff | 468d4f6 | 2019-05-08 14:56:29 -0400 | [diff] [blame] | 100 | import com.android.systemui.plugins.FalsingManager; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 101 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
| 102 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 103 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.OnMenuEventListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 104 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 105 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 106 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 107 | import com.android.systemui.statusbar.CommandQueue; |
| 108 | import com.android.systemui.statusbar.DragDownHelper.DragDownCallback; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 109 | import com.android.systemui.statusbar.EmptyShadeView; |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 110 | import com.android.systemui.statusbar.FeatureFlags; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 111 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 112 | import com.android.systemui.statusbar.NotificationLockscreenUserManager.UserChangedListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 113 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 114 | import com.android.systemui.statusbar.NotificationShelf; |
| 115 | import com.android.systemui.statusbar.RemoteInputController; |
| 116 | import com.android.systemui.statusbar.StatusBarState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 117 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 118 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 119 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 120 | import com.android.systemui.statusbar.notification.ForegroundServiceDismissalFeatureController; |
Julia Reynolds | 4368932 | 2020-04-28 18:48:54 -0400 | [diff] [blame] | 121 | import com.android.systemui.statusbar.notification.NotificationActivityStarter; |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 122 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 123 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 124 | import com.android.systemui.statusbar.notification.NotificationUtils; |
| 125 | import com.android.systemui.statusbar.notification.ShadeViewRefactor; |
| 126 | import com.android.systemui.statusbar.notification.ShadeViewRefactor.RefactorComponent; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 127 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 128 | import com.android.systemui.statusbar.notification.collection.NotifCollection; |
| 129 | import com.android.systemui.statusbar.notification.collection.NotifPipeline; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 130 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 131 | import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats; |
| 132 | import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 133 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 134 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 135 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 136 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 137 | import com.android.systemui.statusbar.notification.row.FooterView; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 138 | import com.android.systemui.statusbar.notification.row.ForegroundServiceDungeonView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 139 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 140 | import com.android.systemui.statusbar.notification.row.NotificationGuts; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 141 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 142 | import com.android.systemui.statusbar.notification.row.NotificationSnooze; |
| 143 | import com.android.systemui.statusbar.notification.row.StackScrollerDecorView; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 144 | import com.android.systemui.statusbar.phone.HeadsUpAppearanceController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 145 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 146 | import com.android.systemui.statusbar.phone.HeadsUpTouchHelper; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 147 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 148 | import com.android.systemui.statusbar.phone.LockscreenGestureLogger; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 149 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 150 | import com.android.systemui.statusbar.phone.NotificationGroupManager.OnGroupChangeListener; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 151 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 152 | import com.android.systemui.statusbar.phone.NotificationPanelViewController; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 153 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 154 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 155 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 156 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 157 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 158 | import com.android.systemui.statusbar.policy.HeadsUpUtil; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 159 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 160 | import com.android.systemui.statusbar.policy.ZenModeController; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 161 | import com.android.systemui.tuner.TunerService; |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 162 | import com.android.systemui.util.Assert; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 163 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 164 | import java.io.FileDescriptor; |
| 165 | import java.io.PrintWriter; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 166 | import java.lang.annotation.Retention; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 167 | import java.util.ArrayList; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 168 | import java.util.Collections; |
| 169 | import java.util.Comparator; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 170 | import java.util.HashSet; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 171 | import java.util.List; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 172 | import java.util.function.BiConsumer; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 173 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 174 | import javax.inject.Inject; |
| 175 | import javax.inject.Named; |
| 176 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 177 | /** |
| 178 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 179 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 180 | public class NotificationStackScrollLayout extends ViewGroup implements ScrollAdapter, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 181 | NotificationListContainer, ConfigurationListener, Dumpable, |
| 182 | DynamicPrivacyController.Listener { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 183 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 184 | public static final float BACKGROUND_ALPHA_DIMMED = 0.7f; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 185 | private static final String TAG = "StackScroller"; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 186 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 187 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 188 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 189 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 190 | /** |
| 191 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 192 | */ |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 193 | private static final int INVALID_POINTER = -1; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 194 | /** |
| 195 | * The distance in pixels between sections when the sections are directly adjacent (no visible |
| 196 | * gap is drawn between them). In this case we don't want to round their corners. |
| 197 | */ |
| 198 | private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 199 | private final KeyguardBypassController mKeyguardBypassController; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 200 | private final DynamicPrivacyController mDynamicPrivacyController; |
| 201 | private final SysuiStatusBarStateController mStatusbarStateController; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 202 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 203 | private ExpandHelper mExpandHelper; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 204 | private final NotificationSwipeHelper mSwipeHelper; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 205 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 206 | private final Paint mBackgroundPaint = new Paint(); |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 207 | private final boolean mShouldDrawNotificationBackground; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 208 | private boolean mHighPriorityBeforeSpeedBump; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 209 | private final boolean mAllowLongPress; |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 210 | private boolean mDismissRtl; |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 211 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 212 | private float mExpandedHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 213 | private int mOwnScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 214 | private View mScrollAnchorView; |
| 215 | private int mScrollAnchorViewY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 216 | private int mMaxLayoutHeight; |
| 217 | |
| 218 | private VelocityTracker mVelocityTracker; |
| 219 | private OverScroller mScroller; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 220 | /** Last Y position reported by {@link #mScroller}, used to calculate scroll delta. */ |
| 221 | private int mLastScrollerY; |
| 222 | /** |
| 223 | * True if the max position was set to a known position on the last call to {@link #mScroller}. |
| 224 | */ |
| 225 | private boolean mIsScrollerBoundSet; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 226 | private Runnable mFinishScrollingCallback; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 227 | private int mTouchSlop; |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 228 | private float mSlopMultiplier; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 229 | private int mMinimumVelocity; |
| 230 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 231 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 232 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 233 | private boolean mIsBeingDragged; |
| 234 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 235 | private int mDownX; |
Dong-wan Kim | b926666 | 2016-09-21 13:08:30 -0700 | [diff] [blame] | 236 | private int mActivePointerId = INVALID_POINTER; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 237 | private boolean mTouchIsClick; |
| 238 | private float mInitialTouchX; |
| 239 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 240 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 241 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 242 | private int mContentHeight; |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 243 | private int mIntrinsicContentHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 244 | private int mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 245 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 246 | private int mIncreasedPaddingBetweenElements; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 247 | private int mMaxTopPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 248 | private int mTopPadding; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 249 | private int mBottomMargin; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 250 | private int mBottomInset = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 251 | private float mQsExpansionFraction; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 252 | |
| 253 | /** |
| 254 | * The algorithm which calculates the properties for our children |
| 255 | */ |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 256 | protected final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 257 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 258 | private final AmbientState mAmbientState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 259 | private NotificationGroupManager mGroupManager; |
Julia Reynolds | 4368932 | 2020-04-28 18:48:54 -0400 | [diff] [blame] | 260 | private NotificationActivityStarter mNotificationActivityStarter; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 261 | private HashSet<ExpandableView> mChildrenToAddAnimated = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 262 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 263 | private ArrayList<ExpandableView> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 264 | private ArrayList<ExpandableView> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 265 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 266 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 267 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 268 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 269 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 270 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 271 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 272 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 273 | /** |
| 274 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 275 | */ |
| 276 | private float mOverScrolledTopPixels; |
| 277 | |
| 278 | /** |
| 279 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 280 | */ |
| 281 | private float mOverScrolledBottomPixels; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 282 | private NotificationLogger.OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 283 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 284 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 285 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 286 | private boolean mNeedsAnimation; |
| 287 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 288 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 289 | private boolean mHideSensitiveNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 290 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 291 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 292 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 293 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 294 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 295 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 296 | private boolean mExpandingNotification; |
| 297 | private boolean mExpandedInThisMotion; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 298 | private boolean mShouldShowShelfOnly; |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 299 | protected boolean mScrollingEnabled; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 300 | protected FooterView mFooterView; |
Muyuan Li | dd9ae75 | 2016-05-13 16:45:43 -0700 | [diff] [blame] | 301 | protected EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 302 | private boolean mDismissAllInProgress; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 303 | private boolean mFadeNotificationsOnDismiss; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * Was the scroller scrolled to the top when the down motion was observed? |
| 307 | */ |
| 308 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 309 | /** |
| 310 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 311 | * when over scrolling on a expanded card. |
| 312 | */ |
| 313 | private float mMinTopOverScrollToEscape; |
| 314 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 315 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 316 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 317 | private boolean mDontReportNextOverScroll; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 318 | private boolean mDontClampNextScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 319 | private boolean mNeedViewResizeAnimation; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 320 | private ExpandableView mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 321 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 322 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 323 | /** |
| 324 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 325 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 326 | * motion. |
| 327 | */ |
| 328 | private int mMaxScrollAfterExpand; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 329 | private ExpandableNotificationRow.LongPressListener mLongPressListener; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 330 | boolean mCheckForLeavebehind; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 331 | |
| 332 | /** |
| 333 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 334 | * animating. |
| 335 | */ |
| 336 | private boolean mOnlyScrollingInThisMotion; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 337 | private boolean mDisallowDismissInThisMotion; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 338 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 339 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 340 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 341 | = new ViewTreeObserver.OnPreDrawListener() { |
| 342 | @Override |
| 343 | public boolean onPreDraw() { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 344 | updateForcedScroll(); |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 345 | updateChildren(); |
| 346 | mChildrenUpdateRequested = false; |
| 347 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 348 | return true; |
| 349 | } |
| 350 | }; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 351 | private final UserChangedListener mLockscreenUserChangeListener = new UserChangedListener() { |
| 352 | @Override |
| 353 | public void onUserChanged(int userId) { |
| 354 | updateSensitiveness(false /* animated */); |
| 355 | } |
| 356 | }; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 357 | private StatusBar mStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 358 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 359 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 360 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 361 | private HashSet<ExpandableView> mClearTransientViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 362 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 363 | = new HashSet<>(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 364 | private HeadsUpManagerPhone mHeadsUpManager; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 365 | private final NotificationRoundnessManager mRoundnessManager; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 366 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 367 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 368 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 369 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 370 | private FalsingManager mFalsingManager; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 371 | private final ZenModeController mZenController; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 372 | private boolean mAnimationRunning; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 373 | private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 374 | = new ViewTreeObserver.OnPreDrawListener() { |
| 375 | @Override |
| 376 | public boolean onPreDraw() { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 377 | onPreDrawDuringAnimation(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 378 | return true; |
| 379 | } |
| 380 | }; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 381 | private NotificationSection[] mSections; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 382 | private boolean mAnimateNextBackgroundTop; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 383 | private boolean mAnimateNextBackgroundBottom; |
| 384 | private boolean mAnimateNextSectionBoundsChange; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 385 | private int mBgColor; |
| 386 | private float mDimAmount; |
| 387 | private ValueAnimator mDimAnimator; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 388 | private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 389 | private final Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 390 | @Override |
| 391 | public void onAnimationEnd(Animator animation) { |
| 392 | mDimAnimator = null; |
| 393 | } |
| 394 | }; |
| 395 | private ValueAnimator.AnimatorUpdateListener mDimUpdateListener |
| 396 | = new ValueAnimator.AnimatorUpdateListener() { |
| 397 | |
| 398 | @Override |
| 399 | public void onAnimationUpdate(ValueAnimator animation) { |
| 400 | setDimAmount((Float) animation.getAnimatedValue()); |
| 401 | } |
| 402 | }; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 403 | protected ViewGroup mQsContainer; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 404 | private boolean mContinuousShadowUpdate; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 405 | private boolean mContinuousBackgroundUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 406 | private ViewTreeObserver.OnPreDrawListener mShadowUpdater |
| 407 | = new ViewTreeObserver.OnPreDrawListener() { |
| 408 | |
| 409 | @Override |
| 410 | public boolean onPreDraw() { |
| 411 | updateViewShadows(); |
| 412 | return true; |
| 413 | } |
| 414 | }; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 415 | private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> { |
| 416 | updateBackground(); |
| 417 | return true; |
| 418 | }; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 419 | private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() { |
| 420 | @Override |
| 421 | public int compare(ExpandableView view, ExpandableView otherView) { |
| 422 | float endY = view.getTranslationY() + view.getActualHeight(); |
| 423 | float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); |
| 424 | if (endY < otherEndY) { |
| 425 | return -1; |
| 426 | } else if (endY > otherEndY) { |
| 427 | return 1; |
| 428 | } else { |
| 429 | // The two notifications end at the same location |
| 430 | return 0; |
| 431 | } |
| 432 | } |
| 433 | }; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 434 | private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() { |
| 435 | @Override |
| 436 | public void getOutline(View view, Outline outline) { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 437 | if (mAmbientState.isHiddenAtAll()) { |
| 438 | float xProgress = mHideXInterpolator.getInterpolation( |
| 439 | (1 - mLinearHideAmount) * mBackgroundXFactor); |
Selim Cinek | 9ad240c | 2019-04-08 19:07:15 -0700 | [diff] [blame] | 440 | outline.setRoundRect(mBackgroundAnimationRect, |
| 441 | MathUtils.lerp(mCornerRadius / 2.0f, mCornerRadius, |
| 442 | xProgress)); |
Selim Cinek | 33295a4 | 2019-07-26 19:49:08 -0700 | [diff] [blame] | 443 | outline.setAlpha(1.0f - mAmbientState.getHideAmount()); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 444 | } else { |
| 445 | ViewOutlineProvider.BACKGROUND.getOutline(view, outline); |
| 446 | } |
| 447 | } |
| 448 | }; |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 449 | private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 450 | private boolean mPulsing; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 451 | private boolean mGroupExpandedForMeasure; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 452 | private boolean mScrollable; |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 453 | private View mForcedScroll; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 454 | |
| 455 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 456 | * @see #setHideAmount(float, float) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 457 | */ |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 458 | private float mInterpolatedHideAmount = 0f; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 459 | |
| 460 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 461 | * @see #setHideAmount(float, float) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 462 | */ |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 463 | private float mLinearHideAmount = 0f; |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 464 | |
| 465 | /** |
| 466 | * How fast the background scales in the X direction as a factor of the Y expansion. |
| 467 | */ |
| 468 | private float mBackgroundXFactor = 1f; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 469 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 470 | private boolean mSwipingInProgress; |
| 471 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 472 | private boolean mUsingLightTheme; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 473 | private boolean mQsExpanded; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 474 | private boolean mForwardScrollable; |
| 475 | private boolean mBackwardScrollable; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 476 | private NotificationShelf mShelf; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 477 | private int mMaxDisplayedNotifications = -1; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 478 | private int mStatusBarHeight; |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 479 | private int mMinInteractionHeight; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 480 | private boolean mNoAmbient; |
| 481 | private final Rect mClipRect = new Rect(); |
| 482 | private boolean mIsClipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 483 | private Rect mRequestedClipBounds; |
| 484 | private boolean mInHeadsUpPinnedMode; |
| 485 | private boolean mHeadsUpAnimatingAway; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 486 | private int mStatusBarState; |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 487 | private int mCachedBackgroundColor; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 488 | private boolean mHeadsUpGoingAwayAnimationsAllowed = true; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 489 | private Runnable mReflingAndAnimateScroll = () -> { |
| 490 | if (ANCHOR_SCROLLING) { |
| 491 | maybeReflingScroller(); |
| 492 | } |
| 493 | animateScroll(); |
| 494 | }; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 495 | private int mCornerRadius; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 496 | private int mSidePaddings; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 497 | private final Rect mBackgroundAnimationRect = new Rect(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 498 | private ArrayList<BiConsumer<Float, Float>> mExpandedHeightListeners = new ArrayList<>(); |
| 499 | private int mHeadsUpInset; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 500 | private HeadsUpAppearanceController mHeadsUpAppearanceController; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 501 | private NotificationIconAreaController mIconAreaController; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 502 | private final NotificationLockscreenUserManager mLockscreenUserManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 503 | private final Rect mTmpRect = new Rect(); |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 504 | private final FeatureFlags mFeatureFlags; |
| 505 | private final NotifPipeline mNotifPipeline; |
| 506 | private final NotifCollection mNotifCollection; |
| 507 | private final NotificationEntryManager mEntryManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 508 | private final IStatusBarService mBarService = IStatusBarService.Stub.asInterface( |
| 509 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 510 | @VisibleForTesting |
| 511 | protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 512 | protected final UiEventLogger mUiEventLogger; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 513 | private final NotificationRemoteInputManager mRemoteInputManager = |
| 514 | Dependency.get(NotificationRemoteInputManager.class); |
| 515 | private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
| 516 | |
| 517 | private final DisplayMetrics mDisplayMetrics = Dependency.get(DisplayMetrics.class); |
| 518 | private final LockscreenGestureLogger mLockscreenGestureLogger = |
| 519 | Dependency.get(LockscreenGestureLogger.class); |
| 520 | private final VisualStabilityManager mVisualStabilityManager = |
| 521 | Dependency.get(VisualStabilityManager.class); |
| 522 | protected boolean mClearAllEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 523 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 524 | private Interpolator mHideXInterpolator = Interpolators.FAST_OUT_SLOW_IN; |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 525 | private NotificationPanelViewController mNotificationPanelController; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 526 | |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 527 | private final NotificationGutsManager mNotificationGutsManager; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 528 | private final NotificationSectionsManager mSectionsManager; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 529 | private final ForegroundServiceSectionController mFgsSectionController; |
| 530 | private ForegroundServiceDungeonView mFgsSectionView; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 531 | private boolean mAnimateBottomOnLayout; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 532 | private float mLastSentAppear; |
| 533 | private float mLastSentExpandedHeight; |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 534 | private boolean mWillExpand; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 535 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 536 | private int mWaterfallTopInset; |
| 537 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 538 | @Inject |
| 539 | public NotificationStackScrollLayout( |
| 540 | @Named(VIEW_CONTEXT) Context context, |
| 541 | AttributeSet attrs, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 542 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress, |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 543 | NotificationRoundnessManager notificationRoundnessManager, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 544 | DynamicPrivacyController dynamicPrivacyController, |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 545 | SysuiStatusBarStateController statusBarStateController, |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 546 | HeadsUpManagerPhone headsUpManager, |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 547 | KeyguardBypassController keyguardBypassController, |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 548 | FalsingManager falsingManager, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 549 | NotificationLockscreenUserManager notificationLockscreenUserManager, |
| 550 | NotificationGutsManager notificationGutsManager, |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 551 | ZenModeController zenController, |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 552 | NotificationSectionsManager notificationSectionsManager, |
| 553 | ForegroundServiceSectionController fgsSectionController, |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 554 | ForegroundServiceDismissalFeatureController fgsFeatureController, |
| 555 | FeatureFlags featureFlags, |
| 556 | NotifPipeline notifPipeline, |
| 557 | NotificationEntryManager entryManager, |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 558 | NotifCollection notifCollection, |
| 559 | UiEventLogger uiEventLogger |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 560 | ) { |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 561 | super(context, attrs, 0, 0); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 562 | Resources res = getResources(); |
| 563 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 564 | mAllowLongPress = allowLongPress; |
| 565 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 566 | mRoundnessManager = notificationRoundnessManager; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 567 | |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 568 | mLockscreenUserManager = notificationLockscreenUserManager; |
| 569 | mNotificationGutsManager = notificationGutsManager; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 570 | mHeadsUpManager = headsUpManager; |
| 571 | mHeadsUpManager.addListener(mRoundnessManager); |
| 572 | mHeadsUpManager.setAnimationStateHandler(this::setHeadsUpGoingAwayAnimationsAllowed); |
| 573 | mKeyguardBypassController = keyguardBypassController; |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 574 | mFalsingManager = falsingManager; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 575 | mZenController = zenController; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 576 | mFgsSectionController = fgsSectionController; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 577 | |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 578 | mSectionsManager = notificationSectionsManager; |
| 579 | mSectionsManager.initialize(this, LayoutInflater.from(context)); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 580 | mSectionsManager.setOnClearGentleNotifsClickListener(v -> { |
| 581 | // Leave the shade open if there will be other notifs left over to clear |
| 582 | final boolean closeShade = !hasActiveClearableNotifications(ROWS_HIGH_PRIORITY); |
| 583 | clearNotifications(ROWS_GENTLE, closeShade); |
| 584 | }); |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 585 | mSections = mSectionsManager.createSectionsForBuckets(); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 586 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 587 | mAmbientState = new AmbientState(context, mSectionsManager, mHeadsUpManager); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 588 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 589 | int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 590 | int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 591 | mExpandHelper = new ExpandHelper(getContext(), mExpandHelperCallback, |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 592 | minHeight, maxHeight); |
| 593 | mExpandHelper.setEventSource(this); |
| 594 | mExpandHelper.setScrollAdapter(this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 595 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, mNotificationCallback, |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 596 | getContext(), mMenuEventListener, mFalsingManager); |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 597 | mStackScrollAlgorithm = createStackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 598 | initView(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 599 | mShouldDrawNotificationBackground = |
| 600 | res.getBoolean(R.bool.config_drawNotificationBackground); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 601 | mFadeNotificationsOnDismiss = |
| 602 | res.getBoolean(R.bool.config_fadeNotificationsOnDismiss); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 603 | mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated); |
| 604 | mRoundnessManager.setOnRoundingChangedCallback(this::invalidate); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 605 | addOnExpandedHeightChangedListener(mRoundnessManager::setExpanded); |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 606 | mLockscreenUserManager.addUserChangedListener(mLockscreenUserChangeListener); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 607 | setOutlineProvider(mOutlineProvider); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 608 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 609 | // Blocking helper manager wants to know the expanded state, update as well. |
| 610 | NotificationBlockingHelperManager blockingHelperManager = |
| 611 | Dependency.get(NotificationBlockingHelperManager.class); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 612 | addOnExpandedHeightChangedListener((height, unused) -> { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 613 | blockingHelperManager.setNotificationShadeExpanded(height); |
| 614 | }); |
| 615 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 616 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
| 617 | setWillNotDraw(!willDraw); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 618 | mBackgroundPaint.setAntiAlias(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 619 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 620 | mDebugPaint = new Paint(); |
| 621 | mDebugPaint.setColor(0xffff0000); |
| 622 | mDebugPaint.setStrokeWidth(2); |
| 623 | mDebugPaint.setStyle(Paint.Style.STROKE); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 624 | mDebugPaint.setTextSize(25f); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 625 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 626 | mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 627 | |
| 628 | TunerService tunerService = Dependency.get(TunerService.class); |
| 629 | tunerService.addTunable((key, newValue) -> { |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 630 | if (key.equals(HIGH_PRIORITY)) { |
| 631 | mHighPriorityBeforeSpeedBump = "1".equals(newValue); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 632 | } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { |
| 633 | updateDismissRtlSetting("1".equals(newValue)); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 634 | } else if (key.equals(Settings.Secure.NOTIFICATION_HISTORY_ENABLED)) { |
| 635 | updateFooter(); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 636 | } |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 637 | }, HIGH_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL, |
| 638 | Settings.Secure.NOTIFICATION_HISTORY_ENABLED); |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 639 | |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 640 | mFeatureFlags = featureFlags; |
| 641 | mNotifPipeline = notifPipeline; |
| 642 | mEntryManager = entryManager; |
| 643 | mNotifCollection = notifCollection; |
| 644 | if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { |
| 645 | mNotifPipeline.addCollectionListener(new NotifCollectionListener() { |
| 646 | @Override |
| 647 | public void onEntryUpdated(NotificationEntry entry) { |
| 648 | NotificationStackScrollLayout.this.onEntryUpdated(entry); |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 649 | } |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 650 | }); |
| 651 | } else { |
| 652 | mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 653 | @Override |
| 654 | public void onPreEntryUpdated(NotificationEntry entry) { |
| 655 | NotificationStackScrollLayout.this.onEntryUpdated(entry); |
| 656 | } |
| 657 | }); |
| 658 | } |
| 659 | |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 660 | dynamicPrivacyController.addListener(this); |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 661 | mDynamicPrivacyController = dynamicPrivacyController; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 662 | mStatusbarStateController = statusBarStateController; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 663 | initializeForegroundServiceSection(fgsFeatureController); |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 664 | mUiEventLogger = uiEventLogger; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | private void initializeForegroundServiceSection( |
| 668 | ForegroundServiceDismissalFeatureController featureController) { |
| 669 | if (featureController.isForegroundServiceDismissalEnabled()) { |
| 670 | LayoutInflater li = LayoutInflater.from(mContext); |
| 671 | mFgsSectionView = |
| 672 | (ForegroundServiceDungeonView) mFgsSectionController.createView(li); |
| 673 | addView(mFgsSectionView, -1); |
| 674 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 675 | } |
| 676 | |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 677 | private void updateDismissRtlSetting(boolean dismissRtl) { |
| 678 | mDismissRtl = dismissRtl; |
| 679 | for (int i = 0; i < getChildCount(); i++) { |
| 680 | View child = getChildAt(i); |
| 681 | if (child instanceof ExpandableNotificationRow) { |
| 682 | ((ExpandableNotificationRow) child).setDismissRtl(dismissRtl); |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 687 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 688 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 689 | protected void onFinishInflate() { |
| 690 | super.onFinishInflate(); |
| 691 | |
| 692 | inflateEmptyShadeView(); |
| 693 | inflateFooterView(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 694 | mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 695 | if (mAllowLongPress) { |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 696 | setLongPressListener(mNotificationGutsManager::openGuts); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 697 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 698 | } |
| 699 | |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 700 | /** |
| 701 | * @return the height at which we will wake up when pulsing |
| 702 | */ |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 703 | public float getWakeUpHeight() { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 704 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 705 | if (firstChild != null) { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 706 | if (mKeyguardBypassController.getBypassEnabled()) { |
| 707 | return firstChild.getHeadsUpHeightWithoutHeader(); |
| 708 | } else { |
| 709 | return firstChild.getCollapsedHeight(); |
| 710 | } |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 711 | } |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 712 | return 0f; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 713 | } |
| 714 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 715 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 716 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 717 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 718 | reinflateViews(); |
| 719 | } |
| 720 | |
| 721 | private void reinflateViews() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 722 | inflateFooterView(); |
| 723 | inflateEmptyShadeView(); |
| 724 | updateFooter(); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 725 | mSectionsManager.reinflateViews(LayoutInflater.from(mContext)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 729 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 730 | public void onThemeChanged() { |
Lucas Dupin | 89233c4 | 2019-06-10 18:00:22 -0700 | [diff] [blame] | 731 | final boolean useDarkText = mColorExtractor.getNeutralColors().supportsDarkText(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 732 | updateDecorViews(useDarkText); |
| 733 | |
| 734 | updateFooter(); |
| 735 | } |
| 736 | |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 737 | @Override |
| 738 | public void onOverlayChanged() { |
| 739 | int newRadius = mContext.getResources().getDimensionPixelSize( |
| 740 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
| 741 | if (mCornerRadius != newRadius) { |
| 742 | mCornerRadius = newRadius; |
| 743 | invalidate(); |
| 744 | } |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 745 | reinflateViews(); |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 746 | } |
| 747 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 748 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 749 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 750 | public void updateFooter() { |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 751 | if (mFooterView == null) { |
| 752 | return; |
| 753 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 754 | boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL); |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 755 | boolean showFooterView = (showDismissView || hasActiveNotifications()) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 756 | && mStatusBarState != StatusBarState.KEYGUARD |
| 757 | && !mRemoteInputManager.getController().isRemoteInputActive(); |
Julia Reynolds | 1f94a9d | 2020-05-05 12:40:21 -0400 | [diff] [blame] | 758 | boolean showHistory = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 759 | Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, UserHandle.USER_CURRENT) == 1; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 760 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 761 | updateFooterView(showFooterView, showDismissView, showHistory); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Return whether there are any clearable notifications |
| 766 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 767 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 768 | public boolean hasActiveClearableNotifications(@SelectedRows int selection) { |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 769 | if (mDynamicPrivacyController.isInLockedDownShade()) { |
| 770 | return false; |
| 771 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 772 | int childCount = getChildCount(); |
| 773 | for (int i = 0; i < childCount; i++) { |
| 774 | View child = getChildAt(i); |
| 775 | if (!(child instanceof ExpandableNotificationRow)) { |
| 776 | continue; |
| 777 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 778 | final ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 779 | if (row.canViewBeDismissed() && matchesSelection(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 780 | return true; |
| 781 | } |
| 782 | } |
| 783 | return false; |
| 784 | } |
| 785 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 786 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 787 | public RemoteInputController.Delegate createDelegate() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 788 | return new RemoteInputController.Delegate() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 789 | public void setRemoteInputActive(NotificationEntry entry, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 790 | boolean remoteInputActive) { |
| 791 | mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 792 | entry.notifyHeightChanged(true /* needsAnimation */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 793 | updateFooter(); |
| 794 | } |
| 795 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 796 | public void lockScrollTo(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 797 | NotificationStackScrollLayout.this.lockScrollTo(entry.getRow()); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | public void requestDisallowLongPressAndDismiss() { |
| 801 | requestDisallowLongPress(); |
| 802 | requestDisallowDismiss(); |
| 803 | } |
| 804 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 805 | } |
| 806 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 807 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 808 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 809 | protected void onAttachedToWindow() { |
| 810 | super.onAttachedToWindow(); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 811 | ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class)) |
| 812 | .addCallback(mStateListener, SysuiStatusBarStateController.RANK_STACK_SCROLLER); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 813 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 817 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 818 | protected void onDetachedFromWindow() { |
| 819 | super.onDetachedFromWindow(); |
Jason Monk | af08c15 | 2018-12-04 11:12:39 -0500 | [diff] [blame] | 820 | Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 821 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | @Override |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 825 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 826 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 827 | return mSwipeHelper; |
| 828 | } |
| 829 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 830 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 831 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 832 | public void onUiModeChanged() { |
| 833 | mBgColor = mContext.getColor(R.color.notification_shade_background_color); |
| 834 | updateBackgroundDimming(); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 835 | mShelf.onUiModeChanged(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 838 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 839 | protected void onDraw(Canvas canvas) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 840 | if (mShouldDrawNotificationBackground |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 841 | && (mSections[0].getCurrentBounds().top |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 842 | < mSections[mSections.length - 1].getCurrentBounds().bottom |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 843 | || mAmbientState.isDozing())) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 844 | drawBackground(canvas); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 845 | } else if (mInHeadsUpPinnedMode || mHeadsUpAnimatingAway) { |
| 846 | drawHeadsUpBackground(canvas); |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 847 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 848 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 849 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 850 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 851 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 852 | y = getLayoutHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 853 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 854 | y = getHeight() - getEmptyBottomMargin(); |
| 855 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 859 | @Override |
| 860 | public void draw(Canvas canvas) { |
| 861 | super.draw(canvas); |
| 862 | |
| 863 | if (DEBUG && ANCHOR_SCROLLING) { |
| 864 | if (mScrollAnchorView instanceof ExpandableNotificationRow) { |
| 865 | canvas.drawRect(0, |
| 866 | mScrollAnchorView.getTranslationY(), |
| 867 | getWidth(), |
| 868 | mScrollAnchorView.getTranslationY() |
| 869 | + ((ExpandableNotificationRow) mScrollAnchorView).getActualHeight(), |
| 870 | mDebugPaint); |
| 871 | canvas.drawText(Integer.toString(mScrollAnchorViewY), getWidth() - 200, |
| 872 | mScrollAnchorView.getTranslationY() + 30, mDebugPaint); |
| 873 | int y = (int) mShelf.getTranslationY(); |
| 874 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 875 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 876 | canvas.drawText(Integer.toString(getMaxNegativeScrollAmount()), getWidth() - 100, |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 877 | getTopPadding() + 30, mDebugPaint); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 878 | canvas.drawText(Integer.toString(getMaxPositiveScrollAmount()), getWidth() - 100, |
| 879 | getHeight() - 30, mDebugPaint); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 883 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 884 | private void drawBackground(Canvas canvas) { |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 885 | int lockScreenLeft = mSidePaddings; |
| 886 | int lockScreenRight = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 887 | int lockScreenTop = mSections[0].getCurrentBounds().top; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 888 | int lockScreenBottom = mSections[mSections.length - 1].getCurrentBounds().bottom; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 889 | int hiddenLeft = getWidth() / 2; |
| 890 | int hiddenTop = mTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 891 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 892 | float yProgress = 1 - mInterpolatedHideAmount; |
| 893 | float xProgress = mHideXInterpolator.getInterpolation( |
| 894 | (1 - mLinearHideAmount) * mBackgroundXFactor); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 895 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 896 | int left = (int) MathUtils.lerp(hiddenLeft, lockScreenLeft, xProgress); |
| 897 | int right = (int) MathUtils.lerp(hiddenLeft, lockScreenRight, xProgress); |
| 898 | int top = (int) MathUtils.lerp(hiddenTop, lockScreenTop, yProgress); |
| 899 | int bottom = (int) MathUtils.lerp(hiddenTop, lockScreenBottom, yProgress); |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 900 | mBackgroundAnimationRect.set( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 901 | left, |
| 902 | top, |
| 903 | right, |
| 904 | bottom); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 905 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 906 | int backgroundTopAnimationOffset = top - lockScreenTop; |
| 907 | // TODO(kprevas): this may not be necessary any more since we don't display the shelf in AOD |
| 908 | boolean anySectionHasVisibleChild = false; |
| 909 | for (NotificationSection section : mSections) { |
| 910 | if (section.getFirstVisibleChild() != null) { |
| 911 | anySectionHasVisibleChild = true; |
| 912 | break; |
| 913 | } |
| 914 | } |
Selim Cinek | 5fedd81 | 2019-06-26 19:34:24 -0700 | [diff] [blame] | 915 | boolean shouldDrawBackground; |
| 916 | if (mKeyguardBypassController.getBypassEnabled() && onKeyguard()) { |
| 917 | shouldDrawBackground = isPulseExpanding(); |
| 918 | } else { |
| 919 | shouldDrawBackground = !mAmbientState.isDozing() || anySectionHasVisibleChild; |
| 920 | } |
| 921 | if (shouldDrawBackground) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 922 | drawBackgroundRects(canvas, left, right, top, backgroundTopAnimationOffset); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 923 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 924 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 925 | updateClipping(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 926 | } |
| 927 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 928 | /** |
| 929 | * Draws round rects for each background section. |
| 930 | * |
| 931 | * We want to draw a round rect for each background section as defined by {@link #mSections}. |
| 932 | * However, if two sections are directly adjacent with no gap between them (e.g. on the |
| 933 | * lockscreen where the shelf can appear directly below the high priority section, or while |
| 934 | * scrolling the shade so that the top of the shelf is right at the bottom of the high priority |
| 935 | * section), we don't want to round the adjacent corners. |
| 936 | * |
| 937 | * Since {@link Canvas} doesn't provide a way to draw a half-rounded rect, this means that we |
| 938 | * need to coalesce the backgrounds for adjacent sections and draw them as a single round rect. |
| 939 | * This method tracks the top of each rect we need to draw, then iterates through the visible |
| 940 | * sections. If a section is not adjacent to the previous section, we draw the previous rect |
| 941 | * behind the sections we've accumulated up to that point, then start a new rect at the top of |
| 942 | * the current section. When we're done iterating we will always have one rect left to draw. |
| 943 | */ |
| 944 | private void drawBackgroundRects(Canvas canvas, int left, int right, int top, |
| 945 | int animationYOffset) { |
| 946 | int backgroundRectTop = top; |
| 947 | int lastSectionBottom = |
| 948 | mSections[0].getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 949 | int currentLeft = left; |
| 950 | int currentRight = right; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 951 | boolean first = true; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 952 | for (NotificationSection section : mSections) { |
| 953 | if (section.getFirstVisibleChild() == null) { |
| 954 | continue; |
| 955 | } |
| 956 | int sectionTop = section.getCurrentBounds().top + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 957 | int ownLeft = Math.min(Math.max(left, section.getCurrentBounds().left), right); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 958 | int ownRight = Math.max(Math.min(right, section.getCurrentBounds().right), ownLeft); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 959 | // If sections are directly adjacent to each other, we don't want to draw them |
| 960 | // as separate roundrects, as the rounded corners right next to each other look |
| 961 | // bad. |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 962 | if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 963 | || ((currentLeft != ownLeft || currentRight != ownRight) && !first)) { |
| 964 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 965 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 966 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 967 | lastSectionBottom, |
| 968 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 969 | backgroundRectTop = sectionTop; |
| 970 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 971 | currentLeft = ownLeft; |
| 972 | currentRight = ownRight; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 973 | lastSectionBottom = |
| 974 | section.getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 975 | first = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 976 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 977 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 978 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 979 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 980 | lastSectionBottom, |
| 981 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 982 | } |
| 983 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 984 | private void drawHeadsUpBackground(Canvas canvas) { |
| 985 | int left = mSidePaddings; |
| 986 | int right = getWidth() - mSidePaddings; |
| 987 | |
| 988 | float top = getHeight(); |
| 989 | float bottom = 0; |
| 990 | int childCount = getChildCount(); |
| 991 | for (int i = 0; i < childCount; i++) { |
| 992 | View child = getChildAt(i); |
| 993 | if (child.getVisibility() != View.GONE |
| 994 | && child instanceof ExpandableNotificationRow) { |
| 995 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 996 | if ((row.isPinned() || row.isHeadsUpAnimatingAway()) && row.getTranslation() < 0 |
| 997 | && row.getProvider().shouldShowGutsOnSnapOpen()) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 998 | top = Math.min(top, row.getTranslationY()); |
| 999 | bottom = Math.max(bottom, row.getTranslationY() + row.getActualHeight()); |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | if (top < bottom) { |
| 1005 | canvas.drawRoundRect( |
| 1006 | left, top, right, bottom, |
| 1007 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 1008 | } |
| 1009 | } |
| 1010 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1011 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 1012 | private void updateBackgroundDimming() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 1013 | // No need to update the background color if it's not being drawn. |
| 1014 | if (!mShouldDrawNotificationBackground) { |
| 1015 | return; |
| 1016 | } |
| 1017 | |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 1018 | // Interpolate between semi-transparent notification panel background color |
| 1019 | // and white AOD separator. |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 1020 | float colorInterpolation = MathUtils.smoothStep(0.4f /* start */, 1f /* end */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 1021 | mLinearHideAmount); |
Felka Chang | 97bc8d5 | 2019-05-29 02:51:15 +0800 | [diff] [blame] | 1022 | int color = ColorUtils.blendARGB(mBgColor, Color.WHITE, colorInterpolation); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 1023 | |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 1024 | if (mCachedBackgroundColor != color) { |
| 1025 | mCachedBackgroundColor = color; |
| 1026 | mBackgroundPaint.setColor(color); |
| 1027 | invalidate(); |
| 1028 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1031 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1032 | private void initView(Context context) { |
| 1033 | mScroller = new OverScroller(getContext()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1034 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1035 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1036 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 1037 | mTouchSlop = configuration.getScaledTouchSlop(); |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 1038 | mSlopMultiplier = configuration.getScaledAmbiguousGestureMultiplier(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1039 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 1040 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1041 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 1042 | |
| 1043 | Resources res = context.getResources(); |
| 1044 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 1045 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 1046 | mAmbientState.reload(context); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 1047 | mPaddingBetweenElements = Math.max(1, |
| 1048 | res.getDimensionPixelSize(R.dimen.notification_divider_height)); |
| 1049 | mIncreasedPaddingBetweenElements = |
| 1050 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 1051 | mMinTopOverScrollToEscape = res.getDimensionPixelSize( |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1052 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1053 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 1054 | mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 1055 | mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1056 | mMinInteractionHeight = res.getDimensionPixelSize( |
| 1057 | R.dimen.notification_min_interaction_height); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 1058 | mCornerRadius = res.getDimensionPixelSize( |
| 1059 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1060 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 1061 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1064 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1065 | private void notifyHeightChangeListener(ExpandableView view) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1066 | notifyHeightChangeListener(view, false /* needsAnimation */); |
| 1067 | } |
| 1068 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1069 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1070 | private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) { |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1071 | if (mOnHeightChangedListener != null) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1072 | mOnHeightChangedListener.onHeightChanged(view, needsAnimation); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1073 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 1076 | public boolean isPulseExpanding() { |
| 1077 | return mAmbientState.isPulseExpanding(); |
| 1078 | } |
| 1079 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1080 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1081 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1082 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1083 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 1084 | |
| 1085 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 1086 | int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2, |
| 1087 | MeasureSpec.getMode(widthMeasureSpec)); |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1088 | // Don't constrain the height of the children so we know how big they'd like to be |
| 1089 | int childHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), |
| 1090 | MeasureSpec.UNSPECIFIED); |
| 1091 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1092 | // We need to measure all children even the GONE ones, such that the heights are calculated |
| 1093 | // correctly as they are used to calculate how many we can fit on the screen. |
| 1094 | final int size = getChildCount(); |
| 1095 | for (int i = 0; i < size; i++) { |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1096 | measureChild(getChildAt(i), childWidthSpec, childHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1097 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1101 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1102 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1103 | // we layout all our children centered on the top |
| 1104 | float centerX = getWidth() / 2.0f; |
| 1105 | for (int i = 0; i < getChildCount(); i++) { |
| 1106 | View child = getChildAt(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1107 | // We need to layout all children even the GONE ones, such that the heights are |
| 1108 | // calculated correctly as they are used to calculate how many we can fit on the screen |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1109 | float width = child.getMeasuredWidth(); |
| 1110 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1111 | child.layout((int) (centerX - width / 2.0f), |
| 1112 | 0, |
| 1113 | (int) (centerX + width / 2.0f), |
| 1114 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1115 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 1116 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1117 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1118 | clampScrollPosition(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1119 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1120 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1121 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | 33295a4 | 2019-07-26 19:49:08 -0700 | [diff] [blame] | 1122 | updateOwnTranslationZ(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1125 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1126 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 1127 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1128 | mNeedViewResizeAnimation = true; |
| 1129 | mNeedsAnimation = true; |
| 1130 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1133 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1134 | public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) { |
| 1135 | mAmbientState.setSpeedBumpIndex(newIndex); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1136 | mNoAmbient = noAmbient; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1139 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1140 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1141 | public void setChildLocationsChangedListener( |
| 1142 | NotificationLogger.OnChildLocationsChangedListener listener) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1143 | mListener = listener; |
| 1144 | } |
| 1145 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1146 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1147 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1148 | public boolean isInVisibleLocation(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1149 | ExpandableNotificationRow row = entry.getRow(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1150 | ExpandableViewState childViewState = row.getViewState(); |
| 1151 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1152 | if (childViewState == null) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1153 | return false; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1154 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 1155 | if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1156 | return false; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 1157 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1158 | if (row.getVisibility() != View.VISIBLE) { |
| 1159 | return false; |
| 1160 | } |
| 1161 | return true; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1164 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1165 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 1166 | mMaxLayoutHeight = maxLayoutHeight; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 1167 | mShelf.setMaxLayoutHeight(maxLayoutHeight); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1168 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1171 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1172 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1173 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1174 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1175 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1178 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1179 | private void updateAlgorithmLayoutMinHeight() { |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 1180 | mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition() |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1181 | ? getLayoutMinHeight() : 0); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1184 | /** |
| 1185 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 1186 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 1187 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1188 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1189 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1190 | updateScrollStateForAddedChildren(); |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 1191 | mAmbientState.setCurrentScrollVelocity(mScroller.isFinished() |
| 1192 | ? 0 |
| 1193 | : mScroller.getCurrVelocity()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1194 | if (ANCHOR_SCROLLING) { |
| 1195 | mAmbientState.setAnchorViewIndex(indexOfChild(mScrollAnchorView)); |
| 1196 | mAmbientState.setAnchorViewY(mScrollAnchorViewY); |
| 1197 | } else { |
| 1198 | mAmbientState.setScrollY(mOwnScrollY); |
| 1199 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1200 | mStackScrollAlgorithm.resetViewStates(mAmbientState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1201 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1202 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1203 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1204 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1208 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1209 | private void onPreDrawDuringAnimation() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1210 | mShelf.updateAppearance(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1211 | updateClippingToTopRoundedCorner(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1212 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 1213 | updateBackground(); |
| 1214 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1217 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1218 | private void updateClippingToTopRoundedCorner() { |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1219 | Float clipStart = (float) mTopPadding |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1220 | + mStackTranslation |
| 1221 | + mAmbientState.getExpandAnimationTopChange(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1222 | Float clipEnd = clipStart + mCornerRadius; |
| 1223 | boolean first = true; |
| 1224 | for (int i = 0; i < getChildCount(); i++) { |
| 1225 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1226 | if (child.getVisibility() == GONE) { |
| 1227 | continue; |
| 1228 | } |
| 1229 | float start = child.getTranslationY(); |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1230 | float end = start + child.getActualHeight(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1231 | boolean clip = clipStart > start && clipStart < end |
| 1232 | || clipEnd >= start && clipEnd <= end; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1233 | clip &= !(first && isScrolledToTop()); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 1234 | child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0) |
| 1235 | : ExpandableView.NO_ROUNDNESS); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1236 | first = false; |
| 1237 | } |
| 1238 | } |
| 1239 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1240 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1241 | private void updateScrollStateForAddedChildren() { |
| 1242 | if (mChildrenToAddAnimated.isEmpty()) { |
| 1243 | return; |
| 1244 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1245 | if (!ANCHOR_SCROLLING) { |
| 1246 | for (int i = 0; i < getChildCount(); i++) { |
| 1247 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1248 | if (mChildrenToAddAnimated.contains(child)) { |
| 1249 | int startingPosition = getPositionInLinearLayout(child); |
| 1250 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
| 1251 | int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements |
| 1252 | : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements; |
| 1253 | int childHeight = getIntrinsicHeight(child) + padding; |
| 1254 | if (startingPosition < mOwnScrollY) { |
| 1255 | // This child starts off screen, so let's keep it offscreen to keep the |
| 1256 | // others visible |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1257 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1258 | setOwnScrollY(mOwnScrollY + childHeight); |
| 1259 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | clampScrollPosition(); |
| 1264 | } |
| 1265 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1266 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1267 | private void updateForcedScroll() { |
| 1268 | if (mForcedScroll != null && (!mForcedScroll.hasFocus() |
| 1269 | || !mForcedScroll.isAttachedToWindow())) { |
| 1270 | mForcedScroll = null; |
| 1271 | } |
| 1272 | if (mForcedScroll != null) { |
| 1273 | ExpandableView expandableView = (ExpandableView) mForcedScroll; |
| 1274 | int positionInLinearLayout = getPositionInLinearLayout(expandableView); |
| 1275 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1276 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1277 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1278 | if (ANCHOR_SCROLLING) { |
| 1279 | // TODO |
| 1280 | } else { |
| 1281 | targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange())); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1282 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1283 | // Only apply the scroll if we're scrolling the view upwards, or the view is so |
| 1284 | // far up that it is not visible anymore. |
| 1285 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1286 | setOwnScrollY(targetScroll); |
| 1287 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1292 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1293 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 1294 | if (!mChildrenUpdateRequested) { |
| 1295 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 1296 | mChildrenUpdateRequested = true; |
| 1297 | invalidate(); |
| 1298 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1299 | } |
| 1300 | |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 1301 | /** |
| 1302 | * Returns best effort count of visible notifications. |
| 1303 | */ |
| 1304 | public int getVisibleNotificationCount() { |
| 1305 | int count = 0; |
| 1306 | for (int i = 0; i < getChildCount(); i++) { |
| 1307 | final View child = getChildAt(i); |
| 1308 | if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) { |
| 1309 | count++; |
| 1310 | } |
| 1311 | } |
| 1312 | return count; |
| 1313 | } |
| 1314 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1315 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1316 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1317 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1320 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1321 | private void clampScrollPosition() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1322 | if (ANCHOR_SCROLLING) { |
| 1323 | // TODO |
| 1324 | } else { |
| 1325 | int scrollRange = getScrollRange(); |
| 1326 | if (scrollRange < mOwnScrollY) { |
| 1327 | setOwnScrollY(scrollRange); |
| 1328 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1332 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1333 | public int getTopPadding() { |
| 1334 | return mTopPadding; |
| 1335 | } |
| 1336 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1337 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1338 | private void setTopPadding(int topPadding, boolean animate) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 1339 | if (mTopPadding != topPadding) { |
| 1340 | mTopPadding = topPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1341 | updateAlgorithmHeightAndPadding(); |
| 1342 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1343 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1344 | mTopPaddingNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1345 | mNeedsAnimation = true; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1346 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1347 | requestChildrenUpdate(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1348 | notifyHeightChangeListener(null, animate); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | /** |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1353 | * Update the height of the panel. |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1354 | * |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1355 | * @param height the expanded height of the panel |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1356 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1357 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1358 | public void setExpandedHeight(float height) { |
| 1359 | mExpandedHeight = height; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1360 | setIsExpanded(height > 0); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1361 | int minExpansionHeight = getMinExpansionHeight(); |
| 1362 | if (height < minExpansionHeight) { |
| 1363 | mClipRect.left = 0; |
| 1364 | mClipRect.right = getWidth(); |
| 1365 | mClipRect.top = 0; |
| 1366 | mClipRect.bottom = (int) height; |
| 1367 | height = minExpansionHeight; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1368 | setRequestedClipBounds(mClipRect); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1369 | } else { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1370 | setRequestedClipBounds(null); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1371 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1372 | int stackHeight; |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1373 | float translationY; |
| 1374 | float appearEndPosition = getAppearEndPosition(); |
| 1375 | float appearStartPosition = getAppearStartPosition(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1376 | float appearFraction = 1.0f; |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 1377 | boolean appearing = height < appearEndPosition; |
| 1378 | mAmbientState.setAppearing(appearing); |
| 1379 | if (!appearing) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1380 | translationY = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 1381 | if (mShouldShowShelfOnly) { |
| 1382 | stackHeight = mTopPadding + mShelf.getIntrinsicHeight(); |
| 1383 | } else if (mQsExpanded) { |
| 1384 | int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding; |
| 1385 | int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight(); |
| 1386 | if (stackStartPosition <= stackEndPosition) { |
| 1387 | stackHeight = stackEndPosition; |
| 1388 | } else { |
| 1389 | stackHeight = (int) NotificationUtils.interpolate(stackStartPosition, |
| 1390 | stackEndPosition, mQsExpansionFraction); |
| 1391 | } |
| 1392 | } else { |
| 1393 | stackHeight = (int) height; |
| 1394 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1395 | } else { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1396 | appearFraction = calculateAppearFraction(height); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1397 | if (appearFraction >= 0) { |
| 1398 | translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0, |
| 1399 | appearFraction); |
| 1400 | } else { |
| 1401 | // This may happen when pushing up a heads up. We linearly push it up from the |
| 1402 | // start |
| 1403 | translationY = height - appearStartPosition + getExpandTranslationStart(); |
| 1404 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1405 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1406 | stackHeight = |
| 1407 | getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1408 | translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction); |
| 1409 | } else { |
| 1410 | stackHeight = (int) (height - translationY); |
| 1411 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1412 | } |
| 1413 | if (stackHeight != mCurrentStackHeight) { |
| 1414 | mCurrentStackHeight = stackHeight; |
| 1415 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1416 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1417 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1418 | setStackTranslation(translationY); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1419 | notifyAppearChangedListeners(); |
| 1420 | } |
| 1421 | |
| 1422 | private void notifyAppearChangedListeners() { |
| 1423 | float appear; |
| 1424 | float expandAmount; |
| 1425 | if (mKeyguardBypassController.getBypassEnabled() && onKeyguard()) { |
| 1426 | appear = calculateAppearFractionBypass(); |
| 1427 | expandAmount = getPulseHeight(); |
| 1428 | } else { |
| 1429 | appear = MathUtils.saturate(calculateAppearFraction(mExpandedHeight)); |
| 1430 | expandAmount = mExpandedHeight; |
| 1431 | } |
| 1432 | if (appear != mLastSentAppear || expandAmount != mLastSentExpandedHeight) { |
| 1433 | mLastSentAppear = appear; |
| 1434 | mLastSentExpandedHeight = expandAmount; |
| 1435 | for (int i = 0; i < mExpandedHeightListeners.size(); i++) { |
| 1436 | BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i); |
| 1437 | listener.accept(expandAmount, appear); |
| 1438 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1439 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1442 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1443 | private void setRequestedClipBounds(Rect clipRect) { |
| 1444 | mRequestedClipBounds = clipRect; |
| 1445 | updateClipping(); |
| 1446 | } |
| 1447 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1448 | /** |
| 1449 | * Return the height of the content ignoring the footer. |
| 1450 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1451 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1452 | public int getIntrinsicContentHeight() { |
| 1453 | return mIntrinsicContentHeight; |
| 1454 | } |
| 1455 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1456 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1457 | public void updateClipping() { |
| 1458 | boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode |
| 1459 | && !mHeadsUpAnimatingAway; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1460 | boolean clipToOutline = false; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1461 | if (mIsClipped != clipped) { |
| 1462 | mIsClipped = clipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1463 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1464 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 1465 | if (mAmbientState.isHiddenAtAll()) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1466 | clipToOutline = true; |
| 1467 | invalidateOutline(); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 1468 | if (isFullyHidden()) { |
| 1469 | setClipBounds(null); |
| 1470 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1471 | } else if (clipped) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1472 | setClipBounds(mRequestedClipBounds); |
| 1473 | } else { |
| 1474 | setClipBounds(null); |
| 1475 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1476 | |
| 1477 | setClipToOutline(clipToOutline); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * @return The translation at the beginning when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1482 | * Measured relative to the resting position. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1483 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1484 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1485 | private float getExpandTranslationStart() { |
Selim Cinek | 083f214 | 2018-11-06 16:32:23 -0800 | [diff] [blame] | 1486 | return -mTopPadding + getMinExpansionHeight() - mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /** |
| 1490 | * @return the position from where the appear transition starts when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1491 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1492 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1493 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1494 | private float getAppearStartPosition() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1495 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1496 | return mHeadsUpInset |
| 1497 | + getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1498 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1499 | return getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1503 | * @return the height of the top heads up notification when pinned. This is different from the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1504 | * intrinsic height, which also includes whether the notification is system expanded and |
| 1505 | * is mainly used when dragging down from a heads up notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1506 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1507 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1508 | private int getTopHeadsUpPinnedHeight() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1509 | NotificationEntry topEntry = mHeadsUpManager.getTopEntry(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1510 | if (topEntry == null) { |
| 1511 | return 0; |
| 1512 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1513 | ExpandableNotificationRow row = topEntry.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1514 | if (row.isChildInGroup()) { |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 1515 | final NotificationEntry groupSummary = |
| 1516 | mGroupManager.getGroupSummary(row.getEntry().getSbn()); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1517 | if (groupSummary != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1518 | row = groupSummary.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | return row.getPinnedHeadsUpHeight(); |
| 1522 | } |
| 1523 | |
| 1524 | /** |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1525 | * @return the position from where the appear transition ends when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1526 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1527 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1528 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1529 | private float getAppearEndPosition() { |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1530 | int appearPosition; |
Selim Cinek | 66440cf | 2017-05-26 13:48:47 -0700 | [diff] [blame] | 1531 | int notGoneChildCount = getNotGoneChildCount(); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 1532 | if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1533 | if (isHeadsUpTransition() |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 1534 | || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1535 | appearPosition = getTopHeadsUpPinnedHeight(); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1536 | } else { |
| 1537 | appearPosition = 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1538 | if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) { |
| 1539 | appearPosition += mShelf.getIntrinsicHeight(); |
| 1540 | } |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1541 | } |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1542 | } else { |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1543 | appearPosition = mEmptyShadeView.getHeight(); |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1544 | } |
| 1545 | return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1548 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1549 | private boolean isHeadsUpTransition() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1550 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 1551 | return mTrackingHeadsUp && firstVisibleSection != null |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 1552 | && firstVisibleSection.getFirstVisibleChild().isAboveShelf(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1553 | } |
| 1554 | |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1555 | /** |
| 1556 | * @param height the height of the panel |
| 1557 | * @return the fraction of the appear animation that has been performed |
| 1558 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1559 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1560 | public float calculateAppearFraction(float height) { |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1561 | float appearEndPosition = getAppearEndPosition(); |
| 1562 | float appearStartPosition = getAppearStartPosition(); |
| 1563 | return (height - appearStartPosition) |
| 1564 | / (appearEndPosition - appearStartPosition); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1567 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1568 | public float getStackTranslation() { |
| 1569 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1572 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1573 | private void setStackTranslation(float stackTranslation) { |
| 1574 | if (stackTranslation != mStackTranslation) { |
| 1575 | mStackTranslation = stackTranslation; |
| 1576 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1577 | requestChildrenUpdate(); |
| 1578 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1582 | * Get the current height of the view. This is at most the msize of the view given by a the |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1583 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 1584 | * |
| 1585 | * @return either the layout height or the externally defined height, whichever is smaller |
| 1586 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1587 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1588 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1589 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 1590 | } |
| 1591 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1592 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1593 | public int getFirstItemMinHeight() { |
| 1594 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1595 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1596 | } |
| 1597 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1598 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1599 | public void setQsContainer(ViewGroup qsContainer) { |
| 1600 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1601 | } |
| 1602 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1603 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1604 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1605 | if (v instanceof ExpandableNotificationRow) { |
| 1606 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1607 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1608 | } |
| 1609 | return false; |
| 1610 | } |
| 1611 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1612 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1613 | private boolean isHeadsUp(View v) { |
| 1614 | if (v instanceof ExpandableNotificationRow) { |
| 1615 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1616 | return row.isHeadsUp(); |
| 1617 | } |
| 1618 | return false; |
| 1619 | } |
| 1620 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1621 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1622 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 1623 | getLocationOnScreen(mTempInt2); |
| 1624 | float localTouchY = touchY - mTempInt2[1]; |
| 1625 | |
| 1626 | ExpandableView closestChild = null; |
| 1627 | float minDist = Float.MAX_VALUE; |
| 1628 | |
| 1629 | // find the view closest to the location, accounting for GONE views |
| 1630 | final int count = getChildCount(); |
| 1631 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 1632 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 1633 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1634 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1635 | continue; |
| 1636 | } |
| 1637 | float childTop = slidingChild.getTranslationY(); |
| 1638 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1639 | float bottom = childTop + slidingChild.getActualHeight() |
| 1640 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1641 | |
| 1642 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 1643 | if (dist < minDist) { |
| 1644 | closestChild = slidingChild; |
| 1645 | minDist = dist; |
| 1646 | } |
| 1647 | } |
| 1648 | return closestChild; |
| 1649 | } |
| 1650 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1651 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
| 1652 | private ExpandableView getChildAtPosition(float touchX, float touchY) { |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 1653 | return getChildAtPosition( |
| 1654 | touchX, touchY, true /* requireMinHeight */, true /* ignoreDecors */); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | /** |
| 1658 | * Get the child at a certain screen location. |
| 1659 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1660 | * @param touchX the x coordinate |
| 1661 | * @param touchY the y coordinate |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1662 | * @param requireMinHeight Whether a minimum height is required for a child to be returned. |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 1663 | * @param ignoreDecors Whether decors can be returned |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1664 | * @return the child at the given location. |
| 1665 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1666 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1667 | private ExpandableView getChildAtPosition(float touchX, float touchY, |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 1668 | boolean requireMinHeight, boolean ignoreDecors) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1669 | // find the view under the pointer, accounting for GONE views |
| 1670 | final int count = getChildCount(); |
| 1671 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1672 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1673 | if (slidingChild.getVisibility() != VISIBLE |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 1674 | || (ignoreDecors && slidingChild instanceof StackScrollerDecorView)) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1675 | continue; |
| 1676 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 1677 | float childTop = slidingChild.getTranslationY(); |
| 1678 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1679 | float bottom = childTop + slidingChild.getActualHeight() |
| 1680 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 1681 | |
| 1682 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 1683 | // camera affordance). |
| 1684 | int left = 0; |
| 1685 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1686 | |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1687 | if ((bottom - top >= mMinInteractionHeight || !requireMinHeight) |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1688 | && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1689 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 1690 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1691 | NotificationEntry entry = row.getEntry(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1692 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1693 | && mHeadsUpManager.getTopEntry().getRow() != row |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1694 | && mGroupManager.getGroupSummary( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 1695 | mHeadsUpManager.getTopEntry().getSbn()) |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1696 | != entry) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1697 | continue; |
| 1698 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1699 | return row.getViewAtPosition(touchY - childTop); |
| 1700 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1701 | return slidingChild; |
| 1702 | } |
| 1703 | } |
| 1704 | return null; |
| 1705 | } |
| 1706 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1707 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1708 | getLocationOnScreen(mTempInt2); |
| 1709 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1712 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1713 | public void setScrollingEnabled(boolean enable) { |
| 1714 | mScrollingEnabled = enable; |
| 1715 | } |
| 1716 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1717 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1718 | public void lockScrollTo(View v) { |
| 1719 | if (mForcedScroll == v) { |
| 1720 | return; |
| 1721 | } |
| 1722 | mForcedScroll = v; |
| 1723 | scrollTo(v); |
| 1724 | } |
| 1725 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1726 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1727 | public boolean scrollTo(View v) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1728 | ExpandableView expandableView = (ExpandableView) v; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1729 | if (ANCHOR_SCROLLING) { |
| 1730 | // TODO |
| 1731 | } else { |
| 1732 | int positionInLinearLayout = getPositionInLinearLayout(v); |
| 1733 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
| 1734 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1735 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1736 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 1737 | // that it is not visible anymore. |
| 1738 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1739 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY); |
| 1740 | mDontReportNextOverScroll = true; |
| 1741 | animateScroll(); |
| 1742 | return true; |
| 1743 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1744 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1745 | return false; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1748 | /** |
| 1749 | * @return the scroll necessary to make the bottom edge of {@param v} align with the top of |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1750 | * the IME. |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1751 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1752 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1753 | private int targetScrollForView(ExpandableView v, int positionInLinearLayout) { |
| 1754 | return positionInLinearLayout + v.getIntrinsicHeight() + |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 1755 | getImeInset() - getHeight() |
| 1756 | + ((!isExpanded() && isPinnedHeadsUp(v)) ? mHeadsUpInset : getTopPadding()); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1757 | } |
| 1758 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1759 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1760 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1761 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1762 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1763 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 1764 | mWaterfallTopInset = 0; |
| 1765 | final DisplayCutout cutout = insets.getDisplayCutout(); |
| 1766 | if (cutout != null) { |
| 1767 | mWaterfallTopInset = cutout.getWaterfallInsets().top; |
| 1768 | } |
| 1769 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1770 | if (ANCHOR_SCROLLING) { |
| 1771 | // TODO |
| 1772 | } else { |
| 1773 | int range = getScrollRange(); |
| 1774 | if (mOwnScrollY > range) { |
| 1775 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1776 | // animating away. To work around that we'll wait until things have settled. |
| 1777 | removeCallbacks(mReclamp); |
| 1778 | postDelayed(mReclamp, 50); |
| 1779 | } else if (mForcedScroll != null) { |
| 1780 | // The scroll was requested before we got the actual inset - in case we need |
| 1781 | // to scroll up some more do so now. |
| 1782 | scrollTo(mForcedScroll); |
| 1783 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1784 | } |
| 1785 | return insets; |
| 1786 | } |
| 1787 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1788 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1789 | private Runnable mReclamp = new Runnable() { |
| 1790 | @Override |
| 1791 | public void run() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1792 | if (ANCHOR_SCROLLING) { |
| 1793 | // TODO |
| 1794 | } else { |
| 1795 | int range = getScrollRange(); |
| 1796 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1797 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1798 | mDontReportNextOverScroll = true; |
| 1799 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1800 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1801 | } |
| 1802 | }; |
| 1803 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1804 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 1805 | public void setExpandingEnabled(boolean enable) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1806 | mExpandHelper.setEnabled(enable); |
| 1807 | } |
| 1808 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1809 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1810 | private boolean isScrollingEnabled() { |
| 1811 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1812 | } |
| 1813 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1814 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1815 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1816 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1817 | } |
| 1818 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1819 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1820 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1821 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1822 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1823 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1824 | float densityScale = getResources().getDisplayMetrics().density; |
| 1825 | mSwipeHelper.setDensityScale(densityScale); |
| 1826 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1827 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1828 | initView(getContext()); |
| 1829 | } |
| 1830 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1831 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1832 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1833 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1834 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1835 | } |
| 1836 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1837 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1838 | private void snapViewIfNeeded(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1839 | ExpandableNotificationRow child = entry.getRow(); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1840 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1841 | // If the child is showing the notification menu snap to that |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 1842 | if (child.getProvider() != null) { |
| 1843 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
| 1844 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
| 1845 | } |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1846 | } |
| 1847 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1848 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1849 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1850 | public ViewGroup getViewParentForNotification(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1851 | return this; |
| 1852 | } |
| 1853 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1854 | /** |
| 1855 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1856 | * |
| 1857 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1858 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1859 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1860 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1861 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1862 | private float overScrollUp(int deltaY, int range) { |
| 1863 | deltaY = Math.max(deltaY, 0); |
| 1864 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1865 | float newTopAmount = currentTopAmount - deltaY; |
| 1866 | if (currentTopAmount > 0) { |
| 1867 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1868 | false /* animate */); |
| 1869 | } |
| 1870 | // Top overScroll might not grab all scrolling motion, |
| 1871 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1872 | if (ANCHOR_SCROLLING) { |
| 1873 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1874 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1875 | ExpandableView lastRow = getLastRowNotGone(); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1876 | if (lastRow != null && !lastRow.isInShelf()) { |
| 1877 | float distanceToMax = Math.max(0, getMaxPositiveScrollAmount()); |
| 1878 | if (scrollAmount > distanceToMax) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1879 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1880 | // We overScroll on the bottom |
| 1881 | setOverScrolledPixels(currentBottomPixels + (scrollAmount - distanceToMax), |
| 1882 | false /* onTop */, |
| 1883 | false /* animate */); |
| 1884 | mScrollAnchorViewY -= distanceToMax; |
| 1885 | scrollAmount = 0f; |
| 1886 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1887 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1888 | return scrollAmount; |
| 1889 | } else { |
| 1890 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1891 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1892 | if (newScrollY > range) { |
| 1893 | if (!mExpandedInThisMotion) { |
| 1894 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1895 | // We overScroll on the bottom |
| 1896 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1897 | false /* onTop */, |
| 1898 | false /* animate */); |
| 1899 | } |
| 1900 | setOwnScrollY(range); |
| 1901 | scrollAmount = 0.0f; |
| 1902 | } |
| 1903 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1904 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1909 | * |
| 1910 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1911 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1912 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1913 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1914 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1915 | private float overScrollDown(int deltaY) { |
| 1916 | deltaY = Math.min(deltaY, 0); |
| 1917 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1918 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1919 | if (currentBottomAmount > 0) { |
| 1920 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1921 | false /* animate */); |
| 1922 | } |
| 1923 | // Bottom overScroll might not grab all scrolling motion, |
| 1924 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1925 | if (ANCHOR_SCROLLING) { |
| 1926 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1927 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1928 | ExpandableView firstChild = getFirstChildNotGone(); |
| 1929 | float top = firstChild.getTranslationY(); |
| 1930 | float distanceToTop = mScrollAnchorView.getTranslationY() - top - mScrollAnchorViewY; |
| 1931 | if (distanceToTop < -scrollAmount) { |
| 1932 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1933 | // We overScroll on the top |
| 1934 | setOverScrolledPixels(currentTopPixels + (-scrollAmount - distanceToTop), |
| 1935 | true /* onTop */, |
| 1936 | false /* animate */); |
| 1937 | mScrollAnchorView = firstChild; |
| 1938 | mScrollAnchorViewY = 0; |
| 1939 | scrollAmount = 0f; |
| 1940 | } |
| 1941 | return scrollAmount; |
| 1942 | } else { |
| 1943 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1944 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1945 | if (newScrollY < 0) { |
| 1946 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1947 | // We overScroll on the top |
| 1948 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1949 | true /* onTop */, |
| 1950 | false /* animate */); |
| 1951 | setOwnScrollY(0); |
| 1952 | scrollAmount = 0.0f; |
| 1953 | } |
| 1954 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1955 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1956 | } |
| 1957 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1958 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1959 | private void initVelocityTrackerIfNotExists() { |
| 1960 | if (mVelocityTracker == null) { |
| 1961 | mVelocityTracker = VelocityTracker.obtain(); |
| 1962 | } |
| 1963 | } |
| 1964 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1965 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1966 | private void recycleVelocityTracker() { |
| 1967 | if (mVelocityTracker != null) { |
| 1968 | mVelocityTracker.recycle(); |
| 1969 | mVelocityTracker = null; |
| 1970 | } |
| 1971 | } |
| 1972 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1973 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1974 | private void initOrResetVelocityTracker() { |
| 1975 | if (mVelocityTracker == null) { |
| 1976 | mVelocityTracker = VelocityTracker.obtain(); |
| 1977 | } else { |
| 1978 | mVelocityTracker.clear(); |
| 1979 | } |
| 1980 | } |
| 1981 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1982 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1983 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1984 | mFinishScrollingCallback = runnable; |
| 1985 | } |
| 1986 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1987 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1988 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1989 | if (mScroller.computeScrollOffset()) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1990 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1991 | int oldY = mLastScrollerY; |
| 1992 | int y = mScroller.getCurrY(); |
| 1993 | int deltaY = y - oldY; |
| 1994 | if (deltaY != 0) { |
| 1995 | int maxNegativeScrollAmount = getMaxNegativeScrollAmount(); |
| 1996 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 1997 | if ((maxNegativeScrollAmount < 0 && deltaY < maxNegativeScrollAmount) |
| 1998 | || (maxPositiveScrollAmount > 0 && deltaY > maxPositiveScrollAmount)) { |
| 1999 | // This frame takes us into overscroll, so set the max overscroll based on |
| 2000 | // the current velocity |
| 2001 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2002 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2003 | customOverScrollBy(deltaY, oldY, 0, (int) mMaxOverScroll); |
| 2004 | mLastScrollerY = y; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2005 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2006 | } else { |
| 2007 | int oldY = mOwnScrollY; |
| 2008 | int y = mScroller.getCurrY(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2009 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2010 | if (oldY != y) { |
| 2011 | int range = getScrollRange(); |
| 2012 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2013 | // This frame takes us into overscroll, so set the max overscroll based on |
| 2014 | // the current velocity |
| 2015 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2016 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2017 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2018 | if (mDontClampNextScroll) { |
| 2019 | range = Math.max(range, oldY); |
| 2020 | } |
| 2021 | customOverScrollBy(y - oldY, oldY, range, |
| 2022 | (int) (mMaxOverScroll)); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 2023 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2024 | } |
| 2025 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2026 | postOnAnimation(mReflingAndAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 2027 | } else { |
| 2028 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 2029 | if (mFinishScrollingCallback != null) { |
| 2030 | mFinishScrollingCallback.run(); |
| 2031 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2035 | private void setMaxOverScrollFromCurrentVelocity() { |
| 2036 | float currVelocity = mScroller.getCurrVelocity(); |
| 2037 | if (currVelocity >= mMinimumVelocity) { |
| 2038 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2039 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2040 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2041 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2042 | /** |
| 2043 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 2044 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 2045 | * |
| 2046 | * This method performs the determination of whether we're exceeding the overscroll and clamps |
| 2047 | * the scroll amount if so. The actual scrolling/overscrolling happens in |
| 2048 | * {@link #onCustomOverScrolled(int, boolean)} (absolute scrolling) or |
| 2049 | * {@link #onCustomOverScrolledBy(int, boolean)} (anchor scrolling). |
| 2050 | * |
| 2051 | * @param deltaY The (signed) number of pixels to scroll. |
| 2052 | * @param scrollY The current scroll position (absolute scrolling only). |
| 2053 | * @param scrollRangeY The maximum allowable scroll position (absolute scrolling only). |
| 2054 | * @param maxOverScrollY The current (unsigned) limit on number of pixels to overscroll by. |
| 2055 | */ |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2056 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2057 | private void customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, int maxOverScrollY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2058 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2059 | boolean clampedY = false; |
| 2060 | if (deltaY < 0) { |
| 2061 | int maxScrollAmount = getMaxNegativeScrollAmount(); |
| 2062 | if (maxScrollAmount > Integer.MIN_VALUE) { |
| 2063 | maxScrollAmount -= maxOverScrollY; |
| 2064 | if (deltaY < maxScrollAmount) { |
| 2065 | deltaY = maxScrollAmount; |
| 2066 | clampedY = true; |
| 2067 | } |
| 2068 | } |
| 2069 | } else { |
| 2070 | int maxScrollAmount = getMaxPositiveScrollAmount(); |
| 2071 | if (maxScrollAmount < Integer.MAX_VALUE) { |
| 2072 | maxScrollAmount += maxOverScrollY; |
| 2073 | if (deltaY > maxScrollAmount) { |
| 2074 | deltaY = maxScrollAmount; |
| 2075 | clampedY = true; |
| 2076 | } |
| 2077 | } |
| 2078 | } |
| 2079 | onCustomOverScrolledBy(deltaY, clampedY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2080 | } else { |
| 2081 | int newScrollY = scrollY + deltaY; |
| 2082 | final int top = -maxOverScrollY; |
| 2083 | final int bottom = maxOverScrollY + scrollRangeY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2084 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2085 | boolean clampedY = false; |
| 2086 | if (newScrollY > bottom) { |
| 2087 | newScrollY = bottom; |
| 2088 | clampedY = true; |
| 2089 | } else if (newScrollY < top) { |
| 2090 | newScrollY = top; |
| 2091 | clampedY = true; |
| 2092 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2093 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2094 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2095 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | /** |
| 2099 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 2100 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 2101 | * same overScroll edge. |
| 2102 | * |
| 2103 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 2104 | * the rubber-banding logic. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2105 | * @param onTop Should the effect be applied on top of the scroller. |
| 2106 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2107 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2108 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2109 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2110 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | /** |
| 2114 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2115 | * By default this will also cancel animations on the same overScroll edge. |
| 2116 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2117 | * @param amount The amount to overScroll by. |
| 2118 | * @param onTop Should the effect be applied on top of the scroller. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2119 | * @param animate Should an animation be performed. |
| 2120 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2121 | |
| 2122 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2123 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 2124 | setOverScrollAmount(amount, onTop, animate, true); |
| 2125 | } |
| 2126 | |
| 2127 | /** |
| 2128 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2129 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2130 | * @param amount The amount to overScroll by. |
| 2131 | * @param onTop Should the effect be applied on top of the scroller. |
| 2132 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2133 | * @param cancelAnimators Should running animations be cancelled. |
| 2134 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2135 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2136 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2137 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2138 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 2139 | } |
| 2140 | |
| 2141 | /** |
| 2142 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2143 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2144 | * @param amount The amount to overScroll by. |
| 2145 | * @param onTop Should the effect be applied on top of the scroller. |
| 2146 | * @param animate Should an animation be performed. |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2147 | * @param cancelAnimators Should running animations be cancelled. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2148 | * @param isRubberbanded The value which will be passed to |
| 2149 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2150 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2151 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2152 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2153 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2154 | if (cancelAnimators) { |
| 2155 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 2156 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2157 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2158 | } |
| 2159 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2160 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2161 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 2162 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2163 | amount = Math.max(0, amount); |
| 2164 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2165 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2166 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2167 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2168 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2169 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2170 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2171 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2172 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2176 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2177 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2178 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 2179 | if (mDontReportNextOverScroll) { |
| 2180 | mDontReportNextOverScroll = false; |
| 2181 | return; |
| 2182 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2183 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2184 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2188 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2189 | public void setOverscrollTopChangedListener( |
| 2190 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 2191 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 2192 | } |
| 2193 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2194 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2195 | public float getCurrentOverScrollAmount(boolean top) { |
| 2196 | return mAmbientState.getOverScrollAmount(top); |
| 2197 | } |
| 2198 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2199 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2200 | public float getCurrentOverScrolledPixels(boolean top) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2201 | return top ? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2202 | } |
| 2203 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2204 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2205 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2206 | if (onTop) { |
| 2207 | mOverScrolledTopPixels = amount; |
| 2208 | } else { |
| 2209 | mOverScrolledBottomPixels = amount; |
| 2210 | } |
| 2211 | } |
| 2212 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2213 | /** |
| 2214 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 2215 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 2216 | * |
| 2217 | * @param deltaY The (signed) number of pixels to scroll. |
| 2218 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2219 | * the overscroll limit. |
| 2220 | */ |
| 2221 | private void onCustomOverScrolledBy(int deltaY, boolean clampedY) { |
| 2222 | assert ANCHOR_SCROLLING; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2223 | mScrollAnchorViewY -= deltaY; |
| 2224 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2225 | if (!mScroller.isFinished()) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2226 | if (clampedY) { |
| 2227 | springBack(); |
| 2228 | } else { |
| 2229 | float overScrollTop = getCurrentOverScrollAmount(true /* top */); |
| 2230 | if (isScrolledToTop() && mScrollAnchorViewY > 0) { |
| 2231 | notifyOverscrollTopListener(mScrollAnchorViewY, |
| 2232 | isRubberbanded(true /* onTop */)); |
| 2233 | } else { |
| 2234 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true /* onTop */)); |
| 2235 | } |
| 2236 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2237 | } |
| 2238 | updateScrollAnchor(); |
| 2239 | updateOnScrollChange(); |
| 2240 | } |
| 2241 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2242 | /** |
| 2243 | * Scrolls to the given position, overscrolling if needed. If called during a fling and the |
| 2244 | * position exceeds the provided maximum overscroll, springs back instead. |
| 2245 | * |
| 2246 | * @param scrollY The target scroll position. |
| 2247 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2248 | * the overscroll limit. |
| 2249 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2250 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2251 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2252 | assert !ANCHOR_SCROLLING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2253 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2254 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2255 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2256 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2257 | springBack(); |
| 2258 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2259 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2260 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2261 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2262 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2263 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2264 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2265 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2266 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2267 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2271 | /** |
| 2272 | * Springs back from an overscroll by stopping the {@link #mScroller} and animating the |
| 2273 | * overscroll amount back to zero. |
| 2274 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2275 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2276 | private void springBack() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2277 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2278 | boolean overScrolledTop = isScrolledToTop() && mScrollAnchorViewY > 0; |
| 2279 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 2280 | boolean overscrolledBottom = maxPositiveScrollAmount < 0; |
| 2281 | if (overScrolledTop || overscrolledBottom) { |
| 2282 | float newAmount; |
| 2283 | if (overScrolledTop) { |
| 2284 | newAmount = mScrollAnchorViewY; |
| 2285 | mScrollAnchorViewY = 0; |
| 2286 | mDontReportNextOverScroll = true; |
| 2287 | } else { |
| 2288 | newAmount = -maxPositiveScrollAmount; |
| 2289 | mScrollAnchorViewY -= maxPositiveScrollAmount; |
| 2290 | } |
| 2291 | setOverScrollAmount(newAmount, overScrolledTop, false); |
| 2292 | setOverScrollAmount(0.0f, overScrolledTop, true); |
| 2293 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2294 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2295 | } else { |
| 2296 | int scrollRange = getScrollRange(); |
| 2297 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2298 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2299 | if (overScrolledTop || overScrolledBottom) { |
| 2300 | boolean onTop; |
| 2301 | float newAmount; |
| 2302 | if (overScrolledTop) { |
| 2303 | onTop = true; |
| 2304 | newAmount = -mOwnScrollY; |
| 2305 | setOwnScrollY(0); |
| 2306 | mDontReportNextOverScroll = true; |
| 2307 | } else { |
| 2308 | onTop = false; |
| 2309 | newAmount = mOwnScrollY - scrollRange; |
| 2310 | setOwnScrollY(scrollRange); |
| 2311 | } |
| 2312 | setOverScrollAmount(newAmount, onTop, false); |
| 2313 | setOverScrollAmount(0.0f, onTop, true); |
| 2314 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2315 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2319 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2320 | private int getScrollRange() { |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2321 | // In current design, it only use the top HUN to treat all of HUNs |
| 2322 | // although there are more than one HUNs |
| 2323 | int contentHeight = mContentHeight; |
| 2324 | if (!isExpanded() && mHeadsUpManager.hasPinnedHeadsUp()) { |
| 2325 | contentHeight = mHeadsUpInset + getTopHeadsUpPinnedHeight(); |
| 2326 | } |
| 2327 | int scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2328 | int imeInset = getImeInset(); |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2329 | scrollRange += Math.min(imeInset, Math.max(0, contentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2330 | return scrollRange; |
| 2331 | } |
| 2332 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2333 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2334 | private int getImeInset() { |
| 2335 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2336 | } |
| 2337 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2338 | /** |
| 2339 | * @return the first child which has visibility unequal to GONE |
| 2340 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2341 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2342 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2343 | int childCount = getChildCount(); |
| 2344 | for (int i = 0; i < childCount; i++) { |
| 2345 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2346 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2347 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2348 | } |
| 2349 | } |
| 2350 | return null; |
| 2351 | } |
| 2352 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2353 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2354 | * @return the child before the given view which has visibility unequal to GONE |
| 2355 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2356 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2357 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2358 | ExpandableView previousView = null; |
| 2359 | int childCount = getChildCount(); |
| 2360 | for (int i = 0; i < childCount; i++) { |
| 2361 | View child = getChildAt(i); |
| 2362 | if (child == view) { |
| 2363 | return previousView; |
| 2364 | } |
| 2365 | if (child.getVisibility() != View.GONE) { |
| 2366 | previousView = (ExpandableView) child; |
| 2367 | } |
| 2368 | } |
| 2369 | return null; |
| 2370 | } |
| 2371 | |
| 2372 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2373 | * @return The first child which has visibility unequal to GONE which is currently below the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2374 | * given translationY or equal to it. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2375 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2376 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2377 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2378 | int childCount = getChildCount(); |
| 2379 | for (int i = 0; i < childCount; i++) { |
| 2380 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2381 | if (child.getVisibility() == View.GONE) { |
| 2382 | continue; |
| 2383 | } |
| 2384 | float rowTranslation = child.getTranslationY(); |
| 2385 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2386 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2387 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2388 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2389 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2390 | List<ExpandableNotificationRow> notificationChildren = |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 2391 | row.getAttachedChildren(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2392 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2393 | childIndex++) { |
| 2394 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2395 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2396 | return rowChild; |
| 2397 | } |
| 2398 | } |
| 2399 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2400 | } |
| 2401 | } |
| 2402 | return null; |
| 2403 | } |
| 2404 | |
| 2405 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2406 | * @return the last child which has visibility unequal to GONE |
| 2407 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2408 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2409 | public ExpandableView getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2410 | int childCount = getChildCount(); |
| 2411 | for (int i = childCount - 1; i >= 0; i--) { |
| 2412 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2413 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2414 | return (ExpandableView) child; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2415 | } |
| 2416 | } |
| 2417 | return null; |
| 2418 | } |
| 2419 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2420 | private ExpandableNotificationRow getLastRowNotGone() { |
| 2421 | int childCount = getChildCount(); |
| 2422 | for (int i = childCount - 1; i >= 0; i--) { |
| 2423 | View child = getChildAt(i); |
| 2424 | if (child instanceof ExpandableNotificationRow && child.getVisibility() != View.GONE) { |
| 2425 | return (ExpandableNotificationRow) child; |
| 2426 | } |
| 2427 | } |
| 2428 | return null; |
| 2429 | } |
| 2430 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2431 | /** |
| 2432 | * @return the number of children which have visibility unequal to GONE |
| 2433 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2434 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2435 | public int getNotGoneChildCount() { |
| 2436 | int childCount = getChildCount(); |
| 2437 | int count = 0; |
| 2438 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2439 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2440 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2441 | count++; |
| 2442 | } |
| 2443 | } |
| 2444 | return count; |
| 2445 | } |
| 2446 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2447 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2448 | private void updateContentHeight() { |
| 2449 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2450 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2451 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2452 | int numShownItems = 0; |
| 2453 | boolean finish = false; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2454 | int maxDisplayedNotifications = mMaxDisplayedNotifications; |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2455 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2456 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2457 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2458 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2459 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2460 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2461 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2462 | && numShownItems >= maxDisplayedNotifications; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2463 | if (limitReached) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2464 | expandableView = mShelf; |
| 2465 | finish = true; |
| 2466 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2467 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2468 | float padding; |
| 2469 | if (increasedPaddingAmount >= 0.0f) { |
| 2470 | padding = (int) NotificationUtils.interpolate( |
| 2471 | previousPaddingRequest, |
| 2472 | mIncreasedPaddingBetweenElements, |
| 2473 | increasedPaddingAmount); |
| 2474 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2475 | mPaddingBetweenElements, |
| 2476 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2477 | increasedPaddingAmount); |
| 2478 | } else { |
| 2479 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2480 | 0, |
| 2481 | mPaddingBetweenElements, |
| 2482 | 1.0f + increasedPaddingAmount); |
| 2483 | if (previousPaddingAmount > 0.0f) { |
| 2484 | padding = (int) NotificationUtils.interpolate( |
| 2485 | ownPadding, |
| 2486 | mIncreasedPaddingBetweenElements, |
| 2487 | previousPaddingAmount); |
| 2488 | } else { |
| 2489 | padding = ownPadding; |
| 2490 | } |
| 2491 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2492 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2493 | if (height != 0) { |
| 2494 | height += padding; |
| 2495 | } |
| 2496 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2497 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2498 | numShownItems++; |
| 2499 | if (finish) { |
| 2500 | break; |
| 2501 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2502 | } |
| 2503 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2504 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2505 | |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 2506 | // The topPadding can be bigger than the regular padding when qs is expanded, in that |
| 2507 | // state the maxPanelHeight and the contentHeight should be bigger |
| 2508 | mContentHeight = height + Math.max(mIntrinsicPadding, mTopPadding) + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2509 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2510 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2511 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2514 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2515 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2516 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2517 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2520 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2521 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2522 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2523 | if (scrollable != mScrollable) { |
| 2524 | mScrollable = scrollable; |
| 2525 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2526 | updateForwardAndBackwardScrollability(); |
| 2527 | } |
| 2528 | } |
| 2529 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2530 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2531 | private void updateForwardAndBackwardScrollability() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2532 | boolean forwardScrollable = mScrollable && !isScrolledToBottom(); |
| 2533 | boolean backwardsScrollable = mScrollable && !isScrolledToTop(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2534 | boolean changed = forwardScrollable != mForwardScrollable |
| 2535 | || backwardsScrollable != mBackwardScrollable; |
| 2536 | mForwardScrollable = forwardScrollable; |
| 2537 | mBackwardScrollable = backwardsScrollable; |
| 2538 | if (changed) { |
| 2539 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2540 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2541 | } |
| 2542 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2543 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2544 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2545 | // No need to update the background color if it's not being drawn. |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 2546 | if (!mShouldDrawNotificationBackground) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2547 | return; |
| 2548 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2549 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2550 | updateBackgroundBounds(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2551 | if (didSectionBoundsChange()) { |
| 2552 | boolean animate = mAnimateNextSectionBoundsChange || mAnimateNextBackgroundTop |
| 2553 | || mAnimateNextBackgroundBottom || areSectionBoundsAnimating(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2554 | if (!isExpanded()) { |
| 2555 | abortBackgroundAnimators(); |
| 2556 | animate = false; |
| 2557 | } |
| 2558 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2559 | startBackgroundAnimation(); |
| 2560 | } else { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2561 | for (NotificationSection section : mSections) { |
| 2562 | section.resetCurrentBounds(); |
| 2563 | } |
Lucas Dupin | 90a38dd | 2018-09-05 09:37:37 -0700 | [diff] [blame] | 2564 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2565 | } |
| 2566 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2567 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2568 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2569 | mAnimateNextBackgroundTop = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2570 | mAnimateNextBackgroundBottom = false; |
| 2571 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2572 | } |
| 2573 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2574 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2575 | private void abortBackgroundAnimators() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2576 | for (NotificationSection section : mSections) { |
| 2577 | section.cancelAnimators(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2581 | private boolean didSectionBoundsChange() { |
| 2582 | for (NotificationSection section : mSections) { |
| 2583 | if (section.didBoundsChange()) { |
| 2584 | return true; |
| 2585 | } |
| 2586 | } |
| 2587 | return false; |
| 2588 | } |
| 2589 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2590 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2591 | private boolean areSectionBoundsAnimating() { |
| 2592 | for (NotificationSection section : mSections) { |
| 2593 | if (section.areBoundsAnimating()) { |
| 2594 | return true; |
| 2595 | } |
| 2596 | } |
| 2597 | return false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2598 | } |
| 2599 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2600 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2601 | private void startBackgroundAnimation() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2602 | // TODO(kprevas): do we still need separate fields for top/bottom? |
| 2603 | // or can each section manage its own animation state? |
| 2604 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2605 | NotificationSection lastVisibleSection = getLastVisibleSection(); |
| 2606 | for (NotificationSection section : mSections) { |
| 2607 | section.startBackgroundAnimation( |
| 2608 | section == firstVisibleSection |
| 2609 | ? mAnimateNextBackgroundTop |
| 2610 | : mAnimateNextSectionBoundsChange, |
| 2611 | section == lastVisibleSection |
| 2612 | ? mAnimateNextBackgroundBottom |
| 2613 | : mAnimateNextSectionBoundsChange); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2614 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | /** |
| 2618 | * Update the background bounds to the new desired bounds |
| 2619 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2620 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2621 | private void updateBackgroundBounds() { |
shawnlin | 2771672 | 2019-04-17 20:09:45 +0800 | [diff] [blame] | 2622 | int left = mSidePaddings; |
| 2623 | int right = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2624 | for (NotificationSection section : mSections) { |
| 2625 | section.getBounds().left = left; |
| 2626 | section.getBounds().right = right; |
| 2627 | } |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2628 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2629 | if (!mIsExpanded) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2630 | for (NotificationSection section : mSections) { |
| 2631 | section.getBounds().top = 0; |
| 2632 | section.getBounds().bottom = 0; |
| 2633 | } |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2634 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2635 | } |
Selim Cinek | 893a9df | 2019-07-19 17:30:16 -0700 | [diff] [blame] | 2636 | int minTopPosition; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2637 | NotificationSection lastSection = getLastVisibleSection(); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 2638 | boolean onKeyguard = mStatusBarState == StatusBarState.KEYGUARD; |
| 2639 | if (!onKeyguard) { |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2640 | minTopPosition = (int) (mTopPadding + mStackTranslation); |
| 2641 | } else if (lastSection == null) { |
| 2642 | minTopPosition = mTopPadding; |
Selim Cinek | 893a9df | 2019-07-19 17:30:16 -0700 | [diff] [blame] | 2643 | } else { |
| 2644 | // The first sections could be empty while there could still be elements in later |
| 2645 | // sections. The position of these first few sections is determined by the position of |
| 2646 | // the first visible section. |
| 2647 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2648 | firstVisibleSection.updateBounds(0 /* minTopPosition*/, 0 /* minBottomPosition */, |
| 2649 | false /* shiftPulsingWithFirst */); |
| 2650 | minTopPosition = firstVisibleSection.getBounds().top; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2651 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 2652 | boolean shiftPulsingWithFirst = mHeadsUpManager.getAllEntries().count() <= 1 |
| 2653 | && (mAmbientState.isDozing() |
| 2654 | || (mKeyguardBypassController.getBypassEnabled() && onKeyguard)); |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2655 | for (NotificationSection section : mSections) { |
| 2656 | int minBottomPosition = minTopPosition; |
| 2657 | if (section == lastSection) { |
| 2658 | // We need to make sure the section goes all the way to the shelf |
Selim Cinek | 3a1d274 | 2019-03-11 18:38:29 -0700 | [diff] [blame] | 2659 | minBottomPosition = (int) (ViewState.getFinalTranslationY(mShelf) |
| 2660 | + mShelf.getIntrinsicHeight()); |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2661 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2662 | minTopPosition = section.updateBounds(minTopPosition, minBottomPosition, |
| 2663 | shiftPulsingWithFirst); |
| 2664 | shiftPulsingWithFirst = false; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2665 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2666 | } |
| 2667 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2668 | private NotificationSection getFirstVisibleSection() { |
| 2669 | for (NotificationSection section : mSections) { |
| 2670 | if (section.getFirstVisibleChild() != null) { |
| 2671 | return section; |
| 2672 | } |
| 2673 | } |
| 2674 | return null; |
| 2675 | } |
| 2676 | |
| 2677 | private NotificationSection getLastVisibleSection() { |
| 2678 | for (int i = mSections.length - 1; i >= 0; i--) { |
| 2679 | NotificationSection section = mSections[i]; |
| 2680 | if (section.getLastVisibleChild() != null) { |
| 2681 | return section; |
| 2682 | } |
| 2683 | } |
| 2684 | return null; |
| 2685 | } |
| 2686 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2687 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2688 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2689 | int childCount = getChildCount(); |
| 2690 | for (int i = childCount - 1; i >= 0; i--) { |
| 2691 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2692 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2693 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2694 | return (ActivatableNotificationView) child; |
| 2695 | } |
| 2696 | } |
| 2697 | return null; |
| 2698 | } |
| 2699 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2700 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2701 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2702 | int childCount = getChildCount(); |
| 2703 | for (int i = 0; i < childCount; i++) { |
| 2704 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2705 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2706 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2707 | return (ActivatableNotificationView) child; |
| 2708 | } |
| 2709 | } |
| 2710 | return null; |
| 2711 | } |
| 2712 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 2713 | //TODO: We shouldn't have to generate this list every time |
| 2714 | private List<ActivatableNotificationView> getChildrenWithBackground() { |
| 2715 | ArrayList<ActivatableNotificationView> children = new ArrayList<>(); |
| 2716 | int childCount = getChildCount(); |
| 2717 | for (int i = 0; i < childCount; i++) { |
| 2718 | View child = getChildAt(i); |
| 2719 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2720 | && child != mShelf) { |
| 2721 | children.add((ActivatableNotificationView) child); |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | return children; |
| 2726 | } |
| 2727 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2728 | /** |
| 2729 | * Fling the scroll view |
| 2730 | * |
| 2731 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2732 | * numbers mean that the finger/cursor is moving down the screen, |
| 2733 | * which means we want to scroll towards the top. |
| 2734 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2735 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2736 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2737 | if (getChildCount() > 0) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2738 | float topAmount = getCurrentOverScrollAmount(true); |
| 2739 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2740 | if (velocityY < 0 && topAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2741 | if (ANCHOR_SCROLLING) { |
| 2742 | mScrollAnchorViewY += topAmount; |
| 2743 | } else { |
| 2744 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
| 2745 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2746 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2747 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2748 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2749 | * mOverflingDistance + topAmount; |
| 2750 | } else if (velocityY > 0 && bottomAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2751 | if (ANCHOR_SCROLLING) { |
| 2752 | mScrollAnchorViewY -= bottomAmount; |
| 2753 | } else { |
| 2754 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
| 2755 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2756 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2757 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2758 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2759 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2760 | } else { |
| 2761 | // it will be set once we reach the boundary |
| 2762 | mMaxOverScroll = 0.0f; |
| 2763 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2764 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2765 | flingScroller(velocityY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2766 | } else { |
| 2767 | int scrollRange = getScrollRange(); |
| 2768 | int minScrollY = Math.max(0, scrollRange); |
| 2769 | if (mExpandedInThisMotion) { |
| 2770 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2771 | } |
| 2772 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2773 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2774 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2775 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2776 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2780 | /** |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2781 | * Flings the overscroller with the given velocity (anchor-based scrolling). |
| 2782 | * |
| 2783 | * Because anchor-based scrolling can't track the current scroll position, the overscroller is |
| 2784 | * always started at startY = 0, and we interpret the positions it computes as relative to the |
| 2785 | * start of the scroll. |
| 2786 | */ |
| 2787 | private void flingScroller(int velocityY) { |
| 2788 | assert ANCHOR_SCROLLING; |
| 2789 | mIsScrollerBoundSet = false; |
| 2790 | maybeFlingScroller(velocityY, true /* always fling */); |
| 2791 | } |
| 2792 | |
| 2793 | private void maybeFlingScroller(int velocityY, boolean alwaysFling) { |
| 2794 | assert ANCHOR_SCROLLING; |
| 2795 | // Attempt to determine the maximum amount to scroll before we reach the end. |
| 2796 | // If the first view is not materialized (for an upwards scroll) or the last view is either |
| 2797 | // not materialized or is pinned to the shade (for a downwards scroll), we don't know this |
| 2798 | // amount, so we do an unbounded fling and rely on {@link #maybeReflingScroller()} to update |
| 2799 | // the scroller once we approach the start/end of the list. |
| 2800 | int minY = Integer.MIN_VALUE; |
| 2801 | int maxY = Integer.MAX_VALUE; |
| 2802 | if (velocityY < 0) { |
| 2803 | minY = getMaxNegativeScrollAmount(); |
| 2804 | if (minY > Integer.MIN_VALUE) { |
| 2805 | mIsScrollerBoundSet = true; |
| 2806 | } |
| 2807 | } else { |
| 2808 | maxY = getMaxPositiveScrollAmount(); |
| 2809 | if (maxY < Integer.MAX_VALUE) { |
| 2810 | mIsScrollerBoundSet = true; |
| 2811 | } |
| 2812 | } |
| 2813 | if (mIsScrollerBoundSet || alwaysFling) { |
| 2814 | mLastScrollerY = 0; |
| 2815 | // x velocity is set to 1 to avoid overscroller bug |
| 2816 | mScroller.fling(0, 0, 1, velocityY, 0, 0, minY, maxY, 0, |
| 2817 | mExpandedInThisMotion && !isScrolledToTop() ? 0 : Integer.MAX_VALUE / 2); |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | /** |
| 2822 | * Returns the maximum number of pixels we can scroll in the positive direction (downwards) |
| 2823 | * before reaching the bottom of the list (discounting overscroll). |
| 2824 | * |
| 2825 | * If the return value is negative then we have overscrolled; this is a transient state which |
| 2826 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2827 | * the bottom overscroll amount. |
| 2828 | * |
| 2829 | * If we don't know how many pixels we have left to scroll (because the last row has not been |
| 2830 | * materialized, or it's in the shelf so it doesn't have its "natural" position), we return |
| 2831 | * {@link Integer#MAX_VALUE}. |
| 2832 | */ |
| 2833 | private int getMaxPositiveScrollAmount() { |
| 2834 | assert ANCHOR_SCROLLING; |
| 2835 | // TODO: once we're recycling we need to check the adapter position of the last child. |
| 2836 | ExpandableNotificationRow lastRow = getLastRowNotGone(); |
| 2837 | if (mScrollAnchorView != null && lastRow != null && !lastRow.isInShelf()) { |
| 2838 | // distance from bottom of last child to bottom of notifications area is: |
| 2839 | // distance from bottom of last child |
| 2840 | return (int) (lastRow.getTranslationY() + lastRow.getActualHeight() |
| 2841 | // to top of anchor view |
| 2842 | - mScrollAnchorView.getTranslationY() |
| 2843 | // plus distance from anchor view to top of notifications area |
| 2844 | + mScrollAnchorViewY |
| 2845 | // minus height of notifications area. |
| 2846 | - (mMaxLayoutHeight - getIntrinsicPadding() - mFooterView.getActualHeight())); |
| 2847 | } else { |
| 2848 | return Integer.MAX_VALUE; |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | /** |
| 2853 | * Returns the maximum number of pixels (as a negative number) we can scroll in the negative |
| 2854 | * direction (upwards) before reaching the top of the list (discounting overscroll). |
| 2855 | * |
| 2856 | * If the return value is positive then we have overscrolled; this is a transient state which |
| 2857 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2858 | * the top overscroll amount. |
| 2859 | * |
| 2860 | * If we don't know how many pixels we have left to scroll (because the first row has not been |
| 2861 | * materialized), we return {@link Integer#MIN_VALUE}. |
| 2862 | */ |
| 2863 | private int getMaxNegativeScrollAmount() { |
| 2864 | assert ANCHOR_SCROLLING; |
| 2865 | // TODO: once we're recycling we need to check the adapter position of the first child. |
| 2866 | ExpandableView firstChild = getFirstChildNotGone(); |
| 2867 | if (mScrollAnchorView != null && firstChild != null) { |
| 2868 | // distance from top of first child to top of notifications area is: |
| 2869 | // distance from top of anchor view |
| 2870 | return (int) -(mScrollAnchorView.getTranslationY() |
| 2871 | // to top of first child |
| 2872 | - firstChild.getTranslationY() |
| 2873 | // minus distance from top of anchor view to top of notifications area. |
| 2874 | - mScrollAnchorViewY); |
| 2875 | } else { |
| 2876 | return Integer.MIN_VALUE; |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | /** |
| 2881 | * During a fling, if we were unable to set the bounds of the fling due to the top/bottom view |
| 2882 | * not being materialized or being pinned to the shelf, we need to check on every frame if we're |
| 2883 | * able to set the bounds. If we are, we fling the scroller again with the newly computed |
| 2884 | * bounds. |
| 2885 | */ |
| 2886 | private void maybeReflingScroller() { |
| 2887 | if (!mIsScrollerBoundSet) { |
| 2888 | // Because mScroller is a flywheel scroller, we fling with the minimum possible |
| 2889 | // velocity to establish direction, so as not to perceptibly affect the velocity. |
| 2890 | maybeFlingScroller((int) Math.signum(mScroller.getCurrVelocity()), |
| 2891 | false /* alwaysFling */); |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | /** |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2896 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2897 | * overScroll view (i.e QS). |
| 2898 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2899 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2900 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2901 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2902 | return mScrolledToTopOnFirstDown |
| 2903 | && !mExpandedInThisMotion |
| 2904 | && topOverScroll > mMinTopOverScrollToEscape |
| 2905 | && initialVelocity > 0; |
| 2906 | } |
| 2907 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2908 | /** |
| 2909 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2910 | * account. |
| 2911 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2912 | * @param qsHeight the top padding imposed by the quick settings panel |
| 2913 | * @param animate whether to animate the change |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2914 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2915 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 2916 | public void updateTopPadding(float qsHeight, boolean animate) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2917 | int topPadding = (int) qsHeight; |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2918 | int minStackHeight = getLayoutMinHeight(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2919 | if (topPadding + minStackHeight > getHeight()) { |
| 2920 | mTopPaddingOverflow = topPadding + minStackHeight - getHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2921 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2922 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2923 | } |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 2924 | setTopPadding(topPadding, animate && !mKeyguardBypassController.getBypassEnabled()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2925 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2926 | } |
| 2927 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2928 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2929 | public void setMaxTopPadding(int maxTopPadding) { |
| 2930 | mMaxTopPadding = maxTopPadding; |
| 2931 | } |
| 2932 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2933 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2934 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2935 | if (isHeadsUpTransition()) { |
| 2936 | return getTopHeadsUpPinnedHeight(); |
| 2937 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2938 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2941 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2942 | public float getTopPaddingOverflow() { |
| 2943 | return mTopPaddingOverflow; |
| 2944 | } |
| 2945 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2946 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2947 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2948 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2949 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2950 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2951 | int shelfHeight = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2952 | if (getLastVisibleSection() != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2953 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2954 | } |
| 2955 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2956 | } |
| 2957 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2958 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2959 | private int clampPadding(int desiredPadding) { |
| 2960 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2961 | } |
| 2962 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2963 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2964 | private float getRubberBandFactor(boolean onTop) { |
| 2965 | if (!onTop) { |
| 2966 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2967 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2968 | if (mExpandedInThisMotion) { |
| 2969 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2970 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2971 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2972 | } else if (mScrolledToTopOnFirstDown) { |
| 2973 | return 1.0f; |
| 2974 | } |
| 2975 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2976 | } |
| 2977 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2978 | /** |
| 2979 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2980 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2981 | * overscroll view (e.g. expand QS). |
| 2982 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2983 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2984 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2985 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2986 | || !mScrolledToTopOnFirstDown; |
| 2987 | } |
| 2988 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2989 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2990 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2991 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2992 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 2993 | Assert.isMainThread(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2994 | mChildTransferInProgress = childTransferInProgress; |
| 2995 | } |
| 2996 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2997 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2998 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2999 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3000 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3001 | // we only call our internal methods if this is actually a removal and not just a |
| 3002 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 3003 | if (!mChildTransferInProgress) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3004 | onViewRemovedInternal((ExpandableView) child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3008 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3009 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 3010 | public void cleanUpViewStateForEntry(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 3011 | View child = entry.getRow(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 3012 | if (child == mSwipeHelper.getTranslatingParentView()) { |
| 3013 | mSwipeHelper.clearTranslatingParentView(); |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 3014 | } |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 3015 | } |
| 3016 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3017 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3018 | private void onViewRemovedInternal(ExpandableView child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3019 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3020 | // This is only a position change, don't do anything special |
| 3021 | return; |
| 3022 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3023 | child.setOnHeightChangedListener(null); |
| 3024 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 3025 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3026 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 3027 | if (!mSwipedOutViews.contains(child) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3028 | || Math.abs(child.getTranslation()) != child.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 3029 | container.addTransientView(child, 0); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3030 | child.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3031 | } |
| 3032 | } else { |
| 3033 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3034 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3035 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 3036 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 3037 | focusNextViewIfFocused(child); |
| 3038 | } |
| 3039 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3040 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 3041 | private void focusNextViewIfFocused(View view) { |
| 3042 | if (view instanceof ExpandableNotificationRow) { |
| 3043 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 3044 | if (row.shouldRefocusOnDismiss()) { |
| 3045 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 3046 | if (nextView == null) { |
| 3047 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 3048 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 3049 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3050 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 3051 | } |
| 3052 | if (nextView != null) { |
| 3053 | nextView.requestAccessibilityFocus(); |
| 3054 | } |
| 3055 | } |
| 3056 | } |
| 3057 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3058 | } |
| 3059 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3060 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3061 | private boolean isChildInGroup(View child) { |
| 3062 | return child instanceof ExpandableNotificationRow |
| 3063 | && mGroupManager.isChildInGroupWithSummary( |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 3064 | ((ExpandableNotificationRow) child).getEntry().getSbn()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3065 | } |
| 3066 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3067 | /** |
| 3068 | * Generate a remove animation for a child view. |
| 3069 | * |
| 3070 | * @param child The view to generate the remove animation for. |
| 3071 | * @return Whether an animation was generated. |
| 3072 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3073 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3074 | private boolean generateRemoveAnimation(ExpandableView child) { |
Selim Cinek | f0f7495 | 2020-04-21 11:45:16 -0700 | [diff] [blame] | 3075 | if (!child.wantsAddAndRemoveAnimations()) { |
| 3076 | return false; |
| 3077 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3078 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 3079 | mAddedHeadsUpChildren.remove(child); |
| 3080 | return false; |
| 3081 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3082 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3083 | // An animation is already running, add it transiently |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3084 | mClearTransientViewsWhenFinished.add(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3085 | return true; |
| 3086 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3087 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 3088 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3089 | // Generate Animations |
| 3090 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3091 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3092 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3093 | } else { |
| 3094 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3095 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3096 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3097 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3098 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3099 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3100 | } |
| 3101 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3102 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3103 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 3104 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3107 | /** |
| 3108 | * Remove a removed child view from the heads up animations if it was just added there |
| 3109 | * |
| 3110 | * @return whether any child was removed from the list to animate |
| 3111 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3112 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3113 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 3114 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3115 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 3116 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3117 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3118 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3119 | mTmpList.add(eventPair); |
| 3120 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3121 | } |
| 3122 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3123 | if (hasAddEvent) { |
| 3124 | // This child was just added lets remove all events. |
| 3125 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3126 | ((ExpandableNotificationRow) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3127 | } |
| 3128 | mTmpList.clear(); |
| 3129 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3132 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3133 | * @param child the child to query |
| 3134 | * @return whether a view is not a top level child but a child notification and that group is |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3135 | * not expanded |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3136 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3137 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3138 | private boolean isChildInInvisibleGroup(View child) { |
| 3139 | if (child instanceof ExpandableNotificationRow) { |
| 3140 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 3141 | NotificationEntry groupSummary = |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 3142 | mGroupManager.getGroupSummary(row.getEntry().getSbn()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 3143 | if (groupSummary != null && groupSummary.getRow() != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 3144 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | return false; |
| 3148 | } |
| 3149 | |
| 3150 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3151 | * Updates the scroll position when a child was removed |
| 3152 | * |
| 3153 | * @param removedChild the removed child |
| 3154 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3155 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3156 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3157 | if (ANCHOR_SCROLLING) { |
| 3158 | if (removedChild == mScrollAnchorView) { |
| 3159 | ExpandableView firstChild = getFirstChildNotGone(); |
| 3160 | if (firstChild != null) { |
| 3161 | mScrollAnchorView = firstChild; |
| 3162 | } else { |
| 3163 | mScrollAnchorView = mShelf; |
| 3164 | } |
| 3165 | // Adjust anchor view Y by the distance between the old and new anchors |
| 3166 | // so that there's no visible change. |
| 3167 | mScrollAnchorViewY += |
| 3168 | mScrollAnchorView.getTranslationY() - removedChild.getTranslationY(); |
| 3169 | } |
| 3170 | updateScrollAnchor(); |
| 3171 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3172 | if (mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY > 0) { |
| 3173 | mScrollAnchorViewY = 0; |
| 3174 | } |
| 3175 | updateOnScrollChange(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3176 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3177 | int startingPosition = getPositionInLinearLayout(removedChild); |
| 3178 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 3179 | int padding; |
| 3180 | if (increasedPaddingAmount >= 0) { |
| 3181 | padding = (int) NotificationUtils.interpolate( |
| 3182 | mPaddingBetweenElements, |
| 3183 | mIncreasedPaddingBetweenElements, |
| 3184 | increasedPaddingAmount); |
| 3185 | } else { |
| 3186 | padding = (int) NotificationUtils.interpolate( |
| 3187 | 0, |
| 3188 | mPaddingBetweenElements, |
| 3189 | 1.0f + increasedPaddingAmount); |
| 3190 | } |
| 3191 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
| 3192 | int endPosition = startingPosition + childHeight; |
| 3193 | if (endPosition <= mOwnScrollY) { |
| 3194 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 3195 | // scrollPosition |
| 3196 | setOwnScrollY(mOwnScrollY - childHeight); |
| 3197 | } else if (startingPosition < mOwnScrollY) { |
| 3198 | // This child is currently being scrolled into, set the scroll position to the |
| 3199 | // start of this child |
| 3200 | setOwnScrollY(startingPosition); |
| 3201 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3202 | } |
| 3203 | } |
| 3204 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3205 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 3206 | private int getIntrinsicHeight(View view) { |
| 3207 | if (view instanceof ExpandableView) { |
| 3208 | ExpandableView expandableView = (ExpandableView) view; |
| 3209 | return expandableView.getIntrinsicHeight(); |
| 3210 | } |
| 3211 | return view.getHeight(); |
| 3212 | } |
| 3213 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3214 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3215 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3216 | ExpandableNotificationRow childInGroup = null; |
| 3217 | ExpandableNotificationRow requestedRow = null; |
| 3218 | if (isChildInGroup(requestedView)) { |
| 3219 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 3220 | // then within the parent. |
| 3221 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 3222 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 3223 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3224 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3225 | float previousPaddingRequest = mPaddingBetweenElements; |
| 3226 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3227 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3228 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3229 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 3230 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3231 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3232 | float padding; |
| 3233 | if (increasedPaddingAmount >= 0.0f) { |
| 3234 | padding = (int) NotificationUtils.interpolate( |
| 3235 | previousPaddingRequest, |
| 3236 | mIncreasedPaddingBetweenElements, |
| 3237 | increasedPaddingAmount); |
| 3238 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3239 | mPaddingBetweenElements, |
| 3240 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3241 | increasedPaddingAmount); |
| 3242 | } else { |
| 3243 | int ownPadding = (int) NotificationUtils.interpolate( |
| 3244 | 0, |
| 3245 | mPaddingBetweenElements, |
| 3246 | 1.0f + increasedPaddingAmount); |
| 3247 | if (previousPaddingAmount > 0.0f) { |
| 3248 | padding = (int) NotificationUtils.interpolate( |
| 3249 | ownPadding, |
| 3250 | mIncreasedPaddingBetweenElements, |
| 3251 | previousPaddingAmount); |
| 3252 | } else { |
| 3253 | padding = ownPadding; |
| 3254 | } |
| 3255 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3256 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3257 | if (position != 0) { |
| 3258 | position += padding; |
| 3259 | } |
| 3260 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3261 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3262 | if (child == requestedView) { |
| 3263 | if (requestedRow != null) { |
| 3264 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3265 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3266 | return position; |
| 3267 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3268 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3269 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3270 | } |
| 3271 | } |
| 3272 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3276 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3277 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3278 | super.onViewAdded(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3279 | onViewAddedInternal((ExpandableView) child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3280 | } |
| 3281 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3282 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3283 | private void updateFirstAndLastBackgroundViews() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3284 | NotificationSection firstSection = getFirstVisibleSection(); |
| 3285 | NotificationSection lastSection = getLastVisibleSection(); |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3286 | ActivatableNotificationView previousFirstChild = |
| 3287 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 3288 | ActivatableNotificationView previousLastChild = |
| 3289 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3290 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3291 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3292 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 3293 | boolean sectionViewsChanged = mSectionsManager.updateFirstAndLastViewsForAllSections( |
| 3294 | mSections, getChildrenWithBackground()); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3295 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3296 | if (mAnimationsEnabled && mIsExpanded) { |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3297 | mAnimateNextBackgroundTop = firstChild != previousFirstChild; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3298 | mAnimateNextBackgroundBottom = lastChild != previousLastChild || mAnimateBottomOnLayout; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3299 | mAnimateNextSectionBoundsChange = sectionViewsChanged; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3300 | } else { |
| 3301 | mAnimateNextBackgroundTop = false; |
| 3302 | mAnimateNextBackgroundBottom = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3303 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3304 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3305 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3306 | mRoundnessManager.updateRoundedChildren(mSections); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3307 | mAnimateBottomOnLayout = false; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3308 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3309 | } |
| 3310 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3311 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3312 | private void onViewAddedInternal(ExpandableView child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3313 | updateHideSensitiveForChild(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3314 | child.setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3315 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3316 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3317 | updateChronometerForChild(child); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 3318 | if (child instanceof ExpandableNotificationRow) { |
| 3319 | ((ExpandableNotificationRow) child).setDismissRtl(mDismissRtl); |
| 3320 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3321 | if (ANCHOR_SCROLLING) { |
| 3322 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3323 | if (child == getFirstChildNotGone() && (isScrolledToTop() || !mIsExpanded)) { |
| 3324 | // New child was added at the top while we're scrolled to the top; |
| 3325 | // make it the new anchor view so that we stay at the top. |
| 3326 | mScrollAnchorView = child; |
| 3327 | } |
| 3328 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3329 | } |
| 3330 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3331 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3332 | private void updateHideSensitiveForChild(ExpandableView child) { |
| 3333 | child.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3336 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3337 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3338 | public void notifyGroupChildRemoved(ExpandableView row, ViewGroup childrenContainer) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3339 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3340 | } |
| 3341 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3342 | @Override |
Evan Laird | 9a9a619 | 2019-12-19 10:44:21 -0500 | [diff] [blame] | 3343 | public void notifyGroupChildRemoved(View child, ViewGroup parent) { |
| 3344 | notifyGroupChildRemoved((ExpandableView) child, parent); |
| 3345 | } |
| 3346 | |
| 3347 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3348 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3349 | public void notifyGroupChildAdded(ExpandableView row) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3350 | onViewAddedInternal(row); |
| 3351 | } |
| 3352 | |
Evan Laird | 9a9a619 | 2019-12-19 10:44:21 -0500 | [diff] [blame] | 3353 | @Override |
| 3354 | public void notifyGroupChildAdded(View view) { |
| 3355 | notifyGroupChildAdded((ExpandableView) view); |
| 3356 | } |
| 3357 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3358 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3359 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3360 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3361 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3362 | if (!animationsEnabled) { |
| 3363 | mSwipedOutViews.clear(); |
| 3364 | mChildrenToRemoveAnimated.clear(); |
| 3365 | clearTemporaryViewsInGroup(this); |
| 3366 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3367 | } |
| 3368 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3369 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3370 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3371 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3372 | mShelf.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3373 | int childCount = getChildCount(); |
| 3374 | for (int i = 0; i < childCount; i++) { |
| 3375 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3376 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3377 | updateAnimationState(running, child); |
| 3378 | } |
| 3379 | } |
| 3380 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3381 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3382 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3383 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3384 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3385 | } |
| 3386 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3387 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3388 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3389 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3390 | mAmbientState.setExpandingNotification(row); |
| 3391 | requestChildrenUpdate(); |
| 3392 | } |
| 3393 | |
| 3394 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3395 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3396 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3397 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3398 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3399 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3400 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | @Override |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 3404 | public boolean containsView(View v) { |
| 3405 | return v.getParent() == this; |
| 3406 | } |
| 3407 | |
| 3408 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3409 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3410 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3411 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3412 | requestChildrenUpdate(); |
| 3413 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3414 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3415 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3416 | private void updateAnimationState(boolean running, View child) { |
| 3417 | if (child instanceof ExpandableNotificationRow) { |
| 3418 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3419 | row.setIconAnimationRunning(running); |
| 3420 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3421 | } |
| 3422 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3423 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3424 | public boolean isAddOrRemoveAnimationPending() { |
| 3425 | return mNeedsAnimation |
| 3426 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3427 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3428 | |
| 3429 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3430 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3431 | public void generateAddAnimation(ExpandableView child, boolean fromMoreCard) { |
Selim Cinek | f0f7495 | 2020-04-21 11:45:16 -0700 | [diff] [blame] | 3432 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress && !isFullyHidden() |
| 3433 | && child.wantsAddAndRemoveAnimations()) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3434 | // Generate Animations |
| 3435 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3436 | if (fromMoreCard) { |
| 3437 | mFromMoreCardAdditions.add(child); |
| 3438 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3439 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3440 | } |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 3441 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress |
| 3442 | && !isFullyHidden()) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3443 | mAddedHeadsUpChildren.add(child); |
| 3444 | mChildrenToAddAnimated.remove(child); |
| 3445 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3446 | } |
| 3447 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3448 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3449 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3450 | public void changeViewPosition(ExpandableView child, int newIndex) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 3451 | Assert.isMainThread(); |
| 3452 | if (mChangePositionInProgress) { |
| 3453 | throw new IllegalStateException("Reentrant call to changeViewPosition"); |
| 3454 | } |
| 3455 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3456 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3457 | |
| 3458 | if (currentIndex == -1) { |
| 3459 | boolean isTransient = false; |
| 3460 | if (child instanceof ExpandableNotificationRow |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 3461 | && child.getTransientContainer() != null) { |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3462 | isTransient = true; |
| 3463 | } |
| 3464 | Log.e(TAG, "Attempting to re-position " |
| 3465 | + (isTransient ? "transient" : "") |
| 3466 | + " view {" |
| 3467 | + child |
| 3468 | + "}"); |
| 3469 | return; |
| 3470 | } |
| 3471 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3472 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3473 | mChangePositionInProgress = true; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 3474 | child.setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3475 | removeView(child); |
| 3476 | addView(child, newIndex); |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 3477 | child.setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3478 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3479 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3480 | mChildrenChangingPositions.add(child); |
| 3481 | mNeedsAnimation = true; |
| 3482 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3483 | } |
| 3484 | } |
| 3485 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3486 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3487 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3488 | if (mNeedsAnimation) { |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3489 | generateAllAnimationEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3490 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3491 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3492 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3493 | setAnimationRunning(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3494 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3495 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3496 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3497 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3498 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3499 | } else { |
| 3500 | applyCurrentState(); |
| 3501 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3502 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3503 | } |
| 3504 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3505 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3506 | private void generateAllAnimationEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3507 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3508 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3509 | generateChildAdditionEvents(); |
| 3510 | generatePositionChangeEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3511 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3512 | generateActivateEvent(); |
| 3513 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3514 | generateHideSensitiveEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3515 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3516 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3517 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3518 | generateAnimateEverythingEvent(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3519 | } |
| 3520 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3521 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3522 | private void generateHeadsUpAnimationEvents() { |
| 3523 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3524 | ExpandableNotificationRow row = eventPair.first; |
| 3525 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 3526 | if (isHeadsUp != row.isHeadsUp()) { |
| 3527 | // For cases where we have a heads up showing and appearing again we shouldn't |
| 3528 | // do the animations at all. |
| 3529 | continue; |
| 3530 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3531 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3532 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3533 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 3534 | boolean performDisappearAnimation = !mIsExpanded |
| 3535 | // Only animate if we still have pinned heads up, otherwise we just have the |
| 3536 | // regular collapse animation of the lock screen |
| 3537 | || (mKeyguardBypassController.getBypassEnabled() && onKeyguard() |
| 3538 | && mHeadsUpManager.hasPinnedHeadsUp()); |
| 3539 | if (performDisappearAnimation && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3540 | type = row.wasJustClicked() |
| 3541 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3542 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3543 | if (row.isChildInGroup()) { |
| 3544 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3545 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3546 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3547 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3548 | } else { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3549 | ExpandableViewState viewState = row.getViewState(); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3550 | if (viewState == null) { |
| 3551 | // A view state was never generated for this view, so we don't need to animate |
| 3552 | // this. This may happen with notification children. |
| 3553 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3554 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3555 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3556 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3557 | // Our custom add animation |
| 3558 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3559 | } else { |
| 3560 | // Normal add animation |
| 3561 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3562 | } |
| 3563 | onBottom = !pinnedAndClosed; |
| 3564 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3565 | } |
| 3566 | AnimationEvent event = new AnimationEvent(row, type); |
| 3567 | event.headsUpFromBottom = onBottom; |
| 3568 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3569 | } |
| 3570 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3571 | mAddedHeadsUpChildren.clear(); |
| 3572 | } |
| 3573 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3574 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3575 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3576 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3577 | return false; |
| 3578 | } |
| 3579 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3582 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3583 | private void generateGroupExpansionEvent() { |
| 3584 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3585 | if (mExpandedGroupView != null) { |
| 3586 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3587 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3588 | mExpandedGroupView = null; |
| 3589 | } |
| 3590 | } |
| 3591 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3592 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3593 | private void generateViewResizeEvent() { |
| 3594 | if (mNeedViewResizeAnimation) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3595 | boolean hasDisappearAnimation = false; |
| 3596 | for (AnimationEvent animationEvent : mAnimationEvents) { |
| 3597 | final int type = animationEvent.animationType; |
| 3598 | if (type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3599 | || type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3600 | hasDisappearAnimation = true; |
| 3601 | break; |
| 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | if (!hasDisappearAnimation) { |
| 3606 | mAnimationEvents.add( |
| 3607 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3608 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3609 | } |
| 3610 | mNeedViewResizeAnimation = false; |
| 3611 | } |
| 3612 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3613 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3614 | private void generateChildRemovalEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3615 | for (ExpandableView child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3616 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3617 | |
| 3618 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3619 | float removedTranslation = child.getTranslationY(); |
| 3620 | boolean ignoreChildren = true; |
| 3621 | if (child instanceof ExpandableNotificationRow) { |
| 3622 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3623 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3624 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3625 | ignoreChildren = false; |
| 3626 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3627 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3628 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3629 | if (!childWasSwipedOut) { |
| 3630 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3631 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3632 | |
| 3633 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3634 | // Clean up any potential transient views if the child has already been swiped |
| 3635 | // out, as we won't be animating it further (due to its height already being |
| 3636 | // clipped to 0. |
| 3637 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3638 | if (transientContainer != null) { |
| 3639 | transientContainer.removeTransientView(child); |
| 3640 | } |
| 3641 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3642 | } |
| 3643 | int animationType = childWasSwipedOut |
| 3644 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3645 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3646 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3647 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3648 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3649 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3650 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3651 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3652 | mChildrenToRemoveAnimated.clear(); |
| 3653 | } |
| 3654 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3655 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3656 | private void generatePositionChangeEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3657 | for (ExpandableView child : mChildrenChangingPositions) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3658 | mAnimationEvents.add(new AnimationEvent(child, |
| 3659 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3660 | } |
| 3661 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3662 | if (mGenerateChildOrderChangedEvent) { |
| 3663 | mAnimationEvents.add(new AnimationEvent(null, |
| 3664 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3665 | mGenerateChildOrderChangedEvent = false; |
| 3666 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3667 | } |
| 3668 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3669 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3670 | private void generateChildAdditionEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3671 | for (ExpandableView child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3672 | if (mFromMoreCardAdditions.contains(child)) { |
| 3673 | mAnimationEvents.add(new AnimationEvent(child, |
| 3674 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3675 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3676 | } else { |
| 3677 | mAnimationEvents.add(new AnimationEvent(child, |
| 3678 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3679 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3680 | } |
| 3681 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3682 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3683 | } |
| 3684 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3685 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3686 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3687 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3688 | AnimationEvent event; |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 3689 | if (mAmbientState.isDozing()) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3690 | event = new AnimationEvent(null /* view */, |
| 3691 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3692 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3693 | } else { |
| 3694 | event = new AnimationEvent(null /* view */, |
| 3695 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3696 | } |
| 3697 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3698 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3699 | mTopPaddingNeedsAnimation = false; |
| 3700 | } |
| 3701 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3702 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3703 | private void generateActivateEvent() { |
| 3704 | if (mActivateNeedsAnimation) { |
| 3705 | mAnimationEvents.add( |
| 3706 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3707 | } |
| 3708 | mActivateNeedsAnimation = false; |
| 3709 | } |
| 3710 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3711 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3712 | private void generateAnimateEverythingEvent() { |
| 3713 | if (mEverythingNeedsAnimation) { |
| 3714 | mAnimationEvents.add( |
| 3715 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3716 | } |
| 3717 | mEverythingNeedsAnimation = false; |
| 3718 | } |
| 3719 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3720 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3721 | private void generateDimmedEvent() { |
| 3722 | if (mDimmedNeedsAnimation) { |
| 3723 | mAnimationEvents.add( |
| 3724 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3725 | } |
| 3726 | mDimmedNeedsAnimation = false; |
| 3727 | } |
| 3728 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3729 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3730 | private void generateHideSensitiveEvent() { |
| 3731 | if (mHideSensitiveNeedsAnimation) { |
| 3732 | mAnimationEvents.add( |
| 3733 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3734 | } |
| 3735 | mHideSensitiveNeedsAnimation = false; |
| 3736 | } |
| 3737 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3738 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3739 | private void generateGoToFullShadeEvent() { |
| 3740 | if (mGoToFullShadeNeedsAnimation) { |
| 3741 | mAnimationEvents.add( |
| 3742 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3743 | } |
| 3744 | mGoToFullShadeNeedsAnimation = false; |
| 3745 | } |
| 3746 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3747 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
| 3748 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3749 | return new StackScrollAlgorithm(context, this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | /** |
| 3753 | * @return Whether a y coordinate is inside the content. |
| 3754 | */ |
| 3755 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 3756 | public boolean isInContentBounds(float y) { |
| 3757 | return y < getHeight() - getEmptyBottomMargin(); |
| 3758 | } |
| 3759 | |
| 3760 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3761 | public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) { |
| 3762 | mLongPressListener = listener; |
| 3763 | } |
| 3764 | |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 3765 | private float getTouchSlop(MotionEvent event) { |
| 3766 | // Adjust the touch slop if another gesture may be being performed. |
| 3767 | return event.getClassification() == MotionEvent.CLASSIFICATION_AMBIGUOUS_GESTURE |
| 3768 | ? mTouchSlop * mSlopMultiplier |
| 3769 | : mTouchSlop; |
| 3770 | } |
| 3771 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3772 | @Override |
| 3773 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3774 | public boolean onTouchEvent(MotionEvent ev) { |
Philip Quinn | 97f2e74 | 2020-03-23 19:07:09 -0700 | [diff] [blame] | 3775 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3776 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 3777 | || ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3778 | handleEmptySpaceClick(ev); |
| 3779 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3780 | boolean swipingInProgress = mSwipingInProgress; |
Philip Quinn | 97f2e74 | 2020-03-23 19:07:09 -0700 | [diff] [blame] | 3781 | if (mIsExpanded && !swipingInProgress && !mOnlyScrollingInThisMotion && guts == null) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3782 | if (isCancelOrUp) { |
| 3783 | mExpandHelper.onlyObserveMovements(false); |
| 3784 | } |
| 3785 | boolean wasExpandingBefore = mExpandingNotification; |
| 3786 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
| 3787 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 3788 | && !mDisallowScrollingInThisMotion) { |
| 3789 | dispatchDownEventToScroller(ev); |
| 3790 | } |
| 3791 | } |
| 3792 | boolean scrollerWantsIt = false; |
| 3793 | if (mIsExpanded && !swipingInProgress && !mExpandingNotification |
| 3794 | && !mDisallowScrollingInThisMotion) { |
| 3795 | scrollerWantsIt = onScrollTouch(ev); |
| 3796 | } |
| 3797 | boolean horizontalSwipeWantsIt = false; |
| 3798 | if (!mIsBeingDragged |
| 3799 | && !mExpandingNotification |
| 3800 | && !mExpandedInThisMotion |
| 3801 | && !mOnlyScrollingInThisMotion |
| 3802 | && !mDisallowDismissInThisMotion) { |
| 3803 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 3804 | } |
| 3805 | |
| 3806 | // Check if we need to clear any snooze leavebehinds |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3807 | if (guts != null && !NotificationSwipeHelper.isTouchInView(ev, guts) |
| 3808 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 3809 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 3810 | if ((ns.isExpanded() && isCancelOrUp) |
| 3811 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 3812 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 3813 | // clear it on the next non-horizontal swipe or expand event. |
| 3814 | checkSnoozeLeavebehind(); |
| 3815 | } |
| 3816 | } |
| 3817 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3818 | mCheckForLeavebehind = true; |
| 3819 | } |
| 3820 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 3821 | } |
| 3822 | |
| 3823 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3824 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 3825 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 3826 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 3827 | onScrollTouch(downEvent); |
| 3828 | downEvent.recycle(); |
| 3829 | } |
| 3830 | |
| 3831 | @Override |
| 3832 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3833 | public boolean onGenericMotionEvent(MotionEvent event) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3834 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3835 | || mDisallowScrollingInThisMotion) { |
| 3836 | return false; |
| 3837 | } |
| 3838 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3839 | switch (event.getAction()) { |
| 3840 | case MotionEvent.ACTION_SCROLL: { |
| 3841 | if (!mIsBeingDragged) { |
| 3842 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 3843 | if (vscroll != 0) { |
| 3844 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3845 | if (ANCHOR_SCROLLING) { |
| 3846 | mScrollAnchorViewY -= delta; |
| 3847 | updateScrollAnchor(); |
| 3848 | clampScrollPosition(); |
| 3849 | updateOnScrollChange(); |
| 3850 | } else { |
| 3851 | final int range = getScrollRange(); |
| 3852 | int oldScrollY = mOwnScrollY; |
| 3853 | int newScrollY = oldScrollY - delta; |
| 3854 | if (newScrollY < 0) { |
| 3855 | newScrollY = 0; |
| 3856 | } else if (newScrollY > range) { |
| 3857 | newScrollY = range; |
| 3858 | } |
| 3859 | if (newScrollY != oldScrollY) { |
| 3860 | setOwnScrollY(newScrollY); |
| 3861 | return true; |
| 3862 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | } |
| 3867 | } |
| 3868 | } |
| 3869 | return super.onGenericMotionEvent(event); |
| 3870 | } |
| 3871 | |
| 3872 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3873 | private boolean onScrollTouch(MotionEvent ev) { |
| 3874 | if (!isScrollingEnabled()) { |
| 3875 | return false; |
| 3876 | } |
| 3877 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
| 3878 | return false; |
| 3879 | } |
| 3880 | mForcedScroll = null; |
| 3881 | initVelocityTrackerIfNotExists(); |
| 3882 | mVelocityTracker.addMovement(ev); |
| 3883 | |
Ned Burns | c8048da | 2020-04-02 17:22:40 -0400 | [diff] [blame] | 3884 | final int action = ev.getActionMasked(); |
| 3885 | if (ev.findPointerIndex(mActivePointerId) == -1 && action != MotionEvent.ACTION_DOWN) { |
| 3886 | // Incomplete gesture, possibly due to window swap mid-gesture. Ignore until a new |
| 3887 | // one starts. |
| 3888 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent " |
| 3889 | + MotionEvent.actionToString(ev.getActionMasked())); |
| 3890 | return true; |
| 3891 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3892 | |
Ned Burns | c8048da | 2020-04-02 17:22:40 -0400 | [diff] [blame] | 3893 | switch (action) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3894 | case MotionEvent.ACTION_DOWN: { |
| 3895 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
| 3896 | return false; |
| 3897 | } |
| 3898 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3899 | setIsBeingDragged(isBeingDragged); |
| 3900 | /* |
| 3901 | * If being flinged and user touches, stop the fling. isFinished |
| 3902 | * will be false if being flinged. |
| 3903 | */ |
| 3904 | if (!mScroller.isFinished()) { |
| 3905 | mScroller.forceFinished(true); |
| 3906 | } |
| 3907 | |
| 3908 | // Remember where the motion event started |
| 3909 | mLastMotionY = (int) ev.getY(); |
| 3910 | mDownX = (int) ev.getX(); |
| 3911 | mActivePointerId = ev.getPointerId(0); |
| 3912 | break; |
| 3913 | } |
| 3914 | case MotionEvent.ACTION_MOVE: |
| 3915 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 3916 | if (activePointerIndex == -1) { |
| 3917 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 3918 | break; |
| 3919 | } |
| 3920 | |
| 3921 | final int y = (int) ev.getY(activePointerIndex); |
| 3922 | final int x = (int) ev.getX(activePointerIndex); |
| 3923 | int deltaY = mLastMotionY - y; |
| 3924 | final int xDiff = Math.abs(x - mDownX); |
| 3925 | final int yDiff = Math.abs(deltaY); |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 3926 | final float touchSlop = getTouchSlop(ev); |
| 3927 | if (!mIsBeingDragged && yDiff > touchSlop && yDiff > xDiff) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3928 | setIsBeingDragged(true); |
| 3929 | if (deltaY > 0) { |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 3930 | deltaY -= touchSlop; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3931 | } else { |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 3932 | deltaY += touchSlop; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | if (mIsBeingDragged) { |
| 3936 | // Scroll to follow the motion event |
| 3937 | mLastMotionY = y; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3938 | float scrollAmount; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3939 | int range; |
| 3940 | if (ANCHOR_SCROLLING) { |
| 3941 | range = 0; // unused in the methods it's being passed to |
| 3942 | } else { |
| 3943 | range = getScrollRange(); |
| 3944 | if (mExpandedInThisMotion) { |
| 3945 | range = Math.min(range, mMaxScrollAfterExpand); |
| 3946 | } |
| 3947 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3948 | if (deltaY < 0) { |
| 3949 | scrollAmount = overScrollDown(deltaY); |
| 3950 | } else { |
| 3951 | scrollAmount = overScrollUp(deltaY, range); |
| 3952 | } |
| 3953 | |
| 3954 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 3955 | // sets the scrolling if applicable. |
| 3956 | if (scrollAmount != 0.0f) { |
| 3957 | // The scrolling motion could not be compensated with the |
| 3958 | // existing overScroll, we have to scroll the view |
| 3959 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 3960 | range, getHeight() / 2); |
| 3961 | // If we're scrolling, leavebehinds should be dismissed |
| 3962 | checkSnoozeLeavebehind(); |
| 3963 | } |
| 3964 | } |
| 3965 | break; |
| 3966 | case MotionEvent.ACTION_UP: |
| 3967 | if (mIsBeingDragged) { |
| 3968 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 3969 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 3970 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 3971 | |
| 3972 | if (shouldOverScrollFling(initialVelocity)) { |
| 3973 | onOverScrollFling(true, initialVelocity); |
| 3974 | } else { |
| 3975 | if (getChildCount() > 0) { |
| 3976 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 3977 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 3978 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 3979 | fling(-initialVelocity); |
| 3980 | } else { |
| 3981 | onOverScrollFling(false, initialVelocity); |
| 3982 | } |
| 3983 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3984 | if (ANCHOR_SCROLLING) { |
| 3985 | // TODO |
| 3986 | } else { |
| 3987 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3988 | getScrollRange())) { |
| 3989 | animateScroll(); |
| 3990 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3991 | } |
| 3992 | } |
| 3993 | } |
| 3994 | } |
| 3995 | mActivePointerId = INVALID_POINTER; |
| 3996 | endDrag(); |
| 3997 | } |
| 3998 | |
| 3999 | break; |
| 4000 | case MotionEvent.ACTION_CANCEL: |
| 4001 | if (mIsBeingDragged && getChildCount() > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4002 | if (ANCHOR_SCROLLING) { |
| 4003 | // TODO |
| 4004 | } else { |
| 4005 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 4006 | getScrollRange())) { |
| 4007 | animateScroll(); |
| 4008 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4009 | } |
| 4010 | mActivePointerId = INVALID_POINTER; |
| 4011 | endDrag(); |
| 4012 | } |
| 4013 | break; |
| 4014 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 4015 | final int index = ev.getActionIndex(); |
| 4016 | mLastMotionY = (int) ev.getY(index); |
| 4017 | mDownX = (int) ev.getX(index); |
| 4018 | mActivePointerId = ev.getPointerId(index); |
| 4019 | break; |
| 4020 | } |
| 4021 | case MotionEvent.ACTION_POINTER_UP: |
| 4022 | onSecondaryPointerUp(ev); |
| 4023 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
| 4024 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
| 4025 | break; |
| 4026 | } |
| 4027 | return true; |
| 4028 | } |
| 4029 | |
| 4030 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4031 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 4032 | return ev.getY() < mQsContainer.getBottom(); |
| 4033 | } |
| 4034 | |
| 4035 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4036 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 4037 | if (mOverscrollTopChangedListener != null) { |
| 4038 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 4039 | } |
| 4040 | mDontReportNextOverScroll = true; |
| 4041 | setOverScrollAmount(0.0f, true, false); |
| 4042 | } |
| 4043 | |
| 4044 | |
| 4045 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4046 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 4047 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 4048 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 4049 | final int pointerId = ev.getPointerId(pointerIndex); |
| 4050 | if (pointerId == mActivePointerId) { |
| 4051 | // This was our active pointer going up. Choose a new |
| 4052 | // active pointer and adjust accordingly. |
| 4053 | // TODO: Make this decision more intelligent. |
| 4054 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 4055 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 4056 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 4057 | if (mVelocityTracker != null) { |
| 4058 | mVelocityTracker.clear(); |
| 4059 | } |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4064 | private void endDrag() { |
| 4065 | setIsBeingDragged(false); |
| 4066 | |
| 4067 | recycleVelocityTracker(); |
| 4068 | |
| 4069 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 4070 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 4071 | } |
| 4072 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 4073 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 4074 | } |
| 4075 | } |
| 4076 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4077 | @Override |
| 4078 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4079 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 4080 | initDownStates(ev); |
| 4081 | handleEmptySpaceClick(ev); |
Philip Quinn | 97f2e74 | 2020-03-23 19:07:09 -0700 | [diff] [blame] | 4082 | |
| 4083 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4084 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 4085 | boolean swipingInProgress = mSwipingInProgress; |
Philip Quinn | 97f2e74 | 2020-03-23 19:07:09 -0700 | [diff] [blame] | 4086 | if (!swipingInProgress && !mOnlyScrollingInThisMotion && guts == null) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4087 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 4088 | } |
| 4089 | boolean scrollWantsIt = false; |
| 4090 | if (!swipingInProgress && !mExpandingNotification) { |
| 4091 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 4092 | } |
| 4093 | boolean swipeWantsIt = false; |
| 4094 | if (!mIsBeingDragged |
| 4095 | && !mExpandingNotification |
| 4096 | && !mExpandedInThisMotion |
| 4097 | && !mOnlyScrollingInThisMotion |
| 4098 | && !mDisallowDismissInThisMotion) { |
| 4099 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 4100 | } |
| 4101 | // Check if we need to clear any snooze leavebehinds |
| 4102 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4103 | if (!NotificationSwipeHelper.isTouchInView(ev, guts) && isUp && !swipeWantsIt && |
| 4104 | !expandWantsIt && !scrollWantsIt) { |
| 4105 | mCheckForLeavebehind = false; |
| 4106 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 4107 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4108 | false /* resetMenu */); |
| 4109 | } |
| 4110 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 4111 | mCheckForLeavebehind = true; |
| 4112 | } |
| 4113 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 4114 | } |
| 4115 | |
| 4116 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4117 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 4118 | switch (ev.getActionMasked()) { |
| 4119 | case MotionEvent.ACTION_MOVE: |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 4120 | final float touchSlop = getTouchSlop(ev); |
| 4121 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > touchSlop |
| 4122 | || Math.abs(ev.getX() - mInitialTouchX) > touchSlop)) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4123 | mTouchIsClick = false; |
| 4124 | } |
| 4125 | break; |
| 4126 | case MotionEvent.ACTION_UP: |
| 4127 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
| 4128 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 4129 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 4130 | } |
| 4131 | break; |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4136 | private void initDownStates(MotionEvent ev) { |
| 4137 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 4138 | mExpandedInThisMotion = false; |
| 4139 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
| 4140 | mDisallowScrollingInThisMotion = false; |
| 4141 | mDisallowDismissInThisMotion = false; |
| 4142 | mTouchIsClick = true; |
| 4143 | mInitialTouchX = ev.getX(); |
| 4144 | mInitialTouchY = ev.getY(); |
| 4145 | } |
| 4146 | } |
| 4147 | |
| 4148 | @Override |
| 4149 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4150 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 4151 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 4152 | if (disallowIntercept) { |
| 4153 | cancelLongPress(); |
| 4154 | } |
| 4155 | } |
| 4156 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4157 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4158 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4159 | if (!isScrollingEnabled()) { |
| 4160 | return false; |
| 4161 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4162 | /* |
| 4163 | * This method JUST determines whether we want to intercept the motion. |
| 4164 | * If we return true, onMotionEvent will be called and we do the actual |
| 4165 | * scrolling there. |
| 4166 | */ |
| 4167 | |
| 4168 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4169 | * Shortcut the most recurring case: the user is in the dragging |
| 4170 | * state and is moving their finger. We want to intercept this |
| 4171 | * motion. |
| 4172 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4173 | final int action = ev.getAction(); |
| 4174 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 4175 | return true; |
| 4176 | } |
| 4177 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4178 | switch (action & MotionEvent.ACTION_MASK) { |
| 4179 | case MotionEvent.ACTION_MOVE: { |
| 4180 | /* |
| 4181 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 4182 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4183 | */ |
| 4184 | |
| 4185 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4186 | * Locally do absolute value. mLastMotionY is set to the y value |
| 4187 | * of the down event. |
| 4188 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4189 | final int activePointerId = mActivePointerId; |
| 4190 | if (activePointerId == INVALID_POINTER) { |
| 4191 | // If we don't have a valid id, the touch down wasn't on content. |
| 4192 | break; |
| 4193 | } |
| 4194 | |
| 4195 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 4196 | if (pointerIndex == -1) { |
| 4197 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 4198 | + " in onInterceptTouchEvent"); |
| 4199 | break; |
| 4200 | } |
| 4201 | |
| 4202 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4203 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4204 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4205 | final int xDiff = Math.abs(x - mDownX); |
Philip Quinn | 4716913 | 2020-03-23 19:04:55 -0700 | [diff] [blame] | 4206 | if (yDiff > getTouchSlop(ev) && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4207 | setIsBeingDragged(true); |
| 4208 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4209 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4210 | initVelocityTrackerIfNotExists(); |
| 4211 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4212 | } |
| 4213 | break; |
| 4214 | } |
| 4215 | |
| 4216 | case MotionEvent.ACTION_DOWN: { |
| 4217 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 4218 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 4219 | final ExpandableView childAtTouchPos = getChildAtPosition( |
| 4220 | ev.getX(), y, false /* requireMinHeight */, false /* ignoreDecors */); |
| 4221 | if (childAtTouchPos == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4222 | setIsBeingDragged(false); |
| 4223 | recycleVelocityTracker(); |
| 4224 | break; |
| 4225 | } |
| 4226 | |
| 4227 | /* |
| 4228 | * Remember location of down touch. |
| 4229 | * ACTION_DOWN always refers to pointer index 0. |
| 4230 | */ |
| 4231 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4232 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4233 | mActivePointerId = ev.getPointerId(0); |
| 4234 | |
| 4235 | initOrResetVelocityTracker(); |
| 4236 | mVelocityTracker.addMovement(ev); |
| 4237 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4238 | * If being flinged and user touches the screen, initiate drag; |
| 4239 | * otherwise don't. mScroller.isFinished should be false when |
| 4240 | * being flinged. |
| 4241 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4242 | boolean isBeingDragged = !mScroller.isFinished(); |
| 4243 | setIsBeingDragged(isBeingDragged); |
| 4244 | break; |
| 4245 | } |
| 4246 | |
| 4247 | case MotionEvent.ACTION_CANCEL: |
| 4248 | case MotionEvent.ACTION_UP: |
| 4249 | /* Release the drag */ |
| 4250 | setIsBeingDragged(false); |
| 4251 | mActivePointerId = INVALID_POINTER; |
| 4252 | recycleVelocityTracker(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4253 | if (ANCHOR_SCROLLING) { |
| 4254 | // TODO |
| 4255 | } else { |
| 4256 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 4257 | animateScroll(); |
| 4258 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4259 | } |
| 4260 | break; |
| 4261 | case MotionEvent.ACTION_POINTER_UP: |
| 4262 | onSecondaryPointerUp(ev); |
| 4263 | break; |
| 4264 | } |
| 4265 | |
| 4266 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4267 | * The only time we want to intercept motion events is if we are in the |
| 4268 | * drag mode. |
| 4269 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4270 | return mIsBeingDragged; |
| 4271 | } |
| 4272 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4273 | /** |
| 4274 | * @return Whether the specified motion event is actually happening over the content. |
| 4275 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4276 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4277 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 4278 | return isInContentBounds(event.getY()); |
| 4279 | } |
| 4280 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4281 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4282 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4283 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4284 | void setIsBeingDragged(boolean isDragged) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4285 | mIsBeingDragged = isDragged; |
| 4286 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4287 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4288 | cancelLongPress(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4289 | resetExposedMenuView(true /* animate */, true /* force */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4290 | } |
| 4291 | } |
| 4292 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4293 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4294 | public void requestDisallowLongPress() { |
| 4295 | cancelLongPress(); |
| 4296 | } |
| 4297 | |
| 4298 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4299 | public void requestDisallowDismiss() { |
| 4300 | mDisallowDismissInThisMotion = true; |
| 4301 | } |
| 4302 | |
| 4303 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4304 | public void cancelLongPress() { |
| 4305 | mSwipeHelper.cancelLongPress(); |
| 4306 | } |
| 4307 | |
| 4308 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4309 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 4310 | mOnEmptySpaceClickListener = listener; |
| 4311 | } |
| 4312 | |
| 4313 | /** @hide */ |
| 4314 | @Override |
| 4315 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4316 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4317 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4318 | return true; |
| 4319 | } |
| 4320 | if (!isEnabled()) { |
| 4321 | return false; |
| 4322 | } |
| 4323 | int direction = -1; |
| 4324 | switch (action) { |
| 4325 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4326 | // fall through |
| 4327 | case android.R.id.accessibilityActionScrollDown: |
| 4328 | direction = 1; |
| 4329 | // fall through |
| 4330 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4331 | // fall through |
| 4332 | case android.R.id.accessibilityActionScrollUp: |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4333 | if (ANCHOR_SCROLLING) { |
| 4334 | // TODO |
| 4335 | } else { |
| 4336 | final int viewportHeight = |
| 4337 | getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
| 4338 | - mShelf.getIntrinsicHeight(); |
| 4339 | final int targetScrollY = Math.max(0, |
| 4340 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4341 | if (targetScrollY != mOwnScrollY) { |
| 4342 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, |
| 4343 | targetScrollY - mOwnScrollY); |
| 4344 | animateScroll(); |
| 4345 | return true; |
| 4346 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4347 | } |
| 4348 | break; |
| 4349 | } |
| 4350 | return false; |
| 4351 | } |
| 4352 | |
| 4353 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4354 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4355 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 4356 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 4357 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 4358 | View view = null; |
| 4359 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4360 | // Only close visible guts if they're not a leavebehind. |
| 4361 | view = guts; |
| 4362 | } else if (menuRow != null && menuRow.isMenuVisible() |
| 4363 | && translatingParentView != null) { |
| 4364 | // Checking menu |
| 4365 | view = translatingParentView; |
| 4366 | } |
| 4367 | if (view != null && !NotificationSwipeHelper.isTouchInView(ev, view)) { |
| 4368 | // Touch was outside visible guts / menu notification, close what's visible |
| 4369 | mNotificationGutsManager.closeAndSaveGuts(false /* removeLeavebehind */, |
| 4370 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4371 | false /* resetMenu */); |
| 4372 | resetExposedMenuView(true /* animate */, true /* force */); |
| 4373 | } |
| 4374 | } |
| 4375 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 4376 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4377 | private void setSwipingInProgress(boolean swiping) { |
| 4378 | mSwipingInProgress = swiping; |
| 4379 | if (swiping) { |
| 4380 | requestDisallowInterceptTouchEvent(true); |
| 4381 | } |
| 4382 | } |
| 4383 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4384 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4385 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4386 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4387 | super.onWindowFocusChanged(hasWindowFocus); |
| 4388 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4389 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4390 | } |
| 4391 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4392 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 4393 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4394 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 4395 | public void clearChildFocus(View child) { |
| 4396 | super.clearChildFocus(child); |
| 4397 | if (mForcedScroll == child) { |
| 4398 | mForcedScroll = null; |
| 4399 | } |
| 4400 | } |
| 4401 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4402 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4403 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4404 | public boolean isScrolledToTop() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4405 | if (ANCHOR_SCROLLING) { |
| 4406 | updateScrollAnchor(); |
| 4407 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 4408 | return mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY >= 0; |
| 4409 | } else { |
| 4410 | return mOwnScrollY == 0; |
| 4411 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4415 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4416 | public boolean isScrolledToBottom() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4417 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 4418 | return getMaxPositiveScrollAmount() <= 0; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4419 | } else { |
| 4420 | return mOwnScrollY >= getScrollRange(); |
| 4421 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4425 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4426 | public View getHostView() { |
| 4427 | return this; |
| 4428 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4429 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4430 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4431 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4432 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4433 | } |
| 4434 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4435 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4436 | public void checkSnoozeLeavebehind() { |
| 4437 | if (mCheckForLeavebehind) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 4438 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4439 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4440 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4441 | mCheckForLeavebehind = false; |
| 4442 | } |
| 4443 | } |
| 4444 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4445 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4446 | public void resetCheckSnoozeLeavebehind() { |
| 4447 | mCheckForLeavebehind = true; |
| 4448 | } |
| 4449 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4450 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4451 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4452 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4453 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4454 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4455 | } |
| 4456 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4457 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4458 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4459 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4460 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4461 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4462 | if (!mIsExpanded) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4463 | resetScrollPosition(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4464 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4465 | clearTemporaryViews(); |
| 4466 | clearUserLockedViews(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4467 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 4468 | if (draggedViews.size() > 0) { |
| 4469 | draggedViews.clear(); |
| 4470 | updateContinuousShadowDrawing(); |
| 4471 | } |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4472 | } |
| 4473 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 4474 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4475 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4476 | private void clearUserLockedViews() { |
| 4477 | for (int i = 0; i < getChildCount(); i++) { |
| 4478 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4479 | if (child instanceof ExpandableNotificationRow) { |
| 4480 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4481 | row.setUserLocked(false); |
| 4482 | } |
| 4483 | } |
| 4484 | } |
| 4485 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4486 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4487 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4488 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4489 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4490 | for (int i = 0; i < getChildCount(); i++) { |
| 4491 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4492 | if (child instanceof ExpandableNotificationRow) { |
| 4493 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4494 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4495 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4496 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4497 | } |
| 4498 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4499 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4500 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4501 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 4502 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4503 | } |
| 4504 | } |
| 4505 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4506 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4507 | public void onPanelTrackingStarted() { |
| 4508 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4509 | mAmbientState.setPanelTracking(true); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4510 | resetExposedMenuView(true /* animate */, true /* force */); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4511 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4512 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4513 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4514 | public void onPanelTrackingStopped() { |
| 4515 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4516 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4519 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4520 | public void resetScrollPosition() { |
| 4521 | mScroller.abortAnimation(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4522 | if (ANCHOR_SCROLLING) { |
| 4523 | // TODO: once we're recycling this will need to modify the adapter position instead |
| 4524 | mScrollAnchorView = getFirstChildNotGone(); |
| 4525 | mScrollAnchorViewY = 0; |
| 4526 | updateOnScrollChange(); |
| 4527 | } else { |
| 4528 | setOwnScrollY(0); |
| 4529 | } |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4532 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4533 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4534 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4535 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4536 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4537 | mAmbientState.setShadeExpanded(isExpanded); |
| 4538 | mStateAnimator.setShadeExpanded(isExpanded); |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 4539 | mSwipeHelper.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4540 | if (changed) { |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 4541 | mWillExpand = false; |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4542 | if (!mIsExpanded) { |
| 4543 | mGroupManager.collapseAllGroups(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4544 | mExpandHelper.cancelImmediately(); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4545 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4546 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4547 | updateChronometers(); |
Selim Cinek | f3fa685 | 2016-12-20 18:36:02 +0100 | [diff] [blame] | 4548 | requestChildrenUpdate(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4549 | } |
| 4550 | } |
| 4551 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4552 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4553 | private void updateChronometers() { |
| 4554 | int childCount = getChildCount(); |
| 4555 | for (int i = 0; i < childCount; i++) { |
| 4556 | updateChronometerForChild(getChildAt(i)); |
| 4557 | } |
| 4558 | } |
| 4559 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4560 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4561 | private void updateChronometerForChild(View child) { |
| 4562 | if (child instanceof ExpandableNotificationRow) { |
| 4563 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4564 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4565 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4566 | } |
| 4567 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4568 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4569 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4570 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4571 | updateScrollPositionOnExpandInBottom(view); |
| 4572 | clampScrollPosition(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4573 | notifyHeightChangeListener(view, needsAnimation); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4574 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 4575 | ? (ExpandableNotificationRow) view |
| 4576 | : null; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4577 | NotificationSection firstSection = getFirstVisibleSection(); |
| 4578 | ActivatableNotificationView firstVisibleChild = |
| 4579 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 4580 | if (row != null) { |
| 4581 | if (row == firstVisibleChild |
| 4582 | || row.getNotificationParent() == firstVisibleChild) { |
| 4583 | updateAlgorithmLayoutMinHeight(); |
| 4584 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4585 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4586 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 4587 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4588 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4589 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4590 | } |
| 4591 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4592 | @Override |
| 4593 | public void onReset(ExpandableView view) { |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 4594 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4595 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4596 | } |
| 4597 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4598 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4599 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 4600 | if (view instanceof ExpandableNotificationRow && !onKeyguard()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4601 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4602 | // TODO: once we're recycling this will need to check the adapter position of the child |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 4603 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4604 | if (row.isSummaryWithChildren()) { |
| 4605 | return; |
| 4606 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4607 | // We are actually expanding this view |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4608 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4609 | if (row.isChildInGroup()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4610 | endPosition += row.getNotificationParent().getTranslationY(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4611 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4612 | int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4613 | NotificationSection lastSection = getLastVisibleSection(); |
| 4614 | ActivatableNotificationView lastVisibleChild = |
| 4615 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
| 4616 | if (row != lastVisibleChild && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4617 | layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements; |
| 4618 | } |
| 4619 | if (endPosition > layoutEnd) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4620 | if (ANCHOR_SCROLLING) { |
| 4621 | mScrollAnchorViewY -= (endPosition - layoutEnd); |
| 4622 | updateScrollAnchor(); |
| 4623 | updateOnScrollChange(); |
| 4624 | } else { |
| 4625 | setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd)); |
| 4626 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4627 | mDisallowScrollingInThisMotion = true; |
| 4628 | } |
| 4629 | } |
| 4630 | } |
| 4631 | } |
| 4632 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4633 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4634 | public void setOnHeightChangedListener( |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4635 | ExpandableView.OnHeightChangedListener onHeightChangedListener) { |
| 4636 | this.mOnHeightChangedListener = onHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4637 | } |
| 4638 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4639 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4640 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4641 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 4642 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4643 | runAnimationFinishedRunnables(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4644 | clearTransient(); |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4645 | clearHeadsUpDisappearRunning(); |
| 4646 | } |
| 4647 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4648 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4649 | private void clearHeadsUpDisappearRunning() { |
| 4650 | for (int i = 0; i < getChildCount(); i++) { |
| 4651 | View view = getChildAt(i); |
| 4652 | if (view instanceof ExpandableNotificationRow) { |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4653 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4654 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4655 | if (row.isSummaryWithChildren()) { |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 4656 | for (ExpandableNotificationRow child : row.getAttachedChildren()) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4657 | child.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4658 | } |
| 4659 | } |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4662 | } |
| 4663 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4664 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4665 | private void clearTransient() { |
| 4666 | for (ExpandableView view : mClearTransientViewsWhenFinished) { |
| 4667 | StackStateAnimator.removeTransientView(view); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4668 | } |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4669 | mClearTransientViewsWhenFinished.clear(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4672 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4673 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4674 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 4675 | runnable.run(); |
| 4676 | } |
| 4677 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4678 | } |
| 4679 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4680 | /** |
| 4681 | * See {@link AmbientState#setDimmed}. |
| 4682 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4683 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4684 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4685 | dimmed &= onKeyguard(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4686 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4687 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4688 | mDimmedNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4689 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4690 | animateDimmed(dimmed); |
| 4691 | } else { |
| 4692 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4693 | } |
| 4694 | requestChildrenUpdate(); |
| 4695 | } |
| 4696 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4697 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4698 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4699 | boolean isDimmed() { |
| 4700 | return mAmbientState.isDimmed(); |
| 4701 | } |
| 4702 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4703 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4704 | private void setDimAmount(float dimAmount) { |
| 4705 | mDimAmount = dimAmount; |
| 4706 | updateBackgroundDimming(); |
| 4707 | } |
| 4708 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4709 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4710 | private void animateDimmed(boolean dimmed) { |
| 4711 | if (mDimAnimator != null) { |
| 4712 | mDimAnimator.cancel(); |
| 4713 | } |
| 4714 | float target = dimmed ? 1.0f : 0.0f; |
| 4715 | if (target == mDimAmount) { |
| 4716 | return; |
| 4717 | } |
| 4718 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 4719 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 4720 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 4721 | mDimAnimator.addListener(mDimEndListener); |
| 4722 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 4723 | mDimAnimator.start(); |
| 4724 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4725 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4726 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 4727 | private void updateSensitiveness(boolean animate) { |
| 4728 | boolean hideSensitive = mLockscreenUserManager.isAnyProfilePublicMode(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4729 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 4730 | int childCount = getChildCount(); |
| 4731 | for (int i = 0; i < childCount; i++) { |
| 4732 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 4733 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 4734 | } |
| 4735 | mAmbientState.setHideSensitive(hideSensitive); |
| 4736 | if (animate && mAnimationsEnabled) { |
| 4737 | mHideSensitiveNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4738 | mNeedsAnimation = true; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4739 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 4740 | updateContentHeight(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4741 | requestChildrenUpdate(); |
| 4742 | } |
| 4743 | } |
| 4744 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4745 | /** |
| 4746 | * See {@link AmbientState#setActivatedChild}. |
| 4747 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4748 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4749 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4750 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4751 | if (mAnimationsEnabled) { |
| 4752 | mActivateNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4753 | mNeedsAnimation = true; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4754 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4755 | requestChildrenUpdate(); |
| 4756 | } |
| 4757 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4758 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4759 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4760 | return mAmbientState.getActivatedChild(); |
| 4761 | } |
| 4762 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4763 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4764 | private void applyCurrentState() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4765 | int numChildren = getChildCount(); |
| 4766 | for (int i = 0; i < numChildren; i++) { |
| 4767 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4768 | child.applyViewState(); |
| 4769 | } |
| 4770 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4771 | if (mListener != null) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4772 | mListener.onChildLocationsChanged(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4773 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4774 | runAnimationFinishedRunnables(); |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 4775 | setAnimationRunning(false); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4776 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4777 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 4778 | updateClippingToTopRoundedCorner(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4779 | } |
| 4780 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4781 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4782 | private void updateViewShadows() { |
| 4783 | // we need to work around an issue where the shadow would not cast between siblings when |
| 4784 | // their z difference is between 0 and 0.1 |
| 4785 | |
| 4786 | // Lefts first sort by Z difference |
| 4787 | for (int i = 0; i < getChildCount(); i++) { |
| 4788 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4789 | if (child.getVisibility() != GONE) { |
| 4790 | mTmpSortedChildren.add(child); |
| 4791 | } |
| 4792 | } |
| 4793 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 4794 | |
| 4795 | // Now lets update the shadow for the views |
| 4796 | ExpandableView previous = null; |
| 4797 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 4798 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 4799 | float translationZ = expandableView.getTranslationZ(); |
| 4800 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 4801 | float diff = otherZ - translationZ; |
| 4802 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 4803 | // There is no fake shadow to be drawn |
| 4804 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 4805 | } else { |
| 4806 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 4807 | expandableView.getTranslationY() - previous.getExtraBottomPadding(); |
| 4808 | expandableView.setFakeShadowIntensity( |
| 4809 | diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4810 | previous.getOutlineAlpha(), (int) yLocation, |
| 4811 | previous.getOutlineTranslation()); |
| 4812 | } |
| 4813 | previous = expandableView; |
| 4814 | } |
| 4815 | |
| 4816 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4817 | } |
| 4818 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4819 | /** |
| 4820 | * Update colors of "dismiss" and "empty shade" views. |
| 4821 | * |
| 4822 | * @param lightTheme True if light theme should be used. |
| 4823 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4824 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4825 | public void updateDecorViews(boolean lightTheme) { |
| 4826 | if (lightTheme == mUsingLightTheme) { |
| 4827 | return; |
| 4828 | } |
| 4829 | mUsingLightTheme = lightTheme; |
| 4830 | Context context = new ContextThemeWrapper(mContext, |
| 4831 | lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI); |
Steve Elliott | 577ef79 | 2020-04-02 13:49:36 -0400 | [diff] [blame] | 4832 | final @ColorInt int textColor = |
| 4833 | Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor); |
| 4834 | mSectionsManager.setHeaderForegroundColor(textColor); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4835 | mFooterView.setTextColor(textColor); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4836 | mEmptyShadeView.setTextColor(textColor); |
| 4837 | } |
| 4838 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4839 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4840 | public void goToFullShade(long delay) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4841 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4842 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4843 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4844 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4845 | } |
| 4846 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4847 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4848 | public void cancelExpandHelper() { |
| 4849 | mExpandHelper.cancel(); |
| 4850 | } |
| 4851 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4852 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4853 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 4854 | mIntrinsicPadding = intrinsicPadding; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 4855 | mAmbientState.setIntrinsicPadding(intrinsicPadding); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4856 | } |
| 4857 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4858 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 4859 | public int getIntrinsicPadding() { |
| 4860 | return mIntrinsicPadding; |
| 4861 | } |
| 4862 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4863 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4864 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4865 | public boolean shouldDelayChildPressedState() { |
| 4866 | return true; |
| 4867 | } |
| 4868 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4869 | /** |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4870 | * See {@link AmbientState#setDozing}. |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4871 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4872 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4873 | public void setDozing(boolean dozing, boolean animate, |
| 4874 | @Nullable PointF touchWakeUpScreenLocation) { |
| 4875 | if (mAmbientState.isDozing() == dozing) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 4876 | return; |
| 4877 | } |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4878 | mAmbientState.setDozing(dozing); |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4879 | requestChildrenUpdate(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4880 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4881 | } |
| 4882 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4883 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4884 | * Sets the current hide amount. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4885 | * |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4886 | * @param linearHideAmount The hide amount that follows linear interpoloation in the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4887 | * animation, |
| 4888 | * i.e. animates from 0 to 1 or vice-versa in a linear manner. |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4889 | * @param interpolatedHideAmount The hide amount that follows the actual interpolation of the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4890 | * animation curve. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4891 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4892 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4893 | public void setHideAmount(float linearHideAmount, float interpolatedHideAmount) { |
| 4894 | mLinearHideAmount = linearHideAmount; |
| 4895 | mInterpolatedHideAmount = interpolatedHideAmount; |
| 4896 | boolean wasFullyHidden = mAmbientState.isFullyHidden(); |
| 4897 | boolean wasHiddenAtAll = mAmbientState.isHiddenAtAll(); |
| 4898 | mAmbientState.setHideAmount(interpolatedHideAmount); |
| 4899 | boolean nowFullyHidden = mAmbientState.isFullyHidden(); |
| 4900 | boolean nowHiddenAtAll = mAmbientState.isHiddenAtAll(); |
| 4901 | if (nowFullyHidden != wasFullyHidden) { |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 4902 | updateVisibility(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4903 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4904 | if (!wasHiddenAtAll && nowHiddenAtAll) { |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4905 | resetExposedMenuView(true /* animate */, true /* animate */); |
| 4906 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4907 | if (nowFullyHidden != wasFullyHidden || wasHiddenAtAll != nowHiddenAtAll) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 4908 | invalidateOutline(); |
| 4909 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4910 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4911 | updateBackgroundDimming(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4912 | requestChildrenUpdate(); |
Selim Cinek | 33295a4 | 2019-07-26 19:49:08 -0700 | [diff] [blame] | 4913 | updateOwnTranslationZ(); |
| 4914 | } |
| 4915 | |
| 4916 | private void updateOwnTranslationZ() { |
| 4917 | // Since we are clipping to the outline we need to make sure that the shadows aren't |
| 4918 | // clipped when pulsing |
| 4919 | float ownTranslationZ = 0; |
| 4920 | if (mKeyguardBypassController.getBypassEnabled() && mAmbientState.isHiddenAtAll()) { |
| 4921 | ExpandableView firstChildNotGone = getFirstChildNotGone(); |
| 4922 | if (firstChildNotGone != null && firstChildNotGone.showingPulsing()) { |
| 4923 | ownTranslationZ = firstChildNotGone.getTranslationZ(); |
| 4924 | } |
| 4925 | } |
| 4926 | setTranslationZ(ownTranslationZ); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4927 | } |
| 4928 | |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 4929 | private void updateVisibility() { |
| 4930 | boolean shouldShow = !mAmbientState.isFullyHidden() || !onKeyguard(); |
| 4931 | setVisibility(shouldShow ? View.VISIBLE : View.INVISIBLE); |
| 4932 | } |
| 4933 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4934 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4935 | public void notifyHideAnimationStart(boolean hide) { |
| 4936 | // We only swap the scaling factor if we're fully hidden or fully awake to avoid |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4937 | // interpolation issues when playing with the power button. |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4938 | if (mInterpolatedHideAmount == 0 || mInterpolatedHideAmount == 1) { |
| 4939 | mBackgroundXFactor = hide ? 1.8f : 1.5f; |
| 4940 | mHideXInterpolator = hide |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4941 | ? Interpolators.FAST_OUT_SLOW_IN_REVERSE |
| 4942 | : Interpolators.FAST_OUT_SLOW_IN; |
| 4943 | } |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4946 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4947 | private int getNotGoneIndex(View child) { |
| 4948 | int count = getChildCount(); |
| 4949 | int notGoneIndex = 0; |
| 4950 | for (int i = 0; i < count; i++) { |
| 4951 | View v = getChildAt(i); |
| 4952 | if (child == v) { |
| 4953 | return notGoneIndex; |
| 4954 | } |
| 4955 | if (v.getVisibility() != View.GONE) { |
| 4956 | notGoneIndex++; |
| 4957 | } |
| 4958 | } |
| 4959 | return -1; |
| 4960 | } |
| 4961 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4962 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4963 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4964 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4965 | if (mFooterView != null) { |
| 4966 | index = indexOfChild(mFooterView); |
| 4967 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4968 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4969 | mFooterView = footerView; |
| 4970 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4971 | } |
| 4972 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4973 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4974 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4975 | int index = -1; |
| 4976 | if (mEmptyShadeView != null) { |
| 4977 | index = indexOfChild(mEmptyShadeView); |
| 4978 | removeView(mEmptyShadeView); |
| 4979 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4980 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4981 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4982 | } |
| 4983 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4984 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4985 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4986 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4987 | |
| 4988 | int oldTextRes = mEmptyShadeView.getTextResource(); |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 4989 | int newTextRes = mZenController.areNotificationsHiddenInShade() |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4990 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4991 | if (oldTextRes != newTextRes) { |
| 4992 | mEmptyShadeView.setText(newTextRes); |
| 4993 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4994 | } |
| 4995 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4996 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 4997 | public void updateFooterView(boolean visible, boolean showDismissView, boolean showHistory) { |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4998 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4999 | return; |
| 5000 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 5001 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 5002 | mFooterView.setVisible(visible, animate); |
| 5003 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 5004 | mFooterView.showHistory(showHistory); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 5005 | } |
| 5006 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5007 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 5008 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 5009 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 5010 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 5011 | handleDismissAllClipping(); |
| 5012 | } |
| 5013 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5014 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 5015 | private void handleDismissAllClipping() { |
| 5016 | final int count = getChildCount(); |
| 5017 | boolean previousChildWillBeDismissed = false; |
| 5018 | for (int i = 0; i < count; i++) { |
| 5019 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5020 | if (child.getVisibility() == GONE) { |
| 5021 | continue; |
| 5022 | } |
| 5023 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 5024 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 5025 | } else { |
| 5026 | child.setMinClipTopAmount(0); |
| 5027 | } |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 5028 | previousChildWillBeDismissed = canChildBeDismissed(child); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 5029 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 5030 | } |
| 5031 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5032 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 5033 | public boolean isFooterViewNotGone() { |
| 5034 | return mFooterView != null |
| 5035 | && mFooterView.getVisibility() != View.GONE |
| 5036 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 5037 | } |
| 5038 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5039 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 5040 | public boolean isFooterViewContentVisible() { |
| 5041 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 5042 | } |
| 5043 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5044 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 5045 | public int getFooterViewHeight() { |
| 5046 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 5047 | } |
| 5048 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5049 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 5050 | public int getEmptyShadeViewHeight() { |
| 5051 | return mEmptyShadeView.getHeight(); |
| 5052 | } |
| 5053 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5054 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 5055 | public float getBottomMostNotificationBottom() { |
| 5056 | final int count = getChildCount(); |
| 5057 | float max = 0; |
| 5058 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 5059 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 5060 | if (child.getVisibility() == GONE) { |
| 5061 | continue; |
| 5062 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 5063 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 5064 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 5065 | if (bottom > max) { |
| 5066 | max = bottom; |
| 5067 | } |
| 5068 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 5069 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 5070 | } |
| 5071 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5072 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 5073 | public void setStatusBar(StatusBar statusBar) { |
| 5074 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 5075 | } |
| 5076 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5077 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5078 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 5079 | this.mGroupManager = groupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 5080 | mGroupManager.addOnGroupChangeListener(mOnGroupChangeListener); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 5081 | } |
| 5082 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5083 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 5084 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5085 | if (mIsExpanded && mAnimationsEnabled) { |
| 5086 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 5087 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5088 | requestChildrenUpdate(); |
| 5089 | } |
| 5090 | } |
| 5091 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5092 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 5093 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5094 | int childCount = getChildCount(); |
| 5095 | for (int i = childCount - 1; i >= 0; i--) { |
| 5096 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5097 | if (child.getVisibility() != View.GONE) { |
| 5098 | float childTop = child.getY(); |
| 5099 | if (childTop > touchY) { |
| 5100 | // we are above a notification entirely let's abort |
| 5101 | return false; |
| 5102 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 5103 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 5104 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 5105 | if (child == mFooterView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5106 | if (!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
| 5107 | touchY - childTop)) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5108 | // We clicked on the dismiss button |
| 5109 | return false; |
| 5110 | } |
| 5111 | } else if (child == mEmptyShadeView) { |
| 5112 | // We arrived at the empty shade view, for which we accept all clicks |
| 5113 | return true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5114 | } else if (!belowChild) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5115 | // We are on a child |
| 5116 | return false; |
| 5117 | } |
| 5118 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5119 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 5120 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5121 | } |
| 5122 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5123 | /** @hide */ |
| 5124 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5125 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5126 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 5127 | super.onInitializeAccessibilityEventInternal(event); |
| 5128 | event.setScrollable(mScrollable); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5129 | event.setMaxScrollX(mScrollX); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5130 | if (ANCHOR_SCROLLING) { |
| 5131 | // TODO |
| 5132 | } else { |
| 5133 | event.setScrollY(mOwnScrollY); |
| 5134 | event.setMaxScrollY(getScrollRange()); |
| 5135 | } |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5136 | } |
| 5137 | |
| 5138 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5139 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5140 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 5141 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5142 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5143 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5144 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5145 | info.addAction( |
| 5146 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 5147 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 5148 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5149 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5150 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 5151 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 5152 | } |
| 5153 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 5154 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 5155 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5158 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5159 | public void generateChildOrderChangedEvent() { |
| 5160 | if (mIsExpanded && mAnimationsEnabled) { |
| 5161 | mGenerateChildOrderChangedEvent = true; |
| 5162 | mNeedsAnimation = true; |
| 5163 | requestChildrenUpdate(); |
| 5164 | } |
| 5165 | } |
| 5166 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5167 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5168 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5169 | public int getContainerChildCount() { |
| 5170 | return getChildCount(); |
| 5171 | } |
| 5172 | |
| 5173 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5174 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5175 | public View getContainerChildAt(int i) { |
| 5176 | return getChildAt(i); |
| 5177 | } |
| 5178 | |
| 5179 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5180 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5181 | public void removeContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5182 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5183 | removeView(v); |
| 5184 | } |
| 5185 | |
| 5186 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5187 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Evan Laird | 9a9a619 | 2019-12-19 10:44:21 -0500 | [diff] [blame] | 5188 | public void removeListItem(NotificationListItem v) { |
| 5189 | removeContainerView(v.getView()); |
| 5190 | } |
| 5191 | |
| 5192 | @Override |
| 5193 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5194 | public void addContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5195 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5196 | addView(v); |
| 5197 | } |
| 5198 | |
Evan Laird | 9a9a619 | 2019-12-19 10:44:21 -0500 | [diff] [blame] | 5199 | @Override |
| 5200 | public void addListItem(NotificationListItem v) { |
| 5201 | addContainerView(v.getView()); |
| 5202 | } |
| 5203 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5204 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 5205 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5206 | mAnimationFinishedRunnables.add(runnable); |
| 5207 | } |
| 5208 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 5209 | public void generateHeadsUpAnimation(NotificationEntry entry, boolean isHeadsUp) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 5210 | ExpandableNotificationRow row = entry.getHeadsUpAnimationView(); |
| 5211 | generateHeadsUpAnimation(row, isHeadsUp); |
| 5212 | } |
| 5213 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5214 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5215 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5216 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5217 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 5218 | mNeedsAnimation = true; |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 5219 | if (!mIsExpanded && !mWillExpand && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5220 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5221 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5222 | requestChildrenUpdate(); |
| 5223 | } |
| 5224 | } |
| 5225 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5226 | /** |
| 5227 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 5228 | * position. |
| 5229 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5230 | * @param height the height of the screen |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5231 | * @param bottomBarHeight the height of the bar on the bottom |
| 5232 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5233 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5234 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 5235 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 5236 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5237 | requestChildrenUpdate(); |
| 5238 | } |
| 5239 | |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 5240 | @Override |
| 5241 | public void setWillExpand(boolean willExpand) { |
| 5242 | mWillExpand = willExpand; |
| 5243 | } |
| 5244 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5245 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5246 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 5247 | mTrackingHeadsUp = row != null; |
| 5248 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5249 | } |
| 5250 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5251 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5252 | public void setScrimController(ScrimController scrimController) { |
| 5253 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 5254 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5255 | } |
| 5256 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5257 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5258 | public void forceNoOverlappingRendering(boolean force) { |
| 5259 | mForceNoOverlappingRendering = force; |
| 5260 | } |
| 5261 | |
| 5262 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5263 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5264 | public boolean hasOverlappingRendering() { |
| 5265 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 5266 | } |
| 5267 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5268 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5269 | public void setAnimationRunning(boolean animationRunning) { |
| 5270 | if (animationRunning != mAnimationRunning) { |
| 5271 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5272 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5273 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5274 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5275 | } |
| 5276 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5277 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5278 | } |
| 5279 | } |
| 5280 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5281 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 5282 | public boolean isExpanded() { |
| 5283 | return mIsExpanded; |
| 5284 | } |
| 5285 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5286 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5287 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5288 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 5289 | return; |
| 5290 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5291 | mPulsing = pulsing; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 5292 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 5293 | mSwipeHelper.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5294 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 5295 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 5296 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 5297 | requestChildrenUpdate(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5298 | notifyHeightChangeListener(null, animated); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5299 | } |
| 5300 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5301 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5302 | public void setQsExpanded(boolean qsExpanded) { |
| 5303 | mQsExpanded = qsExpanded; |
| 5304 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 5305 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5306 | } |
| 5307 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5308 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5309 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 5310 | mQsExpansionFraction = qsExpansionFraction; |
| 5311 | } |
| 5312 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5313 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5314 | private void setOwnScrollY(int ownScrollY) { |
| 5315 | assert !ANCHOR_SCROLLING; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5316 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 5317 | // We still want to call the normal scrolled changed for accessibility reasons |
| 5318 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5319 | mOwnScrollY = ownScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5320 | updateOnScrollChange(); |
| 5321 | } |
| 5322 | } |
| 5323 | |
| 5324 | private void updateOnScrollChange() { |
| 5325 | updateForwardAndBackwardScrollability(); |
| 5326 | requestChildrenUpdate(); |
| 5327 | } |
| 5328 | |
| 5329 | private void updateScrollAnchor() { |
| 5330 | int anchorIndex = indexOfChild(mScrollAnchorView); |
| 5331 | // If the anchor view has been scrolled off the top, move to the next view. |
| 5332 | while (mScrollAnchorViewY < 0) { |
| 5333 | View nextAnchor = null; |
| 5334 | for (int i = anchorIndex + 1; i < getChildCount(); i++) { |
| 5335 | View child = getChildAt(i); |
| 5336 | if (child.getVisibility() != View.GONE |
| 5337 | && child instanceof ExpandableNotificationRow) { |
| 5338 | anchorIndex = i; |
| 5339 | nextAnchor = child; |
| 5340 | break; |
| 5341 | } |
| 5342 | } |
| 5343 | if (nextAnchor == null) { |
| 5344 | break; |
| 5345 | } |
| 5346 | mScrollAnchorViewY += |
| 5347 | (int) (nextAnchor.getTranslationY() - mScrollAnchorView.getTranslationY()); |
| 5348 | mScrollAnchorView = nextAnchor; |
| 5349 | } |
| 5350 | // If the view above the anchor view is fully visible, make it the anchor view. |
| 5351 | while (anchorIndex > 0 && mScrollAnchorViewY > 0) { |
| 5352 | View prevAnchor = null; |
| 5353 | for (int i = anchorIndex - 1; i >= 0; i--) { |
| 5354 | View child = getChildAt(i); |
| 5355 | if (child.getVisibility() != View.GONE |
| 5356 | && child instanceof ExpandableNotificationRow) { |
| 5357 | anchorIndex = i; |
| 5358 | prevAnchor = child; |
| 5359 | break; |
| 5360 | } |
| 5361 | } |
| 5362 | if (prevAnchor == null) { |
| 5363 | break; |
| 5364 | } |
| 5365 | float distanceToPreviousAnchor = |
| 5366 | mScrollAnchorView.getTranslationY() - prevAnchor.getTranslationY(); |
| 5367 | if (distanceToPreviousAnchor < mScrollAnchorViewY) { |
| 5368 | mScrollAnchorViewY -= (int) distanceToPreviousAnchor; |
| 5369 | mScrollAnchorView = prevAnchor; |
| 5370 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5371 | } |
| 5372 | } |
| 5373 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5374 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5375 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5376 | int index = -1; |
| 5377 | if (mShelf != null) { |
| 5378 | index = indexOfChild(mShelf); |
| 5379 | removeView(mShelf); |
| 5380 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 5381 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5382 | addView(mShelf, index); |
| 5383 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 5384 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5385 | shelf.bind(mAmbientState, this); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5386 | if (ANCHOR_SCROLLING) { |
| 5387 | mScrollAnchorView = mShelf; |
| 5388 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5389 | } |
| 5390 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5391 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5392 | public NotificationShelf getNotificationShelf() { |
| 5393 | return mShelf; |
| 5394 | } |
| 5395 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5396 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 5397 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 5398 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 5399 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 5400 | updateContentHeight(); |
| 5401 | notifyHeightChangeListener(mShelf); |
| 5402 | } |
| 5403 | } |
| 5404 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5405 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5406 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5407 | mShouldShowShelfOnly = shouldShowShelfOnly; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5408 | updateAlgorithmLayoutMinHeight(); |
| 5409 | } |
| 5410 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5411 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5412 | public int getMinExpansionHeight() { |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 5413 | return mShelf.getIntrinsicHeight() |
| 5414 | - (mShelf.getIntrinsicHeight() - mStatusBarHeight + mWaterfallTopInset) / 2 |
| 5415 | + mWaterfallTopInset; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5416 | } |
| 5417 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5418 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5419 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 5420 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 5421 | updateClipping(); |
| 5422 | } |
| 5423 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5424 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5425 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 5426 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 5427 | updateClipping(); |
| 5428 | } |
| 5429 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5430 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5431 | @VisibleForTesting |
| 5432 | protected void setStatusBarState(int statusBarState) { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5433 | mStatusBarState = statusBarState; |
| 5434 | mAmbientState.setStatusBarState(statusBarState); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | private void onStatePostChange() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5438 | boolean onKeyguard = onKeyguard(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5439 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5440 | if (mHeadsUpAppearanceController != null) { |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 5441 | mHeadsUpAppearanceController.onStateChanged(); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5442 | } |
| 5443 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 5444 | SysuiStatusBarStateController state = (SysuiStatusBarStateController) |
| 5445 | Dependency.get(StatusBarStateController.class); |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 5446 | updateSensitiveness(state.goingToFullShade() /* animate */); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5447 | setDimmed(onKeyguard, state.fromShadeLocked() /* animate */); |
| 5448 | setExpandingEnabled(!onKeyguard); |
| 5449 | ActivatableNotificationView activatedChild = getActivatedChild(); |
| 5450 | setActivatedChild(null); |
| 5451 | if (activatedChild != null) { |
| 5452 | activatedChild.makeInactive(false /* animate */); |
| 5453 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5454 | updateFooter(); |
Dave Mankoff | 5744580 | 2018-10-10 14:47:34 -0400 | [diff] [blame] | 5455 | requestChildrenUpdate(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5456 | onUpdateRowStates(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5457 | |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 5458 | mEntryManager.updateNotifications("StatusBar state changed"); |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 5459 | updateVisibility(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5460 | } |
| 5461 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5462 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 5463 | public void setExpandingVelocity(float expandingVelocity) { |
| 5464 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 5465 | } |
| 5466 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5467 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5468 | public float getOpeningHeight() { |
| 5469 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 5470 | return getMinExpansionHeight(); |
| 5471 | } else { |
| 5472 | return getAppearEndPosition(); |
| 5473 | } |
| 5474 | } |
| 5475 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5476 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5477 | public void setIsFullWidth(boolean isFullWidth) { |
| 5478 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 5479 | } |
| 5480 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5481 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 5482 | public void setUnlockHintRunning(boolean running) { |
| 5483 | mAmbientState.setUnlockHintRunning(running); |
| 5484 | } |
| 5485 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5486 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5487 | public void setQsCustomizerShowing(boolean isShowing) { |
| 5488 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 5489 | requestChildrenUpdate(); |
| 5490 | } |
| 5491 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5492 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5493 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 5494 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 5495 | } |
| 5496 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5497 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5498 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 5499 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5500 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 5501 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5502 | this.getClass().getSimpleName(), |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5503 | mPulsing ? "T" : "f", |
| 5504 | mAmbientState.isQsCustomizerShowing() ? "T" : "f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5505 | getVisibility() == View.VISIBLE ? "visible" |
| 5506 | : getVisibility() == View.GONE ? "gone" |
| 5507 | : "invisible", |
| 5508 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5509 | mAmbientState.getScrollY(), |
| 5510 | mMaxTopPadding, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5511 | mShouldShowShelfOnly ? "T" : "f", |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5512 | mQsExpansionFraction)); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5513 | int childCount = getChildCount(); |
| 5514 | pw.println(" Number of children: " + childCount); |
| 5515 | pw.println(); |
| 5516 | |
| 5517 | for (int i = 0; i < childCount; i++) { |
| 5518 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5519 | child.dump(fd, pw, args); |
| 5520 | if (!(child instanceof ExpandableNotificationRow)) { |
| 5521 | pw.println(" " + child.getClass().getSimpleName()); |
| 5522 | // Notifications dump it's viewstate as part of their dump to support children |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5523 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5524 | if (viewState == null) { |
| 5525 | pw.println(" no viewState!!!"); |
| 5526 | } else { |
| 5527 | pw.print(" "); |
| 5528 | viewState.dump(fd, pw, args); |
| 5529 | pw.println(); |
| 5530 | pw.println(); |
| 5531 | } |
| 5532 | } |
| 5533 | } |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5534 | int transientViewCount = getTransientViewCount(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5535 | pw.println(" Transient Views: " + transientViewCount); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5536 | for (int i = 0; i < transientViewCount; i++) { |
| 5537 | ExpandableView child = (ExpandableView) getTransientView(i); |
| 5538 | child.dump(fd, pw, args); |
| 5539 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5540 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5541 | int draggedCount = draggedViews.size(); |
| 5542 | pw.println(" Dragged Views: " + draggedCount); |
| 5543 | for (int i = 0; i < draggedCount; i++) { |
| 5544 | ExpandableView child = (ExpandableView) draggedViews.get(i); |
| 5545 | child.dump(fd, pw, args); |
| 5546 | } |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5547 | } |
| 5548 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5549 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 5550 | public boolean isFullyHidden() { |
| 5551 | return mAmbientState.isFullyHidden(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 5552 | } |
| 5553 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 5554 | /** |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5555 | * Add a listener whenever the expanded height changes. The first value passed as an |
| 5556 | * argument is the expanded height and the second one is the appearFraction. |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5557 | * |
| 5558 | * @param listener the listener to notify. |
| 5559 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5560 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5561 | public void addOnExpandedHeightChangedListener(BiConsumer<Float, Float> listener) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5562 | mExpandedHeightListeners.add(listener); |
| 5563 | } |
| 5564 | |
| 5565 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5566 | * Stop a listener from listening to the expandedHeight. |
| 5567 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5568 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5569 | public void removeOnExpandedHeightChangedListener(BiConsumer<Float, Float> listener) { |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5570 | mExpandedHeightListeners.remove(listener); |
| 5571 | } |
| 5572 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5573 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 5574 | public void setHeadsUpAppearanceController( |
| 5575 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 5576 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 5577 | } |
| 5578 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5579 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 5580 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 5581 | mIconAreaController = controller; |
| 5582 | } |
| 5583 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5584 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 5585 | @VisibleForTesting |
| 5586 | void clearNotifications( |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5587 | @SelectedRows int selection, |
| 5588 | boolean closeShade) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5589 | // animate-swipe all dismissable notifications, then animate the shade closed |
| 5590 | int numChildren = getChildCount(); |
| 5591 | |
| 5592 | final ArrayList<View> viewsToHide = new ArrayList<>(numChildren); |
| 5593 | final ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>(numChildren); |
| 5594 | for (int i = 0; i < numChildren; i++) { |
| 5595 | final View child = getChildAt(i); |
| 5596 | if (child instanceof ExpandableNotificationRow) { |
| 5597 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 5598 | boolean parentVisible = false; |
| 5599 | boolean hasClipBounds = child.getClipBounds(mTmpRect); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5600 | if (includeChildInDismissAll(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5601 | viewsToRemove.add(row); |
| 5602 | if (child.getVisibility() == View.VISIBLE |
| 5603 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5604 | viewsToHide.add(child); |
| 5605 | parentVisible = true; |
| 5606 | } |
| 5607 | } else if (child.getVisibility() == View.VISIBLE |
| 5608 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5609 | parentVisible = true; |
| 5610 | } |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 5611 | List<ExpandableNotificationRow> children = row.getAttachedChildren(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5612 | if (children != null) { |
| 5613 | for (ExpandableNotificationRow childRow : children) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5614 | if (includeChildInDismissAll(row, selection)) { |
| 5615 | viewsToRemove.add(childRow); |
| 5616 | if (parentVisible && row.areChildrenExpanded()) { |
| 5617 | hasClipBounds = childRow.getClipBounds(mTmpRect); |
| 5618 | if (childRow.getVisibility() == View.VISIBLE |
| 5619 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5620 | viewsToHide.add(childRow); |
| 5621 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5622 | } |
| 5623 | } |
| 5624 | } |
| 5625 | } |
| 5626 | } |
| 5627 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5628 | |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 5629 | // Log dismiss event even if there's nothing to dismiss |
| 5630 | mUiEventLogger.log(NotificationPanelEvent.fromSelection(selection)); |
| 5631 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5632 | if (viewsToRemove.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5633 | if (closeShade) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5634 | Dependency.get(ShadeController.class).animateCollapsePanels( |
| 5635 | CommandQueue.FLAG_EXCLUDE_NONE); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5636 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5637 | return; |
| 5638 | } |
| 5639 | |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 5640 | performDismissAllAnimations( |
| 5641 | viewsToHide, |
| 5642 | closeShade, |
| 5643 | () -> onDismissAllAnimationsEnd(viewsToRemove, selection)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5644 | } |
| 5645 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5646 | private boolean includeChildInDismissAll( |
| 5647 | ExpandableNotificationRow row, |
| 5648 | @SelectedRows int selection) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 5649 | return canChildBeDismissed(row) && matchesSelection(row, selection); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | /** |
| 5653 | * Given a list of rows, animates them away in a staggered fashion as if they were dismissed. |
| 5654 | * Doesn't actually dismiss them, though -- that must be done in the onAnimationComplete |
| 5655 | * handler. |
| 5656 | * |
| 5657 | * @param hideAnimatedList List of rows to animated away. Should only be views that are |
| 5658 | * currently visible, or else the stagger will look funky. |
| 5659 | * @param closeShade Whether to close the shade after the stagger animation completes. |
| 5660 | * @param onAnimationComplete Called after the entire animation completes (including the shade |
| 5661 | * closing if appropriate). The rows must be dismissed for real here. |
| 5662 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5663 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5664 | private void performDismissAllAnimations( |
| 5665 | final ArrayList<View> hideAnimatedList, |
| 5666 | final boolean closeShade, |
| 5667 | final Runnable onAnimationComplete) { |
| 5668 | |
| 5669 | final Runnable onSlideAwayAnimationComplete = () -> { |
| 5670 | if (closeShade) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5671 | Dependency.get(ShadeController.class).addPostCollapseAction(() -> { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5672 | setDismissAllInProgress(false); |
| 5673 | onAnimationComplete.run(); |
| 5674 | }); |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5675 | Dependency.get(ShadeController.class).animateCollapsePanels( |
| 5676 | CommandQueue.FLAG_EXCLUDE_NONE); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5677 | } else { |
| 5678 | setDismissAllInProgress(false); |
| 5679 | onAnimationComplete.run(); |
| 5680 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5681 | }; |
| 5682 | |
| 5683 | if (hideAnimatedList.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5684 | onSlideAwayAnimationComplete.run(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5685 | return; |
| 5686 | } |
| 5687 | |
| 5688 | // let's disable our normal animations |
| 5689 | setDismissAllInProgress(true); |
| 5690 | |
| 5691 | // Decrease the delay for every row we animate to give the sense of |
| 5692 | // accelerating the swipes |
| 5693 | int rowDelayDecrement = 10; |
| 5694 | int currentDelay = 140; |
| 5695 | int totalDelay = 180; |
| 5696 | int numItems = hideAnimatedList.size(); |
| 5697 | for (int i = numItems - 1; i >= 0; i--) { |
| 5698 | View view = hideAnimatedList.get(i); |
| 5699 | Runnable endRunnable = null; |
| 5700 | if (i == 0) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5701 | endRunnable = onSlideAwayAnimationComplete; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5702 | } |
Lucas Dupin | fb8bdbb | 2018-12-02 15:09:37 -0800 | [diff] [blame] | 5703 | dismissViewAnimated(view, endRunnable, totalDelay, ANIMATION_DURATION_SWIPE); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5704 | currentDelay = Math.max(50, currentDelay - rowDelayDecrement); |
| 5705 | totalDelay += currentDelay; |
| 5706 | } |
| 5707 | } |
| 5708 | |
Julia Reynolds | 4368932 | 2020-04-28 18:48:54 -0400 | [diff] [blame] | 5709 | @Override |
| 5710 | public void setNotificationActivityStarter( |
| 5711 | NotificationActivityStarter notificationActivityStarter) { |
| 5712 | mNotificationActivityStarter = notificationActivityStarter; |
| 5713 | } |
| 5714 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5715 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5716 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5717 | protected void inflateFooterView() { |
| 5718 | FooterView footerView = (FooterView) LayoutInflater.from(mContext).inflate( |
| 5719 | R.layout.status_bar_notification_footer, this, false); |
| 5720 | footerView.setDismissButtonClickListener(v -> { |
| 5721 | mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5722 | clearNotifications(ROWS_ALL, true /* closeShade */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5723 | }); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 5724 | footerView.setManageButtonClickListener(v -> { |
Julia Reynolds | 4368932 | 2020-04-28 18:48:54 -0400 | [diff] [blame] | 5725 | mNotificationActivityStarter.startHistoryIntent(mFooterView.isHistoryShown()); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 5726 | }); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5727 | setFooterView(footerView); |
| 5728 | } |
| 5729 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5730 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5731 | private void inflateEmptyShadeView() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5732 | EmptyShadeView view = (EmptyShadeView) LayoutInflater.from(mContext).inflate( |
| 5733 | R.layout.status_bar_no_notifications, this, false); |
| 5734 | view.setText(R.string.empty_shade_text); |
Julia Reynolds | e03eb75 | 2020-04-22 16:57:46 -0400 | [diff] [blame] | 5735 | view.setOnClickListener(v -> { |
Julia Reynolds | 1f94a9d | 2020-05-05 12:40:21 -0400 | [diff] [blame] | 5736 | final boolean showHistory = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 5737 | Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, UserHandle.USER_CURRENT) == 1; |
Julia Reynolds | e03eb75 | 2020-04-22 16:57:46 -0400 | [diff] [blame] | 5738 | Intent intent = showHistory ? new Intent( |
| 5739 | Settings.ACTION_NOTIFICATION_HISTORY) : new Intent( |
| 5740 | Settings.ACTION_NOTIFICATION_SETTINGS); |
| 5741 | mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 5742 | }); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5743 | setEmptyShadeView(view); |
| 5744 | } |
| 5745 | |
| 5746 | /** |
| 5747 | * Updates expanded, dimmed and locked states of notification rows. |
| 5748 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5749 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5750 | public void onUpdateRowStates() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5751 | |
| 5752 | // The following views will be moved to the end of mStackScroller. This counter represents |
| 5753 | // the offset from the last child. Initialized to 1 for the very last position. It is post- |
| 5754 | // incremented in the following "changeViewPosition" calls so that its value is correct for |
| 5755 | // subsequent calls. |
| 5756 | int offsetFromEnd = 1; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 5757 | if (mFgsSectionView != null) { |
| 5758 | changeViewPosition(mFgsSectionView, getChildCount() - offsetFromEnd++); |
| 5759 | } |
| 5760 | changeViewPosition(mFooterView, getChildCount() - offsetFromEnd++); |
| 5761 | changeViewPosition(mEmptyShadeView, getChildCount() - offsetFromEnd++); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5762 | |
| 5763 | // No post-increment for this call because it is the last one. Make sure to add one if |
| 5764 | // another "changeViewPosition" call is ever added. |
| 5765 | changeViewPosition(mShelf, |
| 5766 | getChildCount() - offsetFromEnd); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5767 | } |
| 5768 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5769 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5770 | public void setNotificationPanelController( |
| 5771 | NotificationPanelViewController notificationPanelViewController) { |
| 5772 | mNotificationPanelController = notificationPanelViewController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5773 | } |
| 5774 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5775 | public void updateIconAreaViews() { |
| 5776 | mIconAreaController.updateNotificationIcons(); |
| 5777 | } |
| 5778 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5779 | /** |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5780 | * Set how far the wake up is when waking up from pulsing. This is a height and will adjust the |
| 5781 | * notification positions accordingly. |
| 5782 | * @param height the new wake up height |
| 5783 | * @return the overflow how much the height is further than he lowest notification |
| 5784 | */ |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 5785 | public float setPulseHeight(float height) { |
| 5786 | mAmbientState.setPulseHeight(height); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5787 | if (mKeyguardBypassController.getBypassEnabled()) { |
| 5788 | notifyAppearChangedListeners(); |
| 5789 | } |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5790 | requestChildrenUpdate(); |
| 5791 | return Math.max(0, height - mAmbientState.getInnerHeight(true /* ignorePulseHeight */)); |
| 5792 | } |
| 5793 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5794 | public float getPulseHeight() { |
| 5795 | return mAmbientState.getPulseHeight(); |
| 5796 | } |
| 5797 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5798 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 5799 | * Set the amount how much we're dozing. This is different from how hidden the shade is, when |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5800 | * the notification is pulsing. |
| 5801 | */ |
| 5802 | public void setDozeAmount(float dozeAmount) { |
| 5803 | mAmbientState.setDozeAmount(dozeAmount); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5804 | updateContinuousBackgroundDrawing(); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5805 | requestChildrenUpdate(); |
| 5806 | } |
| 5807 | |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5808 | public void wakeUpFromPulse() { |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5809 | setPulseHeight(getWakeUpHeight()); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5810 | // Let's place the hidden views at the end of the pulsing notification to make sure we have |
| 5811 | // a smooth animation |
| 5812 | boolean firstVisibleView = true; |
| 5813 | float wakeUplocation = -1f; |
| 5814 | int childCount = getChildCount(); |
| 5815 | for (int i = 0; i < childCount; i++) { |
| 5816 | ExpandableView view = (ExpandableView) getChildAt(i); |
| 5817 | if (view.getVisibility() == View.GONE) { |
| 5818 | continue; |
| 5819 | } |
| 5820 | boolean isShelf = view == mShelf; |
| 5821 | if (!(view instanceof ExpandableNotificationRow) && !isShelf) { |
| 5822 | continue; |
| 5823 | } |
| 5824 | if (view.getVisibility() == View.VISIBLE && !isShelf) { |
| 5825 | if (firstVisibleView) { |
| 5826 | firstVisibleView = false; |
| 5827 | wakeUplocation = view.getTranslationY() |
| 5828 | + view.getActualHeight() - mShelf.getIntrinsicHeight(); |
| 5829 | } |
| 5830 | } else if (!firstVisibleView) { |
| 5831 | view.setTranslationY(wakeUplocation); |
| 5832 | } |
| 5833 | } |
Selim Cinek | f434a74 | 2019-05-28 17:39:49 -0700 | [diff] [blame] | 5834 | mDimmedNeedsAnimation = true; |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5835 | } |
| 5836 | |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5837 | @Override |
| 5838 | public void onDynamicPrivacyChanged() { |
| 5839 | if (mIsExpanded) { |
| 5840 | // The bottom might change because we're using the final actual height of the view |
| 5841 | mAnimateBottomOnLayout = true; |
| 5842 | } |
Selim Cinek | abcc201 | 2019-07-23 18:44:07 -0700 | [diff] [blame] | 5843 | // Let's update the footer once the notifications have been updated (in the next frame) |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 5844 | post(() -> { |
| 5845 | updateFooter(); |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 5846 | updateSectionBoundaries("dynamic privacy changed"); |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 5847 | }); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5848 | } |
| 5849 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5850 | public void setOnPulseHeightChangedListener(Runnable listener) { |
| 5851 | mAmbientState.setOnPulseHeightChangedListener(listener); |
| 5852 | } |
| 5853 | |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5854 | public float calculateAppearFractionBypass() { |
| 5855 | float pulseHeight = getPulseHeight(); |
| 5856 | float wakeUpHeight = getWakeUpHeight(); |
| 5857 | float dragDownAmount = pulseHeight - wakeUpHeight; |
| 5858 | |
| 5859 | // The total distance required to fully reveal the header |
| 5860 | float totalDistance = getIntrinsicPadding(); |
| 5861 | return MathUtils.smoothStep(0, totalDistance, dragDownAmount); |
| 5862 | } |
| 5863 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5864 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5865 | * A listener that is notified when the empty space below the notifications is clicked on |
| 5866 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5867 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5868 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 5869 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5873 | * A listener that gets notified when the overscroll at the top has changed. |
| 5874 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5875 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5876 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 5877 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5878 | /** |
| 5879 | * Notifies a listener that the overscroll has changed. |
| 5880 | * |
| 5881 | * @param amount the amount of overscroll, in pixels |
| 5882 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 5883 | * unrubberbanded motion to directly expand overscroll view (e.g |
| 5884 | * expand |
| 5885 | * QS) |
| 5886 | */ |
| 5887 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 5888 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5889 | /** |
| 5890 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 5891 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 5892 | * |
| 5893 | * @param velocity The velocity that the Scroller had when over flinging |
| 5894 | * @param open Should the fling open or close the overscroll view. |
| 5895 | */ |
| 5896 | void flingTopOverscroll(float velocity, boolean open); |
| 5897 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5898 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5899 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5900 | public void updateSpeedBumpIndex() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5901 | int speedBumpIndex = 0; |
| 5902 | int currentIndex = 0; |
| 5903 | final int N = getChildCount(); |
| 5904 | for (int i = 0; i < N; i++) { |
| 5905 | View view = getChildAt(i); |
| 5906 | if (view.getVisibility() == View.GONE || !(view instanceof ExpandableNotificationRow)) { |
| 5907 | continue; |
| 5908 | } |
| 5909 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 5910 | currentIndex++; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5911 | boolean beforeSpeedBump; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5912 | if (mHighPriorityBeforeSpeedBump) { |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 5913 | beforeSpeedBump = row.getEntry().getBucket() < BUCKET_SILENT; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5914 | } else { |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 5915 | beforeSpeedBump = !row.getEntry().isAmbient(); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5916 | } |
| 5917 | if (beforeSpeedBump) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5918 | speedBumpIndex = currentIndex; |
| 5919 | } |
| 5920 | } |
| 5921 | boolean noAmbient = speedBumpIndex == N; |
| 5922 | updateSpeedBumpIndex(speedBumpIndex, noAmbient); |
| 5923 | } |
| 5924 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5925 | /** Updates the indices of the boundaries between sections. */ |
| 5926 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 5927 | public void updateSectionBoundaries(String reason) { |
| 5928 | mSectionsManager.updateSectionBoundaries(reason); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5929 | } |
| 5930 | |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5931 | private void updateContinuousBackgroundDrawing() { |
| 5932 | boolean continuousBackground = !mAmbientState.isFullyAwake() |
| 5933 | && !mAmbientState.getDraggedViews().isEmpty(); |
| 5934 | if (continuousBackground != mContinuousBackgroundUpdate) { |
| 5935 | mContinuousBackgroundUpdate = continuousBackground; |
| 5936 | if (continuousBackground) { |
| 5937 | getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater); |
| 5938 | } else { |
| 5939 | getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater); |
| 5940 | } |
| 5941 | } |
| 5942 | } |
| 5943 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5944 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5945 | private void updateContinuousShadowDrawing() { |
| 5946 | boolean continuousShadowUpdate = mAnimationRunning |
| 5947 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 5948 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 5949 | if (continuousShadowUpdate) { |
| 5950 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 5951 | } else { |
| 5952 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 5953 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 5954 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5955 | } |
| 5956 | } |
| 5957 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5958 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5959 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 5960 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 5961 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 5962 | } |
| 5963 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5964 | private static boolean matchesSelection( |
| 5965 | ExpandableNotificationRow row, |
| 5966 | @SelectedRows int selection) { |
| 5967 | switch (selection) { |
| 5968 | case ROWS_ALL: |
| 5969 | return true; |
| 5970 | case ROWS_HIGH_PRIORITY: |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 5971 | return row.getEntry().getBucket() < BUCKET_SILENT; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5972 | case ROWS_GENTLE: |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 5973 | return row.getEntry().getBucket() == BUCKET_SILENT; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5974 | default: |
| 5975 | throw new IllegalArgumentException("Unknown selection: " + selection); |
| 5976 | } |
| 5977 | } |
| 5978 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5979 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 5980 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5981 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5982 | static AnimationFilter[] FILTERS = new AnimationFilter[]{ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5983 | |
| 5984 | // ANIMATION_TYPE_ADD |
| 5985 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5986 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5987 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5988 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5989 | .animateZ() |
| 5990 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5991 | |
| 5992 | // ANIMATION_TYPE_REMOVE |
| 5993 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5994 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5995 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5996 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5997 | .animateZ() |
| 5998 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5999 | |
| 6000 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 6001 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6002 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 6003 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6004 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6005 | .animateZ() |
| 6006 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6007 | |
| 6008 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 6009 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6010 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 6011 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6012 | .animateY() |
| 6013 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6014 | .animateZ(), |
| 6015 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6016 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 6017 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 6018 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6019 | |
| 6020 | // ANIMATION_TYPE_DIMMED |
| 6021 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6022 | .animateDimmed(), |
| 6023 | |
| 6024 | // ANIMATION_TYPE_CHANGE_POSITION |
| 6025 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 6026 | .animateAlpha() // maybe the children change positions |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6027 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 6028 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6029 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 6030 | .animateZ(), |
| 6031 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6032 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 6033 | new AnimationFilter() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6034 | .animateHeight() |
| 6035 | .animateTopInset() |
| 6036 | .animateY() |
| 6037 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 6038 | .animateZ() |
| 6039 | .hasDelays(), |
| 6040 | |
| 6041 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 6042 | new AnimationFilter() |
| 6043 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 6044 | |
| 6045 | // ANIMATION_TYPE_VIEW_RESIZE |
| 6046 | new AnimationFilter() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 6047 | .animateHeight() |
| 6048 | .animateTopInset() |
| 6049 | .animateY() |
| 6050 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6051 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6052 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 6053 | new AnimationFilter() |
| 6054 | .animateAlpha() |
| 6055 | .animateHeight() |
| 6056 | .animateTopInset() |
| 6057 | .animateY() |
| 6058 | .animateZ(), |
| 6059 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6060 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 6061 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6062 | .animateHeight() |
| 6063 | .animateTopInset() |
| 6064 | .animateY() |
| 6065 | .animateZ(), |
| 6066 | |
| 6067 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 6068 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6069 | .animateHeight() |
| 6070 | .animateTopInset() |
| 6071 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 6072 | .animateZ() |
| 6073 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6074 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 6075 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 6076 | new AnimationFilter() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 6077 | .animateHeight() |
| 6078 | .animateTopInset() |
| 6079 | .animateY() |
| 6080 | .animateZ() |
| 6081 | .hasDelays(), |
| 6082 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6083 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 6084 | new AnimationFilter() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6085 | .animateHeight() |
| 6086 | .animateTopInset() |
| 6087 | .animateY() |
| 6088 | .animateZ(), |
| 6089 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6090 | // ANIMATION_TYPE_EVERYTHING |
| 6091 | new AnimationFilter() |
| 6092 | .animateAlpha() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6093 | .animateDimmed() |
| 6094 | .animateHideSensitive() |
| 6095 | .animateHeight() |
| 6096 | .animateTopInset() |
| 6097 | .animateY() |
| 6098 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6099 | }; |
| 6100 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6101 | static int[] LENGTHS = new int[]{ |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6102 | |
| 6103 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6104 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6105 | |
| 6106 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6107 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6108 | |
| 6109 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 6110 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6111 | |
| 6112 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 6113 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6114 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6115 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 6116 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 6117 | |
| 6118 | // ANIMATION_TYPE_DIMMED |
| 6119 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6120 | |
| 6121 | // ANIMATION_TYPE_CHANGE_POSITION |
| 6122 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 6123 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6124 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 6125 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 6126 | |
| 6127 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 6128 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 6129 | |
| 6130 | // ANIMATION_TYPE_VIEW_RESIZE |
| 6131 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6132 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6133 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 6134 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6135 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6136 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 6137 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 6138 | |
| 6139 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 6140 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6141 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 6142 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 6143 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6144 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6145 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 6146 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6147 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6148 | // ANIMATION_TYPE_EVERYTHING |
| 6149 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6150 | }; |
| 6151 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6152 | static final int ANIMATION_TYPE_ADD = 0; |
| 6153 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 6154 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 6155 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
Selim Cinek | ff2ffec | 2018-11-19 18:52:01 -0800 | [diff] [blame] | 6156 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 4; |
| 6157 | static final int ANIMATION_TYPE_DIMMED = 5; |
| 6158 | static final int ANIMATION_TYPE_CHANGE_POSITION = 6; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 6159 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 7; |
| 6160 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 8; |
| 6161 | static final int ANIMATION_TYPE_VIEW_RESIZE = 9; |
| 6162 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 10; |
| 6163 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 11; |
| 6164 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 12; |
| 6165 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 13; |
| 6166 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 14; |
| 6167 | static final int ANIMATION_TYPE_EVERYTHING = 15; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 6168 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6169 | final long eventStartTime; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6170 | final ExpandableView mChangingView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6171 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6172 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6173 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6174 | View viewAfterChangingView; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6175 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6176 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6177 | AnimationEvent(ExpandableView view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6178 | this(view, type, LENGTHS[type]); |
| 6179 | } |
| 6180 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6181 | AnimationEvent(ExpandableView view, int type, AnimationFilter filter) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6182 | this(view, type, LENGTHS[type], filter); |
| 6183 | } |
| 6184 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6185 | AnimationEvent(ExpandableView view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6186 | this(view, type, length, FILTERS[type]); |
| 6187 | } |
| 6188 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6189 | AnimationEvent(ExpandableView view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6190 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6191 | mChangingView = view; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6192 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6193 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6194 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6195 | } |
| 6196 | |
| 6197 | /** |
| 6198 | * Combines the length of several animation events into a single value. |
| 6199 | * |
| 6200 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6201 | * @return The combined length. Depending on the event types, this might be the maximum of |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6202 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6203 | */ |
| 6204 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 6205 | long length = 0; |
| 6206 | int size = events.size(); |
| 6207 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6208 | AnimationEvent event = events.get(i); |
| 6209 | length = Math.max(length, event.length); |
| 6210 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 6211 | return event.length; |
| 6212 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6213 | } |
| 6214 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6215 | } |
| 6216 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6217 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6218 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 6219 | private final StateListener mStateListener = new StateListener() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6220 | @Override |
| 6221 | public void onStatePreChange(int oldState, int newState) { |
| 6222 | if (oldState == StatusBarState.SHADE_LOCKED && newState == StatusBarState.KEYGUARD) { |
| 6223 | requestAnimateEverything(); |
| 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | @Override |
| 6228 | public void onStateChanged(int newState) { |
| 6229 | setStatusBarState(newState); |
| 6230 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6231 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6232 | @Override |
| 6233 | public void onStatePostChange() { |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6234 | NotificationStackScrollLayout.this.onStatePostChange(); |
| 6235 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6236 | }; |
| 6237 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6238 | @VisibleForTesting |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6239 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6240 | protected final OnMenuEventListener mMenuEventListener = new OnMenuEventListener() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6241 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6242 | public void onMenuClicked(View view, int x, int y, MenuItem item) { |
| 6243 | if (mLongPressListener == null) { |
| 6244 | return; |
| 6245 | } |
| 6246 | if (view instanceof ExpandableNotificationRow) { |
| 6247 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6248 | mMetricsLogger.write(row.getEntry().getSbn().getLogMaker() |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6249 | .setCategory(MetricsEvent.ACTION_TOUCH_GEAR) |
| 6250 | .setType(MetricsEvent.TYPE_ACTION) |
| 6251 | ); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6252 | } |
| 6253 | mLongPressListener.onLongPress(view, x, y, item); |
| 6254 | } |
| 6255 | |
| 6256 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6257 | public void onMenuReset(View row) { |
| 6258 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 6259 | if (translatingParentView != null && row == translatingParentView) { |
| 6260 | mSwipeHelper.clearExposedMenuView(); |
| 6261 | mSwipeHelper.clearTranslatingParentView(); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6262 | if (row instanceof ExpandableNotificationRow) { |
| 6263 | mHeadsUpManager.setMenuShown( |
| 6264 | ((ExpandableNotificationRow) row).getEntry(), false); |
| 6265 | |
| 6266 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6271 | public void onMenuShown(View row) { |
| 6272 | if (row instanceof ExpandableNotificationRow) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6273 | ExpandableNotificationRow notificationRow = (ExpandableNotificationRow) row; |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6274 | mMetricsLogger.write(notificationRow.getEntry().getSbn().getLogMaker() |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6275 | .setCategory(MetricsEvent.ACTION_REVEAL_GEAR) |
| 6276 | .setType(MetricsEvent.TYPE_ACTION)); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6277 | mHeadsUpManager.setMenuShown(notificationRow.getEntry(), true); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6278 | mSwipeHelper.onMenuShown(row); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6279 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6280 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6281 | false /* resetMenu */); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6282 | |
| 6283 | // Check to see if we want to go directly to the notfication guts |
| 6284 | NotificationMenuRowPlugin provider = notificationRow.getProvider(); |
| 6285 | if (provider.shouldShowGutsOnSnapOpen()) { |
| 6286 | MenuItem item = provider.menuItemToExposeOnSnap(); |
| 6287 | if (item != null) { |
| 6288 | Point origin = provider.getRevealAnimationOrigin(); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6289 | mNotificationGutsManager.openGuts(row, origin.x, origin.y, item); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6290 | } else { |
| 6291 | Log.e(TAG, "Provider has shouldShowGutsOnSnapOpen, but provided no " |
| 6292 | + "menu item in menuItemtoExposeOnSnap. Skipping."); |
| 6293 | } |
| 6294 | |
| 6295 | // Close the menu row since we went directly to the guts |
| 6296 | resetExposedMenuView(false, true); |
| 6297 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6298 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6299 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6300 | }; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6301 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6302 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6303 | private final NotificationSwipeHelper.NotificationCallback mNotificationCallback = |
| 6304 | new NotificationSwipeHelper.NotificationCallback() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6305 | @Override |
| 6306 | public void onDismiss() { |
| 6307 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6308 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6309 | false /* resetMenu */); |
| 6310 | } |
| 6311 | |
| 6312 | @Override |
| 6313 | public void onSnooze(StatusBarNotification sbn, |
| 6314 | NotificationSwipeActionHelper.SnoozeOption snoozeOption) { |
| 6315 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
| 6316 | } |
| 6317 | |
| 6318 | @Override |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 6319 | public void onSnooze(StatusBarNotification sbn, int hours) { |
| 6320 | mStatusBar.setNotificationSnoozed(sbn, hours); |
| 6321 | } |
| 6322 | |
| 6323 | @Override |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6324 | public boolean shouldDismissQuickly() { |
| 6325 | return NotificationStackScrollLayout.this.isExpanded() && mAmbientState.isFullyAwake(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6326 | } |
| 6327 | |
| 6328 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6329 | public void onDragCancelled(View v) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6330 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6331 | mFalsingManager.onNotificatonStopDismissing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | /** |
| 6335 | * Handles cleanup after the given {@code view} has been fully swiped out (including |
| 6336 | * re-invoking dismiss logic in case the notification has not made its way out yet). |
| 6337 | */ |
| 6338 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6339 | public void onChildDismissed(View view) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6340 | if (!(view instanceof ActivatableNotificationView)) { |
| 6341 | return; |
| 6342 | } |
| 6343 | ActivatableNotificationView row = (ActivatableNotificationView) view; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6344 | if (!row.isDismissed()) { |
| 6345 | handleChildViewDismissed(view); |
| 6346 | } |
| 6347 | ViewGroup transientContainer = row.getTransientContainer(); |
| 6348 | if (transientContainer != null) { |
| 6349 | transientContainer.removeTransientView(view); |
| 6350 | } |
| 6351 | } |
| 6352 | |
| 6353 | /** |
| 6354 | * Starts up notification dismiss and tells the notification, if any, to remove itself from |
| 6355 | * layout. |
| 6356 | * |
| 6357 | * @param view view (e.g. notification) to dismiss from the layout |
| 6358 | */ |
| 6359 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6360 | public void handleChildViewDismissed(View view) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6361 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6362 | if (mDismissAllInProgress) { |
| 6363 | return; |
| 6364 | } |
| 6365 | |
| 6366 | boolean isBlockingHelperShown = false; |
| 6367 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6368 | mAmbientState.onDragFinished(view); |
| 6369 | updateContinuousShadowDrawing(); |
| 6370 | |
| 6371 | if (view instanceof ExpandableNotificationRow) { |
| 6372 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6373 | if (row.isHeadsUp()) { |
| 6374 | mHeadsUpManager.addSwipedOutNotification( |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6375 | row.getEntry().getSbn().getKey()); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6376 | } |
| 6377 | isBlockingHelperShown = |
| 6378 | row.performDismissWithBlockingHelper(false /* fromAccessibility */); |
| 6379 | } |
| 6380 | |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6381 | if (view instanceof PeopleHubView) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6382 | mSectionsManager.hidePeopleRow(); |
| 6383 | } |
| 6384 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6385 | if (!isBlockingHelperShown) { |
| 6386 | mSwipedOutViews.add(view); |
| 6387 | } |
| 6388 | mFalsingManager.onNotificationDismissed(); |
| 6389 | if (mFalsingManager.shouldEnforceBouncer()) { |
| 6390 | mStatusBar.executeRunnableDismissingKeyguard( |
| 6391 | null, |
| 6392 | null /* cancelAction */, |
| 6393 | false /* dismissShade */, |
| 6394 | true /* afterKeyguardGone */, |
| 6395 | false /* deferred */); |
| 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6400 | public boolean isAntiFalsingNeeded() { |
| 6401 | return onKeyguard(); |
| 6402 | } |
| 6403 | |
| 6404 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6405 | public View getChildAtPosition(MotionEvent ev) { |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 6406 | View child = NotificationStackScrollLayout.this.getChildAtPosition( |
| 6407 | ev.getX(), |
| 6408 | ev.getY(), |
| 6409 | true /* requireMinHeight */, |
| 6410 | false /* ignoreDecors */); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6411 | if (child instanceof ExpandableNotificationRow) { |
| 6412 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 6413 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 6414 | if (parent != null && parent.areChildrenExpanded() |
| 6415 | && (parent.areGutsExposed() |
| 6416 | || mSwipeHelper.getExposedMenuView() == parent |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 6417 | || (parent.getAttachedChildren().size() == 1 |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 6418 | && parent.getEntry().isClearable()))) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6419 | // In this case the group is expanded and showing the menu for the |
| 6420 | // group, further interaction should apply to the group, not any |
| 6421 | // child notifications so we use the parent of the child. We also do the same |
| 6422 | // if we only have a single child. |
| 6423 | child = parent; |
| 6424 | } |
| 6425 | } |
| 6426 | return child; |
| 6427 | } |
| 6428 | |
| 6429 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6430 | public void onBeginDrag(View v) { |
| 6431 | mFalsingManager.onNotificatonStartDismissing(); |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6432 | setSwipingInProgress(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6433 | mAmbientState.onBeginDrag((ExpandableView) v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6434 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6435 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6436 | requestChildrenUpdate(); |
| 6437 | } |
| 6438 | |
| 6439 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6440 | public void onChildSnappedBack(View animView, float targetLeft) { |
| 6441 | mAmbientState.onDragFinished(animView); |
| 6442 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6443 | updateContinuousBackgroundDrawing(); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 6444 | if (animView instanceof ExpandableNotificationRow) { |
| 6445 | ExpandableNotificationRow row = (ExpandableNotificationRow) animView; |
| 6446 | if (row.isPinned() && !canChildBeDismissed(row) |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6447 | && row.getEntry().getSbn().getNotification().fullScreenIntent |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 6448 | == null) { |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6449 | mHeadsUpManager.removeNotification(row.getEntry().getSbn().getKey(), |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 6450 | true /* removeImmediately */); |
| 6451 | } |
| 6452 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6456 | public boolean updateSwipeProgress(View animView, boolean dismissable, |
| 6457 | float swipeProgress) { |
| 6458 | // Returning true prevents alpha fading. |
| 6459 | return !mFadeNotificationsOnDismiss; |
| 6460 | } |
| 6461 | |
| 6462 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6463 | public float getFalsingThresholdFactor() { |
| 6464 | return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
| 6465 | } |
| 6466 | |
| 6467 | @Override |
Gus Prevas | c4e68d4 | 2019-01-17 15:45:21 -0500 | [diff] [blame] | 6468 | public int getConstrainSwipeStartPosition() { |
| 6469 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 6470 | if (menuRow != null) { |
| 6471 | return Math.abs(menuRow.getMenuSnapTarget()); |
| 6472 | } |
| 6473 | return 0; |
| 6474 | } |
| 6475 | |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6476 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6477 | public boolean canChildBeDismissed(View v) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6478 | return NotificationStackScrollLayout.canChildBeDismissed(v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6479 | } |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6480 | |
| 6481 | @Override |
| 6482 | public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) { |
Evan Laird | 30b9b16 | 2019-04-24 15:22:24 -0400 | [diff] [blame] | 6483 | //TODO: b/131242807 for why this doesn't do anything with direction |
| 6484 | return canChildBeDismissed(v); |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6485 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6486 | }; |
| 6487 | |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6488 | private static boolean canChildBeDismissed(View v) { |
| 6489 | if (v instanceof ExpandableNotificationRow) { |
| 6490 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6491 | if (row.isBlockingHelperShowingAndTranslationFinished()) { |
| 6492 | return true; |
| 6493 | } |
| 6494 | if (row.areGutsExposed() || !row.getEntry().hasFinishedInitialization()) { |
| 6495 | return false; |
| 6496 | } |
| 6497 | return row.canViewBeDismissed(); |
| 6498 | } |
| 6499 | if (v instanceof PeopleHubView) { |
| 6500 | return true; |
| 6501 | } |
| 6502 | return false; |
| 6503 | } |
| 6504 | |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 6505 | // --------------------- NotificationEntryManager/NotifPipeline methods ------------------------ |
| 6506 | |
| 6507 | private void onEntryUpdated(NotificationEntry entry) { |
| 6508 | // If the row already exists, the user may have performed a dismiss action on the |
| 6509 | // notification. Since it's not clearable we should snap it back. |
| 6510 | if (entry.rowExists() && !entry.getSbn().isClearable()) { |
| 6511 | snapViewIfNeeded(entry); |
| 6512 | } |
| 6513 | } |
| 6514 | |
| 6515 | private boolean hasActiveNotifications() { |
| 6516 | if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { |
Kevin Han | 4943b86 | 2020-03-23 17:14:39 -0700 | [diff] [blame] | 6517 | return !mNotifPipeline.getShadeList().isEmpty(); |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 6518 | } else { |
| 6519 | return mEntryManager.hasActiveNotifications(); |
| 6520 | } |
| 6521 | } |
| 6522 | |
| 6523 | /** |
| 6524 | * Called after the animations for a "clear all notifications" action has ended. |
| 6525 | */ |
| 6526 | private void onDismissAllAnimationsEnd( |
| 6527 | List<ExpandableNotificationRow> viewsToRemove, |
| 6528 | @SelectedRows int selectedRows) { |
| 6529 | if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { |
| 6530 | if (selectedRows == ROWS_ALL) { |
| 6531 | mNotifCollection.dismissAllNotifications(mLockscreenUserManager.getCurrentUserId()); |
| 6532 | } else { |
| 6533 | final List<Pair<NotificationEntry, DismissedByUserStats>> |
| 6534 | entriesWithRowsDismissedFromShade = new ArrayList<>(); |
| 6535 | final List<DismissedByUserStats> dismissalUserStats = new ArrayList<>(); |
| 6536 | final int numVisibleEntries = mNotifPipeline.getShadeListCount(); |
| 6537 | for (int i = 0; i < viewsToRemove.size(); i++) { |
| 6538 | final NotificationEntry entry = viewsToRemove.get(i).getEntry(); |
| 6539 | final DismissedByUserStats stats = |
| 6540 | new DismissedByUserStats( |
| 6541 | DISMISSAL_SHADE, |
| 6542 | DISMISS_SENTIMENT_NEUTRAL, |
| 6543 | NotificationVisibility.obtain( |
| 6544 | entry.getKey(), |
| 6545 | entry.getRanking().getRank(), |
| 6546 | numVisibleEntries, |
| 6547 | true, |
| 6548 | NotificationLogger.getNotificationLocation(entry))); |
| 6549 | entriesWithRowsDismissedFromShade.add( |
| 6550 | new Pair<NotificationEntry, DismissedByUserStats>(entry, stats)); |
| 6551 | } |
| 6552 | mNotifCollection.dismissNotifications(entriesWithRowsDismissedFromShade); |
| 6553 | } |
| 6554 | } else { |
| 6555 | for (ExpandableNotificationRow rowToRemove : viewsToRemove) { |
| 6556 | if (canChildBeDismissed(rowToRemove)) { |
| 6557 | if (selectedRows == ROWS_ALL) { |
| 6558 | // TODO: This is a listener method; we shouldn't be calling it. Can we just |
| 6559 | // call performRemoveNotification as below? |
| 6560 | mEntryManager.removeNotification( |
| 6561 | rowToRemove.getEntry().getKey(), |
| 6562 | null /* ranking */, |
| 6563 | NotificationListenerService.REASON_CANCEL_ALL); |
| 6564 | } else { |
| 6565 | mEntryManager.performRemoveNotification( |
| 6566 | rowToRemove.getEntry().getSbn(), |
| 6567 | NotificationListenerService.REASON_CANCEL_ALL); |
| 6568 | } |
| 6569 | } else { |
| 6570 | rowToRemove.resetTranslation(); |
| 6571 | } |
| 6572 | } |
| 6573 | if (selectedRows == ROWS_ALL) { |
| 6574 | try { |
| 6575 | mBarService.onClearAllNotifications(mLockscreenUserManager.getCurrentUserId()); |
| 6576 | } catch (Exception ex) { |
| 6577 | } |
| 6578 | } |
| 6579 | } |
| 6580 | } |
| 6581 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6582 | // ---------------------- DragDownHelper.OnDragDownListener ------------------------------------ |
| 6583 | |
| 6584 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6585 | private final DragDownCallback mDragDownCallback = new DragDownCallback() { |
| 6586 | |
| 6587 | /* Only ever called as a consequence of a lockscreen expansion gesture. */ |
| 6588 | @Override |
| 6589 | public boolean onDraggedDown(View startingChild, int dragLengthY) { |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 6590 | if (mStatusBarState == StatusBarState.KEYGUARD && hasActiveNotifications()) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6591 | mLockscreenGestureLogger.write( |
| 6592 | MetricsEvent.ACTION_LS_SHADE, |
| 6593 | (int) (dragLengthY / mDisplayMetrics.density), |
| 6594 | 0 /* velocityDp - N/A */); |
| 6595 | |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 6596 | if (!mAmbientState.isDozing() || startingChild != null) { |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6597 | // We have notifications, go to locked shade. |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 6598 | Dependency.get(ShadeController.class).goToLockedShade(startingChild); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6599 | if (startingChild instanceof ExpandableNotificationRow) { |
| 6600 | ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild; |
| 6601 | row.onExpandedByGesture(true /* drag down is always an open */); |
| 6602 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6603 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6604 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6605 | return true; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 6606 | } else if (mDynamicPrivacyController.isInLockedDownShade()) { |
| 6607 | mStatusbarStateController.setLeaveOpenOnKeyguardHide(true); |
| 6608 | mStatusBar.dismissKeyguardThenExecute(() -> false /* dismissAction */, |
| 6609 | null /* cancelRunnable */, false /* afterKeyguardGone */); |
| 6610 | return true; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6611 | } else { |
| 6612 | // abort gesture. |
| 6613 | return false; |
| 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | @Override |
| 6618 | public void onDragDownReset() { |
| 6619 | setDimmed(true /* dimmed */, true /* animated */); |
| 6620 | resetScrollPosition(); |
| 6621 | resetCheckSnoozeLeavebehind(); |
| 6622 | } |
| 6623 | |
| 6624 | @Override |
| 6625 | public void onCrossedThreshold(boolean above) { |
| 6626 | setDimmed(!above /* dimmed */, true /* animate */); |
| 6627 | } |
| 6628 | |
| 6629 | @Override |
| 6630 | public void onTouchSlopExceeded() { |
| 6631 | cancelLongPress(); |
| 6632 | checkSnoozeLeavebehind(); |
| 6633 | } |
| 6634 | |
| 6635 | @Override |
| 6636 | public void setEmptyDragAmount(float amount) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 6637 | mNotificationPanelController.setEmptyDragAmount(amount); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6638 | } |
| 6639 | |
| 6640 | @Override |
| 6641 | public boolean isFalsingCheckNeeded() { |
| 6642 | return mStatusBarState == StatusBarState.KEYGUARD; |
| 6643 | } |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 6644 | |
| 6645 | @Override |
| 6646 | public boolean isDragDownEnabledForView(ExpandableView view) { |
| 6647 | if (isDragDownAnywhereEnabled()) { |
| 6648 | return true; |
| 6649 | } |
| 6650 | if (mDynamicPrivacyController.isInLockedDownShade()) { |
| 6651 | if (view == null) { |
| 6652 | // Dragging down is allowed in general |
| 6653 | return true; |
| 6654 | } |
| 6655 | if (view instanceof ExpandableNotificationRow) { |
| 6656 | // Only drag down on sensitive views, otherwise the ExpandHelper will take this |
| 6657 | return ((ExpandableNotificationRow) view).getEntry().isSensitive(); |
| 6658 | } |
| 6659 | } |
| 6660 | return false; |
| 6661 | } |
| 6662 | |
| 6663 | @Override |
| 6664 | public boolean isDragDownAnywhereEnabled() { |
| 6665 | return mStatusbarStateController.getState() == StatusBarState.KEYGUARD |
| 6666 | && !mKeyguardBypassController.getBypassEnabled(); |
| 6667 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6668 | }; |
| 6669 | |
| 6670 | public DragDownCallback getDragDownCallback() { return mDragDownCallback; } |
| 6671 | |
| 6672 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6673 | private final HeadsUpTouchHelper.Callback mHeadsUpCallback = new HeadsUpTouchHelper.Callback() { |
| 6674 | @Override |
| 6675 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6676 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6677 | } |
| 6678 | |
| 6679 | @Override |
| 6680 | public boolean isExpanded() { |
| 6681 | return mIsExpanded; |
| 6682 | } |
| 6683 | |
| 6684 | @Override |
| 6685 | public Context getContext() { |
| 6686 | return mContext; |
| 6687 | } |
| 6688 | }; |
| 6689 | |
| 6690 | public HeadsUpTouchHelper.Callback getHeadsUpCallback() { return mHeadsUpCallback; } |
| 6691 | |
| 6692 | |
| 6693 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6694 | private final OnGroupChangeListener mOnGroupChangeListener = new OnGroupChangeListener() { |
| 6695 | @Override |
| 6696 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
| 6697 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 6698 | && (mIsExpanded || changedRow.isPinned()); |
| 6699 | if (animated) { |
| 6700 | mExpandedGroupView = changedRow; |
| 6701 | mNeedsAnimation = true; |
| 6702 | } |
| 6703 | changedRow.setChildrenExpanded(expanded, animated); |
| 6704 | if (!mGroupExpandedForMeasure) { |
| 6705 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 6706 | } |
| 6707 | runAfterAnimationFinished(new Runnable() { |
| 6708 | @Override |
| 6709 | public void run() { |
| 6710 | changedRow.onFinishedExpansionChange(); |
| 6711 | } |
| 6712 | }); |
| 6713 | } |
| 6714 | |
| 6715 | @Override |
| 6716 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 6717 | mStatusBar.requestNotificationUpdate("onGroupCreatedFromChildren"); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | @Override |
| 6721 | public void onGroupsChanged() { |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 6722 | mStatusBar.requestNotificationUpdate("onGroupsChanged"); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6723 | } |
| 6724 | }; |
| 6725 | |
| 6726 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6727 | private ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { |
| 6728 | @Override |
| 6729 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
| 6730 | return NotificationStackScrollLayout.this.getChildAtPosition(touchX, touchY); |
| 6731 | } |
| 6732 | |
| 6733 | @Override |
| 6734 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6735 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6736 | } |
| 6737 | |
| 6738 | @Override |
| 6739 | public boolean canChildBeExpanded(View v) { |
| 6740 | return v instanceof ExpandableNotificationRow |
| 6741 | && ((ExpandableNotificationRow) v).isExpandable() |
| 6742 | && !((ExpandableNotificationRow) v).areGutsExposed() |
| 6743 | && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned()); |
| 6744 | } |
| 6745 | |
| 6746 | /* Only ever called as a consequence of an expansion gesture in the shade. */ |
| 6747 | @Override |
| 6748 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 6749 | if (v instanceof ExpandableNotificationRow) { |
| 6750 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6751 | if (userExpanded && onKeyguard()) { |
| 6752 | // Due to a race when locking the screen while touching, a notification may be |
| 6753 | // expanded even after we went back to keyguard. An example of this happens if |
| 6754 | // you click in the empty space while expanding a group. |
| 6755 | |
| 6756 | // We also need to un-user lock it here, since otherwise the content height |
| 6757 | // calculated might be wrong. We also can't invert the two calls since |
| 6758 | // un-userlocking it will trigger a layout switch in the content view. |
| 6759 | row.setUserLocked(false); |
| 6760 | updateContentHeight(); |
| 6761 | notifyHeightChangeListener(row); |
| 6762 | return; |
| 6763 | } |
| 6764 | row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */); |
| 6765 | row.onExpandedByGesture(userExpanded); |
| 6766 | } |
| 6767 | } |
| 6768 | |
| 6769 | @Override |
| 6770 | public void setExpansionCancelled(View v) { |
| 6771 | if (v instanceof ExpandableNotificationRow) { |
| 6772 | ((ExpandableNotificationRow) v).setGroupExpansionChanging(false); |
| 6773 | } |
| 6774 | } |
| 6775 | |
| 6776 | @Override |
| 6777 | public void setUserLockedChild(View v, boolean userLocked) { |
| 6778 | if (v instanceof ExpandableNotificationRow) { |
| 6779 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 6780 | } |
| 6781 | cancelLongPress(); |
| 6782 | requestDisallowInterceptTouchEvent(true); |
| 6783 | } |
| 6784 | |
| 6785 | @Override |
| 6786 | public void expansionStateChanged(boolean isExpanding) { |
| 6787 | mExpandingNotification = isExpanding; |
| 6788 | if (!mExpandedInThisMotion) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 6789 | if (ANCHOR_SCROLLING) { |
| 6790 | // TODO |
| 6791 | } else { |
| 6792 | mMaxScrollAfterExpand = mOwnScrollY; |
| 6793 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6794 | mExpandedInThisMotion = true; |
| 6795 | } |
| 6796 | } |
| 6797 | |
| 6798 | @Override |
| 6799 | public int getMaxExpandHeight(ExpandableView view) { |
| 6800 | return view.getMaxContentHeight(); |
| 6801 | } |
| 6802 | }; |
| 6803 | |
| 6804 | public ExpandHelper.Callback getExpandHelperCallback() { |
| 6805 | return mExpandHelperCallback; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6806 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6807 | |
| 6808 | /** Enum for selecting some or all notification rows (does not included non-notif views). */ |
| 6809 | @Retention(SOURCE) |
| 6810 | @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE}) |
| 6811 | public @interface SelectedRows {} |
| 6812 | /** All rows representing notifs. */ |
| 6813 | public static final int ROWS_ALL = 0; |
| 6814 | /** Only rows where entry.isHighPriority() is true. */ |
| 6815 | public static final int ROWS_HIGH_PRIORITY = 1; |
| 6816 | /** Only rows where entry.isHighPriority() is false. */ |
| 6817 | public static final int ROWS_GENTLE = 2; |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 6818 | |
| 6819 | /** |
| 6820 | * Enum for UiEvent logged from this class |
| 6821 | */ |
| 6822 | enum NotificationPanelEvent implements UiEventLogger.UiEventEnum { |
| 6823 | INVALID(0), |
| 6824 | @UiEvent(doc = "User dismissed all notifications from notification panel.") |
| 6825 | DISMISS_ALL_NOTIFICATIONS_PANEL(312), |
| 6826 | @UiEvent(doc = "User dismissed all silent notifications from notification panel.") |
| 6827 | DISMISS_SILENT_NOTIFICATIONS_PANEL(314); |
| 6828 | private final int mId; |
| 6829 | NotificationPanelEvent(int id) { |
| 6830 | mId = id; |
| 6831 | } |
| 6832 | @Override public int getId() { |
| 6833 | return mId; |
| 6834 | } |
| 6835 | |
| 6836 | public static UiEventLogger.UiEventEnum fromSelection(@SelectedRows int selection) { |
| 6837 | if (selection == ROWS_ALL) { |
| 6838 | return DISMISS_ALL_NOTIFICATIONS_PANEL; |
| 6839 | } |
| 6840 | if (selection == ROWS_GENTLE) { |
| 6841 | return DISMISS_SILENT_NOTIFICATIONS_PANEL; |
| 6842 | } |
| 6843 | if (NotificationStackScrollLayout.DEBUG) { |
| 6844 | throw new IllegalArgumentException("Unexpected selection" + selection); |
| 6845 | } |
| 6846 | return INVALID; |
| 6847 | } |
| 6848 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 6849 | } |