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; |
| 91 | import com.android.systemui.classifier.FalsingManagerFactory.FalsingManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 92 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 93 | import com.android.systemui.plugins.ActivityStarter; |
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) { |
Lucas Dupin | 9f1e948 | 2019-04-01 11:04:10 -0700 | [diff] [blame] | 412 | if (mAmbientState.isDarkAtAll() || !mShowDarkShelf) { |
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 | */ |
| 510 | private boolean mShowDarkShelf; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 511 | private boolean mAnimateBottomOnLayout; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 512 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 513 | @Inject |
| 514 | public NotificationStackScrollLayout( |
| 515 | @Named(VIEW_CONTEXT) Context context, |
| 516 | AttributeSet attrs, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 517 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress, |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 518 | NotificationRoundnessManager notificationRoundnessManager, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 519 | AmbientPulseManager ambientPulseManager, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 520 | DynamicPrivacyController dynamicPrivacyController, |
| 521 | ActivityStarter activityStarter) { |
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, |
| 537 | NotificationUtils.useNewInterruptionModel(context)); |
| 538 | mSectionsManager.inflateViews(context); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 539 | mSectionsManager.setOnClearGentleNotifsClickListener(v -> { |
| 540 | // Leave the shade open if there will be other notifs left over to clear |
| 541 | final boolean closeShade = !hasActiveClearableNotifications(ROWS_HIGH_PRIORITY); |
| 542 | clearNotifications(ROWS_GENTLE, closeShade); |
| 543 | }); |
| 544 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 545 | mAmbientState = new AmbientState(context, mSectionsManager); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 546 | mRoundnessManager = notificationRoundnessManager; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 547 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 548 | int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 549 | int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 550 | mExpandHelper = new ExpandHelper(getContext(), mExpandHelperCallback, |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 551 | minHeight, maxHeight); |
| 552 | mExpandHelper.setEventSource(this); |
| 553 | mExpandHelper.setScrollAdapter(this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 554 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, mNotificationCallback, |
| 555 | getContext(), mMenuEventListener); |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 556 | mStackScrollAlgorithm = createStackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 557 | initView(context); |
Dave Mankoff | dde5ee6 | 2019-05-02 17:36:11 -0400 | [diff] [blame] | 558 | mFalsingManager = FalsingManagerFactory.getInstance(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 559 | mShouldDrawNotificationBackground = |
| 560 | res.getBoolean(R.bool.config_drawNotificationBackground); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 561 | mFadeNotificationsOnDismiss = |
| 562 | res.getBoolean(R.bool.config_fadeNotificationsOnDismiss); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 563 | mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated); |
| 564 | mRoundnessManager.setOnRoundingChangedCallback(this::invalidate); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 565 | addOnExpandedHeightListener(mRoundnessManager::setExpanded); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 566 | setOutlineProvider(mOutlineProvider); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 567 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 568 | // Blocking helper manager wants to know the expanded state, update as well. |
| 569 | NotificationBlockingHelperManager blockingHelperManager = |
| 570 | Dependency.get(NotificationBlockingHelperManager.class); |
| 571 | addOnExpandedHeightListener((height, unused) -> { |
| 572 | blockingHelperManager.setNotificationShadeExpanded(height); |
| 573 | }); |
| 574 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 575 | updateWillNotDraw(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 576 | mBackgroundPaint.setAntiAlias(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 577 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 578 | mDebugPaint = new Paint(); |
| 579 | mDebugPaint.setColor(0xffff0000); |
| 580 | mDebugPaint.setStrokeWidth(2); |
| 581 | mDebugPaint.setStyle(Paint.Style.STROKE); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 582 | mDebugPaint.setTextSize(25f); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 583 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 584 | mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 585 | |
| 586 | TunerService tunerService = Dependency.get(TunerService.class); |
| 587 | tunerService.addTunable((key, newValue) -> { |
| 588 | if (key.equals(LOW_PRIORITY)) { |
| 589 | mLowPriorityBeforeSpeedBump = "1".equals(newValue); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 590 | } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { |
| 591 | updateDismissRtlSetting("1".equals(newValue)); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 592 | } |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 593 | }, LOW_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL); |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 594 | |
| 595 | mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 596 | @Override |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 597 | public void onPostEntryUpdated(NotificationEntry entry) { |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 598 | if (!entry.notification.isClearable()) { |
| 599 | // The user may have performed a dismiss action on the notification, since it's |
| 600 | // not clearable we should snap it back. |
| 601 | snapViewIfNeeded(entry); |
| 602 | } |
| 603 | } |
| 604 | }); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 605 | dynamicPrivacyController.addListener(this); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 606 | } |
| 607 | |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 608 | private void updateDismissRtlSetting(boolean dismissRtl) { |
| 609 | mDismissRtl = dismissRtl; |
| 610 | for (int i = 0; i < getChildCount(); i++) { |
| 611 | View child = getChildAt(i); |
| 612 | if (child instanceof ExpandableNotificationRow) { |
| 613 | ((ExpandableNotificationRow) child).setDismissRtl(dismissRtl); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 618 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 619 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 620 | protected void onFinishInflate() { |
| 621 | super.onFinishInflate(); |
| 622 | |
| 623 | inflateEmptyShadeView(); |
| 624 | inflateFooterView(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 625 | mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 626 | if (mAllowLongPress) { |
| 627 | setLongPressListener(mGutsManager::openGuts); |
| 628 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 629 | } |
| 630 | |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 631 | /** |
| 632 | * @return the height at which we will wake up when pulsing |
| 633 | */ |
| 634 | public float getPulseHeight() { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 635 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 636 | if (firstChild != null) { |
| 637 | return firstChild.getCollapsedHeight(); |
| 638 | } |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 639 | return 0f; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 640 | } |
| 641 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 642 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 643 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 644 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 645 | reinflateViews(); |
| 646 | } |
| 647 | |
| 648 | private void reinflateViews() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 649 | inflateFooterView(); |
| 650 | inflateEmptyShadeView(); |
| 651 | updateFooter(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 652 | mSectionsManager.inflateViews(mContext); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 656 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 657 | public void onThemeChanged() { |
| 658 | int which; |
| 659 | if (mStatusBarState == StatusBarState.KEYGUARD |
| 660 | || mStatusBarState == StatusBarState.SHADE_LOCKED) { |
| 661 | which = WallpaperManager.FLAG_LOCK; |
| 662 | } else { |
| 663 | which = WallpaperManager.FLAG_SYSTEM; |
| 664 | } |
| 665 | final boolean useDarkText = mColorExtractor.getColors(which, |
| 666 | true /* ignoreVisibility */).supportsDarkText(); |
| 667 | updateDecorViews(useDarkText); |
| 668 | |
| 669 | updateFooter(); |
| 670 | } |
| 671 | |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 672 | @Override |
| 673 | public void onOverlayChanged() { |
| 674 | int newRadius = mContext.getResources().getDimensionPixelSize( |
| 675 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
| 676 | if (mCornerRadius != newRadius) { |
| 677 | mCornerRadius = newRadius; |
| 678 | invalidate(); |
| 679 | } |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 680 | reinflateViews(); |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 681 | } |
| 682 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 683 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 684 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 685 | public void updateFooter() { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 686 | boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 687 | boolean showFooterView = (showDismissView || |
| 688 | mEntryManager.getNotificationData().getActiveNotifications().size() != 0) |
| 689 | && mStatusBarState != StatusBarState.KEYGUARD |
| 690 | && !mRemoteInputManager.getController().isRemoteInputActive(); |
| 691 | |
| 692 | updateFooterView(showFooterView, showDismissView); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Return whether there are any clearable notifications |
| 697 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 698 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 699 | public boolean hasActiveClearableNotifications(@SelectedRows int selection) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 700 | int childCount = getChildCount(); |
| 701 | for (int i = 0; i < childCount; i++) { |
| 702 | View child = getChildAt(i); |
| 703 | if (!(child instanceof ExpandableNotificationRow)) { |
| 704 | continue; |
| 705 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 706 | final ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 707 | if (row.canViewBeDismissed() && matchesSelection(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 708 | return true; |
| 709 | } |
| 710 | } |
| 711 | return false; |
| 712 | } |
| 713 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 714 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 715 | public RemoteInputController.Delegate createDelegate() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 716 | return new RemoteInputController.Delegate() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 717 | public void setRemoteInputActive(NotificationEntry entry, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 718 | boolean remoteInputActive) { |
| 719 | mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 720 | entry.notifyHeightChanged(true /* needsAnimation */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 721 | updateFooter(); |
| 722 | } |
| 723 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 724 | public void lockScrollTo(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 725 | NotificationStackScrollLayout.this.lockScrollTo(entry.getRow()); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | public void requestDisallowLongPressAndDismiss() { |
| 729 | requestDisallowLongPress(); |
| 730 | requestDisallowDismiss(); |
| 731 | } |
| 732 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 733 | } |
| 734 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 735 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 736 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 737 | protected void onAttachedToWindow() { |
| 738 | super.onAttachedToWindow(); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 739 | ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class)) |
| 740 | .addCallback(mStateListener, SysuiStatusBarStateController.RANK_STACK_SCROLLER); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 741 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 745 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 746 | protected void onDetachedFromWindow() { |
| 747 | super.onDetachedFromWindow(); |
Jason Monk | af08c15 | 2018-12-04 11:12:39 -0500 | [diff] [blame] | 748 | Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 749 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | @Override |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 753 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 754 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 755 | return mSwipeHelper; |
| 756 | } |
| 757 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 758 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 759 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 760 | public void onUiModeChanged() { |
| 761 | mBgColor = mContext.getColor(R.color.notification_shade_background_color); |
| 762 | updateBackgroundDimming(); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 763 | mShelf.onUiModeChanged(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 764 | mSectionsManager.onUiModeChanged(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 767 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 768 | protected void onDraw(Canvas canvas) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 769 | if (mShouldDrawNotificationBackground |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 770 | && (mSections[0].getCurrentBounds().top |
| 771 | < mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom |
| 772 | || mAmbientState.isDark())) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 773 | drawBackground(canvas); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 774 | } else if (mInHeadsUpPinnedMode || mHeadsUpAnimatingAway) { |
| 775 | drawHeadsUpBackground(canvas); |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 776 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 777 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 778 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 779 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 780 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 781 | y = getLayoutHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 782 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 783 | y = getHeight() - getEmptyBottomMargin(); |
| 784 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 788 | @Override |
| 789 | public void draw(Canvas canvas) { |
| 790 | super.draw(canvas); |
| 791 | |
| 792 | if (DEBUG && ANCHOR_SCROLLING) { |
| 793 | if (mScrollAnchorView instanceof ExpandableNotificationRow) { |
| 794 | canvas.drawRect(0, |
| 795 | mScrollAnchorView.getTranslationY(), |
| 796 | getWidth(), |
| 797 | mScrollAnchorView.getTranslationY() |
| 798 | + ((ExpandableNotificationRow) mScrollAnchorView).getActualHeight(), |
| 799 | mDebugPaint); |
| 800 | canvas.drawText(Integer.toString(mScrollAnchorViewY), getWidth() - 200, |
| 801 | mScrollAnchorView.getTranslationY() + 30, mDebugPaint); |
| 802 | int y = (int) mShelf.getTranslationY(); |
| 803 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 804 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 805 | canvas.drawText(Integer.toString(getMaxNegativeScrollAmount()), getWidth() - 100, |
| 806 | getIntrinsicPadding() + 30, mDebugPaint); |
| 807 | canvas.drawText(Integer.toString(getMaxPositiveScrollAmount()), getWidth() - 100, |
| 808 | getHeight() - 30, mDebugPaint); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 812 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 813 | private void drawBackground(Canvas canvas) { |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 814 | int lockScreenLeft = mSidePaddings; |
| 815 | int lockScreenRight = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 816 | int lockScreenTop = mSections[0].getCurrentBounds().top; |
| 817 | int lockScreenBottom = mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom; |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 818 | int darkLeft = getWidth() / 2; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 819 | int darkTop = mTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 820 | |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 821 | float yProgress = 1 - mInterpolatedDarkAmount; |
| 822 | float xProgress = mDarkXInterpolator.getInterpolation( |
| 823 | (1 - mLinearDarkAmount) * mBackgroundXFactor); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 824 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 825 | int left = (int) MathUtils.lerp(darkLeft, lockScreenLeft, xProgress); |
| 826 | int right = (int) MathUtils.lerp(darkLeft, lockScreenRight, xProgress); |
| 827 | int top = (int) MathUtils.lerp(darkTop, lockScreenTop, yProgress); |
| 828 | int bottom = (int) MathUtils.lerp(darkTop, lockScreenBottom, yProgress); |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 829 | mBackgroundAnimationRect.set( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 830 | left, |
| 831 | top, |
| 832 | right, |
| 833 | bottom); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 834 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 835 | int backgroundTopAnimationOffset = top - lockScreenTop; |
| 836 | // TODO(kprevas): this may not be necessary any more since we don't display the shelf in AOD |
| 837 | boolean anySectionHasVisibleChild = false; |
| 838 | for (NotificationSection section : mSections) { |
| 839 | if (section.getFirstVisibleChild() != null) { |
| 840 | anySectionHasVisibleChild = true; |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | if (!mAmbientState.isDark() || anySectionHasVisibleChild) { |
| 845 | drawBackgroundRects(canvas, left, right, top, backgroundTopAnimationOffset); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 846 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 847 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 848 | updateClipping(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 849 | } |
| 850 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 851 | /** |
| 852 | * Draws round rects for each background section. |
| 853 | * |
| 854 | * We want to draw a round rect for each background section as defined by {@link #mSections}. |
| 855 | * However, if two sections are directly adjacent with no gap between them (e.g. on the |
| 856 | * lockscreen where the shelf can appear directly below the high priority section, or while |
| 857 | * scrolling the shade so that the top of the shelf is right at the bottom of the high priority |
| 858 | * section), we don't want to round the adjacent corners. |
| 859 | * |
| 860 | * Since {@link Canvas} doesn't provide a way to draw a half-rounded rect, this means that we |
| 861 | * need to coalesce the backgrounds for adjacent sections and draw them as a single round rect. |
| 862 | * This method tracks the top of each rect we need to draw, then iterates through the visible |
| 863 | * sections. If a section is not adjacent to the previous section, we draw the previous rect |
| 864 | * behind the sections we've accumulated up to that point, then start a new rect at the top of |
| 865 | * the current section. When we're done iterating we will always have one rect left to draw. |
| 866 | */ |
| 867 | private void drawBackgroundRects(Canvas canvas, int left, int right, int top, |
| 868 | int animationYOffset) { |
| 869 | int backgroundRectTop = top; |
| 870 | int lastSectionBottom = |
| 871 | mSections[0].getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 872 | int previousLeft = left; |
| 873 | boolean first = true; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 874 | for (NotificationSection section : mSections) { |
| 875 | if (section.getFirstVisibleChild() == null) { |
| 876 | continue; |
| 877 | } |
| 878 | int sectionTop = section.getCurrentBounds().top + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 879 | int ownLeft = Math.min(Math.max(left, section.getCurrentBounds().left), right); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 880 | // If sections are directly adjacent to each other, we don't want to draw them |
| 881 | // as separate roundrects, as the rounded corners right next to each other look |
| 882 | // bad. |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 883 | if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX |
| 884 | || (previousLeft != ownLeft && !first)) { |
| 885 | canvas.drawRoundRect(ownLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 886 | backgroundRectTop, |
| 887 | right, |
| 888 | lastSectionBottom, |
| 889 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 890 | backgroundRectTop = sectionTop; |
| 891 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 892 | previousLeft = ownLeft; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 893 | lastSectionBottom = |
| 894 | section.getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 895 | first = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 896 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 897 | canvas.drawRoundRect(previousLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 898 | backgroundRectTop, |
| 899 | right, |
| 900 | lastSectionBottom, |
| 901 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 902 | } |
| 903 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 904 | private void drawHeadsUpBackground(Canvas canvas) { |
| 905 | int left = mSidePaddings; |
| 906 | int right = getWidth() - mSidePaddings; |
| 907 | |
| 908 | float top = getHeight(); |
| 909 | float bottom = 0; |
| 910 | int childCount = getChildCount(); |
| 911 | for (int i = 0; i < childCount; i++) { |
| 912 | View child = getChildAt(i); |
| 913 | if (child.getVisibility() != View.GONE |
| 914 | && child instanceof ExpandableNotificationRow) { |
| 915 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 916 | if ((row.isPinned() || row.isHeadsUpAnimatingAway()) && row.getTranslation() < 0) { |
| 917 | top = Math.min(top, row.getTranslationY()); |
| 918 | bottom = Math.max(bottom, row.getTranslationY() + row.getActualHeight()); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | if (top < bottom) { |
| 924 | canvas.drawRoundRect( |
| 925 | left, top, right, bottom, |
| 926 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 927 | } |
| 928 | } |
| 929 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 930 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 931 | private void updateBackgroundDimming() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 932 | // No need to update the background color if it's not being drawn. |
| 933 | if (!mShouldDrawNotificationBackground) { |
| 934 | return; |
| 935 | } |
| 936 | |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 937 | float alpha = |
| 938 | BACKGROUND_ALPHA_DIMMED + (1 - BACKGROUND_ALPHA_DIMMED) * (1.0f - mDimAmount); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 939 | alpha *= 1f - mInterpolatedDarkAmount; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 940 | // We need to manually blend in the background color. |
| 941 | int scrimColor = mScrimController.getBackgroundColor(); |
| 942 | int awakeColor = ColorUtils.blendARGB(scrimColor, mBgColor, alpha); |
| 943 | |
| 944 | // Interpolate between semi-transparent notification panel background color |
| 945 | // and white AOD separator. |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 946 | float colorInterpolation = MathUtils.smoothStep(0.4f /* start */, 1f /* end */, |
| 947 | mLinearDarkAmount); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 948 | int color = ColorUtils.blendARGB(awakeColor, Color.WHITE, colorInterpolation); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 949 | |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 950 | if (mCachedBackgroundColor != color) { |
| 951 | mCachedBackgroundColor = color; |
| 952 | mBackgroundPaint.setColor(color); |
| 953 | invalidate(); |
| 954 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 955 | } |
| 956 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 957 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 958 | private void initView(Context context) { |
| 959 | mScroller = new OverScroller(getContext()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 960 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 961 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 962 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 963 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 964 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 965 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 966 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 967 | |
| 968 | Resources res = context.getResources(); |
| 969 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 970 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 971 | mAmbientState.reload(context); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 972 | mPaddingBetweenElements = Math.max(1, |
| 973 | res.getDimensionPixelSize(R.dimen.notification_divider_height)); |
| 974 | mIncreasedPaddingBetweenElements = |
| 975 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 976 | mMinTopOverScrollToEscape = res.getDimensionPixelSize( |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 977 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 978 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 979 | mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 980 | mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 981 | mMinInteractionHeight = res.getDimensionPixelSize( |
| 982 | R.dimen.notification_min_interaction_height); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 983 | mCornerRadius = res.getDimensionPixelSize( |
| 984 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 985 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 986 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 987 | } |
| 988 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 989 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 990 | private void notifyHeightChangeListener(ExpandableView view) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 991 | notifyHeightChangeListener(view, false /* needsAnimation */); |
| 992 | } |
| 993 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 994 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 995 | private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) { |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 996 | if (mOnHeightChangedListener != null) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 997 | mOnHeightChangedListener.onHeightChanged(view, needsAnimation); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 998 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1002 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1003 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1004 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 1005 | |
| 1006 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 1007 | int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2, |
| 1008 | MeasureSpec.getMode(widthMeasureSpec)); |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1009 | // Don't constrain the height of the children so we know how big they'd like to be |
| 1010 | int childHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), |
| 1011 | MeasureSpec.UNSPECIFIED); |
| 1012 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1013 | // We need to measure all children even the GONE ones, such that the heights are calculated |
| 1014 | // correctly as they are used to calculate how many we can fit on the screen. |
| 1015 | final int size = getChildCount(); |
| 1016 | for (int i = 0; i < size; i++) { |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1017 | measureChild(getChildAt(i), childWidthSpec, childHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1018 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1022 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1023 | 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] | 1024 | // we layout all our children centered on the top |
| 1025 | float centerX = getWidth() / 2.0f; |
| 1026 | for (int i = 0; i < getChildCount(); i++) { |
| 1027 | View child = getChildAt(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1028 | // We need to layout all children even the GONE ones, such that the heights are |
| 1029 | // 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] | 1030 | float width = child.getMeasuredWidth(); |
| 1031 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1032 | child.layout((int) (centerX - width / 2.0f), |
| 1033 | 0, |
| 1034 | (int) (centerX + width / 2.0f), |
| 1035 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1036 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 1037 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1038 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1039 | clampScrollPosition(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1040 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1041 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1042 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1045 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1046 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 1047 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1048 | mNeedViewResizeAnimation = true; |
| 1049 | mNeedsAnimation = true; |
| 1050 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1053 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1054 | public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) { |
| 1055 | mAmbientState.setSpeedBumpIndex(newIndex); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1056 | mNoAmbient = noAmbient; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1057 | } |
| 1058 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1059 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1060 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1061 | public void setChildLocationsChangedListener( |
| 1062 | NotificationLogger.OnChildLocationsChangedListener listener) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1063 | mListener = listener; |
| 1064 | } |
| 1065 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1066 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1067 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1068 | public boolean isInVisibleLocation(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1069 | ExpandableNotificationRow row = entry.getRow(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1070 | ExpandableViewState childViewState = row.getViewState(); |
| 1071 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1072 | if (childViewState == null) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1073 | return false; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1074 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 1075 | if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1076 | return false; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 1077 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1078 | if (row.getVisibility() != View.VISIBLE) { |
| 1079 | return false; |
| 1080 | } |
| 1081 | return true; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1084 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1085 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 1086 | mMaxLayoutHeight = maxLayoutHeight; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 1087 | mShelf.setMaxLayoutHeight(maxLayoutHeight); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1088 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1091 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1092 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1093 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1094 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1095 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1098 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1099 | private void updateAlgorithmLayoutMinHeight() { |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 1100 | mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition() |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1101 | ? getLayoutMinHeight() : 0); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1104 | /** |
| 1105 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 1106 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 1107 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1108 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1109 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1110 | updateScrollStateForAddedChildren(); |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 1111 | mAmbientState.setCurrentScrollVelocity(mScroller.isFinished() |
| 1112 | ? 0 |
| 1113 | : mScroller.getCurrVelocity()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1114 | if (ANCHOR_SCROLLING) { |
| 1115 | mAmbientState.setAnchorViewIndex(indexOfChild(mScrollAnchorView)); |
| 1116 | mAmbientState.setAnchorViewY(mScrollAnchorViewY); |
| 1117 | } else { |
| 1118 | mAmbientState.setScrollY(mOwnScrollY); |
| 1119 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1120 | mStackScrollAlgorithm.resetViewStates(mAmbientState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1121 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1122 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1123 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1124 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1128 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1129 | private void onPreDrawDuringAnimation() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1130 | mShelf.updateAppearance(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1131 | updateClippingToTopRoundedCorner(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1132 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 1133 | updateBackground(); |
| 1134 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1137 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1138 | private void updateClippingToTopRoundedCorner() { |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1139 | Float clipStart = (float) mTopPadding |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1140 | + mStackTranslation |
| 1141 | + mAmbientState.getExpandAnimationTopChange(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1142 | Float clipEnd = clipStart + mCornerRadius; |
| 1143 | boolean first = true; |
| 1144 | for (int i = 0; i < getChildCount(); i++) { |
| 1145 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1146 | if (child.getVisibility() == GONE) { |
| 1147 | continue; |
| 1148 | } |
| 1149 | float start = child.getTranslationY(); |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1150 | float end = start + child.getActualHeight(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1151 | boolean clip = clipStart > start && clipStart < end |
| 1152 | || clipEnd >= start && clipEnd <= end; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1153 | clip &= !(first && isScrolledToTop()); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 1154 | child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0) |
| 1155 | : ExpandableView.NO_ROUNDNESS); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1156 | first = false; |
| 1157 | } |
| 1158 | } |
| 1159 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1160 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1161 | private void updateScrollStateForAddedChildren() { |
| 1162 | if (mChildrenToAddAnimated.isEmpty()) { |
| 1163 | return; |
| 1164 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1165 | if (!ANCHOR_SCROLLING) { |
| 1166 | for (int i = 0; i < getChildCount(); i++) { |
| 1167 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1168 | if (mChildrenToAddAnimated.contains(child)) { |
| 1169 | int startingPosition = getPositionInLinearLayout(child); |
| 1170 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
| 1171 | int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements |
| 1172 | : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements; |
| 1173 | int childHeight = getIntrinsicHeight(child) + padding; |
| 1174 | if (startingPosition < mOwnScrollY) { |
| 1175 | // This child starts off screen, so let's keep it offscreen to keep the |
| 1176 | // others visible |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1177 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1178 | setOwnScrollY(mOwnScrollY + childHeight); |
| 1179 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | clampScrollPosition(); |
| 1184 | } |
| 1185 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1186 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1187 | private void updateForcedScroll() { |
| 1188 | if (mForcedScroll != null && (!mForcedScroll.hasFocus() |
| 1189 | || !mForcedScroll.isAttachedToWindow())) { |
| 1190 | mForcedScroll = null; |
| 1191 | } |
| 1192 | if (mForcedScroll != null) { |
| 1193 | ExpandableView expandableView = (ExpandableView) mForcedScroll; |
| 1194 | int positionInLinearLayout = getPositionInLinearLayout(expandableView); |
| 1195 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1196 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1197 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1198 | if (ANCHOR_SCROLLING) { |
| 1199 | // TODO |
| 1200 | } else { |
| 1201 | targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange())); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1202 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1203 | // Only apply the scroll if we're scrolling the view upwards, or the view is so |
| 1204 | // far up that it is not visible anymore. |
| 1205 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1206 | setOwnScrollY(targetScroll); |
| 1207 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1212 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1213 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 1214 | if (!mChildrenUpdateRequested) { |
| 1215 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 1216 | mChildrenUpdateRequested = true; |
| 1217 | invalidate(); |
| 1218 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1219 | } |
| 1220 | |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 1221 | /** |
| 1222 | * Returns best effort count of visible notifications. |
| 1223 | */ |
| 1224 | public int getVisibleNotificationCount() { |
| 1225 | int count = 0; |
| 1226 | for (int i = 0; i < getChildCount(); i++) { |
| 1227 | final View child = getChildAt(i); |
| 1228 | if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) { |
| 1229 | count++; |
| 1230 | } |
| 1231 | } |
| 1232 | return count; |
| 1233 | } |
| 1234 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1235 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1236 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1237 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1240 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1241 | private void clampScrollPosition() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1242 | if (ANCHOR_SCROLLING) { |
| 1243 | // TODO |
| 1244 | } else { |
| 1245 | int scrollRange = getScrollRange(); |
| 1246 | if (scrollRange < mOwnScrollY) { |
| 1247 | setOwnScrollY(scrollRange); |
| 1248 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1252 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1253 | public int getTopPadding() { |
| 1254 | return mTopPadding; |
| 1255 | } |
| 1256 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1257 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1258 | private void setTopPadding(int topPadding, boolean animate) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 1259 | if (mTopPadding != topPadding) { |
| 1260 | mTopPadding = topPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1261 | updateAlgorithmHeightAndPadding(); |
| 1262 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1263 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1264 | mTopPaddingNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1265 | mNeedsAnimation = true; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1266 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1267 | requestChildrenUpdate(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1268 | notifyHeightChangeListener(null, animate); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | /** |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1273 | * Update the height of the panel. |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1274 | * |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1275 | * @param height the expanded height of the panel |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1276 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1277 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1278 | public void setExpandedHeight(float height) { |
| 1279 | mExpandedHeight = height; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1280 | setIsExpanded(height > 0); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1281 | int minExpansionHeight = getMinExpansionHeight(); |
| 1282 | if (height < minExpansionHeight) { |
| 1283 | mClipRect.left = 0; |
| 1284 | mClipRect.right = getWidth(); |
| 1285 | mClipRect.top = 0; |
| 1286 | mClipRect.bottom = (int) height; |
| 1287 | height = minExpansionHeight; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1288 | setRequestedClipBounds(mClipRect); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1289 | } else { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1290 | setRequestedClipBounds(null); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1291 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1292 | int stackHeight; |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1293 | float translationY; |
| 1294 | float appearEndPosition = getAppearEndPosition(); |
| 1295 | float appearStartPosition = getAppearStartPosition(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1296 | float appearFraction = 1.0f; |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 1297 | boolean appearing = height < appearEndPosition; |
| 1298 | mAmbientState.setAppearing(appearing); |
| 1299 | if (!appearing) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1300 | translationY = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 1301 | if (mShouldShowShelfOnly) { |
| 1302 | stackHeight = mTopPadding + mShelf.getIntrinsicHeight(); |
| 1303 | } else if (mQsExpanded) { |
| 1304 | int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding; |
| 1305 | int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight(); |
| 1306 | if (stackStartPosition <= stackEndPosition) { |
| 1307 | stackHeight = stackEndPosition; |
| 1308 | } else { |
| 1309 | stackHeight = (int) NotificationUtils.interpolate(stackStartPosition, |
| 1310 | stackEndPosition, mQsExpansionFraction); |
| 1311 | } |
| 1312 | } else { |
| 1313 | stackHeight = (int) height; |
| 1314 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1315 | } else { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1316 | appearFraction = getAppearFraction(height); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1317 | if (appearFraction >= 0) { |
| 1318 | translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0, |
| 1319 | appearFraction); |
| 1320 | } else { |
| 1321 | // This may happen when pushing up a heads up. We linearly push it up from the |
| 1322 | // start |
| 1323 | translationY = height - appearStartPosition + getExpandTranslationStart(); |
| 1324 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1325 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1326 | stackHeight = |
| 1327 | getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1328 | translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction); |
| 1329 | } else { |
| 1330 | stackHeight = (int) (height - translationY); |
| 1331 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1332 | } |
| 1333 | if (stackHeight != mCurrentStackHeight) { |
| 1334 | mCurrentStackHeight = stackHeight; |
| 1335 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1336 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1337 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1338 | setStackTranslation(translationY); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1339 | for (int i = 0; i < mExpandedHeightListeners.size(); i++) { |
| 1340 | BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i); |
| 1341 | listener.accept(mExpandedHeight, appearFraction); |
| 1342 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1345 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1346 | private void setRequestedClipBounds(Rect clipRect) { |
| 1347 | mRequestedClipBounds = clipRect; |
| 1348 | updateClipping(); |
| 1349 | } |
| 1350 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1351 | /** |
| 1352 | * Return the height of the content ignoring the footer. |
| 1353 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1354 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1355 | public int getIntrinsicContentHeight() { |
| 1356 | return mIntrinsicContentHeight; |
| 1357 | } |
| 1358 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1359 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1360 | public void updateClipping() { |
| 1361 | boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode |
| 1362 | && !mHeadsUpAnimatingAway; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1363 | boolean clipToOutline = false; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1364 | if (mIsClipped != clipped) { |
| 1365 | mIsClipped = clipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1366 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1367 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1368 | if (!mAmbientPulseManager.hasNotifications() |
| 1369 | && mAmbientState.isFullyDark() && mShowDarkShelf) { |
Lucas Dupin | 4798ea1 | 2018-11-05 19:26:24 -0800 | [diff] [blame] | 1370 | setClipBounds(null); |
| 1371 | } else if (mAmbientState.isDarkAtAll()) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1372 | clipToOutline = true; |
| 1373 | invalidateOutline(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1374 | } else if (clipped) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1375 | setClipBounds(mRequestedClipBounds); |
| 1376 | } else { |
| 1377 | setClipBounds(null); |
| 1378 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1379 | |
| 1380 | setClipToOutline(clipToOutline); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * @return The translation at the beginning when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1385 | * Measured relative to the resting position. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1386 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1387 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1388 | private float getExpandTranslationStart() { |
Selim Cinek | 083f214 | 2018-11-06 16:32:23 -0800 | [diff] [blame] | 1389 | return -mTopPadding + getMinExpansionHeight() - mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * @return the position from where the appear transition starts when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1394 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1395 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1396 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1397 | private float getAppearStartPosition() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1398 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1399 | return mHeadsUpInset |
| 1400 | + getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1401 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1402 | return getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1406 | * @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] | 1407 | * intrinsic height, which also includes whether the notification is system expanded and |
| 1408 | * is mainly used when dragging down from a heads up notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1409 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1410 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1411 | private int getTopHeadsUpPinnedHeight() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1412 | NotificationEntry topEntry = mHeadsUpManager.getTopEntry(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1413 | if (topEntry == null) { |
| 1414 | return 0; |
| 1415 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1416 | ExpandableNotificationRow row = topEntry.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1417 | if (row.isChildInGroup()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1418 | final NotificationEntry groupSummary |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1419 | = mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 1420 | if (groupSummary != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1421 | row = groupSummary.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | return row.getPinnedHeadsUpHeight(); |
| 1425 | } |
| 1426 | |
| 1427 | /** |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1428 | * @return the position from where the appear transition ends when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1429 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1430 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1431 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1432 | private float getAppearEndPosition() { |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1433 | int appearPosition; |
Selim Cinek | 66440cf | 2017-05-26 13:48:47 -0700 | [diff] [blame] | 1434 | int notGoneChildCount = getNotGoneChildCount(); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 1435 | if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1436 | if (isHeadsUpTransition() |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 1437 | || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDark())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1438 | appearPosition = getTopHeadsUpPinnedHeight(); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1439 | } else { |
| 1440 | appearPosition = 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1441 | if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) { |
| 1442 | appearPosition += mShelf.getIntrinsicHeight(); |
| 1443 | } |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1444 | } |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1445 | } else { |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1446 | appearPosition = mEmptyShadeView.getHeight(); |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1447 | } |
| 1448 | return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1451 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1452 | private boolean isHeadsUpTransition() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1453 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 1454 | return mTrackingHeadsUp && firstVisibleSection != null |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 1455 | && firstVisibleSection.getFirstVisibleChild().isAboveShelf(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1456 | } |
| 1457 | |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1458 | /** |
| 1459 | * @param height the height of the panel |
| 1460 | * @return the fraction of the appear animation that has been performed |
| 1461 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1462 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1463 | public float getAppearFraction(float height) { |
| 1464 | float appearEndPosition = getAppearEndPosition(); |
| 1465 | float appearStartPosition = getAppearStartPosition(); |
| 1466 | return (height - appearStartPosition) |
| 1467 | / (appearEndPosition - appearStartPosition); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1470 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1471 | public float getStackTranslation() { |
| 1472 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1475 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1476 | private void setStackTranslation(float stackTranslation) { |
| 1477 | if (stackTranslation != mStackTranslation) { |
| 1478 | mStackTranslation = stackTranslation; |
| 1479 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1480 | requestChildrenUpdate(); |
| 1481 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1485 | * 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] | 1486 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 1487 | * |
| 1488 | * @return either the layout height or the externally defined height, whichever is smaller |
| 1489 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1490 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1491 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1492 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 1493 | } |
| 1494 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1495 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1496 | public int getFirstItemMinHeight() { |
| 1497 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1498 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1501 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1502 | public void setQsContainer(ViewGroup qsContainer) { |
| 1503 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1504 | } |
| 1505 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1506 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1507 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1508 | if (v instanceof ExpandableNotificationRow) { |
| 1509 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1510 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1511 | } |
| 1512 | return false; |
| 1513 | } |
| 1514 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1515 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1516 | private boolean isHeadsUp(View v) { |
| 1517 | if (v instanceof ExpandableNotificationRow) { |
| 1518 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1519 | return row.isHeadsUp(); |
| 1520 | } |
| 1521 | return false; |
| 1522 | } |
| 1523 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1524 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1525 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 1526 | getLocationOnScreen(mTempInt2); |
| 1527 | float localTouchY = touchY - mTempInt2[1]; |
| 1528 | |
| 1529 | ExpandableView closestChild = null; |
| 1530 | float minDist = Float.MAX_VALUE; |
| 1531 | |
| 1532 | // find the view closest to the location, accounting for GONE views |
| 1533 | final int count = getChildCount(); |
| 1534 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 1535 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 1536 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1537 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1538 | continue; |
| 1539 | } |
| 1540 | float childTop = slidingChild.getTranslationY(); |
| 1541 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1542 | float bottom = childTop + slidingChild.getActualHeight() |
| 1543 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1544 | |
| 1545 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 1546 | if (dist < minDist) { |
| 1547 | closestChild = slidingChild; |
| 1548 | minDist = dist; |
| 1549 | } |
| 1550 | } |
| 1551 | return closestChild; |
| 1552 | } |
| 1553 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1554 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
| 1555 | private ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1556 | return getChildAtPosition(touchX, touchY, true /* requireMinHeight */); |
| 1557 | |
| 1558 | } |
| 1559 | |
| 1560 | /** |
| 1561 | * Get the child at a certain screen location. |
| 1562 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1563 | * @param touchX the x coordinate |
| 1564 | * @param touchY the y coordinate |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1565 | * @param requireMinHeight Whether a minimum height is required for a child to be returned. |
| 1566 | * @return the child at the given location. |
| 1567 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1568 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1569 | private ExpandableView getChildAtPosition(float touchX, float touchY, |
| 1570 | boolean requireMinHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1571 | // find the view under the pointer, accounting for GONE views |
| 1572 | final int count = getChildCount(); |
| 1573 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1574 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1575 | if (slidingChild.getVisibility() != VISIBLE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1576 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1577 | continue; |
| 1578 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 1579 | float childTop = slidingChild.getTranslationY(); |
| 1580 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1581 | float bottom = childTop + slidingChild.getActualHeight() |
| 1582 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 1583 | |
| 1584 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 1585 | // camera affordance). |
| 1586 | int left = 0; |
| 1587 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1588 | |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1589 | if ((bottom - top >= mMinInteractionHeight || !requireMinHeight) |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1590 | && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1591 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 1592 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1593 | NotificationEntry entry = row.getEntry(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1594 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1595 | && mHeadsUpManager.getTopEntry().getRow() != row |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1596 | && mGroupManager.getGroupSummary( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1597 | mHeadsUpManager.getTopEntry().notification) |
| 1598 | != entry) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1599 | continue; |
| 1600 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1601 | return row.getViewAtPosition(touchY - childTop); |
| 1602 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1603 | return slidingChild; |
| 1604 | } |
| 1605 | } |
| 1606 | return null; |
| 1607 | } |
| 1608 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1609 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1610 | getLocationOnScreen(mTempInt2); |
| 1611 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1614 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1615 | public void setScrollingEnabled(boolean enable) { |
| 1616 | mScrollingEnabled = enable; |
| 1617 | } |
| 1618 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1619 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1620 | public void lockScrollTo(View v) { |
| 1621 | if (mForcedScroll == v) { |
| 1622 | return; |
| 1623 | } |
| 1624 | mForcedScroll = v; |
| 1625 | scrollTo(v); |
| 1626 | } |
| 1627 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1628 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1629 | public boolean scrollTo(View v) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1630 | ExpandableView expandableView = (ExpandableView) v; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1631 | if (ANCHOR_SCROLLING) { |
| 1632 | // TODO |
| 1633 | } else { |
| 1634 | int positionInLinearLayout = getPositionInLinearLayout(v); |
| 1635 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
| 1636 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1637 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1638 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 1639 | // that it is not visible anymore. |
| 1640 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1641 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY); |
| 1642 | mDontReportNextOverScroll = true; |
| 1643 | animateScroll(); |
| 1644 | return true; |
| 1645 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1646 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1647 | return false; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1650 | /** |
| 1651 | * @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] | 1652 | * the IME. |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1653 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1654 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1655 | private int targetScrollForView(ExpandableView v, int positionInLinearLayout) { |
| 1656 | return positionInLinearLayout + v.getIntrinsicHeight() + |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 1657 | getImeInset() - getHeight() |
| 1658 | + ((!isExpanded() && isPinnedHeadsUp(v)) ? mHeadsUpInset : getTopPadding()); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1659 | } |
| 1660 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1661 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1662 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1663 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1664 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1665 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1666 | if (ANCHOR_SCROLLING) { |
| 1667 | // TODO |
| 1668 | } else { |
| 1669 | int range = getScrollRange(); |
| 1670 | if (mOwnScrollY > range) { |
| 1671 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1672 | // animating away. To work around that we'll wait until things have settled. |
| 1673 | removeCallbacks(mReclamp); |
| 1674 | postDelayed(mReclamp, 50); |
| 1675 | } else if (mForcedScroll != null) { |
| 1676 | // The scroll was requested before we got the actual inset - in case we need |
| 1677 | // to scroll up some more do so now. |
| 1678 | scrollTo(mForcedScroll); |
| 1679 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1680 | } |
| 1681 | return insets; |
| 1682 | } |
| 1683 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1684 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1685 | private Runnable mReclamp = new Runnable() { |
| 1686 | @Override |
| 1687 | public void run() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1688 | if (ANCHOR_SCROLLING) { |
| 1689 | // TODO |
| 1690 | } else { |
| 1691 | int range = getScrollRange(); |
| 1692 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1693 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1694 | mDontReportNextOverScroll = true; |
| 1695 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1696 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1697 | } |
| 1698 | }; |
| 1699 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1700 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 1701 | public void setExpandingEnabled(boolean enable) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1702 | mExpandHelper.setEnabled(enable); |
| 1703 | } |
| 1704 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1705 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1706 | private boolean isScrollingEnabled() { |
| 1707 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1710 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1711 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1712 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1713 | } |
| 1714 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1715 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1716 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1717 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1718 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1719 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1720 | float densityScale = getResources().getDisplayMetrics().density; |
| 1721 | mSwipeHelper.setDensityScale(densityScale); |
| 1722 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1723 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1724 | initView(getContext()); |
| 1725 | } |
| 1726 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1727 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1728 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1729 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1730 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1731 | } |
| 1732 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1733 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1734 | private void snapViewIfNeeded(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1735 | ExpandableNotificationRow child = entry.getRow(); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1736 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1737 | // If the child is showing the notification menu snap to that |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 1738 | if (child.getProvider() != null) { |
| 1739 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
| 1740 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
| 1741 | } |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1742 | } |
| 1743 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1744 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1745 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1746 | public ViewGroup getViewParentForNotification(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1747 | return this; |
| 1748 | } |
| 1749 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1750 | /** |
| 1751 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1752 | * |
| 1753 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1754 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1755 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1756 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1757 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1758 | private float overScrollUp(int deltaY, int range) { |
| 1759 | deltaY = Math.max(deltaY, 0); |
| 1760 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1761 | float newTopAmount = currentTopAmount - deltaY; |
| 1762 | if (currentTopAmount > 0) { |
| 1763 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1764 | false /* animate */); |
| 1765 | } |
| 1766 | // Top overScroll might not grab all scrolling motion, |
| 1767 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1768 | if (ANCHOR_SCROLLING) { |
| 1769 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1770 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1771 | ExpandableView lastRow = getLastRowNotGone(); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1772 | if (lastRow != null && !lastRow.isInShelf()) { |
| 1773 | float distanceToMax = Math.max(0, getMaxPositiveScrollAmount()); |
| 1774 | if (scrollAmount > distanceToMax) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1775 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1776 | // We overScroll on the bottom |
| 1777 | setOverScrolledPixels(currentBottomPixels + (scrollAmount - distanceToMax), |
| 1778 | false /* onTop */, |
| 1779 | false /* animate */); |
| 1780 | mScrollAnchorViewY -= distanceToMax; |
| 1781 | scrollAmount = 0f; |
| 1782 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1783 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1784 | return scrollAmount; |
| 1785 | } else { |
| 1786 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1787 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1788 | if (newScrollY > range) { |
| 1789 | if (!mExpandedInThisMotion) { |
| 1790 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1791 | // We overScroll on the bottom |
| 1792 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1793 | false /* onTop */, |
| 1794 | false /* animate */); |
| 1795 | } |
| 1796 | setOwnScrollY(range); |
| 1797 | scrollAmount = 0.0f; |
| 1798 | } |
| 1799 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1800 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | /** |
| 1804 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1805 | * |
| 1806 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1807 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1808 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1809 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1810 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1811 | private float overScrollDown(int deltaY) { |
| 1812 | deltaY = Math.min(deltaY, 0); |
| 1813 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1814 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1815 | if (currentBottomAmount > 0) { |
| 1816 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1817 | false /* animate */); |
| 1818 | } |
| 1819 | // Bottom overScroll might not grab all scrolling motion, |
| 1820 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1821 | if (ANCHOR_SCROLLING) { |
| 1822 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1823 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1824 | ExpandableView firstChild = getFirstChildNotGone(); |
| 1825 | float top = firstChild.getTranslationY(); |
| 1826 | float distanceToTop = mScrollAnchorView.getTranslationY() - top - mScrollAnchorViewY; |
| 1827 | if (distanceToTop < -scrollAmount) { |
| 1828 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1829 | // We overScroll on the top |
| 1830 | setOverScrolledPixels(currentTopPixels + (-scrollAmount - distanceToTop), |
| 1831 | true /* onTop */, |
| 1832 | false /* animate */); |
| 1833 | mScrollAnchorView = firstChild; |
| 1834 | mScrollAnchorViewY = 0; |
| 1835 | scrollAmount = 0f; |
| 1836 | } |
| 1837 | return scrollAmount; |
| 1838 | } else { |
| 1839 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1840 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1841 | if (newScrollY < 0) { |
| 1842 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1843 | // We overScroll on the top |
| 1844 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1845 | true /* onTop */, |
| 1846 | false /* animate */); |
| 1847 | setOwnScrollY(0); |
| 1848 | scrollAmount = 0.0f; |
| 1849 | } |
| 1850 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1851 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1852 | } |
| 1853 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1854 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1855 | private void initVelocityTrackerIfNotExists() { |
| 1856 | if (mVelocityTracker == null) { |
| 1857 | mVelocityTracker = VelocityTracker.obtain(); |
| 1858 | } |
| 1859 | } |
| 1860 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1861 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1862 | private void recycleVelocityTracker() { |
| 1863 | if (mVelocityTracker != null) { |
| 1864 | mVelocityTracker.recycle(); |
| 1865 | mVelocityTracker = null; |
| 1866 | } |
| 1867 | } |
| 1868 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1869 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1870 | private void initOrResetVelocityTracker() { |
| 1871 | if (mVelocityTracker == null) { |
| 1872 | mVelocityTracker = VelocityTracker.obtain(); |
| 1873 | } else { |
| 1874 | mVelocityTracker.clear(); |
| 1875 | } |
| 1876 | } |
| 1877 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1878 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1879 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1880 | mFinishScrollingCallback = runnable; |
| 1881 | } |
| 1882 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1883 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1884 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1885 | if (mScroller.computeScrollOffset()) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1886 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1887 | int oldY = mLastScrollerY; |
| 1888 | int y = mScroller.getCurrY(); |
| 1889 | int deltaY = y - oldY; |
| 1890 | if (deltaY != 0) { |
| 1891 | int maxNegativeScrollAmount = getMaxNegativeScrollAmount(); |
| 1892 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 1893 | if ((maxNegativeScrollAmount < 0 && deltaY < maxNegativeScrollAmount) |
| 1894 | || (maxPositiveScrollAmount > 0 && deltaY > maxPositiveScrollAmount)) { |
| 1895 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1896 | // the current velocity |
| 1897 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1898 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1899 | customOverScrollBy(deltaY, oldY, 0, (int) mMaxOverScroll); |
| 1900 | mLastScrollerY = y; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1901 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1902 | } else { |
| 1903 | int oldY = mOwnScrollY; |
| 1904 | int y = mScroller.getCurrY(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1905 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1906 | if (oldY != y) { |
| 1907 | int range = getScrollRange(); |
| 1908 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1909 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1910 | // the current velocity |
| 1911 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1912 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1913 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1914 | if (mDontClampNextScroll) { |
| 1915 | range = Math.max(range, oldY); |
| 1916 | } |
| 1917 | customOverScrollBy(y - oldY, oldY, range, |
| 1918 | (int) (mMaxOverScroll)); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1919 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1920 | } |
| 1921 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1922 | postOnAnimation(mReflingAndAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1923 | } else { |
| 1924 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1925 | if (mFinishScrollingCallback != null) { |
| 1926 | mFinishScrollingCallback.run(); |
| 1927 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1931 | private void setMaxOverScrollFromCurrentVelocity() { |
| 1932 | float currVelocity = mScroller.getCurrVelocity(); |
| 1933 | if (currVelocity >= mMinimumVelocity) { |
| 1934 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1935 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1936 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1937 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1938 | /** |
| 1939 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 1940 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 1941 | * |
| 1942 | * This method performs the determination of whether we're exceeding the overscroll and clamps |
| 1943 | * the scroll amount if so. The actual scrolling/overscrolling happens in |
| 1944 | * {@link #onCustomOverScrolled(int, boolean)} (absolute scrolling) or |
| 1945 | * {@link #onCustomOverScrolledBy(int, boolean)} (anchor scrolling). |
| 1946 | * |
| 1947 | * @param deltaY The (signed) number of pixels to scroll. |
| 1948 | * @param scrollY The current scroll position (absolute scrolling only). |
| 1949 | * @param scrollRangeY The maximum allowable scroll position (absolute scrolling only). |
| 1950 | * @param maxOverScrollY The current (unsigned) limit on number of pixels to overscroll by. |
| 1951 | */ |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1952 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1953 | private void customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, int maxOverScrollY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1954 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1955 | boolean clampedY = false; |
| 1956 | if (deltaY < 0) { |
| 1957 | int maxScrollAmount = getMaxNegativeScrollAmount(); |
| 1958 | if (maxScrollAmount > Integer.MIN_VALUE) { |
| 1959 | maxScrollAmount -= maxOverScrollY; |
| 1960 | if (deltaY < maxScrollAmount) { |
| 1961 | deltaY = maxScrollAmount; |
| 1962 | clampedY = true; |
| 1963 | } |
| 1964 | } |
| 1965 | } else { |
| 1966 | int maxScrollAmount = getMaxPositiveScrollAmount(); |
| 1967 | if (maxScrollAmount < Integer.MAX_VALUE) { |
| 1968 | maxScrollAmount += maxOverScrollY; |
| 1969 | if (deltaY > maxScrollAmount) { |
| 1970 | deltaY = maxScrollAmount; |
| 1971 | clampedY = true; |
| 1972 | } |
| 1973 | } |
| 1974 | } |
| 1975 | onCustomOverScrolledBy(deltaY, clampedY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1976 | } else { |
| 1977 | int newScrollY = scrollY + deltaY; |
| 1978 | final int top = -maxOverScrollY; |
| 1979 | final int bottom = maxOverScrollY + scrollRangeY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1980 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1981 | boolean clampedY = false; |
| 1982 | if (newScrollY > bottom) { |
| 1983 | newScrollY = bottom; |
| 1984 | clampedY = true; |
| 1985 | } else if (newScrollY < top) { |
| 1986 | newScrollY = top; |
| 1987 | clampedY = true; |
| 1988 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1989 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1990 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1991 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /** |
| 1995 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1996 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1997 | * same overScroll edge. |
| 1998 | * |
| 1999 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 2000 | * the rubber-banding logic. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2001 | * @param onTop Should the effect be applied on top of the scroller. |
| 2002 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2003 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2004 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2005 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2006 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | /** |
| 2010 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2011 | * By default this will also cancel animations on the same overScroll edge. |
| 2012 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2013 | * @param amount The amount to overScroll by. |
| 2014 | * @param onTop Should the effect be applied on top of the scroller. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2015 | * @param animate Should an animation be performed. |
| 2016 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2017 | |
| 2018 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2019 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 2020 | setOverScrollAmount(amount, onTop, animate, true); |
| 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2025 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2026 | * @param amount The amount to overScroll by. |
| 2027 | * @param onTop Should the effect be applied on top of the scroller. |
| 2028 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2029 | * @param cancelAnimators Should running animations be cancelled. |
| 2030 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2031 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2032 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2033 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2034 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 2035 | } |
| 2036 | |
| 2037 | /** |
| 2038 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2039 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2040 | * @param amount The amount to overScroll by. |
| 2041 | * @param onTop Should the effect be applied on top of the scroller. |
| 2042 | * @param animate Should an animation be performed. |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2043 | * @param cancelAnimators Should running animations be cancelled. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2044 | * @param isRubberbanded The value which will be passed to |
| 2045 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2046 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2047 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2048 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2049 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2050 | if (cancelAnimators) { |
| 2051 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 2052 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2053 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2054 | } |
| 2055 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2056 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2057 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 2058 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2059 | amount = Math.max(0, amount); |
| 2060 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2061 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2062 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2063 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2064 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2065 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2066 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2067 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2068 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2072 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2073 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2074 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 2075 | if (mDontReportNextOverScroll) { |
| 2076 | mDontReportNextOverScroll = false; |
| 2077 | return; |
| 2078 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2079 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2080 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2081 | } |
| 2082 | } |
| 2083 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2084 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2085 | public void setOverscrollTopChangedListener( |
| 2086 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 2087 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 2088 | } |
| 2089 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2090 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2091 | public float getCurrentOverScrollAmount(boolean top) { |
| 2092 | return mAmbientState.getOverScrollAmount(top); |
| 2093 | } |
| 2094 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2095 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2096 | public float getCurrentOverScrolledPixels(boolean top) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2097 | return top ? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2098 | } |
| 2099 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2100 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2101 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2102 | if (onTop) { |
| 2103 | mOverScrolledTopPixels = amount; |
| 2104 | } else { |
| 2105 | mOverScrolledBottomPixels = amount; |
| 2106 | } |
| 2107 | } |
| 2108 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2109 | /** |
| 2110 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 2111 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 2112 | * |
| 2113 | * @param deltaY The (signed) number of pixels to scroll. |
| 2114 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2115 | * the overscroll limit. |
| 2116 | */ |
| 2117 | private void onCustomOverScrolledBy(int deltaY, boolean clampedY) { |
| 2118 | assert ANCHOR_SCROLLING; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2119 | mScrollAnchorViewY -= deltaY; |
| 2120 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2121 | if (!mScroller.isFinished()) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2122 | if (clampedY) { |
| 2123 | springBack(); |
| 2124 | } else { |
| 2125 | float overScrollTop = getCurrentOverScrollAmount(true /* top */); |
| 2126 | if (isScrolledToTop() && mScrollAnchorViewY > 0) { |
| 2127 | notifyOverscrollTopListener(mScrollAnchorViewY, |
| 2128 | isRubberbanded(true /* onTop */)); |
| 2129 | } else { |
| 2130 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true /* onTop */)); |
| 2131 | } |
| 2132 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2133 | } |
| 2134 | updateScrollAnchor(); |
| 2135 | updateOnScrollChange(); |
| 2136 | } |
| 2137 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2138 | /** |
| 2139 | * Scrolls to the given position, overscrolling if needed. If called during a fling and the |
| 2140 | * position exceeds the provided maximum overscroll, springs back instead. |
| 2141 | * |
| 2142 | * @param scrollY The target scroll position. |
| 2143 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2144 | * the overscroll limit. |
| 2145 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2146 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2147 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2148 | assert !ANCHOR_SCROLLING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2149 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2150 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2151 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2152 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2153 | springBack(); |
| 2154 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2155 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2156 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2157 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2158 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2159 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2160 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2161 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2162 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2163 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2164 | } |
| 2165 | } |
| 2166 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2167 | /** |
| 2168 | * Springs back from an overscroll by stopping the {@link #mScroller} and animating the |
| 2169 | * overscroll amount back to zero. |
| 2170 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2171 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2172 | private void springBack() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2173 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2174 | boolean overScrolledTop = isScrolledToTop() && mScrollAnchorViewY > 0; |
| 2175 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 2176 | boolean overscrolledBottom = maxPositiveScrollAmount < 0; |
| 2177 | if (overScrolledTop || overscrolledBottom) { |
| 2178 | float newAmount; |
| 2179 | if (overScrolledTop) { |
| 2180 | newAmount = mScrollAnchorViewY; |
| 2181 | mScrollAnchorViewY = 0; |
| 2182 | mDontReportNextOverScroll = true; |
| 2183 | } else { |
| 2184 | newAmount = -maxPositiveScrollAmount; |
| 2185 | mScrollAnchorViewY -= maxPositiveScrollAmount; |
| 2186 | } |
| 2187 | setOverScrollAmount(newAmount, overScrolledTop, false); |
| 2188 | setOverScrollAmount(0.0f, overScrolledTop, true); |
| 2189 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2190 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2191 | } else { |
| 2192 | int scrollRange = getScrollRange(); |
| 2193 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2194 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2195 | if (overScrolledTop || overScrolledBottom) { |
| 2196 | boolean onTop; |
| 2197 | float newAmount; |
| 2198 | if (overScrolledTop) { |
| 2199 | onTop = true; |
| 2200 | newAmount = -mOwnScrollY; |
| 2201 | setOwnScrollY(0); |
| 2202 | mDontReportNextOverScroll = true; |
| 2203 | } else { |
| 2204 | onTop = false; |
| 2205 | newAmount = mOwnScrollY - scrollRange; |
| 2206 | setOwnScrollY(scrollRange); |
| 2207 | } |
| 2208 | setOverScrollAmount(newAmount, onTop, false); |
| 2209 | setOverScrollAmount(0.0f, onTop, true); |
| 2210 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2211 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2212 | } |
| 2213 | } |
| 2214 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2215 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2216 | private int getScrollRange() { |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2217 | // In current design, it only use the top HUN to treat all of HUNs |
| 2218 | // although there are more than one HUNs |
| 2219 | int contentHeight = mContentHeight; |
| 2220 | if (!isExpanded() && mHeadsUpManager.hasPinnedHeadsUp()) { |
| 2221 | contentHeight = mHeadsUpInset + getTopHeadsUpPinnedHeight(); |
| 2222 | } |
| 2223 | int scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2224 | int imeInset = getImeInset(); |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2225 | scrollRange += Math.min(imeInset, Math.max(0, contentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2226 | return scrollRange; |
| 2227 | } |
| 2228 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2229 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2230 | private int getImeInset() { |
| 2231 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2232 | } |
| 2233 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2234 | /** |
| 2235 | * @return the first child which has visibility unequal to GONE |
| 2236 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2237 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2238 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2239 | int childCount = getChildCount(); |
| 2240 | for (int i = 0; i < childCount; i++) { |
| 2241 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2242 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2243 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | return null; |
| 2247 | } |
| 2248 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2249 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2250 | * @return the child before the given view which has visibility unequal to GONE |
| 2251 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2252 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2253 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2254 | ExpandableView previousView = null; |
| 2255 | int childCount = getChildCount(); |
| 2256 | for (int i = 0; i < childCount; i++) { |
| 2257 | View child = getChildAt(i); |
| 2258 | if (child == view) { |
| 2259 | return previousView; |
| 2260 | } |
| 2261 | if (child.getVisibility() != View.GONE) { |
| 2262 | previousView = (ExpandableView) child; |
| 2263 | } |
| 2264 | } |
| 2265 | return null; |
| 2266 | } |
| 2267 | |
| 2268 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2269 | * @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] | 2270 | * given translationY or equal to it. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2271 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2272 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2273 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2274 | int childCount = getChildCount(); |
| 2275 | for (int i = 0; i < childCount; i++) { |
| 2276 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2277 | if (child.getVisibility() == View.GONE) { |
| 2278 | continue; |
| 2279 | } |
| 2280 | float rowTranslation = child.getTranslationY(); |
| 2281 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2282 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2283 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2284 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2285 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2286 | List<ExpandableNotificationRow> notificationChildren = |
| 2287 | row.getNotificationChildren(); |
| 2288 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2289 | childIndex++) { |
| 2290 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2291 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2292 | return rowChild; |
| 2293 | } |
| 2294 | } |
| 2295 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2296 | } |
| 2297 | } |
| 2298 | return null; |
| 2299 | } |
| 2300 | |
| 2301 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2302 | * @return the last child which has visibility unequal to GONE |
| 2303 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2304 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2305 | public ExpandableView getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2306 | int childCount = getChildCount(); |
| 2307 | for (int i = childCount - 1; i >= 0; i--) { |
| 2308 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2309 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2310 | return (ExpandableView) child; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | return null; |
| 2314 | } |
| 2315 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2316 | private ExpandableNotificationRow getLastRowNotGone() { |
| 2317 | int childCount = getChildCount(); |
| 2318 | for (int i = childCount - 1; i >= 0; i--) { |
| 2319 | View child = getChildAt(i); |
| 2320 | if (child instanceof ExpandableNotificationRow && child.getVisibility() != View.GONE) { |
| 2321 | return (ExpandableNotificationRow) child; |
| 2322 | } |
| 2323 | } |
| 2324 | return null; |
| 2325 | } |
| 2326 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2327 | /** |
| 2328 | * @return the number of children which have visibility unequal to GONE |
| 2329 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2330 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2331 | public int getNotGoneChildCount() { |
| 2332 | int childCount = getChildCount(); |
| 2333 | int count = 0; |
| 2334 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2335 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2336 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2337 | count++; |
| 2338 | } |
| 2339 | } |
| 2340 | return count; |
| 2341 | } |
| 2342 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2343 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2344 | private void updateContentHeight() { |
| 2345 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2346 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2347 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2348 | int numShownItems = 0; |
| 2349 | boolean finish = false; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2350 | int maxDisplayedNotifications = mMaxDisplayedNotifications; |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2351 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2352 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2353 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2354 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2355 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2356 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2357 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2358 | && numShownItems >= maxDisplayedNotifications; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2359 | if (limitReached) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2360 | expandableView = mShelf; |
| 2361 | finish = true; |
| 2362 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2363 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2364 | float padding; |
| 2365 | if (increasedPaddingAmount >= 0.0f) { |
| 2366 | padding = (int) NotificationUtils.interpolate( |
| 2367 | previousPaddingRequest, |
| 2368 | mIncreasedPaddingBetweenElements, |
| 2369 | increasedPaddingAmount); |
| 2370 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2371 | mPaddingBetweenElements, |
| 2372 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2373 | increasedPaddingAmount); |
| 2374 | } else { |
| 2375 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2376 | 0, |
| 2377 | mPaddingBetweenElements, |
| 2378 | 1.0f + increasedPaddingAmount); |
| 2379 | if (previousPaddingAmount > 0.0f) { |
| 2380 | padding = (int) NotificationUtils.interpolate( |
| 2381 | ownPadding, |
| 2382 | mIncreasedPaddingBetweenElements, |
| 2383 | previousPaddingAmount); |
| 2384 | } else { |
| 2385 | padding = ownPadding; |
| 2386 | } |
| 2387 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2388 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2389 | if (height != 0) { |
| 2390 | height += padding; |
| 2391 | } |
| 2392 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2393 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2394 | numShownItems++; |
| 2395 | if (finish) { |
| 2396 | break; |
| 2397 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2398 | } |
| 2399 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2400 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2401 | |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 2402 | mContentHeight = height + mTopPadding + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2403 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2404 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2405 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2408 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2409 | private boolean isPulsing(NotificationEntry entry) { |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 2410 | return mAmbientState.isPulsing(entry); |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2413 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2414 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2415 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2416 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2419 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2420 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2421 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2422 | if (scrollable != mScrollable) { |
| 2423 | mScrollable = scrollable; |
| 2424 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2425 | updateForwardAndBackwardScrollability(); |
| 2426 | } |
| 2427 | } |
| 2428 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2429 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2430 | private void updateForwardAndBackwardScrollability() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2431 | boolean forwardScrollable = mScrollable && !isScrolledToBottom(); |
| 2432 | boolean backwardsScrollable = mScrollable && !isScrolledToTop(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2433 | boolean changed = forwardScrollable != mForwardScrollable |
| 2434 | || backwardsScrollable != mBackwardScrollable; |
| 2435 | mForwardScrollable = forwardScrollable; |
| 2436 | mBackwardScrollable = backwardsScrollable; |
| 2437 | if (changed) { |
| 2438 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2439 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2440 | } |
| 2441 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2442 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2443 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2444 | // 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] | 2445 | if (!mShouldDrawNotificationBackground || mAmbientState.isFullyDark()) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2446 | return; |
| 2447 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2448 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2449 | updateBackgroundBounds(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2450 | if (didSectionBoundsChange()) { |
| 2451 | boolean animate = mAnimateNextSectionBoundsChange || mAnimateNextBackgroundTop |
| 2452 | || mAnimateNextBackgroundBottom || areSectionBoundsAnimating(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2453 | if (!isExpanded()) { |
| 2454 | abortBackgroundAnimators(); |
| 2455 | animate = false; |
| 2456 | } |
| 2457 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2458 | startBackgroundAnimation(); |
| 2459 | } else { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2460 | for (NotificationSection section : mSections) { |
| 2461 | section.resetCurrentBounds(); |
| 2462 | } |
Lucas Dupin | 90a38dd | 2018-09-05 09:37:37 -0700 | [diff] [blame] | 2463 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2464 | } |
| 2465 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2466 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2467 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2468 | mAnimateNextBackgroundTop = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2469 | mAnimateNextBackgroundBottom = false; |
| 2470 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2471 | } |
| 2472 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2473 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2474 | private void abortBackgroundAnimators() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2475 | for (NotificationSection section : mSections) { |
| 2476 | section.cancelAnimators(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2480 | private boolean didSectionBoundsChange() { |
| 2481 | for (NotificationSection section : mSections) { |
| 2482 | if (section.didBoundsChange()) { |
| 2483 | return true; |
| 2484 | } |
| 2485 | } |
| 2486 | return false; |
| 2487 | } |
| 2488 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2489 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2490 | private boolean areSectionBoundsAnimating() { |
| 2491 | for (NotificationSection section : mSections) { |
| 2492 | if (section.areBoundsAnimating()) { |
| 2493 | return true; |
| 2494 | } |
| 2495 | } |
| 2496 | return false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2497 | } |
| 2498 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2499 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2500 | private void startBackgroundAnimation() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2501 | // TODO(kprevas): do we still need separate fields for top/bottom? |
| 2502 | // or can each section manage its own animation state? |
| 2503 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2504 | NotificationSection lastVisibleSection = getLastVisibleSection(); |
| 2505 | for (NotificationSection section : mSections) { |
| 2506 | section.startBackgroundAnimation( |
| 2507 | section == firstVisibleSection |
| 2508 | ? mAnimateNextBackgroundTop |
| 2509 | : mAnimateNextSectionBoundsChange, |
| 2510 | section == lastVisibleSection |
| 2511 | ? mAnimateNextBackgroundBottom |
| 2512 | : mAnimateNextSectionBoundsChange); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2513 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | /** |
| 2517 | * Update the background bounds to the new desired bounds |
| 2518 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2519 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2520 | private void updateBackgroundBounds() { |
shawnlin | 2771672 | 2019-04-17 20:09:45 +0800 | [diff] [blame] | 2521 | int left = mSidePaddings; |
| 2522 | int right = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2523 | for (NotificationSection section : mSections) { |
| 2524 | section.getBounds().left = left; |
| 2525 | section.getBounds().right = right; |
| 2526 | } |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2527 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2528 | if (!mIsExpanded) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2529 | for (NotificationSection section : mSections) { |
| 2530 | section.getBounds().top = 0; |
| 2531 | section.getBounds().bottom = 0; |
| 2532 | } |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2533 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2534 | } |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2535 | int minTopPosition = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2536 | NotificationSection lastSection = getLastVisibleSection(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 2537 | if (mStatusBarState != StatusBarState.KEYGUARD) { |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2538 | minTopPosition = (int) (mTopPadding + mStackTranslation); |
| 2539 | } else if (lastSection == null) { |
| 2540 | minTopPosition = mTopPadding; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2541 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2542 | boolean shiftPulsingWithFirst = mAmbientPulseManager.getAllEntries().count() <= 1; |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2543 | for (NotificationSection section : mSections) { |
| 2544 | int minBottomPosition = minTopPosition; |
| 2545 | if (section == lastSection) { |
| 2546 | // 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] | 2547 | minBottomPosition = (int) (ViewState.getFinalTranslationY(mShelf) |
| 2548 | + mShelf.getIntrinsicHeight()); |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2549 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2550 | minTopPosition = section.updateBounds(minTopPosition, minBottomPosition, |
| 2551 | shiftPulsingWithFirst); |
| 2552 | shiftPulsingWithFirst = false; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2553 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2554 | } |
| 2555 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2556 | private NotificationSection getFirstVisibleSection() { |
| 2557 | for (NotificationSection section : mSections) { |
| 2558 | if (section.getFirstVisibleChild() != null) { |
| 2559 | return section; |
| 2560 | } |
| 2561 | } |
| 2562 | return null; |
| 2563 | } |
| 2564 | |
| 2565 | private NotificationSection getLastVisibleSection() { |
| 2566 | for (int i = mSections.length - 1; i >= 0; i--) { |
| 2567 | NotificationSection section = mSections[i]; |
| 2568 | if (section.getLastVisibleChild() != null) { |
| 2569 | return section; |
| 2570 | } |
| 2571 | } |
| 2572 | return null; |
| 2573 | } |
| 2574 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2575 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2576 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2577 | int childCount = getChildCount(); |
| 2578 | for (int i = childCount - 1; i >= 0; i--) { |
| 2579 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2580 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2581 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2582 | return (ActivatableNotificationView) child; |
| 2583 | } |
| 2584 | } |
| 2585 | return null; |
| 2586 | } |
| 2587 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2588 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2589 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2590 | int childCount = getChildCount(); |
| 2591 | for (int i = 0; i < childCount; i++) { |
| 2592 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2593 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2594 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2595 | return (ActivatableNotificationView) child; |
| 2596 | } |
| 2597 | } |
| 2598 | return null; |
| 2599 | } |
| 2600 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2601 | /** |
| 2602 | * Fling the scroll view |
| 2603 | * |
| 2604 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2605 | * numbers mean that the finger/cursor is moving down the screen, |
| 2606 | * which means we want to scroll towards the top. |
| 2607 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2608 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2609 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2610 | if (getChildCount() > 0) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2611 | float topAmount = getCurrentOverScrollAmount(true); |
| 2612 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2613 | if (velocityY < 0 && topAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2614 | if (ANCHOR_SCROLLING) { |
| 2615 | mScrollAnchorViewY += topAmount; |
| 2616 | } else { |
| 2617 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
| 2618 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2619 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2620 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2621 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2622 | * mOverflingDistance + topAmount; |
| 2623 | } else if (velocityY > 0 && bottomAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2624 | if (ANCHOR_SCROLLING) { |
| 2625 | mScrollAnchorViewY -= bottomAmount; |
| 2626 | } else { |
| 2627 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
| 2628 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2629 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2630 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2631 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2632 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2633 | } else { |
| 2634 | // it will be set once we reach the boundary |
| 2635 | mMaxOverScroll = 0.0f; |
| 2636 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2637 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2638 | flingScroller(velocityY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2639 | } else { |
| 2640 | int scrollRange = getScrollRange(); |
| 2641 | int minScrollY = Math.max(0, scrollRange); |
| 2642 | if (mExpandedInThisMotion) { |
| 2643 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2644 | } |
| 2645 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2646 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2647 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2648 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2649 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2653 | /** |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2654 | * Flings the overscroller with the given velocity (anchor-based scrolling). |
| 2655 | * |
| 2656 | * Because anchor-based scrolling can't track the current scroll position, the overscroller is |
| 2657 | * always started at startY = 0, and we interpret the positions it computes as relative to the |
| 2658 | * start of the scroll. |
| 2659 | */ |
| 2660 | private void flingScroller(int velocityY) { |
| 2661 | assert ANCHOR_SCROLLING; |
| 2662 | mIsScrollerBoundSet = false; |
| 2663 | maybeFlingScroller(velocityY, true /* always fling */); |
| 2664 | } |
| 2665 | |
| 2666 | private void maybeFlingScroller(int velocityY, boolean alwaysFling) { |
| 2667 | assert ANCHOR_SCROLLING; |
| 2668 | // Attempt to determine the maximum amount to scroll before we reach the end. |
| 2669 | // If the first view is not materialized (for an upwards scroll) or the last view is either |
| 2670 | // not materialized or is pinned to the shade (for a downwards scroll), we don't know this |
| 2671 | // amount, so we do an unbounded fling and rely on {@link #maybeReflingScroller()} to update |
| 2672 | // the scroller once we approach the start/end of the list. |
| 2673 | int minY = Integer.MIN_VALUE; |
| 2674 | int maxY = Integer.MAX_VALUE; |
| 2675 | if (velocityY < 0) { |
| 2676 | minY = getMaxNegativeScrollAmount(); |
| 2677 | if (minY > Integer.MIN_VALUE) { |
| 2678 | mIsScrollerBoundSet = true; |
| 2679 | } |
| 2680 | } else { |
| 2681 | maxY = getMaxPositiveScrollAmount(); |
| 2682 | if (maxY < Integer.MAX_VALUE) { |
| 2683 | mIsScrollerBoundSet = true; |
| 2684 | } |
| 2685 | } |
| 2686 | if (mIsScrollerBoundSet || alwaysFling) { |
| 2687 | mLastScrollerY = 0; |
| 2688 | // x velocity is set to 1 to avoid overscroller bug |
| 2689 | mScroller.fling(0, 0, 1, velocityY, 0, 0, minY, maxY, 0, |
| 2690 | mExpandedInThisMotion && !isScrolledToTop() ? 0 : Integer.MAX_VALUE / 2); |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | /** |
| 2695 | * Returns the maximum number of pixels we can scroll in the positive direction (downwards) |
| 2696 | * before reaching the bottom of the list (discounting overscroll). |
| 2697 | * |
| 2698 | * If the return value is negative then we have overscrolled; this is a transient state which |
| 2699 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2700 | * the bottom overscroll amount. |
| 2701 | * |
| 2702 | * If we don't know how many pixels we have left to scroll (because the last row has not been |
| 2703 | * materialized, or it's in the shelf so it doesn't have its "natural" position), we return |
| 2704 | * {@link Integer#MAX_VALUE}. |
| 2705 | */ |
| 2706 | private int getMaxPositiveScrollAmount() { |
| 2707 | assert ANCHOR_SCROLLING; |
| 2708 | // TODO: once we're recycling we need to check the adapter position of the last child. |
| 2709 | ExpandableNotificationRow lastRow = getLastRowNotGone(); |
| 2710 | if (mScrollAnchorView != null && lastRow != null && !lastRow.isInShelf()) { |
| 2711 | // distance from bottom of last child to bottom of notifications area is: |
| 2712 | // distance from bottom of last child |
| 2713 | return (int) (lastRow.getTranslationY() + lastRow.getActualHeight() |
| 2714 | // to top of anchor view |
| 2715 | - mScrollAnchorView.getTranslationY() |
| 2716 | // plus distance from anchor view to top of notifications area |
| 2717 | + mScrollAnchorViewY |
| 2718 | // minus height of notifications area. |
| 2719 | - (mMaxLayoutHeight - getIntrinsicPadding() - mFooterView.getActualHeight())); |
| 2720 | } else { |
| 2721 | return Integer.MAX_VALUE; |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * Returns the maximum number of pixels (as a negative number) we can scroll in the negative |
| 2727 | * direction (upwards) before reaching the top of the list (discounting overscroll). |
| 2728 | * |
| 2729 | * If the return value is positive then we have overscrolled; this is a transient state which |
| 2730 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2731 | * the top overscroll amount. |
| 2732 | * |
| 2733 | * If we don't know how many pixels we have left to scroll (because the first row has not been |
| 2734 | * materialized), we return {@link Integer#MIN_VALUE}. |
| 2735 | */ |
| 2736 | private int getMaxNegativeScrollAmount() { |
| 2737 | assert ANCHOR_SCROLLING; |
| 2738 | // TODO: once we're recycling we need to check the adapter position of the first child. |
| 2739 | ExpandableView firstChild = getFirstChildNotGone(); |
| 2740 | if (mScrollAnchorView != null && firstChild != null) { |
| 2741 | // distance from top of first child to top of notifications area is: |
| 2742 | // distance from top of anchor view |
| 2743 | return (int) -(mScrollAnchorView.getTranslationY() |
| 2744 | // to top of first child |
| 2745 | - firstChild.getTranslationY() |
| 2746 | // minus distance from top of anchor view to top of notifications area. |
| 2747 | - mScrollAnchorViewY); |
| 2748 | } else { |
| 2749 | return Integer.MIN_VALUE; |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | /** |
| 2754 | * During a fling, if we were unable to set the bounds of the fling due to the top/bottom view |
| 2755 | * not being materialized or being pinned to the shelf, we need to check on every frame if we're |
| 2756 | * able to set the bounds. If we are, we fling the scroller again with the newly computed |
| 2757 | * bounds. |
| 2758 | */ |
| 2759 | private void maybeReflingScroller() { |
| 2760 | if (!mIsScrollerBoundSet) { |
| 2761 | // Because mScroller is a flywheel scroller, we fling with the minimum possible |
| 2762 | // velocity to establish direction, so as not to perceptibly affect the velocity. |
| 2763 | maybeFlingScroller((int) Math.signum(mScroller.getCurrVelocity()), |
| 2764 | false /* alwaysFling */); |
| 2765 | } |
| 2766 | } |
| 2767 | |
| 2768 | /** |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2769 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2770 | * overScroll view (i.e QS). |
| 2771 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2772 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2773 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2774 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2775 | return mScrolledToTopOnFirstDown |
| 2776 | && !mExpandedInThisMotion |
| 2777 | && topOverScroll > mMinTopOverScrollToEscape |
| 2778 | && initialVelocity > 0; |
| 2779 | } |
| 2780 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2781 | /** |
| 2782 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2783 | * account. |
| 2784 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2785 | * @param qsHeight the top padding imposed by the quick settings panel |
| 2786 | * @param animate whether to animate the change |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2787 | * @param ignoreIntrinsicPadding if true, {@link #getIntrinsicPadding()} is ignored and |
| 2788 | * {@code qsHeight} is the final top padding |
| 2789 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2790 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 2791 | public void updateTopPadding(float qsHeight, boolean animate, |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2792 | boolean ignoreIntrinsicPadding) { |
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 | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2800 | setTopPadding(ignoreIntrinsicPadding ? topPadding : clampPadding(topPadding), |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2801 | animate); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2802 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2803 | } |
| 2804 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2805 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2806 | public void setMaxTopPadding(int maxTopPadding) { |
| 2807 | mMaxTopPadding = maxTopPadding; |
| 2808 | } |
| 2809 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2810 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2811 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2812 | if (isHeadsUpTransition()) { |
| 2813 | return getTopHeadsUpPinnedHeight(); |
| 2814 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2815 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2816 | } |
| 2817 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2818 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2819 | public float getTopPaddingOverflow() { |
| 2820 | return mTopPaddingOverflow; |
| 2821 | } |
| 2822 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2823 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2824 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2825 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2826 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2827 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2828 | int shelfHeight = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2829 | if (getLastVisibleSection() != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2830 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2831 | } |
| 2832 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2833 | } |
| 2834 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2835 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2836 | private int clampPadding(int desiredPadding) { |
| 2837 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2838 | } |
| 2839 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2840 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2841 | private float getRubberBandFactor(boolean onTop) { |
| 2842 | if (!onTop) { |
| 2843 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2844 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2845 | if (mExpandedInThisMotion) { |
| 2846 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2847 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2848 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2849 | } else if (mScrolledToTopOnFirstDown) { |
| 2850 | return 1.0f; |
| 2851 | } |
| 2852 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2853 | } |
| 2854 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2855 | /** |
| 2856 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2857 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2858 | * overscroll view (e.g. expand QS). |
| 2859 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2860 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2861 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2862 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2863 | || !mScrolledToTopOnFirstDown; |
| 2864 | } |
| 2865 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2866 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2867 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2868 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2869 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
| 2870 | mChildTransferInProgress = childTransferInProgress; |
| 2871 | } |
| 2872 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2873 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2874 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2875 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2876 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2877 | // we only call our internal methods if this is actually a removal and not just a |
| 2878 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2879 | if (!mChildTransferInProgress) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2880 | onViewRemovedInternal((ExpandableView) child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2881 | } |
| 2882 | } |
| 2883 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2884 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2885 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2886 | public void cleanUpViewStateForEntry(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 2887 | View child = entry.getRow(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 2888 | if (child == mSwipeHelper.getTranslatingParentView()) { |
| 2889 | mSwipeHelper.clearTranslatingParentView(); |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2890 | } |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2891 | } |
| 2892 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2893 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2894 | private void onViewRemovedInternal(ExpandableView child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2895 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2896 | // This is only a position change, don't do anything special |
| 2897 | return; |
| 2898 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2899 | child.setOnHeightChangedListener(null); |
| 2900 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2901 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2902 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2903 | if (!mSwipedOutViews.contains(child) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2904 | || Math.abs(child.getTranslation()) != child.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2905 | container.addTransientView(child, 0); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2906 | child.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2907 | } |
| 2908 | } else { |
| 2909 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2910 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2911 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2912 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2913 | focusNextViewIfFocused(child); |
| 2914 | } |
| 2915 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2916 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2917 | private void focusNextViewIfFocused(View view) { |
| 2918 | if (view instanceof ExpandableNotificationRow) { |
| 2919 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2920 | if (row.shouldRefocusOnDismiss()) { |
| 2921 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 2922 | if (nextView == null) { |
| 2923 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 2924 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 2925 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2926 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2927 | } |
| 2928 | if (nextView != null) { |
| 2929 | nextView.requestAccessibilityFocus(); |
| 2930 | } |
| 2931 | } |
| 2932 | } |
| 2933 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2934 | } |
| 2935 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2936 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2937 | private boolean isChildInGroup(View child) { |
| 2938 | return child instanceof ExpandableNotificationRow |
| 2939 | && mGroupManager.isChildInGroupWithSummary( |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2940 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2941 | } |
| 2942 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2943 | /** |
| 2944 | * Generate a remove animation for a child view. |
| 2945 | * |
| 2946 | * @param child The view to generate the remove animation for. |
| 2947 | * @return Whether an animation was generated. |
| 2948 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2949 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2950 | private boolean generateRemoveAnimation(ExpandableView child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2951 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2952 | mAddedHeadsUpChildren.remove(child); |
| 2953 | return false; |
| 2954 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2955 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 2956 | // An animation is already running, add it transiently |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2957 | mClearTransientViewsWhenFinished.add(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2958 | return true; |
| 2959 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2960 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2961 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2962 | // Generate Animations |
| 2963 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2964 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2965 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2966 | } else { |
| 2967 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2968 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2969 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2970 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2971 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2972 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2973 | } |
| 2974 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2975 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2976 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2977 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2980 | /** |
| 2981 | * Remove a removed child view from the heads up animations if it was just added there |
| 2982 | * |
| 2983 | * @return whether any child was removed from the list to animate |
| 2984 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2985 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2986 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 2987 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2988 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 2989 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2990 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2991 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2992 | mTmpList.add(eventPair); |
| 2993 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2994 | } |
| 2995 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2996 | if (hasAddEvent) { |
| 2997 | // This child was just added lets remove all events. |
| 2998 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2999 | ((ExpandableNotificationRow) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 3000 | } |
| 3001 | mTmpList.clear(); |
| 3002 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3005 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3006 | * @param child the child to query |
| 3007 | * @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] | 3008 | * not expanded |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3009 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3010 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3011 | private boolean isChildInInvisibleGroup(View child) { |
| 3012 | if (child instanceof ExpandableNotificationRow) { |
| 3013 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 3014 | NotificationEntry groupSummary = |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3015 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 3016 | if (groupSummary != null && groupSummary.getRow() != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 3017 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3018 | } |
| 3019 | } |
| 3020 | return false; |
| 3021 | } |
| 3022 | |
| 3023 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3024 | * Updates the scroll position when a child was removed |
| 3025 | * |
| 3026 | * @param removedChild the removed child |
| 3027 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3028 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3029 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3030 | if (ANCHOR_SCROLLING) { |
| 3031 | if (removedChild == mScrollAnchorView) { |
| 3032 | ExpandableView firstChild = getFirstChildNotGone(); |
| 3033 | if (firstChild != null) { |
| 3034 | mScrollAnchorView = firstChild; |
| 3035 | } else { |
| 3036 | mScrollAnchorView = mShelf; |
| 3037 | } |
| 3038 | // Adjust anchor view Y by the distance between the old and new anchors |
| 3039 | // so that there's no visible change. |
| 3040 | mScrollAnchorViewY += |
| 3041 | mScrollAnchorView.getTranslationY() - removedChild.getTranslationY(); |
| 3042 | } |
| 3043 | updateScrollAnchor(); |
| 3044 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3045 | if (mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY > 0) { |
| 3046 | mScrollAnchorViewY = 0; |
| 3047 | } |
| 3048 | updateOnScrollChange(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3049 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3050 | int startingPosition = getPositionInLinearLayout(removedChild); |
| 3051 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 3052 | int padding; |
| 3053 | if (increasedPaddingAmount >= 0) { |
| 3054 | padding = (int) NotificationUtils.interpolate( |
| 3055 | mPaddingBetweenElements, |
| 3056 | mIncreasedPaddingBetweenElements, |
| 3057 | increasedPaddingAmount); |
| 3058 | } else { |
| 3059 | padding = (int) NotificationUtils.interpolate( |
| 3060 | 0, |
| 3061 | mPaddingBetweenElements, |
| 3062 | 1.0f + increasedPaddingAmount); |
| 3063 | } |
| 3064 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
| 3065 | int endPosition = startingPosition + childHeight; |
| 3066 | if (endPosition <= mOwnScrollY) { |
| 3067 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 3068 | // scrollPosition |
| 3069 | setOwnScrollY(mOwnScrollY - childHeight); |
| 3070 | } else if (startingPosition < mOwnScrollY) { |
| 3071 | // This child is currently being scrolled into, set the scroll position to the |
| 3072 | // start of this child |
| 3073 | setOwnScrollY(startingPosition); |
| 3074 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3075 | } |
| 3076 | } |
| 3077 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3078 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 3079 | private int getIntrinsicHeight(View view) { |
| 3080 | if (view instanceof ExpandableView) { |
| 3081 | ExpandableView expandableView = (ExpandableView) view; |
| 3082 | return expandableView.getIntrinsicHeight(); |
| 3083 | } |
| 3084 | return view.getHeight(); |
| 3085 | } |
| 3086 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3087 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3088 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3089 | ExpandableNotificationRow childInGroup = null; |
| 3090 | ExpandableNotificationRow requestedRow = null; |
| 3091 | if (isChildInGroup(requestedView)) { |
| 3092 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 3093 | // then within the parent. |
| 3094 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 3095 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 3096 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3097 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3098 | float previousPaddingRequest = mPaddingBetweenElements; |
| 3099 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3100 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3101 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3102 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 3103 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3104 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3105 | float padding; |
| 3106 | if (increasedPaddingAmount >= 0.0f) { |
| 3107 | padding = (int) NotificationUtils.interpolate( |
| 3108 | previousPaddingRequest, |
| 3109 | mIncreasedPaddingBetweenElements, |
| 3110 | increasedPaddingAmount); |
| 3111 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3112 | mPaddingBetweenElements, |
| 3113 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3114 | increasedPaddingAmount); |
| 3115 | } else { |
| 3116 | int ownPadding = (int) NotificationUtils.interpolate( |
| 3117 | 0, |
| 3118 | mPaddingBetweenElements, |
| 3119 | 1.0f + increasedPaddingAmount); |
| 3120 | if (previousPaddingAmount > 0.0f) { |
| 3121 | padding = (int) NotificationUtils.interpolate( |
| 3122 | ownPadding, |
| 3123 | mIncreasedPaddingBetweenElements, |
| 3124 | previousPaddingAmount); |
| 3125 | } else { |
| 3126 | padding = ownPadding; |
| 3127 | } |
| 3128 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3129 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3130 | if (position != 0) { |
| 3131 | position += padding; |
| 3132 | } |
| 3133 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3134 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3135 | if (child == requestedView) { |
| 3136 | if (requestedRow != null) { |
| 3137 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3138 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3139 | return position; |
| 3140 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3141 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3142 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3143 | } |
| 3144 | } |
| 3145 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3149 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3150 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3151 | super.onViewAdded(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3152 | onViewAddedInternal((ExpandableView) child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3153 | } |
| 3154 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3155 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3156 | private void updateFirstAndLastBackgroundViews() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3157 | NotificationSection firstSection = getFirstVisibleSection(); |
| 3158 | NotificationSection lastSection = getLastVisibleSection(); |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3159 | ActivatableNotificationView previousFirstChild = |
| 3160 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 3161 | ActivatableNotificationView previousLastChild = |
| 3162 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3163 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3164 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3165 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 3166 | boolean sectionViewsChanged = mSectionsManager.updateFirstAndLastViewsInSections( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3167 | mSections[0], mSections[1], firstChild, lastChild); |
| 3168 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3169 | if (mAnimationsEnabled && mIsExpanded) { |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3170 | mAnimateNextBackgroundTop = firstChild != previousFirstChild; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3171 | mAnimateNextBackgroundBottom = lastChild != previousLastChild || mAnimateBottomOnLayout; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3172 | mAnimateNextSectionBoundsChange = sectionViewsChanged; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3173 | } else { |
| 3174 | mAnimateNextBackgroundTop = false; |
| 3175 | mAnimateNextBackgroundBottom = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3176 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3177 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3178 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3179 | mRoundnessManager.updateRoundedChildren(mSections); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3180 | mAnimateBottomOnLayout = false; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3181 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3182 | } |
| 3183 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3184 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3185 | private void onViewAddedInternal(ExpandableView child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3186 | updateHideSensitiveForChild(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3187 | child.setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3188 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3189 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3190 | updateChronometerForChild(child); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 3191 | if (child instanceof ExpandableNotificationRow) { |
| 3192 | ((ExpandableNotificationRow) child).setDismissRtl(mDismissRtl); |
| 3193 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3194 | if (ANCHOR_SCROLLING) { |
| 3195 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3196 | if (child == getFirstChildNotGone() && (isScrolledToTop() || !mIsExpanded)) { |
| 3197 | // New child was added at the top while we're scrolled to the top; |
| 3198 | // make it the new anchor view so that we stay at the top. |
| 3199 | mScrollAnchorView = child; |
| 3200 | } |
| 3201 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3202 | } |
| 3203 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3204 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3205 | private void updateHideSensitiveForChild(ExpandableView child) { |
| 3206 | child.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3209 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3210 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3211 | public void notifyGroupChildRemoved(ExpandableView row, ViewGroup childrenContainer) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3212 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3213 | } |
| 3214 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3215 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3216 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3217 | public void notifyGroupChildAdded(ExpandableView row) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3218 | onViewAddedInternal(row); |
| 3219 | } |
| 3220 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3221 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3222 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3223 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3224 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3225 | if (!animationsEnabled) { |
| 3226 | mSwipedOutViews.clear(); |
| 3227 | mChildrenToRemoveAnimated.clear(); |
| 3228 | clearTemporaryViewsInGroup(this); |
| 3229 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3230 | } |
| 3231 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3232 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3233 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3234 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3235 | mShelf.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3236 | int childCount = getChildCount(); |
| 3237 | for (int i = 0; i < childCount; i++) { |
| 3238 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3239 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3240 | updateAnimationState(running, child); |
| 3241 | } |
| 3242 | } |
| 3243 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3244 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3245 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3246 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3247 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3248 | } |
| 3249 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3250 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3251 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3252 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3253 | mAmbientState.setExpandingNotification(row); |
| 3254 | requestChildrenUpdate(); |
| 3255 | } |
| 3256 | |
| 3257 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3258 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3259 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3260 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3261 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3262 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3263 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | @Override |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 3267 | public boolean containsView(View v) { |
| 3268 | return v.getParent() == this; |
| 3269 | } |
| 3270 | |
| 3271 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3272 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3273 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3274 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3275 | requestChildrenUpdate(); |
| 3276 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3277 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3278 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3279 | private void updateAnimationState(boolean running, View child) { |
| 3280 | if (child instanceof ExpandableNotificationRow) { |
| 3281 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3282 | row.setIconAnimationRunning(running); |
| 3283 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3284 | } |
| 3285 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3286 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3287 | public boolean isAddOrRemoveAnimationPending() { |
| 3288 | return mNeedsAnimation |
| 3289 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3290 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3291 | |
| 3292 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3293 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3294 | public void generateAddAnimation(ExpandableView child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3295 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3296 | // Generate Animations |
| 3297 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3298 | if (fromMoreCard) { |
| 3299 | mFromMoreCardAdditions.add(child); |
| 3300 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3301 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3302 | } |
Selim Cinek | f306d9b | 2017-02-21 11:45:13 -0800 | [diff] [blame] | 3303 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3304 | mAddedHeadsUpChildren.add(child); |
| 3305 | mChildrenToAddAnimated.remove(child); |
| 3306 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3307 | } |
| 3308 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3309 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3310 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3311 | public void changeViewPosition(ExpandableView child, int newIndex) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3312 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3313 | |
| 3314 | if (currentIndex == -1) { |
| 3315 | boolean isTransient = false; |
| 3316 | if (child instanceof ExpandableNotificationRow |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3317 | && ((ExpandableNotificationRow) child).getTransientContainer() != null) { |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3318 | isTransient = true; |
| 3319 | } |
| 3320 | Log.e(TAG, "Attempting to re-position " |
| 3321 | + (isTransient ? "transient" : "") |
| 3322 | + " view {" |
| 3323 | + child |
| 3324 | + "}"); |
| 3325 | return; |
| 3326 | } |
| 3327 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3328 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3329 | mChangePositionInProgress = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3330 | ((ExpandableView) child).setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3331 | removeView(child); |
| 3332 | addView(child, newIndex); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3333 | ((ExpandableView) child).setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3334 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3335 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3336 | mChildrenChangingPositions.add(child); |
| 3337 | mNeedsAnimation = true; |
| 3338 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3339 | } |
| 3340 | } |
| 3341 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3342 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3343 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3344 | if (mNeedsAnimation) { |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3345 | generateAllAnimationEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3346 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3347 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3348 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3349 | setAnimationRunning(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3350 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3351 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3352 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3353 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3354 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3355 | } else { |
| 3356 | applyCurrentState(); |
| 3357 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3358 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3359 | } |
| 3360 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3361 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3362 | private void generateAllAnimationEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3363 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3364 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3365 | generateChildAdditionEvents(); |
| 3366 | generatePositionChangeEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3367 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3368 | generateActivateEvent(); |
| 3369 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3370 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3371 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3372 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3373 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3374 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3375 | generateAnimateEverythingEvent(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3376 | } |
| 3377 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3378 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3379 | private void generateHeadsUpAnimationEvents() { |
| 3380 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3381 | ExpandableNotificationRow row = eventPair.first; |
| 3382 | boolean isHeadsUp = eventPair.second; |
| 3383 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3384 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3385 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3386 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3387 | type = row.wasJustClicked() |
| 3388 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3389 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3390 | if (row.isChildInGroup()) { |
| 3391 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3392 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3393 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3394 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3395 | } else { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3396 | ExpandableViewState viewState = row.getViewState(); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3397 | if (viewState == null) { |
| 3398 | // A view state was never generated for this view, so we don't need to animate |
| 3399 | // this. This may happen with notification children. |
| 3400 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3401 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3402 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3403 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3404 | // Our custom add animation |
| 3405 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3406 | } else { |
| 3407 | // Normal add animation |
| 3408 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3409 | } |
| 3410 | onBottom = !pinnedAndClosed; |
| 3411 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3412 | } |
| 3413 | AnimationEvent event = new AnimationEvent(row, type); |
| 3414 | event.headsUpFromBottom = onBottom; |
| 3415 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3416 | } |
| 3417 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3418 | mAddedHeadsUpChildren.clear(); |
| 3419 | } |
| 3420 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3421 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3422 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3423 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3424 | return false; |
| 3425 | } |
| 3426 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3429 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3430 | private void generateGroupExpansionEvent() { |
| 3431 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3432 | if (mExpandedGroupView != null) { |
| 3433 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3434 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3435 | mExpandedGroupView = null; |
| 3436 | } |
| 3437 | } |
| 3438 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3439 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3440 | private void generateViewResizeEvent() { |
| 3441 | if (mNeedViewResizeAnimation) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3442 | boolean hasDisappearAnimation = false; |
| 3443 | for (AnimationEvent animationEvent : mAnimationEvents) { |
| 3444 | final int type = animationEvent.animationType; |
| 3445 | if (type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3446 | || type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3447 | hasDisappearAnimation = true; |
| 3448 | break; |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | if (!hasDisappearAnimation) { |
| 3453 | mAnimationEvents.add( |
| 3454 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3455 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3456 | } |
| 3457 | mNeedViewResizeAnimation = false; |
| 3458 | } |
| 3459 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3460 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3461 | private void generateChildRemovalEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3462 | for (ExpandableView child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3463 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3464 | |
| 3465 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3466 | float removedTranslation = child.getTranslationY(); |
| 3467 | boolean ignoreChildren = true; |
| 3468 | if (child instanceof ExpandableNotificationRow) { |
| 3469 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3470 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3471 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3472 | ignoreChildren = false; |
| 3473 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3474 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3475 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3476 | if (!childWasSwipedOut) { |
| 3477 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3478 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3479 | |
| 3480 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3481 | // Clean up any potential transient views if the child has already been swiped |
| 3482 | // out, as we won't be animating it further (due to its height already being |
| 3483 | // clipped to 0. |
| 3484 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3485 | if (transientContainer != null) { |
| 3486 | transientContainer.removeTransientView(child); |
| 3487 | } |
| 3488 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3489 | } |
| 3490 | int animationType = childWasSwipedOut |
| 3491 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3492 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3493 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3494 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3495 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3496 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3497 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3498 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3499 | mChildrenToRemoveAnimated.clear(); |
| 3500 | } |
| 3501 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3502 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3503 | private void generatePositionChangeEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3504 | for (ExpandableView child : mChildrenChangingPositions) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3505 | mAnimationEvents.add(new AnimationEvent(child, |
| 3506 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3507 | } |
| 3508 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3509 | if (mGenerateChildOrderChangedEvent) { |
| 3510 | mAnimationEvents.add(new AnimationEvent(null, |
| 3511 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3512 | mGenerateChildOrderChangedEvent = false; |
| 3513 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3514 | } |
| 3515 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3516 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3517 | private void generateChildAdditionEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3518 | for (ExpandableView child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3519 | if (mFromMoreCardAdditions.contains(child)) { |
| 3520 | mAnimationEvents.add(new AnimationEvent(child, |
| 3521 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3522 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3523 | } else { |
| 3524 | mAnimationEvents.add(new AnimationEvent(child, |
| 3525 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3526 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3527 | } |
| 3528 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3529 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3530 | } |
| 3531 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3532 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3533 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3534 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3535 | AnimationEvent event; |
| 3536 | if (mAmbientState.isDark()) { |
| 3537 | event = new AnimationEvent(null /* view */, |
| 3538 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3539 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3540 | } else { |
| 3541 | event = new AnimationEvent(null /* view */, |
| 3542 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3543 | } |
| 3544 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3545 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3546 | mTopPaddingNeedsAnimation = false; |
| 3547 | } |
| 3548 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3549 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3550 | private void generateActivateEvent() { |
| 3551 | if (mActivateNeedsAnimation) { |
| 3552 | mAnimationEvents.add( |
| 3553 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3554 | } |
| 3555 | mActivateNeedsAnimation = false; |
| 3556 | } |
| 3557 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3558 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3559 | private void generateAnimateEverythingEvent() { |
| 3560 | if (mEverythingNeedsAnimation) { |
| 3561 | mAnimationEvents.add( |
| 3562 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3563 | } |
| 3564 | mEverythingNeedsAnimation = false; |
| 3565 | } |
| 3566 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3567 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3568 | private void generateDimmedEvent() { |
| 3569 | if (mDimmedNeedsAnimation) { |
| 3570 | mAnimationEvents.add( |
| 3571 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3572 | } |
| 3573 | mDimmedNeedsAnimation = false; |
| 3574 | } |
| 3575 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3576 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3577 | private void generateHideSensitiveEvent() { |
| 3578 | if (mHideSensitiveNeedsAnimation) { |
| 3579 | mAnimationEvents.add( |
| 3580 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3581 | } |
| 3582 | mHideSensitiveNeedsAnimation = false; |
| 3583 | } |
| 3584 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3585 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3586 | private void generateDarkEvent() { |
| 3587 | if (mDarkNeedsAnimation) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 3588 | AnimationEvent ev = new AnimationEvent(null, |
| 3589 | AnimationEvent.ANIMATION_TYPE_DARK, |
| 3590 | new AnimationFilter() |
| 3591 | .animateDark() |
| 3592 | .animateY(mShelf)); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3593 | ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex; |
| 3594 | mAnimationEvents.add(ev); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3595 | } |
| 3596 | mDarkNeedsAnimation = false; |
| 3597 | } |
| 3598 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3599 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3600 | private void generateGoToFullShadeEvent() { |
| 3601 | if (mGoToFullShadeNeedsAnimation) { |
| 3602 | mAnimationEvents.add( |
| 3603 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3604 | } |
| 3605 | mGoToFullShadeNeedsAnimation = false; |
| 3606 | } |
| 3607 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3608 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
| 3609 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3610 | return new StackScrollAlgorithm(context, this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | /** |
| 3614 | * @return Whether a y coordinate is inside the content. |
| 3615 | */ |
| 3616 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 3617 | public boolean isInContentBounds(float y) { |
| 3618 | return y < getHeight() - getEmptyBottomMargin(); |
| 3619 | } |
| 3620 | |
| 3621 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3622 | public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) { |
| 3623 | mLongPressListener = listener; |
| 3624 | } |
| 3625 | |
| 3626 | @Override |
| 3627 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3628 | public boolean onTouchEvent(MotionEvent ev) { |
| 3629 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 3630 | || ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3631 | handleEmptySpaceClick(ev); |
| 3632 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3633 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3634 | if (mIsExpanded && !swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3635 | if (isCancelOrUp) { |
| 3636 | mExpandHelper.onlyObserveMovements(false); |
| 3637 | } |
| 3638 | boolean wasExpandingBefore = mExpandingNotification; |
| 3639 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
| 3640 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 3641 | && !mDisallowScrollingInThisMotion) { |
| 3642 | dispatchDownEventToScroller(ev); |
| 3643 | } |
| 3644 | } |
| 3645 | boolean scrollerWantsIt = false; |
| 3646 | if (mIsExpanded && !swipingInProgress && !mExpandingNotification |
| 3647 | && !mDisallowScrollingInThisMotion) { |
| 3648 | scrollerWantsIt = onScrollTouch(ev); |
| 3649 | } |
| 3650 | boolean horizontalSwipeWantsIt = false; |
| 3651 | if (!mIsBeingDragged |
| 3652 | && !mExpandingNotification |
| 3653 | && !mExpandedInThisMotion |
| 3654 | && !mOnlyScrollingInThisMotion |
| 3655 | && !mDisallowDismissInThisMotion) { |
| 3656 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 3657 | } |
| 3658 | |
| 3659 | // Check if we need to clear any snooze leavebehinds |
| 3660 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3661 | if (guts != null && !NotificationSwipeHelper.isTouchInView(ev, guts) |
| 3662 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 3663 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 3664 | if ((ns.isExpanded() && isCancelOrUp) |
| 3665 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 3666 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 3667 | // clear it on the next non-horizontal swipe or expand event. |
| 3668 | checkSnoozeLeavebehind(); |
| 3669 | } |
| 3670 | } |
| 3671 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3672 | mCheckForLeavebehind = true; |
| 3673 | } |
| 3674 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 3675 | } |
| 3676 | |
| 3677 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3678 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 3679 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 3680 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 3681 | onScrollTouch(downEvent); |
| 3682 | downEvent.recycle(); |
| 3683 | } |
| 3684 | |
| 3685 | @Override |
| 3686 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3687 | public boolean onGenericMotionEvent(MotionEvent event) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3688 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3689 | || mDisallowScrollingInThisMotion) { |
| 3690 | return false; |
| 3691 | } |
| 3692 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3693 | switch (event.getAction()) { |
| 3694 | case MotionEvent.ACTION_SCROLL: { |
| 3695 | if (!mIsBeingDragged) { |
| 3696 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 3697 | if (vscroll != 0) { |
| 3698 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3699 | if (ANCHOR_SCROLLING) { |
| 3700 | mScrollAnchorViewY -= delta; |
| 3701 | updateScrollAnchor(); |
| 3702 | clampScrollPosition(); |
| 3703 | updateOnScrollChange(); |
| 3704 | } else { |
| 3705 | final int range = getScrollRange(); |
| 3706 | int oldScrollY = mOwnScrollY; |
| 3707 | int newScrollY = oldScrollY - delta; |
| 3708 | if (newScrollY < 0) { |
| 3709 | newScrollY = 0; |
| 3710 | } else if (newScrollY > range) { |
| 3711 | newScrollY = range; |
| 3712 | } |
| 3713 | if (newScrollY != oldScrollY) { |
| 3714 | setOwnScrollY(newScrollY); |
| 3715 | return true; |
| 3716 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3717 | } |
| 3718 | } |
| 3719 | } |
| 3720 | } |
| 3721 | } |
| 3722 | } |
| 3723 | return super.onGenericMotionEvent(event); |
| 3724 | } |
| 3725 | |
| 3726 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3727 | private boolean onScrollTouch(MotionEvent ev) { |
| 3728 | if (!isScrollingEnabled()) { |
| 3729 | return false; |
| 3730 | } |
| 3731 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
| 3732 | return false; |
| 3733 | } |
| 3734 | mForcedScroll = null; |
| 3735 | initVelocityTrackerIfNotExists(); |
| 3736 | mVelocityTracker.addMovement(ev); |
| 3737 | |
| 3738 | final int action = ev.getAction(); |
| 3739 | |
| 3740 | switch (action & MotionEvent.ACTION_MASK) { |
| 3741 | case MotionEvent.ACTION_DOWN: { |
| 3742 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
| 3743 | return false; |
| 3744 | } |
| 3745 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3746 | setIsBeingDragged(isBeingDragged); |
| 3747 | /* |
| 3748 | * If being flinged and user touches, stop the fling. isFinished |
| 3749 | * will be false if being flinged. |
| 3750 | */ |
| 3751 | if (!mScroller.isFinished()) { |
| 3752 | mScroller.forceFinished(true); |
| 3753 | } |
| 3754 | |
| 3755 | // Remember where the motion event started |
| 3756 | mLastMotionY = (int) ev.getY(); |
| 3757 | mDownX = (int) ev.getX(); |
| 3758 | mActivePointerId = ev.getPointerId(0); |
| 3759 | break; |
| 3760 | } |
| 3761 | case MotionEvent.ACTION_MOVE: |
| 3762 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 3763 | if (activePointerIndex == -1) { |
| 3764 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 3765 | break; |
| 3766 | } |
| 3767 | |
| 3768 | final int y = (int) ev.getY(activePointerIndex); |
| 3769 | final int x = (int) ev.getX(activePointerIndex); |
| 3770 | int deltaY = mLastMotionY - y; |
| 3771 | final int xDiff = Math.abs(x - mDownX); |
| 3772 | final int yDiff = Math.abs(deltaY); |
| 3773 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
| 3774 | setIsBeingDragged(true); |
| 3775 | if (deltaY > 0) { |
| 3776 | deltaY -= mTouchSlop; |
| 3777 | } else { |
| 3778 | deltaY += mTouchSlop; |
| 3779 | } |
| 3780 | } |
| 3781 | if (mIsBeingDragged) { |
| 3782 | // Scroll to follow the motion event |
| 3783 | mLastMotionY = y; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3784 | float scrollAmount; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3785 | int range; |
| 3786 | if (ANCHOR_SCROLLING) { |
| 3787 | range = 0; // unused in the methods it's being passed to |
| 3788 | } else { |
| 3789 | range = getScrollRange(); |
| 3790 | if (mExpandedInThisMotion) { |
| 3791 | range = Math.min(range, mMaxScrollAfterExpand); |
| 3792 | } |
| 3793 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3794 | if (deltaY < 0) { |
| 3795 | scrollAmount = overScrollDown(deltaY); |
| 3796 | } else { |
| 3797 | scrollAmount = overScrollUp(deltaY, range); |
| 3798 | } |
| 3799 | |
| 3800 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 3801 | // sets the scrolling if applicable. |
| 3802 | if (scrollAmount != 0.0f) { |
| 3803 | // The scrolling motion could not be compensated with the |
| 3804 | // existing overScroll, we have to scroll the view |
| 3805 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 3806 | range, getHeight() / 2); |
| 3807 | // If we're scrolling, leavebehinds should be dismissed |
| 3808 | checkSnoozeLeavebehind(); |
| 3809 | } |
| 3810 | } |
| 3811 | break; |
| 3812 | case MotionEvent.ACTION_UP: |
| 3813 | if (mIsBeingDragged) { |
| 3814 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 3815 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 3816 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 3817 | |
| 3818 | if (shouldOverScrollFling(initialVelocity)) { |
| 3819 | onOverScrollFling(true, initialVelocity); |
| 3820 | } else { |
| 3821 | if (getChildCount() > 0) { |
| 3822 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 3823 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 3824 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 3825 | fling(-initialVelocity); |
| 3826 | } else { |
| 3827 | onOverScrollFling(false, initialVelocity); |
| 3828 | } |
| 3829 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3830 | if (ANCHOR_SCROLLING) { |
| 3831 | // TODO |
| 3832 | } else { |
| 3833 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3834 | getScrollRange())) { |
| 3835 | animateScroll(); |
| 3836 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3837 | } |
| 3838 | } |
| 3839 | } |
| 3840 | } |
| 3841 | mActivePointerId = INVALID_POINTER; |
| 3842 | endDrag(); |
| 3843 | } |
| 3844 | |
| 3845 | break; |
| 3846 | case MotionEvent.ACTION_CANCEL: |
| 3847 | if (mIsBeingDragged && getChildCount() > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3848 | if (ANCHOR_SCROLLING) { |
| 3849 | // TODO |
| 3850 | } else { |
| 3851 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3852 | getScrollRange())) { |
| 3853 | animateScroll(); |
| 3854 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3855 | } |
| 3856 | mActivePointerId = INVALID_POINTER; |
| 3857 | endDrag(); |
| 3858 | } |
| 3859 | break; |
| 3860 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 3861 | final int index = ev.getActionIndex(); |
| 3862 | mLastMotionY = (int) ev.getY(index); |
| 3863 | mDownX = (int) ev.getX(index); |
| 3864 | mActivePointerId = ev.getPointerId(index); |
| 3865 | break; |
| 3866 | } |
| 3867 | case MotionEvent.ACTION_POINTER_UP: |
| 3868 | onSecondaryPointerUp(ev); |
| 3869 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
| 3870 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
| 3871 | break; |
| 3872 | } |
| 3873 | return true; |
| 3874 | } |
| 3875 | |
| 3876 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3877 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 3878 | return ev.getY() < mQsContainer.getBottom(); |
| 3879 | } |
| 3880 | |
| 3881 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3882 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 3883 | if (mOverscrollTopChangedListener != null) { |
| 3884 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 3885 | } |
| 3886 | mDontReportNextOverScroll = true; |
| 3887 | setOverScrollAmount(0.0f, true, false); |
| 3888 | } |
| 3889 | |
| 3890 | |
| 3891 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3892 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 3893 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 3894 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 3895 | final int pointerId = ev.getPointerId(pointerIndex); |
| 3896 | if (pointerId == mActivePointerId) { |
| 3897 | // This was our active pointer going up. Choose a new |
| 3898 | // active pointer and adjust accordingly. |
| 3899 | // TODO: Make this decision more intelligent. |
| 3900 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 3901 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 3902 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 3903 | if (mVelocityTracker != null) { |
| 3904 | mVelocityTracker.clear(); |
| 3905 | } |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3910 | private void endDrag() { |
| 3911 | setIsBeingDragged(false); |
| 3912 | |
| 3913 | recycleVelocityTracker(); |
| 3914 | |
| 3915 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 3916 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 3917 | } |
| 3918 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 3919 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 3920 | } |
| 3921 | } |
| 3922 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3923 | @Override |
| 3924 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3925 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 3926 | initDownStates(ev); |
| 3927 | handleEmptySpaceClick(ev); |
| 3928 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3929 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3930 | if (!swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3931 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 3932 | } |
| 3933 | boolean scrollWantsIt = false; |
| 3934 | if (!swipingInProgress && !mExpandingNotification) { |
| 3935 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 3936 | } |
| 3937 | boolean swipeWantsIt = false; |
| 3938 | if (!mIsBeingDragged |
| 3939 | && !mExpandingNotification |
| 3940 | && !mExpandedInThisMotion |
| 3941 | && !mOnlyScrollingInThisMotion |
| 3942 | && !mDisallowDismissInThisMotion) { |
| 3943 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 3944 | } |
| 3945 | // Check if we need to clear any snooze leavebehinds |
| 3946 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3947 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3948 | if (!NotificationSwipeHelper.isTouchInView(ev, guts) && isUp && !swipeWantsIt && |
| 3949 | !expandWantsIt && !scrollWantsIt) { |
| 3950 | mCheckForLeavebehind = false; |
| 3951 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 3952 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 3953 | false /* resetMenu */); |
| 3954 | } |
| 3955 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3956 | mCheckForLeavebehind = true; |
| 3957 | } |
| 3958 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 3959 | } |
| 3960 | |
| 3961 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3962 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 3963 | switch (ev.getActionMasked()) { |
| 3964 | case MotionEvent.ACTION_MOVE: |
| 3965 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 3966 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop)) { |
| 3967 | mTouchIsClick = false; |
| 3968 | } |
| 3969 | break; |
| 3970 | case MotionEvent.ACTION_UP: |
| 3971 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
| 3972 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 3973 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 3974 | } |
| 3975 | break; |
| 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3980 | private void initDownStates(MotionEvent ev) { |
| 3981 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3982 | mExpandedInThisMotion = false; |
| 3983 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
| 3984 | mDisallowScrollingInThisMotion = false; |
| 3985 | mDisallowDismissInThisMotion = false; |
| 3986 | mTouchIsClick = true; |
| 3987 | mInitialTouchX = ev.getX(); |
| 3988 | mInitialTouchY = ev.getY(); |
| 3989 | } |
| 3990 | } |
| 3991 | |
| 3992 | @Override |
| 3993 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3994 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 3995 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 3996 | if (disallowIntercept) { |
| 3997 | cancelLongPress(); |
| 3998 | } |
| 3999 | } |
| 4000 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4001 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4002 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4003 | if (!isScrollingEnabled()) { |
| 4004 | return false; |
| 4005 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4006 | /* |
| 4007 | * This method JUST determines whether we want to intercept the motion. |
| 4008 | * If we return true, onMotionEvent will be called and we do the actual |
| 4009 | * scrolling there. |
| 4010 | */ |
| 4011 | |
| 4012 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4013 | * Shortcut the most recurring case: the user is in the dragging |
| 4014 | * state and is moving their finger. We want to intercept this |
| 4015 | * motion. |
| 4016 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4017 | final int action = ev.getAction(); |
| 4018 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 4019 | return true; |
| 4020 | } |
| 4021 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4022 | switch (action & MotionEvent.ACTION_MASK) { |
| 4023 | case MotionEvent.ACTION_MOVE: { |
| 4024 | /* |
| 4025 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 4026 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4027 | */ |
| 4028 | |
| 4029 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4030 | * Locally do absolute value. mLastMotionY is set to the y value |
| 4031 | * of the down event. |
| 4032 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4033 | final int activePointerId = mActivePointerId; |
| 4034 | if (activePointerId == INVALID_POINTER) { |
| 4035 | // If we don't have a valid id, the touch down wasn't on content. |
| 4036 | break; |
| 4037 | } |
| 4038 | |
| 4039 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 4040 | if (pointerIndex == -1) { |
| 4041 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 4042 | + " in onInterceptTouchEvent"); |
| 4043 | break; |
| 4044 | } |
| 4045 | |
| 4046 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4047 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4048 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4049 | final int xDiff = Math.abs(x - mDownX); |
| 4050 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4051 | setIsBeingDragged(true); |
| 4052 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4053 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4054 | initVelocityTrackerIfNotExists(); |
| 4055 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4056 | } |
| 4057 | break; |
| 4058 | } |
| 4059 | |
| 4060 | case MotionEvent.ACTION_DOWN: { |
| 4061 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 4062 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 4063 | if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4064 | setIsBeingDragged(false); |
| 4065 | recycleVelocityTracker(); |
| 4066 | break; |
| 4067 | } |
| 4068 | |
| 4069 | /* |
| 4070 | * Remember location of down touch. |
| 4071 | * ACTION_DOWN always refers to pointer index 0. |
| 4072 | */ |
| 4073 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4074 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4075 | mActivePointerId = ev.getPointerId(0); |
| 4076 | |
| 4077 | initOrResetVelocityTracker(); |
| 4078 | mVelocityTracker.addMovement(ev); |
| 4079 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4080 | * If being flinged and user touches the screen, initiate drag; |
| 4081 | * otherwise don't. mScroller.isFinished should be false when |
| 4082 | * being flinged. |
| 4083 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4084 | boolean isBeingDragged = !mScroller.isFinished(); |
| 4085 | setIsBeingDragged(isBeingDragged); |
| 4086 | break; |
| 4087 | } |
| 4088 | |
| 4089 | case MotionEvent.ACTION_CANCEL: |
| 4090 | case MotionEvent.ACTION_UP: |
| 4091 | /* Release the drag */ |
| 4092 | setIsBeingDragged(false); |
| 4093 | mActivePointerId = INVALID_POINTER; |
| 4094 | recycleVelocityTracker(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4095 | if (ANCHOR_SCROLLING) { |
| 4096 | // TODO |
| 4097 | } else { |
| 4098 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 4099 | animateScroll(); |
| 4100 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4101 | } |
| 4102 | break; |
| 4103 | case MotionEvent.ACTION_POINTER_UP: |
| 4104 | onSecondaryPointerUp(ev); |
| 4105 | break; |
| 4106 | } |
| 4107 | |
| 4108 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4109 | * The only time we want to intercept motion events is if we are in the |
| 4110 | * drag mode. |
| 4111 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4112 | return mIsBeingDragged; |
| 4113 | } |
| 4114 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4115 | /** |
| 4116 | * @return Whether the specified motion event is actually happening over the content. |
| 4117 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4118 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4119 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 4120 | return isInContentBounds(event.getY()); |
| 4121 | } |
| 4122 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4123 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4124 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4125 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4126 | void setIsBeingDragged(boolean isDragged) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4127 | mIsBeingDragged = isDragged; |
| 4128 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4129 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4130 | cancelLongPress(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4131 | resetExposedMenuView(true /* animate */, true /* force */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4132 | } |
| 4133 | } |
| 4134 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4135 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4136 | public void requestDisallowLongPress() { |
| 4137 | cancelLongPress(); |
| 4138 | } |
| 4139 | |
| 4140 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4141 | public void requestDisallowDismiss() { |
| 4142 | mDisallowDismissInThisMotion = true; |
| 4143 | } |
| 4144 | |
| 4145 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4146 | public void cancelLongPress() { |
| 4147 | mSwipeHelper.cancelLongPress(); |
| 4148 | } |
| 4149 | |
| 4150 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4151 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 4152 | mOnEmptySpaceClickListener = listener; |
| 4153 | } |
| 4154 | |
| 4155 | /** @hide */ |
| 4156 | @Override |
| 4157 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4158 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4159 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4160 | return true; |
| 4161 | } |
| 4162 | if (!isEnabled()) { |
| 4163 | return false; |
| 4164 | } |
| 4165 | int direction = -1; |
| 4166 | switch (action) { |
| 4167 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4168 | // fall through |
| 4169 | case android.R.id.accessibilityActionScrollDown: |
| 4170 | direction = 1; |
| 4171 | // fall through |
| 4172 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4173 | // fall through |
| 4174 | case android.R.id.accessibilityActionScrollUp: |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4175 | if (ANCHOR_SCROLLING) { |
| 4176 | // TODO |
| 4177 | } else { |
| 4178 | final int viewportHeight = |
| 4179 | getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
| 4180 | - mShelf.getIntrinsicHeight(); |
| 4181 | final int targetScrollY = Math.max(0, |
| 4182 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4183 | if (targetScrollY != mOwnScrollY) { |
| 4184 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, |
| 4185 | targetScrollY - mOwnScrollY); |
| 4186 | animateScroll(); |
| 4187 | return true; |
| 4188 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4189 | } |
| 4190 | break; |
| 4191 | } |
| 4192 | return false; |
| 4193 | } |
| 4194 | |
| 4195 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4196 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4197 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 4198 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 4199 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 4200 | View view = null; |
| 4201 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4202 | // Only close visible guts if they're not a leavebehind. |
| 4203 | view = guts; |
| 4204 | } else if (menuRow != null && menuRow.isMenuVisible() |
| 4205 | && translatingParentView != null) { |
| 4206 | // Checking menu |
| 4207 | view = translatingParentView; |
| 4208 | } |
| 4209 | if (view != null && !NotificationSwipeHelper.isTouchInView(ev, view)) { |
| 4210 | // Touch was outside visible guts / menu notification, close what's visible |
| 4211 | mNotificationGutsManager.closeAndSaveGuts(false /* removeLeavebehind */, |
| 4212 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4213 | false /* resetMenu */); |
| 4214 | resetExposedMenuView(true /* animate */, true /* force */); |
| 4215 | } |
| 4216 | } |
| 4217 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 4218 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4219 | private void setSwipingInProgress(boolean swiping) { |
| 4220 | mSwipingInProgress = swiping; |
| 4221 | if (swiping) { |
| 4222 | requestDisallowInterceptTouchEvent(true); |
| 4223 | } |
| 4224 | } |
| 4225 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4226 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4227 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4228 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4229 | super.onWindowFocusChanged(hasWindowFocus); |
| 4230 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4231 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4232 | } |
| 4233 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4234 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 4235 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4236 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 4237 | public void clearChildFocus(View child) { |
| 4238 | super.clearChildFocus(child); |
| 4239 | if (mForcedScroll == child) { |
| 4240 | mForcedScroll = null; |
| 4241 | } |
| 4242 | } |
| 4243 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4244 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4245 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4246 | public boolean isScrolledToTop() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4247 | if (ANCHOR_SCROLLING) { |
| 4248 | updateScrollAnchor(); |
| 4249 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 4250 | return mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY >= 0; |
| 4251 | } else { |
| 4252 | return mOwnScrollY == 0; |
| 4253 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4257 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4258 | public boolean isScrolledToBottom() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4259 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 4260 | return getMaxPositiveScrollAmount() <= 0; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4261 | } else { |
| 4262 | return mOwnScrollY >= getScrollRange(); |
| 4263 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4267 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4268 | public View getHostView() { |
| 4269 | return this; |
| 4270 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4271 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4272 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4273 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4274 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4275 | } |
| 4276 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4277 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4278 | public void checkSnoozeLeavebehind() { |
| 4279 | if (mCheckForLeavebehind) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 4280 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4281 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4282 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4283 | mCheckForLeavebehind = false; |
| 4284 | } |
| 4285 | } |
| 4286 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4287 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4288 | public void resetCheckSnoozeLeavebehind() { |
| 4289 | mCheckForLeavebehind = true; |
| 4290 | } |
| 4291 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4292 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4293 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4294 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4295 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4296 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4297 | } |
| 4298 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4299 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4300 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4301 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4302 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4303 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4304 | if (!mIsExpanded) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4305 | resetScrollPosition(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4306 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4307 | clearTemporaryViews(); |
| 4308 | clearUserLockedViews(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4309 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 4310 | if (draggedViews.size() > 0) { |
| 4311 | draggedViews.clear(); |
| 4312 | updateContinuousShadowDrawing(); |
| 4313 | } |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4314 | } |
| 4315 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 4316 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4317 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4318 | private void clearUserLockedViews() { |
| 4319 | for (int i = 0; i < getChildCount(); i++) { |
| 4320 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4321 | if (child instanceof ExpandableNotificationRow) { |
| 4322 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4323 | row.setUserLocked(false); |
| 4324 | } |
| 4325 | } |
| 4326 | } |
| 4327 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4328 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4329 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4330 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4331 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4332 | for (int i = 0; i < getChildCount(); i++) { |
| 4333 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4334 | if (child instanceof ExpandableNotificationRow) { |
| 4335 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4336 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4337 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4338 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4339 | } |
| 4340 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4341 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4342 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4343 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 4344 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4345 | } |
| 4346 | } |
| 4347 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4348 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4349 | public void onPanelTrackingStarted() { |
| 4350 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4351 | mAmbientState.setPanelTracking(true); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4352 | resetExposedMenuView(true /* animate */, true /* force */); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4353 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4354 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4355 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4356 | public void onPanelTrackingStopped() { |
| 4357 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4358 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4359 | } |
| 4360 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4361 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4362 | public void resetScrollPosition() { |
| 4363 | mScroller.abortAnimation(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4364 | if (ANCHOR_SCROLLING) { |
| 4365 | // TODO: once we're recycling this will need to modify the adapter position instead |
| 4366 | mScrollAnchorView = getFirstChildNotGone(); |
| 4367 | mScrollAnchorViewY = 0; |
| 4368 | updateOnScrollChange(); |
| 4369 | } else { |
| 4370 | setOwnScrollY(0); |
| 4371 | } |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4372 | } |
| 4373 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4374 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4375 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4376 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4377 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4378 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4379 | mAmbientState.setShadeExpanded(isExpanded); |
| 4380 | mStateAnimator.setShadeExpanded(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 | /** |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4715 | * See {@link AmbientState#setDark}. |
| 4716 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4717 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4718 | public void setDark(boolean dark, boolean animate, @Nullable PointF touchWakeUpScreenLocation) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 4719 | if (mAmbientState.isDark() == dark) { |
| 4720 | return; |
| 4721 | } |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4722 | if (!dark) { |
| 4723 | mShowDarkShelf = false; |
| 4724 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4725 | mAmbientState.setDark(dark); |
| 4726 | if (animate && mAnimationsEnabled) { |
| 4727 | mDarkNeedsAnimation = true; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4728 | mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4729 | mNeedsAnimation = true; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4730 | } else { |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4731 | setDarkAmount(dark ? 1f : 0f); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4732 | updateBackground(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4733 | } |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4734 | requestChildrenUpdate(); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4735 | updateWillNotDraw(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4736 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4737 | } |
| 4738 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4739 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4740 | private void updatePanelTranslation() { |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 4741 | setTranslationX(mHorizontalPanelTranslation + mAntiBurnInOffsetX * mInterpolatedDarkAmount); |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4742 | } |
| 4743 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4744 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 4745 | public void setHorizontalPanelTranslation(float verticalPanelTranslation) { |
| 4746 | mHorizontalPanelTranslation = verticalPanelTranslation; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4747 | updatePanelTranslation(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 4748 | } |
| 4749 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4750 | /** |
| 4751 | * Updates whether or not this Layout will perform its own custom drawing (i.e. whether or |
| 4752 | * not {@link #onDraw(Canvas)} is called). This method should be called whenever the |
| 4753 | * {@link #mAmbientState}'s dark mode is toggled. |
| 4754 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4755 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4756 | private void updateWillNotDraw() { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4757 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 4758 | setWillNotDraw(!willDraw); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4759 | } |
| 4760 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4761 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4762 | private void setDarkAmount(float darkAmount) { |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4763 | setDarkAmount(darkAmount, darkAmount); |
| 4764 | } |
| 4765 | |
| 4766 | /** |
| 4767 | * Sets the current dark amount. |
| 4768 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4769 | * @param linearDarkAmount The dark amount that follows linear interpoloation in the |
| 4770 | * animation, |
| 4771 | * 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] | 4772 | * @param interpolatedDarkAmount The dark amount that follows the actual interpolation of the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4773 | * animation curve. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4774 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4775 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4776 | public void setDarkAmount(float linearDarkAmount, float interpolatedDarkAmount) { |
| 4777 | mLinearDarkAmount = linearDarkAmount; |
| 4778 | mInterpolatedDarkAmount = interpolatedDarkAmount; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4779 | boolean wasFullyDark = mAmbientState.isFullyDark(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4780 | boolean wasDarkAtAll = mAmbientState.isDarkAtAll(); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4781 | mAmbientState.setDarkAmount(interpolatedDarkAmount); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4782 | boolean nowFullyDark = mAmbientState.isFullyDark(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4783 | boolean nowDarkAtAll = mAmbientState.isDarkAtAll(); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4784 | if (nowFullyDark != wasFullyDark) { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4785 | updateContentHeight(); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4786 | if (nowFullyDark && mShowDarkShelf) { |
| 4787 | updateDarkShelfVisibility(); |
| 4788 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4789 | } |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4790 | if (!wasDarkAtAll && nowDarkAtAll) { |
| 4791 | resetExposedMenuView(true /* animate */, true /* animate */); |
| 4792 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 4793 | if (nowFullyDark != wasFullyDark || wasDarkAtAll != nowDarkAtAll) { |
| 4794 | invalidateOutline(); |
| 4795 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4796 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4797 | updateBackgroundDimming(); |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4798 | updatePanelTranslation(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4799 | requestChildrenUpdate(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4800 | } |
| 4801 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4802 | /** |
| 4803 | * If the shelf should be visible when the device is in ambient mode (dozing.) |
| 4804 | */ |
| 4805 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Robert Snoeberger | 6995680 | 2019-04-16 16:55:21 -0400 | [diff] [blame] | 4806 | public void showDarkShelf() { |
| 4807 | mShowDarkShelf = true; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | private void updateDarkShelfVisibility() { |
| 4811 | DozeParameters dozeParameters = DozeParameters.getInstance(mContext); |
| 4812 | if (dozeParameters.shouldControlScreenOff()) { |
| 4813 | mShelf.fadeInTranslating(); |
| 4814 | } |
| 4815 | updateClipping(); |
| 4816 | } |
| 4817 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4818 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4819 | public void notifyDarkAnimationStart(boolean dark) { |
| 4820 | // We only swap the scaling factor if we're fully dark or fully awake to avoid |
| 4821 | // interpolation issues when playing with the power button. |
| 4822 | if (mInterpolatedDarkAmount == 0 || mInterpolatedDarkAmount == 1) { |
| 4823 | mBackgroundXFactor = dark ? 1.8f : 1.5f; |
| 4824 | mDarkXInterpolator = dark |
| 4825 | ? Interpolators.FAST_OUT_SLOW_IN_REVERSE |
| 4826 | : Interpolators.FAST_OUT_SLOW_IN; |
| 4827 | } |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4828 | } |
| 4829 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4830 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4831 | private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4832 | if (screenLocation == null || screenLocation.y < mTopPadding) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4833 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4834 | } |
| 4835 | if (screenLocation.y > getBottomMostNotificationBottom()) { |
| 4836 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW; |
| 4837 | } |
| 4838 | View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y); |
| 4839 | if (child != null) { |
| 4840 | return getNotGoneIndex(child); |
| 4841 | } else { |
| 4842 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4843 | } |
| 4844 | } |
| 4845 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4846 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4847 | private int getNotGoneIndex(View child) { |
| 4848 | int count = getChildCount(); |
| 4849 | int notGoneIndex = 0; |
| 4850 | for (int i = 0; i < count; i++) { |
| 4851 | View v = getChildAt(i); |
| 4852 | if (child == v) { |
| 4853 | return notGoneIndex; |
| 4854 | } |
| 4855 | if (v.getVisibility() != View.GONE) { |
| 4856 | notGoneIndex++; |
| 4857 | } |
| 4858 | } |
| 4859 | return -1; |
| 4860 | } |
| 4861 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4862 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4863 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4864 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4865 | if (mFooterView != null) { |
| 4866 | index = indexOfChild(mFooterView); |
| 4867 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4868 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4869 | mFooterView = footerView; |
| 4870 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4871 | } |
| 4872 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4873 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4874 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4875 | int index = -1; |
| 4876 | if (mEmptyShadeView != null) { |
| 4877 | index = indexOfChild(mEmptyShadeView); |
| 4878 | removeView(mEmptyShadeView); |
| 4879 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4880 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4881 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4882 | } |
| 4883 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4884 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4885 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4886 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4887 | |
| 4888 | int oldTextRes = mEmptyShadeView.getTextResource(); |
| 4889 | int newTextRes = mStatusBar.areNotificationsHidden() |
| 4890 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4891 | if (oldTextRes != newTextRes) { |
| 4892 | mEmptyShadeView.setText(newTextRes); |
| 4893 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4894 | } |
| 4895 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4896 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4897 | public void updateFooterView(boolean visible, boolean showDismissView) { |
| 4898 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4899 | return; |
| 4900 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4901 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 4902 | mFooterView.setVisible(visible, animate); |
| 4903 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4904 | } |
| 4905 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4906 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4907 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 4908 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4909 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4910 | handleDismissAllClipping(); |
| 4911 | } |
| 4912 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4913 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4914 | private void handleDismissAllClipping() { |
| 4915 | final int count = getChildCount(); |
| 4916 | boolean previousChildWillBeDismissed = false; |
| 4917 | for (int i = 0; i < count; i++) { |
| 4918 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4919 | if (child.getVisibility() == GONE) { |
| 4920 | continue; |
| 4921 | } |
| 4922 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 4923 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 4924 | } else { |
| 4925 | child.setMinClipTopAmount(0); |
| 4926 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 4927 | previousChildWillBeDismissed = StackScrollAlgorithm.canChildBeDismissed(child); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4928 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 4929 | } |
| 4930 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4931 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4932 | public boolean isFooterViewNotGone() { |
| 4933 | return mFooterView != null |
| 4934 | && mFooterView.getVisibility() != View.GONE |
| 4935 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4936 | } |
| 4937 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4938 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 4939 | public boolean isFooterViewContentVisible() { |
| 4940 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4941 | } |
| 4942 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4943 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4944 | public int getFooterViewHeight() { |
| 4945 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4946 | } |
| 4947 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4948 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 4949 | public int getEmptyShadeViewHeight() { |
| 4950 | return mEmptyShadeView.getHeight(); |
| 4951 | } |
| 4952 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4953 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4954 | public float getBottomMostNotificationBottom() { |
| 4955 | final int count = getChildCount(); |
| 4956 | float max = 0; |
| 4957 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 4958 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 4959 | if (child.getVisibility() == GONE) { |
| 4960 | continue; |
| 4961 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4962 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 4963 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4964 | if (bottom > max) { |
| 4965 | max = bottom; |
| 4966 | } |
| 4967 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4968 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4969 | } |
| 4970 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4971 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4972 | public void setStatusBar(StatusBar statusBar) { |
| 4973 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 4974 | } |
| 4975 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4976 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4977 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 4978 | this.mGroupManager = groupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 4979 | mGroupManager.addOnGroupChangeListener(mOnGroupChangeListener); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4980 | } |
| 4981 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4982 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4983 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4984 | if (mIsExpanded && mAnimationsEnabled) { |
| 4985 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4986 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4987 | requestChildrenUpdate(); |
| 4988 | } |
| 4989 | } |
| 4990 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4991 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4992 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4993 | int childCount = getChildCount(); |
| 4994 | for (int i = childCount - 1; i >= 0; i--) { |
| 4995 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4996 | if (child.getVisibility() != View.GONE) { |
| 4997 | float childTop = child.getY(); |
| 4998 | if (childTop > touchY) { |
| 4999 | // we are above a notification entirely let's abort |
| 5000 | return false; |
| 5001 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 5002 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 5003 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 5004 | if (child == mFooterView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5005 | if (!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
| 5006 | touchY - childTop)) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5007 | // We clicked on the dismiss button |
| 5008 | return false; |
| 5009 | } |
| 5010 | } else if (child == mEmptyShadeView) { |
| 5011 | // We arrived at the empty shade view, for which we accept all clicks |
| 5012 | return true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5013 | } else if (!belowChild) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 5014 | // We are on a child |
| 5015 | return false; |
| 5016 | } |
| 5017 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5018 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 5019 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5020 | } |
| 5021 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5022 | /** @hide */ |
| 5023 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5024 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5025 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 5026 | super.onInitializeAccessibilityEventInternal(event); |
| 5027 | event.setScrollable(mScrollable); |
| 5028 | event.setScrollX(mScrollX); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5029 | event.setMaxScrollX(mScrollX); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5030 | if (ANCHOR_SCROLLING) { |
| 5031 | // TODO |
| 5032 | } else { |
| 5033 | event.setScrollY(mOwnScrollY); |
| 5034 | event.setMaxScrollY(getScrollRange()); |
| 5035 | } |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5039 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5040 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 5041 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5042 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5043 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5044 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5045 | info.addAction( |
| 5046 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 5047 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 5048 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5049 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5050 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 5051 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 5052 | } |
| 5053 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 5054 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 5055 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5056 | } |
| 5057 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5058 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5059 | public void generateChildOrderChangedEvent() { |
| 5060 | if (mIsExpanded && mAnimationsEnabled) { |
| 5061 | mGenerateChildOrderChangedEvent = true; |
| 5062 | mNeedsAnimation = true; |
| 5063 | requestChildrenUpdate(); |
| 5064 | } |
| 5065 | } |
| 5066 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5067 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5068 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5069 | public int getContainerChildCount() { |
| 5070 | return getChildCount(); |
| 5071 | } |
| 5072 | |
| 5073 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5074 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5075 | public View getContainerChildAt(int i) { |
| 5076 | return getChildAt(i); |
| 5077 | } |
| 5078 | |
| 5079 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5080 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5081 | public void removeContainerView(View v) { |
| 5082 | removeView(v); |
| 5083 | } |
| 5084 | |
| 5085 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5086 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5087 | public void addContainerView(View v) { |
| 5088 | addView(v); |
| 5089 | } |
| 5090 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5091 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 5092 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5093 | mAnimationFinishedRunnables.add(runnable); |
| 5094 | } |
| 5095 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5096 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5097 | public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5098 | mHeadsUpManager = headsUpManager; |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 5099 | mHeadsUpManager.addListener(mRoundnessManager); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 5100 | mHeadsUpManager.setAnimationStateHandler(this::setHeadsUpGoingAwayAnimationsAllowed); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 5103 | public void generateHeadsUpAnimation(NotificationEntry entry, boolean isHeadsUp) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 5104 | ExpandableNotificationRow row = entry.getHeadsUpAnimationView(); |
| 5105 | generateHeadsUpAnimation(row, isHeadsUp); |
| 5106 | } |
| 5107 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5108 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5109 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5110 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5111 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 5112 | mNeedsAnimation = true; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5113 | if (!mIsExpanded && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5114 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5115 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5116 | requestChildrenUpdate(); |
| 5117 | } |
| 5118 | } |
| 5119 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5120 | /** |
| 5121 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 5122 | * position. |
| 5123 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5124 | * @param height the height of the screen |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5125 | * @param bottomBarHeight the height of the bar on the bottom |
| 5126 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5127 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5128 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 5129 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 5130 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5131 | requestChildrenUpdate(); |
| 5132 | } |
| 5133 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5134 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5135 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 5136 | mTrackingHeadsUp = row != null; |
| 5137 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5140 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5141 | public void setScrimController(ScrimController scrimController) { |
| 5142 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 5143 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5146 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5147 | public void forceNoOverlappingRendering(boolean force) { |
| 5148 | mForceNoOverlappingRendering = force; |
| 5149 | } |
| 5150 | |
| 5151 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5152 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5153 | public boolean hasOverlappingRendering() { |
| 5154 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 5155 | } |
| 5156 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5157 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5158 | public void setAnimationRunning(boolean animationRunning) { |
| 5159 | if (animationRunning != mAnimationRunning) { |
| 5160 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5161 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5162 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5163 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5164 | } |
| 5165 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5166 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5167 | } |
| 5168 | } |
| 5169 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5170 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 5171 | public boolean isExpanded() { |
| 5172 | return mIsExpanded; |
| 5173 | } |
| 5174 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5175 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5176 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5177 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 5178 | return; |
| 5179 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5180 | mPulsing = pulsing; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 5181 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5182 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 5183 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 5184 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 5185 | requestChildrenUpdate(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5186 | notifyHeightChangeListener(null, animated); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5187 | } |
| 5188 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5189 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5190 | public void setQsExpanded(boolean qsExpanded) { |
| 5191 | mQsExpanded = qsExpanded; |
| 5192 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 5193 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5196 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5197 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 5198 | mQsExpansionFraction = qsExpansionFraction; |
| 5199 | } |
| 5200 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5201 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5202 | private void setOwnScrollY(int ownScrollY) { |
| 5203 | assert !ANCHOR_SCROLLING; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5204 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 5205 | // We still want to call the normal scrolled changed for accessibility reasons |
| 5206 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5207 | mOwnScrollY = ownScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5208 | updateOnScrollChange(); |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | private void updateOnScrollChange() { |
| 5213 | updateForwardAndBackwardScrollability(); |
| 5214 | requestChildrenUpdate(); |
| 5215 | } |
| 5216 | |
| 5217 | private void updateScrollAnchor() { |
| 5218 | int anchorIndex = indexOfChild(mScrollAnchorView); |
| 5219 | // If the anchor view has been scrolled off the top, move to the next view. |
| 5220 | while (mScrollAnchorViewY < 0) { |
| 5221 | View nextAnchor = null; |
| 5222 | for (int i = anchorIndex + 1; i < getChildCount(); i++) { |
| 5223 | View child = getChildAt(i); |
| 5224 | if (child.getVisibility() != View.GONE |
| 5225 | && child instanceof ExpandableNotificationRow) { |
| 5226 | anchorIndex = i; |
| 5227 | nextAnchor = child; |
| 5228 | break; |
| 5229 | } |
| 5230 | } |
| 5231 | if (nextAnchor == null) { |
| 5232 | break; |
| 5233 | } |
| 5234 | mScrollAnchorViewY += |
| 5235 | (int) (nextAnchor.getTranslationY() - mScrollAnchorView.getTranslationY()); |
| 5236 | mScrollAnchorView = nextAnchor; |
| 5237 | } |
| 5238 | // If the view above the anchor view is fully visible, make it the anchor view. |
| 5239 | while (anchorIndex > 0 && mScrollAnchorViewY > 0) { |
| 5240 | View prevAnchor = null; |
| 5241 | for (int i = anchorIndex - 1; i >= 0; i--) { |
| 5242 | View child = getChildAt(i); |
| 5243 | if (child.getVisibility() != View.GONE |
| 5244 | && child instanceof ExpandableNotificationRow) { |
| 5245 | anchorIndex = i; |
| 5246 | prevAnchor = child; |
| 5247 | break; |
| 5248 | } |
| 5249 | } |
| 5250 | if (prevAnchor == null) { |
| 5251 | break; |
| 5252 | } |
| 5253 | float distanceToPreviousAnchor = |
| 5254 | mScrollAnchorView.getTranslationY() - prevAnchor.getTranslationY(); |
| 5255 | if (distanceToPreviousAnchor < mScrollAnchorViewY) { |
| 5256 | mScrollAnchorViewY -= (int) distanceToPreviousAnchor; |
| 5257 | mScrollAnchorView = prevAnchor; |
| 5258 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5259 | } |
| 5260 | } |
| 5261 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5262 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5263 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5264 | int index = -1; |
| 5265 | if (mShelf != null) { |
| 5266 | index = indexOfChild(mShelf); |
| 5267 | removeView(mShelf); |
| 5268 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 5269 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5270 | addView(mShelf, index); |
| 5271 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 5272 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5273 | shelf.bind(mAmbientState, this); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5274 | if (ANCHOR_SCROLLING) { |
| 5275 | mScrollAnchorView = mShelf; |
| 5276 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5279 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5280 | public NotificationShelf getNotificationShelf() { |
| 5281 | return mShelf; |
| 5282 | } |
| 5283 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5284 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 5285 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 5286 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 5287 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 5288 | updateContentHeight(); |
| 5289 | notifyHeightChangeListener(mShelf); |
| 5290 | } |
| 5291 | } |
| 5292 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5293 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5294 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5295 | mShouldShowShelfOnly = shouldShowShelfOnly; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5296 | updateAlgorithmLayoutMinHeight(); |
| 5297 | } |
| 5298 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5299 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5300 | public int getMinExpansionHeight() { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 5301 | return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5302 | } |
| 5303 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5304 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5305 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 5306 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 5307 | updateClipping(); |
| 5308 | } |
| 5309 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5310 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5311 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 5312 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 5313 | updateClipping(); |
| 5314 | } |
| 5315 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5316 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5317 | @VisibleForTesting |
| 5318 | protected void setStatusBarState(int statusBarState) { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5319 | mStatusBarState = statusBarState; |
| 5320 | mAmbientState.setStatusBarState(statusBarState); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | private void onStatePostChange() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5324 | boolean onKeyguard = onKeyguard(); |
| 5325 | boolean publicMode = mLockscreenUserManager.isAnyProfilePublicMode(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5326 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5327 | if (mHeadsUpAppearanceController != null) { |
| 5328 | mHeadsUpAppearanceController.setPublicMode(publicMode); |
| 5329 | } |
| 5330 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 5331 | SysuiStatusBarStateController state = (SysuiStatusBarStateController) |
| 5332 | Dependency.get(StatusBarStateController.class); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5333 | setHideSensitive(publicMode, state.goingToFullShade() /* animate */); |
| 5334 | setDimmed(onKeyguard, state.fromShadeLocked() /* animate */); |
| 5335 | setExpandingEnabled(!onKeyguard); |
| 5336 | ActivatableNotificationView activatedChild = getActivatedChild(); |
| 5337 | setActivatedChild(null); |
| 5338 | if (activatedChild != null) { |
| 5339 | activatedChild.makeInactive(false /* animate */); |
| 5340 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5341 | updateFooter(); |
Dave Mankoff | 5744580 | 2018-10-10 14:47:34 -0400 | [diff] [blame] | 5342 | requestChildrenUpdate(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5343 | onUpdateRowStates(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5344 | |
| 5345 | mEntryManager.updateNotifications(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5346 | } |
| 5347 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5348 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 5349 | public void setExpandingVelocity(float expandingVelocity) { |
| 5350 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 5351 | } |
| 5352 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5353 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5354 | public float getOpeningHeight() { |
| 5355 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 5356 | return getMinExpansionHeight(); |
| 5357 | } else { |
| 5358 | return getAppearEndPosition(); |
| 5359 | } |
| 5360 | } |
| 5361 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5362 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5363 | public void setIsFullWidth(boolean isFullWidth) { |
| 5364 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 5365 | } |
| 5366 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5367 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 5368 | public void setUnlockHintRunning(boolean running) { |
| 5369 | mAmbientState.setUnlockHintRunning(running); |
| 5370 | } |
| 5371 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5372 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5373 | public void setQsCustomizerShowing(boolean isShowing) { |
| 5374 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 5375 | requestChildrenUpdate(); |
| 5376 | } |
| 5377 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5378 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5379 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 5380 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 5381 | } |
| 5382 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5383 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 5384 | public void setAntiBurnInOffsetX(int antiBurnInOffsetX) { |
| 5385 | mAntiBurnInOffsetX = antiBurnInOffsetX; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 5386 | updatePanelTranslation(); |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5389 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5390 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 5391 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5392 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 5393 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5394 | this.getClass().getSimpleName(), |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5395 | mPulsing ? "T" : "f", |
| 5396 | mAmbientState.isQsCustomizerShowing() ? "T" : "f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5397 | getVisibility() == View.VISIBLE ? "visible" |
| 5398 | : getVisibility() == View.GONE ? "gone" |
| 5399 | : "invisible", |
| 5400 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5401 | mAmbientState.getScrollY(), |
| 5402 | mMaxTopPadding, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5403 | mShouldShowShelfOnly ? "T" : "f", |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5404 | mQsExpansionFraction)); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5405 | int childCount = getChildCount(); |
| 5406 | pw.println(" Number of children: " + childCount); |
| 5407 | pw.println(); |
| 5408 | |
| 5409 | for (int i = 0; i < childCount; i++) { |
| 5410 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5411 | child.dump(fd, pw, args); |
| 5412 | if (!(child instanceof ExpandableNotificationRow)) { |
| 5413 | pw.println(" " + child.getClass().getSimpleName()); |
| 5414 | // 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] | 5415 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5416 | if (viewState == null) { |
| 5417 | pw.println(" no viewState!!!"); |
| 5418 | } else { |
| 5419 | pw.print(" "); |
| 5420 | viewState.dump(fd, pw, args); |
| 5421 | pw.println(); |
| 5422 | pw.println(); |
| 5423 | } |
| 5424 | } |
| 5425 | } |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5426 | int transientViewCount = getTransientViewCount(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5427 | pw.println(" Transient Views: " + transientViewCount); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5428 | for (int i = 0; i < transientViewCount; i++) { |
| 5429 | ExpandableView child = (ExpandableView) getTransientView(i); |
| 5430 | child.dump(fd, pw, args); |
| 5431 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5432 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5433 | int draggedCount = draggedViews.size(); |
| 5434 | pw.println(" Dragged Views: " + draggedCount); |
| 5435 | for (int i = 0; i < draggedCount; i++) { |
| 5436 | ExpandableView child = (ExpandableView) draggedViews.get(i); |
| 5437 | child.dump(fd, pw, args); |
| 5438 | } |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5439 | } |
| 5440 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5441 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 5442 | public boolean isFullyDark() { |
| 5443 | return mAmbientState.isFullyDark(); |
| 5444 | } |
| 5445 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 5446 | /** |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5447 | * Add a listener whenever the expanded height changes. The first value passed as an argument |
| 5448 | * is the expanded height and the second one is the appearFraction. |
| 5449 | * |
| 5450 | * @param listener the listener to notify. |
| 5451 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5452 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5453 | public void addOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 5454 | mExpandedHeightListeners.add(listener); |
| 5455 | } |
| 5456 | |
| 5457 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5458 | * Stop a listener from listening to the expandedHeight. |
| 5459 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5460 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5461 | public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 5462 | mExpandedHeightListeners.remove(listener); |
| 5463 | } |
| 5464 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5465 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 5466 | public void setHeadsUpAppearanceController( |
| 5467 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 5468 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 5469 | } |
| 5470 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5471 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 5472 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 5473 | mIconAreaController = controller; |
| 5474 | } |
| 5475 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5476 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5477 | public void manageNotifications(View v) { |
| 5478 | Intent intent = new Intent(Settings.ACTION_ALL_APPS_NOTIFICATION_SETTINGS); |
| 5479 | mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 5480 | } |
| 5481 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5482 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5483 | private void clearNotifications( |
| 5484 | @SelectedRows int selection, |
| 5485 | boolean closeShade) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5486 | // animate-swipe all dismissable notifications, then animate the shade closed |
| 5487 | int numChildren = getChildCount(); |
| 5488 | |
| 5489 | final ArrayList<View> viewsToHide = new ArrayList<>(numChildren); |
| 5490 | final ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>(numChildren); |
| 5491 | for (int i = 0; i < numChildren; i++) { |
| 5492 | final View child = getChildAt(i); |
| 5493 | if (child instanceof ExpandableNotificationRow) { |
| 5494 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 5495 | boolean parentVisible = false; |
| 5496 | boolean hasClipBounds = child.getClipBounds(mTmpRect); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5497 | if (includeChildInDismissAll(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5498 | viewsToRemove.add(row); |
| 5499 | if (child.getVisibility() == View.VISIBLE |
| 5500 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5501 | viewsToHide.add(child); |
| 5502 | parentVisible = true; |
| 5503 | } |
| 5504 | } else if (child.getVisibility() == View.VISIBLE |
| 5505 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5506 | parentVisible = true; |
| 5507 | } |
| 5508 | List<ExpandableNotificationRow> children = row.getNotificationChildren(); |
| 5509 | if (children != null) { |
| 5510 | for (ExpandableNotificationRow childRow : children) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5511 | if (includeChildInDismissAll(row, selection)) { |
| 5512 | viewsToRemove.add(childRow); |
| 5513 | if (parentVisible && row.areChildrenExpanded()) { |
| 5514 | hasClipBounds = childRow.getClipBounds(mTmpRect); |
| 5515 | if (childRow.getVisibility() == View.VISIBLE |
| 5516 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5517 | viewsToHide.add(childRow); |
| 5518 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5519 | } |
| 5520 | } |
| 5521 | } |
| 5522 | } |
| 5523 | } |
| 5524 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5525 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5526 | if (viewsToRemove.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5527 | if (closeShade) { |
| 5528 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5529 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5530 | return; |
| 5531 | } |
| 5532 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5533 | performDismissAllAnimations(viewsToHide, closeShade, () -> { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5534 | for (ExpandableNotificationRow rowToRemove : viewsToRemove) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5535 | if (StackScrollAlgorithm.canChildBeDismissed(rowToRemove)) { |
| 5536 | if (selection == ROWS_ALL) { |
| 5537 | // TODO: This is a listener method; we shouldn't be calling it. Can we just |
| 5538 | // call performRemoveNotification as below? |
| 5539 | mEntryManager.removeNotification( |
| 5540 | rowToRemove.getEntry().key, |
| 5541 | null /* ranking */, |
| 5542 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5543 | } else { |
| 5544 | mEntryManager.performRemoveNotification( |
| 5545 | rowToRemove.getEntry().notification, |
| 5546 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5547 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5548 | } else { |
| 5549 | rowToRemove.resetTranslation(); |
| 5550 | } |
| 5551 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5552 | if (selection == ROWS_ALL) { |
| 5553 | try { |
| 5554 | mBarService.onClearAllNotifications(mLockscreenUserManager.getCurrentUserId()); |
| 5555 | } catch (Exception ex) { |
| 5556 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5557 | } |
| 5558 | }); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5559 | } |
| 5560 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5561 | private boolean includeChildInDismissAll( |
| 5562 | ExpandableNotificationRow row, |
| 5563 | @SelectedRows int selection) { |
| 5564 | return StackScrollAlgorithm.canChildBeDismissed(row) && matchesSelection(row, selection); |
| 5565 | } |
| 5566 | |
| 5567 | /** |
| 5568 | * Given a list of rows, animates them away in a staggered fashion as if they were dismissed. |
| 5569 | * Doesn't actually dismiss them, though -- that must be done in the onAnimationComplete |
| 5570 | * handler. |
| 5571 | * |
| 5572 | * @param hideAnimatedList List of rows to animated away. Should only be views that are |
| 5573 | * currently visible, or else the stagger will look funky. |
| 5574 | * @param closeShade Whether to close the shade after the stagger animation completes. |
| 5575 | * @param onAnimationComplete Called after the entire animation completes (including the shade |
| 5576 | * closing if appropriate). The rows must be dismissed for real here. |
| 5577 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5578 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5579 | private void performDismissAllAnimations( |
| 5580 | final ArrayList<View> hideAnimatedList, |
| 5581 | final boolean closeShade, |
| 5582 | final Runnable onAnimationComplete) { |
| 5583 | |
| 5584 | final Runnable onSlideAwayAnimationComplete = () -> { |
| 5585 | if (closeShade) { |
| 5586 | mShadeController.addPostCollapseAction(() -> { |
| 5587 | setDismissAllInProgress(false); |
| 5588 | onAnimationComplete.run(); |
| 5589 | }); |
| 5590 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5591 | } else { |
| 5592 | setDismissAllInProgress(false); |
| 5593 | onAnimationComplete.run(); |
| 5594 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5595 | }; |
| 5596 | |
| 5597 | if (hideAnimatedList.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5598 | onSlideAwayAnimationComplete.run(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5599 | return; |
| 5600 | } |
| 5601 | |
| 5602 | // let's disable our normal animations |
| 5603 | setDismissAllInProgress(true); |
| 5604 | |
| 5605 | // Decrease the delay for every row we animate to give the sense of |
| 5606 | // accelerating the swipes |
| 5607 | int rowDelayDecrement = 10; |
| 5608 | int currentDelay = 140; |
| 5609 | int totalDelay = 180; |
| 5610 | int numItems = hideAnimatedList.size(); |
| 5611 | for (int i = numItems - 1; i >= 0; i--) { |
| 5612 | View view = hideAnimatedList.get(i); |
| 5613 | Runnable endRunnable = null; |
| 5614 | if (i == 0) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5615 | endRunnable = onSlideAwayAnimationComplete; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5616 | } |
Lucas Dupin | fb8bdbb | 2018-12-02 15:09:37 -0800 | [diff] [blame] | 5617 | dismissViewAnimated(view, endRunnable, totalDelay, ANIMATION_DURATION_SWIPE); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5618 | currentDelay = Math.max(50, currentDelay - rowDelayDecrement); |
| 5619 | totalDelay += currentDelay; |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5624 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5625 | protected void inflateFooterView() { |
| 5626 | FooterView footerView = (FooterView) LayoutInflater.from(mContext).inflate( |
| 5627 | R.layout.status_bar_notification_footer, this, false); |
| 5628 | footerView.setDismissButtonClickListener(v -> { |
| 5629 | mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5630 | clearNotifications(ROWS_ALL, true /* closeShade */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5631 | }); |
| 5632 | footerView.setManageButtonClickListener(this::manageNotifications); |
| 5633 | setFooterView(footerView); |
| 5634 | } |
| 5635 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5636 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5637 | private void inflateEmptyShadeView() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5638 | EmptyShadeView view = (EmptyShadeView) LayoutInflater.from(mContext).inflate( |
| 5639 | R.layout.status_bar_no_notifications, this, false); |
| 5640 | view.setText(R.string.empty_shade_text); |
| 5641 | setEmptyShadeView(view); |
| 5642 | } |
| 5643 | |
| 5644 | /** |
| 5645 | * Updates expanded, dimmed and locked states of notification rows. |
| 5646 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5647 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5648 | public void onUpdateRowStates() { |
| 5649 | changeViewPosition(mFooterView, -1); |
| 5650 | |
| 5651 | // The following views will be moved to the end of mStackScroller. This counter represents |
| 5652 | // the offset from the last child. Initialized to 1 for the very last position. It is post- |
| 5653 | // incremented in the following "changeViewPosition" calls so that its value is correct for |
| 5654 | // subsequent calls. |
| 5655 | int offsetFromEnd = 1; |
| 5656 | changeViewPosition(mEmptyShadeView, |
| 5657 | getChildCount() - offsetFromEnd++); |
| 5658 | |
| 5659 | // No post-increment for this call because it is the last one. Make sure to add one if |
| 5660 | // another "changeViewPosition" call is ever added. |
| 5661 | changeViewPosition(mShelf, |
| 5662 | getChildCount() - offsetFromEnd); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5663 | } |
| 5664 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5665 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5666 | public void setNotificationPanel(NotificationPanelView notificationPanelView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5667 | mNotificationPanel = notificationPanelView; |
| 5668 | } |
| 5669 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5670 | public void updateIconAreaViews() { |
| 5671 | mIconAreaController.updateNotificationIcons(); |
| 5672 | } |
| 5673 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5674 | /** |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5675 | * Set how far the wake up is when waking up from pulsing. This is a height and will adjust the |
| 5676 | * notification positions accordingly. |
| 5677 | * @param height the new wake up height |
| 5678 | * @return the overflow how much the height is further than he lowest notification |
| 5679 | */ |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 5680 | public float setPulseHeight(float height) { |
| 5681 | mAmbientState.setPulseHeight(height); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5682 | requestChildrenUpdate(); |
| 5683 | return Math.max(0, height - mAmbientState.getInnerHeight(true /* ignorePulseHeight */)); |
| 5684 | } |
| 5685 | |
| 5686 | /** |
| 5687 | * Set the amount how much we're dozing. This is different from how dark the shade is, when |
| 5688 | * the notification is pulsing. |
| 5689 | */ |
| 5690 | public void setDozeAmount(float dozeAmount) { |
| 5691 | mAmbientState.setDozeAmount(dozeAmount); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5692 | updateContinuousBackgroundDrawing(); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5693 | requestChildrenUpdate(); |
| 5694 | } |
| 5695 | |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5696 | public void wakeUpFromPulse() { |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 5697 | setPulseHeight(getPulseHeight()); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5698 | // Let's place the hidden views at the end of the pulsing notification to make sure we have |
| 5699 | // a smooth animation |
| 5700 | boolean firstVisibleView = true; |
| 5701 | float wakeUplocation = -1f; |
| 5702 | int childCount = getChildCount(); |
| 5703 | for (int i = 0; i < childCount; i++) { |
| 5704 | ExpandableView view = (ExpandableView) getChildAt(i); |
| 5705 | if (view.getVisibility() == View.GONE) { |
| 5706 | continue; |
| 5707 | } |
| 5708 | boolean isShelf = view == mShelf; |
| 5709 | if (!(view instanceof ExpandableNotificationRow) && !isShelf) { |
| 5710 | continue; |
| 5711 | } |
| 5712 | if (view.getVisibility() == View.VISIBLE && !isShelf) { |
| 5713 | if (firstVisibleView) { |
| 5714 | firstVisibleView = false; |
| 5715 | wakeUplocation = view.getTranslationY() |
| 5716 | + view.getActualHeight() - mShelf.getIntrinsicHeight(); |
| 5717 | } |
| 5718 | } else if (!firstVisibleView) { |
| 5719 | view.setTranslationY(wakeUplocation); |
| 5720 | } |
| 5721 | } |
| 5722 | } |
| 5723 | |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5724 | @Override |
| 5725 | public void onDynamicPrivacyChanged() { |
| 5726 | if (mIsExpanded) { |
| 5727 | // The bottom might change because we're using the final actual height of the view |
| 5728 | mAnimateBottomOnLayout = true; |
| 5729 | } |
| 5730 | } |
| 5731 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5732 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5733 | * A listener that is notified when the empty space below the notifications is clicked on |
| 5734 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5735 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5736 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 5737 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5741 | * A listener that gets notified when the overscroll at the top has changed. |
| 5742 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5743 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5744 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 5745 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5746 | /** |
| 5747 | * Notifies a listener that the overscroll has changed. |
| 5748 | * |
| 5749 | * @param amount the amount of overscroll, in pixels |
| 5750 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 5751 | * unrubberbanded motion to directly expand overscroll view (e.g |
| 5752 | * expand |
| 5753 | * QS) |
| 5754 | */ |
| 5755 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 5756 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5757 | /** |
| 5758 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 5759 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 5760 | * |
| 5761 | * @param velocity The velocity that the Scroller had when over flinging |
| 5762 | * @param open Should the fling open or close the overscroll view. |
| 5763 | */ |
| 5764 | void flingTopOverscroll(float velocity, boolean open); |
| 5765 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5766 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5767 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5768 | public boolean hasActiveNotifications() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5769 | return !mEntryManager.getNotificationData().getActiveNotifications().isEmpty(); |
| 5770 | } |
| 5771 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 5772 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5773 | public void updateSpeedBumpIndex() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5774 | int speedBumpIndex = 0; |
| 5775 | int currentIndex = 0; |
| 5776 | final int N = getChildCount(); |
| 5777 | for (int i = 0; i < N; i++) { |
| 5778 | View view = getChildAt(i); |
| 5779 | if (view.getVisibility() == View.GONE || !(view instanceof ExpandableNotificationRow)) { |
| 5780 | continue; |
| 5781 | } |
| 5782 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 5783 | currentIndex++; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5784 | boolean beforeSpeedBump; |
| 5785 | if (mLowPriorityBeforeSpeedBump) { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 5786 | beforeSpeedBump = !row.getEntry().ambient; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5787 | } else { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 5788 | beforeSpeedBump = row.getEntry().isHighPriority(); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5789 | } |
| 5790 | if (beforeSpeedBump) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5791 | speedBumpIndex = currentIndex; |
| 5792 | } |
| 5793 | } |
| 5794 | boolean noAmbient = speedBumpIndex == N; |
| 5795 | updateSpeedBumpIndex(speedBumpIndex, noAmbient); |
| 5796 | } |
| 5797 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5798 | /** Updates the indices of the boundaries between sections. */ |
| 5799 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 5800 | public void updateSectionBoundaries() { |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 5801 | mSectionsManager.updateSectionBoundaries(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5802 | } |
| 5803 | |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5804 | private void updateContinuousBackgroundDrawing() { |
| 5805 | boolean continuousBackground = !mAmbientState.isFullyAwake() |
| 5806 | && !mAmbientState.getDraggedViews().isEmpty(); |
| 5807 | if (continuousBackground != mContinuousBackgroundUpdate) { |
| 5808 | mContinuousBackgroundUpdate = continuousBackground; |
| 5809 | if (continuousBackground) { |
| 5810 | getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater); |
| 5811 | } else { |
| 5812 | getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater); |
| 5813 | } |
| 5814 | } |
| 5815 | } |
| 5816 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5817 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5818 | private void updateContinuousShadowDrawing() { |
| 5819 | boolean continuousShadowUpdate = mAnimationRunning |
| 5820 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 5821 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 5822 | if (continuousShadowUpdate) { |
| 5823 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 5824 | } else { |
| 5825 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 5826 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 5827 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5828 | } |
| 5829 | } |
| 5830 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5831 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5832 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 5833 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 5834 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 5835 | } |
| 5836 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 5837 | private static boolean matchesSelection( |
| 5838 | ExpandableNotificationRow row, |
| 5839 | @SelectedRows int selection) { |
| 5840 | switch (selection) { |
| 5841 | case ROWS_ALL: |
| 5842 | return true; |
| 5843 | case ROWS_HIGH_PRIORITY: |
| 5844 | return row.getEntry().isHighPriority(); |
| 5845 | case ROWS_GENTLE: |
| 5846 | return !row.getEntry().isHighPriority(); |
| 5847 | default: |
| 5848 | throw new IllegalArgumentException("Unknown selection: " + selection); |
| 5849 | } |
| 5850 | } |
| 5851 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5852 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 5853 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5854 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5855 | static AnimationFilter[] FILTERS = new AnimationFilter[]{ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5856 | |
| 5857 | // ANIMATION_TYPE_ADD |
| 5858 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5859 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5860 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5861 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5862 | .animateZ() |
| 5863 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5864 | |
| 5865 | // ANIMATION_TYPE_REMOVE |
| 5866 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5867 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5868 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5869 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5870 | .animateZ() |
| 5871 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5872 | |
| 5873 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5874 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5875 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5876 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5877 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5878 | .animateZ() |
| 5879 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5880 | |
| 5881 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5882 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5883 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5884 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5885 | .animateY() |
| 5886 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5887 | .animateZ(), |
| 5888 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5889 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5890 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5891 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5892 | |
| 5893 | // ANIMATION_TYPE_DIMMED |
| 5894 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5895 | .animateDimmed(), |
| 5896 | |
| 5897 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5898 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5899 | .animateAlpha() // maybe the children change positions |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5900 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5901 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5902 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5903 | .animateZ(), |
| 5904 | |
| 5905 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5906 | null, // Unused |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5907 | |
| 5908 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5909 | new AnimationFilter() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5910 | .animateHeight() |
| 5911 | .animateTopInset() |
| 5912 | .animateY() |
| 5913 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5914 | .animateZ() |
| 5915 | .hasDelays(), |
| 5916 | |
| 5917 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5918 | new AnimationFilter() |
| 5919 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5920 | |
| 5921 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5922 | new AnimationFilter() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5923 | .animateHeight() |
| 5924 | .animateTopInset() |
| 5925 | .animateY() |
| 5926 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5927 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5928 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 5929 | new AnimationFilter() |
| 5930 | .animateAlpha() |
| 5931 | .animateHeight() |
| 5932 | .animateTopInset() |
| 5933 | .animateY() |
| 5934 | .animateZ(), |
| 5935 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5936 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5937 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5938 | .animateHeight() |
| 5939 | .animateTopInset() |
| 5940 | .animateY() |
| 5941 | .animateZ(), |
| 5942 | |
| 5943 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5944 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5945 | .animateHeight() |
| 5946 | .animateTopInset() |
| 5947 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 5948 | .animateZ() |
| 5949 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5950 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5951 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5952 | new AnimationFilter() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5953 | .animateHeight() |
| 5954 | .animateTopInset() |
| 5955 | .animateY() |
| 5956 | .animateZ() |
| 5957 | .hasDelays(), |
| 5958 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5959 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5960 | new AnimationFilter() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5961 | .animateHeight() |
| 5962 | .animateTopInset() |
| 5963 | .animateY() |
| 5964 | .animateZ(), |
| 5965 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5966 | // ANIMATION_TYPE_EVERYTHING |
| 5967 | new AnimationFilter() |
| 5968 | .animateAlpha() |
| 5969 | .animateDark() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5970 | .animateDimmed() |
| 5971 | .animateHideSensitive() |
| 5972 | .animateHeight() |
| 5973 | .animateTopInset() |
| 5974 | .animateY() |
| 5975 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5976 | }; |
| 5977 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5978 | static int[] LENGTHS = new int[]{ |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5979 | |
| 5980 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5981 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5982 | |
| 5983 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5984 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5985 | |
| 5986 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5987 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5988 | |
| 5989 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5990 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5991 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5992 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5993 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 5994 | |
| 5995 | // ANIMATION_TYPE_DIMMED |
| 5996 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5997 | |
| 5998 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5999 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 6000 | |
| 6001 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6002 | StackStateAnimator.ANIMATION_DURATION_WAKEUP, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6003 | |
| 6004 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 6005 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 6006 | |
| 6007 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 6008 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 6009 | |
| 6010 | // ANIMATION_TYPE_VIEW_RESIZE |
| 6011 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6012 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6013 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 6014 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6015 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6016 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 6017 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 6018 | |
| 6019 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 6020 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6021 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 6022 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 6023 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6024 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6025 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 6026 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6027 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6028 | // ANIMATION_TYPE_EVERYTHING |
| 6029 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6030 | }; |
| 6031 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6032 | static final int ANIMATION_TYPE_ADD = 0; |
| 6033 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 6034 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 6035 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
Selim Cinek | ff2ffec | 2018-11-19 18:52:01 -0800 | [diff] [blame] | 6036 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 4; |
| 6037 | static final int ANIMATION_TYPE_DIMMED = 5; |
| 6038 | static final int ANIMATION_TYPE_CHANGE_POSITION = 6; |
| 6039 | static final int ANIMATION_TYPE_DARK = 7; |
| 6040 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 8; |
| 6041 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 9; |
| 6042 | static final int ANIMATION_TYPE_VIEW_RESIZE = 10; |
| 6043 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 11; |
| 6044 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 12; |
| 6045 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 13; |
| 6046 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 14; |
| 6047 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 15; |
| 6048 | static final int ANIMATION_TYPE_EVERYTHING = 16; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 6049 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 6050 | static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1; |
| 6051 | static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2; |
| 6052 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6053 | final long eventStartTime; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6054 | final ExpandableView mChangingView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6055 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6056 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6057 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6058 | View viewAfterChangingView; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 6059 | int darkAnimationOriginIndex; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6060 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6061 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6062 | AnimationEvent(ExpandableView view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6063 | this(view, type, LENGTHS[type]); |
| 6064 | } |
| 6065 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6066 | AnimationEvent(ExpandableView view, int type, AnimationFilter filter) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6067 | this(view, type, LENGTHS[type], filter); |
| 6068 | } |
| 6069 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6070 | AnimationEvent(ExpandableView view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6071 | this(view, type, length, FILTERS[type]); |
| 6072 | } |
| 6073 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6074 | AnimationEvent(ExpandableView view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6075 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6076 | mChangingView = view; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6077 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6078 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6079 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | /** |
| 6083 | * Combines the length of several animation events into a single value. |
| 6084 | * |
| 6085 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6086 | * @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] | 6087 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6088 | */ |
| 6089 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 6090 | long length = 0; |
| 6091 | int size = events.size(); |
| 6092 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6093 | AnimationEvent event = events.get(i); |
| 6094 | length = Math.max(length, event.length); |
| 6095 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 6096 | return event.length; |
| 6097 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6098 | } |
| 6099 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6100 | } |
| 6101 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6102 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6103 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 6104 | private final StateListener mStateListener = new StateListener() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6105 | @Override |
| 6106 | public void onStatePreChange(int oldState, int newState) { |
| 6107 | if (oldState == StatusBarState.SHADE_LOCKED && newState == StatusBarState.KEYGUARD) { |
| 6108 | requestAnimateEverything(); |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | @Override |
| 6113 | public void onStateChanged(int newState) { |
| 6114 | setStatusBarState(newState); |
| 6115 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6116 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6117 | @Override |
| 6118 | public void onStatePostChange() { |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6119 | NotificationStackScrollLayout.this.onStatePostChange(); |
| 6120 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6121 | }; |
| 6122 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6123 | @VisibleForTesting |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6124 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6125 | protected final OnMenuEventListener mMenuEventListener = new OnMenuEventListener() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6126 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6127 | public void onMenuClicked(View view, int x, int y, MenuItem item) { |
| 6128 | if (mLongPressListener == null) { |
| 6129 | return; |
| 6130 | } |
| 6131 | if (view instanceof ExpandableNotificationRow) { |
| 6132 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6133 | mMetricsLogger.write(row.getStatusBarNotification().getLogMaker() |
| 6134 | .setCategory(MetricsEvent.ACTION_TOUCH_GEAR) |
| 6135 | .setType(MetricsEvent.TYPE_ACTION) |
| 6136 | ); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6137 | } |
| 6138 | mLongPressListener.onLongPress(view, x, y, item); |
| 6139 | } |
| 6140 | |
| 6141 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6142 | public void onMenuReset(View row) { |
| 6143 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 6144 | if (translatingParentView != null && row == translatingParentView) { |
| 6145 | mSwipeHelper.clearExposedMenuView(); |
| 6146 | mSwipeHelper.clearTranslatingParentView(); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6147 | if (row instanceof ExpandableNotificationRow) { |
| 6148 | mHeadsUpManager.setMenuShown( |
| 6149 | ((ExpandableNotificationRow) row).getEntry(), false); |
| 6150 | |
| 6151 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6152 | } |
| 6153 | } |
| 6154 | |
| 6155 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6156 | public void onMenuShown(View row) { |
| 6157 | if (row instanceof ExpandableNotificationRow) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6158 | ExpandableNotificationRow notificationRow = (ExpandableNotificationRow) row; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6159 | mMetricsLogger.write(notificationRow.getStatusBarNotification().getLogMaker() |
| 6160 | .setCategory(MetricsEvent.ACTION_REVEAL_GEAR) |
| 6161 | .setType(MetricsEvent.TYPE_ACTION)); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6162 | mHeadsUpManager.setMenuShown(notificationRow.getEntry(), true); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6163 | mSwipeHelper.onMenuShown(row); |
| 6164 | |
| 6165 | // Check to see if we want to go directly to the notfication guts |
| 6166 | NotificationMenuRowPlugin provider = notificationRow.getProvider(); |
| 6167 | if (provider.shouldShowGutsOnSnapOpen()) { |
| 6168 | MenuItem item = provider.menuItemToExposeOnSnap(); |
| 6169 | if (item != null) { |
| 6170 | Point origin = provider.getRevealAnimationOrigin(); |
| 6171 | mGutsManager.openGuts(row, origin.x, origin.y, item); |
| 6172 | } else { |
| 6173 | Log.e(TAG, "Provider has shouldShowGutsOnSnapOpen, but provided no " |
| 6174 | + "menu item in menuItemtoExposeOnSnap. Skipping."); |
| 6175 | } |
| 6176 | |
| 6177 | // Close the menu row since we went directly to the guts |
| 6178 | resetExposedMenuView(false, true); |
| 6179 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6180 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6181 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6182 | }; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6183 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6184 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6185 | private final NotificationSwipeHelper.NotificationCallback mNotificationCallback = |
| 6186 | new NotificationSwipeHelper.NotificationCallback() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6187 | @Override |
| 6188 | public void onDismiss() { |
| 6189 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6190 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6191 | false /* resetMenu */); |
| 6192 | } |
| 6193 | |
| 6194 | @Override |
| 6195 | public void onSnooze(StatusBarNotification sbn, |
| 6196 | NotificationSwipeActionHelper.SnoozeOption snoozeOption) { |
| 6197 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
| 6198 | } |
| 6199 | |
| 6200 | @Override |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6201 | public boolean shouldDismissQuickly() { |
| 6202 | return NotificationStackScrollLayout.this.isExpanded() && mAmbientState.isFullyAwake(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6203 | } |
| 6204 | |
| 6205 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6206 | public void onDragCancelled(View v) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6207 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6208 | mFalsingManager.onNotificatonStopDismissing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6209 | } |
| 6210 | |
| 6211 | /** |
| 6212 | * Handles cleanup after the given {@code view} has been fully swiped out (including |
| 6213 | * re-invoking dismiss logic in case the notification has not made its way out yet). |
| 6214 | */ |
| 6215 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6216 | public void onChildDismissed(View view) { |
| 6217 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6218 | if (!row.isDismissed()) { |
| 6219 | handleChildViewDismissed(view); |
| 6220 | } |
| 6221 | ViewGroup transientContainer = row.getTransientContainer(); |
| 6222 | if (transientContainer != null) { |
| 6223 | transientContainer.removeTransientView(view); |
| 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | /** |
| 6228 | * Starts up notification dismiss and tells the notification, if any, to remove itself from |
| 6229 | * layout. |
| 6230 | * |
| 6231 | * @param view view (e.g. notification) to dismiss from the layout |
| 6232 | */ |
| 6233 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6234 | public void handleChildViewDismissed(View view) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6235 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6236 | if (mDismissAllInProgress) { |
| 6237 | return; |
| 6238 | } |
| 6239 | |
| 6240 | boolean isBlockingHelperShown = false; |
| 6241 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6242 | mAmbientState.onDragFinished(view); |
| 6243 | updateContinuousShadowDrawing(); |
| 6244 | |
| 6245 | if (view instanceof ExpandableNotificationRow) { |
| 6246 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6247 | if (row.isHeadsUp()) { |
| 6248 | mHeadsUpManager.addSwipedOutNotification( |
| 6249 | row.getStatusBarNotification().getKey()); |
| 6250 | } |
| 6251 | isBlockingHelperShown = |
| 6252 | row.performDismissWithBlockingHelper(false /* fromAccessibility */); |
| 6253 | } |
| 6254 | |
| 6255 | if (!isBlockingHelperShown) { |
| 6256 | mSwipedOutViews.add(view); |
| 6257 | } |
| 6258 | mFalsingManager.onNotificationDismissed(); |
| 6259 | if (mFalsingManager.shouldEnforceBouncer()) { |
| 6260 | mStatusBar.executeRunnableDismissingKeyguard( |
| 6261 | null, |
| 6262 | null /* cancelAction */, |
| 6263 | false /* dismissShade */, |
| 6264 | true /* afterKeyguardGone */, |
| 6265 | false /* deferred */); |
| 6266 | } |
| 6267 | } |
| 6268 | |
| 6269 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6270 | public boolean isAntiFalsingNeeded() { |
| 6271 | return onKeyguard(); |
| 6272 | } |
| 6273 | |
| 6274 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6275 | public View getChildAtPosition(MotionEvent ev) { |
| 6276 | View child = NotificationStackScrollLayout.this.getChildAtPosition(ev.getX(), |
| 6277 | ev.getY()); |
| 6278 | if (child instanceof ExpandableNotificationRow) { |
| 6279 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 6280 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 6281 | if (parent != null && parent.areChildrenExpanded() |
| 6282 | && (parent.areGutsExposed() |
| 6283 | || mSwipeHelper.getExposedMenuView() == parent |
| 6284 | || (parent.getNotificationChildren().size() == 1 |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 6285 | && parent.getEntry().isClearable()))) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6286 | // In this case the group is expanded and showing the menu for the |
| 6287 | // group, further interaction should apply to the group, not any |
| 6288 | // child notifications so we use the parent of the child. We also do the same |
| 6289 | // if we only have a single child. |
| 6290 | child = parent; |
| 6291 | } |
| 6292 | } |
| 6293 | return child; |
| 6294 | } |
| 6295 | |
| 6296 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6297 | public void onBeginDrag(View v) { |
| 6298 | mFalsingManager.onNotificatonStartDismissing(); |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6299 | setSwipingInProgress(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6300 | mAmbientState.onBeginDrag((ExpandableView) v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6301 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6302 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6303 | requestChildrenUpdate(); |
| 6304 | } |
| 6305 | |
| 6306 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6307 | public void onChildSnappedBack(View animView, float targetLeft) { |
| 6308 | mAmbientState.onDragFinished(animView); |
| 6309 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6310 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6314 | public boolean updateSwipeProgress(View animView, boolean dismissable, |
| 6315 | float swipeProgress) { |
| 6316 | // Returning true prevents alpha fading. |
| 6317 | return !mFadeNotificationsOnDismiss; |
| 6318 | } |
| 6319 | |
| 6320 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6321 | public float getFalsingThresholdFactor() { |
| 6322 | return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
| 6323 | } |
| 6324 | |
| 6325 | @Override |
Gus Prevas | c4e68d4 | 2019-01-17 15:45:21 -0500 | [diff] [blame] | 6326 | public int getConstrainSwipeStartPosition() { |
| 6327 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 6328 | if (menuRow != null) { |
| 6329 | return Math.abs(menuRow.getMenuSnapTarget()); |
| 6330 | } |
| 6331 | return 0; |
| 6332 | } |
| 6333 | |
| 6334 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6335 | public boolean canChildBeDismissed(View v) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 6336 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6337 | } |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6338 | |
| 6339 | @Override |
| 6340 | public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) { |
Evan Laird | 30b9b16 | 2019-04-24 15:22:24 -0400 | [diff] [blame] | 6341 | //TODO: b/131242807 for why this doesn't do anything with direction |
| 6342 | return canChildBeDismissed(v); |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6343 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6344 | }; |
| 6345 | |
| 6346 | // ---------------------- DragDownHelper.OnDragDownListener ------------------------------------ |
| 6347 | |
| 6348 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6349 | private final DragDownCallback mDragDownCallback = new DragDownCallback() { |
| 6350 | |
| 6351 | /* Only ever called as a consequence of a lockscreen expansion gesture. */ |
| 6352 | @Override |
| 6353 | public boolean onDraggedDown(View startingChild, int dragLengthY) { |
| 6354 | if (mStatusBarState == StatusBarState.KEYGUARD |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6355 | && hasActiveNotifications()) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6356 | mLockscreenGestureLogger.write( |
| 6357 | MetricsEvent.ACTION_LS_SHADE, |
| 6358 | (int) (dragLengthY / mDisplayMetrics.density), |
| 6359 | 0 /* velocityDp - N/A */); |
| 6360 | |
Lucas Dupin | c780404 | 2018-12-21 12:26:33 -0800 | [diff] [blame] | 6361 | if (!mAmbientState.isDark() || startingChild != null) { |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6362 | // We have notifications, go to locked shade. |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 6363 | mShadeController.goToLockedShade(startingChild); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6364 | if (startingChild instanceof ExpandableNotificationRow) { |
| 6365 | ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild; |
| 6366 | row.onExpandedByGesture(true /* drag down is always an open */); |
| 6367 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6368 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6369 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6370 | return true; |
| 6371 | } else { |
| 6372 | // abort gesture. |
| 6373 | return false; |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | @Override |
| 6378 | public void onDragDownReset() { |
| 6379 | setDimmed(true /* dimmed */, true /* animated */); |
| 6380 | resetScrollPosition(); |
| 6381 | resetCheckSnoozeLeavebehind(); |
| 6382 | } |
| 6383 | |
| 6384 | @Override |
| 6385 | public void onCrossedThreshold(boolean above) { |
| 6386 | setDimmed(!above /* dimmed */, true /* animate */); |
| 6387 | } |
| 6388 | |
| 6389 | @Override |
| 6390 | public void onTouchSlopExceeded() { |
| 6391 | cancelLongPress(); |
| 6392 | checkSnoozeLeavebehind(); |
| 6393 | } |
| 6394 | |
| 6395 | @Override |
| 6396 | public void setEmptyDragAmount(float amount) { |
| 6397 | mNotificationPanel.setEmptyDragAmount(amount); |
| 6398 | } |
| 6399 | |
| 6400 | @Override |
| 6401 | public boolean isFalsingCheckNeeded() { |
| 6402 | return mStatusBarState == StatusBarState.KEYGUARD; |
| 6403 | } |
| 6404 | }; |
| 6405 | |
| 6406 | public DragDownCallback getDragDownCallback() { return mDragDownCallback; } |
| 6407 | |
| 6408 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6409 | private final HeadsUpTouchHelper.Callback mHeadsUpCallback = new HeadsUpTouchHelper.Callback() { |
| 6410 | @Override |
| 6411 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6412 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6413 | } |
| 6414 | |
| 6415 | @Override |
| 6416 | public boolean isExpanded() { |
| 6417 | return mIsExpanded; |
| 6418 | } |
| 6419 | |
| 6420 | @Override |
| 6421 | public Context getContext() { |
| 6422 | return mContext; |
| 6423 | } |
| 6424 | }; |
| 6425 | |
| 6426 | public HeadsUpTouchHelper.Callback getHeadsUpCallback() { return mHeadsUpCallback; } |
| 6427 | |
| 6428 | |
| 6429 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6430 | private final OnGroupChangeListener mOnGroupChangeListener = new OnGroupChangeListener() { |
| 6431 | @Override |
| 6432 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
| 6433 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 6434 | && (mIsExpanded || changedRow.isPinned()); |
| 6435 | if (animated) { |
| 6436 | mExpandedGroupView = changedRow; |
| 6437 | mNeedsAnimation = true; |
| 6438 | } |
| 6439 | changedRow.setChildrenExpanded(expanded, animated); |
| 6440 | if (!mGroupExpandedForMeasure) { |
| 6441 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 6442 | } |
| 6443 | runAfterAnimationFinished(new Runnable() { |
| 6444 | @Override |
| 6445 | public void run() { |
| 6446 | changedRow.onFinishedExpansionChange(); |
| 6447 | } |
| 6448 | }); |
| 6449 | } |
| 6450 | |
| 6451 | @Override |
| 6452 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
| 6453 | mStatusBar.requestNotificationUpdate(); |
| 6454 | } |
| 6455 | |
| 6456 | @Override |
| 6457 | public void onGroupsChanged() { |
| 6458 | mStatusBar.requestNotificationUpdate(); |
| 6459 | } |
| 6460 | }; |
| 6461 | |
| 6462 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6463 | private ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { |
| 6464 | @Override |
| 6465 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
| 6466 | return NotificationStackScrollLayout.this.getChildAtPosition(touchX, touchY); |
| 6467 | } |
| 6468 | |
| 6469 | @Override |
| 6470 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6471 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6472 | } |
| 6473 | |
| 6474 | @Override |
| 6475 | public boolean canChildBeExpanded(View v) { |
| 6476 | return v instanceof ExpandableNotificationRow |
| 6477 | && ((ExpandableNotificationRow) v).isExpandable() |
| 6478 | && !((ExpandableNotificationRow) v).areGutsExposed() |
| 6479 | && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned()); |
| 6480 | } |
| 6481 | |
| 6482 | /* Only ever called as a consequence of an expansion gesture in the shade. */ |
| 6483 | @Override |
| 6484 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 6485 | if (v instanceof ExpandableNotificationRow) { |
| 6486 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6487 | if (userExpanded && onKeyguard()) { |
| 6488 | // Due to a race when locking the screen while touching, a notification may be |
| 6489 | // expanded even after we went back to keyguard. An example of this happens if |
| 6490 | // you click in the empty space while expanding a group. |
| 6491 | |
| 6492 | // We also need to un-user lock it here, since otherwise the content height |
| 6493 | // calculated might be wrong. We also can't invert the two calls since |
| 6494 | // un-userlocking it will trigger a layout switch in the content view. |
| 6495 | row.setUserLocked(false); |
| 6496 | updateContentHeight(); |
| 6497 | notifyHeightChangeListener(row); |
| 6498 | return; |
| 6499 | } |
| 6500 | row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */); |
| 6501 | row.onExpandedByGesture(userExpanded); |
| 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | @Override |
| 6506 | public void setExpansionCancelled(View v) { |
| 6507 | if (v instanceof ExpandableNotificationRow) { |
| 6508 | ((ExpandableNotificationRow) v).setGroupExpansionChanging(false); |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | @Override |
| 6513 | public void setUserLockedChild(View v, boolean userLocked) { |
| 6514 | if (v instanceof ExpandableNotificationRow) { |
| 6515 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 6516 | } |
| 6517 | cancelLongPress(); |
| 6518 | requestDisallowInterceptTouchEvent(true); |
| 6519 | } |
| 6520 | |
| 6521 | @Override |
| 6522 | public void expansionStateChanged(boolean isExpanding) { |
| 6523 | mExpandingNotification = isExpanding; |
| 6524 | if (!mExpandedInThisMotion) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 6525 | if (ANCHOR_SCROLLING) { |
| 6526 | // TODO |
| 6527 | } else { |
| 6528 | mMaxScrollAfterExpand = mOwnScrollY; |
| 6529 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6530 | mExpandedInThisMotion = true; |
| 6531 | } |
| 6532 | } |
| 6533 | |
| 6534 | @Override |
| 6535 | public int getMaxExpandHeight(ExpandableView view) { |
| 6536 | return view.getMaxContentHeight(); |
| 6537 | } |
| 6538 | }; |
| 6539 | |
| 6540 | public ExpandHelper.Callback getExpandHelperCallback() { |
| 6541 | return mExpandHelperCallback; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6542 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame^] | 6543 | |
| 6544 | /** Enum for selecting some or all notification rows (does not included non-notif views). */ |
| 6545 | @Retention(SOURCE) |
| 6546 | @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE}) |
| 6547 | public @interface SelectedRows {} |
| 6548 | /** All rows representing notifs. */ |
| 6549 | public static final int ROWS_ALL = 0; |
| 6550 | /** Only rows where entry.isHighPriority() is true. */ |
| 6551 | public static final int ROWS_HIGH_PRIORITY = 1; |
| 6552 | /** Only rows where entry.isHighPriority() is false. */ |
| 6553 | public static final int ROWS_GENTLE = 2; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 6554 | } |