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; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.phone.NotificationIconAreaController.LOW_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; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 35 | import android.app.WallpaperManager; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 36 | import android.content.Context; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 37 | import android.content.Intent; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 38 | import android.content.res.Configuration; |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 39 | import android.content.res.Resources; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 40 | import android.graphics.Canvas; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 41 | import android.graphics.Color; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 42 | import android.graphics.Outline; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 43 | import android.graphics.Paint; |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 44 | import android.graphics.Point; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 45 | import android.graphics.PointF; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 46 | import android.graphics.PorterDuff; |
| 47 | import android.graphics.PorterDuffXfermode; |
| 48 | import android.graphics.Rect; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 49 | import android.os.Bundle; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 50 | import android.os.ServiceManager; |
| 51 | import android.provider.Settings; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 52 | import android.service.notification.NotificationListenerService; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 53 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 54 | import android.util.AttributeSet; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 55 | import android.util.DisplayMetrics; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 56 | import android.util.Log; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 57 | import android.util.MathUtils; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 58 | import android.util.Pair; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 59 | import android.view.ContextThemeWrapper; |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 60 | import android.view.InputDevice; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 61 | import android.view.LayoutInflater; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 62 | import android.view.MotionEvent; |
| 63 | import android.view.VelocityTracker; |
| 64 | import android.view.View; |
| 65 | import android.view.ViewConfiguration; |
| 66 | import android.view.ViewGroup; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 67 | import android.view.ViewOutlineProvider; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 68 | import android.view.ViewTreeObserver; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 69 | import android.view.WindowInsets; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 70 | import android.view.accessibility.AccessibilityEvent; |
| 71 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 72 | import android.view.animation.AnimationUtils; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 73 | import android.view.animation.Interpolator; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 74 | import android.widget.OverScroller; |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 75 | import android.widget.ScrollView; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 76 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 77 | import com.android.internal.annotations.VisibleForTesting; |
| 78 | import com.android.internal.graphics.ColorUtils; |
Mady Mellor | a41587b | 2016-02-11 18:43:06 -0800 | [diff] [blame] | 79 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 80 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 81 | import com.android.internal.statusbar.IStatusBarService; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 82 | import com.android.keyguard.KeyguardSliceView; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 83 | import com.android.settingslib.Utils; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 84 | import com.android.systemui.Dependency; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 85 | import com.android.systemui.Dumpable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 86 | import com.android.systemui.ExpandHelper; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 87 | import com.android.systemui.Interpolators; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 88 | import com.android.systemui.R; |
| 89 | import com.android.systemui.SwipeHelper; |
Dave Mankoff | dde5ee6 | 2019-05-02 17:36:11 -0400 | [diff] [blame] | 90 | import com.android.systemui.classifier.FalsingManagerFactory; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 91 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 92 | import com.android.systemui.plugins.ActivityStarter; |
Dave Mankoff | 468d4f6 | 2019-05-08 14:56:29 -0400 | [diff] [blame] | 93 | import com.android.systemui.plugins.FalsingManager; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 94 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
| 95 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 96 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.OnMenuEventListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 97 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 98 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 99 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 100 | import com.android.systemui.statusbar.AmbientPulseManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 101 | import com.android.systemui.statusbar.CommandQueue; |
| 102 | import com.android.systemui.statusbar.DragDownHelper.DragDownCallback; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 103 | import com.android.systemui.statusbar.EmptyShadeView; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 104 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 105 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 106 | import com.android.systemui.statusbar.NotificationShelf; |
| 107 | import com.android.systemui.statusbar.RemoteInputController; |
| 108 | import com.android.systemui.statusbar.StatusBarState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 109 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 110 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 111 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 112 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 113 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 114 | import com.android.systemui.statusbar.notification.NotificationUtils; |
| 115 | import com.android.systemui.statusbar.notification.ShadeViewRefactor; |
| 116 | import com.android.systemui.statusbar.notification.ShadeViewRefactor.RefactorComponent; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 117 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 118 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 119 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 120 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 121 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 122 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 123 | import com.android.systemui.statusbar.notification.row.FooterView; |
| 124 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 125 | import com.android.systemui.statusbar.notification.row.NotificationGuts; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 126 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 127 | import com.android.systemui.statusbar.notification.row.NotificationSnooze; |
| 128 | import com.android.systemui.statusbar.notification.row.StackScrollerDecorView; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 129 | import com.android.systemui.statusbar.phone.DozeParameters; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 130 | import com.android.systemui.statusbar.phone.HeadsUpAppearanceController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 131 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 132 | import com.android.systemui.statusbar.phone.HeadsUpTouchHelper; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 133 | import com.android.systemui.statusbar.phone.LockscreenGestureLogger; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 134 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 135 | import com.android.systemui.statusbar.phone.NotificationGroupManager.OnGroupChangeListener; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 136 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 137 | import com.android.systemui.statusbar.phone.NotificationPanelView; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 138 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 139 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 140 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 141 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 142 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 143 | import com.android.systemui.statusbar.policy.HeadsUpUtil; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 144 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 145 | import com.android.systemui.tuner.TunerService; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 146 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 147 | import java.io.FileDescriptor; |
| 148 | import java.io.PrintWriter; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 149 | import java.lang.annotation.Retention; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 150 | import java.util.ArrayList; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 151 | import java.util.Collections; |
| 152 | import java.util.Comparator; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 153 | import java.util.HashSet; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 154 | import java.util.List; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 155 | import java.util.function.BiConsumer; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 156 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 157 | import javax.inject.Inject; |
| 158 | import javax.inject.Named; |
| 159 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 160 | /** |
| 161 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 162 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 163 | public class NotificationStackScrollLayout extends ViewGroup implements ScrollAdapter, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 164 | NotificationListContainer, ConfigurationListener, Dumpable, |
| 165 | DynamicPrivacyController.Listener { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 166 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 167 | public static final float BACKGROUND_ALPHA_DIMMED = 0.7f; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 168 | private static final String TAG = "StackScroller"; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 169 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 170 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 171 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 172 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 173 | /** |
| 174 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 175 | */ |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 176 | private static final int INVALID_POINTER = -1; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 177 | static final int NUM_SECTIONS = 2; |
| 178 | /** |
| 179 | * The distance in pixels between sections when the sections are directly adjacent (no visible |
| 180 | * gap is drawn between them). In this case we don't want to round their corners. |
| 181 | */ |
| 182 | private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 183 | private final AmbientPulseManager mAmbientPulseManager; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 184 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 185 | private ExpandHelper mExpandHelper; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 186 | private final NotificationSwipeHelper mSwipeHelper; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 187 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 188 | private final Paint mBackgroundPaint = new Paint(); |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 189 | private final boolean mShouldDrawNotificationBackground; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 190 | private boolean mLowPriorityBeforeSpeedBump; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 191 | private final boolean mAllowLongPress; |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 192 | private boolean mDismissRtl; |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 193 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 194 | private float mExpandedHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 195 | private int mOwnScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 196 | private View mScrollAnchorView; |
| 197 | private int mScrollAnchorViewY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 198 | private int mMaxLayoutHeight; |
| 199 | |
| 200 | private VelocityTracker mVelocityTracker; |
| 201 | private OverScroller mScroller; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 202 | /** Last Y position reported by {@link #mScroller}, used to calculate scroll delta. */ |
| 203 | private int mLastScrollerY; |
| 204 | /** |
| 205 | * True if the max position was set to a known position on the last call to {@link #mScroller}. |
| 206 | */ |
| 207 | private boolean mIsScrollerBoundSet; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 208 | private Runnable mFinishScrollingCallback; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 209 | private int mTouchSlop; |
| 210 | private int mMinimumVelocity; |
| 211 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 212 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 213 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 214 | private boolean mIsBeingDragged; |
| 215 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 216 | private int mDownX; |
Dong-wan Kim | b926666 | 2016-09-21 13:08:30 -0700 | [diff] [blame] | 217 | private int mActivePointerId = INVALID_POINTER; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 218 | private boolean mTouchIsClick; |
| 219 | private float mInitialTouchX; |
| 220 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 221 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 222 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 223 | private int mContentHeight; |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 224 | private int mIntrinsicContentHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 225 | private int mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 226 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 227 | private int mIncreasedPaddingBetweenElements; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 228 | private int mMaxTopPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 229 | private int mTopPadding; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 230 | private int mBottomMargin; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 231 | private int mBottomInset = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 232 | private float mQsExpansionFraction; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * The algorithm which calculates the properties for our children |
| 236 | */ |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 237 | protected final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 238 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 239 | private final AmbientState mAmbientState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 240 | private NotificationGroupManager mGroupManager; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 241 | private HashSet<ExpandableView> mChildrenToAddAnimated = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 242 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 243 | private ArrayList<ExpandableView> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 244 | private ArrayList<ExpandableView> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 245 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 246 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 247 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 248 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 249 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 250 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 251 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 252 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 253 | /** |
| 254 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 255 | */ |
| 256 | private float mOverScrolledTopPixels; |
| 257 | |
| 258 | /** |
| 259 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 260 | */ |
| 261 | private float mOverScrolledBottomPixels; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 262 | private NotificationLogger.OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 263 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 264 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 265 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 266 | private boolean mNeedsAnimation; |
| 267 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 268 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 269 | private boolean mHideSensitiveNeedsAnimation; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 270 | private boolean mDarkNeedsAnimation; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 271 | private int mDarkAnimationOriginIndex; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 272 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 273 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 274 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 275 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 276 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 277 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 278 | private boolean mExpandingNotification; |
| 279 | private boolean mExpandedInThisMotion; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 280 | private boolean mShouldShowShelfOnly; |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 281 | protected boolean mScrollingEnabled; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 282 | protected FooterView mFooterView; |
Muyuan Li | dd9ae75 | 2016-05-13 16:45:43 -0700 | [diff] [blame] | 283 | protected EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 284 | private boolean mDismissAllInProgress; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 285 | private boolean mFadeNotificationsOnDismiss; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * Was the scroller scrolled to the top when the down motion was observed? |
| 289 | */ |
| 290 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 291 | /** |
| 292 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 293 | * when over scrolling on a expanded card. |
| 294 | */ |
| 295 | private float mMinTopOverScrollToEscape; |
| 296 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 297 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 298 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 299 | private boolean mDontReportNextOverScroll; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 300 | private boolean mDontClampNextScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 301 | private boolean mNeedViewResizeAnimation; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 302 | private ExpandableView mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 303 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 304 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 305 | /** |
| 306 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 307 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 308 | * motion. |
| 309 | */ |
| 310 | private int mMaxScrollAfterExpand; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 311 | private ExpandableNotificationRow.LongPressListener mLongPressListener; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 312 | boolean mCheckForLeavebehind; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 313 | |
| 314 | /** |
| 315 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 316 | * animating. |
| 317 | */ |
| 318 | private boolean mOnlyScrollingInThisMotion; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 319 | private boolean mDisallowDismissInThisMotion; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 320 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 321 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 322 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 323 | = new ViewTreeObserver.OnPreDrawListener() { |
| 324 | @Override |
| 325 | public boolean onPreDraw() { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 326 | updateForcedScroll(); |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 327 | updateChildren(); |
| 328 | mChildrenUpdateRequested = false; |
| 329 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 330 | return true; |
| 331 | } |
| 332 | }; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 333 | private StatusBar mStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 334 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 335 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 336 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 337 | private HashSet<ExpandableView> mClearTransientViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 338 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 339 | = new HashSet<>(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 340 | private HeadsUpManagerPhone mHeadsUpManager; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 341 | private final NotificationRoundnessManager mRoundnessManager; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 342 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 343 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 344 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 345 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 346 | private FalsingManager mFalsingManager; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 347 | private boolean mAnimationRunning; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 348 | private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 349 | = new ViewTreeObserver.OnPreDrawListener() { |
| 350 | @Override |
| 351 | public boolean onPreDraw() { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 352 | onPreDrawDuringAnimation(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 353 | return true; |
| 354 | } |
| 355 | }; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 356 | private NotificationSection[] mSections = new NotificationSection[NUM_SECTIONS]; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 357 | private boolean mAnimateNextBackgroundTop; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 358 | private boolean mAnimateNextBackgroundBottom; |
| 359 | private boolean mAnimateNextSectionBoundsChange; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 360 | private int mBgColor; |
| 361 | private float mDimAmount; |
| 362 | private ValueAnimator mDimAnimator; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 363 | private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 364 | private final Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 365 | @Override |
| 366 | public void onAnimationEnd(Animator animation) { |
| 367 | mDimAnimator = null; |
| 368 | } |
| 369 | }; |
| 370 | private ValueAnimator.AnimatorUpdateListener mDimUpdateListener |
| 371 | = new ValueAnimator.AnimatorUpdateListener() { |
| 372 | |
| 373 | @Override |
| 374 | public void onAnimationUpdate(ValueAnimator animation) { |
| 375 | setDimAmount((Float) animation.getAnimatedValue()); |
| 376 | } |
| 377 | }; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 378 | protected ViewGroup mQsContainer; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 379 | private boolean mContinuousShadowUpdate; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 380 | private boolean mContinuousBackgroundUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 381 | private ViewTreeObserver.OnPreDrawListener mShadowUpdater |
| 382 | = new ViewTreeObserver.OnPreDrawListener() { |
| 383 | |
| 384 | @Override |
| 385 | public boolean onPreDraw() { |
| 386 | updateViewShadows(); |
| 387 | return true; |
| 388 | } |
| 389 | }; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 390 | private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> { |
| 391 | updateBackground(); |
| 392 | return true; |
| 393 | }; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 394 | private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() { |
| 395 | @Override |
| 396 | public int compare(ExpandableView view, ExpandableView otherView) { |
| 397 | float endY = view.getTranslationY() + view.getActualHeight(); |
| 398 | float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); |
| 399 | if (endY < otherEndY) { |
| 400 | return -1; |
| 401 | } else if (endY > otherEndY) { |
| 402 | return 1; |
| 403 | } else { |
| 404 | // The two notifications end at the same location |
| 405 | return 0; |
| 406 | } |
| 407 | } |
| 408 | }; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 409 | private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() { |
| 410 | @Override |
| 411 | public void getOutline(View view, Outline outline) { |
Selim Cinek | 1e05927 | 2019-05-21 18:15:00 -0700 | [diff] [blame] | 412 | if (mAmbientState.isDarkAtAll()) { |
Selim Cinek | 9ad240c | 2019-04-08 19:07:15 -0700 | [diff] [blame] | 413 | float xProgress = mDarkXInterpolator.getInterpolation( |
| 414 | (1 - mLinearDarkAmount) * mBackgroundXFactor); |
| 415 | outline.setRoundRect(mBackgroundAnimationRect, |
| 416 | MathUtils.lerp(mCornerRadius / 2.0f, mCornerRadius, |
| 417 | xProgress)); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 418 | } else { |
| 419 | ViewOutlineProvider.BACKGROUND.getOutline(view, outline); |
| 420 | } |
| 421 | } |
| 422 | }; |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 423 | private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 424 | private boolean mPulsing; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 425 | private boolean mGroupExpandedForMeasure; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 426 | private boolean mScrollable; |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 427 | private View mForcedScroll; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 428 | |
| 429 | /** |
| 430 | * @see #setDarkAmount(float, float) |
| 431 | */ |
| 432 | private float mInterpolatedDarkAmount = 0f; |
| 433 | |
| 434 | /** |
| 435 | * @see #setDarkAmount(float, float) |
| 436 | */ |
| 437 | private float mLinearDarkAmount = 0f; |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 438 | |
| 439 | /** |
| 440 | * How fast the background scales in the X direction as a factor of the Y expansion. |
| 441 | */ |
| 442 | private float mBackgroundXFactor = 1f; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 443 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 444 | private boolean mSwipingInProgress; |
| 445 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 446 | private boolean mUsingLightTheme; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 447 | private boolean mQsExpanded; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 448 | private boolean mForwardScrollable; |
| 449 | private boolean mBackwardScrollable; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 450 | private NotificationShelf mShelf; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 451 | private int mMaxDisplayedNotifications = -1; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 452 | private int mStatusBarHeight; |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 453 | private int mMinInteractionHeight; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 454 | private boolean mNoAmbient; |
| 455 | private final Rect mClipRect = new Rect(); |
| 456 | private boolean mIsClipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 457 | private Rect mRequestedClipBounds; |
| 458 | private boolean mInHeadsUpPinnedMode; |
| 459 | private boolean mHeadsUpAnimatingAway; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 460 | private int mStatusBarState; |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 461 | private int mCachedBackgroundColor; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 462 | private boolean mHeadsUpGoingAwayAnimationsAllowed = true; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 463 | private Runnable mReflingAndAnimateScroll = () -> { |
| 464 | if (ANCHOR_SCROLLING) { |
| 465 | maybeReflingScroller(); |
| 466 | } |
| 467 | animateScroll(); |
| 468 | }; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 469 | private int mCornerRadius; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 470 | private int mSidePaddings; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 471 | private final Rect mBackgroundAnimationRect = new Rect(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 472 | private int mAntiBurnInOffsetX; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 473 | private ArrayList<BiConsumer<Float, Float>> mExpandedHeightListeners = new ArrayList<>(); |
| 474 | private int mHeadsUpInset; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 475 | private HeadsUpAppearanceController mHeadsUpAppearanceController; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 476 | private NotificationIconAreaController mIconAreaController; |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 477 | private float mHorizontalPanelTranslation; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 478 | private final NotificationLockscreenUserManager mLockscreenUserManager = |
| 479 | Dependency.get(NotificationLockscreenUserManager.class); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 480 | protected final NotificationGutsManager mGutsManager = |
| 481 | Dependency.get(NotificationGutsManager.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 482 | private final Rect mTmpRect = new Rect(); |
| 483 | private final NotificationEntryManager mEntryManager = |
| 484 | Dependency.get(NotificationEntryManager.class); |
| 485 | private final IStatusBarService mBarService = IStatusBarService.Stub.asInterface( |
| 486 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 487 | @VisibleForTesting |
| 488 | protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 489 | private final NotificationRemoteInputManager mRemoteInputManager = |
| 490 | Dependency.get(NotificationRemoteInputManager.class); |
| 491 | private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
| 492 | |
| 493 | private final DisplayMetrics mDisplayMetrics = Dependency.get(DisplayMetrics.class); |
| 494 | private final LockscreenGestureLogger mLockscreenGestureLogger = |
| 495 | Dependency.get(LockscreenGestureLogger.class); |
| 496 | private final VisualStabilityManager mVisualStabilityManager = |
| 497 | Dependency.get(VisualStabilityManager.class); |
| 498 | protected boolean mClearAllEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 499 | |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 500 | private Interpolator mDarkXInterpolator = Interpolators.FAST_OUT_SLOW_IN; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 501 | private NotificationPanelView mNotificationPanel; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 502 | private final ShadeController mShadeController = Dependency.get(ShadeController.class); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 503 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 504 | private final NotificationGutsManager |
| 505 | mNotificationGutsManager = Dependency.get(NotificationGutsManager.class); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 506 | private final NotificationSectionsManager mSectionsManager; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 507 | /** |
| 508 | * If the {@link NotificationShelf} should be visible when dark. |
| 509 | */ |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 510 | private boolean mAnimateBottomOnLayout; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 511 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 512 | @Inject |
| 513 | public NotificationStackScrollLayout( |
| 514 | @Named(VIEW_CONTEXT) Context context, |
| 515 | AttributeSet attrs, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 516 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress, |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 517 | NotificationRoundnessManager notificationRoundnessManager, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 518 | AmbientPulseManager ambientPulseManager, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 519 | DynamicPrivacyController dynamicPrivacyController, |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 520 | ActivityStarter activityStarter, |
| 521 | StatusBarStateController statusBarStateController) { |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 522 | super(context, attrs, 0, 0); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 523 | Resources res = getResources(); |
| 524 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 525 | mAllowLongPress = allowLongPress; |
| 526 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 527 | for (int i = 0; i < NUM_SECTIONS; i++) { |
| 528 | mSections[i] = new NotificationSection(this); |
| 529 | } |
| 530 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 531 | mAmbientPulseManager = ambientPulseManager; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 532 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 533 | mSectionsManager = |
| 534 | new NotificationSectionsManager( |
| 535 | this, |
| 536 | activityStarter, |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 537 | statusBarStateController, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 538 | NotificationUtils.useNewInterruptionModel(context)); |
| 539 | mSectionsManager.inflateViews(context); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 540 | mSectionsManager.setOnClearGentleNotifsClickListener(v -> { |
| 541 | // Leave the shade open if there will be other notifs left over to clear |
| 542 | final boolean closeShade = !hasActiveClearableNotifications(ROWS_HIGH_PRIORITY); |
| 543 | clearNotifications(ROWS_GENTLE, closeShade); |
| 544 | }); |
| 545 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 546 | mAmbientState = new AmbientState(context, mSectionsManager); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 547 | mRoundnessManager = notificationRoundnessManager; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 548 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 549 | int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 550 | int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 551 | mExpandHelper = new ExpandHelper(getContext(), mExpandHelperCallback, |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 552 | minHeight, maxHeight); |
| 553 | mExpandHelper.setEventSource(this); |
| 554 | mExpandHelper.setScrollAdapter(this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 555 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, mNotificationCallback, |
| 556 | getContext(), mMenuEventListener); |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 557 | mStackScrollAlgorithm = createStackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 558 | initView(context); |
Dave Mankoff | dde5ee6 | 2019-05-02 17:36:11 -0400 | [diff] [blame] | 559 | mFalsingManager = FalsingManagerFactory.getInstance(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 560 | mShouldDrawNotificationBackground = |
| 561 | res.getBoolean(R.bool.config_drawNotificationBackground); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 562 | mFadeNotificationsOnDismiss = |
| 563 | res.getBoolean(R.bool.config_fadeNotificationsOnDismiss); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 564 | mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated); |
| 565 | mRoundnessManager.setOnRoundingChangedCallback(this::invalidate); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 566 | addOnExpandedHeightListener(mRoundnessManager::setExpanded); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 567 | setOutlineProvider(mOutlineProvider); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 568 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 569 | // Blocking helper manager wants to know the expanded state, update as well. |
| 570 | NotificationBlockingHelperManager blockingHelperManager = |
| 571 | Dependency.get(NotificationBlockingHelperManager.class); |
| 572 | addOnExpandedHeightListener((height, unused) -> { |
| 573 | blockingHelperManager.setNotificationShadeExpanded(height); |
| 574 | }); |
| 575 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 576 | updateWillNotDraw(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 577 | mBackgroundPaint.setAntiAlias(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 578 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 579 | mDebugPaint = new Paint(); |
| 580 | mDebugPaint.setColor(0xffff0000); |
| 581 | mDebugPaint.setStrokeWidth(2); |
| 582 | mDebugPaint.setStyle(Paint.Style.STROKE); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 583 | mDebugPaint.setTextSize(25f); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 584 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 585 | mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 586 | |
| 587 | TunerService tunerService = Dependency.get(TunerService.class); |
| 588 | tunerService.addTunable((key, newValue) -> { |
| 589 | if (key.equals(LOW_PRIORITY)) { |
| 590 | mLowPriorityBeforeSpeedBump = "1".equals(newValue); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 591 | } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { |
| 592 | updateDismissRtlSetting("1".equals(newValue)); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 593 | } |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 594 | }, LOW_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL); |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 595 | |
| 596 | mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 597 | @Override |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 598 | public void onPostEntryUpdated(NotificationEntry entry) { |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 599 | if (!entry.notification.isClearable()) { |
| 600 | // The user may have performed a dismiss action on the notification, since it's |
| 601 | // not clearable we should snap it back. |
| 602 | snapViewIfNeeded(entry); |
| 603 | } |
| 604 | } |
| 605 | }); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 606 | dynamicPrivacyController.addListener(this); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 609 | private void updateDismissRtlSetting(boolean dismissRtl) { |
| 610 | mDismissRtl = dismissRtl; |
| 611 | for (int i = 0; i < getChildCount(); i++) { |
| 612 | View child = getChildAt(i); |
| 613 | if (child instanceof ExpandableNotificationRow) { |
| 614 | ((ExpandableNotificationRow) child).setDismissRtl(dismissRtl); |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 619 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 620 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 621 | protected void onFinishInflate() { |
| 622 | super.onFinishInflate(); |
| 623 | |
| 624 | inflateEmptyShadeView(); |
| 625 | inflateFooterView(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 626 | mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 627 | if (mAllowLongPress) { |
| 628 | setLongPressListener(mGutsManager::openGuts); |
| 629 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 632 | /** |
| 633 | * @return the height at which we will wake up when pulsing |
| 634 | */ |
| 635 | public float getPulseHeight() { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 636 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 637 | if (firstChild != null) { |
| 638 | return firstChild.getCollapsedHeight(); |
| 639 | } |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 640 | return 0f; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 641 | } |
| 642 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 643 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 644 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 645 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 646 | reinflateViews(); |
| 647 | } |
| 648 | |
| 649 | private void reinflateViews() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 650 | inflateFooterView(); |
| 651 | inflateEmptyShadeView(); |
| 652 | updateFooter(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 653 | mSectionsManager.inflateViews(mContext); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 657 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 658 | public void onThemeChanged() { |
| 659 | int which; |
| 660 | if (mStatusBarState == StatusBarState.KEYGUARD |
| 661 | || mStatusBarState == StatusBarState.SHADE_LOCKED) { |
| 662 | which = WallpaperManager.FLAG_LOCK; |
| 663 | } else { |
| 664 | which = WallpaperManager.FLAG_SYSTEM; |
| 665 | } |
| 666 | final boolean useDarkText = mColorExtractor.getColors(which, |
| 667 | true /* ignoreVisibility */).supportsDarkText(); |
| 668 | updateDecorViews(useDarkText); |
| 669 | |
| 670 | updateFooter(); |
| 671 | } |
| 672 | |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 673 | @Override |
| 674 | public void onOverlayChanged() { |
| 675 | int newRadius = mContext.getResources().getDimensionPixelSize( |
| 676 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
| 677 | if (mCornerRadius != newRadius) { |
| 678 | mCornerRadius = newRadius; |
| 679 | invalidate(); |
| 680 | } |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 681 | reinflateViews(); |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 682 | } |
| 683 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 684 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 685 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 686 | public void updateFooter() { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 687 | boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 688 | boolean showFooterView = (showDismissView || |
| 689 | mEntryManager.getNotificationData().getActiveNotifications().size() != 0) |
| 690 | && mStatusBarState != StatusBarState.KEYGUARD |
| 691 | && !mRemoteInputManager.getController().isRemoteInputActive(); |
| 692 | |
| 693 | updateFooterView(showFooterView, showDismissView); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * Return whether there are any clearable notifications |
| 698 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 699 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 700 | public boolean hasActiveClearableNotifications(@SelectedRows int selection) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 701 | int childCount = getChildCount(); |
| 702 | for (int i = 0; i < childCount; i++) { |
| 703 | View child = getChildAt(i); |
| 704 | if (!(child instanceof ExpandableNotificationRow)) { |
| 705 | continue; |
| 706 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 707 | final ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 708 | if (row.canViewBeDismissed() && matchesSelection(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 709 | return true; |
| 710 | } |
| 711 | } |
| 712 | return false; |
| 713 | } |
| 714 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 715 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 716 | public RemoteInputController.Delegate createDelegate() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 717 | return new RemoteInputController.Delegate() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 718 | public void setRemoteInputActive(NotificationEntry entry, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 719 | boolean remoteInputActive) { |
| 720 | mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 721 | entry.notifyHeightChanged(true /* needsAnimation */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 722 | updateFooter(); |
| 723 | } |
| 724 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 725 | public void lockScrollTo(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 726 | NotificationStackScrollLayout.this.lockScrollTo(entry.getRow()); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | public void requestDisallowLongPressAndDismiss() { |
| 730 | requestDisallowLongPress(); |
| 731 | requestDisallowDismiss(); |
| 732 | } |
| 733 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 734 | } |
| 735 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 736 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 737 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 738 | protected void onAttachedToWindow() { |
| 739 | super.onAttachedToWindow(); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 740 | ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class)) |
| 741 | .addCallback(mStateListener, SysuiStatusBarStateController.RANK_STACK_SCROLLER); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 742 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 746 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 747 | protected void onDetachedFromWindow() { |
| 748 | super.onDetachedFromWindow(); |
Jason Monk | af08c15 | 2018-12-04 11:12:39 -0500 | [diff] [blame] | 749 | Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 750 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | @Override |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 754 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 755 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 756 | return mSwipeHelper; |
| 757 | } |
| 758 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 759 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 760 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 761 | public void onUiModeChanged() { |
| 762 | mBgColor = mContext.getColor(R.color.notification_shade_background_color); |
| 763 | updateBackgroundDimming(); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 764 | mShelf.onUiModeChanged(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 765 | mSectionsManager.onUiModeChanged(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 768 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 769 | protected void onDraw(Canvas canvas) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 770 | if (mShouldDrawNotificationBackground |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 771 | && (mSections[0].getCurrentBounds().top |
| 772 | < mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 773 | || mAmbientState.isDozing())) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 774 | drawBackground(canvas); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 775 | } else if (mInHeadsUpPinnedMode || mHeadsUpAnimatingAway) { |
| 776 | drawHeadsUpBackground(canvas); |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 777 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 778 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 779 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 780 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 781 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 782 | y = getLayoutHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 783 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 784 | y = getHeight() - getEmptyBottomMargin(); |
| 785 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 789 | @Override |
| 790 | public void draw(Canvas canvas) { |
| 791 | super.draw(canvas); |
| 792 | |
| 793 | if (DEBUG && ANCHOR_SCROLLING) { |
| 794 | if (mScrollAnchorView instanceof ExpandableNotificationRow) { |
| 795 | canvas.drawRect(0, |
| 796 | mScrollAnchorView.getTranslationY(), |
| 797 | getWidth(), |
| 798 | mScrollAnchorView.getTranslationY() |
| 799 | + ((ExpandableNotificationRow) mScrollAnchorView).getActualHeight(), |
| 800 | mDebugPaint); |
| 801 | canvas.drawText(Integer.toString(mScrollAnchorViewY), getWidth() - 200, |
| 802 | mScrollAnchorView.getTranslationY() + 30, mDebugPaint); |
| 803 | int y = (int) mShelf.getTranslationY(); |
| 804 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 805 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 806 | canvas.drawText(Integer.toString(getMaxNegativeScrollAmount()), getWidth() - 100, |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame^] | 807 | getTopPadding() + 30, mDebugPaint); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 808 | canvas.drawText(Integer.toString(getMaxPositiveScrollAmount()), getWidth() - 100, |
| 809 | getHeight() - 30, mDebugPaint); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 813 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 814 | private void drawBackground(Canvas canvas) { |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 815 | int lockScreenLeft = mSidePaddings; |
| 816 | int lockScreenRight = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 817 | int lockScreenTop = mSections[0].getCurrentBounds().top; |
| 818 | int lockScreenBottom = mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom; |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 819 | int darkLeft = getWidth() / 2; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 820 | int darkTop = mTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 821 | |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 822 | float yProgress = 1 - mInterpolatedDarkAmount; |
| 823 | float xProgress = mDarkXInterpolator.getInterpolation( |
| 824 | (1 - mLinearDarkAmount) * mBackgroundXFactor); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 825 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 826 | int left = (int) MathUtils.lerp(darkLeft, lockScreenLeft, xProgress); |
| 827 | int right = (int) MathUtils.lerp(darkLeft, lockScreenRight, xProgress); |
| 828 | int top = (int) MathUtils.lerp(darkTop, lockScreenTop, yProgress); |
| 829 | int bottom = (int) MathUtils.lerp(darkTop, lockScreenBottom, yProgress); |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 830 | mBackgroundAnimationRect.set( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 831 | left, |
| 832 | top, |
| 833 | right, |
| 834 | bottom); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 835 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 836 | int backgroundTopAnimationOffset = top - lockScreenTop; |
| 837 | // TODO(kprevas): this may not be necessary any more since we don't display the shelf in AOD |
| 838 | boolean anySectionHasVisibleChild = false; |
| 839 | for (NotificationSection section : mSections) { |
| 840 | if (section.getFirstVisibleChild() != null) { |
| 841 | anySectionHasVisibleChild = true; |
| 842 | break; |
| 843 | } |
| 844 | } |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 845 | if (!mAmbientState.isDozing() || anySectionHasVisibleChild) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 846 | drawBackgroundRects(canvas, left, right, top, backgroundTopAnimationOffset); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 847 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 848 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 849 | updateClipping(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 852 | /** |
| 853 | * Draws round rects for each background section. |
| 854 | * |
| 855 | * We want to draw a round rect for each background section as defined by {@link #mSections}. |
| 856 | * However, if two sections are directly adjacent with no gap between them (e.g. on the |
| 857 | * lockscreen where the shelf can appear directly below the high priority section, or while |
| 858 | * scrolling the shade so that the top of the shelf is right at the bottom of the high priority |
| 859 | * section), we don't want to round the adjacent corners. |
| 860 | * |
| 861 | * Since {@link Canvas} doesn't provide a way to draw a half-rounded rect, this means that we |
| 862 | * need to coalesce the backgrounds for adjacent sections and draw them as a single round rect. |
| 863 | * This method tracks the top of each rect we need to draw, then iterates through the visible |
| 864 | * sections. If a section is not adjacent to the previous section, we draw the previous rect |
| 865 | * behind the sections we've accumulated up to that point, then start a new rect at the top of |
| 866 | * the current section. When we're done iterating we will always have one rect left to draw. |
| 867 | */ |
| 868 | private void drawBackgroundRects(Canvas canvas, int left, int right, int top, |
| 869 | int animationYOffset) { |
| 870 | int backgroundRectTop = top; |
| 871 | int lastSectionBottom = |
| 872 | mSections[0].getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 873 | int previousLeft = left; |
| 874 | boolean first = true; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 875 | for (NotificationSection section : mSections) { |
| 876 | if (section.getFirstVisibleChild() == null) { |
| 877 | continue; |
| 878 | } |
| 879 | int sectionTop = section.getCurrentBounds().top + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 880 | int ownLeft = Math.min(Math.max(left, section.getCurrentBounds().left), right); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 881 | // If sections are directly adjacent to each other, we don't want to draw them |
| 882 | // as separate roundrects, as the rounded corners right next to each other look |
| 883 | // bad. |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 884 | if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX |
| 885 | || (previousLeft != ownLeft && !first)) { |
| 886 | canvas.drawRoundRect(ownLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 887 | backgroundRectTop, |
| 888 | right, |
| 889 | lastSectionBottom, |
| 890 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 891 | backgroundRectTop = sectionTop; |
| 892 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 893 | previousLeft = ownLeft; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 894 | lastSectionBottom = |
| 895 | section.getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 896 | first = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 897 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 898 | canvas.drawRoundRect(previousLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 899 | backgroundRectTop, |
| 900 | right, |
| 901 | lastSectionBottom, |
| 902 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 903 | } |
| 904 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 905 | private void drawHeadsUpBackground(Canvas canvas) { |
| 906 | int left = mSidePaddings; |
| 907 | int right = getWidth() - mSidePaddings; |
| 908 | |
| 909 | float top = getHeight(); |
| 910 | float bottom = 0; |
| 911 | int childCount = getChildCount(); |
| 912 | for (int i = 0; i < childCount; i++) { |
| 913 | View child = getChildAt(i); |
| 914 | if (child.getVisibility() != View.GONE |
| 915 | && child instanceof ExpandableNotificationRow) { |
| 916 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 917 | if ((row.isPinned() || row.isHeadsUpAnimatingAway()) && row.getTranslation() < 0 |
| 918 | && row.getProvider().shouldShowGutsOnSnapOpen()) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 919 | top = Math.min(top, row.getTranslationY()); |
| 920 | bottom = Math.max(bottom, row.getTranslationY() + row.getActualHeight()); |
| 921 | } |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | if (top < bottom) { |
| 926 | canvas.drawRoundRect( |
| 927 | left, top, right, bottom, |
| 928 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 929 | } |
| 930 | } |
| 931 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 932 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 933 | private void updateBackgroundDimming() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 934 | // No need to update the background color if it's not being drawn. |
| 935 | if (!mShouldDrawNotificationBackground) { |
| 936 | return; |
| 937 | } |
| 938 | |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 939 | float alpha = |
| 940 | BACKGROUND_ALPHA_DIMMED + (1 - BACKGROUND_ALPHA_DIMMED) * (1.0f - mDimAmount); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 941 | alpha *= 1f - mInterpolatedDarkAmount; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 942 | // We need to manually blend in the background color. |
| 943 | int scrimColor = mScrimController.getBackgroundColor(); |
| 944 | int awakeColor = ColorUtils.blendARGB(scrimColor, mBgColor, alpha); |
| 945 | |
| 946 | // Interpolate between semi-transparent notification panel background color |
| 947 | // and white AOD separator. |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 948 | float colorInterpolation = MathUtils.smoothStep(0.4f /* start */, 1f /* end */, |
| 949 | mLinearDarkAmount); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 950 | int color = ColorUtils.blendARGB(awakeColor, Color.WHITE, colorInterpolation); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 951 | |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 952 | if (mCachedBackgroundColor != color) { |
| 953 | mCachedBackgroundColor = color; |
| 954 | mBackgroundPaint.setColor(color); |
| 955 | invalidate(); |
| 956 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 957 | } |
| 958 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 959 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 960 | private void initView(Context context) { |
| 961 | mScroller = new OverScroller(getContext()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 962 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 963 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 964 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 965 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 966 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 967 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 968 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 969 | |
| 970 | Resources res = context.getResources(); |
| 971 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 972 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 973 | mAmbientState.reload(context); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 974 | mPaddingBetweenElements = Math.max(1, |
| 975 | res.getDimensionPixelSize(R.dimen.notification_divider_height)); |
| 976 | mIncreasedPaddingBetweenElements = |
| 977 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 978 | mMinTopOverScrollToEscape = res.getDimensionPixelSize( |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 979 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 980 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 981 | mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 982 | mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 983 | mMinInteractionHeight = res.getDimensionPixelSize( |
| 984 | R.dimen.notification_min_interaction_height); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 985 | mCornerRadius = res.getDimensionPixelSize( |
| 986 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 987 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 988 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 989 | } |
| 990 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 991 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 992 | private void notifyHeightChangeListener(ExpandableView view) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 993 | notifyHeightChangeListener(view, false /* needsAnimation */); |
| 994 | } |
| 995 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 996 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 997 | private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) { |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 998 | if (mOnHeightChangedListener != null) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 999 | mOnHeightChangedListener.onHeightChanged(view, needsAnimation); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 1000 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1004 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1005 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1006 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 1007 | |
| 1008 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 1009 | int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2, |
| 1010 | MeasureSpec.getMode(widthMeasureSpec)); |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1011 | // Don't constrain the height of the children so we know how big they'd like to be |
| 1012 | int childHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), |
| 1013 | MeasureSpec.UNSPECIFIED); |
| 1014 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1015 | // We need to measure all children even the GONE ones, such that the heights are calculated |
| 1016 | // correctly as they are used to calculate how many we can fit on the screen. |
| 1017 | final int size = getChildCount(); |
| 1018 | for (int i = 0; i < size; i++) { |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1019 | measureChild(getChildAt(i), childWidthSpec, childHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1020 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1024 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1025 | 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] | 1026 | // we layout all our children centered on the top |
| 1027 | float centerX = getWidth() / 2.0f; |
| 1028 | for (int i = 0; i < getChildCount(); i++) { |
| 1029 | View child = getChildAt(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1030 | // We need to layout all children even the GONE ones, such that the heights are |
| 1031 | // 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] | 1032 | float width = child.getMeasuredWidth(); |
| 1033 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1034 | child.layout((int) (centerX - width / 2.0f), |
| 1035 | 0, |
| 1036 | (int) (centerX + width / 2.0f), |
| 1037 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1038 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 1039 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1040 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1041 | clampScrollPosition(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1042 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1043 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1044 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1047 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1048 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 1049 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1050 | mNeedViewResizeAnimation = true; |
| 1051 | mNeedsAnimation = true; |
| 1052 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1053 | } |
| 1054 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1055 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1056 | public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) { |
| 1057 | mAmbientState.setSpeedBumpIndex(newIndex); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1058 | mNoAmbient = noAmbient; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1059 | } |
| 1060 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1061 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1062 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1063 | public void setChildLocationsChangedListener( |
| 1064 | NotificationLogger.OnChildLocationsChangedListener listener) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1065 | mListener = listener; |
| 1066 | } |
| 1067 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1068 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1069 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1070 | public boolean isInVisibleLocation(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1071 | ExpandableNotificationRow row = entry.getRow(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1072 | ExpandableViewState childViewState = row.getViewState(); |
| 1073 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1074 | if (childViewState == null) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1075 | return false; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1076 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 1077 | if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1078 | return false; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 1079 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1080 | if (row.getVisibility() != View.VISIBLE) { |
| 1081 | return false; |
| 1082 | } |
| 1083 | return true; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1084 | } |
| 1085 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1086 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1087 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 1088 | mMaxLayoutHeight = maxLayoutHeight; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 1089 | mShelf.setMaxLayoutHeight(maxLayoutHeight); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1090 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1093 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1094 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1095 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1096 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1097 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1100 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1101 | private void updateAlgorithmLayoutMinHeight() { |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 1102 | mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition() |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1103 | ? getLayoutMinHeight() : 0); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1106 | /** |
| 1107 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 1108 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 1109 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1110 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1111 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1112 | updateScrollStateForAddedChildren(); |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 1113 | mAmbientState.setCurrentScrollVelocity(mScroller.isFinished() |
| 1114 | ? 0 |
| 1115 | : mScroller.getCurrVelocity()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1116 | if (ANCHOR_SCROLLING) { |
| 1117 | mAmbientState.setAnchorViewIndex(indexOfChild(mScrollAnchorView)); |
| 1118 | mAmbientState.setAnchorViewY(mScrollAnchorViewY); |
| 1119 | } else { |
| 1120 | mAmbientState.setScrollY(mOwnScrollY); |
| 1121 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1122 | mStackScrollAlgorithm.resetViewStates(mAmbientState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1123 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1124 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1125 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1126 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1130 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1131 | private void onPreDrawDuringAnimation() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1132 | mShelf.updateAppearance(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1133 | updateClippingToTopRoundedCorner(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1134 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 1135 | updateBackground(); |
| 1136 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1139 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1140 | private void updateClippingToTopRoundedCorner() { |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1141 | Float clipStart = (float) mTopPadding |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1142 | + mStackTranslation |
| 1143 | + mAmbientState.getExpandAnimationTopChange(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1144 | Float clipEnd = clipStart + mCornerRadius; |
| 1145 | boolean first = true; |
| 1146 | for (int i = 0; i < getChildCount(); i++) { |
| 1147 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1148 | if (child.getVisibility() == GONE) { |
| 1149 | continue; |
| 1150 | } |
| 1151 | float start = child.getTranslationY(); |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1152 | float end = start + child.getActualHeight(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1153 | boolean clip = clipStart > start && clipStart < end |
| 1154 | || clipEnd >= start && clipEnd <= end; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1155 | clip &= !(first && isScrolledToTop()); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 1156 | child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0) |
| 1157 | : ExpandableView.NO_ROUNDNESS); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1158 | first = false; |
| 1159 | } |
| 1160 | } |
| 1161 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1162 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1163 | private void updateScrollStateForAddedChildren() { |
| 1164 | if (mChildrenToAddAnimated.isEmpty()) { |
| 1165 | return; |
| 1166 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1167 | if (!ANCHOR_SCROLLING) { |
| 1168 | for (int i = 0; i < getChildCount(); i++) { |
| 1169 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1170 | if (mChildrenToAddAnimated.contains(child)) { |
| 1171 | int startingPosition = getPositionInLinearLayout(child); |
| 1172 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
| 1173 | int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements |
| 1174 | : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements; |
| 1175 | int childHeight = getIntrinsicHeight(child) + padding; |
| 1176 | if (startingPosition < mOwnScrollY) { |
| 1177 | // This child starts off screen, so let's keep it offscreen to keep the |
| 1178 | // others visible |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1179 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1180 | setOwnScrollY(mOwnScrollY + childHeight); |
| 1181 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | clampScrollPosition(); |
| 1186 | } |
| 1187 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1188 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1189 | private void updateForcedScroll() { |
| 1190 | if (mForcedScroll != null && (!mForcedScroll.hasFocus() |
| 1191 | || !mForcedScroll.isAttachedToWindow())) { |
| 1192 | mForcedScroll = null; |
| 1193 | } |
| 1194 | if (mForcedScroll != null) { |
| 1195 | ExpandableView expandableView = (ExpandableView) mForcedScroll; |
| 1196 | int positionInLinearLayout = getPositionInLinearLayout(expandableView); |
| 1197 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1198 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1199 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1200 | if (ANCHOR_SCROLLING) { |
| 1201 | // TODO |
| 1202 | } else { |
| 1203 | targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange())); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1204 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1205 | // Only apply the scroll if we're scrolling the view upwards, or the view is so |
| 1206 | // far up that it is not visible anymore. |
| 1207 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1208 | setOwnScrollY(targetScroll); |
| 1209 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | } |
| 1213 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1214 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1215 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 1216 | if (!mChildrenUpdateRequested) { |
| 1217 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 1218 | mChildrenUpdateRequested = true; |
| 1219 | invalidate(); |
| 1220 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 1223 | /** |
| 1224 | * Returns best effort count of visible notifications. |
| 1225 | */ |
| 1226 | public int getVisibleNotificationCount() { |
| 1227 | int count = 0; |
| 1228 | for (int i = 0; i < getChildCount(); i++) { |
| 1229 | final View child = getChildAt(i); |
| 1230 | if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) { |
| 1231 | count++; |
| 1232 | } |
| 1233 | } |
| 1234 | return count; |
| 1235 | } |
| 1236 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1237 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1238 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1239 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1240 | } |
| 1241 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1242 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1243 | private void clampScrollPosition() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1244 | if (ANCHOR_SCROLLING) { |
| 1245 | // TODO |
| 1246 | } else { |
| 1247 | int scrollRange = getScrollRange(); |
| 1248 | if (scrollRange < mOwnScrollY) { |
| 1249 | setOwnScrollY(scrollRange); |
| 1250 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1254 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1255 | public int getTopPadding() { |
| 1256 | return mTopPadding; |
| 1257 | } |
| 1258 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1259 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1260 | private void setTopPadding(int topPadding, boolean animate) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 1261 | if (mTopPadding != topPadding) { |
| 1262 | mTopPadding = topPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1263 | updateAlgorithmHeightAndPadding(); |
| 1264 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1265 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1266 | mTopPaddingNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1267 | mNeedsAnimation = true; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1268 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1269 | requestChildrenUpdate(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1270 | notifyHeightChangeListener(null, animate); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | /** |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1275 | * Update the height of the panel. |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1276 | * |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1277 | * @param height the expanded height of the panel |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1278 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1279 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1280 | public void setExpandedHeight(float height) { |
| 1281 | mExpandedHeight = height; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1282 | setIsExpanded(height > 0); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1283 | int minExpansionHeight = getMinExpansionHeight(); |
| 1284 | if (height < minExpansionHeight) { |
| 1285 | mClipRect.left = 0; |
| 1286 | mClipRect.right = getWidth(); |
| 1287 | mClipRect.top = 0; |
| 1288 | mClipRect.bottom = (int) height; |
| 1289 | height = minExpansionHeight; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1290 | setRequestedClipBounds(mClipRect); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1291 | } else { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1292 | setRequestedClipBounds(null); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1293 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1294 | int stackHeight; |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1295 | float translationY; |
| 1296 | float appearEndPosition = getAppearEndPosition(); |
| 1297 | float appearStartPosition = getAppearStartPosition(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1298 | float appearFraction = 1.0f; |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 1299 | boolean appearing = height < appearEndPosition; |
| 1300 | mAmbientState.setAppearing(appearing); |
| 1301 | if (!appearing) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1302 | translationY = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 1303 | if (mShouldShowShelfOnly) { |
| 1304 | stackHeight = mTopPadding + mShelf.getIntrinsicHeight(); |
| 1305 | } else if (mQsExpanded) { |
| 1306 | int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding; |
| 1307 | int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight(); |
| 1308 | if (stackStartPosition <= stackEndPosition) { |
| 1309 | stackHeight = stackEndPosition; |
| 1310 | } else { |
| 1311 | stackHeight = (int) NotificationUtils.interpolate(stackStartPosition, |
| 1312 | stackEndPosition, mQsExpansionFraction); |
| 1313 | } |
| 1314 | } else { |
| 1315 | stackHeight = (int) height; |
| 1316 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1317 | } else { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1318 | appearFraction = getAppearFraction(height); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1319 | if (appearFraction >= 0) { |
| 1320 | translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0, |
| 1321 | appearFraction); |
| 1322 | } else { |
| 1323 | // This may happen when pushing up a heads up. We linearly push it up from the |
| 1324 | // start |
| 1325 | translationY = height - appearStartPosition + getExpandTranslationStart(); |
| 1326 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1327 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1328 | stackHeight = |
| 1329 | getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1330 | translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction); |
| 1331 | } else { |
| 1332 | stackHeight = (int) (height - translationY); |
| 1333 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1334 | } |
| 1335 | if (stackHeight != mCurrentStackHeight) { |
| 1336 | mCurrentStackHeight = stackHeight; |
| 1337 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1338 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1339 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1340 | setStackTranslation(translationY); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1341 | for (int i = 0; i < mExpandedHeightListeners.size(); i++) { |
| 1342 | BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i); |
| 1343 | listener.accept(mExpandedHeight, appearFraction); |
| 1344 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1347 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1348 | private void setRequestedClipBounds(Rect clipRect) { |
| 1349 | mRequestedClipBounds = clipRect; |
| 1350 | updateClipping(); |
| 1351 | } |
| 1352 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1353 | /** |
| 1354 | * Return the height of the content ignoring the footer. |
| 1355 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1356 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1357 | public int getIntrinsicContentHeight() { |
| 1358 | return mIntrinsicContentHeight; |
| 1359 | } |
| 1360 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1361 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1362 | public void updateClipping() { |
| 1363 | boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode |
| 1364 | && !mHeadsUpAnimatingAway; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1365 | boolean clipToOutline = false; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1366 | if (mIsClipped != clipped) { |
| 1367 | mIsClipped = clipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1368 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1369 | |
Selim Cinek | 1e05927 | 2019-05-21 18:15:00 -0700 | [diff] [blame] | 1370 | if (!mAmbientPulseManager.hasNotifications() && mAmbientState.isFullyDark()) { |
Lucas Dupin | 4798ea1 | 2018-11-05 19:26:24 -0800 | [diff] [blame] | 1371 | setClipBounds(null); |
| 1372 | } else if (mAmbientState.isDarkAtAll()) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1373 | clipToOutline = true; |
| 1374 | invalidateOutline(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1375 | } else if (clipped) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1376 | setClipBounds(mRequestedClipBounds); |
| 1377 | } else { |
| 1378 | setClipBounds(null); |
| 1379 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1380 | |
| 1381 | setClipToOutline(clipToOutline); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * @return The translation at the beginning when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1386 | * Measured relative to the resting position. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1387 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1388 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1389 | private float getExpandTranslationStart() { |
Selim Cinek | 083f214 | 2018-11-06 16:32:23 -0800 | [diff] [blame] | 1390 | return -mTopPadding + getMinExpansionHeight() - mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | /** |
| 1394 | * @return the position from where the appear transition starts when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1395 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1396 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1397 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1398 | private float getAppearStartPosition() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1399 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1400 | return mHeadsUpInset |
| 1401 | + getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1402 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1403 | return getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1407 | * @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] | 1408 | * intrinsic height, which also includes whether the notification is system expanded and |
| 1409 | * is mainly used when dragging down from a heads up notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1410 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1411 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1412 | private int getTopHeadsUpPinnedHeight() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1413 | NotificationEntry topEntry = mHeadsUpManager.getTopEntry(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1414 | if (topEntry == null) { |
| 1415 | return 0; |
| 1416 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1417 | ExpandableNotificationRow row = topEntry.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1418 | if (row.isChildInGroup()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1419 | final NotificationEntry groupSummary |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1420 | = mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 1421 | if (groupSummary != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1422 | row = groupSummary.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | return row.getPinnedHeadsUpHeight(); |
| 1426 | } |
| 1427 | |
| 1428 | /** |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1429 | * @return the position from where the appear transition ends when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1430 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1431 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1432 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1433 | private float getAppearEndPosition() { |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1434 | int appearPosition; |
Selim Cinek | 66440cf | 2017-05-26 13:48:47 -0700 | [diff] [blame] | 1435 | int notGoneChildCount = getNotGoneChildCount(); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 1436 | if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1437 | if (isHeadsUpTransition() |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 1438 | || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1439 | appearPosition = getTopHeadsUpPinnedHeight(); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1440 | } else { |
| 1441 | appearPosition = 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1442 | if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) { |
| 1443 | appearPosition += mShelf.getIntrinsicHeight(); |
| 1444 | } |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1445 | } |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1446 | } else { |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1447 | appearPosition = mEmptyShadeView.getHeight(); |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1448 | } |
| 1449 | return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1452 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1453 | private boolean isHeadsUpTransition() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1454 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 1455 | return mTrackingHeadsUp && firstVisibleSection != null |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 1456 | && firstVisibleSection.getFirstVisibleChild().isAboveShelf(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1457 | } |
| 1458 | |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1459 | /** |
| 1460 | * @param height the height of the panel |
| 1461 | * @return the fraction of the appear animation that has been performed |
| 1462 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1463 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1464 | public float getAppearFraction(float height) { |
| 1465 | float appearEndPosition = getAppearEndPosition(); |
| 1466 | float appearStartPosition = getAppearStartPosition(); |
| 1467 | return (height - appearStartPosition) |
| 1468 | / (appearEndPosition - appearStartPosition); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1471 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1472 | public float getStackTranslation() { |
| 1473 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1476 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1477 | private void setStackTranslation(float stackTranslation) { |
| 1478 | if (stackTranslation != mStackTranslation) { |
| 1479 | mStackTranslation = stackTranslation; |
| 1480 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1481 | requestChildrenUpdate(); |
| 1482 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1486 | * 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] | 1487 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 1488 | * |
| 1489 | * @return either the layout height or the externally defined height, whichever is smaller |
| 1490 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1491 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1492 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1493 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 1494 | } |
| 1495 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1496 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1497 | public int getFirstItemMinHeight() { |
| 1498 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1499 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1500 | } |
| 1501 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1502 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1503 | public void setQsContainer(ViewGroup qsContainer) { |
| 1504 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1507 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1508 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1509 | if (v instanceof ExpandableNotificationRow) { |
| 1510 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1511 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1512 | } |
| 1513 | return false; |
| 1514 | } |
| 1515 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1516 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1517 | private boolean isHeadsUp(View v) { |
| 1518 | if (v instanceof ExpandableNotificationRow) { |
| 1519 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1520 | return row.isHeadsUp(); |
| 1521 | } |
| 1522 | return false; |
| 1523 | } |
| 1524 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1525 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1526 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 1527 | getLocationOnScreen(mTempInt2); |
| 1528 | float localTouchY = touchY - mTempInt2[1]; |
| 1529 | |
| 1530 | ExpandableView closestChild = null; |
| 1531 | float minDist = Float.MAX_VALUE; |
| 1532 | |
| 1533 | // find the view closest to the location, accounting for GONE views |
| 1534 | final int count = getChildCount(); |
| 1535 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 1536 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 1537 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1538 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1539 | continue; |
| 1540 | } |
| 1541 | float childTop = slidingChild.getTranslationY(); |
| 1542 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1543 | float bottom = childTop + slidingChild.getActualHeight() |
| 1544 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1545 | |
| 1546 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 1547 | if (dist < minDist) { |
| 1548 | closestChild = slidingChild; |
| 1549 | minDist = dist; |
| 1550 | } |
| 1551 | } |
| 1552 | return closestChild; |
| 1553 | } |
| 1554 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1555 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
| 1556 | private ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1557 | return getChildAtPosition(touchX, touchY, true /* requireMinHeight */); |
| 1558 | |
| 1559 | } |
| 1560 | |
| 1561 | /** |
| 1562 | * Get the child at a certain screen location. |
| 1563 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1564 | * @param touchX the x coordinate |
| 1565 | * @param touchY the y coordinate |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1566 | * @param requireMinHeight Whether a minimum height is required for a child to be returned. |
| 1567 | * @return the child at the given location. |
| 1568 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1569 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1570 | private ExpandableView getChildAtPosition(float touchX, float touchY, |
| 1571 | boolean requireMinHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1572 | // find the view under the pointer, accounting for GONE views |
| 1573 | final int count = getChildCount(); |
| 1574 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1575 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1576 | if (slidingChild.getVisibility() != VISIBLE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1577 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1578 | continue; |
| 1579 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 1580 | float childTop = slidingChild.getTranslationY(); |
| 1581 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1582 | float bottom = childTop + slidingChild.getActualHeight() |
| 1583 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 1584 | |
| 1585 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 1586 | // camera affordance). |
| 1587 | int left = 0; |
| 1588 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1589 | |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1590 | if ((bottom - top >= mMinInteractionHeight || !requireMinHeight) |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1591 | && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1592 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 1593 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1594 | NotificationEntry entry = row.getEntry(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1595 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1596 | && mHeadsUpManager.getTopEntry().getRow() != row |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1597 | && mGroupManager.getGroupSummary( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1598 | mHeadsUpManager.getTopEntry().notification) |
| 1599 | != entry) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1600 | continue; |
| 1601 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1602 | return row.getViewAtPosition(touchY - childTop); |
| 1603 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1604 | return slidingChild; |
| 1605 | } |
| 1606 | } |
| 1607 | return null; |
| 1608 | } |
| 1609 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1610 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1611 | getLocationOnScreen(mTempInt2); |
| 1612 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1615 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1616 | public void setScrollingEnabled(boolean enable) { |
| 1617 | mScrollingEnabled = enable; |
| 1618 | } |
| 1619 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1620 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1621 | public void lockScrollTo(View v) { |
| 1622 | if (mForcedScroll == v) { |
| 1623 | return; |
| 1624 | } |
| 1625 | mForcedScroll = v; |
| 1626 | scrollTo(v); |
| 1627 | } |
| 1628 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1629 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1630 | public boolean scrollTo(View v) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1631 | ExpandableView expandableView = (ExpandableView) v; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1632 | if (ANCHOR_SCROLLING) { |
| 1633 | // TODO |
| 1634 | } else { |
| 1635 | int positionInLinearLayout = getPositionInLinearLayout(v); |
| 1636 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
| 1637 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1638 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1639 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 1640 | // that it is not visible anymore. |
| 1641 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1642 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY); |
| 1643 | mDontReportNextOverScroll = true; |
| 1644 | animateScroll(); |
| 1645 | return true; |
| 1646 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1647 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1648 | return false; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1651 | /** |
| 1652 | * @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] | 1653 | * the IME. |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1654 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1655 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1656 | private int targetScrollForView(ExpandableView v, int positionInLinearLayout) { |
| 1657 | return positionInLinearLayout + v.getIntrinsicHeight() + |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 1658 | getImeInset() - getHeight() |
| 1659 | + ((!isExpanded() && isPinnedHeadsUp(v)) ? mHeadsUpInset : getTopPadding()); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1662 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1663 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1664 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1665 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1666 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1667 | if (ANCHOR_SCROLLING) { |
| 1668 | // TODO |
| 1669 | } else { |
| 1670 | int range = getScrollRange(); |
| 1671 | if (mOwnScrollY > range) { |
| 1672 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1673 | // animating away. To work around that we'll wait until things have settled. |
| 1674 | removeCallbacks(mReclamp); |
| 1675 | postDelayed(mReclamp, 50); |
| 1676 | } else if (mForcedScroll != null) { |
| 1677 | // The scroll was requested before we got the actual inset - in case we need |
| 1678 | // to scroll up some more do so now. |
| 1679 | scrollTo(mForcedScroll); |
| 1680 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1681 | } |
| 1682 | return insets; |
| 1683 | } |
| 1684 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1685 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1686 | private Runnable mReclamp = new Runnable() { |
| 1687 | @Override |
| 1688 | public void run() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1689 | if (ANCHOR_SCROLLING) { |
| 1690 | // TODO |
| 1691 | } else { |
| 1692 | int range = getScrollRange(); |
| 1693 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1694 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1695 | mDontReportNextOverScroll = true; |
| 1696 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1697 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1698 | } |
| 1699 | }; |
| 1700 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1701 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 1702 | public void setExpandingEnabled(boolean enable) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1703 | mExpandHelper.setEnabled(enable); |
| 1704 | } |
| 1705 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1706 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1707 | private boolean isScrollingEnabled() { |
| 1708 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1709 | } |
| 1710 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1711 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1712 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1713 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1714 | } |
| 1715 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1716 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1717 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1718 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1719 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1720 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1721 | float densityScale = getResources().getDisplayMetrics().density; |
| 1722 | mSwipeHelper.setDensityScale(densityScale); |
| 1723 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1724 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1725 | initView(getContext()); |
| 1726 | } |
| 1727 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1728 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1729 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1730 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1731 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1732 | } |
| 1733 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1734 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1735 | private void snapViewIfNeeded(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1736 | ExpandableNotificationRow child = entry.getRow(); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1737 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1738 | // If the child is showing the notification menu snap to that |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 1739 | if (child.getProvider() != null) { |
| 1740 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
| 1741 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
| 1742 | } |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1743 | } |
| 1744 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1745 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1746 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1747 | public ViewGroup getViewParentForNotification(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1748 | return this; |
| 1749 | } |
| 1750 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1751 | /** |
| 1752 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1753 | * |
| 1754 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1755 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1756 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1757 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1758 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1759 | private float overScrollUp(int deltaY, int range) { |
| 1760 | deltaY = Math.max(deltaY, 0); |
| 1761 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1762 | float newTopAmount = currentTopAmount - deltaY; |
| 1763 | if (currentTopAmount > 0) { |
| 1764 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1765 | false /* animate */); |
| 1766 | } |
| 1767 | // Top overScroll might not grab all scrolling motion, |
| 1768 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1769 | if (ANCHOR_SCROLLING) { |
| 1770 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1771 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1772 | ExpandableView lastRow = getLastRowNotGone(); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1773 | if (lastRow != null && !lastRow.isInShelf()) { |
| 1774 | float distanceToMax = Math.max(0, getMaxPositiveScrollAmount()); |
| 1775 | if (scrollAmount > distanceToMax) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1776 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1777 | // We overScroll on the bottom |
| 1778 | setOverScrolledPixels(currentBottomPixels + (scrollAmount - distanceToMax), |
| 1779 | false /* onTop */, |
| 1780 | false /* animate */); |
| 1781 | mScrollAnchorViewY -= distanceToMax; |
| 1782 | scrollAmount = 0f; |
| 1783 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1784 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1785 | return scrollAmount; |
| 1786 | } else { |
| 1787 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1788 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1789 | if (newScrollY > range) { |
| 1790 | if (!mExpandedInThisMotion) { |
| 1791 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1792 | // We overScroll on the bottom |
| 1793 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1794 | false /* onTop */, |
| 1795 | false /* animate */); |
| 1796 | } |
| 1797 | setOwnScrollY(range); |
| 1798 | scrollAmount = 0.0f; |
| 1799 | } |
| 1800 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1801 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | /** |
| 1805 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1806 | * |
| 1807 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1808 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1809 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1810 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1811 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1812 | private float overScrollDown(int deltaY) { |
| 1813 | deltaY = Math.min(deltaY, 0); |
| 1814 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1815 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1816 | if (currentBottomAmount > 0) { |
| 1817 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1818 | false /* animate */); |
| 1819 | } |
| 1820 | // Bottom overScroll might not grab all scrolling motion, |
| 1821 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1822 | if (ANCHOR_SCROLLING) { |
| 1823 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1824 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1825 | ExpandableView firstChild = getFirstChildNotGone(); |
| 1826 | float top = firstChild.getTranslationY(); |
| 1827 | float distanceToTop = mScrollAnchorView.getTranslationY() - top - mScrollAnchorViewY; |
| 1828 | if (distanceToTop < -scrollAmount) { |
| 1829 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1830 | // We overScroll on the top |
| 1831 | setOverScrolledPixels(currentTopPixels + (-scrollAmount - distanceToTop), |
| 1832 | true /* onTop */, |
| 1833 | false /* animate */); |
| 1834 | mScrollAnchorView = firstChild; |
| 1835 | mScrollAnchorViewY = 0; |
| 1836 | scrollAmount = 0f; |
| 1837 | } |
| 1838 | return scrollAmount; |
| 1839 | } else { |
| 1840 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1841 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1842 | if (newScrollY < 0) { |
| 1843 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1844 | // We overScroll on the top |
| 1845 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1846 | true /* onTop */, |
| 1847 | false /* animate */); |
| 1848 | setOwnScrollY(0); |
| 1849 | scrollAmount = 0.0f; |
| 1850 | } |
| 1851 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1852 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1853 | } |
| 1854 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1855 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1856 | private void initVelocityTrackerIfNotExists() { |
| 1857 | if (mVelocityTracker == null) { |
| 1858 | mVelocityTracker = VelocityTracker.obtain(); |
| 1859 | } |
| 1860 | } |
| 1861 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1862 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1863 | private void recycleVelocityTracker() { |
| 1864 | if (mVelocityTracker != null) { |
| 1865 | mVelocityTracker.recycle(); |
| 1866 | mVelocityTracker = null; |
| 1867 | } |
| 1868 | } |
| 1869 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1870 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1871 | private void initOrResetVelocityTracker() { |
| 1872 | if (mVelocityTracker == null) { |
| 1873 | mVelocityTracker = VelocityTracker.obtain(); |
| 1874 | } else { |
| 1875 | mVelocityTracker.clear(); |
| 1876 | } |
| 1877 | } |
| 1878 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1879 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1880 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1881 | mFinishScrollingCallback = runnable; |
| 1882 | } |
| 1883 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1884 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1885 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1886 | if (mScroller.computeScrollOffset()) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1887 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1888 | int oldY = mLastScrollerY; |
| 1889 | int y = mScroller.getCurrY(); |
| 1890 | int deltaY = y - oldY; |
| 1891 | if (deltaY != 0) { |
| 1892 | int maxNegativeScrollAmount = getMaxNegativeScrollAmount(); |
| 1893 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 1894 | if ((maxNegativeScrollAmount < 0 && deltaY < maxNegativeScrollAmount) |
| 1895 | || (maxPositiveScrollAmount > 0 && deltaY > maxPositiveScrollAmount)) { |
| 1896 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1897 | // the current velocity |
| 1898 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1899 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1900 | customOverScrollBy(deltaY, oldY, 0, (int) mMaxOverScroll); |
| 1901 | mLastScrollerY = y; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1902 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1903 | } else { |
| 1904 | int oldY = mOwnScrollY; |
| 1905 | int y = mScroller.getCurrY(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1906 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1907 | if (oldY != y) { |
| 1908 | int range = getScrollRange(); |
| 1909 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1910 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1911 | // the current velocity |
| 1912 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1913 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1914 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1915 | if (mDontClampNextScroll) { |
| 1916 | range = Math.max(range, oldY); |
| 1917 | } |
| 1918 | customOverScrollBy(y - oldY, oldY, range, |
| 1919 | (int) (mMaxOverScroll)); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1920 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1921 | } |
| 1922 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1923 | postOnAnimation(mReflingAndAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1924 | } else { |
| 1925 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1926 | if (mFinishScrollingCallback != null) { |
| 1927 | mFinishScrollingCallback.run(); |
| 1928 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1932 | private void setMaxOverScrollFromCurrentVelocity() { |
| 1933 | float currVelocity = mScroller.getCurrVelocity(); |
| 1934 | if (currVelocity >= mMinimumVelocity) { |
| 1935 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1936 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1937 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1938 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1939 | /** |
| 1940 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 1941 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 1942 | * |
| 1943 | * This method performs the determination of whether we're exceeding the overscroll and clamps |
| 1944 | * the scroll amount if so. The actual scrolling/overscrolling happens in |
| 1945 | * {@link #onCustomOverScrolled(int, boolean)} (absolute scrolling) or |
| 1946 | * {@link #onCustomOverScrolledBy(int, boolean)} (anchor scrolling). |
| 1947 | * |
| 1948 | * @param deltaY The (signed) number of pixels to scroll. |
| 1949 | * @param scrollY The current scroll position (absolute scrolling only). |
| 1950 | * @param scrollRangeY The maximum allowable scroll position (absolute scrolling only). |
| 1951 | * @param maxOverScrollY The current (unsigned) limit on number of pixels to overscroll by. |
| 1952 | */ |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1953 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1954 | private void customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, int maxOverScrollY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1955 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1956 | boolean clampedY = false; |
| 1957 | if (deltaY < 0) { |
| 1958 | int maxScrollAmount = getMaxNegativeScrollAmount(); |
| 1959 | if (maxScrollAmount > Integer.MIN_VALUE) { |
| 1960 | maxScrollAmount -= maxOverScrollY; |
| 1961 | if (deltaY < maxScrollAmount) { |
| 1962 | deltaY = maxScrollAmount; |
| 1963 | clampedY = true; |
| 1964 | } |
| 1965 | } |
| 1966 | } else { |
| 1967 | int maxScrollAmount = getMaxPositiveScrollAmount(); |
| 1968 | if (maxScrollAmount < Integer.MAX_VALUE) { |
| 1969 | maxScrollAmount += maxOverScrollY; |
| 1970 | if (deltaY > maxScrollAmount) { |
| 1971 | deltaY = maxScrollAmount; |
| 1972 | clampedY = true; |
| 1973 | } |
| 1974 | } |
| 1975 | } |
| 1976 | onCustomOverScrolledBy(deltaY, clampedY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1977 | } else { |
| 1978 | int newScrollY = scrollY + deltaY; |
| 1979 | final int top = -maxOverScrollY; |
| 1980 | final int bottom = maxOverScrollY + scrollRangeY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1981 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1982 | boolean clampedY = false; |
| 1983 | if (newScrollY > bottom) { |
| 1984 | newScrollY = bottom; |
| 1985 | clampedY = true; |
| 1986 | } else if (newScrollY < top) { |
| 1987 | newScrollY = top; |
| 1988 | clampedY = true; |
| 1989 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1990 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1991 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1992 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | /** |
| 1996 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1997 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1998 | * same overScroll edge. |
| 1999 | * |
| 2000 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 2001 | * the rubber-banding logic. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2002 | * @param onTop Should the effect be applied on top of the scroller. |
| 2003 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2004 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2005 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2006 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2007 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | /** |
| 2011 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2012 | * By default this will also cancel animations on the same overScroll edge. |
| 2013 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2014 | * @param amount The amount to overScroll by. |
| 2015 | * @param onTop Should the effect be applied on top of the scroller. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2016 | * @param animate Should an animation be performed. |
| 2017 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2018 | |
| 2019 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2020 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 2021 | setOverScrollAmount(amount, onTop, animate, true); |
| 2022 | } |
| 2023 | |
| 2024 | /** |
| 2025 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 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. |
| 2029 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2030 | * @param cancelAnimators Should running animations be cancelled. |
| 2031 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 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 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2035 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 2036 | } |
| 2037 | |
| 2038 | /** |
| 2039 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2040 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2041 | * @param amount The amount to overScroll by. |
| 2042 | * @param onTop Should the effect be applied on top of the scroller. |
| 2043 | * @param animate Should an animation be performed. |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2044 | * @param cancelAnimators Should running animations be cancelled. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2045 | * @param isRubberbanded The value which will be passed to |
| 2046 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2047 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2048 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2049 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2050 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2051 | if (cancelAnimators) { |
| 2052 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 2053 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2054 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2055 | } |
| 2056 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2057 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2058 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 2059 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2060 | amount = Math.max(0, amount); |
| 2061 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2062 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2063 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2064 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2065 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2066 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2067 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2068 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2069 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2073 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2074 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2075 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 2076 | if (mDontReportNextOverScroll) { |
| 2077 | mDontReportNextOverScroll = false; |
| 2078 | return; |
| 2079 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2080 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2081 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2082 | } |
| 2083 | } |
| 2084 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2085 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2086 | public void setOverscrollTopChangedListener( |
| 2087 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 2088 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 2089 | } |
| 2090 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2091 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2092 | public float getCurrentOverScrollAmount(boolean top) { |
| 2093 | return mAmbientState.getOverScrollAmount(top); |
| 2094 | } |
| 2095 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2096 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2097 | public float getCurrentOverScrolledPixels(boolean top) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2098 | return top ? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2099 | } |
| 2100 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2101 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2102 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2103 | if (onTop) { |
| 2104 | mOverScrolledTopPixels = amount; |
| 2105 | } else { |
| 2106 | mOverScrolledBottomPixels = amount; |
| 2107 | } |
| 2108 | } |
| 2109 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2110 | /** |
| 2111 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 2112 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 2113 | * |
| 2114 | * @param deltaY The (signed) number of pixels to scroll. |
| 2115 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2116 | * the overscroll limit. |
| 2117 | */ |
| 2118 | private void onCustomOverScrolledBy(int deltaY, boolean clampedY) { |
| 2119 | assert ANCHOR_SCROLLING; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2120 | mScrollAnchorViewY -= deltaY; |
| 2121 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2122 | if (!mScroller.isFinished()) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2123 | if (clampedY) { |
| 2124 | springBack(); |
| 2125 | } else { |
| 2126 | float overScrollTop = getCurrentOverScrollAmount(true /* top */); |
| 2127 | if (isScrolledToTop() && mScrollAnchorViewY > 0) { |
| 2128 | notifyOverscrollTopListener(mScrollAnchorViewY, |
| 2129 | isRubberbanded(true /* onTop */)); |
| 2130 | } else { |
| 2131 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true /* onTop */)); |
| 2132 | } |
| 2133 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2134 | } |
| 2135 | updateScrollAnchor(); |
| 2136 | updateOnScrollChange(); |
| 2137 | } |
| 2138 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2139 | /** |
| 2140 | * Scrolls to the given position, overscrolling if needed. If called during a fling and the |
| 2141 | * position exceeds the provided maximum overscroll, springs back instead. |
| 2142 | * |
| 2143 | * @param scrollY The target scroll position. |
| 2144 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2145 | * the overscroll limit. |
| 2146 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2147 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2148 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2149 | assert !ANCHOR_SCROLLING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2150 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2151 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2152 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2153 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2154 | springBack(); |
| 2155 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2156 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2157 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2158 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2159 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2160 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2161 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2162 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2163 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2164 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2165 | } |
| 2166 | } |
| 2167 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2168 | /** |
| 2169 | * Springs back from an overscroll by stopping the {@link #mScroller} and animating the |
| 2170 | * overscroll amount back to zero. |
| 2171 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2172 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2173 | private void springBack() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2174 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2175 | boolean overScrolledTop = isScrolledToTop() && mScrollAnchorViewY > 0; |
| 2176 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 2177 | boolean overscrolledBottom = maxPositiveScrollAmount < 0; |
| 2178 | if (overScrolledTop || overscrolledBottom) { |
| 2179 | float newAmount; |
| 2180 | if (overScrolledTop) { |
| 2181 | newAmount = mScrollAnchorViewY; |
| 2182 | mScrollAnchorViewY = 0; |
| 2183 | mDontReportNextOverScroll = true; |
| 2184 | } else { |
| 2185 | newAmount = -maxPositiveScrollAmount; |
| 2186 | mScrollAnchorViewY -= maxPositiveScrollAmount; |
| 2187 | } |
| 2188 | setOverScrollAmount(newAmount, overScrolledTop, false); |
| 2189 | setOverScrollAmount(0.0f, overScrolledTop, true); |
| 2190 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2191 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2192 | } else { |
| 2193 | int scrollRange = getScrollRange(); |
| 2194 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2195 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2196 | if (overScrolledTop || overScrolledBottom) { |
| 2197 | boolean onTop; |
| 2198 | float newAmount; |
| 2199 | if (overScrolledTop) { |
| 2200 | onTop = true; |
| 2201 | newAmount = -mOwnScrollY; |
| 2202 | setOwnScrollY(0); |
| 2203 | mDontReportNextOverScroll = true; |
| 2204 | } else { |
| 2205 | onTop = false; |
| 2206 | newAmount = mOwnScrollY - scrollRange; |
| 2207 | setOwnScrollY(scrollRange); |
| 2208 | } |
| 2209 | setOverScrollAmount(newAmount, onTop, false); |
| 2210 | setOverScrollAmount(0.0f, onTop, true); |
| 2211 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2212 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2216 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2217 | private int getScrollRange() { |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2218 | // In current design, it only use the top HUN to treat all of HUNs |
| 2219 | // although there are more than one HUNs |
| 2220 | int contentHeight = mContentHeight; |
| 2221 | if (!isExpanded() && mHeadsUpManager.hasPinnedHeadsUp()) { |
| 2222 | contentHeight = mHeadsUpInset + getTopHeadsUpPinnedHeight(); |
| 2223 | } |
| 2224 | int scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2225 | int imeInset = getImeInset(); |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2226 | scrollRange += Math.min(imeInset, Math.max(0, contentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2227 | return scrollRange; |
| 2228 | } |
| 2229 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2230 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2231 | private int getImeInset() { |
| 2232 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2233 | } |
| 2234 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2235 | /** |
| 2236 | * @return the first child which has visibility unequal to GONE |
| 2237 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2238 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2239 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2240 | int childCount = getChildCount(); |
| 2241 | for (int i = 0; i < childCount; i++) { |
| 2242 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2243 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2244 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2245 | } |
| 2246 | } |
| 2247 | return null; |
| 2248 | } |
| 2249 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2250 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2251 | * @return the child before the given view which has visibility unequal to GONE |
| 2252 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2253 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2254 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2255 | ExpandableView previousView = null; |
| 2256 | int childCount = getChildCount(); |
| 2257 | for (int i = 0; i < childCount; i++) { |
| 2258 | View child = getChildAt(i); |
| 2259 | if (child == view) { |
| 2260 | return previousView; |
| 2261 | } |
| 2262 | if (child.getVisibility() != View.GONE) { |
| 2263 | previousView = (ExpandableView) child; |
| 2264 | } |
| 2265 | } |
| 2266 | return null; |
| 2267 | } |
| 2268 | |
| 2269 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2270 | * @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] | 2271 | * given translationY or equal to it. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2272 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2273 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2274 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2275 | int childCount = getChildCount(); |
| 2276 | for (int i = 0; i < childCount; i++) { |
| 2277 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2278 | if (child.getVisibility() == View.GONE) { |
| 2279 | continue; |
| 2280 | } |
| 2281 | float rowTranslation = child.getTranslationY(); |
| 2282 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2283 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2284 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2285 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2286 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2287 | List<ExpandableNotificationRow> notificationChildren = |
| 2288 | row.getNotificationChildren(); |
| 2289 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2290 | childIndex++) { |
| 2291 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2292 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2293 | return rowChild; |
| 2294 | } |
| 2295 | } |
| 2296 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2297 | } |
| 2298 | } |
| 2299 | return null; |
| 2300 | } |
| 2301 | |
| 2302 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2303 | * @return the last child which has visibility unequal to GONE |
| 2304 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2305 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2306 | public ExpandableView getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2307 | int childCount = getChildCount(); |
| 2308 | for (int i = childCount - 1; i >= 0; i--) { |
| 2309 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2310 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2311 | return (ExpandableView) child; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2312 | } |
| 2313 | } |
| 2314 | return null; |
| 2315 | } |
| 2316 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2317 | private ExpandableNotificationRow getLastRowNotGone() { |
| 2318 | int childCount = getChildCount(); |
| 2319 | for (int i = childCount - 1; i >= 0; i--) { |
| 2320 | View child = getChildAt(i); |
| 2321 | if (child instanceof ExpandableNotificationRow && child.getVisibility() != View.GONE) { |
| 2322 | return (ExpandableNotificationRow) child; |
| 2323 | } |
| 2324 | } |
| 2325 | return null; |
| 2326 | } |
| 2327 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2328 | /** |
| 2329 | * @return the number of children which have visibility unequal to GONE |
| 2330 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2331 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2332 | public int getNotGoneChildCount() { |
| 2333 | int childCount = getChildCount(); |
| 2334 | int count = 0; |
| 2335 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2336 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2337 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2338 | count++; |
| 2339 | } |
| 2340 | } |
| 2341 | return count; |
| 2342 | } |
| 2343 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2344 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2345 | private void updateContentHeight() { |
| 2346 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2347 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2348 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2349 | int numShownItems = 0; |
| 2350 | boolean finish = false; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2351 | int maxDisplayedNotifications = mMaxDisplayedNotifications; |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2352 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2353 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2354 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2355 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2356 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2357 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2358 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2359 | && numShownItems >= maxDisplayedNotifications; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2360 | if (limitReached) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2361 | expandableView = mShelf; |
| 2362 | finish = true; |
| 2363 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2364 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2365 | float padding; |
| 2366 | if (increasedPaddingAmount >= 0.0f) { |
| 2367 | padding = (int) NotificationUtils.interpolate( |
| 2368 | previousPaddingRequest, |
| 2369 | mIncreasedPaddingBetweenElements, |
| 2370 | increasedPaddingAmount); |
| 2371 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2372 | mPaddingBetweenElements, |
| 2373 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2374 | increasedPaddingAmount); |
| 2375 | } else { |
| 2376 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2377 | 0, |
| 2378 | mPaddingBetweenElements, |
| 2379 | 1.0f + increasedPaddingAmount); |
| 2380 | if (previousPaddingAmount > 0.0f) { |
| 2381 | padding = (int) NotificationUtils.interpolate( |
| 2382 | ownPadding, |
| 2383 | mIncreasedPaddingBetweenElements, |
| 2384 | previousPaddingAmount); |
| 2385 | } else { |
| 2386 | padding = ownPadding; |
| 2387 | } |
| 2388 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2389 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2390 | if (height != 0) { |
| 2391 | height += padding; |
| 2392 | } |
| 2393 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2394 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2395 | numShownItems++; |
| 2396 | if (finish) { |
| 2397 | break; |
| 2398 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2399 | } |
| 2400 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2401 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2402 | |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame^] | 2403 | // The topPadding can be bigger than the regular padding when qs is expanded, in that |
| 2404 | // state the maxPanelHeight and the contentHeight should be bigger |
| 2405 | mContentHeight = height + Math.max(mIntrinsicPadding, mTopPadding) + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2406 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2407 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2408 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2411 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2412 | private boolean isPulsing(NotificationEntry entry) { |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 2413 | return mAmbientState.isPulsing(entry); |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2416 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2417 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2418 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2419 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2422 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2423 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2424 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2425 | if (scrollable != mScrollable) { |
| 2426 | mScrollable = scrollable; |
| 2427 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2428 | updateForwardAndBackwardScrollability(); |
| 2429 | } |
| 2430 | } |
| 2431 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2432 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2433 | private void updateForwardAndBackwardScrollability() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2434 | boolean forwardScrollable = mScrollable && !isScrolledToBottom(); |
| 2435 | boolean backwardsScrollable = mScrollable && !isScrolledToTop(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2436 | boolean changed = forwardScrollable != mForwardScrollable |
| 2437 | || backwardsScrollable != mBackwardScrollable; |
| 2438 | mForwardScrollable = forwardScrollable; |
| 2439 | mBackwardScrollable = backwardsScrollable; |
| 2440 | if (changed) { |
| 2441 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2442 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2443 | } |
| 2444 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2445 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2446 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2447 | // No need to update the background color if it's not being drawn. |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 2448 | if (!mShouldDrawNotificationBackground || mAmbientState.isFullyDark()) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2449 | return; |
| 2450 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2451 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2452 | updateBackgroundBounds(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2453 | if (didSectionBoundsChange()) { |
| 2454 | boolean animate = mAnimateNextSectionBoundsChange || mAnimateNextBackgroundTop |
| 2455 | || mAnimateNextBackgroundBottom || areSectionBoundsAnimating(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2456 | if (!isExpanded()) { |
| 2457 | abortBackgroundAnimators(); |
| 2458 | animate = false; |
| 2459 | } |
| 2460 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2461 | startBackgroundAnimation(); |
| 2462 | } else { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2463 | for (NotificationSection section : mSections) { |
| 2464 | section.resetCurrentBounds(); |
| 2465 | } |
Lucas Dupin | 90a38dd | 2018-09-05 09:37:37 -0700 | [diff] [blame] | 2466 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2467 | } |
| 2468 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2469 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2470 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2471 | mAnimateNextBackgroundTop = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2472 | mAnimateNextBackgroundBottom = false; |
| 2473 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2474 | } |
| 2475 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2476 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2477 | private void abortBackgroundAnimators() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2478 | for (NotificationSection section : mSections) { |
| 2479 | section.cancelAnimators(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2483 | private boolean didSectionBoundsChange() { |
| 2484 | for (NotificationSection section : mSections) { |
| 2485 | if (section.didBoundsChange()) { |
| 2486 | return true; |
| 2487 | } |
| 2488 | } |
| 2489 | return false; |
| 2490 | } |
| 2491 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2492 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2493 | private boolean areSectionBoundsAnimating() { |
| 2494 | for (NotificationSection section : mSections) { |
| 2495 | if (section.areBoundsAnimating()) { |
| 2496 | return true; |
| 2497 | } |
| 2498 | } |
| 2499 | return false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2500 | } |
| 2501 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2502 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2503 | private void startBackgroundAnimation() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2504 | // TODO(kprevas): do we still need separate fields for top/bottom? |
| 2505 | // or can each section manage its own animation state? |
| 2506 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2507 | NotificationSection lastVisibleSection = getLastVisibleSection(); |
| 2508 | for (NotificationSection section : mSections) { |
| 2509 | section.startBackgroundAnimation( |
| 2510 | section == firstVisibleSection |
| 2511 | ? mAnimateNextBackgroundTop |
| 2512 | : mAnimateNextSectionBoundsChange, |
| 2513 | section == lastVisibleSection |
| 2514 | ? mAnimateNextBackgroundBottom |
| 2515 | : mAnimateNextSectionBoundsChange); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2516 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | /** |
| 2520 | * Update the background bounds to the new desired bounds |
| 2521 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2522 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2523 | private void updateBackgroundBounds() { |
shawnlin | 2771672 | 2019-04-17 20:09:45 +0800 | [diff] [blame] | 2524 | int left = mSidePaddings; |
| 2525 | int right = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2526 | for (NotificationSection section : mSections) { |
| 2527 | section.getBounds().left = left; |
| 2528 | section.getBounds().right = right; |
| 2529 | } |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2530 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2531 | if (!mIsExpanded) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2532 | for (NotificationSection section : mSections) { |
| 2533 | section.getBounds().top = 0; |
| 2534 | section.getBounds().bottom = 0; |
| 2535 | } |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2536 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2537 | } |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2538 | int minTopPosition = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2539 | NotificationSection lastSection = getLastVisibleSection(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 2540 | if (mStatusBarState != StatusBarState.KEYGUARD) { |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2541 | minTopPosition = (int) (mTopPadding + mStackTranslation); |
| 2542 | } else if (lastSection == null) { |
| 2543 | minTopPosition = mTopPadding; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2544 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2545 | boolean shiftPulsingWithFirst = mAmbientPulseManager.getAllEntries().count() <= 1; |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2546 | for (NotificationSection section : mSections) { |
| 2547 | int minBottomPosition = minTopPosition; |
| 2548 | if (section == lastSection) { |
| 2549 | // 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] | 2550 | minBottomPosition = (int) (ViewState.getFinalTranslationY(mShelf) |
| 2551 | + mShelf.getIntrinsicHeight()); |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2552 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2553 | minTopPosition = section.updateBounds(minTopPosition, minBottomPosition, |
| 2554 | shiftPulsingWithFirst); |
| 2555 | shiftPulsingWithFirst = false; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2556 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2557 | } |
| 2558 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2559 | private NotificationSection getFirstVisibleSection() { |
| 2560 | for (NotificationSection section : mSections) { |
| 2561 | if (section.getFirstVisibleChild() != null) { |
| 2562 | return section; |
| 2563 | } |
| 2564 | } |
| 2565 | return null; |
| 2566 | } |
| 2567 | |
| 2568 | private NotificationSection getLastVisibleSection() { |
| 2569 | for (int i = mSections.length - 1; i >= 0; i--) { |
| 2570 | NotificationSection section = mSections[i]; |
| 2571 | if (section.getLastVisibleChild() != null) { |
| 2572 | return section; |
| 2573 | } |
| 2574 | } |
| 2575 | return null; |
| 2576 | } |
| 2577 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2578 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2579 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2580 | int childCount = getChildCount(); |
| 2581 | for (int i = childCount - 1; i >= 0; i--) { |
| 2582 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2583 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2584 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2585 | return (ActivatableNotificationView) child; |
| 2586 | } |
| 2587 | } |
| 2588 | return null; |
| 2589 | } |
| 2590 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2591 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2592 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2593 | int childCount = getChildCount(); |
| 2594 | for (int i = 0; i < childCount; i++) { |
| 2595 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2596 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2597 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2598 | return (ActivatableNotificationView) child; |
| 2599 | } |
| 2600 | } |
| 2601 | return null; |
| 2602 | } |
| 2603 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2604 | /** |
| 2605 | * Fling the scroll view |
| 2606 | * |
| 2607 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2608 | * numbers mean that the finger/cursor is moving down the screen, |
| 2609 | * which means we want to scroll towards the top. |
| 2610 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2611 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2612 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2613 | if (getChildCount() > 0) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2614 | float topAmount = getCurrentOverScrollAmount(true); |
| 2615 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2616 | if (velocityY < 0 && topAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2617 | if (ANCHOR_SCROLLING) { |
| 2618 | mScrollAnchorViewY += topAmount; |
| 2619 | } else { |
| 2620 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
| 2621 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2622 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2623 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2624 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2625 | * mOverflingDistance + topAmount; |
| 2626 | } else if (velocityY > 0 && bottomAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2627 | if (ANCHOR_SCROLLING) { |
| 2628 | mScrollAnchorViewY -= bottomAmount; |
| 2629 | } else { |
| 2630 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
| 2631 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2632 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2633 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2634 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2635 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2636 | } else { |
| 2637 | // it will be set once we reach the boundary |
| 2638 | mMaxOverScroll = 0.0f; |
| 2639 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2640 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2641 | flingScroller(velocityY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2642 | } else { |
| 2643 | int scrollRange = getScrollRange(); |
| 2644 | int minScrollY = Math.max(0, scrollRange); |
| 2645 | if (mExpandedInThisMotion) { |
| 2646 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2647 | } |
| 2648 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2649 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2650 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2651 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2652 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2656 | /** |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2657 | * Flings the overscroller with the given velocity (anchor-based scrolling). |
| 2658 | * |
| 2659 | * Because anchor-based scrolling can't track the current scroll position, the overscroller is |
| 2660 | * always started at startY = 0, and we interpret the positions it computes as relative to the |
| 2661 | * start of the scroll. |
| 2662 | */ |
| 2663 | private void flingScroller(int velocityY) { |
| 2664 | assert ANCHOR_SCROLLING; |
| 2665 | mIsScrollerBoundSet = false; |
| 2666 | maybeFlingScroller(velocityY, true /* always fling */); |
| 2667 | } |
| 2668 | |
| 2669 | private void maybeFlingScroller(int velocityY, boolean alwaysFling) { |
| 2670 | assert ANCHOR_SCROLLING; |
| 2671 | // Attempt to determine the maximum amount to scroll before we reach the end. |
| 2672 | // If the first view is not materialized (for an upwards scroll) or the last view is either |
| 2673 | // not materialized or is pinned to the shade (for a downwards scroll), we don't know this |
| 2674 | // amount, so we do an unbounded fling and rely on {@link #maybeReflingScroller()} to update |
| 2675 | // the scroller once we approach the start/end of the list. |
| 2676 | int minY = Integer.MIN_VALUE; |
| 2677 | int maxY = Integer.MAX_VALUE; |
| 2678 | if (velocityY < 0) { |
| 2679 | minY = getMaxNegativeScrollAmount(); |
| 2680 | if (minY > Integer.MIN_VALUE) { |
| 2681 | mIsScrollerBoundSet = true; |
| 2682 | } |
| 2683 | } else { |
| 2684 | maxY = getMaxPositiveScrollAmount(); |
| 2685 | if (maxY < Integer.MAX_VALUE) { |
| 2686 | mIsScrollerBoundSet = true; |
| 2687 | } |
| 2688 | } |
| 2689 | if (mIsScrollerBoundSet || alwaysFling) { |
| 2690 | mLastScrollerY = 0; |
| 2691 | // x velocity is set to 1 to avoid overscroller bug |
| 2692 | mScroller.fling(0, 0, 1, velocityY, 0, 0, minY, maxY, 0, |
| 2693 | mExpandedInThisMotion && !isScrolledToTop() ? 0 : Integer.MAX_VALUE / 2); |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | /** |
| 2698 | * Returns the maximum number of pixels we can scroll in the positive direction (downwards) |
| 2699 | * before reaching the bottom of the list (discounting overscroll). |
| 2700 | * |
| 2701 | * If the return value is negative then we have overscrolled; this is a transient state which |
| 2702 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2703 | * the bottom overscroll amount. |
| 2704 | * |
| 2705 | * If we don't know how many pixels we have left to scroll (because the last row has not been |
| 2706 | * materialized, or it's in the shelf so it doesn't have its "natural" position), we return |
| 2707 | * {@link Integer#MAX_VALUE}. |
| 2708 | */ |
| 2709 | private int getMaxPositiveScrollAmount() { |
| 2710 | assert ANCHOR_SCROLLING; |
| 2711 | // TODO: once we're recycling we need to check the adapter position of the last child. |
| 2712 | ExpandableNotificationRow lastRow = getLastRowNotGone(); |
| 2713 | if (mScrollAnchorView != null && lastRow != null && !lastRow.isInShelf()) { |
| 2714 | // distance from bottom of last child to bottom of notifications area is: |
| 2715 | // distance from bottom of last child |
| 2716 | return (int) (lastRow.getTranslationY() + lastRow.getActualHeight() |
| 2717 | // to top of anchor view |
| 2718 | - mScrollAnchorView.getTranslationY() |
| 2719 | // plus distance from anchor view to top of notifications area |
| 2720 | + mScrollAnchorViewY |
| 2721 | // minus height of notifications area. |
| 2722 | - (mMaxLayoutHeight - getIntrinsicPadding() - mFooterView.getActualHeight())); |
| 2723 | } else { |
| 2724 | return Integer.MAX_VALUE; |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | /** |
| 2729 | * Returns the maximum number of pixels (as a negative number) we can scroll in the negative |
| 2730 | * direction (upwards) before reaching the top of the list (discounting overscroll). |
| 2731 | * |
| 2732 | * If the return value is positive then we have overscrolled; this is a transient state which |
| 2733 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2734 | * the top overscroll amount. |
| 2735 | * |
| 2736 | * If we don't know how many pixels we have left to scroll (because the first row has not been |
| 2737 | * materialized), we return {@link Integer#MIN_VALUE}. |
| 2738 | */ |
| 2739 | private int getMaxNegativeScrollAmount() { |
| 2740 | assert ANCHOR_SCROLLING; |
| 2741 | // TODO: once we're recycling we need to check the adapter position of the first child. |
| 2742 | ExpandableView firstChild = getFirstChildNotGone(); |
| 2743 | if (mScrollAnchorView != null && firstChild != null) { |
| 2744 | // distance from top of first child to top of notifications area is: |
| 2745 | // distance from top of anchor view |
| 2746 | return (int) -(mScrollAnchorView.getTranslationY() |
| 2747 | // to top of first child |
| 2748 | - firstChild.getTranslationY() |
| 2749 | // minus distance from top of anchor view to top of notifications area. |
| 2750 | - mScrollAnchorViewY); |
| 2751 | } else { |
| 2752 | return Integer.MIN_VALUE; |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | /** |
| 2757 | * During a fling, if we were unable to set the bounds of the fling due to the top/bottom view |
| 2758 | * not being materialized or being pinned to the shelf, we need to check on every frame if we're |
| 2759 | * able to set the bounds. If we are, we fling the scroller again with the newly computed |
| 2760 | * bounds. |
| 2761 | */ |
| 2762 | private void maybeReflingScroller() { |
| 2763 | if (!mIsScrollerBoundSet) { |
| 2764 | // Because mScroller is a flywheel scroller, we fling with the minimum possible |
| 2765 | // velocity to establish direction, so as not to perceptibly affect the velocity. |
| 2766 | maybeFlingScroller((int) Math.signum(mScroller.getCurrVelocity()), |
| 2767 | false /* alwaysFling */); |
| 2768 | } |
| 2769 | } |
| 2770 | |
| 2771 | /** |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2772 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2773 | * overScroll view (i.e QS). |
| 2774 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2775 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2776 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2777 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2778 | return mScrolledToTopOnFirstDown |
| 2779 | && !mExpandedInThisMotion |
| 2780 | && topOverScroll > mMinTopOverScrollToEscape |
| 2781 | && initialVelocity > 0; |
| 2782 | } |
| 2783 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2784 | /** |
| 2785 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2786 | * account. |
| 2787 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2788 | * @param qsHeight the top padding imposed by the quick settings panel |
| 2789 | * @param animate whether to animate the change |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2790 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2791 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame^] | 2792 | public void updateTopPadding(float qsHeight, boolean animate) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2793 | int topPadding = (int) qsHeight; |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2794 | int minStackHeight = getLayoutMinHeight(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2795 | if (topPadding + minStackHeight > getHeight()) { |
| 2796 | mTopPaddingOverflow = topPadding + minStackHeight - getHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2797 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2798 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2799 | } |
Selim Cinek | db6d6df | 2019-05-22 20:39:59 -0700 | [diff] [blame^] | 2800 | setTopPadding(topPadding, animate); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2801 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2802 | } |
| 2803 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2804 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2805 | public void setMaxTopPadding(int maxTopPadding) { |
| 2806 | mMaxTopPadding = maxTopPadding; |
| 2807 | } |
| 2808 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2809 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2810 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2811 | if (isHeadsUpTransition()) { |
| 2812 | return getTopHeadsUpPinnedHeight(); |
| 2813 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2814 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2817 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2818 | public float getTopPaddingOverflow() { |
| 2819 | return mTopPaddingOverflow; |
| 2820 | } |
| 2821 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2822 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2823 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2824 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2825 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2826 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2827 | int shelfHeight = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2828 | if (getLastVisibleSection() != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2829 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2830 | } |
| 2831 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2832 | } |
| 2833 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2834 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2835 | private int clampPadding(int desiredPadding) { |
| 2836 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2837 | } |
| 2838 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2839 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2840 | private float getRubberBandFactor(boolean onTop) { |
| 2841 | if (!onTop) { |
| 2842 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2843 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2844 | if (mExpandedInThisMotion) { |
| 2845 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2846 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2847 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2848 | } else if (mScrolledToTopOnFirstDown) { |
| 2849 | return 1.0f; |
| 2850 | } |
| 2851 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2852 | } |
| 2853 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2854 | /** |
| 2855 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2856 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2857 | * overscroll view (e.g. expand QS). |
| 2858 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2859 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2860 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2861 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2862 | || !mScrolledToTopOnFirstDown; |
| 2863 | } |
| 2864 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2865 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2866 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2867 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2868 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
| 2869 | mChildTransferInProgress = childTransferInProgress; |
| 2870 | } |
| 2871 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2872 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2873 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2874 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2875 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2876 | // we only call our internal methods if this is actually a removal and not just a |
| 2877 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2878 | if (!mChildTransferInProgress) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2879 | onViewRemovedInternal((ExpandableView) child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2880 | } |
| 2881 | } |
| 2882 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2883 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2884 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2885 | public void cleanUpViewStateForEntry(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 2886 | View child = entry.getRow(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 2887 | if (child == mSwipeHelper.getTranslatingParentView()) { |
| 2888 | mSwipeHelper.clearTranslatingParentView(); |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2889 | } |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2890 | } |
| 2891 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2892 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2893 | private void onViewRemovedInternal(ExpandableView child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2894 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2895 | // This is only a position change, don't do anything special |
| 2896 | return; |
| 2897 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2898 | child.setOnHeightChangedListener(null); |
| 2899 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2900 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2901 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2902 | if (!mSwipedOutViews.contains(child) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2903 | || Math.abs(child.getTranslation()) != child.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2904 | container.addTransientView(child, 0); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2905 | child.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2906 | } |
| 2907 | } else { |
| 2908 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2909 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2910 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2911 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2912 | focusNextViewIfFocused(child); |
| 2913 | } |
| 2914 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2915 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2916 | private void focusNextViewIfFocused(View view) { |
| 2917 | if (view instanceof ExpandableNotificationRow) { |
| 2918 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2919 | if (row.shouldRefocusOnDismiss()) { |
| 2920 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 2921 | if (nextView == null) { |
| 2922 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 2923 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 2924 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2925 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2926 | } |
| 2927 | if (nextView != null) { |
| 2928 | nextView.requestAccessibilityFocus(); |
| 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2933 | } |
| 2934 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2935 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2936 | private boolean isChildInGroup(View child) { |
| 2937 | return child instanceof ExpandableNotificationRow |
| 2938 | && mGroupManager.isChildInGroupWithSummary( |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2939 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2942 | /** |
| 2943 | * Generate a remove animation for a child view. |
| 2944 | * |
| 2945 | * @param child The view to generate the remove animation for. |
| 2946 | * @return Whether an animation was generated. |
| 2947 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2948 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2949 | private boolean generateRemoveAnimation(ExpandableView child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2950 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2951 | mAddedHeadsUpChildren.remove(child); |
| 2952 | return false; |
| 2953 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2954 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 2955 | // An animation is already running, add it transiently |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2956 | mClearTransientViewsWhenFinished.add(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2957 | return true; |
| 2958 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2959 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2960 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2961 | // Generate Animations |
| 2962 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2963 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2964 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2965 | } else { |
| 2966 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2967 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2968 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2969 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2970 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2971 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2972 | } |
| 2973 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2974 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2975 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2976 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2979 | /** |
| 2980 | * Remove a removed child view from the heads up animations if it was just added there |
| 2981 | * |
| 2982 | * @return whether any child was removed from the list to animate |
| 2983 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2984 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2985 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 2986 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2987 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 2988 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2989 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2990 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2991 | mTmpList.add(eventPair); |
| 2992 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2993 | } |
| 2994 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2995 | if (hasAddEvent) { |
| 2996 | // This child was just added lets remove all events. |
| 2997 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2998 | ((ExpandableNotificationRow) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2999 | } |
| 3000 | mTmpList.clear(); |
| 3001 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3002 | } |
| 3003 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3004 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3005 | * @param child the child to query |
| 3006 | * @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] | 3007 | * not expanded |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3008 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3009 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3010 | private boolean isChildInInvisibleGroup(View child) { |
| 3011 | if (child instanceof ExpandableNotificationRow) { |
| 3012 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 3013 | NotificationEntry groupSummary = |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3014 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 3015 | if (groupSummary != null && groupSummary.getRow() != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 3016 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | return false; |
| 3020 | } |
| 3021 | |
| 3022 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3023 | * Updates the scroll position when a child was removed |
| 3024 | * |
| 3025 | * @param removedChild the removed child |
| 3026 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3027 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3028 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3029 | if (ANCHOR_SCROLLING) { |
| 3030 | if (removedChild == mScrollAnchorView) { |
| 3031 | ExpandableView firstChild = getFirstChildNotGone(); |
| 3032 | if (firstChild != null) { |
| 3033 | mScrollAnchorView = firstChild; |
| 3034 | } else { |
| 3035 | mScrollAnchorView = mShelf; |
| 3036 | } |
| 3037 | // Adjust anchor view Y by the distance between the old and new anchors |
| 3038 | // so that there's no visible change. |
| 3039 | mScrollAnchorViewY += |
| 3040 | mScrollAnchorView.getTranslationY() - removedChild.getTranslationY(); |
| 3041 | } |
| 3042 | updateScrollAnchor(); |
| 3043 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3044 | if (mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY > 0) { |
| 3045 | mScrollAnchorViewY = 0; |
| 3046 | } |
| 3047 | updateOnScrollChange(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3048 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3049 | int startingPosition = getPositionInLinearLayout(removedChild); |
| 3050 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 3051 | int padding; |
| 3052 | if (increasedPaddingAmount >= 0) { |
| 3053 | padding = (int) NotificationUtils.interpolate( |
| 3054 | mPaddingBetweenElements, |
| 3055 | mIncreasedPaddingBetweenElements, |
| 3056 | increasedPaddingAmount); |
| 3057 | } else { |
| 3058 | padding = (int) NotificationUtils.interpolate( |
| 3059 | 0, |
| 3060 | mPaddingBetweenElements, |
| 3061 | 1.0f + increasedPaddingAmount); |
| 3062 | } |
| 3063 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
| 3064 | int endPosition = startingPosition + childHeight; |
| 3065 | if (endPosition <= mOwnScrollY) { |
| 3066 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 3067 | // scrollPosition |
| 3068 | setOwnScrollY(mOwnScrollY - childHeight); |
| 3069 | } else if (startingPosition < mOwnScrollY) { |
| 3070 | // This child is currently being scrolled into, set the scroll position to the |
| 3071 | // start of this child |
| 3072 | setOwnScrollY(startingPosition); |
| 3073 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3077 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 3078 | private int getIntrinsicHeight(View view) { |
| 3079 | if (view instanceof ExpandableView) { |
| 3080 | ExpandableView expandableView = (ExpandableView) view; |
| 3081 | return expandableView.getIntrinsicHeight(); |
| 3082 | } |
| 3083 | return view.getHeight(); |
| 3084 | } |
| 3085 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3086 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3087 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3088 | ExpandableNotificationRow childInGroup = null; |
| 3089 | ExpandableNotificationRow requestedRow = null; |
| 3090 | if (isChildInGroup(requestedView)) { |
| 3091 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 3092 | // then within the parent. |
| 3093 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 3094 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 3095 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3096 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3097 | float previousPaddingRequest = mPaddingBetweenElements; |
| 3098 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3099 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3100 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3101 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 3102 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3103 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3104 | float padding; |
| 3105 | if (increasedPaddingAmount >= 0.0f) { |
| 3106 | padding = (int) NotificationUtils.interpolate( |
| 3107 | previousPaddingRequest, |
| 3108 | mIncreasedPaddingBetweenElements, |
| 3109 | increasedPaddingAmount); |
| 3110 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3111 | mPaddingBetweenElements, |
| 3112 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3113 | increasedPaddingAmount); |
| 3114 | } else { |
| 3115 | int ownPadding = (int) NotificationUtils.interpolate( |
| 3116 | 0, |
| 3117 | mPaddingBetweenElements, |
| 3118 | 1.0f + increasedPaddingAmount); |
| 3119 | if (previousPaddingAmount > 0.0f) { |
| 3120 | padding = (int) NotificationUtils.interpolate( |
| 3121 | ownPadding, |
| 3122 | mIncreasedPaddingBetweenElements, |
| 3123 | previousPaddingAmount); |
| 3124 | } else { |
| 3125 | padding = ownPadding; |
| 3126 | } |
| 3127 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3128 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3129 | if (position != 0) { |
| 3130 | position += padding; |
| 3131 | } |
| 3132 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3133 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3134 | if (child == requestedView) { |
| 3135 | if (requestedRow != null) { |
| 3136 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3137 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3138 | return position; |
| 3139 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3140 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3141 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3148 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3149 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3150 | super.onViewAdded(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3151 | onViewAddedInternal((ExpandableView) child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3152 | } |
| 3153 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3154 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3155 | private void updateFirstAndLastBackgroundViews() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3156 | NotificationSection firstSection = getFirstVisibleSection(); |
| 3157 | NotificationSection lastSection = getLastVisibleSection(); |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3158 | ActivatableNotificationView previousFirstChild = |
| 3159 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 3160 | ActivatableNotificationView previousLastChild = |
| 3161 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3162 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3163 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3164 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 3165 | boolean sectionViewsChanged = mSectionsManager.updateFirstAndLastViewsInSections( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3166 | mSections[0], mSections[1], firstChild, lastChild); |
| 3167 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3168 | if (mAnimationsEnabled && mIsExpanded) { |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3169 | mAnimateNextBackgroundTop = firstChild != previousFirstChild; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3170 | mAnimateNextBackgroundBottom = lastChild != previousLastChild || mAnimateBottomOnLayout; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3171 | mAnimateNextSectionBoundsChange = sectionViewsChanged; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3172 | } else { |
| 3173 | mAnimateNextBackgroundTop = false; |
| 3174 | mAnimateNextBackgroundBottom = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3175 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3176 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3177 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3178 | mRoundnessManager.updateRoundedChildren(mSections); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3179 | mAnimateBottomOnLayout = false; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3180 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3181 | } |
| 3182 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3183 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3184 | private void onViewAddedInternal(ExpandableView child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3185 | updateHideSensitiveForChild(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3186 | child.setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3187 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3188 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3189 | updateChronometerForChild(child); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 3190 | if (child instanceof ExpandableNotificationRow) { |
| 3191 | ((ExpandableNotificationRow) child).setDismissRtl(mDismissRtl); |
| 3192 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3193 | if (ANCHOR_SCROLLING) { |
| 3194 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3195 | if (child == getFirstChildNotGone() && (isScrolledToTop() || !mIsExpanded)) { |
| 3196 | // New child was added at the top while we're scrolled to the top; |
| 3197 | // make it the new anchor view so that we stay at the top. |
| 3198 | mScrollAnchorView = child; |
| 3199 | } |
| 3200 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3201 | } |
| 3202 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3203 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3204 | private void updateHideSensitiveForChild(ExpandableView child) { |
| 3205 | child.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3206 | } |
| 3207 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3208 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3209 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3210 | public void notifyGroupChildRemoved(ExpandableView row, ViewGroup childrenContainer) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3211 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3212 | } |
| 3213 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3214 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3215 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3216 | public void notifyGroupChildAdded(ExpandableView row) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3217 | onViewAddedInternal(row); |
| 3218 | } |
| 3219 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3220 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3221 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3222 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3223 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3224 | if (!animationsEnabled) { |
| 3225 | mSwipedOutViews.clear(); |
| 3226 | mChildrenToRemoveAnimated.clear(); |
| 3227 | clearTemporaryViewsInGroup(this); |
| 3228 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3229 | } |
| 3230 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3231 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3232 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3233 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3234 | mShelf.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3235 | int childCount = getChildCount(); |
| 3236 | for (int i = 0; i < childCount; i++) { |
| 3237 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3238 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3239 | updateAnimationState(running, child); |
| 3240 | } |
| 3241 | } |
| 3242 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3243 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3244 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3245 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3246 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3247 | } |
| 3248 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3249 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3250 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3251 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3252 | mAmbientState.setExpandingNotification(row); |
| 3253 | requestChildrenUpdate(); |
| 3254 | } |
| 3255 | |
| 3256 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3257 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3258 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3259 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3260 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3261 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3262 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | @Override |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 3266 | public boolean containsView(View v) { |
| 3267 | return v.getParent() == this; |
| 3268 | } |
| 3269 | |
| 3270 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3271 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3272 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3273 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3274 | requestChildrenUpdate(); |
| 3275 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3276 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3277 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3278 | private void updateAnimationState(boolean running, View child) { |
| 3279 | if (child instanceof ExpandableNotificationRow) { |
| 3280 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3281 | row.setIconAnimationRunning(running); |
| 3282 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3283 | } |
| 3284 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3285 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3286 | public boolean isAddOrRemoveAnimationPending() { |
| 3287 | return mNeedsAnimation |
| 3288 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3289 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3290 | |
| 3291 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3292 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3293 | public void generateAddAnimation(ExpandableView child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3294 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3295 | // Generate Animations |
| 3296 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3297 | if (fromMoreCard) { |
| 3298 | mFromMoreCardAdditions.add(child); |
| 3299 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3300 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3301 | } |
Selim Cinek | f306d9b | 2017-02-21 11:45:13 -0800 | [diff] [blame] | 3302 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3303 | mAddedHeadsUpChildren.add(child); |
| 3304 | mChildrenToAddAnimated.remove(child); |
| 3305 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3306 | } |
| 3307 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3308 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3309 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3310 | public void changeViewPosition(ExpandableView child, int newIndex) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3311 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3312 | |
| 3313 | if (currentIndex == -1) { |
| 3314 | boolean isTransient = false; |
| 3315 | if (child instanceof ExpandableNotificationRow |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3316 | && ((ExpandableNotificationRow) child).getTransientContainer() != null) { |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3317 | isTransient = true; |
| 3318 | } |
| 3319 | Log.e(TAG, "Attempting to re-position " |
| 3320 | + (isTransient ? "transient" : "") |
| 3321 | + " view {" |
| 3322 | + child |
| 3323 | + "}"); |
| 3324 | return; |
| 3325 | } |
| 3326 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3327 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3328 | mChangePositionInProgress = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3329 | ((ExpandableView) child).setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3330 | removeView(child); |
| 3331 | addView(child, newIndex); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3332 | ((ExpandableView) child).setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3333 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3334 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3335 | mChildrenChangingPositions.add(child); |
| 3336 | mNeedsAnimation = true; |
| 3337 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3338 | } |
| 3339 | } |
| 3340 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3341 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3342 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3343 | if (mNeedsAnimation) { |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3344 | generateAllAnimationEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3345 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3346 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3347 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3348 | setAnimationRunning(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3349 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3350 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3351 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3352 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3353 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3354 | } else { |
| 3355 | applyCurrentState(); |
| 3356 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3357 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3358 | } |
| 3359 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3360 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3361 | private void generateAllAnimationEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3362 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3363 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3364 | generateChildAdditionEvents(); |
| 3365 | generatePositionChangeEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3366 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3367 | generateActivateEvent(); |
| 3368 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3369 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3370 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3371 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3372 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3373 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3374 | generateAnimateEverythingEvent(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3375 | } |
| 3376 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3377 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3378 | private void generateHeadsUpAnimationEvents() { |
| 3379 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3380 | ExpandableNotificationRow row = eventPair.first; |
| 3381 | boolean isHeadsUp = eventPair.second; |
| 3382 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3383 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3384 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3385 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3386 | type = row.wasJustClicked() |
| 3387 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3388 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3389 | if (row.isChildInGroup()) { |
| 3390 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3391 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3392 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3393 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3394 | } else { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3395 | ExpandableViewState viewState = row.getViewState(); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3396 | if (viewState == null) { |
| 3397 | // A view state was never generated for this view, so we don't need to animate |
| 3398 | // this. This may happen with notification children. |
| 3399 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3400 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3401 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3402 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3403 | // Our custom add animation |
| 3404 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3405 | } else { |
| 3406 | // Normal add animation |
| 3407 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3408 | } |
| 3409 | onBottom = !pinnedAndClosed; |
| 3410 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3411 | } |
| 3412 | AnimationEvent event = new AnimationEvent(row, type); |
| 3413 | event.headsUpFromBottom = onBottom; |
| 3414 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3415 | } |
| 3416 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3417 | mAddedHeadsUpChildren.clear(); |
| 3418 | } |
| 3419 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3420 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3421 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3422 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3423 | return false; |
| 3424 | } |
| 3425 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3428 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3429 | private void generateGroupExpansionEvent() { |
| 3430 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3431 | if (mExpandedGroupView != null) { |
| 3432 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3433 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3434 | mExpandedGroupView = null; |
| 3435 | } |
| 3436 | } |
| 3437 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3438 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3439 | private void generateViewResizeEvent() { |
| 3440 | if (mNeedViewResizeAnimation) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3441 | boolean hasDisappearAnimation = false; |
| 3442 | for (AnimationEvent animationEvent : mAnimationEvents) { |
| 3443 | final int type = animationEvent.animationType; |
| 3444 | if (type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3445 | || type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3446 | hasDisappearAnimation = true; |
| 3447 | break; |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | if (!hasDisappearAnimation) { |
| 3452 | mAnimationEvents.add( |
| 3453 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3454 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3455 | } |
| 3456 | mNeedViewResizeAnimation = false; |
| 3457 | } |
| 3458 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3459 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3460 | private void generateChildRemovalEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3461 | for (ExpandableView child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3462 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3463 | |
| 3464 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3465 | float removedTranslation = child.getTranslationY(); |
| 3466 | boolean ignoreChildren = true; |
| 3467 | if (child instanceof ExpandableNotificationRow) { |
| 3468 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3469 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3470 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3471 | ignoreChildren = false; |
| 3472 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3473 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3474 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3475 | if (!childWasSwipedOut) { |
| 3476 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3477 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3478 | |
| 3479 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3480 | // Clean up any potential transient views if the child has already been swiped |
| 3481 | // out, as we won't be animating it further (due to its height already being |
| 3482 | // clipped to 0. |
| 3483 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3484 | if (transientContainer != null) { |
| 3485 | transientContainer.removeTransientView(child); |
| 3486 | } |
| 3487 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3488 | } |
| 3489 | int animationType = childWasSwipedOut |
| 3490 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3491 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3492 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3493 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3494 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3495 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3496 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3497 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3498 | mChildrenToRemoveAnimated.clear(); |
| 3499 | } |
| 3500 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3501 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3502 | private void generatePositionChangeEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3503 | for (ExpandableView child : mChildrenChangingPositions) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3504 | mAnimationEvents.add(new AnimationEvent(child, |
| 3505 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3506 | } |
| 3507 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3508 | if (mGenerateChildOrderChangedEvent) { |
| 3509 | mAnimationEvents.add(new AnimationEvent(null, |
| 3510 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3511 | mGenerateChildOrderChangedEvent = false; |
| 3512 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3513 | } |
| 3514 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3515 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3516 | private void generateChildAdditionEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3517 | for (ExpandableView child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3518 | if (mFromMoreCardAdditions.contains(child)) { |
| 3519 | mAnimationEvents.add(new AnimationEvent(child, |
| 3520 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3521 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3522 | } else { |
| 3523 | mAnimationEvents.add(new AnimationEvent(child, |
| 3524 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3525 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3526 | } |
| 3527 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3528 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3529 | } |
| 3530 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3531 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3532 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3533 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3534 | AnimationEvent event; |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 3535 | if (mAmbientState.isDozing()) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3536 | event = new AnimationEvent(null /* view */, |
| 3537 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3538 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3539 | } else { |
| 3540 | event = new AnimationEvent(null /* view */, |
| 3541 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3542 | } |
| 3543 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3544 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3545 | mTopPaddingNeedsAnimation = false; |
| 3546 | } |
| 3547 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3548 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3549 | private void generateActivateEvent() { |
| 3550 | if (mActivateNeedsAnimation) { |
| 3551 | mAnimationEvents.add( |
| 3552 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3553 | } |
| 3554 | mActivateNeedsAnimation = false; |
| 3555 | } |
| 3556 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3557 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3558 | private void generateAnimateEverythingEvent() { |
| 3559 | if (mEverythingNeedsAnimation) { |
| 3560 | mAnimationEvents.add( |
| 3561 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3562 | } |
| 3563 | mEverythingNeedsAnimation = false; |
| 3564 | } |
| 3565 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3566 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3567 | private void generateDimmedEvent() { |
| 3568 | if (mDimmedNeedsAnimation) { |
| 3569 | mAnimationEvents.add( |
| 3570 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3571 | } |
| 3572 | mDimmedNeedsAnimation = false; |
| 3573 | } |
| 3574 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3575 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3576 | private void generateHideSensitiveEvent() { |
| 3577 | if (mHideSensitiveNeedsAnimation) { |
| 3578 | mAnimationEvents.add( |
| 3579 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3580 | } |
| 3581 | mHideSensitiveNeedsAnimation = false; |
| 3582 | } |
| 3583 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3584 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3585 | private void generateDarkEvent() { |
| 3586 | if (mDarkNeedsAnimation) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 3587 | AnimationEvent ev = new AnimationEvent(null, |
| 3588 | AnimationEvent.ANIMATION_TYPE_DARK, |
| 3589 | new AnimationFilter() |
| 3590 | .animateDark() |
| 3591 | .animateY(mShelf)); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3592 | ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex; |
| 3593 | mAnimationEvents.add(ev); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3594 | } |
| 3595 | mDarkNeedsAnimation = false; |
| 3596 | } |
| 3597 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3598 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3599 | private void generateGoToFullShadeEvent() { |
| 3600 | if (mGoToFullShadeNeedsAnimation) { |
| 3601 | mAnimationEvents.add( |
| 3602 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3603 | } |
| 3604 | mGoToFullShadeNeedsAnimation = false; |
| 3605 | } |
| 3606 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3607 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
| 3608 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3609 | return new StackScrollAlgorithm(context, this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | /** |
| 3613 | * @return Whether a y coordinate is inside the content. |
| 3614 | */ |
| 3615 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 3616 | public boolean isInContentBounds(float y) { |
| 3617 | return y < getHeight() - getEmptyBottomMargin(); |
| 3618 | } |
| 3619 | |
| 3620 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3621 | public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) { |
| 3622 | mLongPressListener = listener; |
| 3623 | } |
| 3624 | |
| 3625 | @Override |
| 3626 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3627 | public boolean onTouchEvent(MotionEvent ev) { |
| 3628 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 3629 | || ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3630 | handleEmptySpaceClick(ev); |
| 3631 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3632 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3633 | if (mIsExpanded && !swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3634 | if (isCancelOrUp) { |
| 3635 | mExpandHelper.onlyObserveMovements(false); |
| 3636 | } |
| 3637 | boolean wasExpandingBefore = mExpandingNotification; |
| 3638 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
| 3639 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 3640 | && !mDisallowScrollingInThisMotion) { |
| 3641 | dispatchDownEventToScroller(ev); |
| 3642 | } |
| 3643 | } |
| 3644 | boolean scrollerWantsIt = false; |
| 3645 | if (mIsExpanded && !swipingInProgress && !mExpandingNotification |
| 3646 | && !mDisallowScrollingInThisMotion) { |
| 3647 | scrollerWantsIt = onScrollTouch(ev); |
| 3648 | } |
| 3649 | boolean horizontalSwipeWantsIt = false; |
| 3650 | if (!mIsBeingDragged |
| 3651 | && !mExpandingNotification |
| 3652 | && !mExpandedInThisMotion |
| 3653 | && !mOnlyScrollingInThisMotion |
| 3654 | && !mDisallowDismissInThisMotion) { |
| 3655 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 3656 | } |
| 3657 | |
| 3658 | // Check if we need to clear any snooze leavebehinds |
| 3659 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3660 | if (guts != null && !NotificationSwipeHelper.isTouchInView(ev, guts) |
| 3661 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 3662 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 3663 | if ((ns.isExpanded() && isCancelOrUp) |
| 3664 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 3665 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 3666 | // clear it on the next non-horizontal swipe or expand event. |
| 3667 | checkSnoozeLeavebehind(); |
| 3668 | } |
| 3669 | } |
| 3670 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3671 | mCheckForLeavebehind = true; |
| 3672 | } |
| 3673 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 3674 | } |
| 3675 | |
| 3676 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3677 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 3678 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 3679 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 3680 | onScrollTouch(downEvent); |
| 3681 | downEvent.recycle(); |
| 3682 | } |
| 3683 | |
| 3684 | @Override |
| 3685 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3686 | public boolean onGenericMotionEvent(MotionEvent event) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3687 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3688 | || mDisallowScrollingInThisMotion) { |
| 3689 | return false; |
| 3690 | } |
| 3691 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3692 | switch (event.getAction()) { |
| 3693 | case MotionEvent.ACTION_SCROLL: { |
| 3694 | if (!mIsBeingDragged) { |
| 3695 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 3696 | if (vscroll != 0) { |
| 3697 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3698 | if (ANCHOR_SCROLLING) { |
| 3699 | mScrollAnchorViewY -= delta; |
| 3700 | updateScrollAnchor(); |
| 3701 | clampScrollPosition(); |
| 3702 | updateOnScrollChange(); |
| 3703 | } else { |
| 3704 | final int range = getScrollRange(); |
| 3705 | int oldScrollY = mOwnScrollY; |
| 3706 | int newScrollY = oldScrollY - delta; |
| 3707 | if (newScrollY < 0) { |
| 3708 | newScrollY = 0; |
| 3709 | } else if (newScrollY > range) { |
| 3710 | newScrollY = range; |
| 3711 | } |
| 3712 | if (newScrollY != oldScrollY) { |
| 3713 | setOwnScrollY(newScrollY); |
| 3714 | return true; |
| 3715 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3716 | } |
| 3717 | } |
| 3718 | } |
| 3719 | } |
| 3720 | } |
| 3721 | } |
| 3722 | return super.onGenericMotionEvent(event); |
| 3723 | } |
| 3724 | |
| 3725 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3726 | private boolean onScrollTouch(MotionEvent ev) { |
| 3727 | if (!isScrollingEnabled()) { |
| 3728 | return false; |
| 3729 | } |
| 3730 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
| 3731 | return false; |
| 3732 | } |
| 3733 | mForcedScroll = null; |
| 3734 | initVelocityTrackerIfNotExists(); |
| 3735 | mVelocityTracker.addMovement(ev); |
| 3736 | |
| 3737 | final int action = ev.getAction(); |
| 3738 | |
| 3739 | switch (action & MotionEvent.ACTION_MASK) { |
| 3740 | case MotionEvent.ACTION_DOWN: { |
| 3741 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
| 3742 | return false; |
| 3743 | } |
| 3744 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3745 | setIsBeingDragged(isBeingDragged); |
| 3746 | /* |
| 3747 | * If being flinged and user touches, stop the fling. isFinished |
| 3748 | * will be false if being flinged. |
| 3749 | */ |
| 3750 | if (!mScroller.isFinished()) { |
| 3751 | mScroller.forceFinished(true); |
| 3752 | } |
| 3753 | |
| 3754 | // Remember where the motion event started |
| 3755 | mLastMotionY = (int) ev.getY(); |
| 3756 | mDownX = (int) ev.getX(); |
| 3757 | mActivePointerId = ev.getPointerId(0); |
| 3758 | break; |
| 3759 | } |
| 3760 | case MotionEvent.ACTION_MOVE: |
| 3761 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 3762 | if (activePointerIndex == -1) { |
| 3763 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 3764 | break; |
| 3765 | } |
| 3766 | |
| 3767 | final int y = (int) ev.getY(activePointerIndex); |
| 3768 | final int x = (int) ev.getX(activePointerIndex); |
| 3769 | int deltaY = mLastMotionY - y; |
| 3770 | final int xDiff = Math.abs(x - mDownX); |
| 3771 | final int yDiff = Math.abs(deltaY); |
| 3772 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
| 3773 | setIsBeingDragged(true); |
| 3774 | if (deltaY > 0) { |
| 3775 | deltaY -= mTouchSlop; |
| 3776 | } else { |
| 3777 | deltaY += mTouchSlop; |
| 3778 | } |
| 3779 | } |
| 3780 | if (mIsBeingDragged) { |
| 3781 | // Scroll to follow the motion event |
| 3782 | mLastMotionY = y; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3783 | float scrollAmount; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3784 | int range; |
| 3785 | if (ANCHOR_SCROLLING) { |
| 3786 | range = 0; // unused in the methods it's being passed to |
| 3787 | } else { |
| 3788 | range = getScrollRange(); |
| 3789 | if (mExpandedInThisMotion) { |
| 3790 | range = Math.min(range, mMaxScrollAfterExpand); |
| 3791 | } |
| 3792 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3793 | if (deltaY < 0) { |
| 3794 | scrollAmount = overScrollDown(deltaY); |
| 3795 | } else { |
| 3796 | scrollAmount = overScrollUp(deltaY, range); |
| 3797 | } |
| 3798 | |
| 3799 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 3800 | // sets the scrolling if applicable. |
| 3801 | if (scrollAmount != 0.0f) { |
| 3802 | // The scrolling motion could not be compensated with the |
| 3803 | // existing overScroll, we have to scroll the view |
| 3804 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 3805 | range, getHeight() / 2); |
| 3806 | // If we're scrolling, leavebehinds should be dismissed |
| 3807 | checkSnoozeLeavebehind(); |
| 3808 | } |
| 3809 | } |
| 3810 | break; |
| 3811 | case MotionEvent.ACTION_UP: |
| 3812 | if (mIsBeingDragged) { |
| 3813 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 3814 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 3815 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 3816 | |
| 3817 | if (shouldOverScrollFling(initialVelocity)) { |
| 3818 | onOverScrollFling(true, initialVelocity); |
| 3819 | } else { |
| 3820 | if (getChildCount() > 0) { |
| 3821 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 3822 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 3823 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 3824 | fling(-initialVelocity); |
| 3825 | } else { |
| 3826 | onOverScrollFling(false, initialVelocity); |
| 3827 | } |
| 3828 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3829 | if (ANCHOR_SCROLLING) { |
| 3830 | // TODO |
| 3831 | } else { |
| 3832 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3833 | getScrollRange())) { |
| 3834 | animateScroll(); |
| 3835 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3836 | } |
| 3837 | } |
| 3838 | } |
| 3839 | } |
| 3840 | mActivePointerId = INVALID_POINTER; |
| 3841 | endDrag(); |
| 3842 | } |
| 3843 | |
| 3844 | break; |
| 3845 | case MotionEvent.ACTION_CANCEL: |
| 3846 | if (mIsBeingDragged && getChildCount() > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3847 | if (ANCHOR_SCROLLING) { |
| 3848 | // TODO |
| 3849 | } else { |
| 3850 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3851 | getScrollRange())) { |
| 3852 | animateScroll(); |
| 3853 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3854 | } |
| 3855 | mActivePointerId = INVALID_POINTER; |
| 3856 | endDrag(); |
| 3857 | } |
| 3858 | break; |
| 3859 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 3860 | final int index = ev.getActionIndex(); |
| 3861 | mLastMotionY = (int) ev.getY(index); |
| 3862 | mDownX = (int) ev.getX(index); |
| 3863 | mActivePointerId = ev.getPointerId(index); |
| 3864 | break; |
| 3865 | } |
| 3866 | case MotionEvent.ACTION_POINTER_UP: |
| 3867 | onSecondaryPointerUp(ev); |
| 3868 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
| 3869 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
| 3870 | break; |
| 3871 | } |
| 3872 | return true; |
| 3873 | } |
| 3874 | |
| 3875 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3876 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 3877 | return ev.getY() < mQsContainer.getBottom(); |
| 3878 | } |
| 3879 | |
| 3880 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3881 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 3882 | if (mOverscrollTopChangedListener != null) { |
| 3883 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 3884 | } |
| 3885 | mDontReportNextOverScroll = true; |
| 3886 | setOverScrollAmount(0.0f, true, false); |
| 3887 | } |
| 3888 | |
| 3889 | |
| 3890 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3891 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 3892 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 3893 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 3894 | final int pointerId = ev.getPointerId(pointerIndex); |
| 3895 | if (pointerId == mActivePointerId) { |
| 3896 | // This was our active pointer going up. Choose a new |
| 3897 | // active pointer and adjust accordingly. |
| 3898 | // TODO: Make this decision more intelligent. |
| 3899 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 3900 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 3901 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 3902 | if (mVelocityTracker != null) { |
| 3903 | mVelocityTracker.clear(); |
| 3904 | } |
| 3905 | } |
| 3906 | } |
| 3907 | |
| 3908 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3909 | private void endDrag() { |
| 3910 | setIsBeingDragged(false); |
| 3911 | |
| 3912 | recycleVelocityTracker(); |
| 3913 | |
| 3914 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 3915 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 3916 | } |
| 3917 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 3918 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 3919 | } |
| 3920 | } |
| 3921 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3922 | @Override |
| 3923 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3924 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 3925 | initDownStates(ev); |
| 3926 | handleEmptySpaceClick(ev); |
| 3927 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3928 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3929 | if (!swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3930 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 3931 | } |
| 3932 | boolean scrollWantsIt = false; |
| 3933 | if (!swipingInProgress && !mExpandingNotification) { |
| 3934 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 3935 | } |
| 3936 | boolean swipeWantsIt = false; |
| 3937 | if (!mIsBeingDragged |
| 3938 | && !mExpandingNotification |
| 3939 | && !mExpandedInThisMotion |
| 3940 | && !mOnlyScrollingInThisMotion |
| 3941 | && !mDisallowDismissInThisMotion) { |
| 3942 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 3943 | } |
| 3944 | // Check if we need to clear any snooze leavebehinds |
| 3945 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3946 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3947 | if (!NotificationSwipeHelper.isTouchInView(ev, guts) && isUp && !swipeWantsIt && |
| 3948 | !expandWantsIt && !scrollWantsIt) { |
| 3949 | mCheckForLeavebehind = false; |
| 3950 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 3951 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 3952 | false /* resetMenu */); |
| 3953 | } |
| 3954 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3955 | mCheckForLeavebehind = true; |
| 3956 | } |
| 3957 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 3958 | } |
| 3959 | |
| 3960 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3961 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 3962 | switch (ev.getActionMasked()) { |
| 3963 | case MotionEvent.ACTION_MOVE: |
| 3964 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 3965 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop)) { |
| 3966 | mTouchIsClick = false; |
| 3967 | } |
| 3968 | break; |
| 3969 | case MotionEvent.ACTION_UP: |
| 3970 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
| 3971 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 3972 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 3973 | } |
| 3974 | break; |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3979 | private void initDownStates(MotionEvent ev) { |
| 3980 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3981 | mExpandedInThisMotion = false; |
| 3982 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
| 3983 | mDisallowScrollingInThisMotion = false; |
| 3984 | mDisallowDismissInThisMotion = false; |
| 3985 | mTouchIsClick = true; |
| 3986 | mInitialTouchX = ev.getX(); |
| 3987 | mInitialTouchY = ev.getY(); |
| 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | @Override |
| 3992 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3993 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 3994 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 3995 | if (disallowIntercept) { |
| 3996 | cancelLongPress(); |
| 3997 | } |
| 3998 | } |
| 3999 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4000 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4001 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4002 | if (!isScrollingEnabled()) { |
| 4003 | return false; |
| 4004 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4005 | /* |
| 4006 | * This method JUST determines whether we want to intercept the motion. |
| 4007 | * If we return true, onMotionEvent will be called and we do the actual |
| 4008 | * scrolling there. |
| 4009 | */ |
| 4010 | |
| 4011 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4012 | * Shortcut the most recurring case: the user is in the dragging |
| 4013 | * state and is moving their finger. We want to intercept this |
| 4014 | * motion. |
| 4015 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4016 | final int action = ev.getAction(); |
| 4017 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 4018 | return true; |
| 4019 | } |
| 4020 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4021 | switch (action & MotionEvent.ACTION_MASK) { |
| 4022 | case MotionEvent.ACTION_MOVE: { |
| 4023 | /* |
| 4024 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 4025 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4026 | */ |
| 4027 | |
| 4028 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4029 | * Locally do absolute value. mLastMotionY is set to the y value |
| 4030 | * of the down event. |
| 4031 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4032 | final int activePointerId = mActivePointerId; |
| 4033 | if (activePointerId == INVALID_POINTER) { |
| 4034 | // If we don't have a valid id, the touch down wasn't on content. |
| 4035 | break; |
| 4036 | } |
| 4037 | |
| 4038 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 4039 | if (pointerIndex == -1) { |
| 4040 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 4041 | + " in onInterceptTouchEvent"); |
| 4042 | break; |
| 4043 | } |
| 4044 | |
| 4045 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4046 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4047 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4048 | final int xDiff = Math.abs(x - mDownX); |
| 4049 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4050 | setIsBeingDragged(true); |
| 4051 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4052 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4053 | initVelocityTrackerIfNotExists(); |
| 4054 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4055 | } |
| 4056 | break; |
| 4057 | } |
| 4058 | |
| 4059 | case MotionEvent.ACTION_DOWN: { |
| 4060 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 4061 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 4062 | if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4063 | setIsBeingDragged(false); |
| 4064 | recycleVelocityTracker(); |
| 4065 | break; |
| 4066 | } |
| 4067 | |
| 4068 | /* |
| 4069 | * Remember location of down touch. |
| 4070 | * ACTION_DOWN always refers to pointer index 0. |
| 4071 | */ |
| 4072 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4073 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4074 | mActivePointerId = ev.getPointerId(0); |
| 4075 | |
| 4076 | initOrResetVelocityTracker(); |
| 4077 | mVelocityTracker.addMovement(ev); |
| 4078 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4079 | * If being flinged and user touches the screen, initiate drag; |
| 4080 | * otherwise don't. mScroller.isFinished should be false when |
| 4081 | * being flinged. |
| 4082 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4083 | boolean isBeingDragged = !mScroller.isFinished(); |
| 4084 | setIsBeingDragged(isBeingDragged); |
| 4085 | break; |
| 4086 | } |
| 4087 | |
| 4088 | case MotionEvent.ACTION_CANCEL: |
| 4089 | case MotionEvent.ACTION_UP: |
| 4090 | /* Release the drag */ |
| 4091 | setIsBeingDragged(false); |
| 4092 | mActivePointerId = INVALID_POINTER; |
| 4093 | recycleVelocityTracker(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4094 | if (ANCHOR_SCROLLING) { |
| 4095 | // TODO |
| 4096 | } else { |
| 4097 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 4098 | animateScroll(); |
| 4099 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4100 | } |
| 4101 | break; |
| 4102 | case MotionEvent.ACTION_POINTER_UP: |
| 4103 | onSecondaryPointerUp(ev); |
| 4104 | break; |
| 4105 | } |
| 4106 | |
| 4107 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4108 | * The only time we want to intercept motion events is if we are in the |
| 4109 | * drag mode. |
| 4110 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4111 | return mIsBeingDragged; |
| 4112 | } |
| 4113 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4114 | /** |
| 4115 | * @return Whether the specified motion event is actually happening over the content. |
| 4116 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4117 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4118 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 4119 | return isInContentBounds(event.getY()); |
| 4120 | } |
| 4121 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4122 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4123 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4124 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4125 | void setIsBeingDragged(boolean isDragged) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4126 | mIsBeingDragged = isDragged; |
| 4127 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4128 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4129 | cancelLongPress(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4130 | resetExposedMenuView(true /* animate */, true /* force */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4131 | } |
| 4132 | } |
| 4133 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4134 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4135 | public void requestDisallowLongPress() { |
| 4136 | cancelLongPress(); |
| 4137 | } |
| 4138 | |
| 4139 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4140 | public void requestDisallowDismiss() { |
| 4141 | mDisallowDismissInThisMotion = true; |
| 4142 | } |
| 4143 | |
| 4144 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4145 | public void cancelLongPress() { |
| 4146 | mSwipeHelper.cancelLongPress(); |
| 4147 | } |
| 4148 | |
| 4149 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4150 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 4151 | mOnEmptySpaceClickListener = listener; |
| 4152 | } |
| 4153 | |
| 4154 | /** @hide */ |
| 4155 | @Override |
| 4156 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4157 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4158 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4159 | return true; |
| 4160 | } |
| 4161 | if (!isEnabled()) { |
| 4162 | return false; |
| 4163 | } |
| 4164 | int direction = -1; |
| 4165 | switch (action) { |
| 4166 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4167 | // fall through |
| 4168 | case android.R.id.accessibilityActionScrollDown: |
| 4169 | direction = 1; |
| 4170 | // fall through |
| 4171 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4172 | // fall through |
| 4173 | case android.R.id.accessibilityActionScrollUp: |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4174 | if (ANCHOR_SCROLLING) { |
| 4175 | // TODO |
| 4176 | } else { |
| 4177 | final int viewportHeight = |
| 4178 | getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
| 4179 | - mShelf.getIntrinsicHeight(); |
| 4180 | final int targetScrollY = Math.max(0, |
| 4181 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4182 | if (targetScrollY != mOwnScrollY) { |
| 4183 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, |
| 4184 | targetScrollY - mOwnScrollY); |
| 4185 | animateScroll(); |
| 4186 | return true; |
| 4187 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4188 | } |
| 4189 | break; |
| 4190 | } |
| 4191 | return false; |
| 4192 | } |
| 4193 | |
| 4194 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4195 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4196 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 4197 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 4198 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 4199 | View view = null; |
| 4200 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4201 | // Only close visible guts if they're not a leavebehind. |
| 4202 | view = guts; |
| 4203 | } else if (menuRow != null && menuRow.isMenuVisible() |
| 4204 | && translatingParentView != null) { |
| 4205 | // Checking menu |
| 4206 | view = translatingParentView; |
| 4207 | } |
| 4208 | if (view != null && !NotificationSwipeHelper.isTouchInView(ev, view)) { |
| 4209 | // Touch was outside visible guts / menu notification, close what's visible |
| 4210 | mNotificationGutsManager.closeAndSaveGuts(false /* removeLeavebehind */, |
| 4211 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4212 | false /* resetMenu */); |
| 4213 | resetExposedMenuView(true /* animate */, true /* force */); |
| 4214 | } |
| 4215 | } |
| 4216 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 4217 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4218 | private void setSwipingInProgress(boolean swiping) { |
| 4219 | mSwipingInProgress = swiping; |
| 4220 | if (swiping) { |
| 4221 | requestDisallowInterceptTouchEvent(true); |
| 4222 | } |
| 4223 | } |
| 4224 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4225 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4226 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4227 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4228 | super.onWindowFocusChanged(hasWindowFocus); |
| 4229 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4230 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4231 | } |
| 4232 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4233 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 4234 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4235 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 4236 | public void clearChildFocus(View child) { |
| 4237 | super.clearChildFocus(child); |
| 4238 | if (mForcedScroll == child) { |
| 4239 | mForcedScroll = null; |
| 4240 | } |
| 4241 | } |
| 4242 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4243 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4244 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4245 | public boolean isScrolledToTop() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4246 | if (ANCHOR_SCROLLING) { |
| 4247 | updateScrollAnchor(); |
| 4248 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 4249 | return mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY >= 0; |
| 4250 | } else { |
| 4251 | return mOwnScrollY == 0; |
| 4252 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4256 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4257 | public boolean isScrolledToBottom() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4258 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 4259 | return getMaxPositiveScrollAmount() <= 0; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4260 | } else { |
| 4261 | return mOwnScrollY >= getScrollRange(); |
| 4262 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4266 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4267 | public View getHostView() { |
| 4268 | return this; |
| 4269 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4270 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4271 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4272 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4273 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4274 | } |
| 4275 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4276 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4277 | public void checkSnoozeLeavebehind() { |
| 4278 | if (mCheckForLeavebehind) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 4279 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4280 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4281 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4282 | mCheckForLeavebehind = false; |
| 4283 | } |
| 4284 | } |
| 4285 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4286 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4287 | public void resetCheckSnoozeLeavebehind() { |
| 4288 | mCheckForLeavebehind = true; |
| 4289 | } |
| 4290 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4291 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4292 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4293 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4294 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4295 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4296 | } |
| 4297 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4298 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4299 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4300 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4301 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4302 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4303 | if (!mIsExpanded) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4304 | resetScrollPosition(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4305 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4306 | clearTemporaryViews(); |
| 4307 | clearUserLockedViews(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4308 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 4309 | if (draggedViews.size() > 0) { |
| 4310 | draggedViews.clear(); |
| 4311 | updateContinuousShadowDrawing(); |
| 4312 | } |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4313 | } |
| 4314 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 4315 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4316 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4317 | private void clearUserLockedViews() { |
| 4318 | for (int i = 0; i < getChildCount(); i++) { |
| 4319 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4320 | if (child instanceof ExpandableNotificationRow) { |
| 4321 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4322 | row.setUserLocked(false); |
| 4323 | } |
| 4324 | } |
| 4325 | } |
| 4326 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4327 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4328 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4329 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4330 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4331 | for (int i = 0; i < getChildCount(); i++) { |
| 4332 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4333 | if (child instanceof ExpandableNotificationRow) { |
| 4334 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4335 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4336 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4337 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4338 | } |
| 4339 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4340 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4341 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4342 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 4343 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4344 | } |
| 4345 | } |
| 4346 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4347 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4348 | public void onPanelTrackingStarted() { |
| 4349 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4350 | mAmbientState.setPanelTracking(true); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4351 | resetExposedMenuView(true /* animate */, true /* force */); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4352 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4353 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4354 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4355 | public void onPanelTrackingStopped() { |
| 4356 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4357 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4360 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4361 | public void resetScrollPosition() { |
| 4362 | mScroller.abortAnimation(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4363 | if (ANCHOR_SCROLLING) { |
| 4364 | // TODO: once we're recycling this will need to modify the adapter position instead |
| 4365 | mScrollAnchorView = getFirstChildNotGone(); |
| 4366 | mScrollAnchorViewY = 0; |
| 4367 | updateOnScrollChange(); |
| 4368 | } else { |
| 4369 | setOwnScrollY(0); |
| 4370 | } |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4371 | } |
| 4372 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4373 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4374 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4375 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4376 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4377 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4378 | mAmbientState.setShadeExpanded(isExpanded); |
| 4379 | mStateAnimator.setShadeExpanded(isExpanded); |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 4380 | mSwipeHelper.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4381 | if (changed) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4382 | if (!mIsExpanded) { |
| 4383 | mGroupManager.collapseAllGroups(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4384 | mExpandHelper.cancelImmediately(); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4385 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4386 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4387 | updateChronometers(); |
Selim Cinek | f3fa685 | 2016-12-20 18:36:02 +0100 | [diff] [blame] | 4388 | requestChildrenUpdate(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4389 | } |
| 4390 | } |
| 4391 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4392 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4393 | private void updateChronometers() { |
| 4394 | int childCount = getChildCount(); |
| 4395 | for (int i = 0; i < childCount; i++) { |
| 4396 | updateChronometerForChild(getChildAt(i)); |
| 4397 | } |
| 4398 | } |
| 4399 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4400 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4401 | private void updateChronometerForChild(View child) { |
| 4402 | if (child instanceof ExpandableNotificationRow) { |
| 4403 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4404 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4405 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4406 | } |
| 4407 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4408 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4409 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4410 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4411 | updateScrollPositionOnExpandInBottom(view); |
| 4412 | clampScrollPosition(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4413 | notifyHeightChangeListener(view, needsAnimation); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4414 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 4415 | ? (ExpandableNotificationRow) view |
| 4416 | : null; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4417 | NotificationSection firstSection = getFirstVisibleSection(); |
| 4418 | ActivatableNotificationView firstVisibleChild = |
| 4419 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 4420 | if (row != null) { |
| 4421 | if (row == firstVisibleChild |
| 4422 | || row.getNotificationParent() == firstVisibleChild) { |
| 4423 | updateAlgorithmLayoutMinHeight(); |
| 4424 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4425 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4426 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 4427 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4428 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4429 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4430 | } |
| 4431 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4432 | @Override |
| 4433 | public void onReset(ExpandableView view) { |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 4434 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4435 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4436 | } |
| 4437 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4438 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4439 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 4440 | if (view instanceof ExpandableNotificationRow && !onKeyguard()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4441 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4442 | // 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] | 4443 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4444 | if (row.isSummaryWithChildren()) { |
| 4445 | return; |
| 4446 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4447 | // We are actually expanding this view |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4448 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4449 | if (row.isChildInGroup()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4450 | endPosition += row.getNotificationParent().getTranslationY(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4451 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4452 | int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4453 | NotificationSection lastSection = getLastVisibleSection(); |
| 4454 | ActivatableNotificationView lastVisibleChild = |
| 4455 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
| 4456 | if (row != lastVisibleChild && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4457 | layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements; |
| 4458 | } |
| 4459 | if (endPosition > layoutEnd) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4460 | if (ANCHOR_SCROLLING) { |
| 4461 | mScrollAnchorViewY -= (endPosition - layoutEnd); |
| 4462 | updateScrollAnchor(); |
| 4463 | updateOnScrollChange(); |
| 4464 | } else { |
| 4465 | setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd)); |
| 4466 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4467 | mDisallowScrollingInThisMotion = true; |
| 4468 | } |
| 4469 | } |
| 4470 | } |
| 4471 | } |
| 4472 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4473 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4474 | public void setOnHeightChangedListener( |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4475 | ExpandableView.OnHeightChangedListener onHeightChangedListener) { |
| 4476 | this.mOnHeightChangedListener = onHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4477 | } |
| 4478 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4479 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4480 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4481 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 4482 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4483 | runAnimationFinishedRunnables(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4484 | clearTransient(); |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4485 | clearHeadsUpDisappearRunning(); |
| 4486 | } |
| 4487 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4488 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4489 | private void clearHeadsUpDisappearRunning() { |
| 4490 | for (int i = 0; i < getChildCount(); i++) { |
| 4491 | View view = getChildAt(i); |
| 4492 | if (view instanceof ExpandableNotificationRow) { |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4493 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4494 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4495 | if (row.isSummaryWithChildren()) { |
| 4496 | for (ExpandableNotificationRow child : row.getNotificationChildren()) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4497 | child.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4498 | } |
| 4499 | } |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4500 | } |
| 4501 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4504 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4505 | private void clearTransient() { |
| 4506 | for (ExpandableView view : mClearTransientViewsWhenFinished) { |
| 4507 | StackStateAnimator.removeTransientView(view); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4508 | } |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4509 | mClearTransientViewsWhenFinished.clear(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4510 | } |
| 4511 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4512 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4513 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4514 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 4515 | runnable.run(); |
| 4516 | } |
| 4517 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4518 | } |
| 4519 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4520 | /** |
| 4521 | * See {@link AmbientState#setDimmed}. |
| 4522 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4523 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4524 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4525 | dimmed &= onKeyguard(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4526 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4527 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4528 | mDimmedNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4529 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4530 | animateDimmed(dimmed); |
| 4531 | } else { |
| 4532 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4533 | } |
| 4534 | requestChildrenUpdate(); |
| 4535 | } |
| 4536 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4537 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4538 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4539 | boolean isDimmed() { |
| 4540 | return mAmbientState.isDimmed(); |
| 4541 | } |
| 4542 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4543 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4544 | private void setDimAmount(float dimAmount) { |
| 4545 | mDimAmount = dimAmount; |
| 4546 | updateBackgroundDimming(); |
| 4547 | } |
| 4548 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4549 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4550 | private void animateDimmed(boolean dimmed) { |
| 4551 | if (mDimAnimator != null) { |
| 4552 | mDimAnimator.cancel(); |
| 4553 | } |
| 4554 | float target = dimmed ? 1.0f : 0.0f; |
| 4555 | if (target == mDimAmount) { |
| 4556 | return; |
| 4557 | } |
| 4558 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 4559 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 4560 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 4561 | mDimAnimator.addListener(mDimEndListener); |
| 4562 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 4563 | mDimAnimator.start(); |
| 4564 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4565 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4566 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4567 | private void setHideSensitive(boolean hideSensitive, boolean animate) { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4568 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 4569 | int childCount = getChildCount(); |
| 4570 | for (int i = 0; i < childCount; i++) { |
| 4571 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 4572 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 4573 | } |
| 4574 | mAmbientState.setHideSensitive(hideSensitive); |
| 4575 | if (animate && mAnimationsEnabled) { |
| 4576 | mHideSensitiveNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4577 | mNeedsAnimation = true; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4578 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 4579 | updateContentHeight(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4580 | requestChildrenUpdate(); |
| 4581 | } |
| 4582 | } |
| 4583 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4584 | /** |
| 4585 | * See {@link AmbientState#setActivatedChild}. |
| 4586 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4587 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4588 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4589 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4590 | if (mAnimationsEnabled) { |
| 4591 | mActivateNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4592 | mNeedsAnimation = true; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4593 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4594 | requestChildrenUpdate(); |
| 4595 | } |
| 4596 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4597 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4598 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4599 | return mAmbientState.getActivatedChild(); |
| 4600 | } |
| 4601 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4602 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4603 | private void applyCurrentState() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4604 | int numChildren = getChildCount(); |
| 4605 | for (int i = 0; i < numChildren; i++) { |
| 4606 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4607 | child.applyViewState(); |
| 4608 | } |
| 4609 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4610 | if (mListener != null) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4611 | mListener.onChildLocationsChanged(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4612 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4613 | runAnimationFinishedRunnables(); |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 4614 | setAnimationRunning(false); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4615 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4616 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 4617 | updateClippingToTopRoundedCorner(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4618 | } |
| 4619 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4620 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4621 | private void updateViewShadows() { |
| 4622 | // we need to work around an issue where the shadow would not cast between siblings when |
| 4623 | // their z difference is between 0 and 0.1 |
| 4624 | |
| 4625 | // Lefts first sort by Z difference |
| 4626 | for (int i = 0; i < getChildCount(); i++) { |
| 4627 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4628 | if (child.getVisibility() != GONE) { |
| 4629 | mTmpSortedChildren.add(child); |
| 4630 | } |
| 4631 | } |
| 4632 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 4633 | |
| 4634 | // Now lets update the shadow for the views |
| 4635 | ExpandableView previous = null; |
| 4636 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 4637 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 4638 | float translationZ = expandableView.getTranslationZ(); |
| 4639 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 4640 | float diff = otherZ - translationZ; |
| 4641 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 4642 | // There is no fake shadow to be drawn |
| 4643 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 4644 | } else { |
| 4645 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 4646 | expandableView.getTranslationY() - previous.getExtraBottomPadding(); |
| 4647 | expandableView.setFakeShadowIntensity( |
| 4648 | diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4649 | previous.getOutlineAlpha(), (int) yLocation, |
| 4650 | previous.getOutlineTranslation()); |
| 4651 | } |
| 4652 | previous = expandableView; |
| 4653 | } |
| 4654 | |
| 4655 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4656 | } |
| 4657 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4658 | /** |
| 4659 | * Update colors of "dismiss" and "empty shade" views. |
| 4660 | * |
| 4661 | * @param lightTheme True if light theme should be used. |
| 4662 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4663 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4664 | public void updateDecorViews(boolean lightTheme) { |
| 4665 | if (lightTheme == mUsingLightTheme) { |
| 4666 | return; |
| 4667 | } |
| 4668 | mUsingLightTheme = lightTheme; |
| 4669 | Context context = new ContextThemeWrapper(mContext, |
| 4670 | lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 4671 | final int textColor = Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4672 | mFooterView.setTextColor(textColor); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4673 | mEmptyShadeView.setTextColor(textColor); |
| 4674 | } |
| 4675 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4676 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4677 | public void goToFullShade(long delay) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4678 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4679 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4680 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4681 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4682 | } |
| 4683 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4684 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4685 | public void cancelExpandHelper() { |
| 4686 | mExpandHelper.cancel(); |
| 4687 | } |
| 4688 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4689 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4690 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 4691 | mIntrinsicPadding = intrinsicPadding; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 4692 | mAmbientState.setIntrinsicPadding(intrinsicPadding); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4693 | } |
| 4694 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4695 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 4696 | public int getIntrinsicPadding() { |
| 4697 | return mIntrinsicPadding; |
| 4698 | } |
| 4699 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4700 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4701 | * @return the y position of the first notification |
| 4702 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4703 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4704 | public float getNotificationsTopY() { |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4705 | return mTopPadding + getStackTranslation(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4706 | } |
| 4707 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4708 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4709 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4710 | public boolean shouldDelayChildPressedState() { |
| 4711 | return true; |
| 4712 | } |
| 4713 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4714 | /** |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4715 | * See {@link AmbientState#setDozing}. |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4716 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4717 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4718 | public void setDozing(boolean dozing, boolean animate, |
| 4719 | @Nullable PointF touchWakeUpScreenLocation) { |
| 4720 | if (mAmbientState.isDozing() == dozing) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 4721 | return; |
| 4722 | } |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 4723 | mAmbientState.setDozing(dozing); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4724 | if (animate && mAnimationsEnabled) { |
| 4725 | mDarkNeedsAnimation = true; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4726 | mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4727 | mNeedsAnimation = true; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4728 | } |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4729 | requestChildrenUpdate(); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4730 | updateWillNotDraw(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4731 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4732 | } |
| 4733 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4734 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4735 | private void updatePanelTranslation() { |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 4736 | setTranslationX(mHorizontalPanelTranslation + mAntiBurnInOffsetX * mInterpolatedDarkAmount); |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4737 | } |
| 4738 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4739 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 4740 | public void setHorizontalPanelTranslation(float verticalPanelTranslation) { |
| 4741 | mHorizontalPanelTranslation = verticalPanelTranslation; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4742 | updatePanelTranslation(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 4743 | } |
| 4744 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4745 | /** |
| 4746 | * Updates whether or not this Layout will perform its own custom drawing (i.e. whether or |
| 4747 | * not {@link #onDraw(Canvas)} is called). This method should be called whenever the |
| 4748 | * {@link #mAmbientState}'s dark mode is toggled. |
| 4749 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4750 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4751 | private void updateWillNotDraw() { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4752 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 4753 | setWillNotDraw(!willDraw); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4754 | } |
| 4755 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4756 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4757 | private void setDarkAmount(float darkAmount) { |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4758 | setDarkAmount(darkAmount, darkAmount); |
| 4759 | } |
| 4760 | |
| 4761 | /** |
| 4762 | * Sets the current dark amount. |
| 4763 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4764 | * @param linearDarkAmount The dark amount that follows linear interpoloation in the |
| 4765 | * animation, |
| 4766 | * i.e. animates from 0 to 1 or vice-versa in a linear manner. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4767 | * @param interpolatedDarkAmount The dark amount that follows the actual interpolation of the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4768 | * animation curve. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4769 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4770 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4771 | public void setDarkAmount(float linearDarkAmount, float interpolatedDarkAmount) { |
| 4772 | mLinearDarkAmount = linearDarkAmount; |
| 4773 | mInterpolatedDarkAmount = interpolatedDarkAmount; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4774 | boolean wasFullyDark = mAmbientState.isFullyDark(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4775 | boolean wasDarkAtAll = mAmbientState.isDarkAtAll(); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4776 | mAmbientState.setDarkAmount(interpolatedDarkAmount); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4777 | boolean nowFullyDark = mAmbientState.isFullyDark(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4778 | boolean nowDarkAtAll = mAmbientState.isDarkAtAll(); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4779 | if (nowFullyDark != wasFullyDark) { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4780 | updateContentHeight(); |
Selim Cinek | 1e05927 | 2019-05-21 18:15:00 -0700 | [diff] [blame] | 4781 | if (nowFullyDark) { |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4782 | updateDarkShelfVisibility(); |
| 4783 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4784 | } |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4785 | if (!wasDarkAtAll && nowDarkAtAll) { |
| 4786 | resetExposedMenuView(true /* animate */, true /* animate */); |
| 4787 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 4788 | if (nowFullyDark != wasFullyDark || wasDarkAtAll != nowDarkAtAll) { |
| 4789 | invalidateOutline(); |
| 4790 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4791 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4792 | updateBackgroundDimming(); |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4793 | updatePanelTranslation(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4794 | requestChildrenUpdate(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4795 | } |
| 4796 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4797 | private void updateDarkShelfVisibility() { |
| 4798 | DozeParameters dozeParameters = DozeParameters.getInstance(mContext); |
| 4799 | if (dozeParameters.shouldControlScreenOff()) { |
| 4800 | mShelf.fadeInTranslating(); |
| 4801 | } |
| 4802 | updateClipping(); |
| 4803 | } |
| 4804 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4805 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4806 | public void notifyDarkAnimationStart(boolean dark) { |
| 4807 | // We only swap the scaling factor if we're fully dark or fully awake to avoid |
| 4808 | // interpolation issues when playing with the power button. |
| 4809 | if (mInterpolatedDarkAmount == 0 || mInterpolatedDarkAmount == 1) { |
| 4810 | mBackgroundXFactor = dark ? 1.8f : 1.5f; |
| 4811 | mDarkXInterpolator = dark |
| 4812 | ? Interpolators.FAST_OUT_SLOW_IN_REVERSE |
| 4813 | : Interpolators.FAST_OUT_SLOW_IN; |
| 4814 | } |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4815 | } |
| 4816 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4817 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4818 | private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4819 | if (screenLocation == null || screenLocation.y < mTopPadding) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4820 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4821 | } |
| 4822 | if (screenLocation.y > getBottomMostNotificationBottom()) { |
| 4823 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW; |
| 4824 | } |
| 4825 | View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y); |
| 4826 | if (child != null) { |
| 4827 | return getNotGoneIndex(child); |
| 4828 | } else { |
| 4829 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4830 | } |
| 4831 | } |
| 4832 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4833 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4834 | private int getNotGoneIndex(View child) { |
| 4835 | int count = getChildCount(); |
| 4836 | int notGoneIndex = 0; |
| 4837 | for (int i = 0; i < count; i++) { |
| 4838 | View v = getChildAt(i); |
| 4839 | if (child == v) { |
| 4840 | return notGoneIndex; |
| 4841 | } |
| 4842 | if (v.getVisibility() != View.GONE) { |
| 4843 | notGoneIndex++; |
| 4844 | } |
| 4845 | } |
| 4846 | return -1; |
| 4847 | } |
| 4848 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4849 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4850 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4851 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4852 | if (mFooterView != null) { |
| 4853 | index = indexOfChild(mFooterView); |
| 4854 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4855 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4856 | mFooterView = footerView; |
| 4857 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4858 | } |
| 4859 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4860 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4861 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4862 | int index = -1; |
| 4863 | if (mEmptyShadeView != null) { |
| 4864 | index = indexOfChild(mEmptyShadeView); |
| 4865 | removeView(mEmptyShadeView); |
| 4866 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4867 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4868 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4869 | } |
| 4870 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4871 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4872 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4873 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4874 | |
| 4875 | int oldTextRes = mEmptyShadeView.getTextResource(); |
| 4876 | int newTextRes = mStatusBar.areNotificationsHidden() |
| 4877 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4878 | if (oldTextRes != newTextRes) { |
| 4879 | mEmptyShadeView.setText(newTextRes); |
| 4880 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4881 | } |
| 4882 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4883 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4884 | public void updateFooterView(boolean visible, boolean showDismissView) { |
| 4885 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4886 | return; |
| 4887 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4888 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 4889 | mFooterView.setVisible(visible, animate); |
| 4890 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4891 | } |
| 4892 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4893 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4894 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 4895 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4896 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4897 | handleDismissAllClipping(); |
| 4898 | } |
| 4899 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4900 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4901 | private void handleDismissAllClipping() { |
| 4902 | final int count = getChildCount(); |
| 4903 | boolean previousChildWillBeDismissed = false; |
| 4904 | for (int i = 0; i < count; i++) { |
| 4905 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4906 | if (child.getVisibility() == GONE) { |
| 4907 | continue; |
| 4908 | } |
| 4909 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 4910 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 4911 | } else { |
| 4912 | child.setMinClipTopAmount(0); |
| 4913 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 4914 | previousChildWillBeDismissed = StackScrollAlgorithm.canChildBeDismissed(child); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4915 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 4916 | } |
| 4917 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4918 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4919 | public boolean isFooterViewNotGone() { |
| 4920 | return mFooterView != null |
| 4921 | && mFooterView.getVisibility() != View.GONE |
| 4922 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4923 | } |
| 4924 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4925 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 4926 | public boolean isFooterViewContentVisible() { |
| 4927 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4928 | } |
| 4929 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4930 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4931 | public int getFooterViewHeight() { |
| 4932 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4933 | } |
| 4934 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4935 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 4936 | public int getEmptyShadeViewHeight() { |
| 4937 | return mEmptyShadeView.getHeight(); |
| 4938 | } |
| 4939 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4940 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4941 | public float getBottomMostNotificationBottom() { |
| 4942 | final int count = getChildCount(); |
| 4943 | float max = 0; |
| 4944 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 4945 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 4946 | if (child.getVisibility() == GONE) { |
| 4947 | continue; |
| 4948 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4949 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 4950 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4951 | if (bottom > max) { |
| 4952 | max = bottom; |
| 4953 | } |
| 4954 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4955 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4956 | } |
| 4957 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4958 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4959 | public void setStatusBar(StatusBar statusBar) { |
| 4960 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 4961 | } |
| 4962 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4963 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4964 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 4965 | this.mGroupManager = groupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 4966 | mGroupManager.addOnGroupChangeListener(mOnGroupChangeListener); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4967 | } |
| 4968 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4969 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4970 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4971 | if (mIsExpanded && mAnimationsEnabled) { |
| 4972 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4973 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4974 | requestChildrenUpdate(); |
| 4975 | } |
| 4976 | } |
| 4977 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4978 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4979 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4980 | int childCount = getChildCount(); |
| 4981 | for (int i = childCount - 1; i >= 0; i--) { |
| 4982 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4983 | if (child.getVisibility() != View.GONE) { |
| 4984 | float childTop = child.getY(); |
| 4985 | if (childTop > touchY) { |
| 4986 | // we are above a notification entirely let's abort |
| 4987 | return false; |
| 4988 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4989 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 4990 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4991 | if (child == mFooterView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4992 | if (!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
| 4993 | touchY - childTop)) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4994 | // We clicked on the dismiss button |
| 4995 | return false; |
| 4996 | } |
| 4997 | } else if (child == mEmptyShadeView) { |
| 4998 | // We arrived at the empty shade view, for which we accept all clicks |
| 4999 | return true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5000 | } else if (!belowChild) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5001 | // We are on a child |
| 5002 | return false; |
| 5003 | } |
| 5004 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5005 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 5006 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5007 | } |
| 5008 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5009 | /** @hide */ |
| 5010 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5011 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5012 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 5013 | super.onInitializeAccessibilityEventInternal(event); |
| 5014 | event.setScrollable(mScrollable); |
| 5015 | event.setScrollX(mScrollX); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5016 | event.setMaxScrollX(mScrollX); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5017 | if (ANCHOR_SCROLLING) { |
| 5018 | // TODO |
| 5019 | } else { |
| 5020 | event.setScrollY(mOwnScrollY); |
| 5021 | event.setMaxScrollY(getScrollRange()); |
| 5022 | } |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5026 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5027 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 5028 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5029 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5030 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5031 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5032 | info.addAction( |
| 5033 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 5034 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 5035 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5036 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5037 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 5038 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 5039 | } |
| 5040 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 5041 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 5042 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5043 | } |
| 5044 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5045 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5046 | public void generateChildOrderChangedEvent() { |
| 5047 | if (mIsExpanded && mAnimationsEnabled) { |
| 5048 | mGenerateChildOrderChangedEvent = true; |
| 5049 | mNeedsAnimation = true; |
| 5050 | requestChildrenUpdate(); |
| 5051 | } |
| 5052 | } |
| 5053 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5054 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5055 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5056 | public int getContainerChildCount() { |
| 5057 | return getChildCount(); |
| 5058 | } |
| 5059 | |
| 5060 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5061 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5062 | public View getContainerChildAt(int i) { |
| 5063 | return getChildAt(i); |
| 5064 | } |
| 5065 | |
| 5066 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5067 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5068 | public void removeContainerView(View v) { |
| 5069 | removeView(v); |
| 5070 | } |
| 5071 | |
| 5072 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5073 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5074 | public void addContainerView(View v) { |
| 5075 | addView(v); |
| 5076 | } |
| 5077 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5078 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 5079 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5080 | mAnimationFinishedRunnables.add(runnable); |
| 5081 | } |
| 5082 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5083 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5084 | public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5085 | mHeadsUpManager = headsUpManager; |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 5086 | mHeadsUpManager.addListener(mRoundnessManager); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 5087 | mHeadsUpManager.setAnimationStateHandler(this::setHeadsUpGoingAwayAnimationsAllowed); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 5090 | public void generateHeadsUpAnimation(NotificationEntry entry, boolean isHeadsUp) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 5091 | ExpandableNotificationRow row = entry.getHeadsUpAnimationView(); |
| 5092 | generateHeadsUpAnimation(row, isHeadsUp); |
| 5093 | } |
| 5094 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5095 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5096 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5097 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5098 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 5099 | mNeedsAnimation = true; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5100 | if (!mIsExpanded && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5101 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5102 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5103 | requestChildrenUpdate(); |
| 5104 | } |
| 5105 | } |
| 5106 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5107 | /** |
| 5108 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 5109 | * position. |
| 5110 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5111 | * @param height the height of the screen |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5112 | * @param bottomBarHeight the height of the bar on the bottom |
| 5113 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5114 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5115 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 5116 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 5117 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5118 | requestChildrenUpdate(); |
| 5119 | } |
| 5120 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5121 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5122 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 5123 | mTrackingHeadsUp = row != null; |
| 5124 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5125 | } |
| 5126 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5127 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5128 | public void setScrimController(ScrimController scrimController) { |
| 5129 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 5130 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5131 | } |
| 5132 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5133 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5134 | public void forceNoOverlappingRendering(boolean force) { |
| 5135 | mForceNoOverlappingRendering = force; |
| 5136 | } |
| 5137 | |
| 5138 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5139 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5140 | public boolean hasOverlappingRendering() { |
| 5141 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 5142 | } |
| 5143 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5144 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5145 | public void setAnimationRunning(boolean animationRunning) { |
| 5146 | if (animationRunning != mAnimationRunning) { |
| 5147 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5148 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5149 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5150 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5151 | } |
| 5152 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5153 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5154 | } |
| 5155 | } |
| 5156 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5157 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 5158 | public boolean isExpanded() { |
| 5159 | return mIsExpanded; |
| 5160 | } |
| 5161 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5162 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5163 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5164 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 5165 | return; |
| 5166 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5167 | mPulsing = pulsing; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 5168 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5169 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 5170 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 5171 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 5172 | requestChildrenUpdate(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5173 | notifyHeightChangeListener(null, animated); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5174 | } |
| 5175 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5176 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5177 | public void setQsExpanded(boolean qsExpanded) { |
| 5178 | mQsExpanded = qsExpanded; |
| 5179 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 5180 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5181 | } |
| 5182 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5183 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5184 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 5185 | mQsExpansionFraction = qsExpansionFraction; |
| 5186 | } |
| 5187 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5188 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5189 | private void setOwnScrollY(int ownScrollY) { |
| 5190 | assert !ANCHOR_SCROLLING; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5191 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 5192 | // We still want to call the normal scrolled changed for accessibility reasons |
| 5193 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5194 | mOwnScrollY = ownScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5195 | updateOnScrollChange(); |
| 5196 | } |
| 5197 | } |
| 5198 | |
| 5199 | private void updateOnScrollChange() { |
| 5200 | updateForwardAndBackwardScrollability(); |
| 5201 | requestChildrenUpdate(); |
| 5202 | } |
| 5203 | |
| 5204 | private void updateScrollAnchor() { |
| 5205 | int anchorIndex = indexOfChild(mScrollAnchorView); |
| 5206 | // If the anchor view has been scrolled off the top, move to the next view. |
| 5207 | while (mScrollAnchorViewY < 0) { |
| 5208 | View nextAnchor = null; |
| 5209 | for (int i = anchorIndex + 1; i < getChildCount(); i++) { |
| 5210 | View child = getChildAt(i); |
| 5211 | if (child.getVisibility() != View.GONE |
| 5212 | && child instanceof ExpandableNotificationRow) { |
| 5213 | anchorIndex = i; |
| 5214 | nextAnchor = child; |
| 5215 | break; |
| 5216 | } |
| 5217 | } |
| 5218 | if (nextAnchor == null) { |
| 5219 | break; |
| 5220 | } |
| 5221 | mScrollAnchorViewY += |
| 5222 | (int) (nextAnchor.getTranslationY() - mScrollAnchorView.getTranslationY()); |
| 5223 | mScrollAnchorView = nextAnchor; |
| 5224 | } |
| 5225 | // If the view above the anchor view is fully visible, make it the anchor view. |
| 5226 | while (anchorIndex > 0 && mScrollAnchorViewY > 0) { |
| 5227 | View prevAnchor = null; |
| 5228 | for (int i = anchorIndex - 1; i >= 0; i--) { |
| 5229 | View child = getChildAt(i); |
| 5230 | if (child.getVisibility() != View.GONE |
| 5231 | && child instanceof ExpandableNotificationRow) { |
| 5232 | anchorIndex = i; |
| 5233 | prevAnchor = child; |
| 5234 | break; |
| 5235 | } |
| 5236 | } |
| 5237 | if (prevAnchor == null) { |
| 5238 | break; |
| 5239 | } |
| 5240 | float distanceToPreviousAnchor = |
| 5241 | mScrollAnchorView.getTranslationY() - prevAnchor.getTranslationY(); |
| 5242 | if (distanceToPreviousAnchor < mScrollAnchorViewY) { |
| 5243 | mScrollAnchorViewY -= (int) distanceToPreviousAnchor; |
| 5244 | mScrollAnchorView = prevAnchor; |
| 5245 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5246 | } |
| 5247 | } |
| 5248 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5249 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5250 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5251 | int index = -1; |
| 5252 | if (mShelf != null) { |
| 5253 | index = indexOfChild(mShelf); |
| 5254 | removeView(mShelf); |
| 5255 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 5256 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5257 | addView(mShelf, index); |
| 5258 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 5259 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5260 | shelf.bind(mAmbientState, this); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5261 | if (ANCHOR_SCROLLING) { |
| 5262 | mScrollAnchorView = mShelf; |
| 5263 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5264 | } |
| 5265 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5266 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5267 | public NotificationShelf getNotificationShelf() { |
| 5268 | return mShelf; |
| 5269 | } |
| 5270 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5271 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 5272 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 5273 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 5274 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 5275 | updateContentHeight(); |
| 5276 | notifyHeightChangeListener(mShelf); |
| 5277 | } |
| 5278 | } |
| 5279 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5280 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5281 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5282 | mShouldShowShelfOnly = shouldShowShelfOnly; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5283 | updateAlgorithmLayoutMinHeight(); |
| 5284 | } |
| 5285 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5286 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5287 | public int getMinExpansionHeight() { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 5288 | return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5289 | } |
| 5290 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5291 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5292 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 5293 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 5294 | updateClipping(); |
| 5295 | } |
| 5296 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5297 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5298 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 5299 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 5300 | updateClipping(); |
| 5301 | } |
| 5302 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5303 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5304 | @VisibleForTesting |
| 5305 | protected void setStatusBarState(int statusBarState) { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5306 | mStatusBarState = statusBarState; |
| 5307 | mAmbientState.setStatusBarState(statusBarState); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | private void onStatePostChange() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5311 | boolean onKeyguard = onKeyguard(); |
| 5312 | boolean publicMode = mLockscreenUserManager.isAnyProfilePublicMode(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5313 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5314 | if (mHeadsUpAppearanceController != null) { |
| 5315 | mHeadsUpAppearanceController.setPublicMode(publicMode); |
| 5316 | } |
| 5317 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 5318 | SysuiStatusBarStateController state = (SysuiStatusBarStateController) |
| 5319 | Dependency.get(StatusBarStateController.class); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5320 | setHideSensitive(publicMode, state.goingToFullShade() /* animate */); |
| 5321 | setDimmed(onKeyguard, state.fromShadeLocked() /* animate */); |
| 5322 | setExpandingEnabled(!onKeyguard); |
| 5323 | ActivatableNotificationView activatedChild = getActivatedChild(); |
| 5324 | setActivatedChild(null); |
| 5325 | if (activatedChild != null) { |
| 5326 | activatedChild.makeInactive(false /* animate */); |
| 5327 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5328 | updateFooter(); |
Dave Mankoff | 5744580 | 2018-10-10 14:47:34 -0400 | [diff] [blame] | 5329 | requestChildrenUpdate(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5330 | onUpdateRowStates(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5331 | |
| 5332 | mEntryManager.updateNotifications(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5333 | } |
| 5334 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5335 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 5336 | public void setExpandingVelocity(float expandingVelocity) { |
| 5337 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 5338 | } |
| 5339 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5340 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5341 | public float getOpeningHeight() { |
| 5342 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 5343 | return getMinExpansionHeight(); |
| 5344 | } else { |
| 5345 | return getAppearEndPosition(); |
| 5346 | } |
| 5347 | } |
| 5348 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5349 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5350 | public void setIsFullWidth(boolean isFullWidth) { |
| 5351 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 5352 | } |
| 5353 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5354 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 5355 | public void setUnlockHintRunning(boolean running) { |
| 5356 | mAmbientState.setUnlockHintRunning(running); |
| 5357 | } |
| 5358 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5359 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5360 | public void setQsCustomizerShowing(boolean isShowing) { |
| 5361 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 5362 | requestChildrenUpdate(); |
| 5363 | } |
| 5364 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5365 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5366 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 5367 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 5368 | } |
| 5369 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5370 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 5371 | public void setAntiBurnInOffsetX(int antiBurnInOffsetX) { |
| 5372 | mAntiBurnInOffsetX = antiBurnInOffsetX; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 5373 | updatePanelTranslation(); |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5376 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5377 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 5378 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5379 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 5380 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5381 | this.getClass().getSimpleName(), |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5382 | mPulsing ? "T" : "f", |
| 5383 | mAmbientState.isQsCustomizerShowing() ? "T" : "f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5384 | getVisibility() == View.VISIBLE ? "visible" |
| 5385 | : getVisibility() == View.GONE ? "gone" |
| 5386 | : "invisible", |
| 5387 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5388 | mAmbientState.getScrollY(), |
| 5389 | mMaxTopPadding, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5390 | mShouldShowShelfOnly ? "T" : "f", |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5391 | mQsExpansionFraction)); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5392 | int childCount = getChildCount(); |
| 5393 | pw.println(" Number of children: " + childCount); |
| 5394 | pw.println(); |
| 5395 | |
| 5396 | for (int i = 0; i < childCount; i++) { |
| 5397 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5398 | child.dump(fd, pw, args); |
| 5399 | if (!(child instanceof ExpandableNotificationRow)) { |
| 5400 | pw.println(" " + child.getClass().getSimpleName()); |
| 5401 | // 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] | 5402 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5403 | if (viewState == null) { |
| 5404 | pw.println(" no viewState!!!"); |
| 5405 | } else { |
| 5406 | pw.print(" "); |
| 5407 | viewState.dump(fd, pw, args); |
| 5408 | pw.println(); |
| 5409 | pw.println(); |
| 5410 | } |
| 5411 | } |
| 5412 | } |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5413 | int transientViewCount = getTransientViewCount(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5414 | pw.println(" Transient Views: " + transientViewCount); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5415 | for (int i = 0; i < transientViewCount; i++) { |
| 5416 | ExpandableView child = (ExpandableView) getTransientView(i); |
| 5417 | child.dump(fd, pw, args); |
| 5418 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5419 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5420 | int draggedCount = draggedViews.size(); |
| 5421 | pw.println(" Dragged Views: " + draggedCount); |
| 5422 | for (int i = 0; i < draggedCount; i++) { |
| 5423 | ExpandableView child = (ExpandableView) draggedViews.get(i); |
| 5424 | child.dump(fd, pw, args); |
| 5425 | } |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5426 | } |
| 5427 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5428 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 5429 | public boolean isFullyDark() { |
| 5430 | return mAmbientState.isFullyDark(); |
| 5431 | } |
| 5432 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 5433 | /** |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5434 | * Add a listener whenever the expanded height changes. The first value passed as an argument |
| 5435 | * is the expanded height and the second one is the appearFraction. |
| 5436 | * |
| 5437 | * @param listener the listener to notify. |
| 5438 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5439 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5440 | public void addOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 5441 | mExpandedHeightListeners.add(listener); |
| 5442 | } |
| 5443 | |
| 5444 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5445 | * Stop a listener from listening to the expandedHeight. |
| 5446 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5447 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5448 | public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 5449 | mExpandedHeightListeners.remove(listener); |
| 5450 | } |
| 5451 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5452 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 5453 | public void setHeadsUpAppearanceController( |
| 5454 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 5455 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 5456 | } |
| 5457 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5458 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 5459 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 5460 | mIconAreaController = controller; |
| 5461 | } |
| 5462 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5463 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5464 | public void manageNotifications(View v) { |
| 5465 | Intent intent = new Intent(Settings.ACTION_ALL_APPS_NOTIFICATION_SETTINGS); |
| 5466 | mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 5467 | } |
| 5468 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5469 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5470 | private void clearNotifications( |
| 5471 | @SelectedRows int selection, |
| 5472 | boolean closeShade) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5473 | // animate-swipe all dismissable notifications, then animate the shade closed |
| 5474 | int numChildren = getChildCount(); |
| 5475 | |
| 5476 | final ArrayList<View> viewsToHide = new ArrayList<>(numChildren); |
| 5477 | final ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>(numChildren); |
| 5478 | for (int i = 0; i < numChildren; i++) { |
| 5479 | final View child = getChildAt(i); |
| 5480 | if (child instanceof ExpandableNotificationRow) { |
| 5481 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 5482 | boolean parentVisible = false; |
| 5483 | boolean hasClipBounds = child.getClipBounds(mTmpRect); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5484 | if (includeChildInDismissAll(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5485 | viewsToRemove.add(row); |
| 5486 | if (child.getVisibility() == View.VISIBLE |
| 5487 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5488 | viewsToHide.add(child); |
| 5489 | parentVisible = true; |
| 5490 | } |
| 5491 | } else if (child.getVisibility() == View.VISIBLE |
| 5492 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5493 | parentVisible = true; |
| 5494 | } |
| 5495 | List<ExpandableNotificationRow> children = row.getNotificationChildren(); |
| 5496 | if (children != null) { |
| 5497 | for (ExpandableNotificationRow childRow : children) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5498 | if (includeChildInDismissAll(row, selection)) { |
| 5499 | viewsToRemove.add(childRow); |
| 5500 | if (parentVisible && row.areChildrenExpanded()) { |
| 5501 | hasClipBounds = childRow.getClipBounds(mTmpRect); |
| 5502 | if (childRow.getVisibility() == View.VISIBLE |
| 5503 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5504 | viewsToHide.add(childRow); |
| 5505 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5506 | } |
| 5507 | } |
| 5508 | } |
| 5509 | } |
| 5510 | } |
| 5511 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5512 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5513 | if (viewsToRemove.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5514 | if (closeShade) { |
| 5515 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5516 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5517 | return; |
| 5518 | } |
| 5519 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5520 | performDismissAllAnimations(viewsToHide, closeShade, () -> { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5521 | for (ExpandableNotificationRow rowToRemove : viewsToRemove) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5522 | if (StackScrollAlgorithm.canChildBeDismissed(rowToRemove)) { |
| 5523 | if (selection == ROWS_ALL) { |
| 5524 | // TODO: This is a listener method; we shouldn't be calling it. Can we just |
| 5525 | // call performRemoveNotification as below? |
| 5526 | mEntryManager.removeNotification( |
| 5527 | rowToRemove.getEntry().key, |
| 5528 | null /* ranking */, |
| 5529 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5530 | } else { |
| 5531 | mEntryManager.performRemoveNotification( |
| 5532 | rowToRemove.getEntry().notification, |
| 5533 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5534 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5535 | } else { |
| 5536 | rowToRemove.resetTranslation(); |
| 5537 | } |
| 5538 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5539 | if (selection == ROWS_ALL) { |
| 5540 | try { |
| 5541 | mBarService.onClearAllNotifications(mLockscreenUserManager.getCurrentUserId()); |
| 5542 | } catch (Exception ex) { |
| 5543 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5544 | } |
| 5545 | }); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5546 | } |
| 5547 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5548 | private boolean includeChildInDismissAll( |
| 5549 | ExpandableNotificationRow row, |
| 5550 | @SelectedRows int selection) { |
| 5551 | return StackScrollAlgorithm.canChildBeDismissed(row) && matchesSelection(row, selection); |
| 5552 | } |
| 5553 | |
| 5554 | /** |
| 5555 | * Given a list of rows, animates them away in a staggered fashion as if they were dismissed. |
| 5556 | * Doesn't actually dismiss them, though -- that must be done in the onAnimationComplete |
| 5557 | * handler. |
| 5558 | * |
| 5559 | * @param hideAnimatedList List of rows to animated away. Should only be views that are |
| 5560 | * currently visible, or else the stagger will look funky. |
| 5561 | * @param closeShade Whether to close the shade after the stagger animation completes. |
| 5562 | * @param onAnimationComplete Called after the entire animation completes (including the shade |
| 5563 | * closing if appropriate). The rows must be dismissed for real here. |
| 5564 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5565 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5566 | private void performDismissAllAnimations( |
| 5567 | final ArrayList<View> hideAnimatedList, |
| 5568 | final boolean closeShade, |
| 5569 | final Runnable onAnimationComplete) { |
| 5570 | |
| 5571 | final Runnable onSlideAwayAnimationComplete = () -> { |
| 5572 | if (closeShade) { |
| 5573 | mShadeController.addPostCollapseAction(() -> { |
| 5574 | setDismissAllInProgress(false); |
| 5575 | onAnimationComplete.run(); |
| 5576 | }); |
| 5577 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5578 | } else { |
| 5579 | setDismissAllInProgress(false); |
| 5580 | onAnimationComplete.run(); |
| 5581 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5582 | }; |
| 5583 | |
| 5584 | if (hideAnimatedList.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5585 | onSlideAwayAnimationComplete.run(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5586 | return; |
| 5587 | } |
| 5588 | |
| 5589 | // let's disable our normal animations |
| 5590 | setDismissAllInProgress(true); |
| 5591 | |
| 5592 | // Decrease the delay for every row we animate to give the sense of |
| 5593 | // accelerating the swipes |
| 5594 | int rowDelayDecrement = 10; |
| 5595 | int currentDelay = 140; |
| 5596 | int totalDelay = 180; |
| 5597 | int numItems = hideAnimatedList.size(); |
| 5598 | for (int i = numItems - 1; i >= 0; i--) { |
| 5599 | View view = hideAnimatedList.get(i); |
| 5600 | Runnable endRunnable = null; |
| 5601 | if (i == 0) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5602 | endRunnable = onSlideAwayAnimationComplete; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5603 | } |
Lucas Dupin | fb8bdbb | 2018-12-02 15:09:37 -0800 | [diff] [blame] | 5604 | dismissViewAnimated(view, endRunnable, totalDelay, ANIMATION_DURATION_SWIPE); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5605 | currentDelay = Math.max(50, currentDelay - rowDelayDecrement); |
| 5606 | totalDelay += currentDelay; |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5611 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5612 | protected void inflateFooterView() { |
| 5613 | FooterView footerView = (FooterView) LayoutInflater.from(mContext).inflate( |
| 5614 | R.layout.status_bar_notification_footer, this, false); |
| 5615 | footerView.setDismissButtonClickListener(v -> { |
| 5616 | mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5617 | clearNotifications(ROWS_ALL, true /* closeShade */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5618 | }); |
| 5619 | footerView.setManageButtonClickListener(this::manageNotifications); |
| 5620 | setFooterView(footerView); |
| 5621 | } |
| 5622 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5623 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5624 | private void inflateEmptyShadeView() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5625 | EmptyShadeView view = (EmptyShadeView) LayoutInflater.from(mContext).inflate( |
| 5626 | R.layout.status_bar_no_notifications, this, false); |
| 5627 | view.setText(R.string.empty_shade_text); |
| 5628 | setEmptyShadeView(view); |
| 5629 | } |
| 5630 | |
| 5631 | /** |
| 5632 | * Updates expanded, dimmed and locked states of notification rows. |
| 5633 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5634 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5635 | public void onUpdateRowStates() { |
| 5636 | changeViewPosition(mFooterView, -1); |
| 5637 | |
| 5638 | // The following views will be moved to the end of mStackScroller. This counter represents |
| 5639 | // the offset from the last child. Initialized to 1 for the very last position. It is post- |
| 5640 | // incremented in the following "changeViewPosition" calls so that its value is correct for |
| 5641 | // subsequent calls. |
| 5642 | int offsetFromEnd = 1; |
| 5643 | changeViewPosition(mEmptyShadeView, |
| 5644 | getChildCount() - offsetFromEnd++); |
| 5645 | |
| 5646 | // No post-increment for this call because it is the last one. Make sure to add one if |
| 5647 | // another "changeViewPosition" call is ever added. |
| 5648 | changeViewPosition(mShelf, |
| 5649 | getChildCount() - offsetFromEnd); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5650 | } |
| 5651 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5652 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5653 | public void setNotificationPanel(NotificationPanelView notificationPanelView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5654 | mNotificationPanel = notificationPanelView; |
| 5655 | } |
| 5656 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5657 | public void updateIconAreaViews() { |
| 5658 | mIconAreaController.updateNotificationIcons(); |
| 5659 | } |
| 5660 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5661 | /** |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5662 | * Set how far the wake up is when waking up from pulsing. This is a height and will adjust the |
| 5663 | * notification positions accordingly. |
| 5664 | * @param height the new wake up height |
| 5665 | * @return the overflow how much the height is further than he lowest notification |
| 5666 | */ |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 5667 | public float setPulseHeight(float height) { |
| 5668 | mAmbientState.setPulseHeight(height); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5669 | requestChildrenUpdate(); |
| 5670 | return Math.max(0, height - mAmbientState.getInnerHeight(true /* ignorePulseHeight */)); |
| 5671 | } |
| 5672 | |
| 5673 | /** |
| 5674 | * Set the amount how much we're dozing. This is different from how dark the shade is, when |
| 5675 | * the notification is pulsing. |
| 5676 | */ |
| 5677 | public void setDozeAmount(float dozeAmount) { |
| 5678 | mAmbientState.setDozeAmount(dozeAmount); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5679 | updateContinuousBackgroundDrawing(); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5680 | requestChildrenUpdate(); |
| 5681 | } |
| 5682 | |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5683 | public void wakeUpFromPulse() { |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 5684 | setPulseHeight(getPulseHeight()); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5685 | // Let's place the hidden views at the end of the pulsing notification to make sure we have |
| 5686 | // a smooth animation |
| 5687 | boolean firstVisibleView = true; |
| 5688 | float wakeUplocation = -1f; |
| 5689 | int childCount = getChildCount(); |
| 5690 | for (int i = 0; i < childCount; i++) { |
| 5691 | ExpandableView view = (ExpandableView) getChildAt(i); |
| 5692 | if (view.getVisibility() == View.GONE) { |
| 5693 | continue; |
| 5694 | } |
| 5695 | boolean isShelf = view == mShelf; |
| 5696 | if (!(view instanceof ExpandableNotificationRow) && !isShelf) { |
| 5697 | continue; |
| 5698 | } |
| 5699 | if (view.getVisibility() == View.VISIBLE && !isShelf) { |
| 5700 | if (firstVisibleView) { |
| 5701 | firstVisibleView = false; |
| 5702 | wakeUplocation = view.getTranslationY() |
| 5703 | + view.getActualHeight() - mShelf.getIntrinsicHeight(); |
| 5704 | } |
| 5705 | } else if (!firstVisibleView) { |
| 5706 | view.setTranslationY(wakeUplocation); |
| 5707 | } |
| 5708 | } |
| 5709 | } |
| 5710 | |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5711 | @Override |
| 5712 | public void onDynamicPrivacyChanged() { |
| 5713 | if (mIsExpanded) { |
| 5714 | // The bottom might change because we're using the final actual height of the view |
| 5715 | mAnimateBottomOnLayout = true; |
| 5716 | } |
| 5717 | } |
| 5718 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5719 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5720 | * A listener that is notified when the empty space below the notifications is clicked on |
| 5721 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5722 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5723 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 5724 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5728 | * A listener that gets notified when the overscroll at the top has changed. |
| 5729 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5730 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5731 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 5732 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5733 | /** |
| 5734 | * Notifies a listener that the overscroll has changed. |
| 5735 | * |
| 5736 | * @param amount the amount of overscroll, in pixels |
| 5737 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 5738 | * unrubberbanded motion to directly expand overscroll view (e.g |
| 5739 | * expand |
| 5740 | * QS) |
| 5741 | */ |
| 5742 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 5743 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5744 | /** |
| 5745 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 5746 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 5747 | * |
| 5748 | * @param velocity The velocity that the Scroller had when over flinging |
| 5749 | * @param open Should the fling open or close the overscroll view. |
| 5750 | */ |
| 5751 | void flingTopOverscroll(float velocity, boolean open); |
| 5752 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5753 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5754 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5755 | public boolean hasActiveNotifications() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5756 | return !mEntryManager.getNotificationData().getActiveNotifications().isEmpty(); |
| 5757 | } |
| 5758 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 5759 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5760 | public void updateSpeedBumpIndex() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5761 | int speedBumpIndex = 0; |
| 5762 | int currentIndex = 0; |
| 5763 | final int N = getChildCount(); |
| 5764 | for (int i = 0; i < N; i++) { |
| 5765 | View view = getChildAt(i); |
| 5766 | if (view.getVisibility() == View.GONE || !(view instanceof ExpandableNotificationRow)) { |
| 5767 | continue; |
| 5768 | } |
| 5769 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 5770 | currentIndex++; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5771 | boolean beforeSpeedBump; |
| 5772 | if (mLowPriorityBeforeSpeedBump) { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 5773 | beforeSpeedBump = !row.getEntry().ambient; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5774 | } else { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 5775 | beforeSpeedBump = row.getEntry().isHighPriority(); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5776 | } |
| 5777 | if (beforeSpeedBump) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5778 | speedBumpIndex = currentIndex; |
| 5779 | } |
| 5780 | } |
| 5781 | boolean noAmbient = speedBumpIndex == N; |
| 5782 | updateSpeedBumpIndex(speedBumpIndex, noAmbient); |
| 5783 | } |
| 5784 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5785 | /** Updates the indices of the boundaries between sections. */ |
| 5786 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 5787 | public void updateSectionBoundaries() { |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 5788 | mSectionsManager.updateSectionBoundaries(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5789 | } |
| 5790 | |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5791 | private void updateContinuousBackgroundDrawing() { |
| 5792 | boolean continuousBackground = !mAmbientState.isFullyAwake() |
| 5793 | && !mAmbientState.getDraggedViews().isEmpty(); |
| 5794 | if (continuousBackground != mContinuousBackgroundUpdate) { |
| 5795 | mContinuousBackgroundUpdate = continuousBackground; |
| 5796 | if (continuousBackground) { |
| 5797 | getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater); |
| 5798 | } else { |
| 5799 | getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater); |
| 5800 | } |
| 5801 | } |
| 5802 | } |
| 5803 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5804 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5805 | private void updateContinuousShadowDrawing() { |
| 5806 | boolean continuousShadowUpdate = mAnimationRunning |
| 5807 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 5808 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 5809 | if (continuousShadowUpdate) { |
| 5810 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 5811 | } else { |
| 5812 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 5813 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 5814 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5815 | } |
| 5816 | } |
| 5817 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5818 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5819 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 5820 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 5821 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5824 | private static boolean matchesSelection( |
| 5825 | ExpandableNotificationRow row, |
| 5826 | @SelectedRows int selection) { |
| 5827 | switch (selection) { |
| 5828 | case ROWS_ALL: |
| 5829 | return true; |
| 5830 | case ROWS_HIGH_PRIORITY: |
| 5831 | return row.getEntry().isHighPriority(); |
| 5832 | case ROWS_GENTLE: |
| 5833 | return !row.getEntry().isHighPriority(); |
| 5834 | default: |
| 5835 | throw new IllegalArgumentException("Unknown selection: " + selection); |
| 5836 | } |
| 5837 | } |
| 5838 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5839 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 5840 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5841 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5842 | static AnimationFilter[] FILTERS = new AnimationFilter[]{ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5843 | |
| 5844 | // ANIMATION_TYPE_ADD |
| 5845 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5846 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5847 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5848 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5849 | .animateZ() |
| 5850 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5851 | |
| 5852 | // ANIMATION_TYPE_REMOVE |
| 5853 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5854 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5855 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5856 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5857 | .animateZ() |
| 5858 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5859 | |
| 5860 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5861 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5862 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5863 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5864 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5865 | .animateZ() |
| 5866 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5867 | |
| 5868 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5869 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5870 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5871 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5872 | .animateY() |
| 5873 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5874 | .animateZ(), |
| 5875 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5876 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5877 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5878 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5879 | |
| 5880 | // ANIMATION_TYPE_DIMMED |
| 5881 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5882 | .animateDimmed(), |
| 5883 | |
| 5884 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5885 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5886 | .animateAlpha() // maybe the children change positions |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5887 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5888 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5889 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5890 | .animateZ(), |
| 5891 | |
| 5892 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5893 | null, // Unused |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5894 | |
| 5895 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5896 | new AnimationFilter() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5897 | .animateHeight() |
| 5898 | .animateTopInset() |
| 5899 | .animateY() |
| 5900 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5901 | .animateZ() |
| 5902 | .hasDelays(), |
| 5903 | |
| 5904 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5905 | new AnimationFilter() |
| 5906 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5907 | |
| 5908 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5909 | new AnimationFilter() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5910 | .animateHeight() |
| 5911 | .animateTopInset() |
| 5912 | .animateY() |
| 5913 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5914 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5915 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 5916 | new AnimationFilter() |
| 5917 | .animateAlpha() |
| 5918 | .animateHeight() |
| 5919 | .animateTopInset() |
| 5920 | .animateY() |
| 5921 | .animateZ(), |
| 5922 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5923 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5924 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5925 | .animateHeight() |
| 5926 | .animateTopInset() |
| 5927 | .animateY() |
| 5928 | .animateZ(), |
| 5929 | |
| 5930 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5931 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5932 | .animateHeight() |
| 5933 | .animateTopInset() |
| 5934 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 5935 | .animateZ() |
| 5936 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5937 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5938 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5939 | new AnimationFilter() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5940 | .animateHeight() |
| 5941 | .animateTopInset() |
| 5942 | .animateY() |
| 5943 | .animateZ() |
| 5944 | .hasDelays(), |
| 5945 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5946 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5947 | new AnimationFilter() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5948 | .animateHeight() |
| 5949 | .animateTopInset() |
| 5950 | .animateY() |
| 5951 | .animateZ(), |
| 5952 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5953 | // ANIMATION_TYPE_EVERYTHING |
| 5954 | new AnimationFilter() |
| 5955 | .animateAlpha() |
| 5956 | .animateDark() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5957 | .animateDimmed() |
| 5958 | .animateHideSensitive() |
| 5959 | .animateHeight() |
| 5960 | .animateTopInset() |
| 5961 | .animateY() |
| 5962 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5963 | }; |
| 5964 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5965 | static int[] LENGTHS = new int[]{ |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5966 | |
| 5967 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5968 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5969 | |
| 5970 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5971 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5972 | |
| 5973 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5974 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5975 | |
| 5976 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5977 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5978 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5979 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5980 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 5981 | |
| 5982 | // ANIMATION_TYPE_DIMMED |
| 5983 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5984 | |
| 5985 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5986 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5987 | |
| 5988 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5989 | StackStateAnimator.ANIMATION_DURATION_WAKEUP, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5990 | |
| 5991 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5992 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5993 | |
| 5994 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5995 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5996 | |
| 5997 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5998 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5999 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6000 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 6001 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6002 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6003 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 6004 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 6005 | |
| 6006 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 6007 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6008 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 6009 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 6010 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6011 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6012 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 6013 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6014 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6015 | // ANIMATION_TYPE_EVERYTHING |
| 6016 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6017 | }; |
| 6018 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6019 | static final int ANIMATION_TYPE_ADD = 0; |
| 6020 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 6021 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 6022 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
Selim Cinek | ff2ffec | 2018-11-19 18:52:01 -0800 | [diff] [blame] | 6023 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 4; |
| 6024 | static final int ANIMATION_TYPE_DIMMED = 5; |
| 6025 | static final int ANIMATION_TYPE_CHANGE_POSITION = 6; |
| 6026 | static final int ANIMATION_TYPE_DARK = 7; |
| 6027 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 8; |
| 6028 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 9; |
| 6029 | static final int ANIMATION_TYPE_VIEW_RESIZE = 10; |
| 6030 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 11; |
| 6031 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 12; |
| 6032 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 13; |
| 6033 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 14; |
| 6034 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 15; |
| 6035 | static final int ANIMATION_TYPE_EVERYTHING = 16; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 6036 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 6037 | static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1; |
| 6038 | static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2; |
| 6039 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6040 | final long eventStartTime; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6041 | final ExpandableView mChangingView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6042 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6043 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6044 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6045 | View viewAfterChangingView; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 6046 | int darkAnimationOriginIndex; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6047 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6048 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6049 | AnimationEvent(ExpandableView view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6050 | this(view, type, LENGTHS[type]); |
| 6051 | } |
| 6052 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6053 | AnimationEvent(ExpandableView view, int type, AnimationFilter filter) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6054 | this(view, type, LENGTHS[type], filter); |
| 6055 | } |
| 6056 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6057 | AnimationEvent(ExpandableView view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6058 | this(view, type, length, FILTERS[type]); |
| 6059 | } |
| 6060 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6061 | AnimationEvent(ExpandableView view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6062 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6063 | mChangingView = view; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6064 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6065 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6066 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | /** |
| 6070 | * Combines the length of several animation events into a single value. |
| 6071 | * |
| 6072 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6073 | * @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] | 6074 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6075 | */ |
| 6076 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 6077 | long length = 0; |
| 6078 | int size = events.size(); |
| 6079 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6080 | AnimationEvent event = events.get(i); |
| 6081 | length = Math.max(length, event.length); |
| 6082 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 6083 | return event.length; |
| 6084 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6085 | } |
| 6086 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6087 | } |
| 6088 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6089 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6090 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 6091 | private final StateListener mStateListener = new StateListener() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6092 | @Override |
| 6093 | public void onStatePreChange(int oldState, int newState) { |
| 6094 | if (oldState == StatusBarState.SHADE_LOCKED && newState == StatusBarState.KEYGUARD) { |
| 6095 | requestAnimateEverything(); |
| 6096 | } |
| 6097 | } |
| 6098 | |
| 6099 | @Override |
| 6100 | public void onStateChanged(int newState) { |
| 6101 | setStatusBarState(newState); |
| 6102 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6103 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6104 | @Override |
| 6105 | public void onStatePostChange() { |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6106 | NotificationStackScrollLayout.this.onStatePostChange(); |
| 6107 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6108 | }; |
| 6109 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6110 | @VisibleForTesting |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6111 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6112 | protected final OnMenuEventListener mMenuEventListener = new OnMenuEventListener() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6113 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6114 | public void onMenuClicked(View view, int x, int y, MenuItem item) { |
| 6115 | if (mLongPressListener == null) { |
| 6116 | return; |
| 6117 | } |
| 6118 | if (view instanceof ExpandableNotificationRow) { |
| 6119 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6120 | mMetricsLogger.write(row.getStatusBarNotification().getLogMaker() |
| 6121 | .setCategory(MetricsEvent.ACTION_TOUCH_GEAR) |
| 6122 | .setType(MetricsEvent.TYPE_ACTION) |
| 6123 | ); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6124 | } |
| 6125 | mLongPressListener.onLongPress(view, x, y, item); |
| 6126 | } |
| 6127 | |
| 6128 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6129 | public void onMenuReset(View row) { |
| 6130 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 6131 | if (translatingParentView != null && row == translatingParentView) { |
| 6132 | mSwipeHelper.clearExposedMenuView(); |
| 6133 | mSwipeHelper.clearTranslatingParentView(); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6134 | if (row instanceof ExpandableNotificationRow) { |
| 6135 | mHeadsUpManager.setMenuShown( |
| 6136 | ((ExpandableNotificationRow) row).getEntry(), false); |
| 6137 | |
| 6138 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6143 | public void onMenuShown(View row) { |
| 6144 | if (row instanceof ExpandableNotificationRow) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6145 | ExpandableNotificationRow notificationRow = (ExpandableNotificationRow) row; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6146 | mMetricsLogger.write(notificationRow.getStatusBarNotification().getLogMaker() |
| 6147 | .setCategory(MetricsEvent.ACTION_REVEAL_GEAR) |
| 6148 | .setType(MetricsEvent.TYPE_ACTION)); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6149 | mHeadsUpManager.setMenuShown(notificationRow.getEntry(), true); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6150 | mSwipeHelper.onMenuShown(row); |
| 6151 | |
| 6152 | // Check to see if we want to go directly to the notfication guts |
| 6153 | NotificationMenuRowPlugin provider = notificationRow.getProvider(); |
| 6154 | if (provider.shouldShowGutsOnSnapOpen()) { |
| 6155 | MenuItem item = provider.menuItemToExposeOnSnap(); |
| 6156 | if (item != null) { |
| 6157 | Point origin = provider.getRevealAnimationOrigin(); |
| 6158 | mGutsManager.openGuts(row, origin.x, origin.y, item); |
| 6159 | } else { |
| 6160 | Log.e(TAG, "Provider has shouldShowGutsOnSnapOpen, but provided no " |
| 6161 | + "menu item in menuItemtoExposeOnSnap. Skipping."); |
| 6162 | } |
| 6163 | |
| 6164 | // Close the menu row since we went directly to the guts |
| 6165 | resetExposedMenuView(false, true); |
| 6166 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6167 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6168 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6169 | }; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6170 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6171 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6172 | private final NotificationSwipeHelper.NotificationCallback mNotificationCallback = |
| 6173 | new NotificationSwipeHelper.NotificationCallback() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6174 | @Override |
| 6175 | public void onDismiss() { |
| 6176 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6177 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6178 | false /* resetMenu */); |
| 6179 | } |
| 6180 | |
| 6181 | @Override |
| 6182 | public void onSnooze(StatusBarNotification sbn, |
| 6183 | NotificationSwipeActionHelper.SnoozeOption snoozeOption) { |
| 6184 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
| 6185 | } |
| 6186 | |
| 6187 | @Override |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6188 | public boolean shouldDismissQuickly() { |
| 6189 | return NotificationStackScrollLayout.this.isExpanded() && mAmbientState.isFullyAwake(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6193 | public void onDragCancelled(View v) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6194 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6195 | mFalsingManager.onNotificatonStopDismissing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | /** |
| 6199 | * Handles cleanup after the given {@code view} has been fully swiped out (including |
| 6200 | * re-invoking dismiss logic in case the notification has not made its way out yet). |
| 6201 | */ |
| 6202 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6203 | public void onChildDismissed(View view) { |
| 6204 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6205 | if (!row.isDismissed()) { |
| 6206 | handleChildViewDismissed(view); |
| 6207 | } |
| 6208 | ViewGroup transientContainer = row.getTransientContainer(); |
| 6209 | if (transientContainer != null) { |
| 6210 | transientContainer.removeTransientView(view); |
| 6211 | } |
| 6212 | } |
| 6213 | |
| 6214 | /** |
| 6215 | * Starts up notification dismiss and tells the notification, if any, to remove itself from |
| 6216 | * layout. |
| 6217 | * |
| 6218 | * @param view view (e.g. notification) to dismiss from the layout |
| 6219 | */ |
| 6220 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6221 | public void handleChildViewDismissed(View view) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6222 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6223 | if (mDismissAllInProgress) { |
| 6224 | return; |
| 6225 | } |
| 6226 | |
| 6227 | boolean isBlockingHelperShown = false; |
| 6228 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6229 | mAmbientState.onDragFinished(view); |
| 6230 | updateContinuousShadowDrawing(); |
| 6231 | |
| 6232 | if (view instanceof ExpandableNotificationRow) { |
| 6233 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6234 | if (row.isHeadsUp()) { |
| 6235 | mHeadsUpManager.addSwipedOutNotification( |
| 6236 | row.getStatusBarNotification().getKey()); |
| 6237 | } |
| 6238 | isBlockingHelperShown = |
| 6239 | row.performDismissWithBlockingHelper(false /* fromAccessibility */); |
| 6240 | } |
| 6241 | |
| 6242 | if (!isBlockingHelperShown) { |
| 6243 | mSwipedOutViews.add(view); |
| 6244 | } |
| 6245 | mFalsingManager.onNotificationDismissed(); |
| 6246 | if (mFalsingManager.shouldEnforceBouncer()) { |
| 6247 | mStatusBar.executeRunnableDismissingKeyguard( |
| 6248 | null, |
| 6249 | null /* cancelAction */, |
| 6250 | false /* dismissShade */, |
| 6251 | true /* afterKeyguardGone */, |
| 6252 | false /* deferred */); |
| 6253 | } |
| 6254 | } |
| 6255 | |
| 6256 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6257 | public boolean isAntiFalsingNeeded() { |
| 6258 | return onKeyguard(); |
| 6259 | } |
| 6260 | |
| 6261 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6262 | public View getChildAtPosition(MotionEvent ev) { |
| 6263 | View child = NotificationStackScrollLayout.this.getChildAtPosition(ev.getX(), |
| 6264 | ev.getY()); |
| 6265 | if (child instanceof ExpandableNotificationRow) { |
| 6266 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 6267 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 6268 | if (parent != null && parent.areChildrenExpanded() |
| 6269 | && (parent.areGutsExposed() |
| 6270 | || mSwipeHelper.getExposedMenuView() == parent |
| 6271 | || (parent.getNotificationChildren().size() == 1 |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 6272 | && parent.getEntry().isClearable()))) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6273 | // In this case the group is expanded and showing the menu for the |
| 6274 | // group, further interaction should apply to the group, not any |
| 6275 | // child notifications so we use the parent of the child. We also do the same |
| 6276 | // if we only have a single child. |
| 6277 | child = parent; |
| 6278 | } |
| 6279 | } |
| 6280 | return child; |
| 6281 | } |
| 6282 | |
| 6283 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6284 | public void onBeginDrag(View v) { |
| 6285 | mFalsingManager.onNotificatonStartDismissing(); |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6286 | setSwipingInProgress(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6287 | mAmbientState.onBeginDrag((ExpandableView) v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6288 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6289 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6290 | requestChildrenUpdate(); |
| 6291 | } |
| 6292 | |
| 6293 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6294 | public void onChildSnappedBack(View animView, float targetLeft) { |
| 6295 | mAmbientState.onDragFinished(animView); |
| 6296 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6297 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6301 | public boolean updateSwipeProgress(View animView, boolean dismissable, |
| 6302 | float swipeProgress) { |
| 6303 | // Returning true prevents alpha fading. |
| 6304 | return !mFadeNotificationsOnDismiss; |
| 6305 | } |
| 6306 | |
| 6307 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6308 | public float getFalsingThresholdFactor() { |
| 6309 | return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
| 6310 | } |
| 6311 | |
| 6312 | @Override |
Gus Prevas | c4e68d4 | 2019-01-17 15:45:21 -0500 | [diff] [blame] | 6313 | public int getConstrainSwipeStartPosition() { |
| 6314 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 6315 | if (menuRow != null) { |
| 6316 | return Math.abs(menuRow.getMenuSnapTarget()); |
| 6317 | } |
| 6318 | return 0; |
| 6319 | } |
| 6320 | |
| 6321 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6322 | public boolean canChildBeDismissed(View v) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6323 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6324 | } |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6325 | |
| 6326 | @Override |
| 6327 | public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) { |
Evan Laird | 30b9b16 | 2019-04-24 15:22:24 -0400 | [diff] [blame] | 6328 | //TODO: b/131242807 for why this doesn't do anything with direction |
| 6329 | return canChildBeDismissed(v); |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6330 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6331 | }; |
| 6332 | |
| 6333 | // ---------------------- DragDownHelper.OnDragDownListener ------------------------------------ |
| 6334 | |
| 6335 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6336 | private final DragDownCallback mDragDownCallback = new DragDownCallback() { |
| 6337 | |
| 6338 | /* Only ever called as a consequence of a lockscreen expansion gesture. */ |
| 6339 | @Override |
| 6340 | public boolean onDraggedDown(View startingChild, int dragLengthY) { |
| 6341 | if (mStatusBarState == StatusBarState.KEYGUARD |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6342 | && hasActiveNotifications()) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6343 | mLockscreenGestureLogger.write( |
| 6344 | MetricsEvent.ACTION_LS_SHADE, |
| 6345 | (int) (dragLengthY / mDisplayMetrics.density), |
| 6346 | 0 /* velocityDp - N/A */); |
| 6347 | |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 6348 | if (!mAmbientState.isDozing() || startingChild != null) { |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6349 | // We have notifications, go to locked shade. |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 6350 | mShadeController.goToLockedShade(startingChild); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6351 | if (startingChild instanceof ExpandableNotificationRow) { |
| 6352 | ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild; |
| 6353 | row.onExpandedByGesture(true /* drag down is always an open */); |
| 6354 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6355 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6356 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6357 | return true; |
| 6358 | } else { |
| 6359 | // abort gesture. |
| 6360 | return false; |
| 6361 | } |
| 6362 | } |
| 6363 | |
| 6364 | @Override |
| 6365 | public void onDragDownReset() { |
| 6366 | setDimmed(true /* dimmed */, true /* animated */); |
| 6367 | resetScrollPosition(); |
| 6368 | resetCheckSnoozeLeavebehind(); |
| 6369 | } |
| 6370 | |
| 6371 | @Override |
| 6372 | public void onCrossedThreshold(boolean above) { |
| 6373 | setDimmed(!above /* dimmed */, true /* animate */); |
| 6374 | } |
| 6375 | |
| 6376 | @Override |
| 6377 | public void onTouchSlopExceeded() { |
| 6378 | cancelLongPress(); |
| 6379 | checkSnoozeLeavebehind(); |
| 6380 | } |
| 6381 | |
| 6382 | @Override |
| 6383 | public void setEmptyDragAmount(float amount) { |
| 6384 | mNotificationPanel.setEmptyDragAmount(amount); |
| 6385 | } |
| 6386 | |
| 6387 | @Override |
| 6388 | public boolean isFalsingCheckNeeded() { |
| 6389 | return mStatusBarState == StatusBarState.KEYGUARD; |
| 6390 | } |
| 6391 | }; |
| 6392 | |
| 6393 | public DragDownCallback getDragDownCallback() { return mDragDownCallback; } |
| 6394 | |
| 6395 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6396 | private final HeadsUpTouchHelper.Callback mHeadsUpCallback = new HeadsUpTouchHelper.Callback() { |
| 6397 | @Override |
| 6398 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6399 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6400 | } |
| 6401 | |
| 6402 | @Override |
| 6403 | public boolean isExpanded() { |
| 6404 | return mIsExpanded; |
| 6405 | } |
| 6406 | |
| 6407 | @Override |
| 6408 | public Context getContext() { |
| 6409 | return mContext; |
| 6410 | } |
| 6411 | }; |
| 6412 | |
| 6413 | public HeadsUpTouchHelper.Callback getHeadsUpCallback() { return mHeadsUpCallback; } |
| 6414 | |
| 6415 | |
| 6416 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6417 | private final OnGroupChangeListener mOnGroupChangeListener = new OnGroupChangeListener() { |
| 6418 | @Override |
| 6419 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
| 6420 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 6421 | && (mIsExpanded || changedRow.isPinned()); |
| 6422 | if (animated) { |
| 6423 | mExpandedGroupView = changedRow; |
| 6424 | mNeedsAnimation = true; |
| 6425 | } |
| 6426 | changedRow.setChildrenExpanded(expanded, animated); |
| 6427 | if (!mGroupExpandedForMeasure) { |
| 6428 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 6429 | } |
| 6430 | runAfterAnimationFinished(new Runnable() { |
| 6431 | @Override |
| 6432 | public void run() { |
| 6433 | changedRow.onFinishedExpansionChange(); |
| 6434 | } |
| 6435 | }); |
| 6436 | } |
| 6437 | |
| 6438 | @Override |
| 6439 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
| 6440 | mStatusBar.requestNotificationUpdate(); |
| 6441 | } |
| 6442 | |
| 6443 | @Override |
| 6444 | public void onGroupsChanged() { |
| 6445 | mStatusBar.requestNotificationUpdate(); |
| 6446 | } |
| 6447 | }; |
| 6448 | |
| 6449 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6450 | private ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { |
| 6451 | @Override |
| 6452 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
| 6453 | return NotificationStackScrollLayout.this.getChildAtPosition(touchX, touchY); |
| 6454 | } |
| 6455 | |
| 6456 | @Override |
| 6457 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6458 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6459 | } |
| 6460 | |
| 6461 | @Override |
| 6462 | public boolean canChildBeExpanded(View v) { |
| 6463 | return v instanceof ExpandableNotificationRow |
| 6464 | && ((ExpandableNotificationRow) v).isExpandable() |
| 6465 | && !((ExpandableNotificationRow) v).areGutsExposed() |
| 6466 | && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned()); |
| 6467 | } |
| 6468 | |
| 6469 | /* Only ever called as a consequence of an expansion gesture in the shade. */ |
| 6470 | @Override |
| 6471 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 6472 | if (v instanceof ExpandableNotificationRow) { |
| 6473 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6474 | if (userExpanded && onKeyguard()) { |
| 6475 | // Due to a race when locking the screen while touching, a notification may be |
| 6476 | // expanded even after we went back to keyguard. An example of this happens if |
| 6477 | // you click in the empty space while expanding a group. |
| 6478 | |
| 6479 | // We also need to un-user lock it here, since otherwise the content height |
| 6480 | // calculated might be wrong. We also can't invert the two calls since |
| 6481 | // un-userlocking it will trigger a layout switch in the content view. |
| 6482 | row.setUserLocked(false); |
| 6483 | updateContentHeight(); |
| 6484 | notifyHeightChangeListener(row); |
| 6485 | return; |
| 6486 | } |
| 6487 | row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */); |
| 6488 | row.onExpandedByGesture(userExpanded); |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | @Override |
| 6493 | public void setExpansionCancelled(View v) { |
| 6494 | if (v instanceof ExpandableNotificationRow) { |
| 6495 | ((ExpandableNotificationRow) v).setGroupExpansionChanging(false); |
| 6496 | } |
| 6497 | } |
| 6498 | |
| 6499 | @Override |
| 6500 | public void setUserLockedChild(View v, boolean userLocked) { |
| 6501 | if (v instanceof ExpandableNotificationRow) { |
| 6502 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 6503 | } |
| 6504 | cancelLongPress(); |
| 6505 | requestDisallowInterceptTouchEvent(true); |
| 6506 | } |
| 6507 | |
| 6508 | @Override |
| 6509 | public void expansionStateChanged(boolean isExpanding) { |
| 6510 | mExpandingNotification = isExpanding; |
| 6511 | if (!mExpandedInThisMotion) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 6512 | if (ANCHOR_SCROLLING) { |
| 6513 | // TODO |
| 6514 | } else { |
| 6515 | mMaxScrollAfterExpand = mOwnScrollY; |
| 6516 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6517 | mExpandedInThisMotion = true; |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | @Override |
| 6522 | public int getMaxExpandHeight(ExpandableView view) { |
| 6523 | return view.getMaxContentHeight(); |
| 6524 | } |
| 6525 | }; |
| 6526 | |
| 6527 | public ExpandHelper.Callback getExpandHelperCallback() { |
| 6528 | return mExpandHelperCallback; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6529 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6530 | |
| 6531 | /** Enum for selecting some or all notification rows (does not included non-notif views). */ |
| 6532 | @Retention(SOURCE) |
| 6533 | @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE}) |
| 6534 | public @interface SelectedRows {} |
| 6535 | /** All rows representing notifs. */ |
| 6536 | public static final int ROWS_ALL = 0; |
| 6537 | /** Only rows where entry.isHighPriority() is true. */ |
| 6538 | public static final int ROWS_HIGH_PRIORITY = 1; |
| 6539 | /** Only rows where entry.isHighPriority() is false. */ |
| 6540 | public static final int ROWS_GENTLE = 2; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 6541 | } |