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; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.ANCHOR_SCROLLING; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 22 | import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_SWIPE; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.phone.NotificationIconAreaController.HIGH_PRIORITY; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 24 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 25 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 26 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 27 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 28 | import android.animation.Animator; |
| 29 | import android.animation.AnimatorListenerAdapter; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 30 | import android.animation.TimeAnimator; |
| 31 | import android.animation.ValueAnimator; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 32 | import android.annotation.IntDef; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 33 | import android.annotation.NonNull; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 34 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 35 | import android.content.Context; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 36 | import android.content.Intent; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 37 | import android.content.res.Configuration; |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 38 | import android.content.res.Resources; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 39 | import android.graphics.Canvas; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 40 | import android.graphics.Color; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 41 | import android.graphics.Outline; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 42 | import android.graphics.Paint; |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 43 | import android.graphics.Point; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 44 | import android.graphics.PointF; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 45 | import android.graphics.PorterDuff; |
| 46 | import android.graphics.PorterDuffXfermode; |
| 47 | import android.graphics.Rect; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 48 | import android.os.Bundle; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 49 | import android.os.ServiceManager; |
| 50 | import android.provider.Settings; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 51 | import android.service.notification.NotificationListenerService; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 52 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 53 | import android.util.AttributeSet; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 54 | import android.util.DisplayMetrics; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 55 | import android.util.Log; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 56 | import android.util.MathUtils; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 57 | import android.util.Pair; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 58 | import android.view.ContextThemeWrapper; |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 59 | import android.view.InputDevice; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 60 | import android.view.LayoutInflater; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 61 | import android.view.MotionEvent; |
| 62 | import android.view.VelocityTracker; |
| 63 | import android.view.View; |
| 64 | import android.view.ViewConfiguration; |
| 65 | import android.view.ViewGroup; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 66 | import android.view.ViewOutlineProvider; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 67 | import android.view.ViewTreeObserver; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 68 | import android.view.WindowInsets; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 69 | import android.view.accessibility.AccessibilityEvent; |
| 70 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 71 | import android.view.animation.AnimationUtils; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 72 | import android.view.animation.Interpolator; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 73 | import android.widget.OverScroller; |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 74 | import android.widget.ScrollView; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 75 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 76 | import com.android.internal.annotations.VisibleForTesting; |
| 77 | import com.android.internal.graphics.ColorUtils; |
Mady Mellor | a41587b | 2016-02-11 18:43:06 -0800 | [diff] [blame] | 78 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 79 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 80 | import com.android.internal.statusbar.IStatusBarService; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 81 | import com.android.keyguard.KeyguardSliceView; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 82 | import com.android.settingslib.Utils; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 83 | import com.android.systemui.Dependency; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 84 | import com.android.systemui.Dumpable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 85 | import com.android.systemui.ExpandHelper; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 86 | import com.android.systemui.Interpolators; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 87 | import com.android.systemui.R; |
| 88 | import com.android.systemui.SwipeHelper; |
Dave Mankoff | dde5ee6 | 2019-05-02 17:36:11 -0400 | [diff] [blame] | 89 | import com.android.systemui.classifier.FalsingManagerFactory; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 90 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 91 | import com.android.systemui.plugins.ActivityStarter; |
Dave Mankoff | 468d4f6 | 2019-05-08 14:56:29 -0400 | [diff] [blame] | 92 | import com.android.systemui.plugins.FalsingManager; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 93 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
| 94 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 95 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.OnMenuEventListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 96 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 97 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 98 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 99 | import com.android.systemui.statusbar.CommandQueue; |
| 100 | import com.android.systemui.statusbar.DragDownHelper.DragDownCallback; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 101 | import com.android.systemui.statusbar.EmptyShadeView; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 102 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 103 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 104 | import com.android.systemui.statusbar.NotificationShelf; |
| 105 | import com.android.systemui.statusbar.RemoteInputController; |
| 106 | import com.android.systemui.statusbar.StatusBarState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 107 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 108 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 109 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 110 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 111 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 112 | import com.android.systemui.statusbar.notification.NotificationUtils; |
| 113 | import com.android.systemui.statusbar.notification.ShadeViewRefactor; |
| 114 | import com.android.systemui.statusbar.notification.ShadeViewRefactor.RefactorComponent; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 115 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 116 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 117 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 118 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 119 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 120 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 121 | import com.android.systemui.statusbar.notification.row.FooterView; |
| 122 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 123 | import com.android.systemui.statusbar.notification.row.NotificationGuts; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 124 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 125 | import com.android.systemui.statusbar.notification.row.NotificationSnooze; |
| 126 | import com.android.systemui.statusbar.notification.row.StackScrollerDecorView; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 127 | import com.android.systemui.statusbar.phone.HeadsUpAppearanceController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 128 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 129 | import com.android.systemui.statusbar.phone.HeadsUpTouchHelper; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 130 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 131 | import com.android.systemui.statusbar.phone.LockscreenGestureLogger; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 132 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 133 | import com.android.systemui.statusbar.phone.NotificationGroupManager.OnGroupChangeListener; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 134 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 135 | import com.android.systemui.statusbar.phone.NotificationPanelView; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 136 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 137 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 138 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 139 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 140 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 141 | import com.android.systemui.statusbar.policy.HeadsUpUtil; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 142 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 143 | import com.android.systemui.tuner.TunerService; |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 144 | import com.android.systemui.util.Assert; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 145 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 146 | import java.io.FileDescriptor; |
| 147 | import java.io.PrintWriter; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 148 | import java.lang.annotation.Retention; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 149 | import java.util.ArrayList; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 150 | import java.util.Collections; |
| 151 | import java.util.Comparator; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 152 | import java.util.HashSet; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 153 | import java.util.List; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 154 | import java.util.function.BiConsumer; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 155 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 156 | import javax.inject.Inject; |
| 157 | import javax.inject.Named; |
| 158 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 159 | /** |
| 160 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 161 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 162 | public class NotificationStackScrollLayout extends ViewGroup implements ScrollAdapter, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 163 | NotificationListContainer, ConfigurationListener, Dumpable, |
| 164 | DynamicPrivacyController.Listener { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 165 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 166 | public static final float BACKGROUND_ALPHA_DIMMED = 0.7f; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 167 | private static final String TAG = "StackScroller"; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 168 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 169 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 170 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 171 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 172 | /** |
| 173 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 174 | */ |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 175 | private static final int INVALID_POINTER = -1; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 176 | static final int NUM_SECTIONS = 2; |
| 177 | /** |
| 178 | * The distance in pixels between sections when the sections are directly adjacent (no visible |
| 179 | * gap is drawn between them). In this case we don't want to round their corners. |
| 180 | */ |
| 181 | private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 182 | private final KeyguardBypassController mKeyguardBypassController; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 183 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 184 | private ExpandHelper mExpandHelper; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 185 | private final NotificationSwipeHelper mSwipeHelper; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 186 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 187 | private final Paint mBackgroundPaint = new Paint(); |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 188 | private final boolean mShouldDrawNotificationBackground; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 189 | private boolean mHighPriorityBeforeSpeedBump; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 190 | private final boolean mAllowLongPress; |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 191 | private boolean mDismissRtl; |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 192 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 193 | private float mExpandedHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 194 | private int mOwnScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 195 | private View mScrollAnchorView; |
| 196 | private int mScrollAnchorViewY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 197 | private int mMaxLayoutHeight; |
| 198 | |
| 199 | private VelocityTracker mVelocityTracker; |
| 200 | private OverScroller mScroller; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 201 | /** Last Y position reported by {@link #mScroller}, used to calculate scroll delta. */ |
| 202 | private int mLastScrollerY; |
| 203 | /** |
| 204 | * True if the max position was set to a known position on the last call to {@link #mScroller}. |
| 205 | */ |
| 206 | private boolean mIsScrollerBoundSet; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 207 | private Runnable mFinishScrollingCallback; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 208 | private int mTouchSlop; |
| 209 | private int mMinimumVelocity; |
| 210 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 211 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 212 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 213 | private boolean mIsBeingDragged; |
| 214 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 215 | private int mDownX; |
Dong-wan Kim | b926666 | 2016-09-21 13:08:30 -0700 | [diff] [blame] | 216 | private int mActivePointerId = INVALID_POINTER; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 217 | private boolean mTouchIsClick; |
| 218 | private float mInitialTouchX; |
| 219 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 220 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 221 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 222 | private int mContentHeight; |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 223 | private int mIntrinsicContentHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 224 | private int mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 225 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 226 | private int mIncreasedPaddingBetweenElements; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 227 | private int mMaxTopPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 228 | private int mTopPadding; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 229 | private int mBottomMargin; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 230 | private int mBottomInset = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 231 | private float mQsExpansionFraction; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * The algorithm which calculates the properties for our children |
| 235 | */ |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 236 | protected final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 237 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 238 | private final AmbientState mAmbientState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 239 | private NotificationGroupManager mGroupManager; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 240 | private HashSet<ExpandableView> mChildrenToAddAnimated = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 241 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 242 | private ArrayList<ExpandableView> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 243 | private ArrayList<ExpandableView> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 244 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 245 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 246 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 247 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 248 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 249 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 250 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 251 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 252 | /** |
| 253 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 254 | */ |
| 255 | private float mOverScrolledTopPixels; |
| 256 | |
| 257 | /** |
| 258 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 259 | */ |
| 260 | private float mOverScrolledBottomPixels; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 261 | private NotificationLogger.OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 262 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 263 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 264 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 265 | private boolean mNeedsAnimation; |
| 266 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 267 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 268 | private boolean mHideSensitiveNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 269 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 270 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 271 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 272 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 273 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 274 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 275 | private boolean mExpandingNotification; |
| 276 | private boolean mExpandedInThisMotion; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 277 | private boolean mShouldShowShelfOnly; |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 278 | protected boolean mScrollingEnabled; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 279 | protected FooterView mFooterView; |
Muyuan Li | dd9ae75 | 2016-05-13 16:45:43 -0700 | [diff] [blame] | 280 | protected EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 281 | private boolean mDismissAllInProgress; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 282 | private boolean mFadeNotificationsOnDismiss; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 283 | |
| 284 | /** |
| 285 | * Was the scroller scrolled to the top when the down motion was observed? |
| 286 | */ |
| 287 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 288 | /** |
| 289 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 290 | * when over scrolling on a expanded card. |
| 291 | */ |
| 292 | private float mMinTopOverScrollToEscape; |
| 293 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 294 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 295 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 296 | private boolean mDontReportNextOverScroll; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 297 | private boolean mDontClampNextScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 298 | private boolean mNeedViewResizeAnimation; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 299 | private ExpandableView mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 300 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 301 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 302 | /** |
| 303 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 304 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 305 | * motion. |
| 306 | */ |
| 307 | private int mMaxScrollAfterExpand; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 308 | private ExpandableNotificationRow.LongPressListener mLongPressListener; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 309 | boolean mCheckForLeavebehind; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 310 | |
| 311 | /** |
| 312 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 313 | * animating. |
| 314 | */ |
| 315 | private boolean mOnlyScrollingInThisMotion; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 316 | private boolean mDisallowDismissInThisMotion; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 317 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 318 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 319 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 320 | = new ViewTreeObserver.OnPreDrawListener() { |
| 321 | @Override |
| 322 | public boolean onPreDraw() { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 323 | updateForcedScroll(); |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 324 | updateChildren(); |
| 325 | mChildrenUpdateRequested = false; |
| 326 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 327 | return true; |
| 328 | } |
| 329 | }; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 330 | private StatusBar mStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 331 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 332 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 333 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 334 | private HashSet<ExpandableView> mClearTransientViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 335 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 336 | = new HashSet<>(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 337 | private HeadsUpManagerPhone mHeadsUpManager; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 338 | private final NotificationRoundnessManager mRoundnessManager; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 339 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 340 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 341 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 342 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 343 | private FalsingManager mFalsingManager; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 344 | private boolean mAnimationRunning; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 345 | private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 346 | = new ViewTreeObserver.OnPreDrawListener() { |
| 347 | @Override |
| 348 | public boolean onPreDraw() { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 349 | onPreDrawDuringAnimation(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | }; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 353 | private NotificationSection[] mSections = new NotificationSection[NUM_SECTIONS]; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 354 | private boolean mAnimateNextBackgroundTop; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 355 | private boolean mAnimateNextBackgroundBottom; |
| 356 | private boolean mAnimateNextSectionBoundsChange; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 357 | private int mBgColor; |
| 358 | private float mDimAmount; |
| 359 | private ValueAnimator mDimAnimator; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 360 | private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 361 | private final Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 362 | @Override |
| 363 | public void onAnimationEnd(Animator animation) { |
| 364 | mDimAnimator = null; |
| 365 | } |
| 366 | }; |
| 367 | private ValueAnimator.AnimatorUpdateListener mDimUpdateListener |
| 368 | = new ValueAnimator.AnimatorUpdateListener() { |
| 369 | |
| 370 | @Override |
| 371 | public void onAnimationUpdate(ValueAnimator animation) { |
| 372 | setDimAmount((Float) animation.getAnimatedValue()); |
| 373 | } |
| 374 | }; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 375 | protected ViewGroup mQsContainer; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 376 | private boolean mContinuousShadowUpdate; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 377 | private boolean mContinuousBackgroundUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 378 | private ViewTreeObserver.OnPreDrawListener mShadowUpdater |
| 379 | = new ViewTreeObserver.OnPreDrawListener() { |
| 380 | |
| 381 | @Override |
| 382 | public boolean onPreDraw() { |
| 383 | updateViewShadows(); |
| 384 | return true; |
| 385 | } |
| 386 | }; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 387 | private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> { |
| 388 | updateBackground(); |
| 389 | return true; |
| 390 | }; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 391 | private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() { |
| 392 | @Override |
| 393 | public int compare(ExpandableView view, ExpandableView otherView) { |
| 394 | float endY = view.getTranslationY() + view.getActualHeight(); |
| 395 | float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); |
| 396 | if (endY < otherEndY) { |
| 397 | return -1; |
| 398 | } else if (endY > otherEndY) { |
| 399 | return 1; |
| 400 | } else { |
| 401 | // The two notifications end at the same location |
| 402 | return 0; |
| 403 | } |
| 404 | } |
| 405 | }; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 406 | private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() { |
| 407 | @Override |
| 408 | public void getOutline(View view, Outline outline) { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 409 | if (mAmbientState.isHiddenAtAll()) { |
| 410 | float xProgress = mHideXInterpolator.getInterpolation( |
| 411 | (1 - mLinearHideAmount) * mBackgroundXFactor); |
Selim Cinek | 9ad240c | 2019-04-08 19:07:15 -0700 | [diff] [blame] | 412 | outline.setRoundRect(mBackgroundAnimationRect, |
| 413 | MathUtils.lerp(mCornerRadius / 2.0f, mCornerRadius, |
| 414 | xProgress)); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 415 | } else { |
| 416 | ViewOutlineProvider.BACKGROUND.getOutline(view, outline); |
| 417 | } |
| 418 | } |
| 419 | }; |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 420 | private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 421 | private boolean mPulsing; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 422 | private boolean mGroupExpandedForMeasure; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 423 | private boolean mScrollable; |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 424 | private View mForcedScroll; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 425 | |
| 426 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 427 | * @see #setHideAmount(float, float) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 428 | */ |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 429 | private float mInterpolatedHideAmount = 0f; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 430 | |
| 431 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 432 | * @see #setHideAmount(float, float) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 433 | */ |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 434 | private float mLinearHideAmount = 0f; |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 435 | |
| 436 | /** |
| 437 | * How fast the background scales in the X direction as a factor of the Y expansion. |
| 438 | */ |
| 439 | private float mBackgroundXFactor = 1f; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 440 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 441 | private boolean mSwipingInProgress; |
| 442 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 443 | private boolean mUsingLightTheme; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 444 | private boolean mQsExpanded; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 445 | private boolean mForwardScrollable; |
| 446 | private boolean mBackwardScrollable; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 447 | private NotificationShelf mShelf; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 448 | private int mMaxDisplayedNotifications = -1; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 449 | private int mStatusBarHeight; |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 450 | private int mMinInteractionHeight; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 451 | private boolean mNoAmbient; |
| 452 | private final Rect mClipRect = new Rect(); |
| 453 | private boolean mIsClipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 454 | private Rect mRequestedClipBounds; |
| 455 | private boolean mInHeadsUpPinnedMode; |
| 456 | private boolean mHeadsUpAnimatingAway; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 457 | private int mStatusBarState; |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 458 | private int mCachedBackgroundColor; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 459 | private boolean mHeadsUpGoingAwayAnimationsAllowed = true; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 460 | private Runnable mReflingAndAnimateScroll = () -> { |
| 461 | if (ANCHOR_SCROLLING) { |
| 462 | maybeReflingScroller(); |
| 463 | } |
| 464 | animateScroll(); |
| 465 | }; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 466 | private int mCornerRadius; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 467 | private int mSidePaddings; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 468 | private final Rect mBackgroundAnimationRect = new Rect(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 469 | private ArrayList<BiConsumer<Float, Float>> mExpandedHeightListeners = new ArrayList<>(); |
| 470 | private int mHeadsUpInset; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 471 | private HeadsUpAppearanceController mHeadsUpAppearanceController; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 472 | private NotificationIconAreaController mIconAreaController; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 473 | private final NotificationLockscreenUserManager mLockscreenUserManager = |
| 474 | Dependency.get(NotificationLockscreenUserManager.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 475 | private final Rect mTmpRect = new Rect(); |
| 476 | private final NotificationEntryManager mEntryManager = |
| 477 | Dependency.get(NotificationEntryManager.class); |
| 478 | private final IStatusBarService mBarService = IStatusBarService.Stub.asInterface( |
| 479 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 480 | @VisibleForTesting |
| 481 | protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 482 | private final NotificationRemoteInputManager mRemoteInputManager = |
| 483 | Dependency.get(NotificationRemoteInputManager.class); |
| 484 | private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
| 485 | |
| 486 | private final DisplayMetrics mDisplayMetrics = Dependency.get(DisplayMetrics.class); |
| 487 | private final LockscreenGestureLogger mLockscreenGestureLogger = |
| 488 | Dependency.get(LockscreenGestureLogger.class); |
| 489 | private final VisualStabilityManager mVisualStabilityManager = |
| 490 | Dependency.get(VisualStabilityManager.class); |
| 491 | protected boolean mClearAllEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 492 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 493 | private Interpolator mHideXInterpolator = Interpolators.FAST_OUT_SLOW_IN; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 494 | private NotificationPanelView mNotificationPanel; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 495 | private final ShadeController mShadeController = Dependency.get(ShadeController.class); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 496 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 497 | private final NotificationGutsManager |
| 498 | mNotificationGutsManager = Dependency.get(NotificationGutsManager.class); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 499 | private final NotificationSectionsManager mSectionsManager; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 500 | private boolean mAnimateBottomOnLayout; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 501 | private float mLastSentAppear; |
| 502 | private float mLastSentExpandedHeight; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 503 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 504 | @Inject |
| 505 | public NotificationStackScrollLayout( |
| 506 | @Named(VIEW_CONTEXT) Context context, |
| 507 | AttributeSet attrs, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 508 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress, |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 509 | NotificationRoundnessManager notificationRoundnessManager, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 510 | DynamicPrivacyController dynamicPrivacyController, |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 511 | ConfigurationController configurationController, |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 512 | ActivityStarter activityStarter, |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 513 | StatusBarStateController statusBarStateController, |
| 514 | HeadsUpManagerPhone headsUpManager, |
| 515 | KeyguardBypassController keyguardBypassController) { |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 516 | super(context, attrs, 0, 0); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 517 | Resources res = getResources(); |
| 518 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 519 | mAllowLongPress = allowLongPress; |
| 520 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 521 | for (int i = 0; i < NUM_SECTIONS; i++) { |
| 522 | mSections[i] = new NotificationSection(this); |
| 523 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 524 | mRoundnessManager = notificationRoundnessManager; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 525 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 526 | mHeadsUpManager = headsUpManager; |
| 527 | mHeadsUpManager.addListener(mRoundnessManager); |
| 528 | mHeadsUpManager.setAnimationStateHandler(this::setHeadsUpGoingAwayAnimationsAllowed); |
| 529 | mKeyguardBypassController = keyguardBypassController; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 530 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 531 | mSectionsManager = |
| 532 | new NotificationSectionsManager( |
| 533 | this, |
| 534 | activityStarter, |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 535 | statusBarStateController, |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 536 | configurationController, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 537 | NotificationUtils.useNewInterruptionModel(context)); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 538 | mSectionsManager.initialize(LayoutInflater.from(context)); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 539 | mSectionsManager.setOnClearGentleNotifsClickListener(v -> { |
| 540 | // Leave the shade open if there will be other notifs left over to clear |
| 541 | final boolean closeShade = !hasActiveClearableNotifications(ROWS_HIGH_PRIORITY); |
| 542 | clearNotifications(ROWS_GENTLE, closeShade); |
| 543 | }); |
| 544 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 545 | mAmbientState = new AmbientState(context, mSectionsManager, mHeadsUpManager); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 546 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 547 | int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 548 | int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 549 | mExpandHelper = new ExpandHelper(getContext(), mExpandHelperCallback, |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 550 | minHeight, maxHeight); |
| 551 | mExpandHelper.setEventSource(this); |
| 552 | mExpandHelper.setScrollAdapter(this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 553 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, mNotificationCallback, |
| 554 | getContext(), mMenuEventListener); |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 555 | mStackScrollAlgorithm = createStackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 556 | initView(context); |
Dave Mankoff | dde5ee6 | 2019-05-02 17:36:11 -0400 | [diff] [blame] | 557 | mFalsingManager = FalsingManagerFactory.getInstance(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 558 | mShouldDrawNotificationBackground = |
| 559 | res.getBoolean(R.bool.config_drawNotificationBackground); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 560 | mFadeNotificationsOnDismiss = |
| 561 | res.getBoolean(R.bool.config_fadeNotificationsOnDismiss); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 562 | mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated); |
| 563 | mRoundnessManager.setOnRoundingChangedCallback(this::invalidate); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 564 | addOnExpandedHeightChangedListener(mRoundnessManager::setExpanded); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 565 | setOutlineProvider(mOutlineProvider); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 566 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 567 | // Blocking helper manager wants to know the expanded state, update as well. |
| 568 | NotificationBlockingHelperManager blockingHelperManager = |
| 569 | Dependency.get(NotificationBlockingHelperManager.class); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 570 | addOnExpandedHeightChangedListener((height, unused) -> { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 571 | blockingHelperManager.setNotificationShadeExpanded(height); |
| 572 | }); |
| 573 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 574 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
| 575 | setWillNotDraw(!willDraw); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 576 | mBackgroundPaint.setAntiAlias(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 577 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 578 | mDebugPaint = new Paint(); |
| 579 | mDebugPaint.setColor(0xffff0000); |
| 580 | mDebugPaint.setStrokeWidth(2); |
| 581 | mDebugPaint.setStyle(Paint.Style.STROKE); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 582 | mDebugPaint.setTextSize(25f); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 583 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 584 | mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 585 | |
| 586 | TunerService tunerService = Dependency.get(TunerService.class); |
| 587 | tunerService.addTunable((key, newValue) -> { |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 588 | if (key.equals(HIGH_PRIORITY)) { |
| 589 | mHighPriorityBeforeSpeedBump = "1".equals(newValue); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 590 | } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { |
| 591 | updateDismissRtlSetting("1".equals(newValue)); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 592 | } |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 593 | }, HIGH_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL); |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 594 | |
| 595 | mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 596 | @Override |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 597 | public void onPostEntryUpdated(NotificationEntry entry) { |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 598 | if (!entry.notification.isClearable()) { |
| 599 | // The user may have performed a dismiss action on the notification, since it's |
| 600 | // not clearable we should snap it back. |
| 601 | snapViewIfNeeded(entry); |
| 602 | } |
| 603 | } |
| 604 | }); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 605 | dynamicPrivacyController.addListener(this); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 606 | } |
| 607 | |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 608 | private void updateDismissRtlSetting(boolean dismissRtl) { |
| 609 | mDismissRtl = dismissRtl; |
| 610 | for (int i = 0; i < getChildCount(); i++) { |
| 611 | View child = getChildAt(i); |
| 612 | if (child instanceof ExpandableNotificationRow) { |
| 613 | ((ExpandableNotificationRow) child).setDismissRtl(dismissRtl); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 618 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 619 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 620 | protected void onFinishInflate() { |
| 621 | super.onFinishInflate(); |
| 622 | |
| 623 | inflateEmptyShadeView(); |
| 624 | inflateFooterView(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 625 | mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 626 | if (mAllowLongPress) { |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 627 | setLongPressListener(mNotificationGutsManager::openGuts); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 628 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 629 | } |
| 630 | |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 631 | /** |
| 632 | * @return the height at which we will wake up when pulsing |
| 633 | */ |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 634 | public float getWakeUpHeight() { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 635 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 636 | if (firstChild != null) { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 637 | if (mKeyguardBypassController.getBypassEnabled()) { |
| 638 | return firstChild.getHeadsUpHeightWithoutHeader(); |
| 639 | } else { |
| 640 | return firstChild.getCollapsedHeight(); |
| 641 | } |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 642 | } |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 643 | return 0f; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 646 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 647 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 648 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 649 | reinflateViews(); |
| 650 | } |
| 651 | |
| 652 | private void reinflateViews() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 653 | inflateFooterView(); |
| 654 | inflateEmptyShadeView(); |
| 655 | updateFooter(); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 656 | mSectionsManager.reinflateViews(LayoutInflater.from(mContext)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 660 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 661 | public void onThemeChanged() { |
Lucas Dupin | 89233c4 | 2019-06-10 18:00:22 -0700 | [diff] [blame] | 662 | final boolean useDarkText = mColorExtractor.getNeutralColors().supportsDarkText(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 663 | updateDecorViews(useDarkText); |
| 664 | |
| 665 | updateFooter(); |
| 666 | } |
| 667 | |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 668 | @Override |
| 669 | public void onOverlayChanged() { |
| 670 | int newRadius = mContext.getResources().getDimensionPixelSize( |
| 671 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
| 672 | if (mCornerRadius != newRadius) { |
| 673 | mCornerRadius = newRadius; |
| 674 | invalidate(); |
| 675 | } |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 676 | reinflateViews(); |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 677 | } |
| 678 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 679 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 680 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 681 | public void updateFooter() { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 682 | boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 683 | boolean showFooterView = (showDismissView || |
| 684 | mEntryManager.getNotificationData().getActiveNotifications().size() != 0) |
| 685 | && mStatusBarState != StatusBarState.KEYGUARD |
| 686 | && !mRemoteInputManager.getController().isRemoteInputActive(); |
| 687 | |
| 688 | updateFooterView(showFooterView, showDismissView); |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Return whether there are any clearable notifications |
| 693 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 694 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 695 | public boolean hasActiveClearableNotifications(@SelectedRows int selection) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 696 | int childCount = getChildCount(); |
| 697 | for (int i = 0; i < childCount; i++) { |
| 698 | View child = getChildAt(i); |
| 699 | if (!(child instanceof ExpandableNotificationRow)) { |
| 700 | continue; |
| 701 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 702 | final ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 703 | if (row.canViewBeDismissed() && matchesSelection(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 704 | return true; |
| 705 | } |
| 706 | } |
| 707 | return false; |
| 708 | } |
| 709 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 710 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 711 | public RemoteInputController.Delegate createDelegate() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 712 | return new RemoteInputController.Delegate() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 713 | public void setRemoteInputActive(NotificationEntry entry, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 714 | boolean remoteInputActive) { |
| 715 | mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 716 | entry.notifyHeightChanged(true /* needsAnimation */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 717 | updateFooter(); |
| 718 | } |
| 719 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 720 | public void lockScrollTo(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 721 | NotificationStackScrollLayout.this.lockScrollTo(entry.getRow()); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | public void requestDisallowLongPressAndDismiss() { |
| 725 | requestDisallowLongPress(); |
| 726 | requestDisallowDismiss(); |
| 727 | } |
| 728 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 729 | } |
| 730 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 731 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 732 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 733 | protected void onAttachedToWindow() { |
| 734 | super.onAttachedToWindow(); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 735 | ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class)) |
| 736 | .addCallback(mStateListener, SysuiStatusBarStateController.RANK_STACK_SCROLLER); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 737 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 741 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 742 | protected void onDetachedFromWindow() { |
| 743 | super.onDetachedFromWindow(); |
Jason Monk | af08c15 | 2018-12-04 11:12:39 -0500 | [diff] [blame] | 744 | Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 745 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | @Override |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 749 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 750 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 751 | return mSwipeHelper; |
| 752 | } |
| 753 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 754 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 755 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 756 | public void onUiModeChanged() { |
| 757 | mBgColor = mContext.getColor(R.color.notification_shade_background_color); |
| 758 | updateBackgroundDimming(); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 759 | mShelf.onUiModeChanged(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 760 | mSectionsManager.onUiModeChanged(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 763 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 764 | protected void onDraw(Canvas canvas) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 765 | if (mShouldDrawNotificationBackground |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 766 | && (mSections[0].getCurrentBounds().top |
| 767 | < mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 768 | || mAmbientState.isDozing())) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 769 | drawBackground(canvas); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 770 | } else if (mInHeadsUpPinnedMode || mHeadsUpAnimatingAway) { |
| 771 | drawHeadsUpBackground(canvas); |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 772 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 773 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 774 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 775 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 776 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 777 | y = getLayoutHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 778 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 779 | y = getHeight() - getEmptyBottomMargin(); |
| 780 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 784 | @Override |
| 785 | public void draw(Canvas canvas) { |
| 786 | super.draw(canvas); |
| 787 | |
| 788 | if (DEBUG && ANCHOR_SCROLLING) { |
| 789 | if (mScrollAnchorView instanceof ExpandableNotificationRow) { |
| 790 | canvas.drawRect(0, |
| 791 | mScrollAnchorView.getTranslationY(), |
| 792 | getWidth(), |
| 793 | mScrollAnchorView.getTranslationY() |
| 794 | + ((ExpandableNotificationRow) mScrollAnchorView).getActualHeight(), |
| 795 | mDebugPaint); |
| 796 | canvas.drawText(Integer.toString(mScrollAnchorViewY), getWidth() - 200, |
| 797 | mScrollAnchorView.getTranslationY() + 30, mDebugPaint); |
| 798 | int y = (int) mShelf.getTranslationY(); |
| 799 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 800 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 801 | canvas.drawText(Integer.toString(getMaxNegativeScrollAmount()), getWidth() - 100, |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 802 | getTopPadding() + 30, mDebugPaint); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 803 | canvas.drawText(Integer.toString(getMaxPositiveScrollAmount()), getWidth() - 100, |
| 804 | getHeight() - 30, mDebugPaint); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 808 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 809 | private void drawBackground(Canvas canvas) { |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 810 | int lockScreenLeft = mSidePaddings; |
| 811 | int lockScreenRight = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 812 | int lockScreenTop = mSections[0].getCurrentBounds().top; |
| 813 | int lockScreenBottom = mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 814 | int hiddenLeft = getWidth() / 2; |
| 815 | int hiddenTop = mTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 816 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 817 | float yProgress = 1 - mInterpolatedHideAmount; |
| 818 | float xProgress = mHideXInterpolator.getInterpolation( |
| 819 | (1 - mLinearHideAmount) * mBackgroundXFactor); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 820 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 821 | int left = (int) MathUtils.lerp(hiddenLeft, lockScreenLeft, xProgress); |
| 822 | int right = (int) MathUtils.lerp(hiddenLeft, lockScreenRight, xProgress); |
| 823 | int top = (int) MathUtils.lerp(hiddenTop, lockScreenTop, yProgress); |
| 824 | int bottom = (int) MathUtils.lerp(hiddenTop, lockScreenBottom, yProgress); |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 825 | mBackgroundAnimationRect.set( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 826 | left, |
| 827 | top, |
| 828 | right, |
| 829 | bottom); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 830 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 831 | int backgroundTopAnimationOffset = top - lockScreenTop; |
| 832 | // TODO(kprevas): this may not be necessary any more since we don't display the shelf in AOD |
| 833 | boolean anySectionHasVisibleChild = false; |
| 834 | for (NotificationSection section : mSections) { |
| 835 | if (section.getFirstVisibleChild() != null) { |
| 836 | anySectionHasVisibleChild = true; |
| 837 | break; |
| 838 | } |
| 839 | } |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 840 | if (!mAmbientState.isDozing() || anySectionHasVisibleChild) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 841 | drawBackgroundRects(canvas, left, right, top, backgroundTopAnimationOffset); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 842 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 843 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 844 | updateClipping(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 847 | /** |
| 848 | * Draws round rects for each background section. |
| 849 | * |
| 850 | * We want to draw a round rect for each background section as defined by {@link #mSections}. |
| 851 | * However, if two sections are directly adjacent with no gap between them (e.g. on the |
| 852 | * lockscreen where the shelf can appear directly below the high priority section, or while |
| 853 | * scrolling the shade so that the top of the shelf is right at the bottom of the high priority |
| 854 | * section), we don't want to round the adjacent corners. |
| 855 | * |
| 856 | * Since {@link Canvas} doesn't provide a way to draw a half-rounded rect, this means that we |
| 857 | * need to coalesce the backgrounds for adjacent sections and draw them as a single round rect. |
| 858 | * This method tracks the top of each rect we need to draw, then iterates through the visible |
| 859 | * sections. If a section is not adjacent to the previous section, we draw the previous rect |
| 860 | * behind the sections we've accumulated up to that point, then start a new rect at the top of |
| 861 | * the current section. When we're done iterating we will always have one rect left to draw. |
| 862 | */ |
| 863 | private void drawBackgroundRects(Canvas canvas, int left, int right, int top, |
| 864 | int animationYOffset) { |
| 865 | int backgroundRectTop = top; |
| 866 | int lastSectionBottom = |
| 867 | mSections[0].getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 868 | int currentLeft = left; |
| 869 | int currentRight = right; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 870 | boolean first = true; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 871 | for (NotificationSection section : mSections) { |
| 872 | if (section.getFirstVisibleChild() == null) { |
| 873 | continue; |
| 874 | } |
| 875 | int sectionTop = section.getCurrentBounds().top + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 876 | int ownLeft = Math.min(Math.max(left, section.getCurrentBounds().left), right); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 877 | int ownRight = Math.max(Math.min(right, section.getCurrentBounds().right), ownLeft); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 878 | // If sections are directly adjacent to each other, we don't want to draw them |
| 879 | // as separate roundrects, as the rounded corners right next to each other look |
| 880 | // bad. |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 881 | if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 882 | || ((currentLeft != ownLeft || currentRight != ownRight) && !first)) { |
| 883 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 884 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 885 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 886 | lastSectionBottom, |
| 887 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 888 | backgroundRectTop = sectionTop; |
| 889 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 890 | currentLeft = ownLeft; |
| 891 | currentRight = ownRight; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 892 | lastSectionBottom = |
| 893 | section.getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 894 | first = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 895 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 896 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 897 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 898 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 899 | lastSectionBottom, |
| 900 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 901 | } |
| 902 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 903 | private void drawHeadsUpBackground(Canvas canvas) { |
| 904 | int left = mSidePaddings; |
| 905 | int right = getWidth() - mSidePaddings; |
| 906 | |
| 907 | float top = getHeight(); |
| 908 | float bottom = 0; |
| 909 | int childCount = getChildCount(); |
| 910 | for (int i = 0; i < childCount; i++) { |
| 911 | View child = getChildAt(i); |
| 912 | if (child.getVisibility() != View.GONE |
| 913 | && child instanceof ExpandableNotificationRow) { |
| 914 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 915 | if ((row.isPinned() || row.isHeadsUpAnimatingAway()) && row.getTranslation() < 0 |
| 916 | && row.getProvider().shouldShowGutsOnSnapOpen()) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 917 | top = Math.min(top, row.getTranslationY()); |
| 918 | bottom = Math.max(bottom, row.getTranslationY() + row.getActualHeight()); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | if (top < bottom) { |
| 924 | canvas.drawRoundRect( |
| 925 | left, top, right, bottom, |
| 926 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 927 | } |
| 928 | } |
| 929 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 930 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 931 | private void updateBackgroundDimming() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 932 | // No need to update the background color if it's not being drawn. |
| 933 | if (!mShouldDrawNotificationBackground) { |
| 934 | return; |
| 935 | } |
| 936 | |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 937 | // Interpolate between semi-transparent notification panel background color |
| 938 | // and white AOD separator. |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 939 | float colorInterpolation = MathUtils.smoothStep(0.4f /* start */, 1f /* end */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 940 | mLinearHideAmount); |
Felka Chang | 97bc8d5 | 2019-05-29 02:51:15 +0800 | [diff] [blame] | 941 | int color = ColorUtils.blendARGB(mBgColor, Color.WHITE, colorInterpolation); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 942 | |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 943 | if (mCachedBackgroundColor != color) { |
| 944 | mCachedBackgroundColor = color; |
| 945 | mBackgroundPaint.setColor(color); |
| 946 | invalidate(); |
| 947 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 948 | } |
| 949 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 950 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 951 | private void initView(Context context) { |
| 952 | mScroller = new OverScroller(getContext()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 953 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 954 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 955 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 956 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 957 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 958 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 959 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 960 | |
| 961 | Resources res = context.getResources(); |
| 962 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 963 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 964 | mAmbientState.reload(context); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 965 | mPaddingBetweenElements = Math.max(1, |
| 966 | res.getDimensionPixelSize(R.dimen.notification_divider_height)); |
| 967 | mIncreasedPaddingBetweenElements = |
| 968 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 969 | mMinTopOverScrollToEscape = res.getDimensionPixelSize( |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 970 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 971 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 972 | mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 973 | mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 974 | mMinInteractionHeight = res.getDimensionPixelSize( |
| 975 | R.dimen.notification_min_interaction_height); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 976 | mCornerRadius = res.getDimensionPixelSize( |
| 977 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 978 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 979 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 980 | } |
| 981 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 982 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 983 | private void notifyHeightChangeListener(ExpandableView view) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 984 | notifyHeightChangeListener(view, false /* needsAnimation */); |
| 985 | } |
| 986 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 987 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 988 | private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) { |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 989 | if (mOnHeightChangedListener != null) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 990 | mOnHeightChangedListener.onHeightChanged(view, needsAnimation); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 991 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 994 | public boolean isPulseExpanding() { |
| 995 | return mAmbientState.isPulseExpanding(); |
| 996 | } |
| 997 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 998 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 999 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1000 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1001 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 1002 | |
| 1003 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 1004 | int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2, |
| 1005 | MeasureSpec.getMode(widthMeasureSpec)); |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1006 | // Don't constrain the height of the children so we know how big they'd like to be |
| 1007 | int childHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), |
| 1008 | MeasureSpec.UNSPECIFIED); |
| 1009 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1010 | // We need to measure all children even the GONE ones, such that the heights are calculated |
| 1011 | // correctly as they are used to calculate how many we can fit on the screen. |
| 1012 | final int size = getChildCount(); |
| 1013 | for (int i = 0; i < size; i++) { |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1014 | measureChild(getChildAt(i), childWidthSpec, childHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1015 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1019 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1020 | 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] | 1021 | // we layout all our children centered on the top |
| 1022 | float centerX = getWidth() / 2.0f; |
| 1023 | for (int i = 0; i < getChildCount(); i++) { |
| 1024 | View child = getChildAt(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1025 | // We need to layout all children even the GONE ones, such that the heights are |
| 1026 | // 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] | 1027 | float width = child.getMeasuredWidth(); |
| 1028 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1029 | child.layout((int) (centerX - width / 2.0f), |
| 1030 | 0, |
| 1031 | (int) (centerX + width / 2.0f), |
| 1032 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1033 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 1034 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1035 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1036 | clampScrollPosition(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1037 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1038 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1039 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1040 | } |
| 1041 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1042 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1043 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 1044 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1045 | mNeedViewResizeAnimation = true; |
| 1046 | mNeedsAnimation = true; |
| 1047 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1050 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1051 | public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) { |
| 1052 | mAmbientState.setSpeedBumpIndex(newIndex); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1053 | mNoAmbient = noAmbient; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1054 | } |
| 1055 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1056 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1057 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1058 | public void setChildLocationsChangedListener( |
| 1059 | NotificationLogger.OnChildLocationsChangedListener listener) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1060 | mListener = listener; |
| 1061 | } |
| 1062 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1063 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1064 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1065 | public boolean isInVisibleLocation(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1066 | ExpandableNotificationRow row = entry.getRow(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1067 | ExpandableViewState childViewState = row.getViewState(); |
| 1068 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1069 | if (childViewState == null) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1070 | return false; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1071 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 1072 | if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1073 | return false; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 1074 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1075 | if (row.getVisibility() != View.VISIBLE) { |
| 1076 | return false; |
| 1077 | } |
| 1078 | return true; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1079 | } |
| 1080 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1081 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1082 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 1083 | mMaxLayoutHeight = maxLayoutHeight; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 1084 | mShelf.setMaxLayoutHeight(maxLayoutHeight); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1085 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1088 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1089 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1090 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1091 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1092 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1095 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1096 | private void updateAlgorithmLayoutMinHeight() { |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 1097 | mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition() |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1098 | ? getLayoutMinHeight() : 0); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1101 | /** |
| 1102 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 1103 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 1104 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1105 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1106 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1107 | updateScrollStateForAddedChildren(); |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 1108 | mAmbientState.setCurrentScrollVelocity(mScroller.isFinished() |
| 1109 | ? 0 |
| 1110 | : mScroller.getCurrVelocity()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1111 | if (ANCHOR_SCROLLING) { |
| 1112 | mAmbientState.setAnchorViewIndex(indexOfChild(mScrollAnchorView)); |
| 1113 | mAmbientState.setAnchorViewY(mScrollAnchorViewY); |
| 1114 | } else { |
| 1115 | mAmbientState.setScrollY(mOwnScrollY); |
| 1116 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1117 | mStackScrollAlgorithm.resetViewStates(mAmbientState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1118 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1119 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1120 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1121 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1125 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1126 | private void onPreDrawDuringAnimation() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1127 | mShelf.updateAppearance(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1128 | updateClippingToTopRoundedCorner(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1129 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 1130 | updateBackground(); |
| 1131 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1134 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1135 | private void updateClippingToTopRoundedCorner() { |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1136 | Float clipStart = (float) mTopPadding |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1137 | + mStackTranslation |
| 1138 | + mAmbientState.getExpandAnimationTopChange(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1139 | Float clipEnd = clipStart + mCornerRadius; |
| 1140 | boolean first = true; |
| 1141 | for (int i = 0; i < getChildCount(); i++) { |
| 1142 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1143 | if (child.getVisibility() == GONE) { |
| 1144 | continue; |
| 1145 | } |
| 1146 | float start = child.getTranslationY(); |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1147 | float end = start + child.getActualHeight(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1148 | boolean clip = clipStart > start && clipStart < end |
| 1149 | || clipEnd >= start && clipEnd <= end; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1150 | clip &= !(first && isScrolledToTop()); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 1151 | child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0) |
| 1152 | : ExpandableView.NO_ROUNDNESS); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1153 | first = false; |
| 1154 | } |
| 1155 | } |
| 1156 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1157 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1158 | private void updateScrollStateForAddedChildren() { |
| 1159 | if (mChildrenToAddAnimated.isEmpty()) { |
| 1160 | return; |
| 1161 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1162 | if (!ANCHOR_SCROLLING) { |
| 1163 | for (int i = 0; i < getChildCount(); i++) { |
| 1164 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1165 | if (mChildrenToAddAnimated.contains(child)) { |
| 1166 | int startingPosition = getPositionInLinearLayout(child); |
| 1167 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
| 1168 | int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements |
| 1169 | : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements; |
| 1170 | int childHeight = getIntrinsicHeight(child) + padding; |
| 1171 | if (startingPosition < mOwnScrollY) { |
| 1172 | // This child starts off screen, so let's keep it offscreen to keep the |
| 1173 | // others visible |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1174 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1175 | setOwnScrollY(mOwnScrollY + childHeight); |
| 1176 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | clampScrollPosition(); |
| 1181 | } |
| 1182 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1183 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1184 | private void updateForcedScroll() { |
| 1185 | if (mForcedScroll != null && (!mForcedScroll.hasFocus() |
| 1186 | || !mForcedScroll.isAttachedToWindow())) { |
| 1187 | mForcedScroll = null; |
| 1188 | } |
| 1189 | if (mForcedScroll != null) { |
| 1190 | ExpandableView expandableView = (ExpandableView) mForcedScroll; |
| 1191 | int positionInLinearLayout = getPositionInLinearLayout(expandableView); |
| 1192 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1193 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1194 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1195 | if (ANCHOR_SCROLLING) { |
| 1196 | // TODO |
| 1197 | } else { |
| 1198 | targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange())); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1199 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1200 | // Only apply the scroll if we're scrolling the view upwards, or the view is so |
| 1201 | // far up that it is not visible anymore. |
| 1202 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1203 | setOwnScrollY(targetScroll); |
| 1204 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1209 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1210 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 1211 | if (!mChildrenUpdateRequested) { |
| 1212 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 1213 | mChildrenUpdateRequested = true; |
| 1214 | invalidate(); |
| 1215 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1216 | } |
| 1217 | |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 1218 | /** |
| 1219 | * Returns best effort count of visible notifications. |
| 1220 | */ |
| 1221 | public int getVisibleNotificationCount() { |
| 1222 | int count = 0; |
| 1223 | for (int i = 0; i < getChildCount(); i++) { |
| 1224 | final View child = getChildAt(i); |
| 1225 | if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) { |
| 1226 | count++; |
| 1227 | } |
| 1228 | } |
| 1229 | return count; |
| 1230 | } |
| 1231 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1232 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1233 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1234 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1237 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1238 | private void clampScrollPosition() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1239 | if (ANCHOR_SCROLLING) { |
| 1240 | // TODO |
| 1241 | } else { |
| 1242 | int scrollRange = getScrollRange(); |
| 1243 | if (scrollRange < mOwnScrollY) { |
| 1244 | setOwnScrollY(scrollRange); |
| 1245 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1249 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1250 | public int getTopPadding() { |
| 1251 | return mTopPadding; |
| 1252 | } |
| 1253 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1254 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1255 | private void setTopPadding(int topPadding, boolean animate) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 1256 | if (mTopPadding != topPadding) { |
| 1257 | mTopPadding = topPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1258 | updateAlgorithmHeightAndPadding(); |
| 1259 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1260 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1261 | mTopPaddingNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1262 | mNeedsAnimation = true; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1263 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1264 | requestChildrenUpdate(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1265 | notifyHeightChangeListener(null, animate); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /** |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1270 | * Update the height of the panel. |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1271 | * |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1272 | * @param height the expanded height of the panel |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1273 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1274 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1275 | public void setExpandedHeight(float height) { |
| 1276 | mExpandedHeight = height; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1277 | setIsExpanded(height > 0); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1278 | int minExpansionHeight = getMinExpansionHeight(); |
| 1279 | if (height < minExpansionHeight) { |
| 1280 | mClipRect.left = 0; |
| 1281 | mClipRect.right = getWidth(); |
| 1282 | mClipRect.top = 0; |
| 1283 | mClipRect.bottom = (int) height; |
| 1284 | height = minExpansionHeight; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1285 | setRequestedClipBounds(mClipRect); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1286 | } else { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1287 | setRequestedClipBounds(null); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1288 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1289 | int stackHeight; |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1290 | float translationY; |
| 1291 | float appearEndPosition = getAppearEndPosition(); |
| 1292 | float appearStartPosition = getAppearStartPosition(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1293 | float appearFraction = 1.0f; |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 1294 | boolean appearing = height < appearEndPosition; |
| 1295 | mAmbientState.setAppearing(appearing); |
| 1296 | if (!appearing) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1297 | translationY = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 1298 | if (mShouldShowShelfOnly) { |
| 1299 | stackHeight = mTopPadding + mShelf.getIntrinsicHeight(); |
| 1300 | } else if (mQsExpanded) { |
| 1301 | int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding; |
| 1302 | int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight(); |
| 1303 | if (stackStartPosition <= stackEndPosition) { |
| 1304 | stackHeight = stackEndPosition; |
| 1305 | } else { |
| 1306 | stackHeight = (int) NotificationUtils.interpolate(stackStartPosition, |
| 1307 | stackEndPosition, mQsExpansionFraction); |
| 1308 | } |
| 1309 | } else { |
| 1310 | stackHeight = (int) height; |
| 1311 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1312 | } else { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1313 | appearFraction = calculateAppearFraction(height); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1314 | if (appearFraction >= 0) { |
| 1315 | translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0, |
| 1316 | appearFraction); |
| 1317 | } else { |
| 1318 | // This may happen when pushing up a heads up. We linearly push it up from the |
| 1319 | // start |
| 1320 | translationY = height - appearStartPosition + getExpandTranslationStart(); |
| 1321 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1322 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1323 | stackHeight = |
| 1324 | getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1325 | translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction); |
| 1326 | } else { |
| 1327 | stackHeight = (int) (height - translationY); |
| 1328 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1329 | } |
| 1330 | if (stackHeight != mCurrentStackHeight) { |
| 1331 | mCurrentStackHeight = stackHeight; |
| 1332 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1333 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1334 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1335 | setStackTranslation(translationY); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1336 | notifyAppearChangedListeners(); |
| 1337 | } |
| 1338 | |
| 1339 | private void notifyAppearChangedListeners() { |
| 1340 | float appear; |
| 1341 | float expandAmount; |
| 1342 | if (mKeyguardBypassController.getBypassEnabled() && onKeyguard()) { |
| 1343 | appear = calculateAppearFractionBypass(); |
| 1344 | expandAmount = getPulseHeight(); |
| 1345 | } else { |
| 1346 | appear = MathUtils.saturate(calculateAppearFraction(mExpandedHeight)); |
| 1347 | expandAmount = mExpandedHeight; |
| 1348 | } |
| 1349 | if (appear != mLastSentAppear || expandAmount != mLastSentExpandedHeight) { |
| 1350 | mLastSentAppear = appear; |
| 1351 | mLastSentExpandedHeight = expandAmount; |
| 1352 | for (int i = 0; i < mExpandedHeightListeners.size(); i++) { |
| 1353 | BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i); |
| 1354 | listener.accept(expandAmount, appear); |
| 1355 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1356 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1359 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1360 | private void setRequestedClipBounds(Rect clipRect) { |
| 1361 | mRequestedClipBounds = clipRect; |
| 1362 | updateClipping(); |
| 1363 | } |
| 1364 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1365 | /** |
| 1366 | * Return the height of the content ignoring the footer. |
| 1367 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1368 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1369 | public int getIntrinsicContentHeight() { |
| 1370 | return mIntrinsicContentHeight; |
| 1371 | } |
| 1372 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1373 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1374 | public void updateClipping() { |
| 1375 | boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode |
| 1376 | && !mHeadsUpAnimatingAway; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1377 | boolean clipToOutline = false; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1378 | if (mIsClipped != clipped) { |
| 1379 | mIsClipped = clipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1380 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1381 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 1382 | if (mAmbientState.isHiddenAtAll()) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1383 | clipToOutline = true; |
| 1384 | invalidateOutline(); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 1385 | if (isFullyHidden()) { |
| 1386 | setClipBounds(null); |
| 1387 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1388 | } else if (clipped) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1389 | setClipBounds(mRequestedClipBounds); |
| 1390 | } else { |
| 1391 | setClipBounds(null); |
| 1392 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1393 | |
| 1394 | setClipToOutline(clipToOutline); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * @return The translation at the beginning when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1399 | * Measured relative to the resting position. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1400 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1401 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1402 | private float getExpandTranslationStart() { |
Selim Cinek | 083f214 | 2018-11-06 16:32:23 -0800 | [diff] [blame] | 1403 | return -mTopPadding + getMinExpansionHeight() - mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * @return the position from where the appear transition starts when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1408 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1409 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1410 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1411 | private float getAppearStartPosition() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1412 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1413 | return mHeadsUpInset |
| 1414 | + getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1415 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1416 | return getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1420 | * @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] | 1421 | * intrinsic height, which also includes whether the notification is system expanded and |
| 1422 | * is mainly used when dragging down from a heads up notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1423 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1424 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1425 | private int getTopHeadsUpPinnedHeight() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1426 | NotificationEntry topEntry = mHeadsUpManager.getTopEntry(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1427 | if (topEntry == null) { |
| 1428 | return 0; |
| 1429 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1430 | ExpandableNotificationRow row = topEntry.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1431 | if (row.isChildInGroup()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1432 | final NotificationEntry groupSummary |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1433 | = mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 1434 | if (groupSummary != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1435 | row = groupSummary.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | return row.getPinnedHeadsUpHeight(); |
| 1439 | } |
| 1440 | |
| 1441 | /** |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1442 | * @return the position from where the appear transition ends when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1443 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1444 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1445 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1446 | private float getAppearEndPosition() { |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1447 | int appearPosition; |
Selim Cinek | 66440cf | 2017-05-26 13:48:47 -0700 | [diff] [blame] | 1448 | int notGoneChildCount = getNotGoneChildCount(); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 1449 | if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1450 | if (isHeadsUpTransition() |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 1451 | || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1452 | appearPosition = getTopHeadsUpPinnedHeight(); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1453 | } else { |
| 1454 | appearPosition = 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1455 | if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) { |
| 1456 | appearPosition += mShelf.getIntrinsicHeight(); |
| 1457 | } |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1458 | } |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1459 | } else { |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1460 | appearPosition = mEmptyShadeView.getHeight(); |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1461 | } |
| 1462 | return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1465 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1466 | private boolean isHeadsUpTransition() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1467 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 1468 | return mTrackingHeadsUp && firstVisibleSection != null |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 1469 | && firstVisibleSection.getFirstVisibleChild().isAboveShelf(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1472 | /** |
| 1473 | * @param height the height of the panel |
| 1474 | * @return the fraction of the appear animation that has been performed |
| 1475 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1476 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 1477 | public float calculateAppearFraction(float height) { |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1478 | float appearEndPosition = getAppearEndPosition(); |
| 1479 | float appearStartPosition = getAppearStartPosition(); |
| 1480 | return (height - appearStartPosition) |
| 1481 | / (appearEndPosition - appearStartPosition); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1484 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1485 | public float getStackTranslation() { |
| 1486 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1489 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1490 | private void setStackTranslation(float stackTranslation) { |
| 1491 | if (stackTranslation != mStackTranslation) { |
| 1492 | mStackTranslation = stackTranslation; |
| 1493 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1494 | requestChildrenUpdate(); |
| 1495 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1499 | * 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] | 1500 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 1501 | * |
| 1502 | * @return either the layout height or the externally defined height, whichever is smaller |
| 1503 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1504 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1505 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1506 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 1507 | } |
| 1508 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1509 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1510 | public int getFirstItemMinHeight() { |
| 1511 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1512 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1513 | } |
| 1514 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1515 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1516 | public void setQsContainer(ViewGroup qsContainer) { |
| 1517 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1518 | } |
| 1519 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1520 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1521 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1522 | if (v instanceof ExpandableNotificationRow) { |
| 1523 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1524 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1525 | } |
| 1526 | return false; |
| 1527 | } |
| 1528 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1529 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1530 | private boolean isHeadsUp(View v) { |
| 1531 | if (v instanceof ExpandableNotificationRow) { |
| 1532 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1533 | return row.isHeadsUp(); |
| 1534 | } |
| 1535 | return false; |
| 1536 | } |
| 1537 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1538 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1539 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 1540 | getLocationOnScreen(mTempInt2); |
| 1541 | float localTouchY = touchY - mTempInt2[1]; |
| 1542 | |
| 1543 | ExpandableView closestChild = null; |
| 1544 | float minDist = Float.MAX_VALUE; |
| 1545 | |
| 1546 | // find the view closest to the location, accounting for GONE views |
| 1547 | final int count = getChildCount(); |
| 1548 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 1549 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 1550 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1551 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1552 | continue; |
| 1553 | } |
| 1554 | float childTop = slidingChild.getTranslationY(); |
| 1555 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1556 | float bottom = childTop + slidingChild.getActualHeight() |
| 1557 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1558 | |
| 1559 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 1560 | if (dist < minDist) { |
| 1561 | closestChild = slidingChild; |
| 1562 | minDist = dist; |
| 1563 | } |
| 1564 | } |
| 1565 | return closestChild; |
| 1566 | } |
| 1567 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1568 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
| 1569 | private ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1570 | return getChildAtPosition(touchX, touchY, true /* requireMinHeight */); |
| 1571 | |
| 1572 | } |
| 1573 | |
| 1574 | /** |
| 1575 | * Get the child at a certain screen location. |
| 1576 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1577 | * @param touchX the x coordinate |
| 1578 | * @param touchY the y coordinate |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1579 | * @param requireMinHeight Whether a minimum height is required for a child to be returned. |
| 1580 | * @return the child at the given location. |
| 1581 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1582 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1583 | private ExpandableView getChildAtPosition(float touchX, float touchY, |
| 1584 | boolean requireMinHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1585 | // find the view under the pointer, accounting for GONE views |
| 1586 | final int count = getChildCount(); |
| 1587 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1588 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1589 | if (slidingChild.getVisibility() != VISIBLE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1590 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1591 | continue; |
| 1592 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 1593 | float childTop = slidingChild.getTranslationY(); |
| 1594 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1595 | float bottom = childTop + slidingChild.getActualHeight() |
| 1596 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 1597 | |
| 1598 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 1599 | // camera affordance). |
| 1600 | int left = 0; |
| 1601 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1602 | |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1603 | if ((bottom - top >= mMinInteractionHeight || !requireMinHeight) |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1604 | && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1605 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 1606 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1607 | NotificationEntry entry = row.getEntry(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1608 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1609 | && mHeadsUpManager.getTopEntry().getRow() != row |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1610 | && mGroupManager.getGroupSummary( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1611 | mHeadsUpManager.getTopEntry().notification) |
| 1612 | != entry) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1613 | continue; |
| 1614 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1615 | return row.getViewAtPosition(touchY - childTop); |
| 1616 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1617 | return slidingChild; |
| 1618 | } |
| 1619 | } |
| 1620 | return null; |
| 1621 | } |
| 1622 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1623 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1624 | getLocationOnScreen(mTempInt2); |
| 1625 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1628 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1629 | public void setScrollingEnabled(boolean enable) { |
| 1630 | mScrollingEnabled = enable; |
| 1631 | } |
| 1632 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1633 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1634 | public void lockScrollTo(View v) { |
| 1635 | if (mForcedScroll == v) { |
| 1636 | return; |
| 1637 | } |
| 1638 | mForcedScroll = v; |
| 1639 | scrollTo(v); |
| 1640 | } |
| 1641 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1642 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1643 | public boolean scrollTo(View v) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1644 | ExpandableView expandableView = (ExpandableView) v; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1645 | if (ANCHOR_SCROLLING) { |
| 1646 | // TODO |
| 1647 | } else { |
| 1648 | int positionInLinearLayout = getPositionInLinearLayout(v); |
| 1649 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
| 1650 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1651 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1652 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 1653 | // that it is not visible anymore. |
| 1654 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1655 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY); |
| 1656 | mDontReportNextOverScroll = true; |
| 1657 | animateScroll(); |
| 1658 | return true; |
| 1659 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1660 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1661 | return false; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1664 | /** |
| 1665 | * @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] | 1666 | * the IME. |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1667 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1668 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1669 | private int targetScrollForView(ExpandableView v, int positionInLinearLayout) { |
| 1670 | return positionInLinearLayout + v.getIntrinsicHeight() + |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 1671 | getImeInset() - getHeight() |
| 1672 | + ((!isExpanded() && isPinnedHeadsUp(v)) ? mHeadsUpInset : getTopPadding()); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1673 | } |
| 1674 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1675 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1676 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1677 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1678 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1679 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1680 | if (ANCHOR_SCROLLING) { |
| 1681 | // TODO |
| 1682 | } else { |
| 1683 | int range = getScrollRange(); |
| 1684 | if (mOwnScrollY > range) { |
| 1685 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1686 | // animating away. To work around that we'll wait until things have settled. |
| 1687 | removeCallbacks(mReclamp); |
| 1688 | postDelayed(mReclamp, 50); |
| 1689 | } else if (mForcedScroll != null) { |
| 1690 | // The scroll was requested before we got the actual inset - in case we need |
| 1691 | // to scroll up some more do so now. |
| 1692 | scrollTo(mForcedScroll); |
| 1693 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1694 | } |
| 1695 | return insets; |
| 1696 | } |
| 1697 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1698 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1699 | private Runnable mReclamp = new Runnable() { |
| 1700 | @Override |
| 1701 | public void run() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1702 | if (ANCHOR_SCROLLING) { |
| 1703 | // TODO |
| 1704 | } else { |
| 1705 | int range = getScrollRange(); |
| 1706 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1707 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1708 | mDontReportNextOverScroll = true; |
| 1709 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1710 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1711 | } |
| 1712 | }; |
| 1713 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1714 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 1715 | public void setExpandingEnabled(boolean enable) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1716 | mExpandHelper.setEnabled(enable); |
| 1717 | } |
| 1718 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1719 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1720 | private boolean isScrollingEnabled() { |
| 1721 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1722 | } |
| 1723 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1724 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1725 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1726 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1727 | } |
| 1728 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1729 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1730 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1731 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1732 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1733 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1734 | float densityScale = getResources().getDisplayMetrics().density; |
| 1735 | mSwipeHelper.setDensityScale(densityScale); |
| 1736 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1737 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1738 | initView(getContext()); |
| 1739 | } |
| 1740 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1741 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1742 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1743 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1744 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1747 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1748 | private void snapViewIfNeeded(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1749 | ExpandableNotificationRow child = entry.getRow(); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1750 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1751 | // If the child is showing the notification menu snap to that |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 1752 | if (child.getProvider() != null) { |
| 1753 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
| 1754 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
| 1755 | } |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1756 | } |
| 1757 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1758 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1759 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1760 | public ViewGroup getViewParentForNotification(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1761 | return this; |
| 1762 | } |
| 1763 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1764 | /** |
| 1765 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1766 | * |
| 1767 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1768 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1769 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1770 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1771 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1772 | private float overScrollUp(int deltaY, int range) { |
| 1773 | deltaY = Math.max(deltaY, 0); |
| 1774 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1775 | float newTopAmount = currentTopAmount - deltaY; |
| 1776 | if (currentTopAmount > 0) { |
| 1777 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1778 | false /* animate */); |
| 1779 | } |
| 1780 | // Top overScroll might not grab all scrolling motion, |
| 1781 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1782 | if (ANCHOR_SCROLLING) { |
| 1783 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1784 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1785 | ExpandableView lastRow = getLastRowNotGone(); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1786 | if (lastRow != null && !lastRow.isInShelf()) { |
| 1787 | float distanceToMax = Math.max(0, getMaxPositiveScrollAmount()); |
| 1788 | if (scrollAmount > distanceToMax) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1789 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1790 | // We overScroll on the bottom |
| 1791 | setOverScrolledPixels(currentBottomPixels + (scrollAmount - distanceToMax), |
| 1792 | false /* onTop */, |
| 1793 | false /* animate */); |
| 1794 | mScrollAnchorViewY -= distanceToMax; |
| 1795 | scrollAmount = 0f; |
| 1796 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1797 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1798 | return scrollAmount; |
| 1799 | } else { |
| 1800 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1801 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1802 | if (newScrollY > range) { |
| 1803 | if (!mExpandedInThisMotion) { |
| 1804 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1805 | // We overScroll on the bottom |
| 1806 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1807 | false /* onTop */, |
| 1808 | false /* animate */); |
| 1809 | } |
| 1810 | setOwnScrollY(range); |
| 1811 | scrollAmount = 0.0f; |
| 1812 | } |
| 1813 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1814 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | /** |
| 1818 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1819 | * |
| 1820 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1821 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1822 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1823 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1824 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1825 | private float overScrollDown(int deltaY) { |
| 1826 | deltaY = Math.min(deltaY, 0); |
| 1827 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1828 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1829 | if (currentBottomAmount > 0) { |
| 1830 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1831 | false /* animate */); |
| 1832 | } |
| 1833 | // Bottom overScroll might not grab all scrolling motion, |
| 1834 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1835 | if (ANCHOR_SCROLLING) { |
| 1836 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1837 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1838 | ExpandableView firstChild = getFirstChildNotGone(); |
| 1839 | float top = firstChild.getTranslationY(); |
| 1840 | float distanceToTop = mScrollAnchorView.getTranslationY() - top - mScrollAnchorViewY; |
| 1841 | if (distanceToTop < -scrollAmount) { |
| 1842 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1843 | // We overScroll on the top |
| 1844 | setOverScrolledPixels(currentTopPixels + (-scrollAmount - distanceToTop), |
| 1845 | true /* onTop */, |
| 1846 | false /* animate */); |
| 1847 | mScrollAnchorView = firstChild; |
| 1848 | mScrollAnchorViewY = 0; |
| 1849 | scrollAmount = 0f; |
| 1850 | } |
| 1851 | return scrollAmount; |
| 1852 | } else { |
| 1853 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1854 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1855 | if (newScrollY < 0) { |
| 1856 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1857 | // We overScroll on the top |
| 1858 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1859 | true /* onTop */, |
| 1860 | false /* animate */); |
| 1861 | setOwnScrollY(0); |
| 1862 | scrollAmount = 0.0f; |
| 1863 | } |
| 1864 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1865 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1868 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1869 | private void initVelocityTrackerIfNotExists() { |
| 1870 | if (mVelocityTracker == null) { |
| 1871 | mVelocityTracker = VelocityTracker.obtain(); |
| 1872 | } |
| 1873 | } |
| 1874 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1875 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1876 | private void recycleVelocityTracker() { |
| 1877 | if (mVelocityTracker != null) { |
| 1878 | mVelocityTracker.recycle(); |
| 1879 | mVelocityTracker = null; |
| 1880 | } |
| 1881 | } |
| 1882 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1883 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1884 | private void initOrResetVelocityTracker() { |
| 1885 | if (mVelocityTracker == null) { |
| 1886 | mVelocityTracker = VelocityTracker.obtain(); |
| 1887 | } else { |
| 1888 | mVelocityTracker.clear(); |
| 1889 | } |
| 1890 | } |
| 1891 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1892 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1893 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1894 | mFinishScrollingCallback = runnable; |
| 1895 | } |
| 1896 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1897 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1898 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1899 | if (mScroller.computeScrollOffset()) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1900 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1901 | int oldY = mLastScrollerY; |
| 1902 | int y = mScroller.getCurrY(); |
| 1903 | int deltaY = y - oldY; |
| 1904 | if (deltaY != 0) { |
| 1905 | int maxNegativeScrollAmount = getMaxNegativeScrollAmount(); |
| 1906 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 1907 | if ((maxNegativeScrollAmount < 0 && deltaY < maxNegativeScrollAmount) |
| 1908 | || (maxPositiveScrollAmount > 0 && deltaY > maxPositiveScrollAmount)) { |
| 1909 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1910 | // the current velocity |
| 1911 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1912 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1913 | customOverScrollBy(deltaY, oldY, 0, (int) mMaxOverScroll); |
| 1914 | mLastScrollerY = y; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1915 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1916 | } else { |
| 1917 | int oldY = mOwnScrollY; |
| 1918 | int y = mScroller.getCurrY(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1919 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1920 | if (oldY != y) { |
| 1921 | int range = getScrollRange(); |
| 1922 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1923 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1924 | // the current velocity |
| 1925 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1926 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1927 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1928 | if (mDontClampNextScroll) { |
| 1929 | range = Math.max(range, oldY); |
| 1930 | } |
| 1931 | customOverScrollBy(y - oldY, oldY, range, |
| 1932 | (int) (mMaxOverScroll)); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1933 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1934 | } |
| 1935 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1936 | postOnAnimation(mReflingAndAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1937 | } else { |
| 1938 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1939 | if (mFinishScrollingCallback != null) { |
| 1940 | mFinishScrollingCallback.run(); |
| 1941 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1945 | private void setMaxOverScrollFromCurrentVelocity() { |
| 1946 | float currVelocity = mScroller.getCurrVelocity(); |
| 1947 | if (currVelocity >= mMinimumVelocity) { |
| 1948 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1949 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1950 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1951 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1952 | /** |
| 1953 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 1954 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 1955 | * |
| 1956 | * This method performs the determination of whether we're exceeding the overscroll and clamps |
| 1957 | * the scroll amount if so. The actual scrolling/overscrolling happens in |
| 1958 | * {@link #onCustomOverScrolled(int, boolean)} (absolute scrolling) or |
| 1959 | * {@link #onCustomOverScrolledBy(int, boolean)} (anchor scrolling). |
| 1960 | * |
| 1961 | * @param deltaY The (signed) number of pixels to scroll. |
| 1962 | * @param scrollY The current scroll position (absolute scrolling only). |
| 1963 | * @param scrollRangeY The maximum allowable scroll position (absolute scrolling only). |
| 1964 | * @param maxOverScrollY The current (unsigned) limit on number of pixels to overscroll by. |
| 1965 | */ |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1966 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1967 | private void customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, int maxOverScrollY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1968 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1969 | boolean clampedY = false; |
| 1970 | if (deltaY < 0) { |
| 1971 | int maxScrollAmount = getMaxNegativeScrollAmount(); |
| 1972 | if (maxScrollAmount > Integer.MIN_VALUE) { |
| 1973 | maxScrollAmount -= maxOverScrollY; |
| 1974 | if (deltaY < maxScrollAmount) { |
| 1975 | deltaY = maxScrollAmount; |
| 1976 | clampedY = true; |
| 1977 | } |
| 1978 | } |
| 1979 | } else { |
| 1980 | int maxScrollAmount = getMaxPositiveScrollAmount(); |
| 1981 | if (maxScrollAmount < Integer.MAX_VALUE) { |
| 1982 | maxScrollAmount += maxOverScrollY; |
| 1983 | if (deltaY > maxScrollAmount) { |
| 1984 | deltaY = maxScrollAmount; |
| 1985 | clampedY = true; |
| 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | onCustomOverScrolledBy(deltaY, clampedY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1990 | } else { |
| 1991 | int newScrollY = scrollY + deltaY; |
| 1992 | final int top = -maxOverScrollY; |
| 1993 | final int bottom = maxOverScrollY + scrollRangeY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1994 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1995 | boolean clampedY = false; |
| 1996 | if (newScrollY > bottom) { |
| 1997 | newScrollY = bottom; |
| 1998 | clampedY = true; |
| 1999 | } else if (newScrollY < top) { |
| 2000 | newScrollY = top; |
| 2001 | clampedY = true; |
| 2002 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2003 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2004 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2005 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | /** |
| 2009 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 2010 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 2011 | * same overScroll edge. |
| 2012 | * |
| 2013 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 2014 | * the rubber-banding logic. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2015 | * @param onTop Should the effect be applied on top of the scroller. |
| 2016 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2017 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2018 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2019 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2020 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2025 | * By default this will also cancel animations on the same overScroll edge. |
| 2026 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2027 | * @param amount The amount to overScroll by. |
| 2028 | * @param onTop Should the effect be applied on top of the scroller. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2029 | * @param animate Should an animation be performed. |
| 2030 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2031 | |
| 2032 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2033 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 2034 | setOverScrollAmount(amount, onTop, animate, true); |
| 2035 | } |
| 2036 | |
| 2037 | /** |
| 2038 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2039 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2040 | * @param amount The amount to overScroll by. |
| 2041 | * @param onTop Should the effect be applied on top of the scroller. |
| 2042 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2043 | * @param cancelAnimators Should running animations be cancelled. |
| 2044 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2045 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2046 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2047 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2048 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 2049 | } |
| 2050 | |
| 2051 | /** |
| 2052 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2053 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2054 | * @param amount The amount to overScroll by. |
| 2055 | * @param onTop Should the effect be applied on top of the scroller. |
| 2056 | * @param animate Should an animation be performed. |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2057 | * @param cancelAnimators Should running animations be cancelled. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2058 | * @param isRubberbanded The value which will be passed to |
| 2059 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2060 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2061 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2062 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2063 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2064 | if (cancelAnimators) { |
| 2065 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 2066 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2067 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2068 | } |
| 2069 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2070 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2071 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 2072 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2073 | amount = Math.max(0, amount); |
| 2074 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2075 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2076 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2077 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2078 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2079 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2080 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2081 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2082 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2086 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2087 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2088 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 2089 | if (mDontReportNextOverScroll) { |
| 2090 | mDontReportNextOverScroll = false; |
| 2091 | return; |
| 2092 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2093 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2094 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2095 | } |
| 2096 | } |
| 2097 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2098 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2099 | public void setOverscrollTopChangedListener( |
| 2100 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 2101 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 2102 | } |
| 2103 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2104 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2105 | public float getCurrentOverScrollAmount(boolean top) { |
| 2106 | return mAmbientState.getOverScrollAmount(top); |
| 2107 | } |
| 2108 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2109 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2110 | public float getCurrentOverScrolledPixels(boolean top) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2111 | return top ? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2112 | } |
| 2113 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2114 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2115 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2116 | if (onTop) { |
| 2117 | mOverScrolledTopPixels = amount; |
| 2118 | } else { |
| 2119 | mOverScrolledBottomPixels = amount; |
| 2120 | } |
| 2121 | } |
| 2122 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2123 | /** |
| 2124 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 2125 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 2126 | * |
| 2127 | * @param deltaY The (signed) number of pixels to scroll. |
| 2128 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2129 | * the overscroll limit. |
| 2130 | */ |
| 2131 | private void onCustomOverScrolledBy(int deltaY, boolean clampedY) { |
| 2132 | assert ANCHOR_SCROLLING; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2133 | mScrollAnchorViewY -= deltaY; |
| 2134 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2135 | if (!mScroller.isFinished()) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2136 | if (clampedY) { |
| 2137 | springBack(); |
| 2138 | } else { |
| 2139 | float overScrollTop = getCurrentOverScrollAmount(true /* top */); |
| 2140 | if (isScrolledToTop() && mScrollAnchorViewY > 0) { |
| 2141 | notifyOverscrollTopListener(mScrollAnchorViewY, |
| 2142 | isRubberbanded(true /* onTop */)); |
| 2143 | } else { |
| 2144 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true /* onTop */)); |
| 2145 | } |
| 2146 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2147 | } |
| 2148 | updateScrollAnchor(); |
| 2149 | updateOnScrollChange(); |
| 2150 | } |
| 2151 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2152 | /** |
| 2153 | * Scrolls to the given position, overscrolling if needed. If called during a fling and the |
| 2154 | * position exceeds the provided maximum overscroll, springs back instead. |
| 2155 | * |
| 2156 | * @param scrollY The target scroll position. |
| 2157 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2158 | * the overscroll limit. |
| 2159 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2160 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2161 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2162 | assert !ANCHOR_SCROLLING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2163 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2164 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2165 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2166 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2167 | springBack(); |
| 2168 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2169 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2170 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2171 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2172 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2173 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2174 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2175 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2176 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2177 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2181 | /** |
| 2182 | * Springs back from an overscroll by stopping the {@link #mScroller} and animating the |
| 2183 | * overscroll amount back to zero. |
| 2184 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2185 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2186 | private void springBack() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2187 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2188 | boolean overScrolledTop = isScrolledToTop() && mScrollAnchorViewY > 0; |
| 2189 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 2190 | boolean overscrolledBottom = maxPositiveScrollAmount < 0; |
| 2191 | if (overScrolledTop || overscrolledBottom) { |
| 2192 | float newAmount; |
| 2193 | if (overScrolledTop) { |
| 2194 | newAmount = mScrollAnchorViewY; |
| 2195 | mScrollAnchorViewY = 0; |
| 2196 | mDontReportNextOverScroll = true; |
| 2197 | } else { |
| 2198 | newAmount = -maxPositiveScrollAmount; |
| 2199 | mScrollAnchorViewY -= maxPositiveScrollAmount; |
| 2200 | } |
| 2201 | setOverScrollAmount(newAmount, overScrolledTop, false); |
| 2202 | setOverScrollAmount(0.0f, overScrolledTop, true); |
| 2203 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2204 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2205 | } else { |
| 2206 | int scrollRange = getScrollRange(); |
| 2207 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2208 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2209 | if (overScrolledTop || overScrolledBottom) { |
| 2210 | boolean onTop; |
| 2211 | float newAmount; |
| 2212 | if (overScrolledTop) { |
| 2213 | onTop = true; |
| 2214 | newAmount = -mOwnScrollY; |
| 2215 | setOwnScrollY(0); |
| 2216 | mDontReportNextOverScroll = true; |
| 2217 | } else { |
| 2218 | onTop = false; |
| 2219 | newAmount = mOwnScrollY - scrollRange; |
| 2220 | setOwnScrollY(scrollRange); |
| 2221 | } |
| 2222 | setOverScrollAmount(newAmount, onTop, false); |
| 2223 | setOverScrollAmount(0.0f, onTop, true); |
| 2224 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2225 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2226 | } |
| 2227 | } |
| 2228 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2229 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2230 | private int getScrollRange() { |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2231 | // In current design, it only use the top HUN to treat all of HUNs |
| 2232 | // although there are more than one HUNs |
| 2233 | int contentHeight = mContentHeight; |
| 2234 | if (!isExpanded() && mHeadsUpManager.hasPinnedHeadsUp()) { |
| 2235 | contentHeight = mHeadsUpInset + getTopHeadsUpPinnedHeight(); |
| 2236 | } |
| 2237 | int scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2238 | int imeInset = getImeInset(); |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2239 | scrollRange += Math.min(imeInset, Math.max(0, contentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2240 | return scrollRange; |
| 2241 | } |
| 2242 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2243 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2244 | private int getImeInset() { |
| 2245 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2246 | } |
| 2247 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2248 | /** |
| 2249 | * @return the first child which has visibility unequal to GONE |
| 2250 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2251 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2252 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2253 | int childCount = getChildCount(); |
| 2254 | for (int i = 0; i < childCount; i++) { |
| 2255 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2256 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2257 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | return null; |
| 2261 | } |
| 2262 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2263 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2264 | * @return the child before the given view which has visibility unequal to GONE |
| 2265 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2266 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2267 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2268 | ExpandableView previousView = null; |
| 2269 | int childCount = getChildCount(); |
| 2270 | for (int i = 0; i < childCount; i++) { |
| 2271 | View child = getChildAt(i); |
| 2272 | if (child == view) { |
| 2273 | return previousView; |
| 2274 | } |
| 2275 | if (child.getVisibility() != View.GONE) { |
| 2276 | previousView = (ExpandableView) child; |
| 2277 | } |
| 2278 | } |
| 2279 | return null; |
| 2280 | } |
| 2281 | |
| 2282 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2283 | * @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] | 2284 | * given translationY or equal to it. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2285 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2286 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2287 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2288 | int childCount = getChildCount(); |
| 2289 | for (int i = 0; i < childCount; i++) { |
| 2290 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2291 | if (child.getVisibility() == View.GONE) { |
| 2292 | continue; |
| 2293 | } |
| 2294 | float rowTranslation = child.getTranslationY(); |
| 2295 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2296 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2297 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2298 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2299 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2300 | List<ExpandableNotificationRow> notificationChildren = |
| 2301 | row.getNotificationChildren(); |
| 2302 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2303 | childIndex++) { |
| 2304 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2305 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2306 | return rowChild; |
| 2307 | } |
| 2308 | } |
| 2309 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2310 | } |
| 2311 | } |
| 2312 | return null; |
| 2313 | } |
| 2314 | |
| 2315 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2316 | * @return the last child which has visibility unequal to GONE |
| 2317 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2318 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2319 | public ExpandableView getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2320 | int childCount = getChildCount(); |
| 2321 | for (int i = childCount - 1; i >= 0; i--) { |
| 2322 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2323 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2324 | return (ExpandableView) child; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | return null; |
| 2328 | } |
| 2329 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2330 | private ExpandableNotificationRow getLastRowNotGone() { |
| 2331 | int childCount = getChildCount(); |
| 2332 | for (int i = childCount - 1; i >= 0; i--) { |
| 2333 | View child = getChildAt(i); |
| 2334 | if (child instanceof ExpandableNotificationRow && child.getVisibility() != View.GONE) { |
| 2335 | return (ExpandableNotificationRow) child; |
| 2336 | } |
| 2337 | } |
| 2338 | return null; |
| 2339 | } |
| 2340 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2341 | /** |
| 2342 | * @return the number of children which have visibility unequal to GONE |
| 2343 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2344 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2345 | public int getNotGoneChildCount() { |
| 2346 | int childCount = getChildCount(); |
| 2347 | int count = 0; |
| 2348 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2349 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2350 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2351 | count++; |
| 2352 | } |
| 2353 | } |
| 2354 | return count; |
| 2355 | } |
| 2356 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2357 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2358 | private void updateContentHeight() { |
| 2359 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2360 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2361 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2362 | int numShownItems = 0; |
| 2363 | boolean finish = false; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2364 | int maxDisplayedNotifications = mMaxDisplayedNotifications; |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2365 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2366 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2367 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2368 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2369 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2370 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2371 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2372 | && numShownItems >= maxDisplayedNotifications; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2373 | if (limitReached) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2374 | expandableView = mShelf; |
| 2375 | finish = true; |
| 2376 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2377 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2378 | float padding; |
| 2379 | if (increasedPaddingAmount >= 0.0f) { |
| 2380 | padding = (int) NotificationUtils.interpolate( |
| 2381 | previousPaddingRequest, |
| 2382 | mIncreasedPaddingBetweenElements, |
| 2383 | increasedPaddingAmount); |
| 2384 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2385 | mPaddingBetweenElements, |
| 2386 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2387 | increasedPaddingAmount); |
| 2388 | } else { |
| 2389 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2390 | 0, |
| 2391 | mPaddingBetweenElements, |
| 2392 | 1.0f + increasedPaddingAmount); |
| 2393 | if (previousPaddingAmount > 0.0f) { |
| 2394 | padding = (int) NotificationUtils.interpolate( |
| 2395 | ownPadding, |
| 2396 | mIncreasedPaddingBetweenElements, |
| 2397 | previousPaddingAmount); |
| 2398 | } else { |
| 2399 | padding = ownPadding; |
| 2400 | } |
| 2401 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2402 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2403 | if (height != 0) { |
| 2404 | height += padding; |
| 2405 | } |
| 2406 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2407 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2408 | numShownItems++; |
| 2409 | if (finish) { |
| 2410 | break; |
| 2411 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2412 | } |
| 2413 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2414 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2415 | |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 2416 | // The topPadding can be bigger than the regular padding when qs is expanded, in that |
| 2417 | // state the maxPanelHeight and the contentHeight should be bigger |
| 2418 | mContentHeight = height + Math.max(mIntrinsicPadding, mTopPadding) + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2419 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2420 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2421 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2424 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2425 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2426 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2427 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2430 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2431 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2432 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2433 | if (scrollable != mScrollable) { |
| 2434 | mScrollable = scrollable; |
| 2435 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2436 | updateForwardAndBackwardScrollability(); |
| 2437 | } |
| 2438 | } |
| 2439 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2440 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2441 | private void updateForwardAndBackwardScrollability() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2442 | boolean forwardScrollable = mScrollable && !isScrolledToBottom(); |
| 2443 | boolean backwardsScrollable = mScrollable && !isScrolledToTop(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2444 | boolean changed = forwardScrollable != mForwardScrollable |
| 2445 | || backwardsScrollable != mBackwardScrollable; |
| 2446 | mForwardScrollable = forwardScrollable; |
| 2447 | mBackwardScrollable = backwardsScrollable; |
| 2448 | if (changed) { |
| 2449 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2450 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2453 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2454 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2455 | // 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] | 2456 | if (!mShouldDrawNotificationBackground) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2457 | return; |
| 2458 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2459 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2460 | updateBackgroundBounds(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2461 | if (didSectionBoundsChange()) { |
| 2462 | boolean animate = mAnimateNextSectionBoundsChange || mAnimateNextBackgroundTop |
| 2463 | || mAnimateNextBackgroundBottom || areSectionBoundsAnimating(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2464 | if (!isExpanded()) { |
| 2465 | abortBackgroundAnimators(); |
| 2466 | animate = false; |
| 2467 | } |
| 2468 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2469 | startBackgroundAnimation(); |
| 2470 | } else { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2471 | for (NotificationSection section : mSections) { |
| 2472 | section.resetCurrentBounds(); |
| 2473 | } |
Lucas Dupin | 90a38dd | 2018-09-05 09:37:37 -0700 | [diff] [blame] | 2474 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2475 | } |
| 2476 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2477 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2478 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2479 | mAnimateNextBackgroundTop = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2480 | mAnimateNextBackgroundBottom = false; |
| 2481 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2482 | } |
| 2483 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2484 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2485 | private void abortBackgroundAnimators() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2486 | for (NotificationSection section : mSections) { |
| 2487 | section.cancelAnimators(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2488 | } |
| 2489 | } |
| 2490 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2491 | private boolean didSectionBoundsChange() { |
| 2492 | for (NotificationSection section : mSections) { |
| 2493 | if (section.didBoundsChange()) { |
| 2494 | return true; |
| 2495 | } |
| 2496 | } |
| 2497 | return false; |
| 2498 | } |
| 2499 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2500 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2501 | private boolean areSectionBoundsAnimating() { |
| 2502 | for (NotificationSection section : mSections) { |
| 2503 | if (section.areBoundsAnimating()) { |
| 2504 | return true; |
| 2505 | } |
| 2506 | } |
| 2507 | return false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2508 | } |
| 2509 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2510 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2511 | private void startBackgroundAnimation() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2512 | // TODO(kprevas): do we still need separate fields for top/bottom? |
| 2513 | // or can each section manage its own animation state? |
| 2514 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2515 | NotificationSection lastVisibleSection = getLastVisibleSection(); |
| 2516 | for (NotificationSection section : mSections) { |
| 2517 | section.startBackgroundAnimation( |
| 2518 | section == firstVisibleSection |
| 2519 | ? mAnimateNextBackgroundTop |
| 2520 | : mAnimateNextSectionBoundsChange, |
| 2521 | section == lastVisibleSection |
| 2522 | ? mAnimateNextBackgroundBottom |
| 2523 | : mAnimateNextSectionBoundsChange); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2524 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | /** |
| 2528 | * Update the background bounds to the new desired bounds |
| 2529 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2530 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2531 | private void updateBackgroundBounds() { |
shawnlin | 2771672 | 2019-04-17 20:09:45 +0800 | [diff] [blame] | 2532 | int left = mSidePaddings; |
| 2533 | int right = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2534 | for (NotificationSection section : mSections) { |
| 2535 | section.getBounds().left = left; |
| 2536 | section.getBounds().right = right; |
| 2537 | } |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2538 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2539 | if (!mIsExpanded) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2540 | for (NotificationSection section : mSections) { |
| 2541 | section.getBounds().top = 0; |
| 2542 | section.getBounds().bottom = 0; |
| 2543 | } |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2544 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2545 | } |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2546 | int minTopPosition = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2547 | NotificationSection lastSection = getLastVisibleSection(); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 2548 | boolean onKeyguard = mStatusBarState == StatusBarState.KEYGUARD; |
| 2549 | if (!onKeyguard) { |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2550 | minTopPosition = (int) (mTopPadding + mStackTranslation); |
| 2551 | } else if (lastSection == null) { |
| 2552 | minTopPosition = mTopPadding; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2553 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 2554 | boolean shiftPulsingWithFirst = mHeadsUpManager.getAllEntries().count() <= 1 |
| 2555 | && (mAmbientState.isDozing() |
| 2556 | || (mKeyguardBypassController.getBypassEnabled() && onKeyguard)); |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2557 | for (NotificationSection section : mSections) { |
| 2558 | int minBottomPosition = minTopPosition; |
| 2559 | if (section == lastSection) { |
| 2560 | // 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] | 2561 | minBottomPosition = (int) (ViewState.getFinalTranslationY(mShelf) |
| 2562 | + mShelf.getIntrinsicHeight()); |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2563 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2564 | minTopPosition = section.updateBounds(minTopPosition, minBottomPosition, |
| 2565 | shiftPulsingWithFirst); |
| 2566 | shiftPulsingWithFirst = false; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2567 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2568 | } |
| 2569 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2570 | private NotificationSection getFirstVisibleSection() { |
| 2571 | for (NotificationSection section : mSections) { |
| 2572 | if (section.getFirstVisibleChild() != null) { |
| 2573 | return section; |
| 2574 | } |
| 2575 | } |
| 2576 | return null; |
| 2577 | } |
| 2578 | |
| 2579 | private NotificationSection getLastVisibleSection() { |
| 2580 | for (int i = mSections.length - 1; i >= 0; i--) { |
| 2581 | NotificationSection section = mSections[i]; |
| 2582 | if (section.getLastVisibleChild() != null) { |
| 2583 | return section; |
| 2584 | } |
| 2585 | } |
| 2586 | return null; |
| 2587 | } |
| 2588 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2589 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2590 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2591 | int childCount = getChildCount(); |
| 2592 | for (int i = childCount - 1; i >= 0; i--) { |
| 2593 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2594 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2595 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2596 | return (ActivatableNotificationView) child; |
| 2597 | } |
| 2598 | } |
| 2599 | return null; |
| 2600 | } |
| 2601 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2602 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2603 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2604 | int childCount = getChildCount(); |
| 2605 | for (int i = 0; i < childCount; i++) { |
| 2606 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2607 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2608 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2609 | return (ActivatableNotificationView) child; |
| 2610 | } |
| 2611 | } |
| 2612 | return null; |
| 2613 | } |
| 2614 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2615 | /** |
| 2616 | * Fling the scroll view |
| 2617 | * |
| 2618 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2619 | * numbers mean that the finger/cursor is moving down the screen, |
| 2620 | * which means we want to scroll towards the top. |
| 2621 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2622 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2623 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2624 | if (getChildCount() > 0) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2625 | float topAmount = getCurrentOverScrollAmount(true); |
| 2626 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2627 | if (velocityY < 0 && topAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2628 | if (ANCHOR_SCROLLING) { |
| 2629 | mScrollAnchorViewY += topAmount; |
| 2630 | } else { |
| 2631 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
| 2632 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2633 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2634 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2635 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2636 | * mOverflingDistance + topAmount; |
| 2637 | } else if (velocityY > 0 && bottomAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2638 | if (ANCHOR_SCROLLING) { |
| 2639 | mScrollAnchorViewY -= bottomAmount; |
| 2640 | } else { |
| 2641 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
| 2642 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2643 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2644 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2645 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2646 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2647 | } else { |
| 2648 | // it will be set once we reach the boundary |
| 2649 | mMaxOverScroll = 0.0f; |
| 2650 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2651 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2652 | flingScroller(velocityY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2653 | } else { |
| 2654 | int scrollRange = getScrollRange(); |
| 2655 | int minScrollY = Math.max(0, scrollRange); |
| 2656 | if (mExpandedInThisMotion) { |
| 2657 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2658 | } |
| 2659 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2660 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2661 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2662 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2663 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2664 | } |
| 2665 | } |
| 2666 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2667 | /** |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2668 | * Flings the overscroller with the given velocity (anchor-based scrolling). |
| 2669 | * |
| 2670 | * Because anchor-based scrolling can't track the current scroll position, the overscroller is |
| 2671 | * always started at startY = 0, and we interpret the positions it computes as relative to the |
| 2672 | * start of the scroll. |
| 2673 | */ |
| 2674 | private void flingScroller(int velocityY) { |
| 2675 | assert ANCHOR_SCROLLING; |
| 2676 | mIsScrollerBoundSet = false; |
| 2677 | maybeFlingScroller(velocityY, true /* always fling */); |
| 2678 | } |
| 2679 | |
| 2680 | private void maybeFlingScroller(int velocityY, boolean alwaysFling) { |
| 2681 | assert ANCHOR_SCROLLING; |
| 2682 | // Attempt to determine the maximum amount to scroll before we reach the end. |
| 2683 | // If the first view is not materialized (for an upwards scroll) or the last view is either |
| 2684 | // not materialized or is pinned to the shade (for a downwards scroll), we don't know this |
| 2685 | // amount, so we do an unbounded fling and rely on {@link #maybeReflingScroller()} to update |
| 2686 | // the scroller once we approach the start/end of the list. |
| 2687 | int minY = Integer.MIN_VALUE; |
| 2688 | int maxY = Integer.MAX_VALUE; |
| 2689 | if (velocityY < 0) { |
| 2690 | minY = getMaxNegativeScrollAmount(); |
| 2691 | if (minY > Integer.MIN_VALUE) { |
| 2692 | mIsScrollerBoundSet = true; |
| 2693 | } |
| 2694 | } else { |
| 2695 | maxY = getMaxPositiveScrollAmount(); |
| 2696 | if (maxY < Integer.MAX_VALUE) { |
| 2697 | mIsScrollerBoundSet = true; |
| 2698 | } |
| 2699 | } |
| 2700 | if (mIsScrollerBoundSet || alwaysFling) { |
| 2701 | mLastScrollerY = 0; |
| 2702 | // x velocity is set to 1 to avoid overscroller bug |
| 2703 | mScroller.fling(0, 0, 1, velocityY, 0, 0, minY, maxY, 0, |
| 2704 | mExpandedInThisMotion && !isScrolledToTop() ? 0 : Integer.MAX_VALUE / 2); |
| 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | /** |
| 2709 | * Returns the maximum number of pixels we can scroll in the positive direction (downwards) |
| 2710 | * before reaching the bottom of the list (discounting overscroll). |
| 2711 | * |
| 2712 | * If the return value is negative then we have overscrolled; this is a transient state which |
| 2713 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2714 | * the bottom overscroll amount. |
| 2715 | * |
| 2716 | * If we don't know how many pixels we have left to scroll (because the last row has not been |
| 2717 | * materialized, or it's in the shelf so it doesn't have its "natural" position), we return |
| 2718 | * {@link Integer#MAX_VALUE}. |
| 2719 | */ |
| 2720 | private int getMaxPositiveScrollAmount() { |
| 2721 | assert ANCHOR_SCROLLING; |
| 2722 | // TODO: once we're recycling we need to check the adapter position of the last child. |
| 2723 | ExpandableNotificationRow lastRow = getLastRowNotGone(); |
| 2724 | if (mScrollAnchorView != null && lastRow != null && !lastRow.isInShelf()) { |
| 2725 | // distance from bottom of last child to bottom of notifications area is: |
| 2726 | // distance from bottom of last child |
| 2727 | return (int) (lastRow.getTranslationY() + lastRow.getActualHeight() |
| 2728 | // to top of anchor view |
| 2729 | - mScrollAnchorView.getTranslationY() |
| 2730 | // plus distance from anchor view to top of notifications area |
| 2731 | + mScrollAnchorViewY |
| 2732 | // minus height of notifications area. |
| 2733 | - (mMaxLayoutHeight - getIntrinsicPadding() - mFooterView.getActualHeight())); |
| 2734 | } else { |
| 2735 | return Integer.MAX_VALUE; |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | /** |
| 2740 | * Returns the maximum number of pixels (as a negative number) we can scroll in the negative |
| 2741 | * direction (upwards) before reaching the top of the list (discounting overscroll). |
| 2742 | * |
| 2743 | * If the return value is positive then we have overscrolled; this is a transient state which |
| 2744 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2745 | * the top overscroll amount. |
| 2746 | * |
| 2747 | * If we don't know how many pixels we have left to scroll (because the first row has not been |
| 2748 | * materialized), we return {@link Integer#MIN_VALUE}. |
| 2749 | */ |
| 2750 | private int getMaxNegativeScrollAmount() { |
| 2751 | assert ANCHOR_SCROLLING; |
| 2752 | // TODO: once we're recycling we need to check the adapter position of the first child. |
| 2753 | ExpandableView firstChild = getFirstChildNotGone(); |
| 2754 | if (mScrollAnchorView != null && firstChild != null) { |
| 2755 | // distance from top of first child to top of notifications area is: |
| 2756 | // distance from top of anchor view |
| 2757 | return (int) -(mScrollAnchorView.getTranslationY() |
| 2758 | // to top of first child |
| 2759 | - firstChild.getTranslationY() |
| 2760 | // minus distance from top of anchor view to top of notifications area. |
| 2761 | - mScrollAnchorViewY); |
| 2762 | } else { |
| 2763 | return Integer.MIN_VALUE; |
| 2764 | } |
| 2765 | } |
| 2766 | |
| 2767 | /** |
| 2768 | * During a fling, if we were unable to set the bounds of the fling due to the top/bottom view |
| 2769 | * not being materialized or being pinned to the shelf, we need to check on every frame if we're |
| 2770 | * able to set the bounds. If we are, we fling the scroller again with the newly computed |
| 2771 | * bounds. |
| 2772 | */ |
| 2773 | private void maybeReflingScroller() { |
| 2774 | if (!mIsScrollerBoundSet) { |
| 2775 | // Because mScroller is a flywheel scroller, we fling with the minimum possible |
| 2776 | // velocity to establish direction, so as not to perceptibly affect the velocity. |
| 2777 | maybeFlingScroller((int) Math.signum(mScroller.getCurrVelocity()), |
| 2778 | false /* alwaysFling */); |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | /** |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2783 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2784 | * overScroll view (i.e QS). |
| 2785 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2786 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2787 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2788 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2789 | return mScrolledToTopOnFirstDown |
| 2790 | && !mExpandedInThisMotion |
| 2791 | && topOverScroll > mMinTopOverScrollToEscape |
| 2792 | && initialVelocity > 0; |
| 2793 | } |
| 2794 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2795 | /** |
| 2796 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2797 | * account. |
| 2798 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2799 | * @param qsHeight the top padding imposed by the quick settings panel |
| 2800 | * @param animate whether to animate the change |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2801 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2802 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame] | 2803 | public void updateTopPadding(float qsHeight, boolean animate) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2804 | int topPadding = (int) qsHeight; |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2805 | int minStackHeight = getLayoutMinHeight(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2806 | if (topPadding + minStackHeight > getHeight()) { |
| 2807 | mTopPaddingOverflow = topPadding + minStackHeight - getHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2808 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2809 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2810 | } |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 2811 | setTopPadding(topPadding, animate && !mKeyguardBypassController.getBypassEnabled()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2812 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2813 | } |
| 2814 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2815 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2816 | public void setMaxTopPadding(int maxTopPadding) { |
| 2817 | mMaxTopPadding = maxTopPadding; |
| 2818 | } |
| 2819 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2820 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2821 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2822 | if (isHeadsUpTransition()) { |
| 2823 | return getTopHeadsUpPinnedHeight(); |
| 2824 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2825 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2828 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2829 | public float getTopPaddingOverflow() { |
| 2830 | return mTopPaddingOverflow; |
| 2831 | } |
| 2832 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2833 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2834 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2835 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2836 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2837 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2838 | int shelfHeight = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2839 | if (getLastVisibleSection() != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2840 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2841 | } |
| 2842 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2843 | } |
| 2844 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2845 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2846 | private int clampPadding(int desiredPadding) { |
| 2847 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2848 | } |
| 2849 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2850 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2851 | private float getRubberBandFactor(boolean onTop) { |
| 2852 | if (!onTop) { |
| 2853 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2854 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2855 | if (mExpandedInThisMotion) { |
| 2856 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2857 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2858 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2859 | } else if (mScrolledToTopOnFirstDown) { |
| 2860 | return 1.0f; |
| 2861 | } |
| 2862 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2863 | } |
| 2864 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2865 | /** |
| 2866 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2867 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2868 | * overscroll view (e.g. expand QS). |
| 2869 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2870 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2871 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2872 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2873 | || !mScrolledToTopOnFirstDown; |
| 2874 | } |
| 2875 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2876 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2877 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2878 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2879 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 2880 | Assert.isMainThread(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2881 | mChildTransferInProgress = childTransferInProgress; |
| 2882 | } |
| 2883 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2884 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2885 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2886 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2887 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2888 | // we only call our internal methods if this is actually a removal and not just a |
| 2889 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2890 | if (!mChildTransferInProgress) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2891 | onViewRemovedInternal((ExpandableView) child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2895 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2896 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2897 | public void cleanUpViewStateForEntry(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 2898 | View child = entry.getRow(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 2899 | if (child == mSwipeHelper.getTranslatingParentView()) { |
| 2900 | mSwipeHelper.clearTranslatingParentView(); |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2901 | } |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2902 | } |
| 2903 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2904 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2905 | private void onViewRemovedInternal(ExpandableView child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2906 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2907 | // This is only a position change, don't do anything special |
| 2908 | return; |
| 2909 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2910 | child.setOnHeightChangedListener(null); |
| 2911 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2912 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2913 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2914 | if (!mSwipedOutViews.contains(child) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2915 | || Math.abs(child.getTranslation()) != child.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2916 | container.addTransientView(child, 0); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2917 | child.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2918 | } |
| 2919 | } else { |
| 2920 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2921 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2922 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2923 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2924 | focusNextViewIfFocused(child); |
| 2925 | } |
| 2926 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2927 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2928 | private void focusNextViewIfFocused(View view) { |
| 2929 | if (view instanceof ExpandableNotificationRow) { |
| 2930 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2931 | if (row.shouldRefocusOnDismiss()) { |
| 2932 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 2933 | if (nextView == null) { |
| 2934 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 2935 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 2936 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2937 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2938 | } |
| 2939 | if (nextView != null) { |
| 2940 | nextView.requestAccessibilityFocus(); |
| 2941 | } |
| 2942 | } |
| 2943 | } |
| 2944 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2945 | } |
| 2946 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2947 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2948 | private boolean isChildInGroup(View child) { |
| 2949 | return child instanceof ExpandableNotificationRow |
| 2950 | && mGroupManager.isChildInGroupWithSummary( |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2951 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2952 | } |
| 2953 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2954 | /** |
| 2955 | * Generate a remove animation for a child view. |
| 2956 | * |
| 2957 | * @param child The view to generate the remove animation for. |
| 2958 | * @return Whether an animation was generated. |
| 2959 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2960 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2961 | private boolean generateRemoveAnimation(ExpandableView child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2962 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2963 | mAddedHeadsUpChildren.remove(child); |
| 2964 | return false; |
| 2965 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2966 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 2967 | // An animation is already running, add it transiently |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2968 | mClearTransientViewsWhenFinished.add(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2969 | return true; |
| 2970 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2971 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2972 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2973 | // Generate Animations |
| 2974 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2975 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2976 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2977 | } else { |
| 2978 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2979 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2980 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2981 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2982 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2983 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2984 | } |
| 2985 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2986 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2987 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2988 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2991 | /** |
| 2992 | * Remove a removed child view from the heads up animations if it was just added there |
| 2993 | * |
| 2994 | * @return whether any child was removed from the list to animate |
| 2995 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2996 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2997 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 2998 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2999 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 3000 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3001 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3002 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3003 | mTmpList.add(eventPair); |
| 3004 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3005 | } |
| 3006 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3007 | if (hasAddEvent) { |
| 3008 | // This child was just added lets remove all events. |
| 3009 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3010 | ((ExpandableNotificationRow) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3011 | } |
| 3012 | mTmpList.clear(); |
| 3013 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3016 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3017 | * @param child the child to query |
| 3018 | * @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] | 3019 | * not expanded |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3020 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3021 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3022 | private boolean isChildInInvisibleGroup(View child) { |
| 3023 | if (child instanceof ExpandableNotificationRow) { |
| 3024 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 3025 | NotificationEntry groupSummary = |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3026 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 3027 | if (groupSummary != null && groupSummary.getRow() != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 3028 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3029 | } |
| 3030 | } |
| 3031 | return false; |
| 3032 | } |
| 3033 | |
| 3034 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3035 | * Updates the scroll position when a child was removed |
| 3036 | * |
| 3037 | * @param removedChild the removed child |
| 3038 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3039 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3040 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3041 | if (ANCHOR_SCROLLING) { |
| 3042 | if (removedChild == mScrollAnchorView) { |
| 3043 | ExpandableView firstChild = getFirstChildNotGone(); |
| 3044 | if (firstChild != null) { |
| 3045 | mScrollAnchorView = firstChild; |
| 3046 | } else { |
| 3047 | mScrollAnchorView = mShelf; |
| 3048 | } |
| 3049 | // Adjust anchor view Y by the distance between the old and new anchors |
| 3050 | // so that there's no visible change. |
| 3051 | mScrollAnchorViewY += |
| 3052 | mScrollAnchorView.getTranslationY() - removedChild.getTranslationY(); |
| 3053 | } |
| 3054 | updateScrollAnchor(); |
| 3055 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3056 | if (mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY > 0) { |
| 3057 | mScrollAnchorViewY = 0; |
| 3058 | } |
| 3059 | updateOnScrollChange(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3060 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3061 | int startingPosition = getPositionInLinearLayout(removedChild); |
| 3062 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 3063 | int padding; |
| 3064 | if (increasedPaddingAmount >= 0) { |
| 3065 | padding = (int) NotificationUtils.interpolate( |
| 3066 | mPaddingBetweenElements, |
| 3067 | mIncreasedPaddingBetweenElements, |
| 3068 | increasedPaddingAmount); |
| 3069 | } else { |
| 3070 | padding = (int) NotificationUtils.interpolate( |
| 3071 | 0, |
| 3072 | mPaddingBetweenElements, |
| 3073 | 1.0f + increasedPaddingAmount); |
| 3074 | } |
| 3075 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
| 3076 | int endPosition = startingPosition + childHeight; |
| 3077 | if (endPosition <= mOwnScrollY) { |
| 3078 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 3079 | // scrollPosition |
| 3080 | setOwnScrollY(mOwnScrollY - childHeight); |
| 3081 | } else if (startingPosition < mOwnScrollY) { |
| 3082 | // This child is currently being scrolled into, set the scroll position to the |
| 3083 | // start of this child |
| 3084 | setOwnScrollY(startingPosition); |
| 3085 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3086 | } |
| 3087 | } |
| 3088 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3089 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 3090 | private int getIntrinsicHeight(View view) { |
| 3091 | if (view instanceof ExpandableView) { |
| 3092 | ExpandableView expandableView = (ExpandableView) view; |
| 3093 | return expandableView.getIntrinsicHeight(); |
| 3094 | } |
| 3095 | return view.getHeight(); |
| 3096 | } |
| 3097 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3098 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3099 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3100 | ExpandableNotificationRow childInGroup = null; |
| 3101 | ExpandableNotificationRow requestedRow = null; |
| 3102 | if (isChildInGroup(requestedView)) { |
| 3103 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 3104 | // then within the parent. |
| 3105 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 3106 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 3107 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3108 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3109 | float previousPaddingRequest = mPaddingBetweenElements; |
| 3110 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3111 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3112 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3113 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 3114 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3115 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3116 | float padding; |
| 3117 | if (increasedPaddingAmount >= 0.0f) { |
| 3118 | padding = (int) NotificationUtils.interpolate( |
| 3119 | previousPaddingRequest, |
| 3120 | mIncreasedPaddingBetweenElements, |
| 3121 | increasedPaddingAmount); |
| 3122 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3123 | mPaddingBetweenElements, |
| 3124 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3125 | increasedPaddingAmount); |
| 3126 | } else { |
| 3127 | int ownPadding = (int) NotificationUtils.interpolate( |
| 3128 | 0, |
| 3129 | mPaddingBetweenElements, |
| 3130 | 1.0f + increasedPaddingAmount); |
| 3131 | if (previousPaddingAmount > 0.0f) { |
| 3132 | padding = (int) NotificationUtils.interpolate( |
| 3133 | ownPadding, |
| 3134 | mIncreasedPaddingBetweenElements, |
| 3135 | previousPaddingAmount); |
| 3136 | } else { |
| 3137 | padding = ownPadding; |
| 3138 | } |
| 3139 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3140 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3141 | if (position != 0) { |
| 3142 | position += padding; |
| 3143 | } |
| 3144 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3145 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3146 | if (child == requestedView) { |
| 3147 | if (requestedRow != null) { |
| 3148 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3149 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3150 | return position; |
| 3151 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3152 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3153 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3154 | } |
| 3155 | } |
| 3156 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3160 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3161 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3162 | super.onViewAdded(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3163 | onViewAddedInternal((ExpandableView) child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3164 | } |
| 3165 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3166 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3167 | private void updateFirstAndLastBackgroundViews() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3168 | NotificationSection firstSection = getFirstVisibleSection(); |
| 3169 | NotificationSection lastSection = getLastVisibleSection(); |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3170 | ActivatableNotificationView previousFirstChild = |
| 3171 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 3172 | ActivatableNotificationView previousLastChild = |
| 3173 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3174 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3175 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3176 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 3177 | boolean sectionViewsChanged = mSectionsManager.updateFirstAndLastViewsInSections( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3178 | mSections[0], mSections[1], firstChild, lastChild); |
| 3179 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3180 | if (mAnimationsEnabled && mIsExpanded) { |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3181 | mAnimateNextBackgroundTop = firstChild != previousFirstChild; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3182 | mAnimateNextBackgroundBottom = lastChild != previousLastChild || mAnimateBottomOnLayout; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3183 | mAnimateNextSectionBoundsChange = sectionViewsChanged; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3184 | } else { |
| 3185 | mAnimateNextBackgroundTop = false; |
| 3186 | mAnimateNextBackgroundBottom = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3187 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3188 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3189 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3190 | mRoundnessManager.updateRoundedChildren(mSections); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3191 | mAnimateBottomOnLayout = false; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3192 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3193 | } |
| 3194 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3195 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3196 | private void onViewAddedInternal(ExpandableView child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3197 | updateHideSensitiveForChild(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3198 | child.setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3199 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3200 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3201 | updateChronometerForChild(child); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 3202 | if (child instanceof ExpandableNotificationRow) { |
| 3203 | ((ExpandableNotificationRow) child).setDismissRtl(mDismissRtl); |
| 3204 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3205 | if (ANCHOR_SCROLLING) { |
| 3206 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3207 | if (child == getFirstChildNotGone() && (isScrolledToTop() || !mIsExpanded)) { |
| 3208 | // New child was added at the top while we're scrolled to the top; |
| 3209 | // make it the new anchor view so that we stay at the top. |
| 3210 | mScrollAnchorView = child; |
| 3211 | } |
| 3212 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3213 | } |
| 3214 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3215 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3216 | private void updateHideSensitiveForChild(ExpandableView child) { |
| 3217 | child.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3220 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3221 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3222 | public void notifyGroupChildRemoved(ExpandableView row, ViewGroup childrenContainer) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3223 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3224 | } |
| 3225 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3226 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3227 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3228 | public void notifyGroupChildAdded(ExpandableView row) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3229 | onViewAddedInternal(row); |
| 3230 | } |
| 3231 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3232 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3233 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3234 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3235 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3236 | if (!animationsEnabled) { |
| 3237 | mSwipedOutViews.clear(); |
| 3238 | mChildrenToRemoveAnimated.clear(); |
| 3239 | clearTemporaryViewsInGroup(this); |
| 3240 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3241 | } |
| 3242 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3243 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3244 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3245 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3246 | mShelf.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3247 | int childCount = getChildCount(); |
| 3248 | for (int i = 0; i < childCount; i++) { |
| 3249 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3250 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3251 | updateAnimationState(running, child); |
| 3252 | } |
| 3253 | } |
| 3254 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3255 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3256 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3257 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3258 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3259 | } |
| 3260 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3261 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3262 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3263 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3264 | mAmbientState.setExpandingNotification(row); |
| 3265 | requestChildrenUpdate(); |
| 3266 | } |
| 3267 | |
| 3268 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3269 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3270 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3271 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3272 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3273 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3274 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | @Override |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 3278 | public boolean containsView(View v) { |
| 3279 | return v.getParent() == this; |
| 3280 | } |
| 3281 | |
| 3282 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3283 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3284 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3285 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3286 | requestChildrenUpdate(); |
| 3287 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3288 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3289 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3290 | private void updateAnimationState(boolean running, View child) { |
| 3291 | if (child instanceof ExpandableNotificationRow) { |
| 3292 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3293 | row.setIconAnimationRunning(running); |
| 3294 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3295 | } |
| 3296 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3297 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3298 | public boolean isAddOrRemoveAnimationPending() { |
| 3299 | return mNeedsAnimation |
| 3300 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3301 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3302 | |
| 3303 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3304 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3305 | public void generateAddAnimation(ExpandableView child, boolean fromMoreCard) { |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 3306 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress && !isFullyHidden()) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3307 | // Generate Animations |
| 3308 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3309 | if (fromMoreCard) { |
| 3310 | mFromMoreCardAdditions.add(child); |
| 3311 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3312 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3313 | } |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 3314 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress |
| 3315 | && !isFullyHidden()) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3316 | mAddedHeadsUpChildren.add(child); |
| 3317 | mChildrenToAddAnimated.remove(child); |
| 3318 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3319 | } |
| 3320 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3321 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3322 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3323 | public void changeViewPosition(ExpandableView child, int newIndex) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 3324 | Assert.isMainThread(); |
| 3325 | if (mChangePositionInProgress) { |
| 3326 | throw new IllegalStateException("Reentrant call to changeViewPosition"); |
| 3327 | } |
| 3328 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3329 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3330 | |
| 3331 | if (currentIndex == -1) { |
| 3332 | boolean isTransient = false; |
| 3333 | if (child instanceof ExpandableNotificationRow |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3334 | && ((ExpandableNotificationRow) child).getTransientContainer() != null) { |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3335 | isTransient = true; |
| 3336 | } |
| 3337 | Log.e(TAG, "Attempting to re-position " |
| 3338 | + (isTransient ? "transient" : "") |
| 3339 | + " view {" |
| 3340 | + child |
| 3341 | + "}"); |
| 3342 | return; |
| 3343 | } |
| 3344 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3345 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3346 | mChangePositionInProgress = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3347 | ((ExpandableView) child).setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3348 | removeView(child); |
| 3349 | addView(child, newIndex); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3350 | ((ExpandableView) child).setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3351 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3352 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3353 | mChildrenChangingPositions.add(child); |
| 3354 | mNeedsAnimation = true; |
| 3355 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3356 | } |
| 3357 | } |
| 3358 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3359 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3360 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3361 | if (mNeedsAnimation) { |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3362 | generateAllAnimationEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3363 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3364 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3365 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3366 | setAnimationRunning(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3367 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3368 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3369 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3370 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3371 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3372 | } else { |
| 3373 | applyCurrentState(); |
| 3374 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3375 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3376 | } |
| 3377 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3378 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3379 | private void generateAllAnimationEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3380 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3381 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3382 | generateChildAdditionEvents(); |
| 3383 | generatePositionChangeEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3384 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3385 | generateActivateEvent(); |
| 3386 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3387 | generateHideSensitiveEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3388 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3389 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3390 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3391 | generateAnimateEverythingEvent(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3392 | } |
| 3393 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3394 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3395 | private void generateHeadsUpAnimationEvents() { |
| 3396 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3397 | ExpandableNotificationRow row = eventPair.first; |
| 3398 | boolean isHeadsUp = eventPair.second; |
| 3399 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3400 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3401 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3402 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3403 | type = row.wasJustClicked() |
| 3404 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3405 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3406 | if (row.isChildInGroup()) { |
| 3407 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3408 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3409 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3410 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3411 | } else { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3412 | ExpandableViewState viewState = row.getViewState(); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3413 | if (viewState == null) { |
| 3414 | // A view state was never generated for this view, so we don't need to animate |
| 3415 | // this. This may happen with notification children. |
| 3416 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3417 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3418 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3419 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3420 | // Our custom add animation |
| 3421 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3422 | } else { |
| 3423 | // Normal add animation |
| 3424 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3425 | } |
| 3426 | onBottom = !pinnedAndClosed; |
| 3427 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3428 | } |
| 3429 | AnimationEvent event = new AnimationEvent(row, type); |
| 3430 | event.headsUpFromBottom = onBottom; |
| 3431 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3432 | } |
| 3433 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3434 | mAddedHeadsUpChildren.clear(); |
| 3435 | } |
| 3436 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3437 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3438 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3439 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3440 | return false; |
| 3441 | } |
| 3442 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3445 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3446 | private void generateGroupExpansionEvent() { |
| 3447 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3448 | if (mExpandedGroupView != null) { |
| 3449 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3450 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3451 | mExpandedGroupView = null; |
| 3452 | } |
| 3453 | } |
| 3454 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3455 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3456 | private void generateViewResizeEvent() { |
| 3457 | if (mNeedViewResizeAnimation) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3458 | boolean hasDisappearAnimation = false; |
| 3459 | for (AnimationEvent animationEvent : mAnimationEvents) { |
| 3460 | final int type = animationEvent.animationType; |
| 3461 | if (type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3462 | || type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3463 | hasDisappearAnimation = true; |
| 3464 | break; |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | if (!hasDisappearAnimation) { |
| 3469 | mAnimationEvents.add( |
| 3470 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3471 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3472 | } |
| 3473 | mNeedViewResizeAnimation = false; |
| 3474 | } |
| 3475 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3476 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3477 | private void generateChildRemovalEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3478 | for (ExpandableView child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3479 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3480 | |
| 3481 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3482 | float removedTranslation = child.getTranslationY(); |
| 3483 | boolean ignoreChildren = true; |
| 3484 | if (child instanceof ExpandableNotificationRow) { |
| 3485 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3486 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3487 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3488 | ignoreChildren = false; |
| 3489 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3490 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3491 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3492 | if (!childWasSwipedOut) { |
| 3493 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3494 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3495 | |
| 3496 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3497 | // Clean up any potential transient views if the child has already been swiped |
| 3498 | // out, as we won't be animating it further (due to its height already being |
| 3499 | // clipped to 0. |
| 3500 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3501 | if (transientContainer != null) { |
| 3502 | transientContainer.removeTransientView(child); |
| 3503 | } |
| 3504 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3505 | } |
| 3506 | int animationType = childWasSwipedOut |
| 3507 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3508 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3509 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3510 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3511 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3512 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3513 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3514 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3515 | mChildrenToRemoveAnimated.clear(); |
| 3516 | } |
| 3517 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3518 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3519 | private void generatePositionChangeEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3520 | for (ExpandableView child : mChildrenChangingPositions) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3521 | mAnimationEvents.add(new AnimationEvent(child, |
| 3522 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3523 | } |
| 3524 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3525 | if (mGenerateChildOrderChangedEvent) { |
| 3526 | mAnimationEvents.add(new AnimationEvent(null, |
| 3527 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3528 | mGenerateChildOrderChangedEvent = false; |
| 3529 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3530 | } |
| 3531 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3532 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3533 | private void generateChildAdditionEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3534 | for (ExpandableView child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3535 | if (mFromMoreCardAdditions.contains(child)) { |
| 3536 | mAnimationEvents.add(new AnimationEvent(child, |
| 3537 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3538 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3539 | } else { |
| 3540 | mAnimationEvents.add(new AnimationEvent(child, |
| 3541 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3542 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3543 | } |
| 3544 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3545 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3546 | } |
| 3547 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3548 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3549 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3550 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3551 | AnimationEvent event; |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 3552 | if (mAmbientState.isDozing()) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3553 | event = new AnimationEvent(null /* view */, |
| 3554 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3555 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3556 | } else { |
| 3557 | event = new AnimationEvent(null /* view */, |
| 3558 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3559 | } |
| 3560 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3561 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3562 | mTopPaddingNeedsAnimation = false; |
| 3563 | } |
| 3564 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3565 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3566 | private void generateActivateEvent() { |
| 3567 | if (mActivateNeedsAnimation) { |
| 3568 | mAnimationEvents.add( |
| 3569 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3570 | } |
| 3571 | mActivateNeedsAnimation = false; |
| 3572 | } |
| 3573 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3574 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3575 | private void generateAnimateEverythingEvent() { |
| 3576 | if (mEverythingNeedsAnimation) { |
| 3577 | mAnimationEvents.add( |
| 3578 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3579 | } |
| 3580 | mEverythingNeedsAnimation = false; |
| 3581 | } |
| 3582 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3583 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3584 | private void generateDimmedEvent() { |
| 3585 | if (mDimmedNeedsAnimation) { |
| 3586 | mAnimationEvents.add( |
| 3587 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3588 | } |
| 3589 | mDimmedNeedsAnimation = false; |
| 3590 | } |
| 3591 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3592 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3593 | private void generateHideSensitiveEvent() { |
| 3594 | if (mHideSensitiveNeedsAnimation) { |
| 3595 | mAnimationEvents.add( |
| 3596 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3597 | } |
| 3598 | mHideSensitiveNeedsAnimation = false; |
| 3599 | } |
| 3600 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3601 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3602 | private void generateGoToFullShadeEvent() { |
| 3603 | if (mGoToFullShadeNeedsAnimation) { |
| 3604 | mAnimationEvents.add( |
| 3605 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3606 | } |
| 3607 | mGoToFullShadeNeedsAnimation = false; |
| 3608 | } |
| 3609 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3610 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
| 3611 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3612 | return new StackScrollAlgorithm(context, this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | /** |
| 3616 | * @return Whether a y coordinate is inside the content. |
| 3617 | */ |
| 3618 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 3619 | public boolean isInContentBounds(float y) { |
| 3620 | return y < getHeight() - getEmptyBottomMargin(); |
| 3621 | } |
| 3622 | |
| 3623 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3624 | public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) { |
| 3625 | mLongPressListener = listener; |
| 3626 | } |
| 3627 | |
| 3628 | @Override |
| 3629 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3630 | public boolean onTouchEvent(MotionEvent ev) { |
| 3631 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 3632 | || ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3633 | handleEmptySpaceClick(ev); |
| 3634 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3635 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3636 | if (mIsExpanded && !swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3637 | if (isCancelOrUp) { |
| 3638 | mExpandHelper.onlyObserveMovements(false); |
| 3639 | } |
| 3640 | boolean wasExpandingBefore = mExpandingNotification; |
| 3641 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
| 3642 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 3643 | && !mDisallowScrollingInThisMotion) { |
| 3644 | dispatchDownEventToScroller(ev); |
| 3645 | } |
| 3646 | } |
| 3647 | boolean scrollerWantsIt = false; |
| 3648 | if (mIsExpanded && !swipingInProgress && !mExpandingNotification |
| 3649 | && !mDisallowScrollingInThisMotion) { |
| 3650 | scrollerWantsIt = onScrollTouch(ev); |
| 3651 | } |
| 3652 | boolean horizontalSwipeWantsIt = false; |
| 3653 | if (!mIsBeingDragged |
| 3654 | && !mExpandingNotification |
| 3655 | && !mExpandedInThisMotion |
| 3656 | && !mOnlyScrollingInThisMotion |
| 3657 | && !mDisallowDismissInThisMotion) { |
| 3658 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 3659 | } |
| 3660 | |
| 3661 | // Check if we need to clear any snooze leavebehinds |
| 3662 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3663 | if (guts != null && !NotificationSwipeHelper.isTouchInView(ev, guts) |
| 3664 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 3665 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 3666 | if ((ns.isExpanded() && isCancelOrUp) |
| 3667 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 3668 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 3669 | // clear it on the next non-horizontal swipe or expand event. |
| 3670 | checkSnoozeLeavebehind(); |
| 3671 | } |
| 3672 | } |
| 3673 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3674 | mCheckForLeavebehind = true; |
| 3675 | } |
| 3676 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 3677 | } |
| 3678 | |
| 3679 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3680 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 3681 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 3682 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 3683 | onScrollTouch(downEvent); |
| 3684 | downEvent.recycle(); |
| 3685 | } |
| 3686 | |
| 3687 | @Override |
| 3688 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3689 | public boolean onGenericMotionEvent(MotionEvent event) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3690 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3691 | || mDisallowScrollingInThisMotion) { |
| 3692 | return false; |
| 3693 | } |
| 3694 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3695 | switch (event.getAction()) { |
| 3696 | case MotionEvent.ACTION_SCROLL: { |
| 3697 | if (!mIsBeingDragged) { |
| 3698 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 3699 | if (vscroll != 0) { |
| 3700 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3701 | if (ANCHOR_SCROLLING) { |
| 3702 | mScrollAnchorViewY -= delta; |
| 3703 | updateScrollAnchor(); |
| 3704 | clampScrollPosition(); |
| 3705 | updateOnScrollChange(); |
| 3706 | } else { |
| 3707 | final int range = getScrollRange(); |
| 3708 | int oldScrollY = mOwnScrollY; |
| 3709 | int newScrollY = oldScrollY - delta; |
| 3710 | if (newScrollY < 0) { |
| 3711 | newScrollY = 0; |
| 3712 | } else if (newScrollY > range) { |
| 3713 | newScrollY = range; |
| 3714 | } |
| 3715 | if (newScrollY != oldScrollY) { |
| 3716 | setOwnScrollY(newScrollY); |
| 3717 | return true; |
| 3718 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3719 | } |
| 3720 | } |
| 3721 | } |
| 3722 | } |
| 3723 | } |
| 3724 | } |
| 3725 | return super.onGenericMotionEvent(event); |
| 3726 | } |
| 3727 | |
| 3728 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3729 | private boolean onScrollTouch(MotionEvent ev) { |
| 3730 | if (!isScrollingEnabled()) { |
| 3731 | return false; |
| 3732 | } |
| 3733 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
| 3734 | return false; |
| 3735 | } |
| 3736 | mForcedScroll = null; |
| 3737 | initVelocityTrackerIfNotExists(); |
| 3738 | mVelocityTracker.addMovement(ev); |
| 3739 | |
| 3740 | final int action = ev.getAction(); |
| 3741 | |
| 3742 | switch (action & MotionEvent.ACTION_MASK) { |
| 3743 | case MotionEvent.ACTION_DOWN: { |
| 3744 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
| 3745 | return false; |
| 3746 | } |
| 3747 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3748 | setIsBeingDragged(isBeingDragged); |
| 3749 | /* |
| 3750 | * If being flinged and user touches, stop the fling. isFinished |
| 3751 | * will be false if being flinged. |
| 3752 | */ |
| 3753 | if (!mScroller.isFinished()) { |
| 3754 | mScroller.forceFinished(true); |
| 3755 | } |
| 3756 | |
| 3757 | // Remember where the motion event started |
| 3758 | mLastMotionY = (int) ev.getY(); |
| 3759 | mDownX = (int) ev.getX(); |
| 3760 | mActivePointerId = ev.getPointerId(0); |
| 3761 | break; |
| 3762 | } |
| 3763 | case MotionEvent.ACTION_MOVE: |
| 3764 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 3765 | if (activePointerIndex == -1) { |
| 3766 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 3767 | break; |
| 3768 | } |
| 3769 | |
| 3770 | final int y = (int) ev.getY(activePointerIndex); |
| 3771 | final int x = (int) ev.getX(activePointerIndex); |
| 3772 | int deltaY = mLastMotionY - y; |
| 3773 | final int xDiff = Math.abs(x - mDownX); |
| 3774 | final int yDiff = Math.abs(deltaY); |
| 3775 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
| 3776 | setIsBeingDragged(true); |
| 3777 | if (deltaY > 0) { |
| 3778 | deltaY -= mTouchSlop; |
| 3779 | } else { |
| 3780 | deltaY += mTouchSlop; |
| 3781 | } |
| 3782 | } |
| 3783 | if (mIsBeingDragged) { |
| 3784 | // Scroll to follow the motion event |
| 3785 | mLastMotionY = y; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3786 | float scrollAmount; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3787 | int range; |
| 3788 | if (ANCHOR_SCROLLING) { |
| 3789 | range = 0; // unused in the methods it's being passed to |
| 3790 | } else { |
| 3791 | range = getScrollRange(); |
| 3792 | if (mExpandedInThisMotion) { |
| 3793 | range = Math.min(range, mMaxScrollAfterExpand); |
| 3794 | } |
| 3795 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3796 | if (deltaY < 0) { |
| 3797 | scrollAmount = overScrollDown(deltaY); |
| 3798 | } else { |
| 3799 | scrollAmount = overScrollUp(deltaY, range); |
| 3800 | } |
| 3801 | |
| 3802 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 3803 | // sets the scrolling if applicable. |
| 3804 | if (scrollAmount != 0.0f) { |
| 3805 | // The scrolling motion could not be compensated with the |
| 3806 | // existing overScroll, we have to scroll the view |
| 3807 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 3808 | range, getHeight() / 2); |
| 3809 | // If we're scrolling, leavebehinds should be dismissed |
| 3810 | checkSnoozeLeavebehind(); |
| 3811 | } |
| 3812 | } |
| 3813 | break; |
| 3814 | case MotionEvent.ACTION_UP: |
| 3815 | if (mIsBeingDragged) { |
| 3816 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 3817 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 3818 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 3819 | |
| 3820 | if (shouldOverScrollFling(initialVelocity)) { |
| 3821 | onOverScrollFling(true, initialVelocity); |
| 3822 | } else { |
| 3823 | if (getChildCount() > 0) { |
| 3824 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 3825 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 3826 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 3827 | fling(-initialVelocity); |
| 3828 | } else { |
| 3829 | onOverScrollFling(false, initialVelocity); |
| 3830 | } |
| 3831 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3832 | if (ANCHOR_SCROLLING) { |
| 3833 | // TODO |
| 3834 | } else { |
| 3835 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3836 | getScrollRange())) { |
| 3837 | animateScroll(); |
| 3838 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3839 | } |
| 3840 | } |
| 3841 | } |
| 3842 | } |
| 3843 | mActivePointerId = INVALID_POINTER; |
| 3844 | endDrag(); |
| 3845 | } |
| 3846 | |
| 3847 | break; |
| 3848 | case MotionEvent.ACTION_CANCEL: |
| 3849 | if (mIsBeingDragged && getChildCount() > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3850 | if (ANCHOR_SCROLLING) { |
| 3851 | // TODO |
| 3852 | } else { |
| 3853 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3854 | getScrollRange())) { |
| 3855 | animateScroll(); |
| 3856 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3857 | } |
| 3858 | mActivePointerId = INVALID_POINTER; |
| 3859 | endDrag(); |
| 3860 | } |
| 3861 | break; |
| 3862 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 3863 | final int index = ev.getActionIndex(); |
| 3864 | mLastMotionY = (int) ev.getY(index); |
| 3865 | mDownX = (int) ev.getX(index); |
| 3866 | mActivePointerId = ev.getPointerId(index); |
| 3867 | break; |
| 3868 | } |
| 3869 | case MotionEvent.ACTION_POINTER_UP: |
| 3870 | onSecondaryPointerUp(ev); |
| 3871 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
| 3872 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
| 3873 | break; |
| 3874 | } |
| 3875 | return true; |
| 3876 | } |
| 3877 | |
| 3878 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3879 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 3880 | return ev.getY() < mQsContainer.getBottom(); |
| 3881 | } |
| 3882 | |
| 3883 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3884 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 3885 | if (mOverscrollTopChangedListener != null) { |
| 3886 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 3887 | } |
| 3888 | mDontReportNextOverScroll = true; |
| 3889 | setOverScrollAmount(0.0f, true, false); |
| 3890 | } |
| 3891 | |
| 3892 | |
| 3893 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3894 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 3895 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 3896 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 3897 | final int pointerId = ev.getPointerId(pointerIndex); |
| 3898 | if (pointerId == mActivePointerId) { |
| 3899 | // This was our active pointer going up. Choose a new |
| 3900 | // active pointer and adjust accordingly. |
| 3901 | // TODO: Make this decision more intelligent. |
| 3902 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 3903 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 3904 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 3905 | if (mVelocityTracker != null) { |
| 3906 | mVelocityTracker.clear(); |
| 3907 | } |
| 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3912 | private void endDrag() { |
| 3913 | setIsBeingDragged(false); |
| 3914 | |
| 3915 | recycleVelocityTracker(); |
| 3916 | |
| 3917 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 3918 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 3919 | } |
| 3920 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 3921 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 3922 | } |
| 3923 | } |
| 3924 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3925 | @Override |
| 3926 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3927 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 3928 | initDownStates(ev); |
| 3929 | handleEmptySpaceClick(ev); |
| 3930 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3931 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3932 | if (!swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3933 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 3934 | } |
| 3935 | boolean scrollWantsIt = false; |
| 3936 | if (!swipingInProgress && !mExpandingNotification) { |
| 3937 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 3938 | } |
| 3939 | boolean swipeWantsIt = false; |
| 3940 | if (!mIsBeingDragged |
| 3941 | && !mExpandingNotification |
| 3942 | && !mExpandedInThisMotion |
| 3943 | && !mOnlyScrollingInThisMotion |
| 3944 | && !mDisallowDismissInThisMotion) { |
| 3945 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 3946 | } |
| 3947 | // Check if we need to clear any snooze leavebehinds |
| 3948 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3949 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3950 | if (!NotificationSwipeHelper.isTouchInView(ev, guts) && isUp && !swipeWantsIt && |
| 3951 | !expandWantsIt && !scrollWantsIt) { |
| 3952 | mCheckForLeavebehind = false; |
| 3953 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 3954 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 3955 | false /* resetMenu */); |
| 3956 | } |
| 3957 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3958 | mCheckForLeavebehind = true; |
| 3959 | } |
| 3960 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 3961 | } |
| 3962 | |
| 3963 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3964 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 3965 | switch (ev.getActionMasked()) { |
| 3966 | case MotionEvent.ACTION_MOVE: |
| 3967 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 3968 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop)) { |
| 3969 | mTouchIsClick = false; |
| 3970 | } |
| 3971 | break; |
| 3972 | case MotionEvent.ACTION_UP: |
| 3973 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
| 3974 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 3975 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 3976 | } |
| 3977 | break; |
| 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3982 | private void initDownStates(MotionEvent ev) { |
| 3983 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3984 | mExpandedInThisMotion = false; |
| 3985 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
| 3986 | mDisallowScrollingInThisMotion = false; |
| 3987 | mDisallowDismissInThisMotion = false; |
| 3988 | mTouchIsClick = true; |
| 3989 | mInitialTouchX = ev.getX(); |
| 3990 | mInitialTouchY = ev.getY(); |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | @Override |
| 3995 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3996 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 3997 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 3998 | if (disallowIntercept) { |
| 3999 | cancelLongPress(); |
| 4000 | } |
| 4001 | } |
| 4002 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4003 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4004 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4005 | if (!isScrollingEnabled()) { |
| 4006 | return false; |
| 4007 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4008 | /* |
| 4009 | * This method JUST determines whether we want to intercept the motion. |
| 4010 | * If we return true, onMotionEvent will be called and we do the actual |
| 4011 | * scrolling there. |
| 4012 | */ |
| 4013 | |
| 4014 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4015 | * Shortcut the most recurring case: the user is in the dragging |
| 4016 | * state and is moving their finger. We want to intercept this |
| 4017 | * motion. |
| 4018 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4019 | final int action = ev.getAction(); |
| 4020 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 4021 | return true; |
| 4022 | } |
| 4023 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4024 | switch (action & MotionEvent.ACTION_MASK) { |
| 4025 | case MotionEvent.ACTION_MOVE: { |
| 4026 | /* |
| 4027 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 4028 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4029 | */ |
| 4030 | |
| 4031 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4032 | * Locally do absolute value. mLastMotionY is set to the y value |
| 4033 | * of the down event. |
| 4034 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4035 | final int activePointerId = mActivePointerId; |
| 4036 | if (activePointerId == INVALID_POINTER) { |
| 4037 | // If we don't have a valid id, the touch down wasn't on content. |
| 4038 | break; |
| 4039 | } |
| 4040 | |
| 4041 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 4042 | if (pointerIndex == -1) { |
| 4043 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 4044 | + " in onInterceptTouchEvent"); |
| 4045 | break; |
| 4046 | } |
| 4047 | |
| 4048 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4049 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4050 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4051 | final int xDiff = Math.abs(x - mDownX); |
| 4052 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4053 | setIsBeingDragged(true); |
| 4054 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4055 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4056 | initVelocityTrackerIfNotExists(); |
| 4057 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4058 | } |
| 4059 | break; |
| 4060 | } |
| 4061 | |
| 4062 | case MotionEvent.ACTION_DOWN: { |
| 4063 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 4064 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 4065 | if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4066 | setIsBeingDragged(false); |
| 4067 | recycleVelocityTracker(); |
| 4068 | break; |
| 4069 | } |
| 4070 | |
| 4071 | /* |
| 4072 | * Remember location of down touch. |
| 4073 | * ACTION_DOWN always refers to pointer index 0. |
| 4074 | */ |
| 4075 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4076 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4077 | mActivePointerId = ev.getPointerId(0); |
| 4078 | |
| 4079 | initOrResetVelocityTracker(); |
| 4080 | mVelocityTracker.addMovement(ev); |
| 4081 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4082 | * If being flinged and user touches the screen, initiate drag; |
| 4083 | * otherwise don't. mScroller.isFinished should be false when |
| 4084 | * being flinged. |
| 4085 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4086 | boolean isBeingDragged = !mScroller.isFinished(); |
| 4087 | setIsBeingDragged(isBeingDragged); |
| 4088 | break; |
| 4089 | } |
| 4090 | |
| 4091 | case MotionEvent.ACTION_CANCEL: |
| 4092 | case MotionEvent.ACTION_UP: |
| 4093 | /* Release the drag */ |
| 4094 | setIsBeingDragged(false); |
| 4095 | mActivePointerId = INVALID_POINTER; |
| 4096 | recycleVelocityTracker(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4097 | if (ANCHOR_SCROLLING) { |
| 4098 | // TODO |
| 4099 | } else { |
| 4100 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 4101 | animateScroll(); |
| 4102 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4103 | } |
| 4104 | break; |
| 4105 | case MotionEvent.ACTION_POINTER_UP: |
| 4106 | onSecondaryPointerUp(ev); |
| 4107 | break; |
| 4108 | } |
| 4109 | |
| 4110 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4111 | * The only time we want to intercept motion events is if we are in the |
| 4112 | * drag mode. |
| 4113 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4114 | return mIsBeingDragged; |
| 4115 | } |
| 4116 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4117 | /** |
| 4118 | * @return Whether the specified motion event is actually happening over the content. |
| 4119 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4120 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4121 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 4122 | return isInContentBounds(event.getY()); |
| 4123 | } |
| 4124 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4125 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4126 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4127 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4128 | void setIsBeingDragged(boolean isDragged) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4129 | mIsBeingDragged = isDragged; |
| 4130 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4131 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4132 | cancelLongPress(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4133 | resetExposedMenuView(true /* animate */, true /* force */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4134 | } |
| 4135 | } |
| 4136 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4137 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4138 | public void requestDisallowLongPress() { |
| 4139 | cancelLongPress(); |
| 4140 | } |
| 4141 | |
| 4142 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4143 | public void requestDisallowDismiss() { |
| 4144 | mDisallowDismissInThisMotion = true; |
| 4145 | } |
| 4146 | |
| 4147 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4148 | public void cancelLongPress() { |
| 4149 | mSwipeHelper.cancelLongPress(); |
| 4150 | } |
| 4151 | |
| 4152 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4153 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 4154 | mOnEmptySpaceClickListener = listener; |
| 4155 | } |
| 4156 | |
| 4157 | /** @hide */ |
| 4158 | @Override |
| 4159 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4160 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4161 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4162 | return true; |
| 4163 | } |
| 4164 | if (!isEnabled()) { |
| 4165 | return false; |
| 4166 | } |
| 4167 | int direction = -1; |
| 4168 | switch (action) { |
| 4169 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4170 | // fall through |
| 4171 | case android.R.id.accessibilityActionScrollDown: |
| 4172 | direction = 1; |
| 4173 | // fall through |
| 4174 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4175 | // fall through |
| 4176 | case android.R.id.accessibilityActionScrollUp: |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4177 | if (ANCHOR_SCROLLING) { |
| 4178 | // TODO |
| 4179 | } else { |
| 4180 | final int viewportHeight = |
| 4181 | getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
| 4182 | - mShelf.getIntrinsicHeight(); |
| 4183 | final int targetScrollY = Math.max(0, |
| 4184 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4185 | if (targetScrollY != mOwnScrollY) { |
| 4186 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, |
| 4187 | targetScrollY - mOwnScrollY); |
| 4188 | animateScroll(); |
| 4189 | return true; |
| 4190 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4191 | } |
| 4192 | break; |
| 4193 | } |
| 4194 | return false; |
| 4195 | } |
| 4196 | |
| 4197 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4198 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4199 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 4200 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 4201 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 4202 | View view = null; |
| 4203 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4204 | // Only close visible guts if they're not a leavebehind. |
| 4205 | view = guts; |
| 4206 | } else if (menuRow != null && menuRow.isMenuVisible() |
| 4207 | && translatingParentView != null) { |
| 4208 | // Checking menu |
| 4209 | view = translatingParentView; |
| 4210 | } |
| 4211 | if (view != null && !NotificationSwipeHelper.isTouchInView(ev, view)) { |
| 4212 | // Touch was outside visible guts / menu notification, close what's visible |
| 4213 | mNotificationGutsManager.closeAndSaveGuts(false /* removeLeavebehind */, |
| 4214 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4215 | false /* resetMenu */); |
| 4216 | resetExposedMenuView(true /* animate */, true /* force */); |
| 4217 | } |
| 4218 | } |
| 4219 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 4220 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4221 | private void setSwipingInProgress(boolean swiping) { |
| 4222 | mSwipingInProgress = swiping; |
| 4223 | if (swiping) { |
| 4224 | requestDisallowInterceptTouchEvent(true); |
| 4225 | } |
| 4226 | } |
| 4227 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4228 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4229 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4230 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4231 | super.onWindowFocusChanged(hasWindowFocus); |
| 4232 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4233 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4234 | } |
| 4235 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4236 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 4237 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4238 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 4239 | public void clearChildFocus(View child) { |
| 4240 | super.clearChildFocus(child); |
| 4241 | if (mForcedScroll == child) { |
| 4242 | mForcedScroll = null; |
| 4243 | } |
| 4244 | } |
| 4245 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4246 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4247 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4248 | public boolean isScrolledToTop() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4249 | if (ANCHOR_SCROLLING) { |
| 4250 | updateScrollAnchor(); |
| 4251 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 4252 | return mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY >= 0; |
| 4253 | } else { |
| 4254 | return mOwnScrollY == 0; |
| 4255 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4259 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4260 | public boolean isScrolledToBottom() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4261 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 4262 | return getMaxPositiveScrollAmount() <= 0; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4263 | } else { |
| 4264 | return mOwnScrollY >= getScrollRange(); |
| 4265 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4269 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4270 | public View getHostView() { |
| 4271 | return this; |
| 4272 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4273 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4274 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4275 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4276 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4277 | } |
| 4278 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4279 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4280 | public void checkSnoozeLeavebehind() { |
| 4281 | if (mCheckForLeavebehind) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 4282 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4283 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4284 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4285 | mCheckForLeavebehind = false; |
| 4286 | } |
| 4287 | } |
| 4288 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4289 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4290 | public void resetCheckSnoozeLeavebehind() { |
| 4291 | mCheckForLeavebehind = true; |
| 4292 | } |
| 4293 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4294 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4295 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4296 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4297 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4298 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4299 | } |
| 4300 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4301 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4302 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4303 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4304 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4305 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4306 | if (!mIsExpanded) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4307 | resetScrollPosition(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4308 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4309 | clearTemporaryViews(); |
| 4310 | clearUserLockedViews(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4311 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 4312 | if (draggedViews.size() > 0) { |
| 4313 | draggedViews.clear(); |
| 4314 | updateContinuousShadowDrawing(); |
| 4315 | } |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4316 | } |
| 4317 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 4318 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4319 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4320 | private void clearUserLockedViews() { |
| 4321 | for (int i = 0; i < getChildCount(); i++) { |
| 4322 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4323 | if (child instanceof ExpandableNotificationRow) { |
| 4324 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4325 | row.setUserLocked(false); |
| 4326 | } |
| 4327 | } |
| 4328 | } |
| 4329 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4330 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4331 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4332 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4333 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4334 | for (int i = 0; i < getChildCount(); i++) { |
| 4335 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4336 | if (child instanceof ExpandableNotificationRow) { |
| 4337 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4338 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4339 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4340 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4341 | } |
| 4342 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4343 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4344 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4345 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 4346 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4347 | } |
| 4348 | } |
| 4349 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4350 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4351 | public void onPanelTrackingStarted() { |
| 4352 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4353 | mAmbientState.setPanelTracking(true); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4354 | resetExposedMenuView(true /* animate */, true /* force */); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4355 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4356 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4357 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4358 | public void onPanelTrackingStopped() { |
| 4359 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4360 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4363 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4364 | public void resetScrollPosition() { |
| 4365 | mScroller.abortAnimation(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4366 | if (ANCHOR_SCROLLING) { |
| 4367 | // TODO: once we're recycling this will need to modify the adapter position instead |
| 4368 | mScrollAnchorView = getFirstChildNotGone(); |
| 4369 | mScrollAnchorViewY = 0; |
| 4370 | updateOnScrollChange(); |
| 4371 | } else { |
| 4372 | setOwnScrollY(0); |
| 4373 | } |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4374 | } |
| 4375 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4376 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4377 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4378 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4379 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4380 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4381 | mAmbientState.setShadeExpanded(isExpanded); |
| 4382 | mStateAnimator.setShadeExpanded(isExpanded); |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 4383 | mSwipeHelper.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4384 | if (changed) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4385 | if (!mIsExpanded) { |
| 4386 | mGroupManager.collapseAllGroups(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4387 | mExpandHelper.cancelImmediately(); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4388 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4389 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4390 | updateChronometers(); |
Selim Cinek | f3fa685 | 2016-12-20 18:36:02 +0100 | [diff] [blame] | 4391 | requestChildrenUpdate(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4392 | } |
| 4393 | } |
| 4394 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4395 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4396 | private void updateChronometers() { |
| 4397 | int childCount = getChildCount(); |
| 4398 | for (int i = 0; i < childCount; i++) { |
| 4399 | updateChronometerForChild(getChildAt(i)); |
| 4400 | } |
| 4401 | } |
| 4402 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4403 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4404 | private void updateChronometerForChild(View child) { |
| 4405 | if (child instanceof ExpandableNotificationRow) { |
| 4406 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4407 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4408 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4409 | } |
| 4410 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4411 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4412 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4413 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4414 | updateScrollPositionOnExpandInBottom(view); |
| 4415 | clampScrollPosition(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4416 | notifyHeightChangeListener(view, needsAnimation); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4417 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 4418 | ? (ExpandableNotificationRow) view |
| 4419 | : null; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4420 | NotificationSection firstSection = getFirstVisibleSection(); |
| 4421 | ActivatableNotificationView firstVisibleChild = |
| 4422 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 4423 | if (row != null) { |
| 4424 | if (row == firstVisibleChild |
| 4425 | || row.getNotificationParent() == firstVisibleChild) { |
| 4426 | updateAlgorithmLayoutMinHeight(); |
| 4427 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4428 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4429 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 4430 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4431 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4432 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4433 | } |
| 4434 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4435 | @Override |
| 4436 | public void onReset(ExpandableView view) { |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 4437 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4438 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4439 | } |
| 4440 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4441 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4442 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 4443 | if (view instanceof ExpandableNotificationRow && !onKeyguard()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4444 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4445 | // 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] | 4446 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4447 | if (row.isSummaryWithChildren()) { |
| 4448 | return; |
| 4449 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4450 | // We are actually expanding this view |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4451 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4452 | if (row.isChildInGroup()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4453 | endPosition += row.getNotificationParent().getTranslationY(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4454 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4455 | int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4456 | NotificationSection lastSection = getLastVisibleSection(); |
| 4457 | ActivatableNotificationView lastVisibleChild = |
| 4458 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
| 4459 | if (row != lastVisibleChild && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4460 | layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements; |
| 4461 | } |
| 4462 | if (endPosition > layoutEnd) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4463 | if (ANCHOR_SCROLLING) { |
| 4464 | mScrollAnchorViewY -= (endPosition - layoutEnd); |
| 4465 | updateScrollAnchor(); |
| 4466 | updateOnScrollChange(); |
| 4467 | } else { |
| 4468 | setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd)); |
| 4469 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4470 | mDisallowScrollingInThisMotion = true; |
| 4471 | } |
| 4472 | } |
| 4473 | } |
| 4474 | } |
| 4475 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4476 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4477 | public void setOnHeightChangedListener( |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4478 | ExpandableView.OnHeightChangedListener onHeightChangedListener) { |
| 4479 | this.mOnHeightChangedListener = onHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4480 | } |
| 4481 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4482 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4483 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4484 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 4485 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4486 | runAnimationFinishedRunnables(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4487 | clearTransient(); |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4488 | clearHeadsUpDisappearRunning(); |
| 4489 | } |
| 4490 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4491 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4492 | private void clearHeadsUpDisappearRunning() { |
| 4493 | for (int i = 0; i < getChildCount(); i++) { |
| 4494 | View view = getChildAt(i); |
| 4495 | if (view instanceof ExpandableNotificationRow) { |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4496 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4497 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4498 | if (row.isSummaryWithChildren()) { |
| 4499 | for (ExpandableNotificationRow child : row.getNotificationChildren()) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4500 | child.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4501 | } |
| 4502 | } |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4503 | } |
| 4504 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4505 | } |
| 4506 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4507 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4508 | private void clearTransient() { |
| 4509 | for (ExpandableView view : mClearTransientViewsWhenFinished) { |
| 4510 | StackStateAnimator.removeTransientView(view); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4511 | } |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4512 | mClearTransientViewsWhenFinished.clear(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4513 | } |
| 4514 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4515 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4516 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4517 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 4518 | runnable.run(); |
| 4519 | } |
| 4520 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4521 | } |
| 4522 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4523 | /** |
| 4524 | * See {@link AmbientState#setDimmed}. |
| 4525 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4526 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4527 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4528 | dimmed &= onKeyguard(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4529 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4530 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4531 | mDimmedNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4532 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4533 | animateDimmed(dimmed); |
| 4534 | } else { |
| 4535 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4536 | } |
| 4537 | requestChildrenUpdate(); |
| 4538 | } |
| 4539 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4540 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4541 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4542 | boolean isDimmed() { |
| 4543 | return mAmbientState.isDimmed(); |
| 4544 | } |
| 4545 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4546 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4547 | private void setDimAmount(float dimAmount) { |
| 4548 | mDimAmount = dimAmount; |
| 4549 | updateBackgroundDimming(); |
| 4550 | } |
| 4551 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4552 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4553 | private void animateDimmed(boolean dimmed) { |
| 4554 | if (mDimAnimator != null) { |
| 4555 | mDimAnimator.cancel(); |
| 4556 | } |
| 4557 | float target = dimmed ? 1.0f : 0.0f; |
| 4558 | if (target == mDimAmount) { |
| 4559 | return; |
| 4560 | } |
| 4561 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 4562 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 4563 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 4564 | mDimAnimator.addListener(mDimEndListener); |
| 4565 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 4566 | mDimAnimator.start(); |
| 4567 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4568 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4569 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4570 | private void setHideSensitive(boolean hideSensitive, boolean animate) { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4571 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 4572 | int childCount = getChildCount(); |
| 4573 | for (int i = 0; i < childCount; i++) { |
| 4574 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 4575 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 4576 | } |
| 4577 | mAmbientState.setHideSensitive(hideSensitive); |
| 4578 | if (animate && mAnimationsEnabled) { |
| 4579 | mHideSensitiveNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4580 | mNeedsAnimation = true; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4581 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 4582 | updateContentHeight(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4583 | requestChildrenUpdate(); |
| 4584 | } |
| 4585 | } |
| 4586 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4587 | /** |
| 4588 | * See {@link AmbientState#setActivatedChild}. |
| 4589 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4590 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4591 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4592 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4593 | if (mAnimationsEnabled) { |
| 4594 | mActivateNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4595 | mNeedsAnimation = true; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4596 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4597 | requestChildrenUpdate(); |
| 4598 | } |
| 4599 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4600 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4601 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4602 | return mAmbientState.getActivatedChild(); |
| 4603 | } |
| 4604 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4605 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4606 | private void applyCurrentState() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4607 | int numChildren = getChildCount(); |
| 4608 | for (int i = 0; i < numChildren; i++) { |
| 4609 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4610 | child.applyViewState(); |
| 4611 | } |
| 4612 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4613 | if (mListener != null) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4614 | mListener.onChildLocationsChanged(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4615 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4616 | runAnimationFinishedRunnables(); |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 4617 | setAnimationRunning(false); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4618 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4619 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 4620 | updateClippingToTopRoundedCorner(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4621 | } |
| 4622 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4623 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4624 | private void updateViewShadows() { |
| 4625 | // we need to work around an issue where the shadow would not cast between siblings when |
| 4626 | // their z difference is between 0 and 0.1 |
| 4627 | |
| 4628 | // Lefts first sort by Z difference |
| 4629 | for (int i = 0; i < getChildCount(); i++) { |
| 4630 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4631 | if (child.getVisibility() != GONE) { |
| 4632 | mTmpSortedChildren.add(child); |
| 4633 | } |
| 4634 | } |
| 4635 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 4636 | |
| 4637 | // Now lets update the shadow for the views |
| 4638 | ExpandableView previous = null; |
| 4639 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 4640 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 4641 | float translationZ = expandableView.getTranslationZ(); |
| 4642 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 4643 | float diff = otherZ - translationZ; |
| 4644 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 4645 | // There is no fake shadow to be drawn |
| 4646 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 4647 | } else { |
| 4648 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 4649 | expandableView.getTranslationY() - previous.getExtraBottomPadding(); |
| 4650 | expandableView.setFakeShadowIntensity( |
| 4651 | diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4652 | previous.getOutlineAlpha(), (int) yLocation, |
| 4653 | previous.getOutlineTranslation()); |
| 4654 | } |
| 4655 | previous = expandableView; |
| 4656 | } |
| 4657 | |
| 4658 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4659 | } |
| 4660 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4661 | /** |
| 4662 | * Update colors of "dismiss" and "empty shade" views. |
| 4663 | * |
| 4664 | * @param lightTheme True if light theme should be used. |
| 4665 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4666 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4667 | public void updateDecorViews(boolean lightTheme) { |
| 4668 | if (lightTheme == mUsingLightTheme) { |
| 4669 | return; |
| 4670 | } |
| 4671 | mUsingLightTheme = lightTheme; |
| 4672 | Context context = new ContextThemeWrapper(mContext, |
| 4673 | lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 4674 | final int textColor = Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4675 | mFooterView.setTextColor(textColor); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4676 | mEmptyShadeView.setTextColor(textColor); |
| 4677 | } |
| 4678 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4679 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4680 | public void goToFullShade(long delay) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4681 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4682 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4683 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4684 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4685 | } |
| 4686 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4687 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4688 | public void cancelExpandHelper() { |
| 4689 | mExpandHelper.cancel(); |
| 4690 | } |
| 4691 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4692 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4693 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 4694 | mIntrinsicPadding = intrinsicPadding; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 4695 | mAmbientState.setIntrinsicPadding(intrinsicPadding); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4696 | } |
| 4697 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4698 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 4699 | public int getIntrinsicPadding() { |
| 4700 | return mIntrinsicPadding; |
| 4701 | } |
| 4702 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4703 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4704 | * @return the y position of the first notification |
| 4705 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4706 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4707 | public float getNotificationsTopY() { |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4708 | return mTopPadding + getStackTranslation(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4709 | } |
| 4710 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4711 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4712 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4713 | public boolean shouldDelayChildPressedState() { |
| 4714 | return true; |
| 4715 | } |
| 4716 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4717 | /** |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4718 | * See {@link AmbientState#setDozing}. |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4719 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4720 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4721 | public void setDozing(boolean dozing, boolean animate, |
| 4722 | @Nullable PointF touchWakeUpScreenLocation) { |
| 4723 | if (mAmbientState.isDozing() == dozing) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 4724 | return; |
| 4725 | } |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4726 | mAmbientState.setDozing(dozing); |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4727 | requestChildrenUpdate(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4728 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4729 | } |
| 4730 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4731 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4732 | * Sets the current hide amount. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4733 | * |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4734 | * @param linearHideAmount The hide amount that follows linear interpoloation in the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4735 | * animation, |
| 4736 | * 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] | 4737 | * @param interpolatedHideAmount The hide amount that follows the actual interpolation of the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4738 | * animation curve. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4739 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4740 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4741 | public void setHideAmount(float linearHideAmount, float interpolatedHideAmount) { |
| 4742 | mLinearHideAmount = linearHideAmount; |
| 4743 | mInterpolatedHideAmount = interpolatedHideAmount; |
| 4744 | boolean wasFullyHidden = mAmbientState.isFullyHidden(); |
| 4745 | boolean wasHiddenAtAll = mAmbientState.isHiddenAtAll(); |
| 4746 | mAmbientState.setHideAmount(interpolatedHideAmount); |
| 4747 | boolean nowFullyHidden = mAmbientState.isFullyHidden(); |
| 4748 | boolean nowHiddenAtAll = mAmbientState.isHiddenAtAll(); |
| 4749 | if (nowFullyHidden != wasFullyHidden) { |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 4750 | updateVisibility(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4751 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4752 | if (!wasHiddenAtAll && nowHiddenAtAll) { |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4753 | resetExposedMenuView(true /* animate */, true /* animate */); |
| 4754 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4755 | if (nowFullyHidden != wasFullyHidden || wasHiddenAtAll != nowHiddenAtAll) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 4756 | invalidateOutline(); |
| 4757 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4758 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4759 | updateBackgroundDimming(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4760 | requestChildrenUpdate(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 4763 | private void updateVisibility() { |
| 4764 | boolean shouldShow = !mAmbientState.isFullyHidden() || !onKeyguard(); |
| 4765 | setVisibility(shouldShow ? View.VISIBLE : View.INVISIBLE); |
| 4766 | } |
| 4767 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4768 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4769 | public void notifyHideAnimationStart(boolean hide) { |
| 4770 | // 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] | 4771 | // interpolation issues when playing with the power button. |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 4772 | if (mInterpolatedHideAmount == 0 || mInterpolatedHideAmount == 1) { |
| 4773 | mBackgroundXFactor = hide ? 1.8f : 1.5f; |
| 4774 | mHideXInterpolator = hide |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4775 | ? Interpolators.FAST_OUT_SLOW_IN_REVERSE |
| 4776 | : Interpolators.FAST_OUT_SLOW_IN; |
| 4777 | } |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4780 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4781 | private int getNotGoneIndex(View child) { |
| 4782 | int count = getChildCount(); |
| 4783 | int notGoneIndex = 0; |
| 4784 | for (int i = 0; i < count; i++) { |
| 4785 | View v = getChildAt(i); |
| 4786 | if (child == v) { |
| 4787 | return notGoneIndex; |
| 4788 | } |
| 4789 | if (v.getVisibility() != View.GONE) { |
| 4790 | notGoneIndex++; |
| 4791 | } |
| 4792 | } |
| 4793 | return -1; |
| 4794 | } |
| 4795 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4796 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4797 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4798 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4799 | if (mFooterView != null) { |
| 4800 | index = indexOfChild(mFooterView); |
| 4801 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4802 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4803 | mFooterView = footerView; |
| 4804 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4805 | } |
| 4806 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4807 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4808 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4809 | int index = -1; |
| 4810 | if (mEmptyShadeView != null) { |
| 4811 | index = indexOfChild(mEmptyShadeView); |
| 4812 | removeView(mEmptyShadeView); |
| 4813 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4814 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4815 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4816 | } |
| 4817 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4818 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4819 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4820 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4821 | |
| 4822 | int oldTextRes = mEmptyShadeView.getTextResource(); |
| 4823 | int newTextRes = mStatusBar.areNotificationsHidden() |
| 4824 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4825 | if (oldTextRes != newTextRes) { |
| 4826 | mEmptyShadeView.setText(newTextRes); |
| 4827 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4828 | } |
| 4829 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4830 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4831 | public void updateFooterView(boolean visible, boolean showDismissView) { |
| 4832 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4833 | return; |
| 4834 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4835 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 4836 | mFooterView.setVisible(visible, animate); |
| 4837 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4838 | } |
| 4839 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4840 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4841 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 4842 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4843 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4844 | handleDismissAllClipping(); |
| 4845 | } |
| 4846 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4847 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4848 | private void handleDismissAllClipping() { |
| 4849 | final int count = getChildCount(); |
| 4850 | boolean previousChildWillBeDismissed = false; |
| 4851 | for (int i = 0; i < count; i++) { |
| 4852 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4853 | if (child.getVisibility() == GONE) { |
| 4854 | continue; |
| 4855 | } |
| 4856 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 4857 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 4858 | } else { |
| 4859 | child.setMinClipTopAmount(0); |
| 4860 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 4861 | previousChildWillBeDismissed = StackScrollAlgorithm.canChildBeDismissed(child); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4862 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 4863 | } |
| 4864 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4865 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4866 | public boolean isFooterViewNotGone() { |
| 4867 | return mFooterView != null |
| 4868 | && mFooterView.getVisibility() != View.GONE |
| 4869 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4870 | } |
| 4871 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4872 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 4873 | public boolean isFooterViewContentVisible() { |
| 4874 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4875 | } |
| 4876 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4877 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4878 | public int getFooterViewHeight() { |
| 4879 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4880 | } |
| 4881 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4882 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 4883 | public int getEmptyShadeViewHeight() { |
| 4884 | return mEmptyShadeView.getHeight(); |
| 4885 | } |
| 4886 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4887 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4888 | public float getBottomMostNotificationBottom() { |
| 4889 | final int count = getChildCount(); |
| 4890 | float max = 0; |
| 4891 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 4892 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 4893 | if (child.getVisibility() == GONE) { |
| 4894 | continue; |
| 4895 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4896 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 4897 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4898 | if (bottom > max) { |
| 4899 | max = bottom; |
| 4900 | } |
| 4901 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4902 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4903 | } |
| 4904 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4905 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4906 | public void setStatusBar(StatusBar statusBar) { |
| 4907 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 4908 | } |
| 4909 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4910 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4911 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 4912 | this.mGroupManager = groupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 4913 | mGroupManager.addOnGroupChangeListener(mOnGroupChangeListener); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4914 | } |
| 4915 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4916 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4917 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4918 | if (mIsExpanded && mAnimationsEnabled) { |
| 4919 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4920 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4921 | requestChildrenUpdate(); |
| 4922 | } |
| 4923 | } |
| 4924 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4925 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4926 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4927 | int childCount = getChildCount(); |
| 4928 | for (int i = childCount - 1; i >= 0; i--) { |
| 4929 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4930 | if (child.getVisibility() != View.GONE) { |
| 4931 | float childTop = child.getY(); |
| 4932 | if (childTop > touchY) { |
| 4933 | // we are above a notification entirely let's abort |
| 4934 | return false; |
| 4935 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4936 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 4937 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4938 | if (child == mFooterView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4939 | if (!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
| 4940 | touchY - childTop)) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4941 | // We clicked on the dismiss button |
| 4942 | return false; |
| 4943 | } |
| 4944 | } else if (child == mEmptyShadeView) { |
| 4945 | // We arrived at the empty shade view, for which we accept all clicks |
| 4946 | return true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4947 | } else if (!belowChild) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4948 | // We are on a child |
| 4949 | return false; |
| 4950 | } |
| 4951 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4952 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4953 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4954 | } |
| 4955 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4956 | /** @hide */ |
| 4957 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4958 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4959 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 4960 | super.onInitializeAccessibilityEventInternal(event); |
| 4961 | event.setScrollable(mScrollable); |
| 4962 | event.setScrollX(mScrollX); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4963 | event.setMaxScrollX(mScrollX); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4964 | if (ANCHOR_SCROLLING) { |
| 4965 | // TODO |
| 4966 | } else { |
| 4967 | event.setScrollY(mOwnScrollY); |
| 4968 | event.setMaxScrollY(getScrollRange()); |
| 4969 | } |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4973 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4974 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 4975 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4976 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4977 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4978 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4979 | info.addAction( |
| 4980 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 4981 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 4982 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4983 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4984 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 4985 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 4986 | } |
| 4987 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 4988 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 4989 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4992 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4993 | public void generateChildOrderChangedEvent() { |
| 4994 | if (mIsExpanded && mAnimationsEnabled) { |
| 4995 | mGenerateChildOrderChangedEvent = true; |
| 4996 | mNeedsAnimation = true; |
| 4997 | requestChildrenUpdate(); |
| 4998 | } |
| 4999 | } |
| 5000 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5001 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5002 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5003 | public int getContainerChildCount() { |
| 5004 | return getChildCount(); |
| 5005 | } |
| 5006 | |
| 5007 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5008 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5009 | public View getContainerChildAt(int i) { |
| 5010 | return getChildAt(i); |
| 5011 | } |
| 5012 | |
| 5013 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5014 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5015 | public void removeContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5016 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5017 | removeView(v); |
| 5018 | } |
| 5019 | |
| 5020 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5021 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5022 | public void addContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5023 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5024 | addView(v); |
| 5025 | } |
| 5026 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5027 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 5028 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5029 | mAnimationFinishedRunnables.add(runnable); |
| 5030 | } |
| 5031 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 5032 | public void generateHeadsUpAnimation(NotificationEntry entry, boolean isHeadsUp) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 5033 | ExpandableNotificationRow row = entry.getHeadsUpAnimationView(); |
| 5034 | generateHeadsUpAnimation(row, isHeadsUp); |
| 5035 | } |
| 5036 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5037 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5038 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5039 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5040 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 5041 | mNeedsAnimation = true; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5042 | if (!mIsExpanded && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5043 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5044 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5045 | requestChildrenUpdate(); |
| 5046 | } |
| 5047 | } |
| 5048 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5049 | /** |
| 5050 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 5051 | * position. |
| 5052 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5053 | * @param height the height of the screen |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5054 | * @param bottomBarHeight the height of the bar on the bottom |
| 5055 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5056 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5057 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 5058 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 5059 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5060 | requestChildrenUpdate(); |
| 5061 | } |
| 5062 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5063 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5064 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 5065 | mTrackingHeadsUp = row != null; |
| 5066 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5067 | } |
| 5068 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5069 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5070 | public void setScrimController(ScrimController scrimController) { |
| 5071 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 5072 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5073 | } |
| 5074 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5075 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5076 | public void forceNoOverlappingRendering(boolean force) { |
| 5077 | mForceNoOverlappingRendering = force; |
| 5078 | } |
| 5079 | |
| 5080 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5081 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5082 | public boolean hasOverlappingRendering() { |
| 5083 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 5084 | } |
| 5085 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5086 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5087 | public void setAnimationRunning(boolean animationRunning) { |
| 5088 | if (animationRunning != mAnimationRunning) { |
| 5089 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5090 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5091 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5092 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5093 | } |
| 5094 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5095 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5096 | } |
| 5097 | } |
| 5098 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5099 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 5100 | public boolean isExpanded() { |
| 5101 | return mIsExpanded; |
| 5102 | } |
| 5103 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5104 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5105 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5106 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 5107 | return; |
| 5108 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5109 | mPulsing = pulsing; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 5110 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 5111 | mSwipeHelper.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5112 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 5113 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 5114 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 5115 | requestChildrenUpdate(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5116 | notifyHeightChangeListener(null, animated); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5117 | } |
| 5118 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5119 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5120 | public void setQsExpanded(boolean qsExpanded) { |
| 5121 | mQsExpanded = qsExpanded; |
| 5122 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 5123 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5124 | } |
| 5125 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5126 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5127 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 5128 | mQsExpansionFraction = qsExpansionFraction; |
| 5129 | } |
| 5130 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5131 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5132 | private void setOwnScrollY(int ownScrollY) { |
| 5133 | assert !ANCHOR_SCROLLING; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5134 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 5135 | // We still want to call the normal scrolled changed for accessibility reasons |
| 5136 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5137 | mOwnScrollY = ownScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5138 | updateOnScrollChange(); |
| 5139 | } |
| 5140 | } |
| 5141 | |
| 5142 | private void updateOnScrollChange() { |
| 5143 | updateForwardAndBackwardScrollability(); |
| 5144 | requestChildrenUpdate(); |
| 5145 | } |
| 5146 | |
| 5147 | private void updateScrollAnchor() { |
| 5148 | int anchorIndex = indexOfChild(mScrollAnchorView); |
| 5149 | // If the anchor view has been scrolled off the top, move to the next view. |
| 5150 | while (mScrollAnchorViewY < 0) { |
| 5151 | View nextAnchor = null; |
| 5152 | for (int i = anchorIndex + 1; i < getChildCount(); i++) { |
| 5153 | View child = getChildAt(i); |
| 5154 | if (child.getVisibility() != View.GONE |
| 5155 | && child instanceof ExpandableNotificationRow) { |
| 5156 | anchorIndex = i; |
| 5157 | nextAnchor = child; |
| 5158 | break; |
| 5159 | } |
| 5160 | } |
| 5161 | if (nextAnchor == null) { |
| 5162 | break; |
| 5163 | } |
| 5164 | mScrollAnchorViewY += |
| 5165 | (int) (nextAnchor.getTranslationY() - mScrollAnchorView.getTranslationY()); |
| 5166 | mScrollAnchorView = nextAnchor; |
| 5167 | } |
| 5168 | // If the view above the anchor view is fully visible, make it the anchor view. |
| 5169 | while (anchorIndex > 0 && mScrollAnchorViewY > 0) { |
| 5170 | View prevAnchor = null; |
| 5171 | for (int i = anchorIndex - 1; i >= 0; i--) { |
| 5172 | View child = getChildAt(i); |
| 5173 | if (child.getVisibility() != View.GONE |
| 5174 | && child instanceof ExpandableNotificationRow) { |
| 5175 | anchorIndex = i; |
| 5176 | prevAnchor = child; |
| 5177 | break; |
| 5178 | } |
| 5179 | } |
| 5180 | if (prevAnchor == null) { |
| 5181 | break; |
| 5182 | } |
| 5183 | float distanceToPreviousAnchor = |
| 5184 | mScrollAnchorView.getTranslationY() - prevAnchor.getTranslationY(); |
| 5185 | if (distanceToPreviousAnchor < mScrollAnchorViewY) { |
| 5186 | mScrollAnchorViewY -= (int) distanceToPreviousAnchor; |
| 5187 | mScrollAnchorView = prevAnchor; |
| 5188 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5189 | } |
| 5190 | } |
| 5191 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5192 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5193 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5194 | int index = -1; |
| 5195 | if (mShelf != null) { |
| 5196 | index = indexOfChild(mShelf); |
| 5197 | removeView(mShelf); |
| 5198 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 5199 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5200 | addView(mShelf, index); |
| 5201 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 5202 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5203 | shelf.bind(mAmbientState, this); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5204 | if (ANCHOR_SCROLLING) { |
| 5205 | mScrollAnchorView = mShelf; |
| 5206 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5207 | } |
| 5208 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5209 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5210 | public NotificationShelf getNotificationShelf() { |
| 5211 | return mShelf; |
| 5212 | } |
| 5213 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5214 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 5215 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 5216 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 5217 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 5218 | updateContentHeight(); |
| 5219 | notifyHeightChangeListener(mShelf); |
| 5220 | } |
| 5221 | } |
| 5222 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5223 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5224 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5225 | mShouldShowShelfOnly = shouldShowShelfOnly; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5226 | updateAlgorithmLayoutMinHeight(); |
| 5227 | } |
| 5228 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5229 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5230 | public int getMinExpansionHeight() { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 5231 | return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5232 | } |
| 5233 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5234 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5235 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 5236 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 5237 | updateClipping(); |
| 5238 | } |
| 5239 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5240 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5241 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 5242 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 5243 | updateClipping(); |
| 5244 | } |
| 5245 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5246 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5247 | @VisibleForTesting |
| 5248 | protected void setStatusBarState(int statusBarState) { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5249 | mStatusBarState = statusBarState; |
| 5250 | mAmbientState.setStatusBarState(statusBarState); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | private void onStatePostChange() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5254 | boolean onKeyguard = onKeyguard(); |
| 5255 | boolean publicMode = mLockscreenUserManager.isAnyProfilePublicMode(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5256 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5257 | if (mHeadsUpAppearanceController != null) { |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 5258 | mHeadsUpAppearanceController.onStateChanged(); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5259 | } |
| 5260 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 5261 | SysuiStatusBarStateController state = (SysuiStatusBarStateController) |
| 5262 | Dependency.get(StatusBarStateController.class); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5263 | setHideSensitive(publicMode, state.goingToFullShade() /* animate */); |
| 5264 | setDimmed(onKeyguard, state.fromShadeLocked() /* animate */); |
| 5265 | setExpandingEnabled(!onKeyguard); |
| 5266 | ActivatableNotificationView activatedChild = getActivatedChild(); |
| 5267 | setActivatedChild(null); |
| 5268 | if (activatedChild != null) { |
| 5269 | activatedChild.makeInactive(false /* animate */); |
| 5270 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5271 | updateFooter(); |
Dave Mankoff | 5744580 | 2018-10-10 14:47:34 -0400 | [diff] [blame] | 5272 | requestChildrenUpdate(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5273 | onUpdateRowStates(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5274 | |
| 5275 | mEntryManager.updateNotifications(); |
Selim Cinek | d09ec7e | 2019-06-26 11:34:57 -0700 | [diff] [blame] | 5276 | updateVisibility(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5277 | } |
| 5278 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5279 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 5280 | public void setExpandingVelocity(float expandingVelocity) { |
| 5281 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 5282 | } |
| 5283 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5284 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5285 | public float getOpeningHeight() { |
| 5286 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 5287 | return getMinExpansionHeight(); |
| 5288 | } else { |
| 5289 | return getAppearEndPosition(); |
| 5290 | } |
| 5291 | } |
| 5292 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5293 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5294 | public void setIsFullWidth(boolean isFullWidth) { |
| 5295 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 5296 | } |
| 5297 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5298 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 5299 | public void setUnlockHintRunning(boolean running) { |
| 5300 | mAmbientState.setUnlockHintRunning(running); |
| 5301 | } |
| 5302 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5303 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5304 | public void setQsCustomizerShowing(boolean isShowing) { |
| 5305 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 5306 | requestChildrenUpdate(); |
| 5307 | } |
| 5308 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5309 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5310 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 5311 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 5312 | } |
| 5313 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5314 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5315 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 5316 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5317 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 5318 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5319 | this.getClass().getSimpleName(), |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5320 | mPulsing ? "T" : "f", |
| 5321 | mAmbientState.isQsCustomizerShowing() ? "T" : "f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5322 | getVisibility() == View.VISIBLE ? "visible" |
| 5323 | : getVisibility() == View.GONE ? "gone" |
| 5324 | : "invisible", |
| 5325 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5326 | mAmbientState.getScrollY(), |
| 5327 | mMaxTopPadding, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5328 | mShouldShowShelfOnly ? "T" : "f", |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5329 | mQsExpansionFraction)); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5330 | int childCount = getChildCount(); |
| 5331 | pw.println(" Number of children: " + childCount); |
| 5332 | pw.println(); |
| 5333 | |
| 5334 | for (int i = 0; i < childCount; i++) { |
| 5335 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5336 | child.dump(fd, pw, args); |
| 5337 | if (!(child instanceof ExpandableNotificationRow)) { |
| 5338 | pw.println(" " + child.getClass().getSimpleName()); |
| 5339 | // 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] | 5340 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5341 | if (viewState == null) { |
| 5342 | pw.println(" no viewState!!!"); |
| 5343 | } else { |
| 5344 | pw.print(" "); |
| 5345 | viewState.dump(fd, pw, args); |
| 5346 | pw.println(); |
| 5347 | pw.println(); |
| 5348 | } |
| 5349 | } |
| 5350 | } |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5351 | int transientViewCount = getTransientViewCount(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5352 | pw.println(" Transient Views: " + transientViewCount); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5353 | for (int i = 0; i < transientViewCount; i++) { |
| 5354 | ExpandableView child = (ExpandableView) getTransientView(i); |
| 5355 | child.dump(fd, pw, args); |
| 5356 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5357 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5358 | int draggedCount = draggedViews.size(); |
| 5359 | pw.println(" Dragged Views: " + draggedCount); |
| 5360 | for (int i = 0; i < draggedCount; i++) { |
| 5361 | ExpandableView child = (ExpandableView) draggedViews.get(i); |
| 5362 | child.dump(fd, pw, args); |
| 5363 | } |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5364 | } |
| 5365 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5366 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 5367 | public boolean isFullyHidden() { |
| 5368 | return mAmbientState.isFullyHidden(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 5369 | } |
| 5370 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 5371 | /** |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5372 | * Add a listener whenever the expanded height changes. The first value passed as an |
| 5373 | * argument is the expanded height and the second one is the appearFraction. |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5374 | * |
| 5375 | * @param listener the listener to notify. |
| 5376 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5377 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5378 | public void addOnExpandedHeightChangedListener(BiConsumer<Float, Float> listener) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5379 | mExpandedHeightListeners.add(listener); |
| 5380 | } |
| 5381 | |
| 5382 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5383 | * Stop a listener from listening to the expandedHeight. |
| 5384 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5385 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5386 | public void removeOnExpandedHeightChangedListener(BiConsumer<Float, Float> listener) { |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5387 | mExpandedHeightListeners.remove(listener); |
| 5388 | } |
| 5389 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5390 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 5391 | public void setHeadsUpAppearanceController( |
| 5392 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 5393 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 5394 | } |
| 5395 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5396 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 5397 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 5398 | mIconAreaController = controller; |
| 5399 | } |
| 5400 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5401 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5402 | public void manageNotifications(View v) { |
| 5403 | Intent intent = new Intent(Settings.ACTION_ALL_APPS_NOTIFICATION_SETTINGS); |
| 5404 | mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 5405 | } |
| 5406 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5407 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5408 | private void clearNotifications( |
| 5409 | @SelectedRows int selection, |
| 5410 | boolean closeShade) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5411 | // animate-swipe all dismissable notifications, then animate the shade closed |
| 5412 | int numChildren = getChildCount(); |
| 5413 | |
| 5414 | final ArrayList<View> viewsToHide = new ArrayList<>(numChildren); |
| 5415 | final ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>(numChildren); |
| 5416 | for (int i = 0; i < numChildren; i++) { |
| 5417 | final View child = getChildAt(i); |
| 5418 | if (child instanceof ExpandableNotificationRow) { |
| 5419 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 5420 | boolean parentVisible = false; |
| 5421 | boolean hasClipBounds = child.getClipBounds(mTmpRect); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5422 | if (includeChildInDismissAll(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5423 | viewsToRemove.add(row); |
| 5424 | if (child.getVisibility() == View.VISIBLE |
| 5425 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5426 | viewsToHide.add(child); |
| 5427 | parentVisible = true; |
| 5428 | } |
| 5429 | } else if (child.getVisibility() == View.VISIBLE |
| 5430 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5431 | parentVisible = true; |
| 5432 | } |
| 5433 | List<ExpandableNotificationRow> children = row.getNotificationChildren(); |
| 5434 | if (children != null) { |
| 5435 | for (ExpandableNotificationRow childRow : children) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5436 | if (includeChildInDismissAll(row, selection)) { |
| 5437 | viewsToRemove.add(childRow); |
| 5438 | if (parentVisible && row.areChildrenExpanded()) { |
| 5439 | hasClipBounds = childRow.getClipBounds(mTmpRect); |
| 5440 | if (childRow.getVisibility() == View.VISIBLE |
| 5441 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5442 | viewsToHide.add(childRow); |
| 5443 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5444 | } |
| 5445 | } |
| 5446 | } |
| 5447 | } |
| 5448 | } |
| 5449 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5450 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5451 | if (viewsToRemove.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5452 | if (closeShade) { |
| 5453 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5454 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5455 | return; |
| 5456 | } |
| 5457 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5458 | performDismissAllAnimations(viewsToHide, closeShade, () -> { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5459 | for (ExpandableNotificationRow rowToRemove : viewsToRemove) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5460 | if (StackScrollAlgorithm.canChildBeDismissed(rowToRemove)) { |
| 5461 | if (selection == ROWS_ALL) { |
| 5462 | // TODO: This is a listener method; we shouldn't be calling it. Can we just |
| 5463 | // call performRemoveNotification as below? |
| 5464 | mEntryManager.removeNotification( |
| 5465 | rowToRemove.getEntry().key, |
| 5466 | null /* ranking */, |
| 5467 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5468 | } else { |
| 5469 | mEntryManager.performRemoveNotification( |
| 5470 | rowToRemove.getEntry().notification, |
| 5471 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5472 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5473 | } else { |
| 5474 | rowToRemove.resetTranslation(); |
| 5475 | } |
| 5476 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5477 | if (selection == ROWS_ALL) { |
| 5478 | try { |
| 5479 | mBarService.onClearAllNotifications(mLockscreenUserManager.getCurrentUserId()); |
| 5480 | } catch (Exception ex) { |
| 5481 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5482 | } |
| 5483 | }); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5484 | } |
| 5485 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5486 | private boolean includeChildInDismissAll( |
| 5487 | ExpandableNotificationRow row, |
| 5488 | @SelectedRows int selection) { |
| 5489 | return StackScrollAlgorithm.canChildBeDismissed(row) && matchesSelection(row, selection); |
| 5490 | } |
| 5491 | |
| 5492 | /** |
| 5493 | * Given a list of rows, animates them away in a staggered fashion as if they were dismissed. |
| 5494 | * Doesn't actually dismiss them, though -- that must be done in the onAnimationComplete |
| 5495 | * handler. |
| 5496 | * |
| 5497 | * @param hideAnimatedList List of rows to animated away. Should only be views that are |
| 5498 | * currently visible, or else the stagger will look funky. |
| 5499 | * @param closeShade Whether to close the shade after the stagger animation completes. |
| 5500 | * @param onAnimationComplete Called after the entire animation completes (including the shade |
| 5501 | * closing if appropriate). The rows must be dismissed for real here. |
| 5502 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5503 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5504 | private void performDismissAllAnimations( |
| 5505 | final ArrayList<View> hideAnimatedList, |
| 5506 | final boolean closeShade, |
| 5507 | final Runnable onAnimationComplete) { |
| 5508 | |
| 5509 | final Runnable onSlideAwayAnimationComplete = () -> { |
| 5510 | if (closeShade) { |
| 5511 | mShadeController.addPostCollapseAction(() -> { |
| 5512 | setDismissAllInProgress(false); |
| 5513 | onAnimationComplete.run(); |
| 5514 | }); |
| 5515 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5516 | } else { |
| 5517 | setDismissAllInProgress(false); |
| 5518 | onAnimationComplete.run(); |
| 5519 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5520 | }; |
| 5521 | |
| 5522 | if (hideAnimatedList.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5523 | onSlideAwayAnimationComplete.run(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5524 | return; |
| 5525 | } |
| 5526 | |
| 5527 | // let's disable our normal animations |
| 5528 | setDismissAllInProgress(true); |
| 5529 | |
| 5530 | // Decrease the delay for every row we animate to give the sense of |
| 5531 | // accelerating the swipes |
| 5532 | int rowDelayDecrement = 10; |
| 5533 | int currentDelay = 140; |
| 5534 | int totalDelay = 180; |
| 5535 | int numItems = hideAnimatedList.size(); |
| 5536 | for (int i = numItems - 1; i >= 0; i--) { |
| 5537 | View view = hideAnimatedList.get(i); |
| 5538 | Runnable endRunnable = null; |
| 5539 | if (i == 0) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5540 | endRunnable = onSlideAwayAnimationComplete; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5541 | } |
Lucas Dupin | fb8bdbb | 2018-12-02 15:09:37 -0800 | [diff] [blame] | 5542 | dismissViewAnimated(view, endRunnable, totalDelay, ANIMATION_DURATION_SWIPE); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5543 | currentDelay = Math.max(50, currentDelay - rowDelayDecrement); |
| 5544 | totalDelay += currentDelay; |
| 5545 | } |
| 5546 | } |
| 5547 | |
| 5548 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5549 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5550 | protected void inflateFooterView() { |
| 5551 | FooterView footerView = (FooterView) LayoutInflater.from(mContext).inflate( |
| 5552 | R.layout.status_bar_notification_footer, this, false); |
| 5553 | footerView.setDismissButtonClickListener(v -> { |
| 5554 | mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5555 | clearNotifications(ROWS_ALL, true /* closeShade */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5556 | }); |
| 5557 | footerView.setManageButtonClickListener(this::manageNotifications); |
| 5558 | setFooterView(footerView); |
| 5559 | } |
| 5560 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5561 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5562 | private void inflateEmptyShadeView() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5563 | EmptyShadeView view = (EmptyShadeView) LayoutInflater.from(mContext).inflate( |
| 5564 | R.layout.status_bar_no_notifications, this, false); |
| 5565 | view.setText(R.string.empty_shade_text); |
| 5566 | setEmptyShadeView(view); |
| 5567 | } |
| 5568 | |
| 5569 | /** |
| 5570 | * Updates expanded, dimmed and locked states of notification rows. |
| 5571 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5572 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5573 | public void onUpdateRowStates() { |
| 5574 | changeViewPosition(mFooterView, -1); |
| 5575 | |
| 5576 | // The following views will be moved to the end of mStackScroller. This counter represents |
| 5577 | // the offset from the last child. Initialized to 1 for the very last position. It is post- |
| 5578 | // incremented in the following "changeViewPosition" calls so that its value is correct for |
| 5579 | // subsequent calls. |
| 5580 | int offsetFromEnd = 1; |
| 5581 | changeViewPosition(mEmptyShadeView, |
| 5582 | getChildCount() - offsetFromEnd++); |
| 5583 | |
| 5584 | // No post-increment for this call because it is the last one. Make sure to add one if |
| 5585 | // another "changeViewPosition" call is ever added. |
| 5586 | changeViewPosition(mShelf, |
| 5587 | getChildCount() - offsetFromEnd); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5588 | } |
| 5589 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5590 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5591 | public void setNotificationPanel(NotificationPanelView notificationPanelView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5592 | mNotificationPanel = notificationPanelView; |
| 5593 | } |
| 5594 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5595 | public void updateIconAreaViews() { |
| 5596 | mIconAreaController.updateNotificationIcons(); |
| 5597 | } |
| 5598 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5599 | /** |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5600 | * Set how far the wake up is when waking up from pulsing. This is a height and will adjust the |
| 5601 | * notification positions accordingly. |
| 5602 | * @param height the new wake up height |
| 5603 | * @return the overflow how much the height is further than he lowest notification |
| 5604 | */ |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 5605 | public float setPulseHeight(float height) { |
| 5606 | mAmbientState.setPulseHeight(height); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5607 | if (mKeyguardBypassController.getBypassEnabled()) { |
| 5608 | notifyAppearChangedListeners(); |
| 5609 | } |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5610 | requestChildrenUpdate(); |
| 5611 | return Math.max(0, height - mAmbientState.getInnerHeight(true /* ignorePulseHeight */)); |
| 5612 | } |
| 5613 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5614 | public float getPulseHeight() { |
| 5615 | return mAmbientState.getPulseHeight(); |
| 5616 | } |
| 5617 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5618 | /** |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 5619 | * 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] | 5620 | * the notification is pulsing. |
| 5621 | */ |
| 5622 | public void setDozeAmount(float dozeAmount) { |
| 5623 | mAmbientState.setDozeAmount(dozeAmount); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5624 | updateContinuousBackgroundDrawing(); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5625 | requestChildrenUpdate(); |
| 5626 | } |
| 5627 | |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5628 | public void wakeUpFromPulse() { |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5629 | setPulseHeight(getWakeUpHeight()); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5630 | // Let's place the hidden views at the end of the pulsing notification to make sure we have |
| 5631 | // a smooth animation |
| 5632 | boolean firstVisibleView = true; |
| 5633 | float wakeUplocation = -1f; |
| 5634 | int childCount = getChildCount(); |
| 5635 | for (int i = 0; i < childCount; i++) { |
| 5636 | ExpandableView view = (ExpandableView) getChildAt(i); |
| 5637 | if (view.getVisibility() == View.GONE) { |
| 5638 | continue; |
| 5639 | } |
| 5640 | boolean isShelf = view == mShelf; |
| 5641 | if (!(view instanceof ExpandableNotificationRow) && !isShelf) { |
| 5642 | continue; |
| 5643 | } |
| 5644 | if (view.getVisibility() == View.VISIBLE && !isShelf) { |
| 5645 | if (firstVisibleView) { |
| 5646 | firstVisibleView = false; |
| 5647 | wakeUplocation = view.getTranslationY() |
| 5648 | + view.getActualHeight() - mShelf.getIntrinsicHeight(); |
| 5649 | } |
| 5650 | } else if (!firstVisibleView) { |
| 5651 | view.setTranslationY(wakeUplocation); |
| 5652 | } |
| 5653 | } |
Selim Cinek | f434a74 | 2019-05-28 17:39:49 -0700 | [diff] [blame] | 5654 | mDimmedNeedsAnimation = true; |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5655 | } |
| 5656 | |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5657 | @Override |
| 5658 | public void onDynamicPrivacyChanged() { |
| 5659 | if (mIsExpanded) { |
| 5660 | // The bottom might change because we're using the final actual height of the view |
| 5661 | mAnimateBottomOnLayout = true; |
| 5662 | } |
| 5663 | } |
| 5664 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 5665 | public void setOnPulseHeightChangedListener(Runnable listener) { |
| 5666 | mAmbientState.setOnPulseHeightChangedListener(listener); |
| 5667 | } |
| 5668 | |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 5669 | public float calculateAppearFractionBypass() { |
| 5670 | float pulseHeight = getPulseHeight(); |
| 5671 | float wakeUpHeight = getWakeUpHeight(); |
| 5672 | float dragDownAmount = pulseHeight - wakeUpHeight; |
| 5673 | |
| 5674 | // The total distance required to fully reveal the header |
| 5675 | float totalDistance = getIntrinsicPadding(); |
| 5676 | return MathUtils.smoothStep(0, totalDistance, dragDownAmount); |
| 5677 | } |
| 5678 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5679 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5680 | * A listener that is notified when the empty space below the notifications is clicked on |
| 5681 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5682 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5683 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 5684 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5688 | * A listener that gets notified when the overscroll at the top has changed. |
| 5689 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5690 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5691 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 5692 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5693 | /** |
| 5694 | * Notifies a listener that the overscroll has changed. |
| 5695 | * |
| 5696 | * @param amount the amount of overscroll, in pixels |
| 5697 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 5698 | * unrubberbanded motion to directly expand overscroll view (e.g |
| 5699 | * expand |
| 5700 | * QS) |
| 5701 | */ |
| 5702 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 5703 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5704 | /** |
| 5705 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 5706 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 5707 | * |
| 5708 | * @param velocity The velocity that the Scroller had when over flinging |
| 5709 | * @param open Should the fling open or close the overscroll view. |
| 5710 | */ |
| 5711 | void flingTopOverscroll(float velocity, boolean open); |
| 5712 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5713 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5714 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5715 | public boolean hasActiveNotifications() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5716 | return !mEntryManager.getNotificationData().getActiveNotifications().isEmpty(); |
| 5717 | } |
| 5718 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 5719 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5720 | public void updateSpeedBumpIndex() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5721 | int speedBumpIndex = 0; |
| 5722 | int currentIndex = 0; |
| 5723 | final int N = getChildCount(); |
| 5724 | for (int i = 0; i < N; i++) { |
| 5725 | View view = getChildAt(i); |
| 5726 | if (view.getVisibility() == View.GONE || !(view instanceof ExpandableNotificationRow)) { |
| 5727 | continue; |
| 5728 | } |
| 5729 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 5730 | currentIndex++; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5731 | boolean beforeSpeedBump; |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5732 | if (mHighPriorityBeforeSpeedBump) { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 5733 | beforeSpeedBump = row.getEntry().isHighPriority(); |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5734 | } else { |
| 5735 | beforeSpeedBump = !row.getEntry().ambient; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5736 | } |
| 5737 | if (beforeSpeedBump) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5738 | speedBumpIndex = currentIndex; |
| 5739 | } |
| 5740 | } |
| 5741 | boolean noAmbient = speedBumpIndex == N; |
| 5742 | updateSpeedBumpIndex(speedBumpIndex, noAmbient); |
| 5743 | } |
| 5744 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5745 | /** Updates the indices of the boundaries between sections. */ |
| 5746 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 5747 | public void updateSectionBoundaries() { |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 5748 | mSectionsManager.updateSectionBoundaries(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5749 | } |
| 5750 | |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5751 | private void updateContinuousBackgroundDrawing() { |
| 5752 | boolean continuousBackground = !mAmbientState.isFullyAwake() |
| 5753 | && !mAmbientState.getDraggedViews().isEmpty(); |
| 5754 | if (continuousBackground != mContinuousBackgroundUpdate) { |
| 5755 | mContinuousBackgroundUpdate = continuousBackground; |
| 5756 | if (continuousBackground) { |
| 5757 | getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater); |
| 5758 | } else { |
| 5759 | getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater); |
| 5760 | } |
| 5761 | } |
| 5762 | } |
| 5763 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5764 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5765 | private void updateContinuousShadowDrawing() { |
| 5766 | boolean continuousShadowUpdate = mAnimationRunning |
| 5767 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 5768 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 5769 | if (continuousShadowUpdate) { |
| 5770 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 5771 | } else { |
| 5772 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 5773 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 5774 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5775 | } |
| 5776 | } |
| 5777 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5778 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5779 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 5780 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 5781 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5784 | private static boolean matchesSelection( |
| 5785 | ExpandableNotificationRow row, |
| 5786 | @SelectedRows int selection) { |
| 5787 | switch (selection) { |
| 5788 | case ROWS_ALL: |
| 5789 | return true; |
| 5790 | case ROWS_HIGH_PRIORITY: |
| 5791 | return row.getEntry().isHighPriority(); |
| 5792 | case ROWS_GENTLE: |
| 5793 | return !row.getEntry().isHighPriority(); |
| 5794 | default: |
| 5795 | throw new IllegalArgumentException("Unknown selection: " + selection); |
| 5796 | } |
| 5797 | } |
| 5798 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5799 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 5800 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5801 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5802 | static AnimationFilter[] FILTERS = new AnimationFilter[]{ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5803 | |
| 5804 | // ANIMATION_TYPE_ADD |
| 5805 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5806 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5807 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5808 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5809 | .animateZ() |
| 5810 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5811 | |
| 5812 | // ANIMATION_TYPE_REMOVE |
| 5813 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5814 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5815 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5816 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5817 | .animateZ() |
| 5818 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5819 | |
| 5820 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5821 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5822 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5823 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5824 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5825 | .animateZ() |
| 5826 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5827 | |
| 5828 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5829 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5830 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5831 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5832 | .animateY() |
| 5833 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5834 | .animateZ(), |
| 5835 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5836 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5837 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5838 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5839 | |
| 5840 | // ANIMATION_TYPE_DIMMED |
| 5841 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5842 | .animateDimmed(), |
| 5843 | |
| 5844 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5845 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5846 | .animateAlpha() // maybe the children change positions |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5847 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5848 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5849 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5850 | .animateZ(), |
| 5851 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5852 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5853 | new AnimationFilter() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5854 | .animateHeight() |
| 5855 | .animateTopInset() |
| 5856 | .animateY() |
| 5857 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5858 | .animateZ() |
| 5859 | .hasDelays(), |
| 5860 | |
| 5861 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5862 | new AnimationFilter() |
| 5863 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5864 | |
| 5865 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5866 | new AnimationFilter() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5867 | .animateHeight() |
| 5868 | .animateTopInset() |
| 5869 | .animateY() |
| 5870 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5871 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5872 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 5873 | new AnimationFilter() |
| 5874 | .animateAlpha() |
| 5875 | .animateHeight() |
| 5876 | .animateTopInset() |
| 5877 | .animateY() |
| 5878 | .animateZ(), |
| 5879 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5880 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5881 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5882 | .animateHeight() |
| 5883 | .animateTopInset() |
| 5884 | .animateY() |
| 5885 | .animateZ(), |
| 5886 | |
| 5887 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5888 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5889 | .animateHeight() |
| 5890 | .animateTopInset() |
| 5891 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 5892 | .animateZ() |
| 5893 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5894 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5895 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5896 | new AnimationFilter() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5897 | .animateHeight() |
| 5898 | .animateTopInset() |
| 5899 | .animateY() |
| 5900 | .animateZ() |
| 5901 | .hasDelays(), |
| 5902 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5903 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5904 | new AnimationFilter() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5905 | .animateHeight() |
| 5906 | .animateTopInset() |
| 5907 | .animateY() |
| 5908 | .animateZ(), |
| 5909 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5910 | // ANIMATION_TYPE_EVERYTHING |
| 5911 | new AnimationFilter() |
| 5912 | .animateAlpha() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5913 | .animateDimmed() |
| 5914 | .animateHideSensitive() |
| 5915 | .animateHeight() |
| 5916 | .animateTopInset() |
| 5917 | .animateY() |
| 5918 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5919 | }; |
| 5920 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5921 | static int[] LENGTHS = new int[]{ |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5922 | |
| 5923 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5924 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5925 | |
| 5926 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5927 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5928 | |
| 5929 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5930 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5931 | |
| 5932 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5933 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5934 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5935 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5936 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 5937 | |
| 5938 | // ANIMATION_TYPE_DIMMED |
| 5939 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5940 | |
| 5941 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5942 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5943 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5944 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5945 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5946 | |
| 5947 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5948 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5949 | |
| 5950 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5951 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5952 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5953 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 5954 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5955 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5956 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5957 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 5958 | |
| 5959 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5960 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 5961 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5962 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5963 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 5964 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5965 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5966 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5967 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5968 | // ANIMATION_TYPE_EVERYTHING |
| 5969 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5970 | }; |
| 5971 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5972 | static final int ANIMATION_TYPE_ADD = 0; |
| 5973 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 5974 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 5975 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
Selim Cinek | ff2ffec | 2018-11-19 18:52:01 -0800 | [diff] [blame] | 5976 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 4; |
| 5977 | static final int ANIMATION_TYPE_DIMMED = 5; |
| 5978 | static final int ANIMATION_TYPE_CHANGE_POSITION = 6; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 5979 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 7; |
| 5980 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 8; |
| 5981 | static final int ANIMATION_TYPE_VIEW_RESIZE = 9; |
| 5982 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 10; |
| 5983 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 11; |
| 5984 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 12; |
| 5985 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 13; |
| 5986 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 14; |
| 5987 | static final int ANIMATION_TYPE_EVERYTHING = 15; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 5988 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5989 | final long eventStartTime; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5990 | final ExpandableView mChangingView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5991 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5992 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5993 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5994 | View viewAfterChangingView; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5995 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5996 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5997 | AnimationEvent(ExpandableView view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 5998 | this(view, type, LENGTHS[type]); |
| 5999 | } |
| 6000 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6001 | AnimationEvent(ExpandableView view, int type, AnimationFilter filter) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6002 | this(view, type, LENGTHS[type], filter); |
| 6003 | } |
| 6004 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6005 | AnimationEvent(ExpandableView view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6006 | this(view, type, length, FILTERS[type]); |
| 6007 | } |
| 6008 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6009 | AnimationEvent(ExpandableView view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6010 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6011 | mChangingView = view; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6012 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6013 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6014 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | /** |
| 6018 | * Combines the length of several animation events into a single value. |
| 6019 | * |
| 6020 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6021 | * @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] | 6022 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6023 | */ |
| 6024 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 6025 | long length = 0; |
| 6026 | int size = events.size(); |
| 6027 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6028 | AnimationEvent event = events.get(i); |
| 6029 | length = Math.max(length, event.length); |
| 6030 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 6031 | return event.length; |
| 6032 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6033 | } |
| 6034 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6035 | } |
| 6036 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6037 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6038 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 6039 | private final StateListener mStateListener = new StateListener() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6040 | @Override |
| 6041 | public void onStatePreChange(int oldState, int newState) { |
| 6042 | if (oldState == StatusBarState.SHADE_LOCKED && newState == StatusBarState.KEYGUARD) { |
| 6043 | requestAnimateEverything(); |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | @Override |
| 6048 | public void onStateChanged(int newState) { |
| 6049 | setStatusBarState(newState); |
| 6050 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6051 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6052 | @Override |
| 6053 | public void onStatePostChange() { |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6054 | NotificationStackScrollLayout.this.onStatePostChange(); |
| 6055 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6056 | }; |
| 6057 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6058 | @VisibleForTesting |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6059 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6060 | protected final OnMenuEventListener mMenuEventListener = new OnMenuEventListener() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6061 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6062 | public void onMenuClicked(View view, int x, int y, MenuItem item) { |
| 6063 | if (mLongPressListener == null) { |
| 6064 | return; |
| 6065 | } |
| 6066 | if (view instanceof ExpandableNotificationRow) { |
| 6067 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6068 | mMetricsLogger.write(row.getStatusBarNotification().getLogMaker() |
| 6069 | .setCategory(MetricsEvent.ACTION_TOUCH_GEAR) |
| 6070 | .setType(MetricsEvent.TYPE_ACTION) |
| 6071 | ); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6072 | } |
| 6073 | mLongPressListener.onLongPress(view, x, y, item); |
| 6074 | } |
| 6075 | |
| 6076 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6077 | public void onMenuReset(View row) { |
| 6078 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 6079 | if (translatingParentView != null && row == translatingParentView) { |
| 6080 | mSwipeHelper.clearExposedMenuView(); |
| 6081 | mSwipeHelper.clearTranslatingParentView(); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6082 | if (row instanceof ExpandableNotificationRow) { |
| 6083 | mHeadsUpManager.setMenuShown( |
| 6084 | ((ExpandableNotificationRow) row).getEntry(), false); |
| 6085 | |
| 6086 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6087 | } |
| 6088 | } |
| 6089 | |
| 6090 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6091 | public void onMenuShown(View row) { |
| 6092 | if (row instanceof ExpandableNotificationRow) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6093 | ExpandableNotificationRow notificationRow = (ExpandableNotificationRow) row; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6094 | mMetricsLogger.write(notificationRow.getStatusBarNotification().getLogMaker() |
| 6095 | .setCategory(MetricsEvent.ACTION_REVEAL_GEAR) |
| 6096 | .setType(MetricsEvent.TYPE_ACTION)); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6097 | mHeadsUpManager.setMenuShown(notificationRow.getEntry(), true); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6098 | mSwipeHelper.onMenuShown(row); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6099 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6100 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6101 | false /* resetMenu */); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6102 | |
| 6103 | // Check to see if we want to go directly to the notfication guts |
| 6104 | NotificationMenuRowPlugin provider = notificationRow.getProvider(); |
| 6105 | if (provider.shouldShowGutsOnSnapOpen()) { |
| 6106 | MenuItem item = provider.menuItemToExposeOnSnap(); |
| 6107 | if (item != null) { |
| 6108 | Point origin = provider.getRevealAnimationOrigin(); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6109 | mNotificationGutsManager.openGuts(row, origin.x, origin.y, item); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6110 | } else { |
| 6111 | Log.e(TAG, "Provider has shouldShowGutsOnSnapOpen, but provided no " |
| 6112 | + "menu item in menuItemtoExposeOnSnap. Skipping."); |
| 6113 | } |
| 6114 | |
| 6115 | // Close the menu row since we went directly to the guts |
| 6116 | resetExposedMenuView(false, true); |
| 6117 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6118 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6119 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6120 | }; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6121 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6122 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6123 | private final NotificationSwipeHelper.NotificationCallback mNotificationCallback = |
| 6124 | new NotificationSwipeHelper.NotificationCallback() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6125 | @Override |
| 6126 | public void onDismiss() { |
| 6127 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6128 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6129 | false /* resetMenu */); |
| 6130 | } |
| 6131 | |
| 6132 | @Override |
| 6133 | public void onSnooze(StatusBarNotification sbn, |
| 6134 | NotificationSwipeActionHelper.SnoozeOption snoozeOption) { |
| 6135 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
| 6136 | } |
| 6137 | |
| 6138 | @Override |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6139 | public boolean shouldDismissQuickly() { |
| 6140 | return NotificationStackScrollLayout.this.isExpanded() && mAmbientState.isFullyAwake(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6144 | public void onDragCancelled(View v) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6145 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6146 | mFalsingManager.onNotificatonStopDismissing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6147 | } |
| 6148 | |
| 6149 | /** |
| 6150 | * Handles cleanup after the given {@code view} has been fully swiped out (including |
| 6151 | * re-invoking dismiss logic in case the notification has not made its way out yet). |
| 6152 | */ |
| 6153 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6154 | public void onChildDismissed(View view) { |
| 6155 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6156 | if (!row.isDismissed()) { |
| 6157 | handleChildViewDismissed(view); |
| 6158 | } |
| 6159 | ViewGroup transientContainer = row.getTransientContainer(); |
| 6160 | if (transientContainer != null) { |
| 6161 | transientContainer.removeTransientView(view); |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | /** |
| 6166 | * Starts up notification dismiss and tells the notification, if any, to remove itself from |
| 6167 | * layout. |
| 6168 | * |
| 6169 | * @param view view (e.g. notification) to dismiss from the layout |
| 6170 | */ |
| 6171 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6172 | public void handleChildViewDismissed(View view) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6173 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6174 | if (mDismissAllInProgress) { |
| 6175 | return; |
| 6176 | } |
| 6177 | |
| 6178 | boolean isBlockingHelperShown = false; |
| 6179 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6180 | mAmbientState.onDragFinished(view); |
| 6181 | updateContinuousShadowDrawing(); |
| 6182 | |
| 6183 | if (view instanceof ExpandableNotificationRow) { |
| 6184 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6185 | if (row.isHeadsUp()) { |
| 6186 | mHeadsUpManager.addSwipedOutNotification( |
| 6187 | row.getStatusBarNotification().getKey()); |
| 6188 | } |
| 6189 | isBlockingHelperShown = |
| 6190 | row.performDismissWithBlockingHelper(false /* fromAccessibility */); |
| 6191 | } |
| 6192 | |
| 6193 | if (!isBlockingHelperShown) { |
| 6194 | mSwipedOutViews.add(view); |
| 6195 | } |
| 6196 | mFalsingManager.onNotificationDismissed(); |
| 6197 | if (mFalsingManager.shouldEnforceBouncer()) { |
| 6198 | mStatusBar.executeRunnableDismissingKeyguard( |
| 6199 | null, |
| 6200 | null /* cancelAction */, |
| 6201 | false /* dismissShade */, |
| 6202 | true /* afterKeyguardGone */, |
| 6203 | false /* deferred */); |
| 6204 | } |
| 6205 | } |
| 6206 | |
| 6207 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6208 | public boolean isAntiFalsingNeeded() { |
| 6209 | return onKeyguard(); |
| 6210 | } |
| 6211 | |
| 6212 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6213 | public View getChildAtPosition(MotionEvent ev) { |
| 6214 | View child = NotificationStackScrollLayout.this.getChildAtPosition(ev.getX(), |
| 6215 | ev.getY()); |
| 6216 | if (child instanceof ExpandableNotificationRow) { |
| 6217 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 6218 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 6219 | if (parent != null && parent.areChildrenExpanded() |
| 6220 | && (parent.areGutsExposed() |
| 6221 | || mSwipeHelper.getExposedMenuView() == parent |
| 6222 | || (parent.getNotificationChildren().size() == 1 |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 6223 | && parent.getEntry().isClearable()))) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6224 | // In this case the group is expanded and showing the menu for the |
| 6225 | // group, further interaction should apply to the group, not any |
| 6226 | // child notifications so we use the parent of the child. We also do the same |
| 6227 | // if we only have a single child. |
| 6228 | child = parent; |
| 6229 | } |
| 6230 | } |
| 6231 | return child; |
| 6232 | } |
| 6233 | |
| 6234 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6235 | public void onBeginDrag(View v) { |
| 6236 | mFalsingManager.onNotificatonStartDismissing(); |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6237 | setSwipingInProgress(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6238 | mAmbientState.onBeginDrag((ExpandableView) v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6239 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6240 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6241 | requestChildrenUpdate(); |
| 6242 | } |
| 6243 | |
| 6244 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6245 | public void onChildSnappedBack(View animView, float targetLeft) { |
| 6246 | mAmbientState.onDragFinished(animView); |
| 6247 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6248 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6252 | public boolean updateSwipeProgress(View animView, boolean dismissable, |
| 6253 | float swipeProgress) { |
| 6254 | // Returning true prevents alpha fading. |
| 6255 | return !mFadeNotificationsOnDismiss; |
| 6256 | } |
| 6257 | |
| 6258 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6259 | public float getFalsingThresholdFactor() { |
| 6260 | return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
| 6261 | } |
| 6262 | |
| 6263 | @Override |
Gus Prevas | c4e68d4 | 2019-01-17 15:45:21 -0500 | [diff] [blame] | 6264 | public int getConstrainSwipeStartPosition() { |
| 6265 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 6266 | if (menuRow != null) { |
| 6267 | return Math.abs(menuRow.getMenuSnapTarget()); |
| 6268 | } |
| 6269 | return 0; |
| 6270 | } |
| 6271 | |
| 6272 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6273 | public boolean canChildBeDismissed(View v) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6274 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6275 | } |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6276 | |
| 6277 | @Override |
| 6278 | public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) { |
Evan Laird | 30b9b16 | 2019-04-24 15:22:24 -0400 | [diff] [blame] | 6279 | //TODO: b/131242807 for why this doesn't do anything with direction |
| 6280 | return canChildBeDismissed(v); |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6281 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6282 | }; |
| 6283 | |
| 6284 | // ---------------------- DragDownHelper.OnDragDownListener ------------------------------------ |
| 6285 | |
| 6286 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6287 | private final DragDownCallback mDragDownCallback = new DragDownCallback() { |
| 6288 | |
| 6289 | /* Only ever called as a consequence of a lockscreen expansion gesture. */ |
| 6290 | @Override |
| 6291 | public boolean onDraggedDown(View startingChild, int dragLengthY) { |
| 6292 | if (mStatusBarState == StatusBarState.KEYGUARD |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6293 | && hasActiveNotifications()) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6294 | mLockscreenGestureLogger.write( |
| 6295 | MetricsEvent.ACTION_LS_SHADE, |
| 6296 | (int) (dragLengthY / mDisplayMetrics.density), |
| 6297 | 0 /* velocityDp - N/A */); |
| 6298 | |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 6299 | if (!mAmbientState.isDozing() || startingChild != null) { |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6300 | // We have notifications, go to locked shade. |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 6301 | mShadeController.goToLockedShade(startingChild); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6302 | if (startingChild instanceof ExpandableNotificationRow) { |
| 6303 | ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild; |
| 6304 | row.onExpandedByGesture(true /* drag down is always an open */); |
| 6305 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6306 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6307 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6308 | return true; |
| 6309 | } else { |
| 6310 | // abort gesture. |
| 6311 | return false; |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | @Override |
| 6316 | public void onDragDownReset() { |
| 6317 | setDimmed(true /* dimmed */, true /* animated */); |
| 6318 | resetScrollPosition(); |
| 6319 | resetCheckSnoozeLeavebehind(); |
| 6320 | } |
| 6321 | |
| 6322 | @Override |
| 6323 | public void onCrossedThreshold(boolean above) { |
| 6324 | setDimmed(!above /* dimmed */, true /* animate */); |
| 6325 | } |
| 6326 | |
| 6327 | @Override |
| 6328 | public void onTouchSlopExceeded() { |
| 6329 | cancelLongPress(); |
| 6330 | checkSnoozeLeavebehind(); |
| 6331 | } |
| 6332 | |
| 6333 | @Override |
| 6334 | public void setEmptyDragAmount(float amount) { |
| 6335 | mNotificationPanel.setEmptyDragAmount(amount); |
| 6336 | } |
| 6337 | |
| 6338 | @Override |
| 6339 | public boolean isFalsingCheckNeeded() { |
| 6340 | return mStatusBarState == StatusBarState.KEYGUARD; |
| 6341 | } |
| 6342 | }; |
| 6343 | |
| 6344 | public DragDownCallback getDragDownCallback() { return mDragDownCallback; } |
| 6345 | |
| 6346 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6347 | private final HeadsUpTouchHelper.Callback mHeadsUpCallback = new HeadsUpTouchHelper.Callback() { |
| 6348 | @Override |
| 6349 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6350 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6351 | } |
| 6352 | |
| 6353 | @Override |
| 6354 | public boolean isExpanded() { |
| 6355 | return mIsExpanded; |
| 6356 | } |
| 6357 | |
| 6358 | @Override |
| 6359 | public Context getContext() { |
| 6360 | return mContext; |
| 6361 | } |
| 6362 | }; |
| 6363 | |
| 6364 | public HeadsUpTouchHelper.Callback getHeadsUpCallback() { return mHeadsUpCallback; } |
| 6365 | |
| 6366 | |
| 6367 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6368 | private final OnGroupChangeListener mOnGroupChangeListener = new OnGroupChangeListener() { |
| 6369 | @Override |
| 6370 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
| 6371 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 6372 | && (mIsExpanded || changedRow.isPinned()); |
| 6373 | if (animated) { |
| 6374 | mExpandedGroupView = changedRow; |
| 6375 | mNeedsAnimation = true; |
| 6376 | } |
| 6377 | changedRow.setChildrenExpanded(expanded, animated); |
| 6378 | if (!mGroupExpandedForMeasure) { |
| 6379 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 6380 | } |
| 6381 | runAfterAnimationFinished(new Runnable() { |
| 6382 | @Override |
| 6383 | public void run() { |
| 6384 | changedRow.onFinishedExpansionChange(); |
| 6385 | } |
| 6386 | }); |
| 6387 | } |
| 6388 | |
| 6389 | @Override |
| 6390 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
| 6391 | mStatusBar.requestNotificationUpdate(); |
| 6392 | } |
| 6393 | |
| 6394 | @Override |
| 6395 | public void onGroupsChanged() { |
| 6396 | mStatusBar.requestNotificationUpdate(); |
| 6397 | } |
| 6398 | }; |
| 6399 | |
| 6400 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6401 | private ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { |
| 6402 | @Override |
| 6403 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
| 6404 | return NotificationStackScrollLayout.this.getChildAtPosition(touchX, touchY); |
| 6405 | } |
| 6406 | |
| 6407 | @Override |
| 6408 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6409 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6410 | } |
| 6411 | |
| 6412 | @Override |
| 6413 | public boolean canChildBeExpanded(View v) { |
| 6414 | return v instanceof ExpandableNotificationRow |
| 6415 | && ((ExpandableNotificationRow) v).isExpandable() |
| 6416 | && !((ExpandableNotificationRow) v).areGutsExposed() |
| 6417 | && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned()); |
| 6418 | } |
| 6419 | |
| 6420 | /* Only ever called as a consequence of an expansion gesture in the shade. */ |
| 6421 | @Override |
| 6422 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 6423 | if (v instanceof ExpandableNotificationRow) { |
| 6424 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6425 | if (userExpanded && onKeyguard()) { |
| 6426 | // Due to a race when locking the screen while touching, a notification may be |
| 6427 | // expanded even after we went back to keyguard. An example of this happens if |
| 6428 | // you click in the empty space while expanding a group. |
| 6429 | |
| 6430 | // We also need to un-user lock it here, since otherwise the content height |
| 6431 | // calculated might be wrong. We also can't invert the two calls since |
| 6432 | // un-userlocking it will trigger a layout switch in the content view. |
| 6433 | row.setUserLocked(false); |
| 6434 | updateContentHeight(); |
| 6435 | notifyHeightChangeListener(row); |
| 6436 | return; |
| 6437 | } |
| 6438 | row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */); |
| 6439 | row.onExpandedByGesture(userExpanded); |
| 6440 | } |
| 6441 | } |
| 6442 | |
| 6443 | @Override |
| 6444 | public void setExpansionCancelled(View v) { |
| 6445 | if (v instanceof ExpandableNotificationRow) { |
| 6446 | ((ExpandableNotificationRow) v).setGroupExpansionChanging(false); |
| 6447 | } |
| 6448 | } |
| 6449 | |
| 6450 | @Override |
| 6451 | public void setUserLockedChild(View v, boolean userLocked) { |
| 6452 | if (v instanceof ExpandableNotificationRow) { |
| 6453 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 6454 | } |
| 6455 | cancelLongPress(); |
| 6456 | requestDisallowInterceptTouchEvent(true); |
| 6457 | } |
| 6458 | |
| 6459 | @Override |
| 6460 | public void expansionStateChanged(boolean isExpanding) { |
| 6461 | mExpandingNotification = isExpanding; |
| 6462 | if (!mExpandedInThisMotion) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 6463 | if (ANCHOR_SCROLLING) { |
| 6464 | // TODO |
| 6465 | } else { |
| 6466 | mMaxScrollAfterExpand = mOwnScrollY; |
| 6467 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6468 | mExpandedInThisMotion = true; |
| 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | @Override |
| 6473 | public int getMaxExpandHeight(ExpandableView view) { |
| 6474 | return view.getMaxContentHeight(); |
| 6475 | } |
| 6476 | }; |
| 6477 | |
| 6478 | public ExpandHelper.Callback getExpandHelperCallback() { |
| 6479 | return mExpandHelperCallback; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6480 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6481 | |
| 6482 | /** Enum for selecting some or all notification rows (does not included non-notif views). */ |
| 6483 | @Retention(SOURCE) |
| 6484 | @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE}) |
| 6485 | public @interface SelectedRows {} |
| 6486 | /** All rows representing notifs. */ |
| 6487 | public static final int ROWS_ALL = 0; |
| 6488 | /** Only rows where entry.isHighPriority() is true. */ |
| 6489 | public static final int ROWS_HIGH_PRIORITY = 1; |
| 6490 | /** Only rows where entry.isHighPriority() is false. */ |
| 6491 | public static final int ROWS_GENTLE = 2; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 6492 | } |