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 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 19 | import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 20 | import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 22 | import static com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.ANCHOR_SCROLLING; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_SWIPE; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 24 | import static com.android.systemui.statusbar.phone.NotificationIconAreaController.HIGH_PRIORITY; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 25 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 26 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 27 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 28 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 29 | import android.animation.Animator; |
| 30 | import android.animation.AnimatorListenerAdapter; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 31 | import android.animation.TimeAnimator; |
| 32 | import android.animation.ValueAnimator; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 33 | import android.annotation.IntDef; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 34 | import android.annotation.NonNull; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 35 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 36 | import android.content.Context; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 37 | import android.content.Intent; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 38 | import android.content.pm.UserInfo; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 39 | import android.content.res.Configuration; |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 40 | import android.content.res.Resources; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 41 | import android.graphics.Canvas; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 42 | import android.graphics.Color; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 43 | import android.graphics.Outline; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 44 | import android.graphics.Paint; |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 45 | import android.graphics.Point; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 46 | import android.graphics.PointF; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 47 | import android.graphics.PorterDuff; |
| 48 | import android.graphics.PorterDuffXfermode; |
| 49 | import android.graphics.Rect; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 51 | import android.os.ServiceManager; |
| 52 | import android.provider.Settings; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 53 | import android.service.notification.NotificationListenerService; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 54 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 55 | import android.util.AttributeSet; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 56 | import android.util.DisplayMetrics; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 57 | import android.util.Log; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 58 | import android.util.MathUtils; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 59 | import android.util.Pair; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 60 | import android.util.SparseArray; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 61 | import android.view.ContextThemeWrapper; |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 62 | import android.view.InputDevice; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 63 | import android.view.LayoutInflater; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 64 | import android.view.MotionEvent; |
| 65 | import android.view.VelocityTracker; |
| 66 | import android.view.View; |
| 67 | import android.view.ViewConfiguration; |
| 68 | import android.view.ViewGroup; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 69 | import android.view.ViewOutlineProvider; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 70 | import android.view.ViewTreeObserver; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 71 | import android.view.WindowInsets; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 72 | import android.view.accessibility.AccessibilityEvent; |
| 73 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 74 | import android.view.animation.AnimationUtils; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 75 | import android.view.animation.Interpolator; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 76 | import android.widget.OverScroller; |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 77 | import android.widget.ScrollView; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 78 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 79 | import com.android.internal.annotations.VisibleForTesting; |
| 80 | import com.android.internal.graphics.ColorUtils; |
Mady Mellor | a41587b | 2016-02-11 18:43:06 -0800 | [diff] [blame] | 81 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 82 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 83 | import com.android.internal.statusbar.IStatusBarService; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 84 | import com.android.keyguard.KeyguardSliceView; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 85 | import com.android.settingslib.Utils; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 86 | import com.android.systemui.Dependency; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 87 | import com.android.systemui.Dumpable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 88 | import com.android.systemui.ExpandHelper; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 89 | import com.android.systemui.Interpolators; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 90 | import com.android.systemui.R; |
| 91 | import com.android.systemui.SwipeHelper; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 92 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Dave Mankoff | 468d4f6 | 2019-05-08 14:56:29 -0400 | [diff] [blame] | 93 | import com.android.systemui.plugins.FalsingManager; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 94 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
| 95 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 96 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.OnMenuEventListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 97 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 98 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 99 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 100 | import com.android.systemui.statusbar.CommandQueue; |
| 101 | import com.android.systemui.statusbar.DragDownHelper.DragDownCallback; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 102 | import com.android.systemui.statusbar.EmptyShadeView; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 103 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 104 | import com.android.systemui.statusbar.NotificationLockscreenUserManager.UserChangedListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 105 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 106 | import com.android.systemui.statusbar.NotificationShelf; |
| 107 | import com.android.systemui.statusbar.RemoteInputController; |
| 108 | import com.android.systemui.statusbar.StatusBarState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 109 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 110 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 111 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 112 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 113 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 114 | import com.android.systemui.statusbar.notification.NotificationUtils; |
| 115 | import com.android.systemui.statusbar.notification.ShadeViewRefactor; |
| 116 | import com.android.systemui.statusbar.notification.ShadeViewRefactor.RefactorComponent; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 117 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 118 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 119 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 120 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 121 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 122 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 123 | import com.android.systemui.statusbar.notification.row.FooterView; |
| 124 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 125 | import com.android.systemui.statusbar.notification.row.NotificationGuts; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 126 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 127 | import com.android.systemui.statusbar.notification.row.NotificationSnooze; |
| 128 | import com.android.systemui.statusbar.notification.row.StackScrollerDecorView; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 129 | import com.android.systemui.statusbar.phone.HeadsUpAppearanceController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 130 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 131 | import com.android.systemui.statusbar.phone.HeadsUpTouchHelper; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 132 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 133 | import com.android.systemui.statusbar.phone.LockscreenGestureLogger; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 134 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 135 | import com.android.systemui.statusbar.phone.NotificationGroupManager.OnGroupChangeListener; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 136 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 137 | import com.android.systemui.statusbar.phone.NotificationPanelViewController; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 138 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 139 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 140 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 141 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 142 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 143 | import com.android.systemui.statusbar.policy.HeadsUpUtil; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 144 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 145 | import com.android.systemui.statusbar.policy.ZenModeController; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 146 | import com.android.systemui.tuner.TunerService; |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 147 | import com.android.systemui.util.Assert; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 148 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 149 | import java.io.FileDescriptor; |
| 150 | import java.io.PrintWriter; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 151 | import java.lang.annotation.Retention; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 152 | import java.util.ArrayList; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 153 | import java.util.Collections; |
| 154 | import java.util.Comparator; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 155 | import java.util.HashSet; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 156 | import java.util.List; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 157 | import java.util.function.BiConsumer; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 158 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 159 | import javax.inject.Inject; |
| 160 | import javax.inject.Named; |
| 161 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 162 | /** |
| 163 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 164 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 165 | public class NotificationStackScrollLayout extends ViewGroup implements ScrollAdapter, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 166 | NotificationListContainer, ConfigurationListener, Dumpable, |
| 167 | DynamicPrivacyController.Listener { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 168 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 169 | public static final float BACKGROUND_ALPHA_DIMMED = 0.7f; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 170 | private static final String TAG = "StackScroller"; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 171 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 172 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 173 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 174 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 175 | /** |
| 176 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 177 | */ |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 178 | private static final int INVALID_POINTER = -1; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 179 | /** |
| 180 | * The distance in pixels between sections when the sections are directly adjacent (no visible |
| 181 | * gap is drawn between them). In this case we don't want to round their corners. |
| 182 | */ |
| 183 | private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 184 | private final KeyguardBypassController mKeyguardBypassController; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 185 | private final DynamicPrivacyController mDynamicPrivacyController; |
| 186 | private final SysuiStatusBarStateController mStatusbarStateController; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 187 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 188 | private ExpandHelper mExpandHelper; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 189 | private final NotificationSwipeHelper mSwipeHelper; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 190 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 191 | private final Paint mBackgroundPaint = new Paint(); |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 192 | private final boolean mShouldDrawNotificationBackground; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 193 | private boolean mHighPriorityBeforeSpeedBump; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 194 | private final boolean mAllowLongPress; |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 195 | private boolean mDismissRtl; |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 196 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 197 | private float mExpandedHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 198 | private int mOwnScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 199 | private View mScrollAnchorView; |
| 200 | private int mScrollAnchorViewY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 201 | private int mMaxLayoutHeight; |
| 202 | |
| 203 | private VelocityTracker mVelocityTracker; |
| 204 | private OverScroller mScroller; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 205 | /** Last Y position reported by {@link #mScroller}, used to calculate scroll delta. */ |
| 206 | private int mLastScrollerY; |
| 207 | /** |
| 208 | * True if the max position was set to a known position on the last call to {@link #mScroller}. |
| 209 | */ |
| 210 | private boolean mIsScrollerBoundSet; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 211 | private Runnable mFinishScrollingCallback; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 212 | private int mTouchSlop; |
| 213 | private int mMinimumVelocity; |
| 214 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 215 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 216 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 217 | private boolean mIsBeingDragged; |
| 218 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 219 | private int mDownX; |
Dong-wan Kim | b926666 | 2016-09-21 13:08:30 -0700 | [diff] [blame] | 220 | private int mActivePointerId = INVALID_POINTER; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 221 | private boolean mTouchIsClick; |
| 222 | private float mInitialTouchX; |
| 223 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 224 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 225 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 226 | private int mContentHeight; |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 227 | private int mIntrinsicContentHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 228 | private int mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 229 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 230 | private int mIncreasedPaddingBetweenElements; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 231 | private int mMaxTopPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 232 | private int mTopPadding; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 233 | private int mBottomMargin; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 234 | private int mBottomInset = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 235 | private float mQsExpansionFraction; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * The algorithm which calculates the properties for our children |
| 239 | */ |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 240 | protected final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 241 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 242 | private final AmbientState mAmbientState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 243 | private NotificationGroupManager mGroupManager; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 244 | private HashSet<ExpandableView> mChildrenToAddAnimated = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 245 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 246 | private ArrayList<ExpandableView> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 247 | private ArrayList<ExpandableView> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 248 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 249 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 250 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 251 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 252 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 253 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 254 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 255 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 256 | /** |
| 257 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 258 | */ |
| 259 | private float mOverScrolledTopPixels; |
| 260 | |
| 261 | /** |
| 262 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 263 | */ |
| 264 | private float mOverScrolledBottomPixels; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 265 | private NotificationLogger.OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 266 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 267 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 268 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 269 | private boolean mNeedsAnimation; |
| 270 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 271 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 272 | private boolean mHideSensitiveNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 273 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 274 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 275 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 276 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 277 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 278 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 279 | private boolean mExpandingNotification; |
| 280 | private boolean mExpandedInThisMotion; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 281 | private boolean mShouldShowShelfOnly; |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 282 | protected boolean mScrollingEnabled; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 283 | protected FooterView mFooterView; |
Muyuan Li | dd9ae75 | 2016-05-13 16:45:43 -0700 | [diff] [blame] | 284 | protected EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 285 | private boolean mDismissAllInProgress; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 286 | private boolean mFadeNotificationsOnDismiss; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 287 | |
| 288 | /** |
| 289 | * Was the scroller scrolled to the top when the down motion was observed? |
| 290 | */ |
| 291 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 292 | /** |
| 293 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 294 | * when over scrolling on a expanded card. |
| 295 | */ |
| 296 | private float mMinTopOverScrollToEscape; |
| 297 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 298 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 299 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 300 | private boolean mDontReportNextOverScroll; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 301 | private boolean mDontClampNextScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 302 | private boolean mNeedViewResizeAnimation; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 303 | private ExpandableView mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 304 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 305 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 306 | /** |
| 307 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 308 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 309 | * motion. |
| 310 | */ |
| 311 | private int mMaxScrollAfterExpand; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 312 | private ExpandableNotificationRow.LongPressListener mLongPressListener; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 313 | boolean mCheckForLeavebehind; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 314 | |
| 315 | /** |
| 316 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 317 | * animating. |
| 318 | */ |
| 319 | private boolean mOnlyScrollingInThisMotion; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 320 | private boolean mDisallowDismissInThisMotion; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 321 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 322 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 323 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 324 | = new ViewTreeObserver.OnPreDrawListener() { |
| 325 | @Override |
| 326 | public boolean onPreDraw() { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 327 | updateForcedScroll(); |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 328 | updateChildren(); |
| 329 | mChildrenUpdateRequested = false; |
| 330 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 331 | return true; |
| 332 | } |
| 333 | }; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 334 | private final UserChangedListener mLockscreenUserChangeListener = new UserChangedListener() { |
| 335 | @Override |
| 336 | public void onUserChanged(int userId) { |
| 337 | updateSensitiveness(false /* animated */); |
| 338 | } |
| 339 | }; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 340 | private StatusBar mStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 341 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 342 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 343 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 344 | private HashSet<ExpandableView> mClearTransientViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 345 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 346 | = new HashSet<>(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 347 | private HeadsUpManagerPhone mHeadsUpManager; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 348 | private final NotificationRoundnessManager mRoundnessManager; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 349 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 350 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 351 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 352 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 353 | private FalsingManager mFalsingManager; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 354 | private final ZenModeController mZenController; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 355 | private boolean mAnimationRunning; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 356 | private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 357 | = new ViewTreeObserver.OnPreDrawListener() { |
| 358 | @Override |
| 359 | public boolean onPreDraw() { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 360 | onPreDrawDuringAnimation(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 361 | return true; |
| 362 | } |
| 363 | }; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 364 | private NotificationSection[] mSections; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 365 | private boolean mAnimateNextBackgroundTop; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 366 | private boolean mAnimateNextBackgroundBottom; |
| 367 | private boolean mAnimateNextSectionBoundsChange; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 368 | private int mBgColor; |
| 369 | private float mDimAmount; |
| 370 | private ValueAnimator mDimAnimator; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 371 | private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 372 | private final Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 373 | @Override |
| 374 | public void onAnimationEnd(Animator animation) { |
| 375 | mDimAnimator = null; |
| 376 | } |
| 377 | }; |
| 378 | private ValueAnimator.AnimatorUpdateListener mDimUpdateListener |
| 379 | = new ValueAnimator.AnimatorUpdateListener() { |
| 380 | |
| 381 | @Override |
| 382 | public void onAnimationUpdate(ValueAnimator animation) { |
| 383 | setDimAmount((Float) animation.getAnimatedValue()); |
| 384 | } |
| 385 | }; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 386 | protected ViewGroup mQsContainer; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 387 | private boolean mContinuousShadowUpdate; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 388 | private boolean mContinuousBackgroundUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 389 | private ViewTreeObserver.OnPreDrawListener mShadowUpdater |
| 390 | = new ViewTreeObserver.OnPreDrawListener() { |
| 391 | |
| 392 | @Override |
| 393 | public boolean onPreDraw() { |
| 394 | updateViewShadows(); |
| 395 | return true; |
| 396 | } |
| 397 | }; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 398 | private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> { |
| 399 | updateBackground(); |
| 400 | return true; |
| 401 | }; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 402 | private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() { |
| 403 | @Override |
| 404 | public int compare(ExpandableView view, ExpandableView otherView) { |
| 405 | float endY = view.getTranslationY() + view.getActualHeight(); |
| 406 | float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); |
| 407 | if (endY < otherEndY) { |
| 408 | return -1; |
| 409 | } else if (endY > otherEndY) { |
| 410 | return 1; |
| 411 | } else { |
| 412 | // The two notifications end at the same location |
| 413 | return 0; |
| 414 | } |
| 415 | } |
| 416 | }; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 417 | private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() { |
| 418 | @Override |
| 419 | public void getOutline(View view, Outline outline) { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 420 | if (mAmbientState.isHiddenAtAll()) { |
| 421 | float xProgress = mHideXInterpolator.getInterpolation( |
| 422 | (1 - mLinearHideAmount) * mBackgroundXFactor); |
Selim Cinek | 9ad240c | 2019-04-08 19:07:15 -0700 | [diff] [blame] | 423 | outline.setRoundRect(mBackgroundAnimationRect, |
| 424 | MathUtils.lerp(mCornerRadius / 2.0f, mCornerRadius, |
| 425 | xProgress)); |
Selim Cinek | 33295a4 | 2019-07-26 19:49:08 -0700 | [diff] [blame] | 426 | outline.setAlpha(1.0f - mAmbientState.getHideAmount()); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 427 | } else { |
| 428 | ViewOutlineProvider.BACKGROUND.getOutline(view, outline); |
| 429 | } |
| 430 | } |
| 431 | }; |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 432 | private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 433 | private boolean mPulsing; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 434 | private boolean mGroupExpandedForMeasure; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 435 | private boolean mScrollable; |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 436 | private View mForcedScroll; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 437 | |
| 438 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 439 | * @see #setHideAmount(float, float) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 440 | */ |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 441 | private float mInterpolatedHideAmount = 0f; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 442 | |
| 443 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 444 | * @see #setHideAmount(float, float) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 445 | */ |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 446 | private float mLinearHideAmount = 0f; |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 447 | |
| 448 | /** |
| 449 | * How fast the background scales in the X direction as a factor of the Y expansion. |
| 450 | */ |
| 451 | private float mBackgroundXFactor = 1f; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 452 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 453 | private boolean mSwipingInProgress; |
| 454 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 455 | private boolean mUsingLightTheme; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 456 | private boolean mQsExpanded; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 457 | private boolean mForwardScrollable; |
| 458 | private boolean mBackwardScrollable; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 459 | private NotificationShelf mShelf; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 460 | private int mMaxDisplayedNotifications = -1; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 461 | private int mStatusBarHeight; |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 462 | private int mMinInteractionHeight; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 463 | private boolean mNoAmbient; |
| 464 | private final Rect mClipRect = new Rect(); |
| 465 | private boolean mIsClipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 466 | private Rect mRequestedClipBounds; |
| 467 | private boolean mInHeadsUpPinnedMode; |
| 468 | private boolean mHeadsUpAnimatingAway; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 469 | private int mStatusBarState; |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 470 | private int mCachedBackgroundColor; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 471 | private boolean mHeadsUpGoingAwayAnimationsAllowed = true; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 472 | private Runnable mReflingAndAnimateScroll = () -> { |
| 473 | if (ANCHOR_SCROLLING) { |
| 474 | maybeReflingScroller(); |
| 475 | } |
| 476 | animateScroll(); |
| 477 | }; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 478 | private int mCornerRadius; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 479 | private int mSidePaddings; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 480 | private final Rect mBackgroundAnimationRect = new Rect(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 481 | private ArrayList<BiConsumer<Float, Float>> mExpandedHeightListeners = new ArrayList<>(); |
| 482 | private int mHeadsUpInset; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 483 | private HeadsUpAppearanceController mHeadsUpAppearanceController; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 484 | private NotificationIconAreaController mIconAreaController; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 485 | private final NotificationLockscreenUserManager mLockscreenUserManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 486 | private final Rect mTmpRect = new Rect(); |
| 487 | private final NotificationEntryManager mEntryManager = |
| 488 | Dependency.get(NotificationEntryManager.class); |
| 489 | private final IStatusBarService mBarService = IStatusBarService.Stub.asInterface( |
| 490 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 491 | @VisibleForTesting |
| 492 | protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 493 | private final NotificationRemoteInputManager mRemoteInputManager = |
| 494 | Dependency.get(NotificationRemoteInputManager.class); |
| 495 | private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
| 496 | |
| 497 | private final DisplayMetrics mDisplayMetrics = Dependency.get(DisplayMetrics.class); |
| 498 | private final LockscreenGestureLogger mLockscreenGestureLogger = |
| 499 | Dependency.get(LockscreenGestureLogger.class); |
| 500 | private final VisualStabilityManager mVisualStabilityManager = |
| 501 | Dependency.get(VisualStabilityManager.class); |
| 502 | protected boolean mClearAllEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 503 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 504 | private Interpolator mHideXInterpolator = Interpolators.FAST_OUT_SLOW_IN; |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 505 | private NotificationPanelViewController mNotificationPanelController; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 506 | |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 507 | private final NotificationGutsManager mNotificationGutsManager; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 508 | private final NotificationSectionsManager mSectionsManager; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 509 | private boolean mAnimateBottomOnLayout; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 510 | private float mLastSentAppear; |
| 511 | private float mLastSentExpandedHeight; |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 512 | private boolean mWillExpand; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 513 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 514 | @Inject |
| 515 | public NotificationStackScrollLayout( |
| 516 | @Named(VIEW_CONTEXT) Context context, |
| 517 | AttributeSet attrs, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 518 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress, |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 519 | NotificationRoundnessManager notificationRoundnessManager, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 520 | DynamicPrivacyController dynamicPrivacyController, |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 521 | SysuiStatusBarStateController statusBarStateController, |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 522 | HeadsUpManagerPhone headsUpManager, |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 523 | KeyguardBypassController keyguardBypassController, |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 524 | FalsingManager falsingManager, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 525 | NotificationLockscreenUserManager notificationLockscreenUserManager, |
| 526 | NotificationGutsManager notificationGutsManager, |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 527 | ZenModeController zenController, |
| 528 | NotificationSectionsManager notificationSectionsManager) { |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 529 | super(context, attrs, 0, 0); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 530 | Resources res = getResources(); |
| 531 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 532 | mAllowLongPress = allowLongPress; |
| 533 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 534 | mRoundnessManager = notificationRoundnessManager; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 535 | |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 536 | mLockscreenUserManager = notificationLockscreenUserManager; |
| 537 | mNotificationGutsManager = notificationGutsManager; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 538 | mHeadsUpManager = headsUpManager; |
| 539 | mHeadsUpManager.addListener(mRoundnessManager); |
| 540 | mHeadsUpManager.setAnimationStateHandler(this::setHeadsUpGoingAwayAnimationsAllowed); |
| 541 | mKeyguardBypassController = keyguardBypassController; |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 542 | mFalsingManager = falsingManager; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 543 | mZenController = zenController; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 544 | |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 545 | mSectionsManager = notificationSectionsManager; |
| 546 | mSectionsManager.initialize(this, LayoutInflater.from(context)); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 547 | mSectionsManager.setOnClearGentleNotifsClickListener(v -> { |
| 548 | // Leave the shade open if there will be other notifs left over to clear |
| 549 | final boolean closeShade = !hasActiveClearableNotifications(ROWS_HIGH_PRIORITY); |
| 550 | clearNotifications(ROWS_GENTLE, closeShade); |
| 551 | }); |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 552 | mSections = mSectionsManager.createSectionsForBuckets(); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 553 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 554 | mAmbientState = new AmbientState(context, mSectionsManager, mHeadsUpManager); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 555 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 556 | int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 557 | int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 558 | mExpandHelper = new ExpandHelper(getContext(), mExpandHelperCallback, |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 559 | minHeight, maxHeight); |
| 560 | mExpandHelper.setEventSource(this); |
| 561 | mExpandHelper.setScrollAdapter(this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 562 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, mNotificationCallback, |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 563 | getContext(), mMenuEventListener, mFalsingManager); |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 564 | mStackScrollAlgorithm = createStackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 565 | initView(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 566 | mShouldDrawNotificationBackground = |
| 567 | res.getBoolean(R.bool.config_drawNotificationBackground); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 568 | mFadeNotificationsOnDismiss = |
| 569 | res.getBoolean(R.bool.config_fadeNotificationsOnDismiss); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 570 | mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated); |
| 571 | mRoundnessManager.setOnRoundingChangedCallback(this::invalidate); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 572 | addOnExpandedHeightChangedListener(mRoundnessManager::setExpanded); |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 573 | mLockscreenUserManager.addUserChangedListener(mLockscreenUserChangeListener); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 574 | setOutlineProvider(mOutlineProvider); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 575 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 576 | // Blocking helper manager wants to know the expanded state, update as well. |
| 577 | NotificationBlockingHelperManager blockingHelperManager = |
| 578 | Dependency.get(NotificationBlockingHelperManager.class); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 579 | addOnExpandedHeightChangedListener((height, unused) -> { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 580 | blockingHelperManager.setNotificationShadeExpanded(height); |
| 581 | }); |
| 582 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 583 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
| 584 | setWillNotDraw(!willDraw); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 585 | mBackgroundPaint.setAntiAlias(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 586 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 587 | mDebugPaint = new Paint(); |
| 588 | mDebugPaint.setColor(0xffff0000); |
| 589 | mDebugPaint.setStrokeWidth(2); |
| 590 | mDebugPaint.setStyle(Paint.Style.STROKE); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 591 | mDebugPaint.setTextSize(25f); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 592 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 593 | mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 594 | |
| 595 | TunerService tunerService = Dependency.get(TunerService.class); |
| 596 | tunerService.addTunable((key, newValue) -> { |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 597 | if (key.equals(HIGH_PRIORITY)) { |
| 598 | mHighPriorityBeforeSpeedBump = "1".equals(newValue); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 599 | } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { |
| 600 | updateDismissRtlSetting("1".equals(newValue)); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 601 | } |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 602 | }, HIGH_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL); |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 603 | |
| 604 | mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 605 | @Override |
Beverly | e018f0d | 2019-11-06 14:20:29 -0500 | [diff] [blame] | 606 | public void onPreEntryUpdated(NotificationEntry entry) { |
| 607 | if (entry.rowExists() && !entry.getSbn().isClearable()) { |
| 608 | // If the row already exists, the user may have performed a dismiss action on |
| 609 | // the notification. Since it's not clearable we should snap it back. |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 610 | snapViewIfNeeded(entry); |
| 611 | } |
| 612 | } |
| 613 | }); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 614 | dynamicPrivacyController.addListener(this); |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 615 | mDynamicPrivacyController = dynamicPrivacyController; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 616 | mStatusbarStateController = statusBarStateController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 619 | private void updateDismissRtlSetting(boolean dismissRtl) { |
| 620 | mDismissRtl = dismissRtl; |
| 621 | for (int i = 0; i < getChildCount(); i++) { |
| 622 | View child = getChildAt(i); |
| 623 | if (child instanceof ExpandableNotificationRow) { |
| 624 | ((ExpandableNotificationRow) child).setDismissRtl(dismissRtl); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 629 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 630 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 631 | protected void onFinishInflate() { |
| 632 | super.onFinishInflate(); |
| 633 | |
| 634 | inflateEmptyShadeView(); |
| 635 | inflateFooterView(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 636 | mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 637 | if (mAllowLongPress) { |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 638 | setLongPressListener(mNotificationGutsManager::openGuts); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 639 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 640 | } |
| 641 | |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 642 | /** |
| 643 | * @return the height at which we will wake up when pulsing |
| 644 | */ |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 645 | public float getWakeUpHeight() { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 646 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 647 | if (firstChild != null) { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 648 | if (mKeyguardBypassController.getBypassEnabled()) { |
| 649 | return firstChild.getHeadsUpHeightWithoutHeader(); |
| 650 | } else { |
| 651 | return firstChild.getCollapsedHeight(); |
| 652 | } |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 653 | } |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 654 | return 0f; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 657 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 658 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 659 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 660 | reinflateViews(); |
| 661 | } |
| 662 | |
| 663 | private void reinflateViews() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 664 | inflateFooterView(); |
| 665 | inflateEmptyShadeView(); |
| 666 | updateFooter(); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 667 | mSectionsManager.reinflateViews(LayoutInflater.from(mContext)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 671 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 672 | public void onThemeChanged() { |
Lucas Dupin | 89233c4 | 2019-06-10 18:00:22 -0700 | [diff] [blame] | 673 | final boolean useDarkText = mColorExtractor.getNeutralColors().supportsDarkText(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 674 | updateDecorViews(useDarkText); |
| 675 | |
| 676 | updateFooter(); |
| 677 | } |
| 678 | |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 679 | @Override |
| 680 | public void onOverlayChanged() { |
| 681 | int newRadius = mContext.getResources().getDimensionPixelSize( |
| 682 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
| 683 | if (mCornerRadius != newRadius) { |
| 684 | mCornerRadius = newRadius; |
| 685 | invalidate(); |
| 686 | } |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 687 | reinflateViews(); |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 688 | } |
| 689 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 690 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 691 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 692 | public void updateFooter() { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 693 | boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL); |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 694 | boolean showFooterView = (showDismissView || mEntryManager.hasActiveNotifications()) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 695 | && mStatusBarState != StatusBarState.KEYGUARD |
| 696 | && !mRemoteInputManager.getController().isRemoteInputActive(); |
| 697 | |
| 698 | updateFooterView(showFooterView, showDismissView); |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Return whether there are any clearable notifications |
| 703 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 704 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 705 | public boolean hasActiveClearableNotifications(@SelectedRows int selection) { |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 706 | if (mDynamicPrivacyController.isInLockedDownShade()) { |
| 707 | return false; |
| 708 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 709 | int childCount = getChildCount(); |
| 710 | for (int i = 0; i < childCount; i++) { |
| 711 | View child = getChildAt(i); |
| 712 | if (!(child instanceof ExpandableNotificationRow)) { |
| 713 | continue; |
| 714 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 715 | final ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 716 | if (row.canViewBeDismissed() && matchesSelection(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 717 | return true; |
| 718 | } |
| 719 | } |
| 720 | return false; |
| 721 | } |
| 722 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 723 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 724 | public RemoteInputController.Delegate createDelegate() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 725 | return new RemoteInputController.Delegate() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 726 | public void setRemoteInputActive(NotificationEntry entry, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 727 | boolean remoteInputActive) { |
| 728 | mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 729 | entry.notifyHeightChanged(true /* needsAnimation */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 730 | updateFooter(); |
| 731 | } |
| 732 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 733 | public void lockScrollTo(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 734 | NotificationStackScrollLayout.this.lockScrollTo(entry.getRow()); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | public void requestDisallowLongPressAndDismiss() { |
| 738 | requestDisallowLongPress(); |
| 739 | requestDisallowDismiss(); |
| 740 | } |
| 741 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 744 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 745 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 746 | protected void onAttachedToWindow() { |
| 747 | super.onAttachedToWindow(); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 748 | ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class)) |
| 749 | .addCallback(mStateListener, SysuiStatusBarStateController.RANK_STACK_SCROLLER); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 750 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 754 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 755 | protected void onDetachedFromWindow() { |
| 756 | super.onDetachedFromWindow(); |
Jason Monk | af08c15 | 2018-12-04 11:12:39 -0500 | [diff] [blame] | 757 | Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 758 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | @Override |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 762 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 763 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 764 | return mSwipeHelper; |
| 765 | } |
| 766 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 767 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 768 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 769 | public void onUiModeChanged() { |
| 770 | mBgColor = mContext.getColor(R.color.notification_shade_background_color); |
| 771 | updateBackgroundDimming(); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 772 | mShelf.onUiModeChanged(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 773 | mSectionsManager.onUiModeChanged(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 776 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 777 | protected void onDraw(Canvas canvas) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 778 | if (mShouldDrawNotificationBackground |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 779 | && (mSections[0].getCurrentBounds().top |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 780 | < mSections[mSections.length - 1].getCurrentBounds().bottom |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 781 | || mAmbientState.isDozing())) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 782 | drawBackground(canvas); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 783 | } else if (mInHeadsUpPinnedMode || mHeadsUpAnimatingAway) { |
| 784 | drawHeadsUpBackground(canvas); |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 785 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 786 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 787 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 788 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 789 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 790 | y = getLayoutHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 791 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 792 | y = getHeight() - getEmptyBottomMargin(); |
| 793 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 797 | @Override |
| 798 | public void draw(Canvas canvas) { |
| 799 | super.draw(canvas); |
| 800 | |
| 801 | if (DEBUG && ANCHOR_SCROLLING) { |
| 802 | if (mScrollAnchorView instanceof ExpandableNotificationRow) { |
| 803 | canvas.drawRect(0, |
| 804 | mScrollAnchorView.getTranslationY(), |
| 805 | getWidth(), |
| 806 | mScrollAnchorView.getTranslationY() |
| 807 | + ((ExpandableNotificationRow) mScrollAnchorView).getActualHeight(), |
| 808 | mDebugPaint); |
| 809 | canvas.drawText(Integer.toString(mScrollAnchorViewY), getWidth() - 200, |
| 810 | mScrollAnchorView.getTranslationY() + 30, mDebugPaint); |
| 811 | int y = (int) mShelf.getTranslationY(); |
| 812 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 813 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 814 | canvas.drawText(Integer.toString(getMaxNegativeScrollAmount()), getWidth() - 100, |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 815 | getTopPadding() + 30, mDebugPaint); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 816 | canvas.drawText(Integer.toString(getMaxPositiveScrollAmount()), getWidth() - 100, |
| 817 | getHeight() - 30, mDebugPaint); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 821 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 822 | private void drawBackground(Canvas canvas) { |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 823 | int lockScreenLeft = mSidePaddings; |
| 824 | int lockScreenRight = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 825 | int lockScreenTop = mSections[0].getCurrentBounds().top; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 826 | int lockScreenBottom = mSections[mSections.length - 1].getCurrentBounds().bottom; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 827 | int hiddenLeft = getWidth() / 2; |
| 828 | int hiddenTop = mTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 829 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 830 | float yProgress = 1 - mInterpolatedHideAmount; |
| 831 | float xProgress = mHideXInterpolator.getInterpolation( |
| 832 | (1 - mLinearHideAmount) * mBackgroundXFactor); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 833 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 834 | int left = (int) MathUtils.lerp(hiddenLeft, lockScreenLeft, xProgress); |
| 835 | int right = (int) MathUtils.lerp(hiddenLeft, lockScreenRight, xProgress); |
| 836 | int top = (int) MathUtils.lerp(hiddenTop, lockScreenTop, yProgress); |
| 837 | int bottom = (int) MathUtils.lerp(hiddenTop, lockScreenBottom, yProgress); |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 838 | mBackgroundAnimationRect.set( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 839 | left, |
| 840 | top, |
| 841 | right, |
| 842 | bottom); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 843 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 844 | int backgroundTopAnimationOffset = top - lockScreenTop; |
| 845 | // TODO(kprevas): this may not be necessary any more since we don't display the shelf in AOD |
| 846 | boolean anySectionHasVisibleChild = false; |
| 847 | for (NotificationSection section : mSections) { |
| 848 | if (section.getFirstVisibleChild() != null) { |
| 849 | anySectionHasVisibleChild = true; |
| 850 | break; |
| 851 | } |
| 852 | } |
Selim Cinek | 5fedd81 | 2019-06-26 19:34:24 -0700 | [diff] [blame] | 853 | boolean shouldDrawBackground; |
| 854 | if (mKeyguardBypassController.getBypassEnabled() && onKeyguard()) { |
| 855 | shouldDrawBackground = isPulseExpanding(); |
| 856 | } else { |
| 857 | shouldDrawBackground = !mAmbientState.isDozing() || anySectionHasVisibleChild; |
| 858 | } |
| 859 | if (shouldDrawBackground) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 860 | drawBackgroundRects(canvas, left, right, top, backgroundTopAnimationOffset); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 861 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 862 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 863 | updateClipping(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 864 | } |
| 865 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 866 | /** |
| 867 | * Draws round rects for each background section. |
| 868 | * |
| 869 | * We want to draw a round rect for each background section as defined by {@link #mSections}. |
| 870 | * However, if two sections are directly adjacent with no gap between them (e.g. on the |
| 871 | * lockscreen where the shelf can appear directly below the high priority section, or while |
| 872 | * scrolling the shade so that the top of the shelf is right at the bottom of the high priority |
| 873 | * section), we don't want to round the adjacent corners. |
| 874 | * |
| 875 | * Since {@link Canvas} doesn't provide a way to draw a half-rounded rect, this means that we |
| 876 | * need to coalesce the backgrounds for adjacent sections and draw them as a single round rect. |
| 877 | * This method tracks the top of each rect we need to draw, then iterates through the visible |
| 878 | * sections. If a section is not adjacent to the previous section, we draw the previous rect |
| 879 | * behind the sections we've accumulated up to that point, then start a new rect at the top of |
| 880 | * the current section. When we're done iterating we will always have one rect left to draw. |
| 881 | */ |
| 882 | private void drawBackgroundRects(Canvas canvas, int left, int right, int top, |
| 883 | int animationYOffset) { |
| 884 | int backgroundRectTop = top; |
| 885 | int lastSectionBottom = |
| 886 | mSections[0].getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 887 | int currentLeft = left; |
| 888 | int currentRight = right; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 889 | boolean first = true; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 890 | for (NotificationSection section : mSections) { |
| 891 | if (section.getFirstVisibleChild() == null) { |
| 892 | continue; |
| 893 | } |
| 894 | int sectionTop = section.getCurrentBounds().top + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 895 | int ownLeft = Math.min(Math.max(left, section.getCurrentBounds().left), right); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 896 | int ownRight = Math.max(Math.min(right, section.getCurrentBounds().right), ownLeft); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 897 | // If sections are directly adjacent to each other, we don't want to draw them |
| 898 | // as separate roundrects, as the rounded corners right next to each other look |
| 899 | // bad. |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 900 | if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 901 | || ((currentLeft != ownLeft || currentRight != ownRight) && !first)) { |
| 902 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 903 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 904 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 905 | lastSectionBottom, |
| 906 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 907 | backgroundRectTop = sectionTop; |
| 908 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 909 | currentLeft = ownLeft; |
| 910 | currentRight = ownRight; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 911 | lastSectionBottom = |
| 912 | section.getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 913 | first = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 914 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 915 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 916 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 917 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 918 | lastSectionBottom, |
| 919 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 920 | } |
| 921 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 922 | private void drawHeadsUpBackground(Canvas canvas) { |
| 923 | int left = mSidePaddings; |
| 924 | int right = getWidth() - mSidePaddings; |
| 925 | |
| 926 | float top = getHeight(); |
| 927 | float bottom = 0; |
| 928 | int childCount = getChildCount(); |
| 929 | for (int i = 0; i < childCount; i++) { |
| 930 | View child = getChildAt(i); |
| 931 | if (child.getVisibility() != View.GONE |
| 932 | && child instanceof ExpandableNotificationRow) { |
| 933 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 934 | if ((row.isPinned() || row.isHeadsUpAnimatingAway()) && row.getTranslation() < 0 |
| 935 | && row.getProvider().shouldShowGutsOnSnapOpen()) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 936 | top = Math.min(top, row.getTranslationY()); |
| 937 | bottom = Math.max(bottom, row.getTranslationY() + row.getActualHeight()); |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | if (top < bottom) { |
| 943 | canvas.drawRoundRect( |
| 944 | left, top, right, bottom, |
| 945 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 946 | } |
| 947 | } |
| 948 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 949 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 950 | private void updateBackgroundDimming() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 951 | // No need to update the background color if it's not being drawn. |
| 952 | if (!mShouldDrawNotificationBackground) { |
| 953 | return; |
| 954 | } |
| 955 | |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 956 | // Interpolate between semi-transparent notification panel background color |
| 957 | // and white AOD separator. |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 958 | float colorInterpolation = MathUtils.smoothStep(0.4f /* start */, 1f /* end */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 959 | mLinearHideAmount); |
Felka Chang | 97bc8d5 | 2019-05-29 02:51:15 +0800 | [diff] [blame] | 960 | int color = ColorUtils.blendARGB(mBgColor, Color.WHITE, colorInterpolation); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 961 | |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 962 | if (mCachedBackgroundColor != color) { |
| 963 | mCachedBackgroundColor = color; |
| 964 | mBackgroundPaint.setColor(color); |
| 965 | invalidate(); |
| 966 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 969 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 970 | private void initView(Context context) { |
| 971 | mScroller = new OverScroller(getContext()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 972 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 973 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 974 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 975 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 976 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 977 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 978 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 979 | |
| 980 | Resources res = context.getResources(); |
| 981 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 982 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 983 | mAmbientState.reload(context); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 984 | mPaddingBetweenElements = Math.max(1, |
| 985 | res.getDimensionPixelSize(R.dimen.notification_divider_height)); |
| 986 | mIncreasedPaddingBetweenElements = |
| 987 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 988 | mMinTopOverScrollToEscape = res.getDimensionPixelSize( |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 989 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 990 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 991 | mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 992 | mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 993 | mMinInteractionHeight = res.getDimensionPixelSize( |
| 994 | R.dimen.notification_min_interaction_height); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 995 | mCornerRadius = res.getDimensionPixelSize( |
| 996 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 997 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 998 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 999 | } |
| 1000 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1001 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1002 | private void notifyHeightChangeListener(ExpandableView view) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1003 | notifyHeightChangeListener(view, false /* needsAnimation */); |
| 1004 | } |
| 1005 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1006 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1007 | private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) { |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1008 | if (mOnHeightChangedListener != null) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1009 | mOnHeightChangedListener.onHeightChanged(view, needsAnimation); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1010 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 1013 | public boolean isPulseExpanding() { |
| 1014 | return mAmbientState.isPulseExpanding(); |
| 1015 | } |
| 1016 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1017 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1018 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1019 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1020 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 1021 | |
| 1022 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 1023 | int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2, |
| 1024 | MeasureSpec.getMode(widthMeasureSpec)); |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1025 | // Don't constrain the height of the children so we know how big they'd like to be |
| 1026 | int childHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), |
| 1027 | MeasureSpec.UNSPECIFIED); |
| 1028 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1029 | // We need to measure all children even the GONE ones, such that the heights are calculated |
| 1030 | // correctly as they are used to calculate how many we can fit on the screen. |
| 1031 | final int size = getChildCount(); |
| 1032 | for (int i = 0; i < size; i++) { |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1033 | measureChild(getChildAt(i), childWidthSpec, childHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1034 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1038 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1039 | 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] | 1040 | // we layout all our children centered on the top |
| 1041 | float centerX = getWidth() / 2.0f; |
| 1042 | for (int i = 0; i < getChildCount(); i++) { |
| 1043 | View child = getChildAt(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1044 | // We need to layout all children even the GONE ones, such that the heights are |
| 1045 | // 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] | 1046 | float width = child.getMeasuredWidth(); |
| 1047 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1048 | child.layout((int) (centerX - width / 2.0f), |
| 1049 | 0, |
| 1050 | (int) (centerX + width / 2.0f), |
| 1051 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1052 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 1053 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1054 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1055 | clampScrollPosition(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1056 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1057 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1058 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | 33295a4 | 2019-07-26 19:49:08 -0700 | [diff] [blame] | 1059 | updateOwnTranslationZ(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1060 | } |
| 1061 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1062 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1063 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 1064 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1065 | mNeedViewResizeAnimation = true; |
| 1066 | mNeedsAnimation = true; |
| 1067 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1068 | } |
| 1069 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1070 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1071 | public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) { |
| 1072 | mAmbientState.setSpeedBumpIndex(newIndex); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1073 | mNoAmbient = noAmbient; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1074 | } |
| 1075 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1076 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1077 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1078 | public void setChildLocationsChangedListener( |
| 1079 | NotificationLogger.OnChildLocationsChangedListener listener) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1080 | mListener = listener; |
| 1081 | } |
| 1082 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1083 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1084 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1085 | public boolean isInVisibleLocation(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1086 | ExpandableNotificationRow row = entry.getRow(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1087 | ExpandableViewState childViewState = row.getViewState(); |
| 1088 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1089 | if (childViewState == null) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1090 | return false; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1091 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 1092 | if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1093 | return false; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 1094 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1095 | if (row.getVisibility() != View.VISIBLE) { |
| 1096 | return false; |
| 1097 | } |
| 1098 | return true; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1101 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1102 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 1103 | mMaxLayoutHeight = maxLayoutHeight; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 1104 | mShelf.setMaxLayoutHeight(maxLayoutHeight); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1105 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1106 | } |
| 1107 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1108 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1109 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1110 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1111 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1112 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1115 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1116 | private void updateAlgorithmLayoutMinHeight() { |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 1117 | mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition() |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1118 | ? getLayoutMinHeight() : 0); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1121 | /** |
| 1122 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 1123 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 1124 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1125 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1126 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1127 | updateScrollStateForAddedChildren(); |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 1128 | mAmbientState.setCurrentScrollVelocity(mScroller.isFinished() |
| 1129 | ? 0 |
| 1130 | : mScroller.getCurrVelocity()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1131 | if (ANCHOR_SCROLLING) { |
| 1132 | mAmbientState.setAnchorViewIndex(indexOfChild(mScrollAnchorView)); |
| 1133 | mAmbientState.setAnchorViewY(mScrollAnchorViewY); |
| 1134 | } else { |
| 1135 | mAmbientState.setScrollY(mOwnScrollY); |
| 1136 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1137 | mStackScrollAlgorithm.resetViewStates(mAmbientState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1138 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1139 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1140 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1141 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1145 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1146 | private void onPreDrawDuringAnimation() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1147 | mShelf.updateAppearance(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1148 | updateClippingToTopRoundedCorner(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1149 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 1150 | updateBackground(); |
| 1151 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1154 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1155 | private void updateClippingToTopRoundedCorner() { |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1156 | Float clipStart = (float) mTopPadding |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1157 | + mStackTranslation |
| 1158 | + mAmbientState.getExpandAnimationTopChange(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1159 | Float clipEnd = clipStart + mCornerRadius; |
| 1160 | boolean first = true; |
| 1161 | for (int i = 0; i < getChildCount(); i++) { |
| 1162 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1163 | if (child.getVisibility() == GONE) { |
| 1164 | continue; |
| 1165 | } |
| 1166 | float start = child.getTranslationY(); |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1167 | float end = start + child.getActualHeight(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1168 | boolean clip = clipStart > start && clipStart < end |
| 1169 | || clipEnd >= start && clipEnd <= end; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1170 | clip &= !(first && isScrolledToTop()); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 1171 | child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0) |
| 1172 | : ExpandableView.NO_ROUNDNESS); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1173 | first = false; |
| 1174 | } |
| 1175 | } |
| 1176 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1177 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1178 | private void updateScrollStateForAddedChildren() { |
| 1179 | if (mChildrenToAddAnimated.isEmpty()) { |
| 1180 | return; |
| 1181 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1182 | if (!ANCHOR_SCROLLING) { |
| 1183 | for (int i = 0; i < getChildCount(); i++) { |
| 1184 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1185 | if (mChildrenToAddAnimated.contains(child)) { |
| 1186 | int startingPosition = getPositionInLinearLayout(child); |
| 1187 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
| 1188 | int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements |
| 1189 | : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements; |
| 1190 | int childHeight = getIntrinsicHeight(child) + padding; |
| 1191 | if (startingPosition < mOwnScrollY) { |
| 1192 | // This child starts off screen, so let's keep it offscreen to keep the |
| 1193 | // others visible |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1194 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1195 | setOwnScrollY(mOwnScrollY + childHeight); |
| 1196 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | clampScrollPosition(); |
| 1201 | } |
| 1202 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1203 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1204 | private void updateForcedScroll() { |
| 1205 | if (mForcedScroll != null && (!mForcedScroll.hasFocus() |
| 1206 | || !mForcedScroll.isAttachedToWindow())) { |
| 1207 | mForcedScroll = null; |
| 1208 | } |
| 1209 | if (mForcedScroll != null) { |
| 1210 | ExpandableView expandableView = (ExpandableView) mForcedScroll; |
| 1211 | int positionInLinearLayout = getPositionInLinearLayout(expandableView); |
| 1212 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1213 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1214 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1215 | if (ANCHOR_SCROLLING) { |
| 1216 | // TODO |
| 1217 | } else { |
| 1218 | targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange())); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1219 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1220 | // Only apply the scroll if we're scrolling the view upwards, or the view is so |
| 1221 | // far up that it is not visible anymore. |
| 1222 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1223 | setOwnScrollY(targetScroll); |
| 1224 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1229 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1230 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 1231 | if (!mChildrenUpdateRequested) { |
| 1232 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 1233 | mChildrenUpdateRequested = true; |
| 1234 | invalidate(); |
| 1235 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 1238 | /** |
| 1239 | * Returns best effort count of visible notifications. |
| 1240 | */ |
| 1241 | public int getVisibleNotificationCount() { |
| 1242 | int count = 0; |
| 1243 | for (int i = 0; i < getChildCount(); i++) { |
| 1244 | final View child = getChildAt(i); |
| 1245 | if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) { |
| 1246 | count++; |
| 1247 | } |
| 1248 | } |
| 1249 | return count; |
| 1250 | } |
| 1251 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1252 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1253 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1254 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1257 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1258 | private void clampScrollPosition() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1259 | if (ANCHOR_SCROLLING) { |
| 1260 | // TODO |
| 1261 | } else { |
| 1262 | int scrollRange = getScrollRange(); |
| 1263 | if (scrollRange < mOwnScrollY) { |
| 1264 | setOwnScrollY(scrollRange); |
| 1265 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1269 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1270 | public int getTopPadding() { |
| 1271 | return mTopPadding; |
| 1272 | } |
| 1273 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1274 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1275 | private void setTopPadding(int topPadding, boolean animate) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 1276 | if (mTopPadding != topPadding) { |
| 1277 | mTopPadding = topPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1278 | updateAlgorithmHeightAndPadding(); |
| 1279 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1280 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1281 | mTopPaddingNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1282 | mNeedsAnimation = true; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1283 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1284 | requestChildrenUpdate(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1285 | notifyHeightChangeListener(null, animate); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | /** |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1290 | * Update the height of the panel. |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1291 | * |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1292 | * @param height the expanded height of the panel |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1293 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1294 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1295 | public void setExpandedHeight(float height) { |
| 1296 | mExpandedHeight = height; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1297 | setIsExpanded(height > 0); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1298 | int minExpansionHeight = getMinExpansionHeight(); |
| 1299 | if (height < minExpansionHeight) { |
| 1300 | mClipRect.left = 0; |
| 1301 | mClipRect.right = getWidth(); |
| 1302 | mClipRect.top = 0; |
| 1303 | mClipRect.bottom = (int) height; |
| 1304 | height = minExpansionHeight; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1305 | setRequestedClipBounds(mClipRect); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1306 | } else { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1307 | setRequestedClipBounds(null); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1308 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1309 | int stackHeight; |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1310 | float translationY; |
| 1311 | float appearEndPosition = getAppearEndPosition(); |
| 1312 | float appearStartPosition = getAppearStartPosition(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1313 | float appearFraction = 1.0f; |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 1314 | boolean appearing = height < appearEndPosition; |
| 1315 | mAmbientState.setAppearing(appearing); |
| 1316 | if (!appearing) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1317 | translationY = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 1318 | if (mShouldShowShelfOnly) { |
| 1319 | stackHeight = mTopPadding + mShelf.getIntrinsicHeight(); |
| 1320 | } else if (mQsExpanded) { |
| 1321 | int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding; |
| 1322 | int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight(); |
| 1323 | if (stackStartPosition <= stackEndPosition) { |
| 1324 | stackHeight = stackEndPosition; |
| 1325 | } else { |
| 1326 | stackHeight = (int) NotificationUtils.interpolate(stackStartPosition, |
| 1327 | stackEndPosition, mQsExpansionFraction); |
| 1328 | } |
| 1329 | } else { |
| 1330 | stackHeight = (int) height; |
| 1331 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1332 | } else { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1333 | appearFraction = calculateAppearFraction(height); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1334 | if (appearFraction >= 0) { |
| 1335 | translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0, |
| 1336 | appearFraction); |
| 1337 | } else { |
| 1338 | // This may happen when pushing up a heads up. We linearly push it up from the |
| 1339 | // start |
| 1340 | translationY = height - appearStartPosition + getExpandTranslationStart(); |
| 1341 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1342 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1343 | stackHeight = |
| 1344 | getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1345 | translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction); |
| 1346 | } else { |
| 1347 | stackHeight = (int) (height - translationY); |
| 1348 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1349 | } |
| 1350 | if (stackHeight != mCurrentStackHeight) { |
| 1351 | mCurrentStackHeight = stackHeight; |
| 1352 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1353 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1354 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1355 | setStackTranslation(translationY); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1356 | notifyAppearChangedListeners(); |
| 1357 | } |
| 1358 | |
| 1359 | private void notifyAppearChangedListeners() { |
| 1360 | float appear; |
| 1361 | float expandAmount; |
| 1362 | if (mKeyguardBypassController.getBypassEnabled() && onKeyguard()) { |
| 1363 | appear = calculateAppearFractionBypass(); |
| 1364 | expandAmount = getPulseHeight(); |
| 1365 | } else { |
| 1366 | appear = MathUtils.saturate(calculateAppearFraction(mExpandedHeight)); |
| 1367 | expandAmount = mExpandedHeight; |
| 1368 | } |
| 1369 | if (appear != mLastSentAppear || expandAmount != mLastSentExpandedHeight) { |
| 1370 | mLastSentAppear = appear; |
| 1371 | mLastSentExpandedHeight = expandAmount; |
| 1372 | for (int i = 0; i < mExpandedHeightListeners.size(); i++) { |
| 1373 | BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i); |
| 1374 | listener.accept(expandAmount, appear); |
| 1375 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1376 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1379 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1380 | private void setRequestedClipBounds(Rect clipRect) { |
| 1381 | mRequestedClipBounds = clipRect; |
| 1382 | updateClipping(); |
| 1383 | } |
| 1384 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1385 | /** |
| 1386 | * Return the height of the content ignoring the footer. |
| 1387 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1388 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1389 | public int getIntrinsicContentHeight() { |
| 1390 | return mIntrinsicContentHeight; |
| 1391 | } |
| 1392 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1393 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1394 | public void updateClipping() { |
| 1395 | boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode |
| 1396 | && !mHeadsUpAnimatingAway; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1397 | boolean clipToOutline = false; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1398 | if (mIsClipped != clipped) { |
| 1399 | mIsClipped = clipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1400 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1401 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 1402 | if (mAmbientState.isHiddenAtAll()) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1403 | clipToOutline = true; |
| 1404 | invalidateOutline(); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 1405 | if (isFullyHidden()) { |
| 1406 | setClipBounds(null); |
| 1407 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1408 | } else if (clipped) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1409 | setClipBounds(mRequestedClipBounds); |
| 1410 | } else { |
| 1411 | setClipBounds(null); |
| 1412 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1413 | |
| 1414 | setClipToOutline(clipToOutline); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /** |
| 1418 | * @return The translation at the beginning when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1419 | * Measured relative to the resting position. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1420 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1421 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1422 | private float getExpandTranslationStart() { |
Selim Cinek | 083f214 | 2018-11-06 16:32:23 -0800 | [diff] [blame] | 1423 | return -mTopPadding + getMinExpansionHeight() - mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * @return the position from where the appear transition starts when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1428 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1429 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1430 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1431 | private float getAppearStartPosition() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1432 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1433 | return mHeadsUpInset |
| 1434 | + getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1435 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1436 | return getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1440 | * @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] | 1441 | * intrinsic height, which also includes whether the notification is system expanded and |
| 1442 | * is mainly used when dragging down from a heads up notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1443 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1444 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1445 | private int getTopHeadsUpPinnedHeight() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1446 | NotificationEntry topEntry = mHeadsUpManager.getTopEntry(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1447 | if (topEntry == null) { |
| 1448 | return 0; |
| 1449 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1450 | ExpandableNotificationRow row = topEntry.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1451 | if (row.isChildInGroup()) { |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 1452 | final NotificationEntry groupSummary = |
| 1453 | mGroupManager.getGroupSummary(row.getEntry().getSbn()); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1454 | if (groupSummary != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1455 | row = groupSummary.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | return row.getPinnedHeadsUpHeight(); |
| 1459 | } |
| 1460 | |
| 1461 | /** |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1462 | * @return the position from where the appear transition ends when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1463 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1464 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1465 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1466 | private float getAppearEndPosition() { |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1467 | int appearPosition; |
Selim Cinek | 66440cf | 2017-05-26 13:48:47 -0700 | [diff] [blame] | 1468 | int notGoneChildCount = getNotGoneChildCount(); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 1469 | if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1470 | if (isHeadsUpTransition() |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 1471 | || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1472 | appearPosition = getTopHeadsUpPinnedHeight(); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1473 | } else { |
| 1474 | appearPosition = 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1475 | if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) { |
| 1476 | appearPosition += mShelf.getIntrinsicHeight(); |
| 1477 | } |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1478 | } |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1479 | } else { |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1480 | appearPosition = mEmptyShadeView.getHeight(); |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1481 | } |
| 1482 | return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1485 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1486 | private boolean isHeadsUpTransition() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1487 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 1488 | return mTrackingHeadsUp && firstVisibleSection != null |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 1489 | && firstVisibleSection.getFirstVisibleChild().isAboveShelf(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1490 | } |
| 1491 | |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1492 | /** |
| 1493 | * @param height the height of the panel |
| 1494 | * @return the fraction of the appear animation that has been performed |
| 1495 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1496 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1497 | public float calculateAppearFraction(float height) { |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1498 | float appearEndPosition = getAppearEndPosition(); |
| 1499 | float appearStartPosition = getAppearStartPosition(); |
| 1500 | return (height - appearStartPosition) |
| 1501 | / (appearEndPosition - appearStartPosition); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1504 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1505 | public float getStackTranslation() { |
| 1506 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1509 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1510 | private void setStackTranslation(float stackTranslation) { |
| 1511 | if (stackTranslation != mStackTranslation) { |
| 1512 | mStackTranslation = stackTranslation; |
| 1513 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1514 | requestChildrenUpdate(); |
| 1515 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1519 | * 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] | 1520 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 1521 | * |
| 1522 | * @return either the layout height or the externally defined height, whichever is smaller |
| 1523 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1524 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1525 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1526 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 1527 | } |
| 1528 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1529 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1530 | public int getFirstItemMinHeight() { |
| 1531 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1532 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1533 | } |
| 1534 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1535 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1536 | public void setQsContainer(ViewGroup qsContainer) { |
| 1537 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1538 | } |
| 1539 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1540 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1541 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1542 | if (v instanceof ExpandableNotificationRow) { |
| 1543 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1544 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1545 | } |
| 1546 | return false; |
| 1547 | } |
| 1548 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1549 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1550 | private boolean isHeadsUp(View v) { |
| 1551 | if (v instanceof ExpandableNotificationRow) { |
| 1552 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1553 | return row.isHeadsUp(); |
| 1554 | } |
| 1555 | return false; |
| 1556 | } |
| 1557 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1558 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1559 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 1560 | getLocationOnScreen(mTempInt2); |
| 1561 | float localTouchY = touchY - mTempInt2[1]; |
| 1562 | |
| 1563 | ExpandableView closestChild = null; |
| 1564 | float minDist = Float.MAX_VALUE; |
| 1565 | |
| 1566 | // find the view closest to the location, accounting for GONE views |
| 1567 | final int count = getChildCount(); |
| 1568 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 1569 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 1570 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1571 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1572 | continue; |
| 1573 | } |
| 1574 | float childTop = slidingChild.getTranslationY(); |
| 1575 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1576 | float bottom = childTop + slidingChild.getActualHeight() |
| 1577 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1578 | |
| 1579 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 1580 | if (dist < minDist) { |
| 1581 | closestChild = slidingChild; |
| 1582 | minDist = dist; |
| 1583 | } |
| 1584 | } |
| 1585 | return closestChild; |
| 1586 | } |
| 1587 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1588 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
| 1589 | private ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1590 | return getChildAtPosition(touchX, touchY, true /* requireMinHeight */); |
| 1591 | |
| 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * Get the child at a certain screen location. |
| 1596 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1597 | * @param touchX the x coordinate |
| 1598 | * @param touchY the y coordinate |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1599 | * @param requireMinHeight Whether a minimum height is required for a child to be returned. |
| 1600 | * @return the child at the given location. |
| 1601 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1602 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1603 | private ExpandableView getChildAtPosition(float touchX, float touchY, |
| 1604 | boolean requireMinHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1605 | // find the view under the pointer, accounting for GONE views |
| 1606 | final int count = getChildCount(); |
| 1607 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1608 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1609 | if (slidingChild.getVisibility() != VISIBLE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1610 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1611 | continue; |
| 1612 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 1613 | float childTop = slidingChild.getTranslationY(); |
| 1614 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1615 | float bottom = childTop + slidingChild.getActualHeight() |
| 1616 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 1617 | |
| 1618 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 1619 | // camera affordance). |
| 1620 | int left = 0; |
| 1621 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1622 | |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1623 | if ((bottom - top >= mMinInteractionHeight || !requireMinHeight) |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1624 | && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1625 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 1626 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1627 | NotificationEntry entry = row.getEntry(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1628 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1629 | && mHeadsUpManager.getTopEntry().getRow() != row |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1630 | && mGroupManager.getGroupSummary( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 1631 | mHeadsUpManager.getTopEntry().getSbn()) |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1632 | != entry) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1633 | continue; |
| 1634 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1635 | return row.getViewAtPosition(touchY - childTop); |
| 1636 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1637 | return slidingChild; |
| 1638 | } |
| 1639 | } |
| 1640 | return null; |
| 1641 | } |
| 1642 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1643 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1644 | getLocationOnScreen(mTempInt2); |
| 1645 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1648 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1649 | public void setScrollingEnabled(boolean enable) { |
| 1650 | mScrollingEnabled = enable; |
| 1651 | } |
| 1652 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1653 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1654 | public void lockScrollTo(View v) { |
| 1655 | if (mForcedScroll == v) { |
| 1656 | return; |
| 1657 | } |
| 1658 | mForcedScroll = v; |
| 1659 | scrollTo(v); |
| 1660 | } |
| 1661 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1662 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1663 | public boolean scrollTo(View v) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1664 | ExpandableView expandableView = (ExpandableView) v; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1665 | if (ANCHOR_SCROLLING) { |
| 1666 | // TODO |
| 1667 | } else { |
| 1668 | int positionInLinearLayout = getPositionInLinearLayout(v); |
| 1669 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
| 1670 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1671 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1672 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 1673 | // that it is not visible anymore. |
| 1674 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1675 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY); |
| 1676 | mDontReportNextOverScroll = true; |
| 1677 | animateScroll(); |
| 1678 | return true; |
| 1679 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1680 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1681 | return false; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1684 | /** |
| 1685 | * @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] | 1686 | * the IME. |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1687 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1688 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1689 | private int targetScrollForView(ExpandableView v, int positionInLinearLayout) { |
| 1690 | return positionInLinearLayout + v.getIntrinsicHeight() + |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 1691 | getImeInset() - getHeight() |
| 1692 | + ((!isExpanded() && isPinnedHeadsUp(v)) ? mHeadsUpInset : getTopPadding()); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1695 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1696 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1697 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1698 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1699 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1700 | if (ANCHOR_SCROLLING) { |
| 1701 | // TODO |
| 1702 | } else { |
| 1703 | int range = getScrollRange(); |
| 1704 | if (mOwnScrollY > range) { |
| 1705 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1706 | // animating away. To work around that we'll wait until things have settled. |
| 1707 | removeCallbacks(mReclamp); |
| 1708 | postDelayed(mReclamp, 50); |
| 1709 | } else if (mForcedScroll != null) { |
| 1710 | // The scroll was requested before we got the actual inset - in case we need |
| 1711 | // to scroll up some more do so now. |
| 1712 | scrollTo(mForcedScroll); |
| 1713 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1714 | } |
| 1715 | return insets; |
| 1716 | } |
| 1717 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1718 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1719 | private Runnable mReclamp = new Runnable() { |
| 1720 | @Override |
| 1721 | public void run() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1722 | if (ANCHOR_SCROLLING) { |
| 1723 | // TODO |
| 1724 | } else { |
| 1725 | int range = getScrollRange(); |
| 1726 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1727 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1728 | mDontReportNextOverScroll = true; |
| 1729 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1730 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1731 | } |
| 1732 | }; |
| 1733 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1734 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 1735 | public void setExpandingEnabled(boolean enable) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1736 | mExpandHelper.setEnabled(enable); |
| 1737 | } |
| 1738 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1739 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1740 | private boolean isScrollingEnabled() { |
| 1741 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1742 | } |
| 1743 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1744 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1745 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1746 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1747 | } |
| 1748 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1749 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1750 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1751 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1752 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1753 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1754 | float densityScale = getResources().getDisplayMetrics().density; |
| 1755 | mSwipeHelper.setDensityScale(densityScale); |
| 1756 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1757 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1758 | initView(getContext()); |
| 1759 | } |
| 1760 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1761 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1762 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1763 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1764 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1765 | } |
| 1766 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1767 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1768 | private void snapViewIfNeeded(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1769 | ExpandableNotificationRow child = entry.getRow(); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1770 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1771 | // If the child is showing the notification menu snap to that |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 1772 | if (child.getProvider() != null) { |
| 1773 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
| 1774 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
| 1775 | } |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1776 | } |
| 1777 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1778 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1779 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1780 | public ViewGroup getViewParentForNotification(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1781 | return this; |
| 1782 | } |
| 1783 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1784 | /** |
| 1785 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1786 | * |
| 1787 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1788 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1789 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1790 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1791 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1792 | private float overScrollUp(int deltaY, int range) { |
| 1793 | deltaY = Math.max(deltaY, 0); |
| 1794 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1795 | float newTopAmount = currentTopAmount - deltaY; |
| 1796 | if (currentTopAmount > 0) { |
| 1797 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1798 | false /* animate */); |
| 1799 | } |
| 1800 | // Top overScroll might not grab all scrolling motion, |
| 1801 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1802 | if (ANCHOR_SCROLLING) { |
| 1803 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1804 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1805 | ExpandableView lastRow = getLastRowNotGone(); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1806 | if (lastRow != null && !lastRow.isInShelf()) { |
| 1807 | float distanceToMax = Math.max(0, getMaxPositiveScrollAmount()); |
| 1808 | if (scrollAmount > distanceToMax) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1809 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1810 | // We overScroll on the bottom |
| 1811 | setOverScrolledPixels(currentBottomPixels + (scrollAmount - distanceToMax), |
| 1812 | false /* onTop */, |
| 1813 | false /* animate */); |
| 1814 | mScrollAnchorViewY -= distanceToMax; |
| 1815 | scrollAmount = 0f; |
| 1816 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1817 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1818 | return scrollAmount; |
| 1819 | } else { |
| 1820 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1821 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1822 | if (newScrollY > range) { |
| 1823 | if (!mExpandedInThisMotion) { |
| 1824 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1825 | // We overScroll on the bottom |
| 1826 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1827 | false /* onTop */, |
| 1828 | false /* animate */); |
| 1829 | } |
| 1830 | setOwnScrollY(range); |
| 1831 | scrollAmount = 0.0f; |
| 1832 | } |
| 1833 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1834 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | /** |
| 1838 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1839 | * |
| 1840 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1841 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1842 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1843 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1844 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1845 | private float overScrollDown(int deltaY) { |
| 1846 | deltaY = Math.min(deltaY, 0); |
| 1847 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1848 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1849 | if (currentBottomAmount > 0) { |
| 1850 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1851 | false /* animate */); |
| 1852 | } |
| 1853 | // Bottom overScroll might not grab all scrolling motion, |
| 1854 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1855 | if (ANCHOR_SCROLLING) { |
| 1856 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1857 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1858 | ExpandableView firstChild = getFirstChildNotGone(); |
| 1859 | float top = firstChild.getTranslationY(); |
| 1860 | float distanceToTop = mScrollAnchorView.getTranslationY() - top - mScrollAnchorViewY; |
| 1861 | if (distanceToTop < -scrollAmount) { |
| 1862 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1863 | // We overScroll on the top |
| 1864 | setOverScrolledPixels(currentTopPixels + (-scrollAmount - distanceToTop), |
| 1865 | true /* onTop */, |
| 1866 | false /* animate */); |
| 1867 | mScrollAnchorView = firstChild; |
| 1868 | mScrollAnchorViewY = 0; |
| 1869 | scrollAmount = 0f; |
| 1870 | } |
| 1871 | return scrollAmount; |
| 1872 | } else { |
| 1873 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1874 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1875 | if (newScrollY < 0) { |
| 1876 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1877 | // We overScroll on the top |
| 1878 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1879 | true /* onTop */, |
| 1880 | false /* animate */); |
| 1881 | setOwnScrollY(0); |
| 1882 | scrollAmount = 0.0f; |
| 1883 | } |
| 1884 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1885 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1886 | } |
| 1887 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1888 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1889 | private void initVelocityTrackerIfNotExists() { |
| 1890 | if (mVelocityTracker == null) { |
| 1891 | mVelocityTracker = VelocityTracker.obtain(); |
| 1892 | } |
| 1893 | } |
| 1894 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1895 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1896 | private void recycleVelocityTracker() { |
| 1897 | if (mVelocityTracker != null) { |
| 1898 | mVelocityTracker.recycle(); |
| 1899 | mVelocityTracker = null; |
| 1900 | } |
| 1901 | } |
| 1902 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1903 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1904 | private void initOrResetVelocityTracker() { |
| 1905 | if (mVelocityTracker == null) { |
| 1906 | mVelocityTracker = VelocityTracker.obtain(); |
| 1907 | } else { |
| 1908 | mVelocityTracker.clear(); |
| 1909 | } |
| 1910 | } |
| 1911 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1912 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1913 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1914 | mFinishScrollingCallback = runnable; |
| 1915 | } |
| 1916 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1917 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1918 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1919 | if (mScroller.computeScrollOffset()) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1920 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1921 | int oldY = mLastScrollerY; |
| 1922 | int y = mScroller.getCurrY(); |
| 1923 | int deltaY = y - oldY; |
| 1924 | if (deltaY != 0) { |
| 1925 | int maxNegativeScrollAmount = getMaxNegativeScrollAmount(); |
| 1926 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 1927 | if ((maxNegativeScrollAmount < 0 && deltaY < maxNegativeScrollAmount) |
| 1928 | || (maxPositiveScrollAmount > 0 && deltaY > maxPositiveScrollAmount)) { |
| 1929 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1930 | // the current velocity |
| 1931 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1932 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1933 | customOverScrollBy(deltaY, oldY, 0, (int) mMaxOverScroll); |
| 1934 | mLastScrollerY = y; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1935 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1936 | } else { |
| 1937 | int oldY = mOwnScrollY; |
| 1938 | int y = mScroller.getCurrY(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1939 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1940 | if (oldY != y) { |
| 1941 | int range = getScrollRange(); |
| 1942 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1943 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1944 | // the current velocity |
| 1945 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1946 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1947 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1948 | if (mDontClampNextScroll) { |
| 1949 | range = Math.max(range, oldY); |
| 1950 | } |
| 1951 | customOverScrollBy(y - oldY, oldY, range, |
| 1952 | (int) (mMaxOverScroll)); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1953 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1956 | postOnAnimation(mReflingAndAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1957 | } else { |
| 1958 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1959 | if (mFinishScrollingCallback != null) { |
| 1960 | mFinishScrollingCallback.run(); |
| 1961 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1965 | private void setMaxOverScrollFromCurrentVelocity() { |
| 1966 | float currVelocity = mScroller.getCurrVelocity(); |
| 1967 | if (currVelocity >= mMinimumVelocity) { |
| 1968 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1969 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1970 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1971 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1972 | /** |
| 1973 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 1974 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 1975 | * |
| 1976 | * This method performs the determination of whether we're exceeding the overscroll and clamps |
| 1977 | * the scroll amount if so. The actual scrolling/overscrolling happens in |
| 1978 | * {@link #onCustomOverScrolled(int, boolean)} (absolute scrolling) or |
| 1979 | * {@link #onCustomOverScrolledBy(int, boolean)} (anchor scrolling). |
| 1980 | * |
| 1981 | * @param deltaY The (signed) number of pixels to scroll. |
| 1982 | * @param scrollY The current scroll position (absolute scrolling only). |
| 1983 | * @param scrollRangeY The maximum allowable scroll position (absolute scrolling only). |
| 1984 | * @param maxOverScrollY The current (unsigned) limit on number of pixels to overscroll by. |
| 1985 | */ |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1986 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1987 | private void customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, int maxOverScrollY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1988 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1989 | boolean clampedY = false; |
| 1990 | if (deltaY < 0) { |
| 1991 | int maxScrollAmount = getMaxNegativeScrollAmount(); |
| 1992 | if (maxScrollAmount > Integer.MIN_VALUE) { |
| 1993 | maxScrollAmount -= maxOverScrollY; |
| 1994 | if (deltaY < maxScrollAmount) { |
| 1995 | deltaY = maxScrollAmount; |
| 1996 | clampedY = true; |
| 1997 | } |
| 1998 | } |
| 1999 | } else { |
| 2000 | int maxScrollAmount = getMaxPositiveScrollAmount(); |
| 2001 | if (maxScrollAmount < Integer.MAX_VALUE) { |
| 2002 | maxScrollAmount += maxOverScrollY; |
| 2003 | if (deltaY > maxScrollAmount) { |
| 2004 | deltaY = maxScrollAmount; |
| 2005 | clampedY = true; |
| 2006 | } |
| 2007 | } |
| 2008 | } |
| 2009 | onCustomOverScrolledBy(deltaY, clampedY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2010 | } else { |
| 2011 | int newScrollY = scrollY + deltaY; |
| 2012 | final int top = -maxOverScrollY; |
| 2013 | final int bottom = maxOverScrollY + scrollRangeY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2014 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2015 | boolean clampedY = false; |
| 2016 | if (newScrollY > bottom) { |
| 2017 | newScrollY = bottom; |
| 2018 | clampedY = true; |
| 2019 | } else if (newScrollY < top) { |
| 2020 | newScrollY = top; |
| 2021 | clampedY = true; |
| 2022 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2023 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2024 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2025 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | /** |
| 2029 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 2030 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 2031 | * same overScroll edge. |
| 2032 | * |
| 2033 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 2034 | * the rubber-banding logic. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2035 | * @param onTop Should the effect be applied on top of the scroller. |
| 2036 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2037 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2038 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2039 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2040 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | /** |
| 2044 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2045 | * By default this will also cancel animations on the same overScroll edge. |
| 2046 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2047 | * @param amount The amount to overScroll by. |
| 2048 | * @param onTop Should the effect be applied on top of the scroller. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2049 | * @param animate Should an animation be performed. |
| 2050 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2051 | |
| 2052 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2053 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 2054 | setOverScrollAmount(amount, onTop, animate, true); |
| 2055 | } |
| 2056 | |
| 2057 | /** |
| 2058 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2059 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2060 | * @param amount The amount to overScroll by. |
| 2061 | * @param onTop Should the effect be applied on top of the scroller. |
| 2062 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2063 | * @param cancelAnimators Should running animations be cancelled. |
| 2064 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2065 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2066 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2067 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2068 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2073 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2074 | * @param amount The amount to overScroll by. |
| 2075 | * @param onTop Should the effect be applied on top of the scroller. |
| 2076 | * @param animate Should an animation be performed. |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2077 | * @param cancelAnimators Should running animations be cancelled. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2078 | * @param isRubberbanded The value which will be passed to |
| 2079 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2080 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2081 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2082 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2083 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2084 | if (cancelAnimators) { |
| 2085 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 2086 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2087 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2088 | } |
| 2089 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2090 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2091 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 2092 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2093 | amount = Math.max(0, amount); |
| 2094 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2095 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2096 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2097 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2098 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2099 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2100 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2101 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2102 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2103 | } |
| 2104 | } |
| 2105 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2106 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2107 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2108 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 2109 | if (mDontReportNextOverScroll) { |
| 2110 | mDontReportNextOverScroll = false; |
| 2111 | return; |
| 2112 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2113 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2114 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2118 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2119 | public void setOverscrollTopChangedListener( |
| 2120 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 2121 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 2122 | } |
| 2123 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2124 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2125 | public float getCurrentOverScrollAmount(boolean top) { |
| 2126 | return mAmbientState.getOverScrollAmount(top); |
| 2127 | } |
| 2128 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2129 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2130 | public float getCurrentOverScrolledPixels(boolean top) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2131 | return top ? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2132 | } |
| 2133 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2134 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2135 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2136 | if (onTop) { |
| 2137 | mOverScrolledTopPixels = amount; |
| 2138 | } else { |
| 2139 | mOverScrolledBottomPixels = amount; |
| 2140 | } |
| 2141 | } |
| 2142 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2143 | /** |
| 2144 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 2145 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 2146 | * |
| 2147 | * @param deltaY The (signed) number of pixels to scroll. |
| 2148 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2149 | * the overscroll limit. |
| 2150 | */ |
| 2151 | private void onCustomOverScrolledBy(int deltaY, boolean clampedY) { |
| 2152 | assert ANCHOR_SCROLLING; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2153 | mScrollAnchorViewY -= deltaY; |
| 2154 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2155 | if (!mScroller.isFinished()) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2156 | if (clampedY) { |
| 2157 | springBack(); |
| 2158 | } else { |
| 2159 | float overScrollTop = getCurrentOverScrollAmount(true /* top */); |
| 2160 | if (isScrolledToTop() && mScrollAnchorViewY > 0) { |
| 2161 | notifyOverscrollTopListener(mScrollAnchorViewY, |
| 2162 | isRubberbanded(true /* onTop */)); |
| 2163 | } else { |
| 2164 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true /* onTop */)); |
| 2165 | } |
| 2166 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2167 | } |
| 2168 | updateScrollAnchor(); |
| 2169 | updateOnScrollChange(); |
| 2170 | } |
| 2171 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2172 | /** |
| 2173 | * Scrolls to the given position, overscrolling if needed. If called during a fling and the |
| 2174 | * position exceeds the provided maximum overscroll, springs back instead. |
| 2175 | * |
| 2176 | * @param scrollY The target scroll position. |
| 2177 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2178 | * the overscroll limit. |
| 2179 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2180 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2181 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2182 | assert !ANCHOR_SCROLLING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2183 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2184 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2185 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2186 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2187 | springBack(); |
| 2188 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2189 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2190 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2191 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2192 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2193 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2194 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2195 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2196 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2197 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2201 | /** |
| 2202 | * Springs back from an overscroll by stopping the {@link #mScroller} and animating the |
| 2203 | * overscroll amount back to zero. |
| 2204 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2205 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2206 | private void springBack() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2207 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2208 | boolean overScrolledTop = isScrolledToTop() && mScrollAnchorViewY > 0; |
| 2209 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 2210 | boolean overscrolledBottom = maxPositiveScrollAmount < 0; |
| 2211 | if (overScrolledTop || overscrolledBottom) { |
| 2212 | float newAmount; |
| 2213 | if (overScrolledTop) { |
| 2214 | newAmount = mScrollAnchorViewY; |
| 2215 | mScrollAnchorViewY = 0; |
| 2216 | mDontReportNextOverScroll = true; |
| 2217 | } else { |
| 2218 | newAmount = -maxPositiveScrollAmount; |
| 2219 | mScrollAnchorViewY -= maxPositiveScrollAmount; |
| 2220 | } |
| 2221 | setOverScrollAmount(newAmount, overScrolledTop, false); |
| 2222 | setOverScrollAmount(0.0f, overScrolledTop, true); |
| 2223 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2224 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2225 | } else { |
| 2226 | int scrollRange = getScrollRange(); |
| 2227 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2228 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2229 | if (overScrolledTop || overScrolledBottom) { |
| 2230 | boolean onTop; |
| 2231 | float newAmount; |
| 2232 | if (overScrolledTop) { |
| 2233 | onTop = true; |
| 2234 | newAmount = -mOwnScrollY; |
| 2235 | setOwnScrollY(0); |
| 2236 | mDontReportNextOverScroll = true; |
| 2237 | } else { |
| 2238 | onTop = false; |
| 2239 | newAmount = mOwnScrollY - scrollRange; |
| 2240 | setOwnScrollY(scrollRange); |
| 2241 | } |
| 2242 | setOverScrollAmount(newAmount, onTop, false); |
| 2243 | setOverScrollAmount(0.0f, onTop, true); |
| 2244 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2245 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2246 | } |
| 2247 | } |
| 2248 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2249 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2250 | private int getScrollRange() { |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2251 | // In current design, it only use the top HUN to treat all of HUNs |
| 2252 | // although there are more than one HUNs |
| 2253 | int contentHeight = mContentHeight; |
| 2254 | if (!isExpanded() && mHeadsUpManager.hasPinnedHeadsUp()) { |
| 2255 | contentHeight = mHeadsUpInset + getTopHeadsUpPinnedHeight(); |
| 2256 | } |
| 2257 | int scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2258 | int imeInset = getImeInset(); |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2259 | scrollRange += Math.min(imeInset, Math.max(0, contentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2260 | return scrollRange; |
| 2261 | } |
| 2262 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2263 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2264 | private int getImeInset() { |
| 2265 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2266 | } |
| 2267 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2268 | /** |
| 2269 | * @return the first child which has visibility unequal to GONE |
| 2270 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2271 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2272 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2273 | int childCount = getChildCount(); |
| 2274 | for (int i = 0; i < childCount; i++) { |
| 2275 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2276 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2277 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | return null; |
| 2281 | } |
| 2282 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2283 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2284 | * @return the child before the given view which has visibility unequal to GONE |
| 2285 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2286 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2287 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2288 | ExpandableView previousView = null; |
| 2289 | int childCount = getChildCount(); |
| 2290 | for (int i = 0; i < childCount; i++) { |
| 2291 | View child = getChildAt(i); |
| 2292 | if (child == view) { |
| 2293 | return previousView; |
| 2294 | } |
| 2295 | if (child.getVisibility() != View.GONE) { |
| 2296 | previousView = (ExpandableView) child; |
| 2297 | } |
| 2298 | } |
| 2299 | return null; |
| 2300 | } |
| 2301 | |
| 2302 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2303 | * @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] | 2304 | * given translationY or equal to it. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2305 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2306 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2307 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2308 | int childCount = getChildCount(); |
| 2309 | for (int i = 0; i < childCount; i++) { |
| 2310 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2311 | if (child.getVisibility() == View.GONE) { |
| 2312 | continue; |
| 2313 | } |
| 2314 | float rowTranslation = child.getTranslationY(); |
| 2315 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2316 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2317 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2318 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2319 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2320 | List<ExpandableNotificationRow> notificationChildren = |
| 2321 | row.getNotificationChildren(); |
| 2322 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2323 | childIndex++) { |
| 2324 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2325 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2326 | return rowChild; |
| 2327 | } |
| 2328 | } |
| 2329 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | return null; |
| 2333 | } |
| 2334 | |
| 2335 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2336 | * @return the last child which has visibility unequal to GONE |
| 2337 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2338 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2339 | public ExpandableView getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2340 | int childCount = getChildCount(); |
| 2341 | for (int i = childCount - 1; i >= 0; i--) { |
| 2342 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2343 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2344 | return (ExpandableView) child; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2345 | } |
| 2346 | } |
| 2347 | return null; |
| 2348 | } |
| 2349 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2350 | private ExpandableNotificationRow getLastRowNotGone() { |
| 2351 | int childCount = getChildCount(); |
| 2352 | for (int i = childCount - 1; i >= 0; i--) { |
| 2353 | View child = getChildAt(i); |
| 2354 | if (child instanceof ExpandableNotificationRow && child.getVisibility() != View.GONE) { |
| 2355 | return (ExpandableNotificationRow) child; |
| 2356 | } |
| 2357 | } |
| 2358 | return null; |
| 2359 | } |
| 2360 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2361 | /** |
| 2362 | * @return the number of children which have visibility unequal to GONE |
| 2363 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2364 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2365 | public int getNotGoneChildCount() { |
| 2366 | int childCount = getChildCount(); |
| 2367 | int count = 0; |
| 2368 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2369 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2370 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2371 | count++; |
| 2372 | } |
| 2373 | } |
| 2374 | return count; |
| 2375 | } |
| 2376 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2377 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2378 | private void updateContentHeight() { |
| 2379 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2380 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2381 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2382 | int numShownItems = 0; |
| 2383 | boolean finish = false; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2384 | int maxDisplayedNotifications = mMaxDisplayedNotifications; |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2385 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2386 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2387 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2388 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2389 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2390 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2391 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2392 | && numShownItems >= maxDisplayedNotifications; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2393 | if (limitReached) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2394 | expandableView = mShelf; |
| 2395 | finish = true; |
| 2396 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2397 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2398 | float padding; |
| 2399 | if (increasedPaddingAmount >= 0.0f) { |
| 2400 | padding = (int) NotificationUtils.interpolate( |
| 2401 | previousPaddingRequest, |
| 2402 | mIncreasedPaddingBetweenElements, |
| 2403 | increasedPaddingAmount); |
| 2404 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2405 | mPaddingBetweenElements, |
| 2406 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2407 | increasedPaddingAmount); |
| 2408 | } else { |
| 2409 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2410 | 0, |
| 2411 | mPaddingBetweenElements, |
| 2412 | 1.0f + increasedPaddingAmount); |
| 2413 | if (previousPaddingAmount > 0.0f) { |
| 2414 | padding = (int) NotificationUtils.interpolate( |
| 2415 | ownPadding, |
| 2416 | mIncreasedPaddingBetweenElements, |
| 2417 | previousPaddingAmount); |
| 2418 | } else { |
| 2419 | padding = ownPadding; |
| 2420 | } |
| 2421 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2422 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2423 | if (height != 0) { |
| 2424 | height += padding; |
| 2425 | } |
| 2426 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2427 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2428 | numShownItems++; |
| 2429 | if (finish) { |
| 2430 | break; |
| 2431 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2432 | } |
| 2433 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2434 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2435 | |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 2436 | // The topPadding can be bigger than the regular padding when qs is expanded, in that |
| 2437 | // state the maxPanelHeight and the contentHeight should be bigger |
| 2438 | mContentHeight = height + Math.max(mIntrinsicPadding, mTopPadding) + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2439 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2440 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2441 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2444 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2445 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2446 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2447 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2450 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2451 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2452 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2453 | if (scrollable != mScrollable) { |
| 2454 | mScrollable = scrollable; |
| 2455 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2456 | updateForwardAndBackwardScrollability(); |
| 2457 | } |
| 2458 | } |
| 2459 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2460 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2461 | private void updateForwardAndBackwardScrollability() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2462 | boolean forwardScrollable = mScrollable && !isScrolledToBottom(); |
| 2463 | boolean backwardsScrollable = mScrollable && !isScrolledToTop(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2464 | boolean changed = forwardScrollable != mForwardScrollable |
| 2465 | || backwardsScrollable != mBackwardScrollable; |
| 2466 | mForwardScrollable = forwardScrollable; |
| 2467 | mBackwardScrollable = backwardsScrollable; |
| 2468 | if (changed) { |
| 2469 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2470 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2471 | } |
| 2472 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2473 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2474 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2475 | // 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] | 2476 | if (!mShouldDrawNotificationBackground) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2477 | return; |
| 2478 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2479 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2480 | updateBackgroundBounds(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2481 | if (didSectionBoundsChange()) { |
| 2482 | boolean animate = mAnimateNextSectionBoundsChange || mAnimateNextBackgroundTop |
| 2483 | || mAnimateNextBackgroundBottom || areSectionBoundsAnimating(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2484 | if (!isExpanded()) { |
| 2485 | abortBackgroundAnimators(); |
| 2486 | animate = false; |
| 2487 | } |
| 2488 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2489 | startBackgroundAnimation(); |
| 2490 | } else { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2491 | for (NotificationSection section : mSections) { |
| 2492 | section.resetCurrentBounds(); |
| 2493 | } |
Lucas Dupin | 90a38dd | 2018-09-05 09:37:37 -0700 | [diff] [blame] | 2494 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2495 | } |
| 2496 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2497 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2498 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2499 | mAnimateNextBackgroundTop = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2500 | mAnimateNextBackgroundBottom = false; |
| 2501 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2502 | } |
| 2503 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2504 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2505 | private void abortBackgroundAnimators() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2506 | for (NotificationSection section : mSections) { |
| 2507 | section.cancelAnimators(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2508 | } |
| 2509 | } |
| 2510 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2511 | private boolean didSectionBoundsChange() { |
| 2512 | for (NotificationSection section : mSections) { |
| 2513 | if (section.didBoundsChange()) { |
| 2514 | return true; |
| 2515 | } |
| 2516 | } |
| 2517 | return false; |
| 2518 | } |
| 2519 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2520 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2521 | private boolean areSectionBoundsAnimating() { |
| 2522 | for (NotificationSection section : mSections) { |
| 2523 | if (section.areBoundsAnimating()) { |
| 2524 | return true; |
| 2525 | } |
| 2526 | } |
| 2527 | return false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2530 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2531 | private void startBackgroundAnimation() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2532 | // TODO(kprevas): do we still need separate fields for top/bottom? |
| 2533 | // or can each section manage its own animation state? |
| 2534 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2535 | NotificationSection lastVisibleSection = getLastVisibleSection(); |
| 2536 | for (NotificationSection section : mSections) { |
| 2537 | section.startBackgroundAnimation( |
| 2538 | section == firstVisibleSection |
| 2539 | ? mAnimateNextBackgroundTop |
| 2540 | : mAnimateNextSectionBoundsChange, |
| 2541 | section == lastVisibleSection |
| 2542 | ? mAnimateNextBackgroundBottom |
| 2543 | : mAnimateNextSectionBoundsChange); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2544 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * Update the background bounds to the new desired bounds |
| 2549 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2550 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2551 | private void updateBackgroundBounds() { |
shawnlin | 2771672 | 2019-04-17 20:09:45 +0800 | [diff] [blame] | 2552 | int left = mSidePaddings; |
| 2553 | int right = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2554 | for (NotificationSection section : mSections) { |
| 2555 | section.getBounds().left = left; |
| 2556 | section.getBounds().right = right; |
| 2557 | } |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2558 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2559 | if (!mIsExpanded) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2560 | for (NotificationSection section : mSections) { |
| 2561 | section.getBounds().top = 0; |
| 2562 | section.getBounds().bottom = 0; |
| 2563 | } |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2564 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2565 | } |
Selim Cinek | 893a9df | 2019-07-19 17:30:16 -0700 | [diff] [blame] | 2566 | int minTopPosition; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2567 | NotificationSection lastSection = getLastVisibleSection(); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 2568 | boolean onKeyguard = mStatusBarState == StatusBarState.KEYGUARD; |
| 2569 | if (!onKeyguard) { |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2570 | minTopPosition = (int) (mTopPadding + mStackTranslation); |
| 2571 | } else if (lastSection == null) { |
| 2572 | minTopPosition = mTopPadding; |
Selim Cinek | 893a9df | 2019-07-19 17:30:16 -0700 | [diff] [blame] | 2573 | } else { |
| 2574 | // The first sections could be empty while there could still be elements in later |
| 2575 | // sections. The position of these first few sections is determined by the position of |
| 2576 | // the first visible section. |
| 2577 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2578 | firstVisibleSection.updateBounds(0 /* minTopPosition*/, 0 /* minBottomPosition */, |
| 2579 | false /* shiftPulsingWithFirst */); |
| 2580 | minTopPosition = firstVisibleSection.getBounds().top; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2581 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 2582 | boolean shiftPulsingWithFirst = mHeadsUpManager.getAllEntries().count() <= 1 |
| 2583 | && (mAmbientState.isDozing() |
| 2584 | || (mKeyguardBypassController.getBypassEnabled() && onKeyguard)); |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2585 | for (NotificationSection section : mSections) { |
| 2586 | int minBottomPosition = minTopPosition; |
| 2587 | if (section == lastSection) { |
| 2588 | // 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] | 2589 | minBottomPosition = (int) (ViewState.getFinalTranslationY(mShelf) |
| 2590 | + mShelf.getIntrinsicHeight()); |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2591 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2592 | minTopPosition = section.updateBounds(minTopPosition, minBottomPosition, |
| 2593 | shiftPulsingWithFirst); |
| 2594 | shiftPulsingWithFirst = false; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2595 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2596 | } |
| 2597 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2598 | private NotificationSection getFirstVisibleSection() { |
| 2599 | for (NotificationSection section : mSections) { |
| 2600 | if (section.getFirstVisibleChild() != null) { |
| 2601 | return section; |
| 2602 | } |
| 2603 | } |
| 2604 | return null; |
| 2605 | } |
| 2606 | |
| 2607 | private NotificationSection getLastVisibleSection() { |
| 2608 | for (int i = mSections.length - 1; i >= 0; i--) { |
| 2609 | NotificationSection section = mSections[i]; |
| 2610 | if (section.getLastVisibleChild() != null) { |
| 2611 | return section; |
| 2612 | } |
| 2613 | } |
| 2614 | return null; |
| 2615 | } |
| 2616 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2617 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2618 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2619 | int childCount = getChildCount(); |
| 2620 | for (int i = childCount - 1; i >= 0; i--) { |
| 2621 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2622 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2623 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2624 | return (ActivatableNotificationView) child; |
| 2625 | } |
| 2626 | } |
| 2627 | return null; |
| 2628 | } |
| 2629 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2630 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2631 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2632 | int childCount = getChildCount(); |
| 2633 | for (int i = 0; i < childCount; i++) { |
| 2634 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2635 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2636 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2637 | return (ActivatableNotificationView) child; |
| 2638 | } |
| 2639 | } |
| 2640 | return null; |
| 2641 | } |
| 2642 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 2643 | //TODO: We shouldn't have to generate this list every time |
| 2644 | private List<ActivatableNotificationView> getChildrenWithBackground() { |
| 2645 | ArrayList<ActivatableNotificationView> children = new ArrayList<>(); |
| 2646 | int childCount = getChildCount(); |
| 2647 | for (int i = 0; i < childCount; i++) { |
| 2648 | View child = getChildAt(i); |
| 2649 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2650 | && child != mShelf) { |
| 2651 | children.add((ActivatableNotificationView) child); |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | return children; |
| 2656 | } |
| 2657 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2658 | /** |
| 2659 | * Fling the scroll view |
| 2660 | * |
| 2661 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2662 | * numbers mean that the finger/cursor is moving down the screen, |
| 2663 | * which means we want to scroll towards the top. |
| 2664 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2665 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2666 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2667 | if (getChildCount() > 0) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2668 | float topAmount = getCurrentOverScrollAmount(true); |
| 2669 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2670 | if (velocityY < 0 && topAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2671 | if (ANCHOR_SCROLLING) { |
| 2672 | mScrollAnchorViewY += topAmount; |
| 2673 | } else { |
| 2674 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
| 2675 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2676 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2677 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2678 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2679 | * mOverflingDistance + topAmount; |
| 2680 | } else if (velocityY > 0 && bottomAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2681 | if (ANCHOR_SCROLLING) { |
| 2682 | mScrollAnchorViewY -= bottomAmount; |
| 2683 | } else { |
| 2684 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
| 2685 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2686 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2687 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2688 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2689 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2690 | } else { |
| 2691 | // it will be set once we reach the boundary |
| 2692 | mMaxOverScroll = 0.0f; |
| 2693 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2694 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2695 | flingScroller(velocityY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2696 | } else { |
| 2697 | int scrollRange = getScrollRange(); |
| 2698 | int minScrollY = Math.max(0, scrollRange); |
| 2699 | if (mExpandedInThisMotion) { |
| 2700 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2701 | } |
| 2702 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2703 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2704 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2705 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2706 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2710 | /** |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2711 | * Flings the overscroller with the given velocity (anchor-based scrolling). |
| 2712 | * |
| 2713 | * Because anchor-based scrolling can't track the current scroll position, the overscroller is |
| 2714 | * always started at startY = 0, and we interpret the positions it computes as relative to the |
| 2715 | * start of the scroll. |
| 2716 | */ |
| 2717 | private void flingScroller(int velocityY) { |
| 2718 | assert ANCHOR_SCROLLING; |
| 2719 | mIsScrollerBoundSet = false; |
| 2720 | maybeFlingScroller(velocityY, true /* always fling */); |
| 2721 | } |
| 2722 | |
| 2723 | private void maybeFlingScroller(int velocityY, boolean alwaysFling) { |
| 2724 | assert ANCHOR_SCROLLING; |
| 2725 | // Attempt to determine the maximum amount to scroll before we reach the end. |
| 2726 | // If the first view is not materialized (for an upwards scroll) or the last view is either |
| 2727 | // not materialized or is pinned to the shade (for a downwards scroll), we don't know this |
| 2728 | // amount, so we do an unbounded fling and rely on {@link #maybeReflingScroller()} to update |
| 2729 | // the scroller once we approach the start/end of the list. |
| 2730 | int minY = Integer.MIN_VALUE; |
| 2731 | int maxY = Integer.MAX_VALUE; |
| 2732 | if (velocityY < 0) { |
| 2733 | minY = getMaxNegativeScrollAmount(); |
| 2734 | if (minY > Integer.MIN_VALUE) { |
| 2735 | mIsScrollerBoundSet = true; |
| 2736 | } |
| 2737 | } else { |
| 2738 | maxY = getMaxPositiveScrollAmount(); |
| 2739 | if (maxY < Integer.MAX_VALUE) { |
| 2740 | mIsScrollerBoundSet = true; |
| 2741 | } |
| 2742 | } |
| 2743 | if (mIsScrollerBoundSet || alwaysFling) { |
| 2744 | mLastScrollerY = 0; |
| 2745 | // x velocity is set to 1 to avoid overscroller bug |
| 2746 | mScroller.fling(0, 0, 1, velocityY, 0, 0, minY, maxY, 0, |
| 2747 | mExpandedInThisMotion && !isScrolledToTop() ? 0 : Integer.MAX_VALUE / 2); |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | /** |
| 2752 | * Returns the maximum number of pixels we can scroll in the positive direction (downwards) |
| 2753 | * before reaching the bottom of the list (discounting overscroll). |
| 2754 | * |
| 2755 | * If the return value is negative then we have overscrolled; this is a transient state which |
| 2756 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2757 | * the bottom overscroll amount. |
| 2758 | * |
| 2759 | * If we don't know how many pixels we have left to scroll (because the last row has not been |
| 2760 | * materialized, or it's in the shelf so it doesn't have its "natural" position), we return |
| 2761 | * {@link Integer#MAX_VALUE}. |
| 2762 | */ |
| 2763 | private int getMaxPositiveScrollAmount() { |
| 2764 | assert ANCHOR_SCROLLING; |
| 2765 | // TODO: once we're recycling we need to check the adapter position of the last child. |
| 2766 | ExpandableNotificationRow lastRow = getLastRowNotGone(); |
| 2767 | if (mScrollAnchorView != null && lastRow != null && !lastRow.isInShelf()) { |
| 2768 | // distance from bottom of last child to bottom of notifications area is: |
| 2769 | // distance from bottom of last child |
| 2770 | return (int) (lastRow.getTranslationY() + lastRow.getActualHeight() |
| 2771 | // to top of anchor view |
| 2772 | - mScrollAnchorView.getTranslationY() |
| 2773 | // plus distance from anchor view to top of notifications area |
| 2774 | + mScrollAnchorViewY |
| 2775 | // minus height of notifications area. |
| 2776 | - (mMaxLayoutHeight - getIntrinsicPadding() - mFooterView.getActualHeight())); |
| 2777 | } else { |
| 2778 | return Integer.MAX_VALUE; |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | /** |
| 2783 | * Returns the maximum number of pixels (as a negative number) we can scroll in the negative |
| 2784 | * direction (upwards) before reaching the top of the list (discounting overscroll). |
| 2785 | * |
| 2786 | * If the return value is positive then we have overscrolled; this is a transient state which |
| 2787 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2788 | * the top overscroll amount. |
| 2789 | * |
| 2790 | * If we don't know how many pixels we have left to scroll (because the first row has not been |
| 2791 | * materialized), we return {@link Integer#MIN_VALUE}. |
| 2792 | */ |
| 2793 | private int getMaxNegativeScrollAmount() { |
| 2794 | assert ANCHOR_SCROLLING; |
| 2795 | // TODO: once we're recycling we need to check the adapter position of the first child. |
| 2796 | ExpandableView firstChild = getFirstChildNotGone(); |
| 2797 | if (mScrollAnchorView != null && firstChild != null) { |
| 2798 | // distance from top of first child to top of notifications area is: |
| 2799 | // distance from top of anchor view |
| 2800 | return (int) -(mScrollAnchorView.getTranslationY() |
| 2801 | // to top of first child |
| 2802 | - firstChild.getTranslationY() |
| 2803 | // minus distance from top of anchor view to top of notifications area. |
| 2804 | - mScrollAnchorViewY); |
| 2805 | } else { |
| 2806 | return Integer.MIN_VALUE; |
| 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | /** |
| 2811 | * During a fling, if we were unable to set the bounds of the fling due to the top/bottom view |
| 2812 | * not being materialized or being pinned to the shelf, we need to check on every frame if we're |
| 2813 | * able to set the bounds. If we are, we fling the scroller again with the newly computed |
| 2814 | * bounds. |
| 2815 | */ |
| 2816 | private void maybeReflingScroller() { |
| 2817 | if (!mIsScrollerBoundSet) { |
| 2818 | // Because mScroller is a flywheel scroller, we fling with the minimum possible |
| 2819 | // velocity to establish direction, so as not to perceptibly affect the velocity. |
| 2820 | maybeFlingScroller((int) Math.signum(mScroller.getCurrVelocity()), |
| 2821 | false /* alwaysFling */); |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | /** |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2826 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2827 | * overScroll view (i.e QS). |
| 2828 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2829 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2830 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2831 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2832 | return mScrolledToTopOnFirstDown |
| 2833 | && !mExpandedInThisMotion |
| 2834 | && topOverScroll > mMinTopOverScrollToEscape |
| 2835 | && initialVelocity > 0; |
| 2836 | } |
| 2837 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2838 | /** |
| 2839 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2840 | * account. |
| 2841 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2842 | * @param qsHeight the top padding imposed by the quick settings panel |
| 2843 | * @param animate whether to animate the change |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2844 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2845 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 2846 | public void updateTopPadding(float qsHeight, boolean animate) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2847 | int topPadding = (int) qsHeight; |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2848 | int minStackHeight = getLayoutMinHeight(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2849 | if (topPadding + minStackHeight > getHeight()) { |
| 2850 | mTopPaddingOverflow = topPadding + minStackHeight - getHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2851 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2852 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2853 | } |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 2854 | setTopPadding(topPadding, animate && !mKeyguardBypassController.getBypassEnabled()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2855 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2856 | } |
| 2857 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2858 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2859 | public void setMaxTopPadding(int maxTopPadding) { |
| 2860 | mMaxTopPadding = maxTopPadding; |
| 2861 | } |
| 2862 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2863 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2864 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2865 | if (isHeadsUpTransition()) { |
| 2866 | return getTopHeadsUpPinnedHeight(); |
| 2867 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2868 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2871 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2872 | public float getTopPaddingOverflow() { |
| 2873 | return mTopPaddingOverflow; |
| 2874 | } |
| 2875 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2876 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2877 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2878 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2879 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2880 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2881 | int shelfHeight = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2882 | if (getLastVisibleSection() != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2883 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2884 | } |
| 2885 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2886 | } |
| 2887 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2888 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2889 | private int clampPadding(int desiredPadding) { |
| 2890 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2891 | } |
| 2892 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2893 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2894 | private float getRubberBandFactor(boolean onTop) { |
| 2895 | if (!onTop) { |
| 2896 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2897 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2898 | if (mExpandedInThisMotion) { |
| 2899 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2900 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2901 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2902 | } else if (mScrolledToTopOnFirstDown) { |
| 2903 | return 1.0f; |
| 2904 | } |
| 2905 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2906 | } |
| 2907 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2908 | /** |
| 2909 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2910 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2911 | * overscroll view (e.g. expand QS). |
| 2912 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2913 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2914 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2915 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2916 | || !mScrolledToTopOnFirstDown; |
| 2917 | } |
| 2918 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2919 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2920 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2921 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2922 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 2923 | Assert.isMainThread(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2924 | mChildTransferInProgress = childTransferInProgress; |
| 2925 | } |
| 2926 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2927 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2928 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2929 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2930 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2931 | // we only call our internal methods if this is actually a removal and not just a |
| 2932 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2933 | if (!mChildTransferInProgress) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2934 | onViewRemovedInternal((ExpandableView) child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2935 | } |
| 2936 | } |
| 2937 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2938 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2939 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2940 | public void cleanUpViewStateForEntry(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 2941 | View child = entry.getRow(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 2942 | if (child == mSwipeHelper.getTranslatingParentView()) { |
| 2943 | mSwipeHelper.clearTranslatingParentView(); |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2944 | } |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2945 | } |
| 2946 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2947 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2948 | private void onViewRemovedInternal(ExpandableView child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2949 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2950 | // This is only a position change, don't do anything special |
| 2951 | return; |
| 2952 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2953 | child.setOnHeightChangedListener(null); |
| 2954 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2955 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2956 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2957 | if (!mSwipedOutViews.contains(child) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2958 | || Math.abs(child.getTranslation()) != child.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2959 | container.addTransientView(child, 0); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2960 | child.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2961 | } |
| 2962 | } else { |
| 2963 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2964 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2965 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2966 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2967 | focusNextViewIfFocused(child); |
| 2968 | } |
| 2969 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2970 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2971 | private void focusNextViewIfFocused(View view) { |
| 2972 | if (view instanceof ExpandableNotificationRow) { |
| 2973 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2974 | if (row.shouldRefocusOnDismiss()) { |
| 2975 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 2976 | if (nextView == null) { |
| 2977 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 2978 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 2979 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2980 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2981 | } |
| 2982 | if (nextView != null) { |
| 2983 | nextView.requestAccessibilityFocus(); |
| 2984 | } |
| 2985 | } |
| 2986 | } |
| 2987 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2988 | } |
| 2989 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2990 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2991 | private boolean isChildInGroup(View child) { |
| 2992 | return child instanceof ExpandableNotificationRow |
| 2993 | && mGroupManager.isChildInGroupWithSummary( |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 2994 | ((ExpandableNotificationRow) child).getEntry().getSbn()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2995 | } |
| 2996 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2997 | /** |
| 2998 | * Generate a remove animation for a child view. |
| 2999 | * |
| 3000 | * @param child The view to generate the remove animation for. |
| 3001 | * @return Whether an animation was generated. |
| 3002 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3003 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3004 | private boolean generateRemoveAnimation(ExpandableView child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3005 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 3006 | mAddedHeadsUpChildren.remove(child); |
| 3007 | return false; |
| 3008 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3009 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3010 | // An animation is already running, add it transiently |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3011 | mClearTransientViewsWhenFinished.add(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3012 | return true; |
| 3013 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3014 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 3015 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3016 | // Generate Animations |
| 3017 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3018 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3019 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3020 | } else { |
| 3021 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3022 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3023 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3024 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3025 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3026 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3027 | } |
| 3028 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3029 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3030 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 3031 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3034 | /** |
| 3035 | * Remove a removed child view from the heads up animations if it was just added there |
| 3036 | * |
| 3037 | * @return whether any child was removed from the list to animate |
| 3038 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3039 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3040 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 3041 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3042 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 3043 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3044 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3045 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3046 | mTmpList.add(eventPair); |
| 3047 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3048 | } |
| 3049 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3050 | if (hasAddEvent) { |
| 3051 | // This child was just added lets remove all events. |
| 3052 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3053 | ((ExpandableNotificationRow) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3054 | } |
| 3055 | mTmpList.clear(); |
| 3056 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3059 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3060 | * @param child the child to query |
| 3061 | * @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] | 3062 | * not expanded |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3063 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3064 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3065 | private boolean isChildInInvisibleGroup(View child) { |
| 3066 | if (child instanceof ExpandableNotificationRow) { |
| 3067 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 3068 | NotificationEntry groupSummary = |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 3069 | mGroupManager.getGroupSummary(row.getEntry().getSbn()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 3070 | if (groupSummary != null && groupSummary.getRow() != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 3071 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3072 | } |
| 3073 | } |
| 3074 | return false; |
| 3075 | } |
| 3076 | |
| 3077 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3078 | * Updates the scroll position when a child was removed |
| 3079 | * |
| 3080 | * @param removedChild the removed child |
| 3081 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3082 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3083 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3084 | if (ANCHOR_SCROLLING) { |
| 3085 | if (removedChild == mScrollAnchorView) { |
| 3086 | ExpandableView firstChild = getFirstChildNotGone(); |
| 3087 | if (firstChild != null) { |
| 3088 | mScrollAnchorView = firstChild; |
| 3089 | } else { |
| 3090 | mScrollAnchorView = mShelf; |
| 3091 | } |
| 3092 | // Adjust anchor view Y by the distance between the old and new anchors |
| 3093 | // so that there's no visible change. |
| 3094 | mScrollAnchorViewY += |
| 3095 | mScrollAnchorView.getTranslationY() - removedChild.getTranslationY(); |
| 3096 | } |
| 3097 | updateScrollAnchor(); |
| 3098 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3099 | if (mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY > 0) { |
| 3100 | mScrollAnchorViewY = 0; |
| 3101 | } |
| 3102 | updateOnScrollChange(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3103 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3104 | int startingPosition = getPositionInLinearLayout(removedChild); |
| 3105 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 3106 | int padding; |
| 3107 | if (increasedPaddingAmount >= 0) { |
| 3108 | padding = (int) NotificationUtils.interpolate( |
| 3109 | mPaddingBetweenElements, |
| 3110 | mIncreasedPaddingBetweenElements, |
| 3111 | increasedPaddingAmount); |
| 3112 | } else { |
| 3113 | padding = (int) NotificationUtils.interpolate( |
| 3114 | 0, |
| 3115 | mPaddingBetweenElements, |
| 3116 | 1.0f + increasedPaddingAmount); |
| 3117 | } |
| 3118 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
| 3119 | int endPosition = startingPosition + childHeight; |
| 3120 | if (endPosition <= mOwnScrollY) { |
| 3121 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 3122 | // scrollPosition |
| 3123 | setOwnScrollY(mOwnScrollY - childHeight); |
| 3124 | } else if (startingPosition < mOwnScrollY) { |
| 3125 | // This child is currently being scrolled into, set the scroll position to the |
| 3126 | // start of this child |
| 3127 | setOwnScrollY(startingPosition); |
| 3128 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3132 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 3133 | private int getIntrinsicHeight(View view) { |
| 3134 | if (view instanceof ExpandableView) { |
| 3135 | ExpandableView expandableView = (ExpandableView) view; |
| 3136 | return expandableView.getIntrinsicHeight(); |
| 3137 | } |
| 3138 | return view.getHeight(); |
| 3139 | } |
| 3140 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3141 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3142 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3143 | ExpandableNotificationRow childInGroup = null; |
| 3144 | ExpandableNotificationRow requestedRow = null; |
| 3145 | if (isChildInGroup(requestedView)) { |
| 3146 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 3147 | // then within the parent. |
| 3148 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 3149 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 3150 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3151 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3152 | float previousPaddingRequest = mPaddingBetweenElements; |
| 3153 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3154 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3155 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3156 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 3157 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3158 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3159 | float padding; |
| 3160 | if (increasedPaddingAmount >= 0.0f) { |
| 3161 | padding = (int) NotificationUtils.interpolate( |
| 3162 | previousPaddingRequest, |
| 3163 | mIncreasedPaddingBetweenElements, |
| 3164 | increasedPaddingAmount); |
| 3165 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3166 | mPaddingBetweenElements, |
| 3167 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3168 | increasedPaddingAmount); |
| 3169 | } else { |
| 3170 | int ownPadding = (int) NotificationUtils.interpolate( |
| 3171 | 0, |
| 3172 | mPaddingBetweenElements, |
| 3173 | 1.0f + increasedPaddingAmount); |
| 3174 | if (previousPaddingAmount > 0.0f) { |
| 3175 | padding = (int) NotificationUtils.interpolate( |
| 3176 | ownPadding, |
| 3177 | mIncreasedPaddingBetweenElements, |
| 3178 | previousPaddingAmount); |
| 3179 | } else { |
| 3180 | padding = ownPadding; |
| 3181 | } |
| 3182 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3183 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3184 | if (position != 0) { |
| 3185 | position += padding; |
| 3186 | } |
| 3187 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3188 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3189 | if (child == requestedView) { |
| 3190 | if (requestedRow != null) { |
| 3191 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3192 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3193 | return position; |
| 3194 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3195 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3196 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3203 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3204 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3205 | super.onViewAdded(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3206 | onViewAddedInternal((ExpandableView) child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3207 | } |
| 3208 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3209 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3210 | private void updateFirstAndLastBackgroundViews() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3211 | NotificationSection firstSection = getFirstVisibleSection(); |
| 3212 | NotificationSection lastSection = getLastVisibleSection(); |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3213 | ActivatableNotificationView previousFirstChild = |
| 3214 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 3215 | ActivatableNotificationView previousLastChild = |
| 3216 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3217 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3218 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3219 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 3220 | boolean sectionViewsChanged = mSectionsManager.updateFirstAndLastViewsForAllSections( |
| 3221 | mSections, getChildrenWithBackground()); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3222 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3223 | if (mAnimationsEnabled && mIsExpanded) { |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3224 | mAnimateNextBackgroundTop = firstChild != previousFirstChild; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3225 | mAnimateNextBackgroundBottom = lastChild != previousLastChild || mAnimateBottomOnLayout; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3226 | mAnimateNextSectionBoundsChange = sectionViewsChanged; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3227 | } else { |
| 3228 | mAnimateNextBackgroundTop = false; |
| 3229 | mAnimateNextBackgroundBottom = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3230 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3231 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3232 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3233 | mRoundnessManager.updateRoundedChildren(mSections); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3234 | mAnimateBottomOnLayout = false; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3235 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3236 | } |
| 3237 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3238 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3239 | private void onViewAddedInternal(ExpandableView child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3240 | updateHideSensitiveForChild(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3241 | child.setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3242 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3243 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3244 | updateChronometerForChild(child); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 3245 | if (child instanceof ExpandableNotificationRow) { |
| 3246 | ((ExpandableNotificationRow) child).setDismissRtl(mDismissRtl); |
| 3247 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3248 | if (ANCHOR_SCROLLING) { |
| 3249 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3250 | if (child == getFirstChildNotGone() && (isScrolledToTop() || !mIsExpanded)) { |
| 3251 | // New child was added at the top while we're scrolled to the top; |
| 3252 | // make it the new anchor view so that we stay at the top. |
| 3253 | mScrollAnchorView = child; |
| 3254 | } |
| 3255 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3256 | } |
| 3257 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3258 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3259 | private void updateHideSensitiveForChild(ExpandableView child) { |
| 3260 | child.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3261 | } |
| 3262 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3263 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3264 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3265 | public void notifyGroupChildRemoved(ExpandableView row, ViewGroup childrenContainer) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3266 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3267 | } |
| 3268 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3269 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3270 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3271 | public void notifyGroupChildAdded(ExpandableView row) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3272 | onViewAddedInternal(row); |
| 3273 | } |
| 3274 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3275 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3276 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3277 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3278 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3279 | if (!animationsEnabled) { |
| 3280 | mSwipedOutViews.clear(); |
| 3281 | mChildrenToRemoveAnimated.clear(); |
| 3282 | clearTemporaryViewsInGroup(this); |
| 3283 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3284 | } |
| 3285 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3286 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3287 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3288 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3289 | mShelf.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3290 | int childCount = getChildCount(); |
| 3291 | for (int i = 0; i < childCount; i++) { |
| 3292 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3293 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3294 | updateAnimationState(running, child); |
| 3295 | } |
| 3296 | } |
| 3297 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3298 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3299 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3300 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3301 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3302 | } |
| 3303 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3304 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3305 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3306 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3307 | mAmbientState.setExpandingNotification(row); |
| 3308 | requestChildrenUpdate(); |
| 3309 | } |
| 3310 | |
| 3311 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3312 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3313 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3314 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3315 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3316 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3317 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | @Override |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 3321 | public boolean containsView(View v) { |
| 3322 | return v.getParent() == this; |
| 3323 | } |
| 3324 | |
| 3325 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3326 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3327 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3328 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3329 | requestChildrenUpdate(); |
| 3330 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3331 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3332 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3333 | private void updateAnimationState(boolean running, View child) { |
| 3334 | if (child instanceof ExpandableNotificationRow) { |
| 3335 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3336 | row.setIconAnimationRunning(running); |
| 3337 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3338 | } |
| 3339 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3340 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3341 | public boolean isAddOrRemoveAnimationPending() { |
| 3342 | return mNeedsAnimation |
| 3343 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3344 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3345 | |
| 3346 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3347 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3348 | public void generateAddAnimation(ExpandableView child, boolean fromMoreCard) { |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 3349 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress && !isFullyHidden()) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3350 | // Generate Animations |
| 3351 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3352 | if (fromMoreCard) { |
| 3353 | mFromMoreCardAdditions.add(child); |
| 3354 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3355 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3356 | } |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 3357 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress |
| 3358 | && !isFullyHidden()) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3359 | mAddedHeadsUpChildren.add(child); |
| 3360 | mChildrenToAddAnimated.remove(child); |
| 3361 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3362 | } |
| 3363 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3364 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3365 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3366 | public void changeViewPosition(ExpandableView child, int newIndex) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 3367 | Assert.isMainThread(); |
| 3368 | if (mChangePositionInProgress) { |
| 3369 | throw new IllegalStateException("Reentrant call to changeViewPosition"); |
| 3370 | } |
| 3371 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3372 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3373 | |
| 3374 | if (currentIndex == -1) { |
| 3375 | boolean isTransient = false; |
| 3376 | if (child instanceof ExpandableNotificationRow |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3377 | && ((ExpandableNotificationRow) child).getTransientContainer() != null) { |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3378 | isTransient = true; |
| 3379 | } |
| 3380 | Log.e(TAG, "Attempting to re-position " |
| 3381 | + (isTransient ? "transient" : "") |
| 3382 | + " view {" |
| 3383 | + child |
| 3384 | + "}"); |
| 3385 | return; |
| 3386 | } |
| 3387 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3388 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3389 | mChangePositionInProgress = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3390 | ((ExpandableView) child).setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3391 | removeView(child); |
| 3392 | addView(child, newIndex); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3393 | ((ExpandableView) child).setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3394 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3395 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3396 | mChildrenChangingPositions.add(child); |
| 3397 | mNeedsAnimation = true; |
| 3398 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3402 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3403 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3404 | if (mNeedsAnimation) { |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3405 | generateAllAnimationEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3406 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3407 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3408 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3409 | setAnimationRunning(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3410 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3411 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3412 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3413 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3414 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3415 | } else { |
| 3416 | applyCurrentState(); |
| 3417 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3418 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3419 | } |
| 3420 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3421 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3422 | private void generateAllAnimationEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3423 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3424 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3425 | generateChildAdditionEvents(); |
| 3426 | generatePositionChangeEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3427 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3428 | generateActivateEvent(); |
| 3429 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3430 | generateHideSensitiveEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3431 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3432 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3433 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3434 | generateAnimateEverythingEvent(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3435 | } |
| 3436 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3437 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3438 | private void generateHeadsUpAnimationEvents() { |
| 3439 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3440 | ExpandableNotificationRow row = eventPair.first; |
| 3441 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 3442 | if (isHeadsUp != row.isHeadsUp()) { |
| 3443 | // For cases where we have a heads up showing and appearing again we shouldn't |
| 3444 | // do the animations at all. |
| 3445 | continue; |
| 3446 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3447 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3448 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3449 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 3450 | boolean performDisappearAnimation = !mIsExpanded |
| 3451 | // Only animate if we still have pinned heads up, otherwise we just have the |
| 3452 | // regular collapse animation of the lock screen |
| 3453 | || (mKeyguardBypassController.getBypassEnabled() && onKeyguard() |
| 3454 | && mHeadsUpManager.hasPinnedHeadsUp()); |
| 3455 | if (performDisappearAnimation && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3456 | type = row.wasJustClicked() |
| 3457 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3458 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3459 | if (row.isChildInGroup()) { |
| 3460 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3461 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3462 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3463 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3464 | } else { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3465 | ExpandableViewState viewState = row.getViewState(); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3466 | if (viewState == null) { |
| 3467 | // A view state was never generated for this view, so we don't need to animate |
| 3468 | // this. This may happen with notification children. |
| 3469 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3470 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3471 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3472 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3473 | // Our custom add animation |
| 3474 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3475 | } else { |
| 3476 | // Normal add animation |
| 3477 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3478 | } |
| 3479 | onBottom = !pinnedAndClosed; |
| 3480 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3481 | } |
| 3482 | AnimationEvent event = new AnimationEvent(row, type); |
| 3483 | event.headsUpFromBottom = onBottom; |
| 3484 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3485 | } |
| 3486 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3487 | mAddedHeadsUpChildren.clear(); |
| 3488 | } |
| 3489 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3490 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3491 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3492 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3493 | return false; |
| 3494 | } |
| 3495 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3498 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3499 | private void generateGroupExpansionEvent() { |
| 3500 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3501 | if (mExpandedGroupView != null) { |
| 3502 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3503 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3504 | mExpandedGroupView = null; |
| 3505 | } |
| 3506 | } |
| 3507 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3508 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3509 | private void generateViewResizeEvent() { |
| 3510 | if (mNeedViewResizeAnimation) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3511 | boolean hasDisappearAnimation = false; |
| 3512 | for (AnimationEvent animationEvent : mAnimationEvents) { |
| 3513 | final int type = animationEvent.animationType; |
| 3514 | if (type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3515 | || type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3516 | hasDisappearAnimation = true; |
| 3517 | break; |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | if (!hasDisappearAnimation) { |
| 3522 | mAnimationEvents.add( |
| 3523 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3524 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3525 | } |
| 3526 | mNeedViewResizeAnimation = false; |
| 3527 | } |
| 3528 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3529 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3530 | private void generateChildRemovalEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3531 | for (ExpandableView child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3532 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3533 | |
| 3534 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3535 | float removedTranslation = child.getTranslationY(); |
| 3536 | boolean ignoreChildren = true; |
| 3537 | if (child instanceof ExpandableNotificationRow) { |
| 3538 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3539 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3540 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3541 | ignoreChildren = false; |
| 3542 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3543 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3544 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3545 | if (!childWasSwipedOut) { |
| 3546 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3547 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3548 | |
| 3549 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3550 | // Clean up any potential transient views if the child has already been swiped |
| 3551 | // out, as we won't be animating it further (due to its height already being |
| 3552 | // clipped to 0. |
| 3553 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3554 | if (transientContainer != null) { |
| 3555 | transientContainer.removeTransientView(child); |
| 3556 | } |
| 3557 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3558 | } |
| 3559 | int animationType = childWasSwipedOut |
| 3560 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3561 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3562 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3563 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3564 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3565 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3566 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3567 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3568 | mChildrenToRemoveAnimated.clear(); |
| 3569 | } |
| 3570 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3571 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3572 | private void generatePositionChangeEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3573 | for (ExpandableView child : mChildrenChangingPositions) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3574 | mAnimationEvents.add(new AnimationEvent(child, |
| 3575 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3576 | } |
| 3577 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3578 | if (mGenerateChildOrderChangedEvent) { |
| 3579 | mAnimationEvents.add(new AnimationEvent(null, |
| 3580 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3581 | mGenerateChildOrderChangedEvent = false; |
| 3582 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3583 | } |
| 3584 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3585 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3586 | private void generateChildAdditionEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3587 | for (ExpandableView child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3588 | if (mFromMoreCardAdditions.contains(child)) { |
| 3589 | mAnimationEvents.add(new AnimationEvent(child, |
| 3590 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3591 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3592 | } else { |
| 3593 | mAnimationEvents.add(new AnimationEvent(child, |
| 3594 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3595 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3596 | } |
| 3597 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3598 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3599 | } |
| 3600 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3601 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3602 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3603 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3604 | AnimationEvent event; |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 3605 | if (mAmbientState.isDozing()) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3606 | event = new AnimationEvent(null /* view */, |
| 3607 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3608 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3609 | } else { |
| 3610 | event = new AnimationEvent(null /* view */, |
| 3611 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3612 | } |
| 3613 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3614 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3615 | mTopPaddingNeedsAnimation = false; |
| 3616 | } |
| 3617 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3618 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3619 | private void generateActivateEvent() { |
| 3620 | if (mActivateNeedsAnimation) { |
| 3621 | mAnimationEvents.add( |
| 3622 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3623 | } |
| 3624 | mActivateNeedsAnimation = false; |
| 3625 | } |
| 3626 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3627 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3628 | private void generateAnimateEverythingEvent() { |
| 3629 | if (mEverythingNeedsAnimation) { |
| 3630 | mAnimationEvents.add( |
| 3631 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3632 | } |
| 3633 | mEverythingNeedsAnimation = false; |
| 3634 | } |
| 3635 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3636 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3637 | private void generateDimmedEvent() { |
| 3638 | if (mDimmedNeedsAnimation) { |
| 3639 | mAnimationEvents.add( |
| 3640 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3641 | } |
| 3642 | mDimmedNeedsAnimation = false; |
| 3643 | } |
| 3644 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3645 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3646 | private void generateHideSensitiveEvent() { |
| 3647 | if (mHideSensitiveNeedsAnimation) { |
| 3648 | mAnimationEvents.add( |
| 3649 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3650 | } |
| 3651 | mHideSensitiveNeedsAnimation = false; |
| 3652 | } |
| 3653 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3654 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3655 | private void generateGoToFullShadeEvent() { |
| 3656 | if (mGoToFullShadeNeedsAnimation) { |
| 3657 | mAnimationEvents.add( |
| 3658 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3659 | } |
| 3660 | mGoToFullShadeNeedsAnimation = false; |
| 3661 | } |
| 3662 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3663 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
| 3664 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3665 | return new StackScrollAlgorithm(context, this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | /** |
| 3669 | * @return Whether a y coordinate is inside the content. |
| 3670 | */ |
| 3671 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 3672 | public boolean isInContentBounds(float y) { |
| 3673 | return y < getHeight() - getEmptyBottomMargin(); |
| 3674 | } |
| 3675 | |
| 3676 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3677 | public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) { |
| 3678 | mLongPressListener = listener; |
| 3679 | } |
| 3680 | |
| 3681 | @Override |
| 3682 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3683 | public boolean onTouchEvent(MotionEvent ev) { |
| 3684 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 3685 | || ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3686 | handleEmptySpaceClick(ev); |
| 3687 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3688 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3689 | if (mIsExpanded && !swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3690 | if (isCancelOrUp) { |
| 3691 | mExpandHelper.onlyObserveMovements(false); |
| 3692 | } |
| 3693 | boolean wasExpandingBefore = mExpandingNotification; |
| 3694 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
| 3695 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 3696 | && !mDisallowScrollingInThisMotion) { |
| 3697 | dispatchDownEventToScroller(ev); |
| 3698 | } |
| 3699 | } |
| 3700 | boolean scrollerWantsIt = false; |
| 3701 | if (mIsExpanded && !swipingInProgress && !mExpandingNotification |
| 3702 | && !mDisallowScrollingInThisMotion) { |
| 3703 | scrollerWantsIt = onScrollTouch(ev); |
| 3704 | } |
| 3705 | boolean horizontalSwipeWantsIt = false; |
| 3706 | if (!mIsBeingDragged |
| 3707 | && !mExpandingNotification |
| 3708 | && !mExpandedInThisMotion |
| 3709 | && !mOnlyScrollingInThisMotion |
| 3710 | && !mDisallowDismissInThisMotion) { |
| 3711 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 3712 | } |
| 3713 | |
| 3714 | // Check if we need to clear any snooze leavebehinds |
| 3715 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3716 | if (guts != null && !NotificationSwipeHelper.isTouchInView(ev, guts) |
| 3717 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 3718 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 3719 | if ((ns.isExpanded() && isCancelOrUp) |
| 3720 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 3721 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 3722 | // clear it on the next non-horizontal swipe or expand event. |
| 3723 | checkSnoozeLeavebehind(); |
| 3724 | } |
| 3725 | } |
| 3726 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3727 | mCheckForLeavebehind = true; |
| 3728 | } |
| 3729 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 3730 | } |
| 3731 | |
| 3732 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3733 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 3734 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 3735 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 3736 | onScrollTouch(downEvent); |
| 3737 | downEvent.recycle(); |
| 3738 | } |
| 3739 | |
| 3740 | @Override |
| 3741 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3742 | public boolean onGenericMotionEvent(MotionEvent event) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3743 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3744 | || mDisallowScrollingInThisMotion) { |
| 3745 | return false; |
| 3746 | } |
| 3747 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3748 | switch (event.getAction()) { |
| 3749 | case MotionEvent.ACTION_SCROLL: { |
| 3750 | if (!mIsBeingDragged) { |
| 3751 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 3752 | if (vscroll != 0) { |
| 3753 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3754 | if (ANCHOR_SCROLLING) { |
| 3755 | mScrollAnchorViewY -= delta; |
| 3756 | updateScrollAnchor(); |
| 3757 | clampScrollPosition(); |
| 3758 | updateOnScrollChange(); |
| 3759 | } else { |
| 3760 | final int range = getScrollRange(); |
| 3761 | int oldScrollY = mOwnScrollY; |
| 3762 | int newScrollY = oldScrollY - delta; |
| 3763 | if (newScrollY < 0) { |
| 3764 | newScrollY = 0; |
| 3765 | } else if (newScrollY > range) { |
| 3766 | newScrollY = range; |
| 3767 | } |
| 3768 | if (newScrollY != oldScrollY) { |
| 3769 | setOwnScrollY(newScrollY); |
| 3770 | return true; |
| 3771 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3772 | } |
| 3773 | } |
| 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | } |
| 3778 | return super.onGenericMotionEvent(event); |
| 3779 | } |
| 3780 | |
| 3781 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3782 | private boolean onScrollTouch(MotionEvent ev) { |
| 3783 | if (!isScrollingEnabled()) { |
| 3784 | return false; |
| 3785 | } |
| 3786 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
| 3787 | return false; |
| 3788 | } |
| 3789 | mForcedScroll = null; |
| 3790 | initVelocityTrackerIfNotExists(); |
| 3791 | mVelocityTracker.addMovement(ev); |
| 3792 | |
| 3793 | final int action = ev.getAction(); |
| 3794 | |
| 3795 | switch (action & MotionEvent.ACTION_MASK) { |
| 3796 | case MotionEvent.ACTION_DOWN: { |
| 3797 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
| 3798 | return false; |
| 3799 | } |
| 3800 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3801 | setIsBeingDragged(isBeingDragged); |
| 3802 | /* |
| 3803 | * If being flinged and user touches, stop the fling. isFinished |
| 3804 | * will be false if being flinged. |
| 3805 | */ |
| 3806 | if (!mScroller.isFinished()) { |
| 3807 | mScroller.forceFinished(true); |
| 3808 | } |
| 3809 | |
| 3810 | // Remember where the motion event started |
| 3811 | mLastMotionY = (int) ev.getY(); |
| 3812 | mDownX = (int) ev.getX(); |
| 3813 | mActivePointerId = ev.getPointerId(0); |
| 3814 | break; |
| 3815 | } |
| 3816 | case MotionEvent.ACTION_MOVE: |
| 3817 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 3818 | if (activePointerIndex == -1) { |
| 3819 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 3820 | break; |
| 3821 | } |
| 3822 | |
| 3823 | final int y = (int) ev.getY(activePointerIndex); |
| 3824 | final int x = (int) ev.getX(activePointerIndex); |
| 3825 | int deltaY = mLastMotionY - y; |
| 3826 | final int xDiff = Math.abs(x - mDownX); |
| 3827 | final int yDiff = Math.abs(deltaY); |
| 3828 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
| 3829 | setIsBeingDragged(true); |
| 3830 | if (deltaY > 0) { |
| 3831 | deltaY -= mTouchSlop; |
| 3832 | } else { |
| 3833 | deltaY += mTouchSlop; |
| 3834 | } |
| 3835 | } |
| 3836 | if (mIsBeingDragged) { |
| 3837 | // Scroll to follow the motion event |
| 3838 | mLastMotionY = y; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3839 | float scrollAmount; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3840 | int range; |
| 3841 | if (ANCHOR_SCROLLING) { |
| 3842 | range = 0; // unused in the methods it's being passed to |
| 3843 | } else { |
| 3844 | range = getScrollRange(); |
| 3845 | if (mExpandedInThisMotion) { |
| 3846 | range = Math.min(range, mMaxScrollAfterExpand); |
| 3847 | } |
| 3848 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3849 | if (deltaY < 0) { |
| 3850 | scrollAmount = overScrollDown(deltaY); |
| 3851 | } else { |
| 3852 | scrollAmount = overScrollUp(deltaY, range); |
| 3853 | } |
| 3854 | |
| 3855 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 3856 | // sets the scrolling if applicable. |
| 3857 | if (scrollAmount != 0.0f) { |
| 3858 | // The scrolling motion could not be compensated with the |
| 3859 | // existing overScroll, we have to scroll the view |
| 3860 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 3861 | range, getHeight() / 2); |
| 3862 | // If we're scrolling, leavebehinds should be dismissed |
| 3863 | checkSnoozeLeavebehind(); |
| 3864 | } |
| 3865 | } |
| 3866 | break; |
| 3867 | case MotionEvent.ACTION_UP: |
| 3868 | if (mIsBeingDragged) { |
| 3869 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 3870 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 3871 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 3872 | |
| 3873 | if (shouldOverScrollFling(initialVelocity)) { |
| 3874 | onOverScrollFling(true, initialVelocity); |
| 3875 | } else { |
| 3876 | if (getChildCount() > 0) { |
| 3877 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 3878 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 3879 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 3880 | fling(-initialVelocity); |
| 3881 | } else { |
| 3882 | onOverScrollFling(false, initialVelocity); |
| 3883 | } |
| 3884 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3885 | if (ANCHOR_SCROLLING) { |
| 3886 | // TODO |
| 3887 | } else { |
| 3888 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3889 | getScrollRange())) { |
| 3890 | animateScroll(); |
| 3891 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | } |
| 3895 | } |
| 3896 | mActivePointerId = INVALID_POINTER; |
| 3897 | endDrag(); |
| 3898 | } |
| 3899 | |
| 3900 | break; |
| 3901 | case MotionEvent.ACTION_CANCEL: |
| 3902 | if (mIsBeingDragged && getChildCount() > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3903 | if (ANCHOR_SCROLLING) { |
| 3904 | // TODO |
| 3905 | } else { |
| 3906 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3907 | getScrollRange())) { |
| 3908 | animateScroll(); |
| 3909 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3910 | } |
| 3911 | mActivePointerId = INVALID_POINTER; |
| 3912 | endDrag(); |
| 3913 | } |
| 3914 | break; |
| 3915 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 3916 | final int index = ev.getActionIndex(); |
| 3917 | mLastMotionY = (int) ev.getY(index); |
| 3918 | mDownX = (int) ev.getX(index); |
| 3919 | mActivePointerId = ev.getPointerId(index); |
| 3920 | break; |
| 3921 | } |
| 3922 | case MotionEvent.ACTION_POINTER_UP: |
| 3923 | onSecondaryPointerUp(ev); |
| 3924 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
| 3925 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
| 3926 | break; |
| 3927 | } |
| 3928 | return true; |
| 3929 | } |
| 3930 | |
| 3931 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3932 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 3933 | return ev.getY() < mQsContainer.getBottom(); |
| 3934 | } |
| 3935 | |
| 3936 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3937 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 3938 | if (mOverscrollTopChangedListener != null) { |
| 3939 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 3940 | } |
| 3941 | mDontReportNextOverScroll = true; |
| 3942 | setOverScrollAmount(0.0f, true, false); |
| 3943 | } |
| 3944 | |
| 3945 | |
| 3946 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3947 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 3948 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 3949 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 3950 | final int pointerId = ev.getPointerId(pointerIndex); |
| 3951 | if (pointerId == mActivePointerId) { |
| 3952 | // This was our active pointer going up. Choose a new |
| 3953 | // active pointer and adjust accordingly. |
| 3954 | // TODO: Make this decision more intelligent. |
| 3955 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 3956 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 3957 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 3958 | if (mVelocityTracker != null) { |
| 3959 | mVelocityTracker.clear(); |
| 3960 | } |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3965 | private void endDrag() { |
| 3966 | setIsBeingDragged(false); |
| 3967 | |
| 3968 | recycleVelocityTracker(); |
| 3969 | |
| 3970 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 3971 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 3972 | } |
| 3973 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 3974 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 3975 | } |
| 3976 | } |
| 3977 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3978 | @Override |
| 3979 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3980 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 3981 | initDownStates(ev); |
| 3982 | handleEmptySpaceClick(ev); |
| 3983 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3984 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3985 | if (!swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3986 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 3987 | } |
| 3988 | boolean scrollWantsIt = false; |
| 3989 | if (!swipingInProgress && !mExpandingNotification) { |
| 3990 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 3991 | } |
| 3992 | boolean swipeWantsIt = false; |
| 3993 | if (!mIsBeingDragged |
| 3994 | && !mExpandingNotification |
| 3995 | && !mExpandedInThisMotion |
| 3996 | && !mOnlyScrollingInThisMotion |
| 3997 | && !mDisallowDismissInThisMotion) { |
| 3998 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 3999 | } |
| 4000 | // Check if we need to clear any snooze leavebehinds |
| 4001 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 4002 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 4003 | if (!NotificationSwipeHelper.isTouchInView(ev, guts) && isUp && !swipeWantsIt && |
| 4004 | !expandWantsIt && !scrollWantsIt) { |
| 4005 | mCheckForLeavebehind = false; |
| 4006 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 4007 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4008 | false /* resetMenu */); |
| 4009 | } |
| 4010 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 4011 | mCheckForLeavebehind = true; |
| 4012 | } |
| 4013 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 4014 | } |
| 4015 | |
| 4016 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4017 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 4018 | switch (ev.getActionMasked()) { |
| 4019 | case MotionEvent.ACTION_MOVE: |
| 4020 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 4021 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop)) { |
| 4022 | mTouchIsClick = false; |
| 4023 | } |
| 4024 | break; |
| 4025 | case MotionEvent.ACTION_UP: |
| 4026 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
| 4027 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 4028 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 4029 | } |
| 4030 | break; |
| 4031 | } |
| 4032 | } |
| 4033 | |
| 4034 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4035 | private void initDownStates(MotionEvent ev) { |
| 4036 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 4037 | mExpandedInThisMotion = false; |
| 4038 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
| 4039 | mDisallowScrollingInThisMotion = false; |
| 4040 | mDisallowDismissInThisMotion = false; |
| 4041 | mTouchIsClick = true; |
| 4042 | mInitialTouchX = ev.getX(); |
| 4043 | mInitialTouchY = ev.getY(); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | @Override |
| 4048 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4049 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 4050 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 4051 | if (disallowIntercept) { |
| 4052 | cancelLongPress(); |
| 4053 | } |
| 4054 | } |
| 4055 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4056 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4057 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4058 | if (!isScrollingEnabled()) { |
| 4059 | return false; |
| 4060 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4061 | /* |
| 4062 | * This method JUST determines whether we want to intercept the motion. |
| 4063 | * If we return true, onMotionEvent will be called and we do the actual |
| 4064 | * scrolling there. |
| 4065 | */ |
| 4066 | |
| 4067 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4068 | * Shortcut the most recurring case: the user is in the dragging |
| 4069 | * state and is moving their finger. We want to intercept this |
| 4070 | * motion. |
| 4071 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4072 | final int action = ev.getAction(); |
| 4073 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 4074 | return true; |
| 4075 | } |
| 4076 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4077 | switch (action & MotionEvent.ACTION_MASK) { |
| 4078 | case MotionEvent.ACTION_MOVE: { |
| 4079 | /* |
| 4080 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 4081 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4082 | */ |
| 4083 | |
| 4084 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4085 | * Locally do absolute value. mLastMotionY is set to the y value |
| 4086 | * of the down event. |
| 4087 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4088 | final int activePointerId = mActivePointerId; |
| 4089 | if (activePointerId == INVALID_POINTER) { |
| 4090 | // If we don't have a valid id, the touch down wasn't on content. |
| 4091 | break; |
| 4092 | } |
| 4093 | |
| 4094 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 4095 | if (pointerIndex == -1) { |
| 4096 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 4097 | + " in onInterceptTouchEvent"); |
| 4098 | break; |
| 4099 | } |
| 4100 | |
| 4101 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4102 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4103 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4104 | final int xDiff = Math.abs(x - mDownX); |
| 4105 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4106 | setIsBeingDragged(true); |
| 4107 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4108 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4109 | initVelocityTrackerIfNotExists(); |
| 4110 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4111 | } |
| 4112 | break; |
| 4113 | } |
| 4114 | |
| 4115 | case MotionEvent.ACTION_DOWN: { |
| 4116 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 4117 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 4118 | if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4119 | setIsBeingDragged(false); |
| 4120 | recycleVelocityTracker(); |
| 4121 | break; |
| 4122 | } |
| 4123 | |
| 4124 | /* |
| 4125 | * Remember location of down touch. |
| 4126 | * ACTION_DOWN always refers to pointer index 0. |
| 4127 | */ |
| 4128 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4129 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4130 | mActivePointerId = ev.getPointerId(0); |
| 4131 | |
| 4132 | initOrResetVelocityTracker(); |
| 4133 | mVelocityTracker.addMovement(ev); |
| 4134 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4135 | * If being flinged and user touches the screen, initiate drag; |
| 4136 | * otherwise don't. mScroller.isFinished should be false when |
| 4137 | * being flinged. |
| 4138 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4139 | boolean isBeingDragged = !mScroller.isFinished(); |
| 4140 | setIsBeingDragged(isBeingDragged); |
| 4141 | break; |
| 4142 | } |
| 4143 | |
| 4144 | case MotionEvent.ACTION_CANCEL: |
| 4145 | case MotionEvent.ACTION_UP: |
| 4146 | /* Release the drag */ |
| 4147 | setIsBeingDragged(false); |
| 4148 | mActivePointerId = INVALID_POINTER; |
| 4149 | recycleVelocityTracker(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4150 | if (ANCHOR_SCROLLING) { |
| 4151 | // TODO |
| 4152 | } else { |
| 4153 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 4154 | animateScroll(); |
| 4155 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4156 | } |
| 4157 | break; |
| 4158 | case MotionEvent.ACTION_POINTER_UP: |
| 4159 | onSecondaryPointerUp(ev); |
| 4160 | break; |
| 4161 | } |
| 4162 | |
| 4163 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4164 | * The only time we want to intercept motion events is if we are in the |
| 4165 | * drag mode. |
| 4166 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4167 | return mIsBeingDragged; |
| 4168 | } |
| 4169 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4170 | /** |
| 4171 | * @return Whether the specified motion event is actually happening over the content. |
| 4172 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4173 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4174 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 4175 | return isInContentBounds(event.getY()); |
| 4176 | } |
| 4177 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4178 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4179 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4180 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4181 | void setIsBeingDragged(boolean isDragged) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4182 | mIsBeingDragged = isDragged; |
| 4183 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4184 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4185 | cancelLongPress(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4186 | resetExposedMenuView(true /* animate */, true /* force */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4187 | } |
| 4188 | } |
| 4189 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4190 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4191 | public void requestDisallowLongPress() { |
| 4192 | cancelLongPress(); |
| 4193 | } |
| 4194 | |
| 4195 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4196 | public void requestDisallowDismiss() { |
| 4197 | mDisallowDismissInThisMotion = true; |
| 4198 | } |
| 4199 | |
| 4200 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4201 | public void cancelLongPress() { |
| 4202 | mSwipeHelper.cancelLongPress(); |
| 4203 | } |
| 4204 | |
| 4205 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4206 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 4207 | mOnEmptySpaceClickListener = listener; |
| 4208 | } |
| 4209 | |
| 4210 | /** @hide */ |
| 4211 | @Override |
| 4212 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4213 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4214 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4215 | return true; |
| 4216 | } |
| 4217 | if (!isEnabled()) { |
| 4218 | return false; |
| 4219 | } |
| 4220 | int direction = -1; |
| 4221 | switch (action) { |
| 4222 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4223 | // fall through |
| 4224 | case android.R.id.accessibilityActionScrollDown: |
| 4225 | direction = 1; |
| 4226 | // fall through |
| 4227 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4228 | // fall through |
| 4229 | case android.R.id.accessibilityActionScrollUp: |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4230 | if (ANCHOR_SCROLLING) { |
| 4231 | // TODO |
| 4232 | } else { |
| 4233 | final int viewportHeight = |
| 4234 | getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
| 4235 | - mShelf.getIntrinsicHeight(); |
| 4236 | final int targetScrollY = Math.max(0, |
| 4237 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4238 | if (targetScrollY != mOwnScrollY) { |
| 4239 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, |
| 4240 | targetScrollY - mOwnScrollY); |
| 4241 | animateScroll(); |
| 4242 | return true; |
| 4243 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4244 | } |
| 4245 | break; |
| 4246 | } |
| 4247 | return false; |
| 4248 | } |
| 4249 | |
| 4250 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4251 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4252 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 4253 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 4254 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 4255 | View view = null; |
| 4256 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4257 | // Only close visible guts if they're not a leavebehind. |
| 4258 | view = guts; |
| 4259 | } else if (menuRow != null && menuRow.isMenuVisible() |
| 4260 | && translatingParentView != null) { |
| 4261 | // Checking menu |
| 4262 | view = translatingParentView; |
| 4263 | } |
| 4264 | if (view != null && !NotificationSwipeHelper.isTouchInView(ev, view)) { |
| 4265 | // Touch was outside visible guts / menu notification, close what's visible |
| 4266 | mNotificationGutsManager.closeAndSaveGuts(false /* removeLeavebehind */, |
| 4267 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4268 | false /* resetMenu */); |
| 4269 | resetExposedMenuView(true /* animate */, true /* force */); |
| 4270 | } |
| 4271 | } |
| 4272 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 4273 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4274 | private void setSwipingInProgress(boolean swiping) { |
| 4275 | mSwipingInProgress = swiping; |
| 4276 | if (swiping) { |
| 4277 | requestDisallowInterceptTouchEvent(true); |
| 4278 | } |
| 4279 | } |
| 4280 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4281 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4282 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4283 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4284 | super.onWindowFocusChanged(hasWindowFocus); |
| 4285 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4286 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4287 | } |
| 4288 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4289 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 4290 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4291 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 4292 | public void clearChildFocus(View child) { |
| 4293 | super.clearChildFocus(child); |
| 4294 | if (mForcedScroll == child) { |
| 4295 | mForcedScroll = null; |
| 4296 | } |
| 4297 | } |
| 4298 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4299 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4300 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4301 | public boolean isScrolledToTop() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4302 | if (ANCHOR_SCROLLING) { |
| 4303 | updateScrollAnchor(); |
| 4304 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 4305 | return mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY >= 0; |
| 4306 | } else { |
| 4307 | return mOwnScrollY == 0; |
| 4308 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4312 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4313 | public boolean isScrolledToBottom() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4314 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 4315 | return getMaxPositiveScrollAmount() <= 0; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4316 | } else { |
| 4317 | return mOwnScrollY >= getScrollRange(); |
| 4318 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4322 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4323 | public View getHostView() { |
| 4324 | return this; |
| 4325 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4326 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4327 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4328 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4329 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4330 | } |
| 4331 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4332 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4333 | public void checkSnoozeLeavebehind() { |
| 4334 | if (mCheckForLeavebehind) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 4335 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4336 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4337 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4338 | mCheckForLeavebehind = false; |
| 4339 | } |
| 4340 | } |
| 4341 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4342 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4343 | public void resetCheckSnoozeLeavebehind() { |
| 4344 | mCheckForLeavebehind = true; |
| 4345 | } |
| 4346 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4347 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4348 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4349 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4350 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4351 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4352 | } |
| 4353 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4354 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4355 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4356 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4357 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4358 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4359 | if (!mIsExpanded) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4360 | resetScrollPosition(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4361 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4362 | clearTemporaryViews(); |
| 4363 | clearUserLockedViews(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4364 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 4365 | if (draggedViews.size() > 0) { |
| 4366 | draggedViews.clear(); |
| 4367 | updateContinuousShadowDrawing(); |
| 4368 | } |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4369 | } |
| 4370 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 4371 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4372 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4373 | private void clearUserLockedViews() { |
| 4374 | for (int i = 0; i < getChildCount(); i++) { |
| 4375 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4376 | if (child instanceof ExpandableNotificationRow) { |
| 4377 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4378 | row.setUserLocked(false); |
| 4379 | } |
| 4380 | } |
| 4381 | } |
| 4382 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4383 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4384 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4385 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4386 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4387 | for (int i = 0; i < getChildCount(); i++) { |
| 4388 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4389 | if (child instanceof ExpandableNotificationRow) { |
| 4390 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4391 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4392 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4393 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4394 | } |
| 4395 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4396 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4397 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4398 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 4399 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4400 | } |
| 4401 | } |
| 4402 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4403 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4404 | public void onPanelTrackingStarted() { |
| 4405 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4406 | mAmbientState.setPanelTracking(true); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4407 | resetExposedMenuView(true /* animate */, true /* force */); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4408 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4409 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4410 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4411 | public void onPanelTrackingStopped() { |
| 4412 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4413 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4414 | } |
| 4415 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4416 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4417 | public void resetScrollPosition() { |
| 4418 | mScroller.abortAnimation(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4419 | if (ANCHOR_SCROLLING) { |
| 4420 | // TODO: once we're recycling this will need to modify the adapter position instead |
| 4421 | mScrollAnchorView = getFirstChildNotGone(); |
| 4422 | mScrollAnchorViewY = 0; |
| 4423 | updateOnScrollChange(); |
| 4424 | } else { |
| 4425 | setOwnScrollY(0); |
| 4426 | } |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4427 | } |
| 4428 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4429 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4430 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4431 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4432 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4433 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4434 | mAmbientState.setShadeExpanded(isExpanded); |
| 4435 | mStateAnimator.setShadeExpanded(isExpanded); |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 4436 | mSwipeHelper.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4437 | if (changed) { |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 4438 | mWillExpand = false; |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4439 | if (!mIsExpanded) { |
| 4440 | mGroupManager.collapseAllGroups(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4441 | mExpandHelper.cancelImmediately(); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4442 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4443 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4444 | updateChronometers(); |
Selim Cinek | f3fa685 | 2016-12-20 18:36:02 +0100 | [diff] [blame] | 4445 | requestChildrenUpdate(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4446 | } |
| 4447 | } |
| 4448 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4449 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4450 | private void updateChronometers() { |
| 4451 | int childCount = getChildCount(); |
| 4452 | for (int i = 0; i < childCount; i++) { |
| 4453 | updateChronometerForChild(getChildAt(i)); |
| 4454 | } |
| 4455 | } |
| 4456 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4457 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4458 | private void updateChronometerForChild(View child) { |
| 4459 | if (child instanceof ExpandableNotificationRow) { |
| 4460 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4461 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4462 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4463 | } |
| 4464 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4465 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4466 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4467 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4468 | updateScrollPositionOnExpandInBottom(view); |
| 4469 | clampScrollPosition(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4470 | notifyHeightChangeListener(view, needsAnimation); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4471 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 4472 | ? (ExpandableNotificationRow) view |
| 4473 | : null; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4474 | NotificationSection firstSection = getFirstVisibleSection(); |
| 4475 | ActivatableNotificationView firstVisibleChild = |
| 4476 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 4477 | if (row != null) { |
| 4478 | if (row == firstVisibleChild |
| 4479 | || row.getNotificationParent() == firstVisibleChild) { |
| 4480 | updateAlgorithmLayoutMinHeight(); |
| 4481 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4482 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4483 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 4484 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4485 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4486 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4487 | } |
| 4488 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4489 | @Override |
| 4490 | public void onReset(ExpandableView view) { |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 4491 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4492 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4493 | } |
| 4494 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4495 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4496 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 4497 | if (view instanceof ExpandableNotificationRow && !onKeyguard()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4498 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4499 | // 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] | 4500 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4501 | if (row.isSummaryWithChildren()) { |
| 4502 | return; |
| 4503 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4504 | // We are actually expanding this view |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4505 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4506 | if (row.isChildInGroup()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4507 | endPosition += row.getNotificationParent().getTranslationY(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4508 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4509 | int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4510 | NotificationSection lastSection = getLastVisibleSection(); |
| 4511 | ActivatableNotificationView lastVisibleChild = |
| 4512 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
| 4513 | if (row != lastVisibleChild && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4514 | layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements; |
| 4515 | } |
| 4516 | if (endPosition > layoutEnd) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4517 | if (ANCHOR_SCROLLING) { |
| 4518 | mScrollAnchorViewY -= (endPosition - layoutEnd); |
| 4519 | updateScrollAnchor(); |
| 4520 | updateOnScrollChange(); |
| 4521 | } else { |
| 4522 | setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd)); |
| 4523 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4524 | mDisallowScrollingInThisMotion = true; |
| 4525 | } |
| 4526 | } |
| 4527 | } |
| 4528 | } |
| 4529 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4530 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4531 | public void setOnHeightChangedListener( |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4532 | ExpandableView.OnHeightChangedListener onHeightChangedListener) { |
| 4533 | this.mOnHeightChangedListener = onHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4534 | } |
| 4535 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4536 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4537 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4538 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 4539 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4540 | runAnimationFinishedRunnables(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4541 | clearTransient(); |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4542 | clearHeadsUpDisappearRunning(); |
| 4543 | } |
| 4544 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4545 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4546 | private void clearHeadsUpDisappearRunning() { |
| 4547 | for (int i = 0; i < getChildCount(); i++) { |
| 4548 | View view = getChildAt(i); |
| 4549 | if (view instanceof ExpandableNotificationRow) { |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4550 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4551 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4552 | if (row.isSummaryWithChildren()) { |
| 4553 | for (ExpandableNotificationRow child : row.getNotificationChildren()) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4554 | child.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4555 | } |
| 4556 | } |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4557 | } |
| 4558 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4559 | } |
| 4560 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4561 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4562 | private void clearTransient() { |
| 4563 | for (ExpandableView view : mClearTransientViewsWhenFinished) { |
| 4564 | StackStateAnimator.removeTransientView(view); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4565 | } |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4566 | mClearTransientViewsWhenFinished.clear(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4567 | } |
| 4568 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4569 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4570 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4571 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 4572 | runnable.run(); |
| 4573 | } |
| 4574 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4575 | } |
| 4576 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4577 | /** |
| 4578 | * See {@link AmbientState#setDimmed}. |
| 4579 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4580 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4581 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4582 | dimmed &= onKeyguard(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4583 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4584 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4585 | mDimmedNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4586 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4587 | animateDimmed(dimmed); |
| 4588 | } else { |
| 4589 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4590 | } |
| 4591 | requestChildrenUpdate(); |
| 4592 | } |
| 4593 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4594 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4595 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4596 | boolean isDimmed() { |
| 4597 | return mAmbientState.isDimmed(); |
| 4598 | } |
| 4599 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4600 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4601 | private void setDimAmount(float dimAmount) { |
| 4602 | mDimAmount = dimAmount; |
| 4603 | updateBackgroundDimming(); |
| 4604 | } |
| 4605 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4606 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4607 | private void animateDimmed(boolean dimmed) { |
| 4608 | if (mDimAnimator != null) { |
| 4609 | mDimAnimator.cancel(); |
| 4610 | } |
| 4611 | float target = dimmed ? 1.0f : 0.0f; |
| 4612 | if (target == mDimAmount) { |
| 4613 | return; |
| 4614 | } |
| 4615 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 4616 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 4617 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 4618 | mDimAnimator.addListener(mDimEndListener); |
| 4619 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 4620 | mDimAnimator.start(); |
| 4621 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4622 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4623 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 4624 | private void updateSensitiveness(boolean animate) { |
| 4625 | boolean hideSensitive = mLockscreenUserManager.isAnyProfilePublicMode(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4626 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 4627 | int childCount = getChildCount(); |
| 4628 | for (int i = 0; i < childCount; i++) { |
| 4629 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 4630 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 4631 | } |
| 4632 | mAmbientState.setHideSensitive(hideSensitive); |
| 4633 | if (animate && mAnimationsEnabled) { |
| 4634 | mHideSensitiveNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4635 | mNeedsAnimation = true; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4636 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 4637 | updateContentHeight(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4638 | requestChildrenUpdate(); |
| 4639 | } |
| 4640 | } |
| 4641 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4642 | /** |
| 4643 | * See {@link AmbientState#setActivatedChild}. |
| 4644 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4645 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4646 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4647 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4648 | if (mAnimationsEnabled) { |
| 4649 | mActivateNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4650 | mNeedsAnimation = true; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4651 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4652 | requestChildrenUpdate(); |
| 4653 | } |
| 4654 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4655 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4656 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4657 | return mAmbientState.getActivatedChild(); |
| 4658 | } |
| 4659 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4660 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4661 | private void applyCurrentState() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4662 | int numChildren = getChildCount(); |
| 4663 | for (int i = 0; i < numChildren; i++) { |
| 4664 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4665 | child.applyViewState(); |
| 4666 | } |
| 4667 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4668 | if (mListener != null) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4669 | mListener.onChildLocationsChanged(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4670 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4671 | runAnimationFinishedRunnables(); |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 4672 | setAnimationRunning(false); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4673 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4674 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 4675 | updateClippingToTopRoundedCorner(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4676 | } |
| 4677 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4678 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4679 | private void updateViewShadows() { |
| 4680 | // we need to work around an issue where the shadow would not cast between siblings when |
| 4681 | // their z difference is between 0 and 0.1 |
| 4682 | |
| 4683 | // Lefts first sort by Z difference |
| 4684 | for (int i = 0; i < getChildCount(); i++) { |
| 4685 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4686 | if (child.getVisibility() != GONE) { |
| 4687 | mTmpSortedChildren.add(child); |
| 4688 | } |
| 4689 | } |
| 4690 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 4691 | |
| 4692 | // Now lets update the shadow for the views |
| 4693 | ExpandableView previous = null; |
| 4694 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 4695 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 4696 | float translationZ = expandableView.getTranslationZ(); |
| 4697 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 4698 | float diff = otherZ - translationZ; |
| 4699 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 4700 | // There is no fake shadow to be drawn |
| 4701 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 4702 | } else { |
| 4703 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 4704 | expandableView.getTranslationY() - previous.getExtraBottomPadding(); |
| 4705 | expandableView.setFakeShadowIntensity( |
| 4706 | diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4707 | previous.getOutlineAlpha(), (int) yLocation, |
| 4708 | previous.getOutlineTranslation()); |
| 4709 | } |
| 4710 | previous = expandableView; |
| 4711 | } |
| 4712 | |
| 4713 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4714 | } |
| 4715 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4716 | /** |
| 4717 | * Update colors of "dismiss" and "empty shade" views. |
| 4718 | * |
| 4719 | * @param lightTheme True if light theme should be used. |
| 4720 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4721 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4722 | public void updateDecorViews(boolean lightTheme) { |
| 4723 | if (lightTheme == mUsingLightTheme) { |
| 4724 | return; |
| 4725 | } |
| 4726 | mUsingLightTheme = lightTheme; |
| 4727 | Context context = new ContextThemeWrapper(mContext, |
| 4728 | lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 4729 | final int textColor = Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4730 | mFooterView.setTextColor(textColor); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4731 | mEmptyShadeView.setTextColor(textColor); |
| 4732 | } |
| 4733 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4734 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4735 | public void goToFullShade(long delay) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4736 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4737 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4738 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4739 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4740 | } |
| 4741 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4742 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4743 | public void cancelExpandHelper() { |
| 4744 | mExpandHelper.cancel(); |
| 4745 | } |
| 4746 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4747 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4748 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 4749 | mIntrinsicPadding = intrinsicPadding; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 4750 | mAmbientState.setIntrinsicPadding(intrinsicPadding); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4751 | } |
| 4752 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4753 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 4754 | public int getIntrinsicPadding() { |
| 4755 | return mIntrinsicPadding; |
| 4756 | } |
| 4757 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4758 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4759 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4760 | public boolean shouldDelayChildPressedState() { |
| 4761 | return true; |
| 4762 | } |
| 4763 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4764 | /** |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4765 | * See {@link AmbientState#setDozing}. |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4766 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4767 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4768 | public void setDozing(boolean dozing, boolean animate, |
| 4769 | @Nullable PointF touchWakeUpScreenLocation) { |
| 4770 | if (mAmbientState.isDozing() == dozing) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 4771 | return; |
| 4772 | } |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4773 | mAmbientState.setDozing(dozing); |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4774 | requestChildrenUpdate(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4775 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4776 | } |
| 4777 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4778 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4779 | * Sets the current hide amount. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4780 | * |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4781 | * @param linearHideAmount The hide amount that follows linear interpoloation in the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4782 | * animation, |
| 4783 | * 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] | 4784 | * @param interpolatedHideAmount The hide amount that follows the actual interpolation of the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4785 | * animation curve. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4786 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4787 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4788 | public void setHideAmount(float linearHideAmount, float interpolatedHideAmount) { |
| 4789 | mLinearHideAmount = linearHideAmount; |
| 4790 | mInterpolatedHideAmount = interpolatedHideAmount; |
| 4791 | boolean wasFullyHidden = mAmbientState.isFullyHidden(); |
| 4792 | boolean wasHiddenAtAll = mAmbientState.isHiddenAtAll(); |
| 4793 | mAmbientState.setHideAmount(interpolatedHideAmount); |
| 4794 | boolean nowFullyHidden = mAmbientState.isFullyHidden(); |
| 4795 | boolean nowHiddenAtAll = mAmbientState.isHiddenAtAll(); |
| 4796 | if (nowFullyHidden != wasFullyHidden) { |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 4797 | updateVisibility(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4798 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4799 | if (!wasHiddenAtAll && nowHiddenAtAll) { |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4800 | resetExposedMenuView(true /* animate */, true /* animate */); |
| 4801 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4802 | if (nowFullyHidden != wasFullyHidden || wasHiddenAtAll != nowHiddenAtAll) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 4803 | invalidateOutline(); |
| 4804 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4805 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4806 | updateBackgroundDimming(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4807 | requestChildrenUpdate(); |
Selim Cinek | 33295a4 | 2019-07-26 19:49:08 -0700 | [diff] [blame] | 4808 | updateOwnTranslationZ(); |
| 4809 | } |
| 4810 | |
| 4811 | private void updateOwnTranslationZ() { |
| 4812 | // Since we are clipping to the outline we need to make sure that the shadows aren't |
| 4813 | // clipped when pulsing |
| 4814 | float ownTranslationZ = 0; |
| 4815 | if (mKeyguardBypassController.getBypassEnabled() && mAmbientState.isHiddenAtAll()) { |
| 4816 | ExpandableView firstChildNotGone = getFirstChildNotGone(); |
| 4817 | if (firstChildNotGone != null && firstChildNotGone.showingPulsing()) { |
| 4818 | ownTranslationZ = firstChildNotGone.getTranslationZ(); |
| 4819 | } |
| 4820 | } |
| 4821 | setTranslationZ(ownTranslationZ); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 4824 | private void updateVisibility() { |
| 4825 | boolean shouldShow = !mAmbientState.isFullyHidden() || !onKeyguard(); |
| 4826 | setVisibility(shouldShow ? View.VISIBLE : View.INVISIBLE); |
| 4827 | } |
| 4828 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4829 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4830 | public void notifyHideAnimationStart(boolean hide) { |
| 4831 | // 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] | 4832 | // interpolation issues when playing with the power button. |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4833 | if (mInterpolatedHideAmount == 0 || mInterpolatedHideAmount == 1) { |
| 4834 | mBackgroundXFactor = hide ? 1.8f : 1.5f; |
| 4835 | mHideXInterpolator = hide |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4836 | ? Interpolators.FAST_OUT_SLOW_IN_REVERSE |
| 4837 | : Interpolators.FAST_OUT_SLOW_IN; |
| 4838 | } |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4839 | } |
| 4840 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4841 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4842 | private int getNotGoneIndex(View child) { |
| 4843 | int count = getChildCount(); |
| 4844 | int notGoneIndex = 0; |
| 4845 | for (int i = 0; i < count; i++) { |
| 4846 | View v = getChildAt(i); |
| 4847 | if (child == v) { |
| 4848 | return notGoneIndex; |
| 4849 | } |
| 4850 | if (v.getVisibility() != View.GONE) { |
| 4851 | notGoneIndex++; |
| 4852 | } |
| 4853 | } |
| 4854 | return -1; |
| 4855 | } |
| 4856 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4857 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4858 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4859 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4860 | if (mFooterView != null) { |
| 4861 | index = indexOfChild(mFooterView); |
| 4862 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4863 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4864 | mFooterView = footerView; |
| 4865 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4866 | } |
| 4867 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4868 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4869 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4870 | int index = -1; |
| 4871 | if (mEmptyShadeView != null) { |
| 4872 | index = indexOfChild(mEmptyShadeView); |
| 4873 | removeView(mEmptyShadeView); |
| 4874 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4875 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4876 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4877 | } |
| 4878 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4879 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4880 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4881 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4882 | |
| 4883 | int oldTextRes = mEmptyShadeView.getTextResource(); |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 4884 | int newTextRes = mZenController.areNotificationsHiddenInShade() |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4885 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4886 | if (oldTextRes != newTextRes) { |
| 4887 | mEmptyShadeView.setText(newTextRes); |
| 4888 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4889 | } |
| 4890 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4891 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4892 | public void updateFooterView(boolean visible, boolean showDismissView) { |
| 4893 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4894 | return; |
| 4895 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4896 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 4897 | mFooterView.setVisible(visible, animate); |
| 4898 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4899 | } |
| 4900 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4901 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4902 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 4903 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4904 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4905 | handleDismissAllClipping(); |
| 4906 | } |
| 4907 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4908 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4909 | private void handleDismissAllClipping() { |
| 4910 | final int count = getChildCount(); |
| 4911 | boolean previousChildWillBeDismissed = false; |
| 4912 | for (int i = 0; i < count; i++) { |
| 4913 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4914 | if (child.getVisibility() == GONE) { |
| 4915 | continue; |
| 4916 | } |
| 4917 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 4918 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 4919 | } else { |
| 4920 | child.setMinClipTopAmount(0); |
| 4921 | } |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 4922 | previousChildWillBeDismissed = canChildBeDismissed(child); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4923 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 4924 | } |
| 4925 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4926 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4927 | public boolean isFooterViewNotGone() { |
| 4928 | return mFooterView != null |
| 4929 | && mFooterView.getVisibility() != View.GONE |
| 4930 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4931 | } |
| 4932 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4933 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 4934 | public boolean isFooterViewContentVisible() { |
| 4935 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4936 | } |
| 4937 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4938 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4939 | public int getFooterViewHeight() { |
| 4940 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4941 | } |
| 4942 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4943 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 4944 | public int getEmptyShadeViewHeight() { |
| 4945 | return mEmptyShadeView.getHeight(); |
| 4946 | } |
| 4947 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4948 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4949 | public float getBottomMostNotificationBottom() { |
| 4950 | final int count = getChildCount(); |
| 4951 | float max = 0; |
| 4952 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 4953 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 4954 | if (child.getVisibility() == GONE) { |
| 4955 | continue; |
| 4956 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4957 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 4958 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4959 | if (bottom > max) { |
| 4960 | max = bottom; |
| 4961 | } |
| 4962 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4963 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4964 | } |
| 4965 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4966 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4967 | public void setStatusBar(StatusBar statusBar) { |
| 4968 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 4969 | } |
| 4970 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4971 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4972 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 4973 | this.mGroupManager = groupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 4974 | mGroupManager.addOnGroupChangeListener(mOnGroupChangeListener); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4975 | } |
| 4976 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4977 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4978 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4979 | if (mIsExpanded && mAnimationsEnabled) { |
| 4980 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4981 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4982 | requestChildrenUpdate(); |
| 4983 | } |
| 4984 | } |
| 4985 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4986 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4987 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4988 | int childCount = getChildCount(); |
| 4989 | for (int i = childCount - 1; i >= 0; i--) { |
| 4990 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4991 | if (child.getVisibility() != View.GONE) { |
| 4992 | float childTop = child.getY(); |
| 4993 | if (childTop > touchY) { |
| 4994 | // we are above a notification entirely let's abort |
| 4995 | return false; |
| 4996 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4997 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 4998 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4999 | if (child == mFooterView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5000 | if (!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
| 5001 | touchY - childTop)) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5002 | // We clicked on the dismiss button |
| 5003 | return false; |
| 5004 | } |
| 5005 | } else if (child == mEmptyShadeView) { |
| 5006 | // We arrived at the empty shade view, for which we accept all clicks |
| 5007 | return true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5008 | } else if (!belowChild) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5009 | // We are on a child |
| 5010 | return false; |
| 5011 | } |
| 5012 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5013 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 5014 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5015 | } |
| 5016 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5017 | /** @hide */ |
| 5018 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5019 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5020 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 5021 | super.onInitializeAccessibilityEventInternal(event); |
| 5022 | event.setScrollable(mScrollable); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5023 | event.setMaxScrollX(mScrollX); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5024 | if (ANCHOR_SCROLLING) { |
| 5025 | // TODO |
| 5026 | } else { |
| 5027 | event.setScrollY(mOwnScrollY); |
| 5028 | event.setMaxScrollY(getScrollRange()); |
| 5029 | } |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5033 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5034 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 5035 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5036 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5037 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5038 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5039 | info.addAction( |
| 5040 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 5041 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 5042 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5043 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5044 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 5045 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 5046 | } |
| 5047 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 5048 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 5049 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5050 | } |
| 5051 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5052 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5053 | public void generateChildOrderChangedEvent() { |
| 5054 | if (mIsExpanded && mAnimationsEnabled) { |
| 5055 | mGenerateChildOrderChangedEvent = true; |
| 5056 | mNeedsAnimation = true; |
| 5057 | requestChildrenUpdate(); |
| 5058 | } |
| 5059 | } |
| 5060 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5061 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5062 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5063 | public int getContainerChildCount() { |
| 5064 | return getChildCount(); |
| 5065 | } |
| 5066 | |
| 5067 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5068 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5069 | public View getContainerChildAt(int i) { |
| 5070 | return getChildAt(i); |
| 5071 | } |
| 5072 | |
| 5073 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5074 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5075 | public void removeContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5076 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5077 | removeView(v); |
| 5078 | } |
| 5079 | |
| 5080 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5081 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5082 | public void addContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5083 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5084 | addView(v); |
| 5085 | } |
| 5086 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5087 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 5088 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5089 | mAnimationFinishedRunnables.add(runnable); |
| 5090 | } |
| 5091 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 5092 | public void generateHeadsUpAnimation(NotificationEntry entry, boolean isHeadsUp) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 5093 | ExpandableNotificationRow row = entry.getHeadsUpAnimationView(); |
| 5094 | generateHeadsUpAnimation(row, isHeadsUp); |
| 5095 | } |
| 5096 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5097 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5098 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5099 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5100 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 5101 | mNeedsAnimation = true; |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 5102 | if (!mIsExpanded && !mWillExpand && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5103 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5104 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5105 | requestChildrenUpdate(); |
| 5106 | } |
| 5107 | } |
| 5108 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5109 | /** |
| 5110 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 5111 | * position. |
| 5112 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5113 | * @param height the height of the screen |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5114 | * @param bottomBarHeight the height of the bar on the bottom |
| 5115 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5116 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5117 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 5118 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 5119 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5120 | requestChildrenUpdate(); |
| 5121 | } |
| 5122 | |
Selim Cinek | aae9ad6 | 2019-07-22 18:36:54 -0700 | [diff] [blame] | 5123 | @Override |
| 5124 | public void setWillExpand(boolean willExpand) { |
| 5125 | mWillExpand = willExpand; |
| 5126 | } |
| 5127 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5128 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5129 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 5130 | mTrackingHeadsUp = row != null; |
| 5131 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5134 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5135 | public void setScrimController(ScrimController scrimController) { |
| 5136 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 5137 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5140 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5141 | public void forceNoOverlappingRendering(boolean force) { |
| 5142 | mForceNoOverlappingRendering = force; |
| 5143 | } |
| 5144 | |
| 5145 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5146 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5147 | public boolean hasOverlappingRendering() { |
| 5148 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 5149 | } |
| 5150 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5151 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5152 | public void setAnimationRunning(boolean animationRunning) { |
| 5153 | if (animationRunning != mAnimationRunning) { |
| 5154 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5155 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5156 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5157 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5158 | } |
| 5159 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5160 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5161 | } |
| 5162 | } |
| 5163 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5164 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 5165 | public boolean isExpanded() { |
| 5166 | return mIsExpanded; |
| 5167 | } |
| 5168 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5169 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5170 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5171 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 5172 | return; |
| 5173 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5174 | mPulsing = pulsing; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 5175 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 5176 | mSwipeHelper.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5177 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 5178 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 5179 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 5180 | requestChildrenUpdate(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5181 | notifyHeightChangeListener(null, animated); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5182 | } |
| 5183 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5184 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5185 | public void setQsExpanded(boolean qsExpanded) { |
| 5186 | mQsExpanded = qsExpanded; |
| 5187 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 5188 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5191 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5192 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 5193 | mQsExpansionFraction = qsExpansionFraction; |
| 5194 | } |
| 5195 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5196 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5197 | private void setOwnScrollY(int ownScrollY) { |
| 5198 | assert !ANCHOR_SCROLLING; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5199 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 5200 | // We still want to call the normal scrolled changed for accessibility reasons |
| 5201 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5202 | mOwnScrollY = ownScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5203 | updateOnScrollChange(); |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | private void updateOnScrollChange() { |
| 5208 | updateForwardAndBackwardScrollability(); |
| 5209 | requestChildrenUpdate(); |
| 5210 | } |
| 5211 | |
| 5212 | private void updateScrollAnchor() { |
| 5213 | int anchorIndex = indexOfChild(mScrollAnchorView); |
| 5214 | // If the anchor view has been scrolled off the top, move to the next view. |
| 5215 | while (mScrollAnchorViewY < 0) { |
| 5216 | View nextAnchor = null; |
| 5217 | for (int i = anchorIndex + 1; i < getChildCount(); i++) { |
| 5218 | View child = getChildAt(i); |
| 5219 | if (child.getVisibility() != View.GONE |
| 5220 | && child instanceof ExpandableNotificationRow) { |
| 5221 | anchorIndex = i; |
| 5222 | nextAnchor = child; |
| 5223 | break; |
| 5224 | } |
| 5225 | } |
| 5226 | if (nextAnchor == null) { |
| 5227 | break; |
| 5228 | } |
| 5229 | mScrollAnchorViewY += |
| 5230 | (int) (nextAnchor.getTranslationY() - mScrollAnchorView.getTranslationY()); |
| 5231 | mScrollAnchorView = nextAnchor; |
| 5232 | } |
| 5233 | // If the view above the anchor view is fully visible, make it the anchor view. |
| 5234 | while (anchorIndex > 0 && mScrollAnchorViewY > 0) { |
| 5235 | View prevAnchor = null; |
| 5236 | for (int i = anchorIndex - 1; i >= 0; i--) { |
| 5237 | View child = getChildAt(i); |
| 5238 | if (child.getVisibility() != View.GONE |
| 5239 | && child instanceof ExpandableNotificationRow) { |
| 5240 | anchorIndex = i; |
| 5241 | prevAnchor = child; |
| 5242 | break; |
| 5243 | } |
| 5244 | } |
| 5245 | if (prevAnchor == null) { |
| 5246 | break; |
| 5247 | } |
| 5248 | float distanceToPreviousAnchor = |
| 5249 | mScrollAnchorView.getTranslationY() - prevAnchor.getTranslationY(); |
| 5250 | if (distanceToPreviousAnchor < mScrollAnchorViewY) { |
| 5251 | mScrollAnchorViewY -= (int) distanceToPreviousAnchor; |
| 5252 | mScrollAnchorView = prevAnchor; |
| 5253 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5254 | } |
| 5255 | } |
| 5256 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5257 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5258 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5259 | int index = -1; |
| 5260 | if (mShelf != null) { |
| 5261 | index = indexOfChild(mShelf); |
| 5262 | removeView(mShelf); |
| 5263 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 5264 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5265 | addView(mShelf, index); |
| 5266 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 5267 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5268 | shelf.bind(mAmbientState, this); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5269 | if (ANCHOR_SCROLLING) { |
| 5270 | mScrollAnchorView = mShelf; |
| 5271 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5272 | } |
| 5273 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5274 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5275 | public NotificationShelf getNotificationShelf() { |
| 5276 | return mShelf; |
| 5277 | } |
| 5278 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5279 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 5280 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 5281 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 5282 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 5283 | updateContentHeight(); |
| 5284 | notifyHeightChangeListener(mShelf); |
| 5285 | } |
| 5286 | } |
| 5287 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5288 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5289 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5290 | mShouldShowShelfOnly = shouldShowShelfOnly; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5291 | updateAlgorithmLayoutMinHeight(); |
| 5292 | } |
| 5293 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5294 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5295 | public int getMinExpansionHeight() { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 5296 | return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5297 | } |
| 5298 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5299 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5300 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 5301 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 5302 | updateClipping(); |
| 5303 | } |
| 5304 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5305 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5306 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 5307 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 5308 | updateClipping(); |
| 5309 | } |
| 5310 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5311 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5312 | @VisibleForTesting |
| 5313 | protected void setStatusBarState(int statusBarState) { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5314 | mStatusBarState = statusBarState; |
| 5315 | mAmbientState.setStatusBarState(statusBarState); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | private void onStatePostChange() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5319 | boolean onKeyguard = onKeyguard(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5320 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5321 | if (mHeadsUpAppearanceController != null) { |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 5322 | mHeadsUpAppearanceController.onStateChanged(); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5323 | } |
| 5324 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 5325 | SysuiStatusBarStateController state = (SysuiStatusBarStateController) |
| 5326 | Dependency.get(StatusBarStateController.class); |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 5327 | updateSensitiveness(state.goingToFullShade() /* animate */); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5328 | setDimmed(onKeyguard, state.fromShadeLocked() /* animate */); |
| 5329 | setExpandingEnabled(!onKeyguard); |
| 5330 | ActivatableNotificationView activatedChild = getActivatedChild(); |
| 5331 | setActivatedChild(null); |
| 5332 | if (activatedChild != null) { |
| 5333 | activatedChild.makeInactive(false /* animate */); |
| 5334 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5335 | updateFooter(); |
Dave Mankoff | 5744580 | 2018-10-10 14:47:34 -0400 | [diff] [blame] | 5336 | requestChildrenUpdate(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5337 | onUpdateRowStates(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5338 | |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 5339 | mEntryManager.updateNotifications("StatusBar state changed"); |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 5340 | updateVisibility(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5341 | } |
| 5342 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5343 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 5344 | public void setExpandingVelocity(float expandingVelocity) { |
| 5345 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 5346 | } |
| 5347 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5348 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5349 | public float getOpeningHeight() { |
| 5350 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 5351 | return getMinExpansionHeight(); |
| 5352 | } else { |
| 5353 | return getAppearEndPosition(); |
| 5354 | } |
| 5355 | } |
| 5356 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5357 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5358 | public void setIsFullWidth(boolean isFullWidth) { |
| 5359 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 5360 | } |
| 5361 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5362 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 5363 | public void setUnlockHintRunning(boolean running) { |
| 5364 | mAmbientState.setUnlockHintRunning(running); |
| 5365 | } |
| 5366 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5367 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5368 | public void setQsCustomizerShowing(boolean isShowing) { |
| 5369 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 5370 | requestChildrenUpdate(); |
| 5371 | } |
| 5372 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5373 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5374 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 5375 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 5376 | } |
| 5377 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5378 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5379 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 5380 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5381 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 5382 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5383 | this.getClass().getSimpleName(), |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5384 | mPulsing ? "T" : "f", |
| 5385 | mAmbientState.isQsCustomizerShowing() ? "T" : "f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5386 | getVisibility() == View.VISIBLE ? "visible" |
| 5387 | : getVisibility() == View.GONE ? "gone" |
| 5388 | : "invisible", |
| 5389 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5390 | mAmbientState.getScrollY(), |
| 5391 | mMaxTopPadding, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5392 | mShouldShowShelfOnly ? "T" : "f", |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5393 | mQsExpansionFraction)); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5394 | int childCount = getChildCount(); |
| 5395 | pw.println(" Number of children: " + childCount); |
| 5396 | pw.println(); |
| 5397 | |
| 5398 | for (int i = 0; i < childCount; i++) { |
| 5399 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5400 | child.dump(fd, pw, args); |
| 5401 | if (!(child instanceof ExpandableNotificationRow)) { |
| 5402 | pw.println(" " + child.getClass().getSimpleName()); |
| 5403 | // 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] | 5404 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5405 | if (viewState == null) { |
| 5406 | pw.println(" no viewState!!!"); |
| 5407 | } else { |
| 5408 | pw.print(" "); |
| 5409 | viewState.dump(fd, pw, args); |
| 5410 | pw.println(); |
| 5411 | pw.println(); |
| 5412 | } |
| 5413 | } |
| 5414 | } |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5415 | int transientViewCount = getTransientViewCount(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5416 | pw.println(" Transient Views: " + transientViewCount); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5417 | for (int i = 0; i < transientViewCount; i++) { |
| 5418 | ExpandableView child = (ExpandableView) getTransientView(i); |
| 5419 | child.dump(fd, pw, args); |
| 5420 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5421 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5422 | int draggedCount = draggedViews.size(); |
| 5423 | pw.println(" Dragged Views: " + draggedCount); |
| 5424 | for (int i = 0; i < draggedCount; i++) { |
| 5425 | ExpandableView child = (ExpandableView) draggedViews.get(i); |
| 5426 | child.dump(fd, pw, args); |
| 5427 | } |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5428 | } |
| 5429 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5430 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 5431 | public boolean isFullyHidden() { |
| 5432 | return mAmbientState.isFullyHidden(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 5433 | } |
| 5434 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 5435 | /** |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5436 | * Add a listener whenever the expanded height changes. The first value passed as an |
| 5437 | * argument is the expanded height and the second one is the appearFraction. |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5438 | * |
| 5439 | * @param listener the listener to notify. |
| 5440 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5441 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5442 | public void addOnExpandedHeightChangedListener(BiConsumer<Float, Float> listener) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5443 | mExpandedHeightListeners.add(listener); |
| 5444 | } |
| 5445 | |
| 5446 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5447 | * Stop a listener from listening to the expandedHeight. |
| 5448 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5449 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5450 | public void removeOnExpandedHeightChangedListener(BiConsumer<Float, Float> listener) { |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5451 | mExpandedHeightListeners.remove(listener); |
| 5452 | } |
| 5453 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5454 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 5455 | public void setHeadsUpAppearanceController( |
| 5456 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 5457 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 5458 | } |
| 5459 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5460 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 5461 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 5462 | mIconAreaController = controller; |
| 5463 | } |
| 5464 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5465 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5466 | public void manageNotifications(View v) { |
| 5467 | Intent intent = new Intent(Settings.ACTION_ALL_APPS_NOTIFICATION_SETTINGS); |
| 5468 | mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 5469 | } |
| 5470 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5471 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5472 | private void clearNotifications( |
| 5473 | @SelectedRows int selection, |
| 5474 | boolean closeShade) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5475 | // animate-swipe all dismissable notifications, then animate the shade closed |
| 5476 | int numChildren = getChildCount(); |
| 5477 | |
| 5478 | final ArrayList<View> viewsToHide = new ArrayList<>(numChildren); |
| 5479 | final ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>(numChildren); |
| 5480 | for (int i = 0; i < numChildren; i++) { |
| 5481 | final View child = getChildAt(i); |
| 5482 | if (child instanceof ExpandableNotificationRow) { |
| 5483 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 5484 | boolean parentVisible = false; |
| 5485 | boolean hasClipBounds = child.getClipBounds(mTmpRect); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5486 | if (includeChildInDismissAll(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5487 | viewsToRemove.add(row); |
| 5488 | if (child.getVisibility() == View.VISIBLE |
| 5489 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5490 | viewsToHide.add(child); |
| 5491 | parentVisible = true; |
| 5492 | } |
| 5493 | } else if (child.getVisibility() == View.VISIBLE |
| 5494 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5495 | parentVisible = true; |
| 5496 | } |
| 5497 | List<ExpandableNotificationRow> children = row.getNotificationChildren(); |
| 5498 | if (children != null) { |
| 5499 | for (ExpandableNotificationRow childRow : children) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5500 | if (includeChildInDismissAll(row, selection)) { |
| 5501 | viewsToRemove.add(childRow); |
| 5502 | if (parentVisible && row.areChildrenExpanded()) { |
| 5503 | hasClipBounds = childRow.getClipBounds(mTmpRect); |
| 5504 | if (childRow.getVisibility() == View.VISIBLE |
| 5505 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5506 | viewsToHide.add(childRow); |
| 5507 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5508 | } |
| 5509 | } |
| 5510 | } |
| 5511 | } |
| 5512 | } |
| 5513 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5514 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5515 | if (viewsToRemove.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5516 | if (closeShade) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5517 | Dependency.get(ShadeController.class).animateCollapsePanels( |
| 5518 | CommandQueue.FLAG_EXCLUDE_NONE); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5519 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5520 | return; |
| 5521 | } |
| 5522 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5523 | performDismissAllAnimations(viewsToHide, closeShade, () -> { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5524 | for (ExpandableNotificationRow rowToRemove : viewsToRemove) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 5525 | if (canChildBeDismissed(rowToRemove)) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5526 | if (selection == ROWS_ALL) { |
| 5527 | // TODO: This is a listener method; we shouldn't be calling it. Can we just |
| 5528 | // call performRemoveNotification as below? |
| 5529 | mEntryManager.removeNotification( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 5530 | rowToRemove.getEntry().getKey(), |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5531 | null /* ranking */, |
| 5532 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5533 | } else { |
| 5534 | mEntryManager.performRemoveNotification( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 5535 | rowToRemove.getEntry().getSbn(), |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5536 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5537 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5538 | } else { |
| 5539 | rowToRemove.resetTranslation(); |
| 5540 | } |
| 5541 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5542 | if (selection == ROWS_ALL) { |
| 5543 | try { |
| 5544 | mBarService.onClearAllNotifications(mLockscreenUserManager.getCurrentUserId()); |
| 5545 | } catch (Exception ex) { |
| 5546 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5547 | } |
| 5548 | }); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5549 | } |
| 5550 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5551 | private boolean includeChildInDismissAll( |
| 5552 | ExpandableNotificationRow row, |
| 5553 | @SelectedRows int selection) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 5554 | return canChildBeDismissed(row) && matchesSelection(row, selection); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | /** |
| 5558 | * Given a list of rows, animates them away in a staggered fashion as if they were dismissed. |
| 5559 | * Doesn't actually dismiss them, though -- that must be done in the onAnimationComplete |
| 5560 | * handler. |
| 5561 | * |
| 5562 | * @param hideAnimatedList List of rows to animated away. Should only be views that are |
| 5563 | * currently visible, or else the stagger will look funky. |
| 5564 | * @param closeShade Whether to close the shade after the stagger animation completes. |
| 5565 | * @param onAnimationComplete Called after the entire animation completes (including the shade |
| 5566 | * closing if appropriate). The rows must be dismissed for real here. |
| 5567 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5568 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5569 | private void performDismissAllAnimations( |
| 5570 | final ArrayList<View> hideAnimatedList, |
| 5571 | final boolean closeShade, |
| 5572 | final Runnable onAnimationComplete) { |
| 5573 | |
| 5574 | final Runnable onSlideAwayAnimationComplete = () -> { |
| 5575 | if (closeShade) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5576 | Dependency.get(ShadeController.class).addPostCollapseAction(() -> { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5577 | setDismissAllInProgress(false); |
| 5578 | onAnimationComplete.run(); |
| 5579 | }); |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5580 | Dependency.get(ShadeController.class).animateCollapsePanels( |
| 5581 | CommandQueue.FLAG_EXCLUDE_NONE); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5582 | } else { |
| 5583 | setDismissAllInProgress(false); |
| 5584 | onAnimationComplete.run(); |
| 5585 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5586 | }; |
| 5587 | |
| 5588 | if (hideAnimatedList.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5589 | onSlideAwayAnimationComplete.run(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5590 | return; |
| 5591 | } |
| 5592 | |
| 5593 | // let's disable our normal animations |
| 5594 | setDismissAllInProgress(true); |
| 5595 | |
| 5596 | // Decrease the delay for every row we animate to give the sense of |
| 5597 | // accelerating the swipes |
| 5598 | int rowDelayDecrement = 10; |
| 5599 | int currentDelay = 140; |
| 5600 | int totalDelay = 180; |
| 5601 | int numItems = hideAnimatedList.size(); |
| 5602 | for (int i = numItems - 1; i >= 0; i--) { |
| 5603 | View view = hideAnimatedList.get(i); |
| 5604 | Runnable endRunnable = null; |
| 5605 | if (i == 0) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5606 | endRunnable = onSlideAwayAnimationComplete; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5607 | } |
Lucas Dupin | fb8bdbb | 2018-12-02 15:09:37 -0800 | [diff] [blame] | 5608 | dismissViewAnimated(view, endRunnable, totalDelay, ANIMATION_DURATION_SWIPE); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5609 | currentDelay = Math.max(50, currentDelay - rowDelayDecrement); |
| 5610 | totalDelay += currentDelay; |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5615 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5616 | protected void inflateFooterView() { |
| 5617 | FooterView footerView = (FooterView) LayoutInflater.from(mContext).inflate( |
| 5618 | R.layout.status_bar_notification_footer, this, false); |
| 5619 | footerView.setDismissButtonClickListener(v -> { |
| 5620 | mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5621 | clearNotifications(ROWS_ALL, true /* closeShade */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5622 | }); |
| 5623 | footerView.setManageButtonClickListener(this::manageNotifications); |
| 5624 | setFooterView(footerView); |
| 5625 | } |
| 5626 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5627 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5628 | private void inflateEmptyShadeView() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5629 | EmptyShadeView view = (EmptyShadeView) LayoutInflater.from(mContext).inflate( |
| 5630 | R.layout.status_bar_no_notifications, this, false); |
| 5631 | view.setText(R.string.empty_shade_text); |
| 5632 | setEmptyShadeView(view); |
| 5633 | } |
| 5634 | |
| 5635 | /** |
| 5636 | * Updates expanded, dimmed and locked states of notification rows. |
| 5637 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5638 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5639 | public void onUpdateRowStates() { |
| 5640 | changeViewPosition(mFooterView, -1); |
| 5641 | |
| 5642 | // The following views will be moved to the end of mStackScroller. This counter represents |
| 5643 | // the offset from the last child. Initialized to 1 for the very last position. It is post- |
| 5644 | // incremented in the following "changeViewPosition" calls so that its value is correct for |
| 5645 | // subsequent calls. |
| 5646 | int offsetFromEnd = 1; |
| 5647 | changeViewPosition(mEmptyShadeView, |
| 5648 | getChildCount() - offsetFromEnd++); |
| 5649 | |
| 5650 | // No post-increment for this call because it is the last one. Make sure to add one if |
| 5651 | // another "changeViewPosition" call is ever added. |
| 5652 | changeViewPosition(mShelf, |
| 5653 | getChildCount() - offsetFromEnd); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5654 | } |
| 5655 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5656 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 5657 | public void setNotificationPanelController( |
| 5658 | NotificationPanelViewController notificationPanelViewController) { |
| 5659 | mNotificationPanelController = notificationPanelViewController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5660 | } |
| 5661 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5662 | public void updateIconAreaViews() { |
| 5663 | mIconAreaController.updateNotificationIcons(); |
| 5664 | } |
| 5665 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5666 | /** |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5667 | * Set how far the wake up is when waking up from pulsing. This is a height and will adjust the |
| 5668 | * notification positions accordingly. |
| 5669 | * @param height the new wake up height |
| 5670 | * @return the overflow how much the height is further than he lowest notification |
| 5671 | */ |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 5672 | public float setPulseHeight(float height) { |
| 5673 | mAmbientState.setPulseHeight(height); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5674 | if (mKeyguardBypassController.getBypassEnabled()) { |
| 5675 | notifyAppearChangedListeners(); |
| 5676 | } |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5677 | requestChildrenUpdate(); |
| 5678 | return Math.max(0, height - mAmbientState.getInnerHeight(true /* ignorePulseHeight */)); |
| 5679 | } |
| 5680 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5681 | public float getPulseHeight() { |
| 5682 | return mAmbientState.getPulseHeight(); |
| 5683 | } |
| 5684 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5685 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 5686 | * 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] | 5687 | * the notification is pulsing. |
| 5688 | */ |
| 5689 | public void setDozeAmount(float dozeAmount) { |
| 5690 | mAmbientState.setDozeAmount(dozeAmount); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5691 | updateContinuousBackgroundDrawing(); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5692 | requestChildrenUpdate(); |
| 5693 | } |
| 5694 | |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5695 | public void wakeUpFromPulse() { |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5696 | setPulseHeight(getWakeUpHeight()); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5697 | // Let's place the hidden views at the end of the pulsing notification to make sure we have |
| 5698 | // a smooth animation |
| 5699 | boolean firstVisibleView = true; |
| 5700 | float wakeUplocation = -1f; |
| 5701 | int childCount = getChildCount(); |
| 5702 | for (int i = 0; i < childCount; i++) { |
| 5703 | ExpandableView view = (ExpandableView) getChildAt(i); |
| 5704 | if (view.getVisibility() == View.GONE) { |
| 5705 | continue; |
| 5706 | } |
| 5707 | boolean isShelf = view == mShelf; |
| 5708 | if (!(view instanceof ExpandableNotificationRow) && !isShelf) { |
| 5709 | continue; |
| 5710 | } |
| 5711 | if (view.getVisibility() == View.VISIBLE && !isShelf) { |
| 5712 | if (firstVisibleView) { |
| 5713 | firstVisibleView = false; |
| 5714 | wakeUplocation = view.getTranslationY() |
| 5715 | + view.getActualHeight() - mShelf.getIntrinsicHeight(); |
| 5716 | } |
| 5717 | } else if (!firstVisibleView) { |
| 5718 | view.setTranslationY(wakeUplocation); |
| 5719 | } |
| 5720 | } |
Selim Cinek | f434a74 | 2019-05-28 17:39:49 -0700 | [diff] [blame] | 5721 | mDimmedNeedsAnimation = true; |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5722 | } |
| 5723 | |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5724 | @Override |
| 5725 | public void onDynamicPrivacyChanged() { |
| 5726 | if (mIsExpanded) { |
| 5727 | // The bottom might change because we're using the final actual height of the view |
| 5728 | mAnimateBottomOnLayout = true; |
| 5729 | } |
Selim Cinek | abcc201 | 2019-07-23 18:44:07 -0700 | [diff] [blame] | 5730 | // 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] | 5731 | post(() -> { |
| 5732 | updateFooter(); |
| 5733 | updateSectionBoundaries(); |
| 5734 | }); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5735 | } |
| 5736 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5737 | public void setOnPulseHeightChangedListener(Runnable listener) { |
| 5738 | mAmbientState.setOnPulseHeightChangedListener(listener); |
| 5739 | } |
| 5740 | |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5741 | public float calculateAppearFractionBypass() { |
| 5742 | float pulseHeight = getPulseHeight(); |
| 5743 | float wakeUpHeight = getWakeUpHeight(); |
| 5744 | float dragDownAmount = pulseHeight - wakeUpHeight; |
| 5745 | |
| 5746 | // The total distance required to fully reveal the header |
| 5747 | float totalDistance = getIntrinsicPadding(); |
| 5748 | return MathUtils.smoothStep(0, totalDistance, dragDownAmount); |
| 5749 | } |
| 5750 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5751 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5752 | * A listener that is notified when the empty space below the notifications is clicked on |
| 5753 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5754 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5755 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 5756 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5760 | * A listener that gets notified when the overscroll at the top has changed. |
| 5761 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5762 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5763 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 5764 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5765 | /** |
| 5766 | * Notifies a listener that the overscroll has changed. |
| 5767 | * |
| 5768 | * @param amount the amount of overscroll, in pixels |
| 5769 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 5770 | * unrubberbanded motion to directly expand overscroll view (e.g |
| 5771 | * expand |
| 5772 | * QS) |
| 5773 | */ |
| 5774 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 5775 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5776 | /** |
| 5777 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 5778 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 5779 | * |
| 5780 | * @param velocity The velocity that the Scroller had when over flinging |
| 5781 | * @param open Should the fling open or close the overscroll view. |
| 5782 | */ |
| 5783 | void flingTopOverscroll(float velocity, boolean open); |
| 5784 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5785 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5786 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5787 | public void updateSpeedBumpIndex() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5788 | int speedBumpIndex = 0; |
| 5789 | int currentIndex = 0; |
| 5790 | final int N = getChildCount(); |
| 5791 | for (int i = 0; i < N; i++) { |
| 5792 | View view = getChildAt(i); |
| 5793 | if (view.getVisibility() == View.GONE || !(view instanceof ExpandableNotificationRow)) { |
| 5794 | continue; |
| 5795 | } |
| 5796 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 5797 | currentIndex++; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5798 | boolean beforeSpeedBump; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5799 | if (mHighPriorityBeforeSpeedBump) { |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 5800 | beforeSpeedBump = row.getEntry().getBucket() < BUCKET_SILENT; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5801 | } else { |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 5802 | beforeSpeedBump = !row.getEntry().isAmbient(); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5803 | } |
| 5804 | if (beforeSpeedBump) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5805 | speedBumpIndex = currentIndex; |
| 5806 | } |
| 5807 | } |
| 5808 | boolean noAmbient = speedBumpIndex == N; |
| 5809 | updateSpeedBumpIndex(speedBumpIndex, noAmbient); |
| 5810 | } |
| 5811 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5812 | /** Updates the indices of the boundaries between sections. */ |
| 5813 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 5814 | public void updateSectionBoundaries() { |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 5815 | mSectionsManager.updateSectionBoundaries(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5816 | } |
| 5817 | |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5818 | private void updateContinuousBackgroundDrawing() { |
| 5819 | boolean continuousBackground = !mAmbientState.isFullyAwake() |
| 5820 | && !mAmbientState.getDraggedViews().isEmpty(); |
| 5821 | if (continuousBackground != mContinuousBackgroundUpdate) { |
| 5822 | mContinuousBackgroundUpdate = continuousBackground; |
| 5823 | if (continuousBackground) { |
| 5824 | getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater); |
| 5825 | } else { |
| 5826 | getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater); |
| 5827 | } |
| 5828 | } |
| 5829 | } |
| 5830 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5831 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5832 | private void updateContinuousShadowDrawing() { |
| 5833 | boolean continuousShadowUpdate = mAnimationRunning |
| 5834 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 5835 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 5836 | if (continuousShadowUpdate) { |
| 5837 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 5838 | } else { |
| 5839 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 5840 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 5841 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5842 | } |
| 5843 | } |
| 5844 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5845 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5846 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 5847 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 5848 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5851 | private static boolean matchesSelection( |
| 5852 | ExpandableNotificationRow row, |
| 5853 | @SelectedRows int selection) { |
| 5854 | switch (selection) { |
| 5855 | case ROWS_ALL: |
| 5856 | return true; |
| 5857 | case ROWS_HIGH_PRIORITY: |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 5858 | return row.getEntry().getBucket() < BUCKET_SILENT; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5859 | case ROWS_GENTLE: |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 5860 | return row.getEntry().getBucket() == BUCKET_SILENT; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5861 | default: |
| 5862 | throw new IllegalArgumentException("Unknown selection: " + selection); |
| 5863 | } |
| 5864 | } |
| 5865 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5866 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 5867 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5868 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5869 | static AnimationFilter[] FILTERS = new AnimationFilter[]{ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5870 | |
| 5871 | // ANIMATION_TYPE_ADD |
| 5872 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5873 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5874 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5875 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5876 | .animateZ() |
| 5877 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5878 | |
| 5879 | // ANIMATION_TYPE_REMOVE |
| 5880 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5881 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5882 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5883 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5884 | .animateZ() |
| 5885 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5886 | |
| 5887 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5888 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5889 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5890 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5891 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5892 | .animateZ() |
| 5893 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5894 | |
| 5895 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5896 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5897 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5898 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5899 | .animateY() |
| 5900 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5901 | .animateZ(), |
| 5902 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5903 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5904 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5905 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5906 | |
| 5907 | // ANIMATION_TYPE_DIMMED |
| 5908 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5909 | .animateDimmed(), |
| 5910 | |
| 5911 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5912 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5913 | .animateAlpha() // maybe the children change positions |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5914 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5915 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5916 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5917 | .animateZ(), |
| 5918 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5919 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5920 | new AnimationFilter() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5921 | .animateHeight() |
| 5922 | .animateTopInset() |
| 5923 | .animateY() |
| 5924 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5925 | .animateZ() |
| 5926 | .hasDelays(), |
| 5927 | |
| 5928 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5929 | new AnimationFilter() |
| 5930 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5931 | |
| 5932 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5933 | new AnimationFilter() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5934 | .animateHeight() |
| 5935 | .animateTopInset() |
| 5936 | .animateY() |
| 5937 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5938 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5939 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 5940 | new AnimationFilter() |
| 5941 | .animateAlpha() |
| 5942 | .animateHeight() |
| 5943 | .animateTopInset() |
| 5944 | .animateY() |
| 5945 | .animateZ(), |
| 5946 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5947 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5948 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5949 | .animateHeight() |
| 5950 | .animateTopInset() |
| 5951 | .animateY() |
| 5952 | .animateZ(), |
| 5953 | |
| 5954 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5955 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5956 | .animateHeight() |
| 5957 | .animateTopInset() |
| 5958 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 5959 | .animateZ() |
| 5960 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5961 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5962 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5963 | new AnimationFilter() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5964 | .animateHeight() |
| 5965 | .animateTopInset() |
| 5966 | .animateY() |
| 5967 | .animateZ() |
| 5968 | .hasDelays(), |
| 5969 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5970 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5971 | new AnimationFilter() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5972 | .animateHeight() |
| 5973 | .animateTopInset() |
| 5974 | .animateY() |
| 5975 | .animateZ(), |
| 5976 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5977 | // ANIMATION_TYPE_EVERYTHING |
| 5978 | new AnimationFilter() |
| 5979 | .animateAlpha() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5980 | .animateDimmed() |
| 5981 | .animateHideSensitive() |
| 5982 | .animateHeight() |
| 5983 | .animateTopInset() |
| 5984 | .animateY() |
| 5985 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5986 | }; |
| 5987 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5988 | static int[] LENGTHS = new int[]{ |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5989 | |
| 5990 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5991 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5992 | |
| 5993 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5994 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5995 | |
| 5996 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5997 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5998 | |
| 5999 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 6000 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6001 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6002 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 6003 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 6004 | |
| 6005 | // ANIMATION_TYPE_DIMMED |
| 6006 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6007 | |
| 6008 | // ANIMATION_TYPE_CHANGE_POSITION |
| 6009 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 6010 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6011 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 6012 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 6013 | |
| 6014 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 6015 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 6016 | |
| 6017 | // ANIMATION_TYPE_VIEW_RESIZE |
| 6018 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6019 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6020 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 6021 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6022 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6023 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 6024 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 6025 | |
| 6026 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 6027 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6028 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 6029 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 6030 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6031 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6032 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 6033 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6034 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6035 | // ANIMATION_TYPE_EVERYTHING |
| 6036 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6037 | }; |
| 6038 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6039 | static final int ANIMATION_TYPE_ADD = 0; |
| 6040 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 6041 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 6042 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
Selim Cinek | ff2ffec | 2018-11-19 18:52:01 -0800 | [diff] [blame] | 6043 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 4; |
| 6044 | static final int ANIMATION_TYPE_DIMMED = 5; |
| 6045 | static final int ANIMATION_TYPE_CHANGE_POSITION = 6; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 6046 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 7; |
| 6047 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 8; |
| 6048 | static final int ANIMATION_TYPE_VIEW_RESIZE = 9; |
| 6049 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 10; |
| 6050 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 11; |
| 6051 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 12; |
| 6052 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 13; |
| 6053 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 14; |
| 6054 | static final int ANIMATION_TYPE_EVERYTHING = 15; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 6055 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6056 | final long eventStartTime; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6057 | final ExpandableView mChangingView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6058 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6059 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6060 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6061 | View viewAfterChangingView; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6062 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6063 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6064 | AnimationEvent(ExpandableView view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6065 | this(view, type, LENGTHS[type]); |
| 6066 | } |
| 6067 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6068 | AnimationEvent(ExpandableView view, int type, AnimationFilter filter) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6069 | this(view, type, LENGTHS[type], filter); |
| 6070 | } |
| 6071 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6072 | AnimationEvent(ExpandableView view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6073 | this(view, type, length, FILTERS[type]); |
| 6074 | } |
| 6075 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6076 | AnimationEvent(ExpandableView view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6077 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6078 | mChangingView = view; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6079 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6080 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6081 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6082 | } |
| 6083 | |
| 6084 | /** |
| 6085 | * Combines the length of several animation events into a single value. |
| 6086 | * |
| 6087 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6088 | * @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] | 6089 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6090 | */ |
| 6091 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 6092 | long length = 0; |
| 6093 | int size = events.size(); |
| 6094 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6095 | AnimationEvent event = events.get(i); |
| 6096 | length = Math.max(length, event.length); |
| 6097 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 6098 | return event.length; |
| 6099 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6100 | } |
| 6101 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6102 | } |
| 6103 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6104 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6105 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 6106 | private final StateListener mStateListener = new StateListener() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6107 | @Override |
| 6108 | public void onStatePreChange(int oldState, int newState) { |
| 6109 | if (oldState == StatusBarState.SHADE_LOCKED && newState == StatusBarState.KEYGUARD) { |
| 6110 | requestAnimateEverything(); |
| 6111 | } |
| 6112 | } |
| 6113 | |
| 6114 | @Override |
| 6115 | public void onStateChanged(int newState) { |
| 6116 | setStatusBarState(newState); |
| 6117 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6118 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6119 | @Override |
| 6120 | public void onStatePostChange() { |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6121 | NotificationStackScrollLayout.this.onStatePostChange(); |
| 6122 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6123 | }; |
| 6124 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6125 | @VisibleForTesting |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6126 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6127 | protected final OnMenuEventListener mMenuEventListener = new OnMenuEventListener() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6128 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6129 | public void onMenuClicked(View view, int x, int y, MenuItem item) { |
| 6130 | if (mLongPressListener == null) { |
| 6131 | return; |
| 6132 | } |
| 6133 | if (view instanceof ExpandableNotificationRow) { |
| 6134 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6135 | mMetricsLogger.write(row.getEntry().getSbn().getLogMaker() |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6136 | .setCategory(MetricsEvent.ACTION_TOUCH_GEAR) |
| 6137 | .setType(MetricsEvent.TYPE_ACTION) |
| 6138 | ); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6139 | } |
| 6140 | mLongPressListener.onLongPress(view, x, y, item); |
| 6141 | } |
| 6142 | |
| 6143 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6144 | public void onMenuReset(View row) { |
| 6145 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 6146 | if (translatingParentView != null && row == translatingParentView) { |
| 6147 | mSwipeHelper.clearExposedMenuView(); |
| 6148 | mSwipeHelper.clearTranslatingParentView(); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6149 | if (row instanceof ExpandableNotificationRow) { |
| 6150 | mHeadsUpManager.setMenuShown( |
| 6151 | ((ExpandableNotificationRow) row).getEntry(), false); |
| 6152 | |
| 6153 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6154 | } |
| 6155 | } |
| 6156 | |
| 6157 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6158 | public void onMenuShown(View row) { |
| 6159 | if (row instanceof ExpandableNotificationRow) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6160 | ExpandableNotificationRow notificationRow = (ExpandableNotificationRow) row; |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6161 | mMetricsLogger.write(notificationRow.getEntry().getSbn().getLogMaker() |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6162 | .setCategory(MetricsEvent.ACTION_REVEAL_GEAR) |
| 6163 | .setType(MetricsEvent.TYPE_ACTION)); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6164 | mHeadsUpManager.setMenuShown(notificationRow.getEntry(), true); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6165 | mSwipeHelper.onMenuShown(row); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6166 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6167 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6168 | false /* resetMenu */); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6169 | |
| 6170 | // Check to see if we want to go directly to the notfication guts |
| 6171 | NotificationMenuRowPlugin provider = notificationRow.getProvider(); |
| 6172 | if (provider.shouldShowGutsOnSnapOpen()) { |
| 6173 | MenuItem item = provider.menuItemToExposeOnSnap(); |
| 6174 | if (item != null) { |
| 6175 | Point origin = provider.getRevealAnimationOrigin(); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6176 | mNotificationGutsManager.openGuts(row, origin.x, origin.y, item); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6177 | } else { |
| 6178 | Log.e(TAG, "Provider has shouldShowGutsOnSnapOpen, but provided no " |
| 6179 | + "menu item in menuItemtoExposeOnSnap. Skipping."); |
| 6180 | } |
| 6181 | |
| 6182 | // Close the menu row since we went directly to the guts |
| 6183 | resetExposedMenuView(false, true); |
| 6184 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6185 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6186 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6187 | }; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6188 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6189 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6190 | private final NotificationSwipeHelper.NotificationCallback mNotificationCallback = |
| 6191 | new NotificationSwipeHelper.NotificationCallback() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6192 | @Override |
| 6193 | public void onDismiss() { |
| 6194 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6195 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6196 | false /* resetMenu */); |
| 6197 | } |
| 6198 | |
| 6199 | @Override |
| 6200 | public void onSnooze(StatusBarNotification sbn, |
| 6201 | NotificationSwipeActionHelper.SnoozeOption snoozeOption) { |
| 6202 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
| 6203 | } |
| 6204 | |
| 6205 | @Override |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 6206 | public void onSnooze(StatusBarNotification sbn, int hours) { |
| 6207 | mStatusBar.setNotificationSnoozed(sbn, hours); |
| 6208 | } |
| 6209 | |
| 6210 | @Override |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6211 | public boolean shouldDismissQuickly() { |
| 6212 | return NotificationStackScrollLayout.this.isExpanded() && mAmbientState.isFullyAwake(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6216 | public void onDragCancelled(View v) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6217 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6218 | mFalsingManager.onNotificatonStopDismissing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | /** |
| 6222 | * Handles cleanup after the given {@code view} has been fully swiped out (including |
| 6223 | * re-invoking dismiss logic in case the notification has not made its way out yet). |
| 6224 | */ |
| 6225 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6226 | public void onChildDismissed(View view) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6227 | if (!(view instanceof ActivatableNotificationView)) { |
| 6228 | return; |
| 6229 | } |
| 6230 | ActivatableNotificationView row = (ActivatableNotificationView) view; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6231 | if (!row.isDismissed()) { |
| 6232 | handleChildViewDismissed(view); |
| 6233 | } |
| 6234 | ViewGroup transientContainer = row.getTransientContainer(); |
| 6235 | if (transientContainer != null) { |
| 6236 | transientContainer.removeTransientView(view); |
| 6237 | } |
| 6238 | } |
| 6239 | |
| 6240 | /** |
| 6241 | * Starts up notification dismiss and tells the notification, if any, to remove itself from |
| 6242 | * layout. |
| 6243 | * |
| 6244 | * @param view view (e.g. notification) to dismiss from the layout |
| 6245 | */ |
| 6246 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6247 | public void handleChildViewDismissed(View view) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6248 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6249 | if (mDismissAllInProgress) { |
| 6250 | return; |
| 6251 | } |
| 6252 | |
| 6253 | boolean isBlockingHelperShown = false; |
| 6254 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6255 | mAmbientState.onDragFinished(view); |
| 6256 | updateContinuousShadowDrawing(); |
| 6257 | |
| 6258 | if (view instanceof ExpandableNotificationRow) { |
| 6259 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6260 | if (row.isHeadsUp()) { |
| 6261 | mHeadsUpManager.addSwipedOutNotification( |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6262 | row.getEntry().getSbn().getKey()); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6263 | } |
| 6264 | isBlockingHelperShown = |
| 6265 | row.performDismissWithBlockingHelper(false /* fromAccessibility */); |
| 6266 | } |
| 6267 | |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6268 | if (view instanceof PeopleHubView) { |
| 6269 | PeopleHubView row = (PeopleHubView) view; |
| 6270 | row.dismiss(false); |
| 6271 | mSectionsManager.hidePeopleRow(); |
| 6272 | } |
| 6273 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6274 | if (!isBlockingHelperShown) { |
| 6275 | mSwipedOutViews.add(view); |
| 6276 | } |
| 6277 | mFalsingManager.onNotificationDismissed(); |
| 6278 | if (mFalsingManager.shouldEnforceBouncer()) { |
| 6279 | mStatusBar.executeRunnableDismissingKeyguard( |
| 6280 | null, |
| 6281 | null /* cancelAction */, |
| 6282 | false /* dismissShade */, |
| 6283 | true /* afterKeyguardGone */, |
| 6284 | false /* deferred */); |
| 6285 | } |
| 6286 | } |
| 6287 | |
| 6288 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6289 | public boolean isAntiFalsingNeeded() { |
| 6290 | return onKeyguard(); |
| 6291 | } |
| 6292 | |
| 6293 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6294 | public View getChildAtPosition(MotionEvent ev) { |
| 6295 | View child = NotificationStackScrollLayout.this.getChildAtPosition(ev.getX(), |
| 6296 | ev.getY()); |
| 6297 | if (child instanceof ExpandableNotificationRow) { |
| 6298 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 6299 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 6300 | if (parent != null && parent.areChildrenExpanded() |
| 6301 | && (parent.areGutsExposed() |
| 6302 | || mSwipeHelper.getExposedMenuView() == parent |
| 6303 | || (parent.getNotificationChildren().size() == 1 |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 6304 | && parent.getEntry().isClearable()))) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6305 | // In this case the group is expanded and showing the menu for the |
| 6306 | // group, further interaction should apply to the group, not any |
| 6307 | // child notifications so we use the parent of the child. We also do the same |
| 6308 | // if we only have a single child. |
| 6309 | child = parent; |
| 6310 | } |
| 6311 | } |
| 6312 | return child; |
| 6313 | } |
| 6314 | |
| 6315 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6316 | public void onBeginDrag(View v) { |
| 6317 | mFalsingManager.onNotificatonStartDismissing(); |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6318 | setSwipingInProgress(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6319 | mAmbientState.onBeginDrag((ExpandableView) v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6320 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6321 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6322 | requestChildrenUpdate(); |
| 6323 | } |
| 6324 | |
| 6325 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6326 | public void onChildSnappedBack(View animView, float targetLeft) { |
| 6327 | mAmbientState.onDragFinished(animView); |
| 6328 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6329 | updateContinuousBackgroundDrawing(); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 6330 | if (animView instanceof ExpandableNotificationRow) { |
| 6331 | ExpandableNotificationRow row = (ExpandableNotificationRow) animView; |
| 6332 | if (row.isPinned() && !canChildBeDismissed(row) |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6333 | && row.getEntry().getSbn().getNotification().fullScreenIntent |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 6334 | == null) { |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 6335 | mHeadsUpManager.removeNotification(row.getEntry().getSbn().getKey(), |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 6336 | true /* removeImmediately */); |
| 6337 | } |
| 6338 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6339 | } |
| 6340 | |
| 6341 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6342 | public boolean updateSwipeProgress(View animView, boolean dismissable, |
| 6343 | float swipeProgress) { |
| 6344 | // Returning true prevents alpha fading. |
| 6345 | return !mFadeNotificationsOnDismiss; |
| 6346 | } |
| 6347 | |
| 6348 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6349 | public float getFalsingThresholdFactor() { |
| 6350 | return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
| 6351 | } |
| 6352 | |
| 6353 | @Override |
Gus Prevas | c4e68d4 | 2019-01-17 15:45:21 -0500 | [diff] [blame] | 6354 | public int getConstrainSwipeStartPosition() { |
| 6355 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 6356 | if (menuRow != null) { |
| 6357 | return Math.abs(menuRow.getMenuSnapTarget()); |
| 6358 | } |
| 6359 | return 0; |
| 6360 | } |
| 6361 | |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6362 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6363 | public boolean canChildBeDismissed(View v) { |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6364 | return NotificationStackScrollLayout.canChildBeDismissed(v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6365 | } |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6366 | |
| 6367 | @Override |
| 6368 | public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) { |
Evan Laird | 30b9b16 | 2019-04-24 15:22:24 -0400 | [diff] [blame] | 6369 | //TODO: b/131242807 for why this doesn't do anything with direction |
| 6370 | return canChildBeDismissed(v); |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6371 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6372 | }; |
| 6373 | |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 6374 | private static boolean canChildBeDismissed(View v) { |
| 6375 | if (v instanceof ExpandableNotificationRow) { |
| 6376 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6377 | if (row.isBlockingHelperShowingAndTranslationFinished()) { |
| 6378 | return true; |
| 6379 | } |
| 6380 | if (row.areGutsExposed() || !row.getEntry().hasFinishedInitialization()) { |
| 6381 | return false; |
| 6382 | } |
| 6383 | return row.canViewBeDismissed(); |
| 6384 | } |
| 6385 | if (v instanceof PeopleHubView) { |
| 6386 | return true; |
| 6387 | } |
| 6388 | return false; |
| 6389 | } |
| 6390 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6391 | // ---------------------- DragDownHelper.OnDragDownListener ------------------------------------ |
| 6392 | |
| 6393 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6394 | private final DragDownCallback mDragDownCallback = new DragDownCallback() { |
| 6395 | |
| 6396 | /* Only ever called as a consequence of a lockscreen expansion gesture. */ |
| 6397 | @Override |
| 6398 | public boolean onDraggedDown(View startingChild, int dragLengthY) { |
| 6399 | if (mStatusBarState == StatusBarState.KEYGUARD |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 6400 | && mEntryManager.hasActiveNotifications()) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6401 | mLockscreenGestureLogger.write( |
| 6402 | MetricsEvent.ACTION_LS_SHADE, |
| 6403 | (int) (dragLengthY / mDisplayMetrics.density), |
| 6404 | 0 /* velocityDp - N/A */); |
| 6405 | |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 6406 | if (!mAmbientState.isDozing() || startingChild != null) { |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6407 | // We have notifications, go to locked shade. |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 6408 | Dependency.get(ShadeController.class).goToLockedShade(startingChild); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6409 | if (startingChild instanceof ExpandableNotificationRow) { |
| 6410 | ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild; |
| 6411 | row.onExpandedByGesture(true /* drag down is always an open */); |
| 6412 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6413 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6414 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6415 | return true; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 6416 | } else if (mDynamicPrivacyController.isInLockedDownShade()) { |
| 6417 | mStatusbarStateController.setLeaveOpenOnKeyguardHide(true); |
| 6418 | mStatusBar.dismissKeyguardThenExecute(() -> false /* dismissAction */, |
| 6419 | null /* cancelRunnable */, false /* afterKeyguardGone */); |
| 6420 | return true; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6421 | } else { |
| 6422 | // abort gesture. |
| 6423 | return false; |
| 6424 | } |
| 6425 | } |
| 6426 | |
| 6427 | @Override |
| 6428 | public void onDragDownReset() { |
| 6429 | setDimmed(true /* dimmed */, true /* animated */); |
| 6430 | resetScrollPosition(); |
| 6431 | resetCheckSnoozeLeavebehind(); |
| 6432 | } |
| 6433 | |
| 6434 | @Override |
| 6435 | public void onCrossedThreshold(boolean above) { |
| 6436 | setDimmed(!above /* dimmed */, true /* animate */); |
| 6437 | } |
| 6438 | |
| 6439 | @Override |
| 6440 | public void onTouchSlopExceeded() { |
| 6441 | cancelLongPress(); |
| 6442 | checkSnoozeLeavebehind(); |
| 6443 | } |
| 6444 | |
| 6445 | @Override |
| 6446 | public void setEmptyDragAmount(float amount) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 6447 | mNotificationPanelController.setEmptyDragAmount(amount); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | @Override |
| 6451 | public boolean isFalsingCheckNeeded() { |
| 6452 | return mStatusBarState == StatusBarState.KEYGUARD; |
| 6453 | } |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 6454 | |
| 6455 | @Override |
| 6456 | public boolean isDragDownEnabledForView(ExpandableView view) { |
| 6457 | if (isDragDownAnywhereEnabled()) { |
| 6458 | return true; |
| 6459 | } |
| 6460 | if (mDynamicPrivacyController.isInLockedDownShade()) { |
| 6461 | if (view == null) { |
| 6462 | // Dragging down is allowed in general |
| 6463 | return true; |
| 6464 | } |
| 6465 | if (view instanceof ExpandableNotificationRow) { |
| 6466 | // Only drag down on sensitive views, otherwise the ExpandHelper will take this |
| 6467 | return ((ExpandableNotificationRow) view).getEntry().isSensitive(); |
| 6468 | } |
| 6469 | } |
| 6470 | return false; |
| 6471 | } |
| 6472 | |
| 6473 | @Override |
| 6474 | public boolean isDragDownAnywhereEnabled() { |
| 6475 | return mStatusbarStateController.getState() == StatusBarState.KEYGUARD |
| 6476 | && !mKeyguardBypassController.getBypassEnabled(); |
| 6477 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6478 | }; |
| 6479 | |
| 6480 | public DragDownCallback getDragDownCallback() { return mDragDownCallback; } |
| 6481 | |
| 6482 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6483 | private final HeadsUpTouchHelper.Callback mHeadsUpCallback = new HeadsUpTouchHelper.Callback() { |
| 6484 | @Override |
| 6485 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6486 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6487 | } |
| 6488 | |
| 6489 | @Override |
| 6490 | public boolean isExpanded() { |
| 6491 | return mIsExpanded; |
| 6492 | } |
| 6493 | |
| 6494 | @Override |
| 6495 | public Context getContext() { |
| 6496 | return mContext; |
| 6497 | } |
| 6498 | }; |
| 6499 | |
| 6500 | public HeadsUpTouchHelper.Callback getHeadsUpCallback() { return mHeadsUpCallback; } |
| 6501 | |
| 6502 | |
| 6503 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6504 | private final OnGroupChangeListener mOnGroupChangeListener = new OnGroupChangeListener() { |
| 6505 | @Override |
| 6506 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
| 6507 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 6508 | && (mIsExpanded || changedRow.isPinned()); |
| 6509 | if (animated) { |
| 6510 | mExpandedGroupView = changedRow; |
| 6511 | mNeedsAnimation = true; |
| 6512 | } |
| 6513 | changedRow.setChildrenExpanded(expanded, animated); |
| 6514 | if (!mGroupExpandedForMeasure) { |
| 6515 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 6516 | } |
| 6517 | runAfterAnimationFinished(new Runnable() { |
| 6518 | @Override |
| 6519 | public void run() { |
| 6520 | changedRow.onFinishedExpansionChange(); |
| 6521 | } |
| 6522 | }); |
| 6523 | } |
| 6524 | |
| 6525 | @Override |
| 6526 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 6527 | mStatusBar.requestNotificationUpdate("onGroupCreatedFromChildren"); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6528 | } |
| 6529 | |
| 6530 | @Override |
| 6531 | public void onGroupsChanged() { |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 6532 | mStatusBar.requestNotificationUpdate("onGroupsChanged"); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6533 | } |
| 6534 | }; |
| 6535 | |
| 6536 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6537 | private ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { |
| 6538 | @Override |
| 6539 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
| 6540 | return NotificationStackScrollLayout.this.getChildAtPosition(touchX, touchY); |
| 6541 | } |
| 6542 | |
| 6543 | @Override |
| 6544 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6545 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6546 | } |
| 6547 | |
| 6548 | @Override |
| 6549 | public boolean canChildBeExpanded(View v) { |
| 6550 | return v instanceof ExpandableNotificationRow |
| 6551 | && ((ExpandableNotificationRow) v).isExpandable() |
| 6552 | && !((ExpandableNotificationRow) v).areGutsExposed() |
| 6553 | && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned()); |
| 6554 | } |
| 6555 | |
| 6556 | /* Only ever called as a consequence of an expansion gesture in the shade. */ |
| 6557 | @Override |
| 6558 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 6559 | if (v instanceof ExpandableNotificationRow) { |
| 6560 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6561 | if (userExpanded && onKeyguard()) { |
| 6562 | // Due to a race when locking the screen while touching, a notification may be |
| 6563 | // expanded even after we went back to keyguard. An example of this happens if |
| 6564 | // you click in the empty space while expanding a group. |
| 6565 | |
| 6566 | // We also need to un-user lock it here, since otherwise the content height |
| 6567 | // calculated might be wrong. We also can't invert the two calls since |
| 6568 | // un-userlocking it will trigger a layout switch in the content view. |
| 6569 | row.setUserLocked(false); |
| 6570 | updateContentHeight(); |
| 6571 | notifyHeightChangeListener(row); |
| 6572 | return; |
| 6573 | } |
| 6574 | row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */); |
| 6575 | row.onExpandedByGesture(userExpanded); |
| 6576 | } |
| 6577 | } |
| 6578 | |
| 6579 | @Override |
| 6580 | public void setExpansionCancelled(View v) { |
| 6581 | if (v instanceof ExpandableNotificationRow) { |
| 6582 | ((ExpandableNotificationRow) v).setGroupExpansionChanging(false); |
| 6583 | } |
| 6584 | } |
| 6585 | |
| 6586 | @Override |
| 6587 | public void setUserLockedChild(View v, boolean userLocked) { |
| 6588 | if (v instanceof ExpandableNotificationRow) { |
| 6589 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 6590 | } |
| 6591 | cancelLongPress(); |
| 6592 | requestDisallowInterceptTouchEvent(true); |
| 6593 | } |
| 6594 | |
| 6595 | @Override |
| 6596 | public void expansionStateChanged(boolean isExpanding) { |
| 6597 | mExpandingNotification = isExpanding; |
| 6598 | if (!mExpandedInThisMotion) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 6599 | if (ANCHOR_SCROLLING) { |
| 6600 | // TODO |
| 6601 | } else { |
| 6602 | mMaxScrollAfterExpand = mOwnScrollY; |
| 6603 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6604 | mExpandedInThisMotion = true; |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | @Override |
| 6609 | public int getMaxExpandHeight(ExpandableView view) { |
| 6610 | return view.getMaxContentHeight(); |
| 6611 | } |
| 6612 | }; |
| 6613 | |
| 6614 | public ExpandHelper.Callback getExpandHelperCallback() { |
| 6615 | return mExpandHelperCallback; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6616 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6617 | |
| 6618 | /** Enum for selecting some or all notification rows (does not included non-notif views). */ |
| 6619 | @Retention(SOURCE) |
| 6620 | @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE}) |
| 6621 | public @interface SelectedRows {} |
| 6622 | /** All rows representing notifs. */ |
| 6623 | public static final int ROWS_ALL = 0; |
| 6624 | /** Only rows where entry.isHighPriority() is true. */ |
| 6625 | public static final int ROWS_HIGH_PRIORITY = 1; |
| 6626 | /** Only rows where entry.isHighPriority() is false. */ |
| 6627 | public static final int ROWS_GENTLE = 2; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 6628 | } |