Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.stack; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 18 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 19 | import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 20 | import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.ANCHOR_SCROLLING; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 22 | import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_SWIPE; |
Selim Cinek | 3c9b054 | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.phone.NotificationIconAreaController.HIGH_PRIORITY; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 24 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 25 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 26 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 27 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 28 | import android.animation.Animator; |
| 29 | import android.animation.AnimatorListenerAdapter; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 30 | import android.animation.TimeAnimator; |
| 31 | import android.animation.ValueAnimator; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 32 | import android.annotation.IntDef; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 33 | import android.annotation.NonNull; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 34 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 35 | import android.content.Context; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 36 | import android.content.Intent; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 37 | import android.content.res.Configuration; |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 38 | import android.content.res.Resources; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 39 | import android.graphics.Canvas; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 40 | import android.graphics.Color; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 41 | import android.graphics.Outline; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 42 | import android.graphics.Paint; |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 43 | import android.graphics.Point; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 44 | import android.graphics.PointF; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 45 | import android.graphics.PorterDuff; |
| 46 | import android.graphics.PorterDuffXfermode; |
| 47 | import android.graphics.Rect; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 48 | import android.os.Bundle; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 49 | import android.os.ServiceManager; |
| 50 | import android.provider.Settings; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 51 | import android.service.notification.NotificationListenerService; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 52 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 53 | import android.util.AttributeSet; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 54 | import android.util.DisplayMetrics; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 55 | import android.util.Log; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 56 | import android.util.MathUtils; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 57 | import android.util.Pair; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 58 | import android.view.ContextThemeWrapper; |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 59 | import android.view.InputDevice; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 60 | import android.view.LayoutInflater; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 61 | import android.view.MotionEvent; |
| 62 | import android.view.VelocityTracker; |
| 63 | import android.view.View; |
| 64 | import android.view.ViewConfiguration; |
| 65 | import android.view.ViewGroup; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 66 | import android.view.ViewOutlineProvider; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 67 | import android.view.ViewTreeObserver; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 68 | import android.view.WindowInsets; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 69 | import android.view.accessibility.AccessibilityEvent; |
| 70 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 71 | import android.view.animation.AnimationUtils; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 72 | import android.view.animation.Interpolator; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 73 | import android.widget.OverScroller; |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 74 | import android.widget.ScrollView; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 75 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 76 | import com.android.internal.annotations.VisibleForTesting; |
| 77 | import com.android.internal.graphics.ColorUtils; |
Mady Mellor | a41587b | 2016-02-11 18:43:06 -0800 | [diff] [blame] | 78 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 79 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 80 | import com.android.internal.statusbar.IStatusBarService; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 81 | import com.android.keyguard.KeyguardSliceView; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 82 | import com.android.settingslib.Utils; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 83 | import com.android.systemui.Dependency; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 84 | import com.android.systemui.Dumpable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 85 | import com.android.systemui.ExpandHelper; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 86 | import com.android.systemui.Interpolators; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 87 | import com.android.systemui.R; |
| 88 | import com.android.systemui.SwipeHelper; |
Dave Mankoff | dde5ee6 | 2019-05-02 17:36:11 -0400 | [diff] [blame] | 89 | import com.android.systemui.classifier.FalsingManagerFactory; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 90 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 91 | import com.android.systemui.plugins.ActivityStarter; |
Dave Mankoff | 468d4f6 | 2019-05-08 14:56:29 -0400 | [diff] [blame] | 92 | import com.android.systemui.plugins.FalsingManager; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 93 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
| 94 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 95 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.OnMenuEventListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 96 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 97 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 98 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 99 | import com.android.systemui.statusbar.AmbientPulseManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 100 | import com.android.systemui.statusbar.CommandQueue; |
| 101 | import com.android.systemui.statusbar.DragDownHelper.DragDownCallback; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 102 | import com.android.systemui.statusbar.EmptyShadeView; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 103 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 104 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 105 | import com.android.systemui.statusbar.NotificationShelf; |
| 106 | import com.android.systemui.statusbar.RemoteInputController; |
| 107 | import com.android.systemui.statusbar.StatusBarState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 108 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 109 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 110 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 111 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 112 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 113 | import com.android.systemui.statusbar.notification.NotificationUtils; |
| 114 | import com.android.systemui.statusbar.notification.ShadeViewRefactor; |
| 115 | import com.android.systemui.statusbar.notification.ShadeViewRefactor.RefactorComponent; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 116 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 117 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 118 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 119 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 120 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 121 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 122 | import com.android.systemui.statusbar.notification.row.FooterView; |
| 123 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 124 | import com.android.systemui.statusbar.notification.row.NotificationGuts; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 125 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 126 | import com.android.systemui.statusbar.notification.row.NotificationSnooze; |
| 127 | import com.android.systemui.statusbar.notification.row.StackScrollerDecorView; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 128 | import com.android.systemui.statusbar.phone.DozeParameters; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 129 | import com.android.systemui.statusbar.phone.HeadsUpAppearanceController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 130 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 131 | import com.android.systemui.statusbar.phone.HeadsUpTouchHelper; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 132 | import com.android.systemui.statusbar.phone.LockscreenGestureLogger; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 133 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 134 | import com.android.systemui.statusbar.phone.NotificationGroupManager.OnGroupChangeListener; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 135 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 136 | import com.android.systemui.statusbar.phone.NotificationPanelView; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 137 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 138 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 139 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 140 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 141 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 142 | import com.android.systemui.statusbar.policy.HeadsUpUtil; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 143 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 144 | import com.android.systemui.tuner.TunerService; |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 145 | import com.android.systemui.util.Assert; |
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; |
Selim Cinek | 3c9b054 | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 190 | private boolean mHighPriorityBeforeSpeedBump; |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 191 | private final boolean mAllowLongPress; |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 192 | private boolean mDismissRtl; |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 193 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 194 | private float mExpandedHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 195 | private int mOwnScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 196 | private View mScrollAnchorView; |
| 197 | private int mScrollAnchorViewY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 198 | private int mMaxLayoutHeight; |
| 199 | |
| 200 | private VelocityTracker mVelocityTracker; |
| 201 | private OverScroller mScroller; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 202 | /** Last Y position reported by {@link #mScroller}, used to calculate scroll delta. */ |
| 203 | private int mLastScrollerY; |
| 204 | /** |
| 205 | * True if the max position was set to a known position on the last call to {@link #mScroller}. |
| 206 | */ |
| 207 | private boolean mIsScrollerBoundSet; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 208 | private Runnable mFinishScrollingCallback; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 209 | private int mTouchSlop; |
| 210 | private int mMinimumVelocity; |
| 211 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 212 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 213 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 214 | private boolean mIsBeingDragged; |
| 215 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 216 | private int mDownX; |
Dong-wan Kim | b926666 | 2016-09-21 13:08:30 -0700 | [diff] [blame] | 217 | private int mActivePointerId = INVALID_POINTER; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 218 | private boolean mTouchIsClick; |
| 219 | private float mInitialTouchX; |
| 220 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 221 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 222 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 223 | private int mContentHeight; |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 224 | private int mIntrinsicContentHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 225 | private int mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 226 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 227 | private int mIncreasedPaddingBetweenElements; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 228 | private int mMaxTopPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 229 | private int mTopPadding; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 230 | private int mBottomMargin; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 231 | private int mBottomInset = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 232 | private float mQsExpansionFraction; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * The algorithm which calculates the properties for our children |
| 236 | */ |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 237 | protected final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 238 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 239 | private final AmbientState mAmbientState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 240 | private NotificationGroupManager mGroupManager; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 241 | private HashSet<ExpandableView> mChildrenToAddAnimated = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 242 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 243 | private ArrayList<ExpandableView> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 244 | private ArrayList<ExpandableView> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 245 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 246 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 247 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 248 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 249 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 250 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 251 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 252 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 253 | /** |
| 254 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 255 | */ |
| 256 | private float mOverScrolledTopPixels; |
| 257 | |
| 258 | /** |
| 259 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 260 | */ |
| 261 | private float mOverScrolledBottomPixels; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 262 | private NotificationLogger.OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 263 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 264 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 265 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 266 | private boolean mNeedsAnimation; |
| 267 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 268 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 269 | private boolean mHideSensitiveNeedsAnimation; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 270 | private boolean mDarkNeedsAnimation; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 271 | private int mDarkAnimationOriginIndex; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 272 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 273 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 274 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 275 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 276 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 277 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 278 | private boolean mExpandingNotification; |
| 279 | private boolean mExpandedInThisMotion; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 280 | private boolean mShouldShowShelfOnly; |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 281 | protected boolean mScrollingEnabled; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 282 | protected FooterView mFooterView; |
Muyuan Li | dd9ae75 | 2016-05-13 16:45:43 -0700 | [diff] [blame] | 283 | protected EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 284 | private boolean mDismissAllInProgress; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 285 | private boolean mFadeNotificationsOnDismiss; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * Was the scroller scrolled to the top when the down motion was observed? |
| 289 | */ |
| 290 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 291 | /** |
| 292 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 293 | * when over scrolling on a expanded card. |
| 294 | */ |
| 295 | private float mMinTopOverScrollToEscape; |
| 296 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 297 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 298 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 299 | private boolean mDontReportNextOverScroll; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 300 | private boolean mDontClampNextScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 301 | private boolean mNeedViewResizeAnimation; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 302 | private ExpandableView mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 303 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 304 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 305 | /** |
| 306 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 307 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 308 | * motion. |
| 309 | */ |
| 310 | private int mMaxScrollAfterExpand; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 311 | private ExpandableNotificationRow.LongPressListener mLongPressListener; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 312 | boolean mCheckForLeavebehind; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 313 | |
| 314 | /** |
| 315 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 316 | * animating. |
| 317 | */ |
| 318 | private boolean mOnlyScrollingInThisMotion; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 319 | private boolean mDisallowDismissInThisMotion; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 320 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 321 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 322 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 323 | = new ViewTreeObserver.OnPreDrawListener() { |
| 324 | @Override |
| 325 | public boolean onPreDraw() { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 326 | updateForcedScroll(); |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 327 | updateChildren(); |
| 328 | mChildrenUpdateRequested = false; |
| 329 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 330 | return true; |
| 331 | } |
| 332 | }; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 333 | private StatusBar mStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 334 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 335 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 336 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 337 | private HashSet<ExpandableView> mClearTransientViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 338 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 339 | = new HashSet<>(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 340 | private HeadsUpManagerPhone mHeadsUpManager; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 341 | private final NotificationRoundnessManager mRoundnessManager; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 342 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 343 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 344 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 345 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 346 | private FalsingManager mFalsingManager; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 347 | private boolean mAnimationRunning; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 348 | private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 349 | = new ViewTreeObserver.OnPreDrawListener() { |
| 350 | @Override |
| 351 | public boolean onPreDraw() { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 352 | onPreDrawDuringAnimation(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 353 | return true; |
| 354 | } |
| 355 | }; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 356 | private NotificationSection[] mSections = new NotificationSection[NUM_SECTIONS]; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 357 | private boolean mAnimateNextBackgroundTop; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 358 | private boolean mAnimateNextBackgroundBottom; |
| 359 | private boolean mAnimateNextSectionBoundsChange; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 360 | private int mBgColor; |
| 361 | private float mDimAmount; |
| 362 | private ValueAnimator mDimAnimator; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 363 | private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 364 | private final Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 365 | @Override |
| 366 | public void onAnimationEnd(Animator animation) { |
| 367 | mDimAnimator = null; |
| 368 | } |
| 369 | }; |
| 370 | private ValueAnimator.AnimatorUpdateListener mDimUpdateListener |
| 371 | = new ValueAnimator.AnimatorUpdateListener() { |
| 372 | |
| 373 | @Override |
| 374 | public void onAnimationUpdate(ValueAnimator animation) { |
| 375 | setDimAmount((Float) animation.getAnimatedValue()); |
| 376 | } |
| 377 | }; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 378 | protected ViewGroup mQsContainer; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 379 | private boolean mContinuousShadowUpdate; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 380 | private boolean mContinuousBackgroundUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 381 | private ViewTreeObserver.OnPreDrawListener mShadowUpdater |
| 382 | = new ViewTreeObserver.OnPreDrawListener() { |
| 383 | |
| 384 | @Override |
| 385 | public boolean onPreDraw() { |
| 386 | updateViewShadows(); |
| 387 | return true; |
| 388 | } |
| 389 | }; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 390 | private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> { |
| 391 | updateBackground(); |
| 392 | return true; |
| 393 | }; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 394 | private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() { |
| 395 | @Override |
| 396 | public int compare(ExpandableView view, ExpandableView otherView) { |
| 397 | float endY = view.getTranslationY() + view.getActualHeight(); |
| 398 | float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); |
| 399 | if (endY < otherEndY) { |
| 400 | return -1; |
| 401 | } else if (endY > otherEndY) { |
| 402 | return 1; |
| 403 | } else { |
| 404 | // The two notifications end at the same location |
| 405 | return 0; |
| 406 | } |
| 407 | } |
| 408 | }; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 409 | private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() { |
| 410 | @Override |
| 411 | public void getOutline(View view, Outline outline) { |
Selim Cinek | 1e05927 | 2019-05-21 18:15:00 -0700 | [diff] [blame] | 412 | if (mAmbientState.isDarkAtAll()) { |
Selim Cinek | 9ad240c | 2019-04-08 19:07:15 -0700 | [diff] [blame] | 413 | float xProgress = mDarkXInterpolator.getInterpolation( |
| 414 | (1 - mLinearDarkAmount) * mBackgroundXFactor); |
| 415 | outline.setRoundRect(mBackgroundAnimationRect, |
| 416 | MathUtils.lerp(mCornerRadius / 2.0f, mCornerRadius, |
| 417 | xProgress)); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 418 | } else { |
| 419 | ViewOutlineProvider.BACKGROUND.getOutline(view, outline); |
| 420 | } |
| 421 | } |
| 422 | }; |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 423 | private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 424 | private boolean mPulsing; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 425 | private boolean mGroupExpandedForMeasure; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 426 | private boolean mScrollable; |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 427 | private View mForcedScroll; |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 428 | |
| 429 | /** |
| 430 | * @see #setDarkAmount(float, float) |
| 431 | */ |
| 432 | private float mInterpolatedDarkAmount = 0f; |
| 433 | |
| 434 | /** |
| 435 | * @see #setDarkAmount(float, float) |
| 436 | */ |
| 437 | private float mLinearDarkAmount = 0f; |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 438 | |
| 439 | /** |
| 440 | * How fast the background scales in the X direction as a factor of the Y expansion. |
| 441 | */ |
| 442 | private float mBackgroundXFactor = 1f; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 443 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 444 | private boolean mSwipingInProgress; |
| 445 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 446 | private boolean mUsingLightTheme; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 447 | private boolean mQsExpanded; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 448 | private boolean mForwardScrollable; |
| 449 | private boolean mBackwardScrollable; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 450 | private NotificationShelf mShelf; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 451 | private int mMaxDisplayedNotifications = -1; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 452 | private int mStatusBarHeight; |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 453 | private int mMinInteractionHeight; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 454 | private boolean mNoAmbient; |
| 455 | private final Rect mClipRect = new Rect(); |
| 456 | private boolean mIsClipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 457 | private Rect mRequestedClipBounds; |
| 458 | private boolean mInHeadsUpPinnedMode; |
| 459 | private boolean mHeadsUpAnimatingAway; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 460 | private int mStatusBarState; |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 461 | private int mCachedBackgroundColor; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 462 | private boolean mHeadsUpGoingAwayAnimationsAllowed = true; |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 463 | private Runnable mReflingAndAnimateScroll = () -> { |
| 464 | if (ANCHOR_SCROLLING) { |
| 465 | maybeReflingScroller(); |
| 466 | } |
| 467 | animateScroll(); |
| 468 | }; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 469 | private int mCornerRadius; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 470 | private int mSidePaddings; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 471 | private final Rect mBackgroundAnimationRect = new Rect(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 472 | private int mAntiBurnInOffsetX; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 473 | private ArrayList<BiConsumer<Float, Float>> mExpandedHeightListeners = new ArrayList<>(); |
| 474 | private int mHeadsUpInset; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 475 | private HeadsUpAppearanceController mHeadsUpAppearanceController; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 476 | private NotificationIconAreaController mIconAreaController; |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 477 | private float mHorizontalPanelTranslation; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 478 | private final NotificationLockscreenUserManager mLockscreenUserManager = |
| 479 | Dependency.get(NotificationLockscreenUserManager.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 480 | private final Rect mTmpRect = new Rect(); |
| 481 | private final NotificationEntryManager mEntryManager = |
| 482 | Dependency.get(NotificationEntryManager.class); |
| 483 | private final IStatusBarService mBarService = IStatusBarService.Stub.asInterface( |
| 484 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 485 | @VisibleForTesting |
| 486 | protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 487 | private final NotificationRemoteInputManager mRemoteInputManager = |
| 488 | Dependency.get(NotificationRemoteInputManager.class); |
| 489 | private final SysuiColorExtractor mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
| 490 | |
| 491 | private final DisplayMetrics mDisplayMetrics = Dependency.get(DisplayMetrics.class); |
| 492 | private final LockscreenGestureLogger mLockscreenGestureLogger = |
| 493 | Dependency.get(LockscreenGestureLogger.class); |
| 494 | private final VisualStabilityManager mVisualStabilityManager = |
| 495 | Dependency.get(VisualStabilityManager.class); |
| 496 | protected boolean mClearAllEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 497 | |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 498 | private Interpolator mDarkXInterpolator = Interpolators.FAST_OUT_SLOW_IN; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 499 | private NotificationPanelView mNotificationPanel; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 500 | private final ShadeController mShadeController = Dependency.get(ShadeController.class); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 501 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 502 | private final NotificationGutsManager |
| 503 | mNotificationGutsManager = Dependency.get(NotificationGutsManager.class); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 504 | private final NotificationSectionsManager mSectionsManager; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 505 | /** |
| 506 | * If the {@link NotificationShelf} should be visible when dark. |
| 507 | */ |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 508 | private boolean mAnimateBottomOnLayout; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 509 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 510 | @Inject |
| 511 | public NotificationStackScrollLayout( |
| 512 | @Named(VIEW_CONTEXT) Context context, |
| 513 | AttributeSet attrs, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 514 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress, |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 515 | NotificationRoundnessManager notificationRoundnessManager, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 516 | AmbientPulseManager ambientPulseManager, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 517 | DynamicPrivacyController dynamicPrivacyController, |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 518 | ConfigurationController configurationController, |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 519 | ActivityStarter activityStarter, |
| 520 | StatusBarStateController statusBarStateController) { |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 521 | super(context, attrs, 0, 0); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 522 | Resources res = getResources(); |
| 523 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 524 | mAllowLongPress = allowLongPress; |
| 525 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 526 | for (int i = 0; i < NUM_SECTIONS; i++) { |
| 527 | mSections[i] = new NotificationSection(this); |
| 528 | } |
| 529 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 530 | mAmbientPulseManager = ambientPulseManager; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 531 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 532 | mSectionsManager = |
| 533 | new NotificationSectionsManager( |
| 534 | this, |
| 535 | activityStarter, |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 536 | statusBarStateController, |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 537 | configurationController, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 538 | NotificationUtils.useNewInterruptionModel(context)); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 539 | mSectionsManager.initialize(LayoutInflater.from(context)); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 540 | mSectionsManager.setOnClearGentleNotifsClickListener(v -> { |
| 541 | // Leave the shade open if there will be other notifs left over to clear |
| 542 | final boolean closeShade = !hasActiveClearableNotifications(ROWS_HIGH_PRIORITY); |
| 543 | clearNotifications(ROWS_GENTLE, closeShade); |
| 544 | }); |
| 545 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 546 | mAmbientState = new AmbientState(context, mSectionsManager); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 547 | mRoundnessManager = notificationRoundnessManager; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 548 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 549 | int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 550 | int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 551 | mExpandHelper = new ExpandHelper(getContext(), mExpandHelperCallback, |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 552 | minHeight, maxHeight); |
| 553 | mExpandHelper.setEventSource(this); |
| 554 | mExpandHelper.setScrollAdapter(this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 555 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, mNotificationCallback, |
| 556 | getContext(), mMenuEventListener); |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 557 | mStackScrollAlgorithm = createStackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 558 | initView(context); |
Dave Mankoff | dde5ee6 | 2019-05-02 17:36:11 -0400 | [diff] [blame] | 559 | mFalsingManager = FalsingManagerFactory.getInstance(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 560 | mShouldDrawNotificationBackground = |
| 561 | res.getBoolean(R.bool.config_drawNotificationBackground); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 562 | mFadeNotificationsOnDismiss = |
| 563 | res.getBoolean(R.bool.config_fadeNotificationsOnDismiss); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 564 | mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated); |
| 565 | mRoundnessManager.setOnRoundingChangedCallback(this::invalidate); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 566 | addOnExpandedHeightListener(mRoundnessManager::setExpanded); |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 567 | setOutlineProvider(mOutlineProvider); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 568 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 569 | // Blocking helper manager wants to know the expanded state, update as well. |
| 570 | NotificationBlockingHelperManager blockingHelperManager = |
| 571 | Dependency.get(NotificationBlockingHelperManager.class); |
| 572 | addOnExpandedHeightListener((height, unused) -> { |
| 573 | blockingHelperManager.setNotificationShadeExpanded(height); |
| 574 | }); |
| 575 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 576 | updateWillNotDraw(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 577 | mBackgroundPaint.setAntiAlias(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 578 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 579 | mDebugPaint = new Paint(); |
| 580 | mDebugPaint.setColor(0xffff0000); |
| 581 | mDebugPaint.setStrokeWidth(2); |
| 582 | mDebugPaint.setStyle(Paint.Style.STROKE); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 583 | mDebugPaint.setTextSize(25f); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 584 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 585 | mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 586 | |
| 587 | TunerService tunerService = Dependency.get(TunerService.class); |
| 588 | tunerService.addTunable((key, newValue) -> { |
Selim Cinek | 3c9b054 | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 589 | if (key.equals(HIGH_PRIORITY)) { |
| 590 | mHighPriorityBeforeSpeedBump = "1".equals(newValue); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 591 | } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { |
| 592 | updateDismissRtlSetting("1".equals(newValue)); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 593 | } |
Selim Cinek | 3c9b054 | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 594 | }, HIGH_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL); |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 595 | |
| 596 | mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 597 | @Override |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 598 | public void onPostEntryUpdated(NotificationEntry entry) { |
Gus Prevas | 5ecd2b8 | 2019-01-04 17:19:26 -0500 | [diff] [blame] | 599 | if (!entry.notification.isClearable()) { |
| 600 | // The user may have performed a dismiss action on the notification, since it's |
| 601 | // not clearable we should snap it back. |
| 602 | snapViewIfNeeded(entry); |
| 603 | } |
| 604 | } |
| 605 | }); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 606 | dynamicPrivacyController.addListener(this); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 609 | private void updateDismissRtlSetting(boolean dismissRtl) { |
| 610 | mDismissRtl = dismissRtl; |
| 611 | for (int i = 0; i < getChildCount(); i++) { |
| 612 | View child = getChildAt(i); |
| 613 | if (child instanceof ExpandableNotificationRow) { |
| 614 | ((ExpandableNotificationRow) child).setDismissRtl(dismissRtl); |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 619 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 620 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 621 | protected void onFinishInflate() { |
| 622 | super.onFinishInflate(); |
| 623 | |
| 624 | inflateEmptyShadeView(); |
| 625 | inflateFooterView(); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 626 | mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 627 | if (mAllowLongPress) { |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 628 | setLongPressListener(mNotificationGutsManager::openGuts); |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 629 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 632 | /** |
| 633 | * @return the height at which we will wake up when pulsing |
| 634 | */ |
| 635 | public float getPulseHeight() { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 636 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 637 | if (firstChild != null) { |
| 638 | return firstChild.getCollapsedHeight(); |
| 639 | } |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 640 | return 0f; |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 641 | } |
| 642 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 643 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 644 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 645 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 646 | reinflateViews(); |
| 647 | } |
| 648 | |
| 649 | private void reinflateViews() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 650 | inflateFooterView(); |
| 651 | inflateEmptyShadeView(); |
| 652 | updateFooter(); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 653 | mSectionsManager.reinflateViews(LayoutInflater.from(mContext)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 657 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 658 | public void onThemeChanged() { |
Lucas Dupin | a476c79 | 2019-06-10 18:00:22 -0700 | [diff] [blame] | 659 | final boolean useDarkText = mColorExtractor.getNeutralColors().supportsDarkText(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 660 | updateDecorViews(useDarkText); |
| 661 | |
| 662 | updateFooter(); |
| 663 | } |
| 664 | |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 665 | @Override |
| 666 | public void onOverlayChanged() { |
| 667 | int newRadius = mContext.getResources().getDimensionPixelSize( |
| 668 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
| 669 | if (mCornerRadius != newRadius) { |
| 670 | mCornerRadius = newRadius; |
| 671 | invalidate(); |
| 672 | } |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 673 | reinflateViews(); |
Fabian Kozynski | d254b19 | 2019-02-05 13:42:58 -0500 | [diff] [blame] | 674 | } |
| 675 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 676 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 677 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 678 | public void updateFooter() { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 679 | boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 680 | boolean showFooterView = (showDismissView || |
| 681 | mEntryManager.getNotificationData().getActiveNotifications().size() != 0) |
| 682 | && mStatusBarState != StatusBarState.KEYGUARD |
| 683 | && !mRemoteInputManager.getController().isRemoteInputActive(); |
| 684 | |
| 685 | updateFooterView(showFooterView, showDismissView); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * Return whether there are any clearable notifications |
| 690 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 691 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 692 | public boolean hasActiveClearableNotifications(@SelectedRows int selection) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 693 | int childCount = getChildCount(); |
| 694 | for (int i = 0; i < childCount; i++) { |
| 695 | View child = getChildAt(i); |
| 696 | if (!(child instanceof ExpandableNotificationRow)) { |
| 697 | continue; |
| 698 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 699 | final ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 700 | if (row.canViewBeDismissed() && matchesSelection(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 701 | return true; |
| 702 | } |
| 703 | } |
| 704 | return false; |
| 705 | } |
| 706 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 707 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 708 | public RemoteInputController.Delegate createDelegate() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 709 | return new RemoteInputController.Delegate() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 710 | public void setRemoteInputActive(NotificationEntry entry, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 711 | boolean remoteInputActive) { |
| 712 | mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 713 | entry.notifyHeightChanged(true /* needsAnimation */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 714 | updateFooter(); |
| 715 | } |
| 716 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 717 | public void lockScrollTo(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 718 | NotificationStackScrollLayout.this.lockScrollTo(entry.getRow()); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | public void requestDisallowLongPressAndDismiss() { |
| 722 | requestDisallowLongPress(); |
| 723 | requestDisallowDismiss(); |
| 724 | } |
| 725 | }; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 726 | } |
| 727 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 728 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 729 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 730 | protected void onAttachedToWindow() { |
| 731 | super.onAttachedToWindow(); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 732 | ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class)) |
| 733 | .addCallback(mStateListener, SysuiStatusBarStateController.RANK_STACK_SCROLLER); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 734 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 738 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 739 | protected void onDetachedFromWindow() { |
| 740 | super.onDetachedFromWindow(); |
Jason Monk | af08c15 | 2018-12-04 11:12:39 -0500 | [diff] [blame] | 741 | Dependency.get(StatusBarStateController.class).removeCallback(mStateListener); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 742 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | @Override |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 746 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 747 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 748 | return mSwipeHelper; |
| 749 | } |
| 750 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 751 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 752 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 753 | public void onUiModeChanged() { |
| 754 | mBgColor = mContext.getColor(R.color.notification_shade_background_color); |
| 755 | updateBackgroundDimming(); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 756 | mShelf.onUiModeChanged(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 757 | mSectionsManager.onUiModeChanged(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 760 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 761 | protected void onDraw(Canvas canvas) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 762 | if (mShouldDrawNotificationBackground |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 763 | && (mSections[0].getCurrentBounds().top |
| 764 | < mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom |
| 765 | || mAmbientState.isDark())) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 766 | drawBackground(canvas); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 767 | } else if (mInHeadsUpPinnedMode || mHeadsUpAnimatingAway) { |
| 768 | drawHeadsUpBackground(canvas); |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 769 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 770 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 771 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 772 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 773 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 774 | y = getLayoutHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 775 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 776 | y = getHeight() - getEmptyBottomMargin(); |
| 777 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 781 | @Override |
| 782 | public void draw(Canvas canvas) { |
| 783 | super.draw(canvas); |
| 784 | |
| 785 | if (DEBUG && ANCHOR_SCROLLING) { |
| 786 | if (mScrollAnchorView instanceof ExpandableNotificationRow) { |
| 787 | canvas.drawRect(0, |
| 788 | mScrollAnchorView.getTranslationY(), |
| 789 | getWidth(), |
| 790 | mScrollAnchorView.getTranslationY() |
| 791 | + ((ExpandableNotificationRow) mScrollAnchorView).getActualHeight(), |
| 792 | mDebugPaint); |
| 793 | canvas.drawText(Integer.toString(mScrollAnchorViewY), getWidth() - 200, |
| 794 | mScrollAnchorView.getTranslationY() + 30, mDebugPaint); |
| 795 | int y = (int) mShelf.getTranslationY(); |
| 796 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 797 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 798 | canvas.drawText(Integer.toString(getMaxNegativeScrollAmount()), getWidth() - 100, |
| 799 | getIntrinsicPadding() + 30, mDebugPaint); |
| 800 | canvas.drawText(Integer.toString(getMaxPositiveScrollAmount()), getWidth() - 100, |
| 801 | getHeight() - 30, mDebugPaint); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 805 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 806 | private void drawBackground(Canvas canvas) { |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 807 | int lockScreenLeft = mSidePaddings; |
| 808 | int lockScreenRight = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 809 | int lockScreenTop = mSections[0].getCurrentBounds().top; |
| 810 | int lockScreenBottom = mSections[NUM_SECTIONS - 1].getCurrentBounds().bottom; |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 811 | int darkLeft = getWidth() / 2; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 812 | int darkTop = mTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 813 | |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 814 | float yProgress = 1 - mInterpolatedDarkAmount; |
| 815 | float xProgress = mDarkXInterpolator.getInterpolation( |
| 816 | (1 - mLinearDarkAmount) * mBackgroundXFactor); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 817 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 818 | int left = (int) MathUtils.lerp(darkLeft, lockScreenLeft, xProgress); |
| 819 | int right = (int) MathUtils.lerp(darkLeft, lockScreenRight, xProgress); |
| 820 | int top = (int) MathUtils.lerp(darkTop, lockScreenTop, yProgress); |
| 821 | int bottom = (int) MathUtils.lerp(darkTop, lockScreenBottom, yProgress); |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 822 | mBackgroundAnimationRect.set( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 823 | left, |
| 824 | top, |
| 825 | right, |
| 826 | bottom); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 827 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 828 | int backgroundTopAnimationOffset = top - lockScreenTop; |
| 829 | // TODO(kprevas): this may not be necessary any more since we don't display the shelf in AOD |
| 830 | boolean anySectionHasVisibleChild = false; |
| 831 | for (NotificationSection section : mSections) { |
| 832 | if (section.getFirstVisibleChild() != null) { |
| 833 | anySectionHasVisibleChild = true; |
| 834 | break; |
| 835 | } |
| 836 | } |
| 837 | if (!mAmbientState.isDark() || anySectionHasVisibleChild) { |
| 838 | drawBackgroundRects(canvas, left, right, top, backgroundTopAnimationOffset); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 839 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 840 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 841 | updateClipping(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 844 | /** |
| 845 | * Draws round rects for each background section. |
| 846 | * |
| 847 | * We want to draw a round rect for each background section as defined by {@link #mSections}. |
| 848 | * However, if two sections are directly adjacent with no gap between them (e.g. on the |
| 849 | * lockscreen where the shelf can appear directly below the high priority section, or while |
| 850 | * scrolling the shade so that the top of the shelf is right at the bottom of the high priority |
| 851 | * section), we don't want to round the adjacent corners. |
| 852 | * |
| 853 | * Since {@link Canvas} doesn't provide a way to draw a half-rounded rect, this means that we |
| 854 | * need to coalesce the backgrounds for adjacent sections and draw them as a single round rect. |
| 855 | * This method tracks the top of each rect we need to draw, then iterates through the visible |
| 856 | * sections. If a section is not adjacent to the previous section, we draw the previous rect |
| 857 | * behind the sections we've accumulated up to that point, then start a new rect at the top of |
| 858 | * the current section. When we're done iterating we will always have one rect left to draw. |
| 859 | */ |
| 860 | private void drawBackgroundRects(Canvas canvas, int left, int right, int top, |
| 861 | int animationYOffset) { |
| 862 | int backgroundRectTop = top; |
| 863 | int lastSectionBottom = |
| 864 | mSections[0].getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 865 | int currentLeft = left; |
| 866 | int currentRight = right; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 867 | boolean first = true; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 868 | for (NotificationSection section : mSections) { |
| 869 | if (section.getFirstVisibleChild() == null) { |
| 870 | continue; |
| 871 | } |
| 872 | int sectionTop = section.getCurrentBounds().top + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 873 | int ownLeft = Math.min(Math.max(left, section.getCurrentBounds().left), right); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 874 | int ownRight = Math.max(Math.min(right, section.getCurrentBounds().right), ownLeft); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 875 | // If sections are directly adjacent to each other, we don't want to draw them |
| 876 | // as separate roundrects, as the rounded corners right next to each other look |
| 877 | // bad. |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 878 | if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 879 | || ((currentLeft != ownLeft || currentRight != ownRight) && !first)) { |
| 880 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 881 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 882 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 883 | lastSectionBottom, |
| 884 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 885 | backgroundRectTop = sectionTop; |
| 886 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 887 | currentLeft = ownLeft; |
| 888 | currentRight = ownRight; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 889 | lastSectionBottom = |
| 890 | section.getCurrentBounds().bottom + animationYOffset; |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 891 | first = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 892 | } |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 893 | canvas.drawRoundRect(currentLeft, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 894 | backgroundRectTop, |
Selim Cinek | 0acf430 | 2019-06-11 12:43:03 -0700 | [diff] [blame] | 895 | currentRight, |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 896 | lastSectionBottom, |
| 897 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 898 | } |
| 899 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 900 | private void drawHeadsUpBackground(Canvas canvas) { |
| 901 | int left = mSidePaddings; |
| 902 | int right = getWidth() - mSidePaddings; |
| 903 | |
| 904 | float top = getHeight(); |
| 905 | float bottom = 0; |
| 906 | int childCount = getChildCount(); |
| 907 | for (int i = 0; i < childCount; i++) { |
| 908 | View child = getChildAt(i); |
| 909 | if (child.getVisibility() != View.GONE |
| 910 | && child instanceof ExpandableNotificationRow) { |
| 911 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 912 | if ((row.isPinned() || row.isHeadsUpAnimatingAway()) && row.getTranslation() < 0 |
| 913 | && row.getProvider().shouldShowGutsOnSnapOpen()) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 914 | top = Math.min(top, row.getTranslationY()); |
| 915 | bottom = Math.max(bottom, row.getTranslationY() + row.getActualHeight()); |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | if (top < bottom) { |
| 921 | canvas.drawRoundRect( |
| 922 | left, top, right, bottom, |
| 923 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 924 | } |
| 925 | } |
| 926 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 927 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 928 | private void updateBackgroundDimming() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 929 | // No need to update the background color if it's not being drawn. |
| 930 | if (!mShouldDrawNotificationBackground) { |
| 931 | return; |
| 932 | } |
| 933 | |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 934 | // Interpolate between semi-transparent notification panel background color |
| 935 | // and white AOD separator. |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 936 | float colorInterpolation = MathUtils.smoothStep(0.4f /* start */, 1f /* end */, |
| 937 | mLinearDarkAmount); |
Felka Chang | 97bc8d5 | 2019-05-29 02:51:15 +0800 | [diff] [blame] | 938 | int color = ColorUtils.blendARGB(mBgColor, Color.WHITE, colorInterpolation); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 939 | |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 940 | if (mCachedBackgroundColor != color) { |
| 941 | mCachedBackgroundColor = color; |
| 942 | mBackgroundPaint.setColor(color); |
| 943 | invalidate(); |
| 944 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 947 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 948 | private void initView(Context context) { |
| 949 | mScroller = new OverScroller(getContext()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 950 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 951 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 952 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 953 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 954 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 955 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 956 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 957 | |
| 958 | Resources res = context.getResources(); |
| 959 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 960 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 961 | mAmbientState.reload(context); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 962 | mPaddingBetweenElements = Math.max(1, |
| 963 | res.getDimensionPixelSize(R.dimen.notification_divider_height)); |
| 964 | mIncreasedPaddingBetweenElements = |
| 965 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 966 | mMinTopOverScrollToEscape = res.getDimensionPixelSize( |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 967 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 968 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 969 | mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 970 | mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 971 | mMinInteractionHeight = res.getDimensionPixelSize( |
| 972 | R.dimen.notification_min_interaction_height); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 973 | mCornerRadius = res.getDimensionPixelSize( |
| 974 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 975 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 976 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 977 | } |
| 978 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 979 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 980 | private void notifyHeightChangeListener(ExpandableView view) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 981 | notifyHeightChangeListener(view, false /* needsAnimation */); |
| 982 | } |
| 983 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 984 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 985 | private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) { |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 986 | if (mOnHeightChangedListener != null) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 987 | mOnHeightChangedListener.onHeightChanged(view, needsAnimation); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 988 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 992 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 993 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 994 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 995 | |
| 996 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 997 | int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2, |
| 998 | MeasureSpec.getMode(widthMeasureSpec)); |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 999 | // Don't constrain the height of the children so we know how big they'd like to be |
| 1000 | int childHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), |
| 1001 | MeasureSpec.UNSPECIFIED); |
| 1002 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1003 | // We need to measure all children even the GONE ones, such that the heights are calculated |
| 1004 | // correctly as they are used to calculate how many we can fit on the screen. |
| 1005 | final int size = getChildCount(); |
| 1006 | for (int i = 0; i < size; i++) { |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame] | 1007 | measureChild(getChildAt(i), childWidthSpec, childHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1008 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1012 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1013 | 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] | 1014 | // we layout all our children centered on the top |
| 1015 | float centerX = getWidth() / 2.0f; |
| 1016 | for (int i = 0; i < getChildCount(); i++) { |
| 1017 | View child = getChildAt(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 1018 | // We need to layout all children even the GONE ones, such that the heights are |
| 1019 | // 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] | 1020 | float width = child.getMeasuredWidth(); |
| 1021 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1022 | child.layout((int) (centerX - width / 2.0f), |
| 1023 | 0, |
| 1024 | (int) (centerX + width / 2.0f), |
| 1025 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1026 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 1027 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1028 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1029 | clampScrollPosition(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1030 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 1031 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1032 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1035 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1036 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 1037 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1038 | mNeedViewResizeAnimation = true; |
| 1039 | mNeedsAnimation = true; |
| 1040 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1043 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1044 | public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) { |
| 1045 | mAmbientState.setSpeedBumpIndex(newIndex); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1046 | mNoAmbient = noAmbient; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1049 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1050 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1051 | public void setChildLocationsChangedListener( |
| 1052 | NotificationLogger.OnChildLocationsChangedListener listener) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1053 | mListener = listener; |
| 1054 | } |
| 1055 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1056 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1057 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1058 | public boolean isInVisibleLocation(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1059 | ExpandableNotificationRow row = entry.getRow(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1060 | ExpandableViewState childViewState = row.getViewState(); |
| 1061 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1062 | if (childViewState == null) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1063 | return false; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1064 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 1065 | if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1066 | return false; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 1067 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1068 | if (row.getVisibility() != View.VISIBLE) { |
| 1069 | return false; |
| 1070 | } |
| 1071 | return true; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1074 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1075 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 1076 | mMaxLayoutHeight = maxLayoutHeight; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 1077 | mShelf.setMaxLayoutHeight(maxLayoutHeight); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1078 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1079 | } |
| 1080 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1081 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1082 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1083 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1084 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1085 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1088 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1089 | private void updateAlgorithmLayoutMinHeight() { |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 1090 | mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition() |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1091 | ? getLayoutMinHeight() : 0); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1094 | /** |
| 1095 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 1096 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 1097 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1098 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1099 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1100 | updateScrollStateForAddedChildren(); |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 1101 | mAmbientState.setCurrentScrollVelocity(mScroller.isFinished() |
| 1102 | ? 0 |
| 1103 | : mScroller.getCurrVelocity()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1104 | if (ANCHOR_SCROLLING) { |
| 1105 | mAmbientState.setAnchorViewIndex(indexOfChild(mScrollAnchorView)); |
| 1106 | mAmbientState.setAnchorViewY(mScrollAnchorViewY); |
| 1107 | } else { |
| 1108 | mAmbientState.setScrollY(mOwnScrollY); |
| 1109 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 1110 | mStackScrollAlgorithm.resetViewStates(mAmbientState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1111 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1112 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1113 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1114 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1118 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1119 | private void onPreDrawDuringAnimation() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1120 | mShelf.updateAppearance(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1121 | updateClippingToTopRoundedCorner(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1122 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 1123 | updateBackground(); |
| 1124 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1127 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1128 | private void updateClippingToTopRoundedCorner() { |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1129 | Float clipStart = (float) mTopPadding |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1130 | + mStackTranslation |
| 1131 | + mAmbientState.getExpandAnimationTopChange(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1132 | Float clipEnd = clipStart + mCornerRadius; |
| 1133 | boolean first = true; |
| 1134 | for (int i = 0; i < getChildCount(); i++) { |
| 1135 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1136 | if (child.getVisibility() == GONE) { |
| 1137 | continue; |
| 1138 | } |
| 1139 | float start = child.getTranslationY(); |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 1140 | float end = start + child.getActualHeight(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1141 | boolean clip = clipStart > start && clipStart < end |
| 1142 | || clipEnd >= start && clipEnd <= end; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1143 | clip &= !(first && isScrolledToTop()); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 1144 | child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0) |
| 1145 | : ExpandableView.NO_ROUNDNESS); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 1146 | first = false; |
| 1147 | } |
| 1148 | } |
| 1149 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1150 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1151 | private void updateScrollStateForAddedChildren() { |
| 1152 | if (mChildrenToAddAnimated.isEmpty()) { |
| 1153 | return; |
| 1154 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1155 | if (!ANCHOR_SCROLLING) { |
| 1156 | for (int i = 0; i < getChildCount(); i++) { |
| 1157 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1158 | if (mChildrenToAddAnimated.contains(child)) { |
| 1159 | int startingPosition = getPositionInLinearLayout(child); |
| 1160 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
| 1161 | int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements |
| 1162 | : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements; |
| 1163 | int childHeight = getIntrinsicHeight(child) + padding; |
| 1164 | if (startingPosition < mOwnScrollY) { |
| 1165 | // This child starts off screen, so let's keep it offscreen to keep the |
| 1166 | // others visible |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1167 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1168 | setOwnScrollY(mOwnScrollY + childHeight); |
| 1169 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | clampScrollPosition(); |
| 1174 | } |
| 1175 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1176 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1177 | private void updateForcedScroll() { |
| 1178 | if (mForcedScroll != null && (!mForcedScroll.hasFocus() |
| 1179 | || !mForcedScroll.isAttachedToWindow())) { |
| 1180 | mForcedScroll = null; |
| 1181 | } |
| 1182 | if (mForcedScroll != null) { |
| 1183 | ExpandableView expandableView = (ExpandableView) mForcedScroll; |
| 1184 | int positionInLinearLayout = getPositionInLinearLayout(expandableView); |
| 1185 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1186 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1187 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1188 | if (ANCHOR_SCROLLING) { |
| 1189 | // TODO |
| 1190 | } else { |
| 1191 | targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange())); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1192 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1193 | // Only apply the scroll if we're scrolling the view upwards, or the view is so |
| 1194 | // far up that it is not visible anymore. |
| 1195 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1196 | setOwnScrollY(targetScroll); |
| 1197 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | } |
| 1201 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1202 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1203 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 1204 | if (!mChildrenUpdateRequested) { |
| 1205 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 1206 | mChildrenUpdateRequested = true; |
| 1207 | invalidate(); |
| 1208 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1209 | } |
| 1210 | |
Robert Snoeberger | 168949a | 2019-04-18 09:39:42 -0400 | [diff] [blame] | 1211 | /** |
| 1212 | * Returns best effort count of visible notifications. |
| 1213 | */ |
| 1214 | public int getVisibleNotificationCount() { |
| 1215 | int count = 0; |
| 1216 | for (int i = 0; i < getChildCount(); i++) { |
| 1217 | final View child = getChildAt(i); |
| 1218 | if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) { |
| 1219 | count++; |
| 1220 | } |
| 1221 | } |
| 1222 | return count; |
| 1223 | } |
| 1224 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1225 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1226 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1227 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1228 | } |
| 1229 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1230 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1231 | private void clampScrollPosition() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1232 | if (ANCHOR_SCROLLING) { |
| 1233 | // TODO |
| 1234 | } else { |
| 1235 | int scrollRange = getScrollRange(); |
| 1236 | if (scrollRange < mOwnScrollY) { |
| 1237 | setOwnScrollY(scrollRange); |
| 1238 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1242 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1243 | public int getTopPadding() { |
| 1244 | return mTopPadding; |
| 1245 | } |
| 1246 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1247 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1248 | private void setTopPadding(int topPadding, boolean animate) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 1249 | if (mTopPadding != topPadding) { |
| 1250 | mTopPadding = topPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1251 | updateAlgorithmHeightAndPadding(); |
| 1252 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1253 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1254 | mTopPaddingNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1255 | mNeedsAnimation = true; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1256 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1257 | requestChildrenUpdate(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1258 | notifyHeightChangeListener(null, animate); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | /** |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1263 | * Update the height of the panel. |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1264 | * |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1265 | * @param height the expanded height of the panel |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1266 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1267 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1268 | public void setExpandedHeight(float height) { |
| 1269 | mExpandedHeight = height; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1270 | setIsExpanded(height > 0); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1271 | int minExpansionHeight = getMinExpansionHeight(); |
| 1272 | if (height < minExpansionHeight) { |
| 1273 | mClipRect.left = 0; |
| 1274 | mClipRect.right = getWidth(); |
| 1275 | mClipRect.top = 0; |
| 1276 | mClipRect.bottom = (int) height; |
| 1277 | height = minExpansionHeight; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1278 | setRequestedClipBounds(mClipRect); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1279 | } else { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1280 | setRequestedClipBounds(null); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1281 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1282 | int stackHeight; |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1283 | float translationY; |
| 1284 | float appearEndPosition = getAppearEndPosition(); |
| 1285 | float appearStartPosition = getAppearStartPosition(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1286 | float appearFraction = 1.0f; |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 1287 | boolean appearing = height < appearEndPosition; |
| 1288 | mAmbientState.setAppearing(appearing); |
| 1289 | if (!appearing) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1290 | translationY = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 1291 | if (mShouldShowShelfOnly) { |
| 1292 | stackHeight = mTopPadding + mShelf.getIntrinsicHeight(); |
| 1293 | } else if (mQsExpanded) { |
| 1294 | int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding; |
| 1295 | int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight(); |
| 1296 | if (stackStartPosition <= stackEndPosition) { |
| 1297 | stackHeight = stackEndPosition; |
| 1298 | } else { |
| 1299 | stackHeight = (int) NotificationUtils.interpolate(stackStartPosition, |
| 1300 | stackEndPosition, mQsExpansionFraction); |
| 1301 | } |
| 1302 | } else { |
| 1303 | stackHeight = (int) height; |
| 1304 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1305 | } else { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1306 | appearFraction = getAppearFraction(height); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1307 | if (appearFraction >= 0) { |
| 1308 | translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0, |
| 1309 | appearFraction); |
| 1310 | } else { |
| 1311 | // This may happen when pushing up a heads up. We linearly push it up from the |
| 1312 | // start |
| 1313 | translationY = height - appearStartPosition + getExpandTranslationStart(); |
| 1314 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1315 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1316 | stackHeight = |
| 1317 | getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1318 | translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction); |
| 1319 | } else { |
| 1320 | stackHeight = (int) (height - translationY); |
| 1321 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1322 | } |
| 1323 | if (stackHeight != mCurrentStackHeight) { |
| 1324 | mCurrentStackHeight = stackHeight; |
| 1325 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1326 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1327 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1328 | setStackTranslation(translationY); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1329 | for (int i = 0; i < mExpandedHeightListeners.size(); i++) { |
| 1330 | BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i); |
| 1331 | listener.accept(mExpandedHeight, appearFraction); |
| 1332 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1335 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1336 | private void setRequestedClipBounds(Rect clipRect) { |
| 1337 | mRequestedClipBounds = clipRect; |
| 1338 | updateClipping(); |
| 1339 | } |
| 1340 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1341 | /** |
| 1342 | * Return the height of the content ignoring the footer. |
| 1343 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1344 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 1345 | public int getIntrinsicContentHeight() { |
| 1346 | return mIntrinsicContentHeight; |
| 1347 | } |
| 1348 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1349 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1350 | public void updateClipping() { |
| 1351 | boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode |
| 1352 | && !mHeadsUpAnimatingAway; |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1353 | boolean clipToOutline = false; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1354 | if (mIsClipped != clipped) { |
| 1355 | mIsClipped = clipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1356 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1357 | |
Selim Cinek | 1e05927 | 2019-05-21 18:15:00 -0700 | [diff] [blame] | 1358 | if (!mAmbientPulseManager.hasNotifications() && mAmbientState.isFullyDark()) { |
Lucas Dupin | 4798ea1 | 2018-11-05 19:26:24 -0800 | [diff] [blame] | 1359 | setClipBounds(null); |
| 1360 | } else if (mAmbientState.isDarkAtAll()) { |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1361 | clipToOutline = true; |
| 1362 | invalidateOutline(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1363 | } else if (clipped) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1364 | setClipBounds(mRequestedClipBounds); |
| 1365 | } else { |
| 1366 | setClipBounds(null); |
| 1367 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 1368 | |
| 1369 | setClipToOutline(clipToOutline); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * @return The translation at the beginning when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1374 | * Measured relative to the resting position. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1375 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1376 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1377 | private float getExpandTranslationStart() { |
Selim Cinek | 083f214 | 2018-11-06 16:32:23 -0800 | [diff] [blame] | 1378 | return -mTopPadding + getMinExpansionHeight() - mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /** |
| 1382 | * @return the position from where the appear transition starts when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1383 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1384 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1385 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1386 | private float getAppearStartPosition() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1387 | if (isHeadsUpTransition()) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1388 | return mHeadsUpInset |
| 1389 | + getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1390 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1391 | return getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1395 | * @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] | 1396 | * intrinsic height, which also includes whether the notification is system expanded and |
| 1397 | * is mainly used when dragging down from a heads up notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1398 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1399 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1400 | private int getTopHeadsUpPinnedHeight() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1401 | NotificationEntry topEntry = mHeadsUpManager.getTopEntry(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1402 | if (topEntry == null) { |
| 1403 | return 0; |
| 1404 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1405 | ExpandableNotificationRow row = topEntry.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1406 | if (row.isChildInGroup()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1407 | final NotificationEntry groupSummary |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1408 | = mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 1409 | if (groupSummary != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1410 | row = groupSummary.getRow(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1411 | } |
| 1412 | } |
| 1413 | return row.getPinnedHeadsUpHeight(); |
| 1414 | } |
| 1415 | |
| 1416 | /** |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1417 | * @return the position from where the appear transition ends when expanding. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1418 | * Measured in absolute height. |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1419 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1420 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1421 | private float getAppearEndPosition() { |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1422 | int appearPosition; |
Selim Cinek | 66440cf | 2017-05-26 13:48:47 -0700 | [diff] [blame] | 1423 | int notGoneChildCount = getNotGoneChildCount(); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 1424 | if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1425 | if (isHeadsUpTransition() |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 1426 | || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDark())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1427 | appearPosition = getTopHeadsUpPinnedHeight(); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1428 | } else { |
| 1429 | appearPosition = 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1430 | if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) { |
| 1431 | appearPosition += mShelf.getIntrinsicHeight(); |
| 1432 | } |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1433 | } |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1434 | } else { |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1435 | appearPosition = mEmptyShadeView.getHeight(); |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1436 | } |
| 1437 | return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1440 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1441 | private boolean isHeadsUpTransition() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 1442 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 1443 | return mTrackingHeadsUp && firstVisibleSection != null |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 1444 | && firstVisibleSection.getFirstVisibleChild().isAboveShelf(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1445 | } |
| 1446 | |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1447 | /** |
| 1448 | * @param height the height of the panel |
| 1449 | * @return the fraction of the appear animation that has been performed |
| 1450 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1451 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1452 | public float getAppearFraction(float height) { |
| 1453 | float appearEndPosition = getAppearEndPosition(); |
| 1454 | float appearStartPosition = getAppearStartPosition(); |
| 1455 | return (height - appearStartPosition) |
| 1456 | / (appearEndPosition - appearStartPosition); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1459 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1460 | public float getStackTranslation() { |
| 1461 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1464 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1465 | private void setStackTranslation(float stackTranslation) { |
| 1466 | if (stackTranslation != mStackTranslation) { |
| 1467 | mStackTranslation = stackTranslation; |
| 1468 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1469 | requestChildrenUpdate(); |
| 1470 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1474 | * 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] | 1475 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 1476 | * |
| 1477 | * @return either the layout height or the externally defined height, whichever is smaller |
| 1478 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1479 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1480 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1481 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 1482 | } |
| 1483 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1484 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1485 | public int getFirstItemMinHeight() { |
| 1486 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1487 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1488 | } |
| 1489 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1490 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1491 | public void setQsContainer(ViewGroup qsContainer) { |
| 1492 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1493 | } |
| 1494 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1495 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1496 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1497 | if (v instanceof ExpandableNotificationRow) { |
| 1498 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1499 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1500 | } |
| 1501 | return false; |
| 1502 | } |
| 1503 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1504 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1505 | private boolean isHeadsUp(View v) { |
| 1506 | if (v instanceof ExpandableNotificationRow) { |
| 1507 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1508 | return row.isHeadsUp(); |
| 1509 | } |
| 1510 | return false; |
| 1511 | } |
| 1512 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1513 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1514 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 1515 | getLocationOnScreen(mTempInt2); |
| 1516 | float localTouchY = touchY - mTempInt2[1]; |
| 1517 | |
| 1518 | ExpandableView closestChild = null; |
| 1519 | float minDist = Float.MAX_VALUE; |
| 1520 | |
| 1521 | // find the view closest to the location, accounting for GONE views |
| 1522 | final int count = getChildCount(); |
| 1523 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 1524 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 1525 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1526 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1527 | continue; |
| 1528 | } |
| 1529 | float childTop = slidingChild.getTranslationY(); |
| 1530 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1531 | float bottom = childTop + slidingChild.getActualHeight() |
| 1532 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1533 | |
| 1534 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 1535 | if (dist < minDist) { |
| 1536 | closestChild = slidingChild; |
| 1537 | minDist = dist; |
| 1538 | } |
| 1539 | } |
| 1540 | return closestChild; |
| 1541 | } |
| 1542 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1543 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
| 1544 | private ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1545 | return getChildAtPosition(touchX, touchY, true /* requireMinHeight */); |
| 1546 | |
| 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * Get the child at a certain screen location. |
| 1551 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1552 | * @param touchX the x coordinate |
| 1553 | * @param touchY the y coordinate |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1554 | * @param requireMinHeight Whether a minimum height is required for a child to be returned. |
| 1555 | * @return the child at the given location. |
| 1556 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1557 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1558 | private ExpandableView getChildAtPosition(float touchX, float touchY, |
| 1559 | boolean requireMinHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1560 | // find the view under the pointer, accounting for GONE views |
| 1561 | final int count = getChildCount(); |
| 1562 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1563 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1564 | if (slidingChild.getVisibility() != VISIBLE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1565 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1566 | continue; |
| 1567 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 1568 | float childTop = slidingChild.getTranslationY(); |
| 1569 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1570 | float bottom = childTop + slidingChild.getActualHeight() |
| 1571 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 1572 | |
| 1573 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 1574 | // camera affordance). |
| 1575 | int left = 0; |
| 1576 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1577 | |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1578 | if ((bottom - top >= mMinInteractionHeight || !requireMinHeight) |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1579 | && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1580 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 1581 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1582 | NotificationEntry entry = row.getEntry(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1583 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1584 | && mHeadsUpManager.getTopEntry().getRow() != row |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1585 | && mGroupManager.getGroupSummary( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1586 | mHeadsUpManager.getTopEntry().notification) |
| 1587 | != entry) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1588 | continue; |
| 1589 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1590 | return row.getViewAtPosition(touchY - childTop); |
| 1591 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1592 | return slidingChild; |
| 1593 | } |
| 1594 | } |
| 1595 | return null; |
| 1596 | } |
| 1597 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1598 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1599 | getLocationOnScreen(mTempInt2); |
| 1600 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1603 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1604 | public void setScrollingEnabled(boolean enable) { |
| 1605 | mScrollingEnabled = enable; |
| 1606 | } |
| 1607 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1608 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1609 | public void lockScrollTo(View v) { |
| 1610 | if (mForcedScroll == v) { |
| 1611 | return; |
| 1612 | } |
| 1613 | mForcedScroll = v; |
| 1614 | scrollTo(v); |
| 1615 | } |
| 1616 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1617 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1618 | public boolean scrollTo(View v) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1619 | ExpandableView expandableView = (ExpandableView) v; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1620 | if (ANCHOR_SCROLLING) { |
| 1621 | // TODO |
| 1622 | } else { |
| 1623 | int positionInLinearLayout = getPositionInLinearLayout(v); |
| 1624 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
| 1625 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1626 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1627 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 1628 | // that it is not visible anymore. |
| 1629 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
| 1630 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY); |
| 1631 | mDontReportNextOverScroll = true; |
| 1632 | animateScroll(); |
| 1633 | return true; |
| 1634 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1635 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1636 | return false; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1639 | /** |
| 1640 | * @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] | 1641 | * the IME. |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1642 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1643 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1644 | private int targetScrollForView(ExpandableView v, int positionInLinearLayout) { |
| 1645 | return positionInLinearLayout + v.getIntrinsicHeight() + |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 1646 | getImeInset() - getHeight() |
| 1647 | + ((!isExpanded() && isPinnedHeadsUp(v)) ? mHeadsUpInset : getTopPadding()); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1648 | } |
| 1649 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1650 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1651 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1652 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1653 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1654 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1655 | if (ANCHOR_SCROLLING) { |
| 1656 | // TODO |
| 1657 | } else { |
| 1658 | int range = getScrollRange(); |
| 1659 | if (mOwnScrollY > range) { |
| 1660 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1661 | // animating away. To work around that we'll wait until things have settled. |
| 1662 | removeCallbacks(mReclamp); |
| 1663 | postDelayed(mReclamp, 50); |
| 1664 | } else if (mForcedScroll != null) { |
| 1665 | // The scroll was requested before we got the actual inset - in case we need |
| 1666 | // to scroll up some more do so now. |
| 1667 | scrollTo(mForcedScroll); |
| 1668 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1669 | } |
| 1670 | return insets; |
| 1671 | } |
| 1672 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1673 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1674 | private Runnable mReclamp = new Runnable() { |
| 1675 | @Override |
| 1676 | public void run() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1677 | if (ANCHOR_SCROLLING) { |
| 1678 | // TODO |
| 1679 | } else { |
| 1680 | int range = getScrollRange(); |
| 1681 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1682 | } |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1683 | mDontReportNextOverScroll = true; |
| 1684 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1685 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1686 | } |
| 1687 | }; |
| 1688 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1689 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 1690 | public void setExpandingEnabled(boolean enable) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1691 | mExpandHelper.setEnabled(enable); |
| 1692 | } |
| 1693 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1694 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1695 | private boolean isScrollingEnabled() { |
| 1696 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1697 | } |
| 1698 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1699 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1700 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1701 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1702 | } |
| 1703 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1704 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1705 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1706 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1707 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1708 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1709 | float densityScale = getResources().getDisplayMetrics().density; |
| 1710 | mSwipeHelper.setDensityScale(densityScale); |
| 1711 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1712 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1713 | initView(getContext()); |
| 1714 | } |
| 1715 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1716 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1717 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1718 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1719 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1720 | } |
| 1721 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1722 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1723 | private void snapViewIfNeeded(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1724 | ExpandableNotificationRow child = entry.getRow(); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1725 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1726 | // If the child is showing the notification menu snap to that |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 1727 | if (child.getProvider() != null) { |
| 1728 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
| 1729 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
| 1730 | } |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1731 | } |
| 1732 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1733 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1734 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1735 | public ViewGroup getViewParentForNotification(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1736 | return this; |
| 1737 | } |
| 1738 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1739 | /** |
| 1740 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1741 | * |
| 1742 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1743 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1744 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1745 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 1746 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1747 | private float overScrollUp(int deltaY, int range) { |
| 1748 | deltaY = Math.max(deltaY, 0); |
| 1749 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1750 | float newTopAmount = currentTopAmount - deltaY; |
| 1751 | if (currentTopAmount > 0) { |
| 1752 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1753 | false /* animate */); |
| 1754 | } |
| 1755 | // Top overScroll might not grab all scrolling motion, |
| 1756 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1757 | if (ANCHOR_SCROLLING) { |
| 1758 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1759 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1760 | ExpandableView lastRow = getLastRowNotGone(); |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1761 | if (lastRow != null && !lastRow.isInShelf()) { |
| 1762 | float distanceToMax = Math.max(0, getMaxPositiveScrollAmount()); |
| 1763 | if (scrollAmount > distanceToMax) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1764 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1765 | // We overScroll on the bottom |
| 1766 | setOverScrolledPixels(currentBottomPixels + (scrollAmount - distanceToMax), |
| 1767 | false /* onTop */, |
| 1768 | false /* animate */); |
| 1769 | mScrollAnchorViewY -= distanceToMax; |
| 1770 | scrollAmount = 0f; |
| 1771 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1772 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1773 | return scrollAmount; |
| 1774 | } else { |
| 1775 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1776 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1777 | if (newScrollY > range) { |
| 1778 | if (!mExpandedInThisMotion) { |
| 1779 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1780 | // We overScroll on the bottom |
| 1781 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1782 | false /* onTop */, |
| 1783 | false /* animate */); |
| 1784 | } |
| 1785 | setOwnScrollY(range); |
| 1786 | scrollAmount = 0.0f; |
| 1787 | } |
| 1788 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1789 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | /** |
| 1793 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1794 | * |
| 1795 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1796 | * @return The amount of scrolling to be performed by the scroller, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1797 | * not handled by the overScroll amount. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1798 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1799 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1800 | private float overScrollDown(int deltaY) { |
| 1801 | deltaY = Math.min(deltaY, 0); |
| 1802 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1803 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1804 | if (currentBottomAmount > 0) { |
| 1805 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1806 | false /* animate */); |
| 1807 | } |
| 1808 | // Bottom overScroll might not grab all scrolling motion, |
| 1809 | // we have to scroll as well. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1810 | if (ANCHOR_SCROLLING) { |
| 1811 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1812 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 1813 | ExpandableView firstChild = getFirstChildNotGone(); |
| 1814 | float top = firstChild.getTranslationY(); |
| 1815 | float distanceToTop = mScrollAnchorView.getTranslationY() - top - mScrollAnchorViewY; |
| 1816 | if (distanceToTop < -scrollAmount) { |
| 1817 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1818 | // We overScroll on the top |
| 1819 | setOverScrolledPixels(currentTopPixels + (-scrollAmount - distanceToTop), |
| 1820 | true /* onTop */, |
| 1821 | false /* animate */); |
| 1822 | mScrollAnchorView = firstChild; |
| 1823 | mScrollAnchorViewY = 0; |
| 1824 | scrollAmount = 0f; |
| 1825 | } |
| 1826 | return scrollAmount; |
| 1827 | } else { |
| 1828 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1829 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1830 | if (newScrollY < 0) { |
| 1831 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1832 | // We overScroll on the top |
| 1833 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1834 | true /* onTop */, |
| 1835 | false /* animate */); |
| 1836 | setOwnScrollY(0); |
| 1837 | scrollAmount = 0.0f; |
| 1838 | } |
| 1839 | return scrollAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1840 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1841 | } |
| 1842 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1843 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1844 | private void initVelocityTrackerIfNotExists() { |
| 1845 | if (mVelocityTracker == null) { |
| 1846 | mVelocityTracker = VelocityTracker.obtain(); |
| 1847 | } |
| 1848 | } |
| 1849 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1850 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1851 | private void recycleVelocityTracker() { |
| 1852 | if (mVelocityTracker != null) { |
| 1853 | mVelocityTracker.recycle(); |
| 1854 | mVelocityTracker = null; |
| 1855 | } |
| 1856 | } |
| 1857 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1858 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1859 | private void initOrResetVelocityTracker() { |
| 1860 | if (mVelocityTracker == null) { |
| 1861 | mVelocityTracker = VelocityTracker.obtain(); |
| 1862 | } else { |
| 1863 | mVelocityTracker.clear(); |
| 1864 | } |
| 1865 | } |
| 1866 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1867 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1868 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1869 | mFinishScrollingCallback = runnable; |
| 1870 | } |
| 1871 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1872 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1873 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1874 | if (mScroller.computeScrollOffset()) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1875 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1876 | int oldY = mLastScrollerY; |
| 1877 | int y = mScroller.getCurrY(); |
| 1878 | int deltaY = y - oldY; |
| 1879 | if (deltaY != 0) { |
| 1880 | int maxNegativeScrollAmount = getMaxNegativeScrollAmount(); |
| 1881 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 1882 | if ((maxNegativeScrollAmount < 0 && deltaY < maxNegativeScrollAmount) |
| 1883 | || (maxPositiveScrollAmount > 0 && deltaY > maxPositiveScrollAmount)) { |
| 1884 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1885 | // the current velocity |
| 1886 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1887 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1888 | customOverScrollBy(deltaY, oldY, 0, (int) mMaxOverScroll); |
| 1889 | mLastScrollerY = y; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1890 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1891 | } else { |
| 1892 | int oldY = mOwnScrollY; |
| 1893 | int y = mScroller.getCurrY(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1894 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1895 | if (oldY != y) { |
| 1896 | int range = getScrollRange(); |
| 1897 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1898 | // This frame takes us into overscroll, so set the max overscroll based on |
| 1899 | // the current velocity |
| 1900 | setMaxOverScrollFromCurrentVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1901 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1902 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1903 | if (mDontClampNextScroll) { |
| 1904 | range = Math.max(range, oldY); |
| 1905 | } |
| 1906 | customOverScrollBy(y - oldY, oldY, range, |
| 1907 | (int) (mMaxOverScroll)); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1908 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1909 | } |
| 1910 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1911 | postOnAnimation(mReflingAndAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1912 | } else { |
| 1913 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1914 | if (mFinishScrollingCallback != null) { |
| 1915 | mFinishScrollingCallback.run(); |
| 1916 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1920 | private void setMaxOverScrollFromCurrentVelocity() { |
| 1921 | float currVelocity = mScroller.getCurrVelocity(); |
| 1922 | if (currVelocity >= mMinimumVelocity) { |
| 1923 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1924 | } |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1925 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1926 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1927 | /** |
| 1928 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 1929 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 1930 | * |
| 1931 | * This method performs the determination of whether we're exceeding the overscroll and clamps |
| 1932 | * the scroll amount if so. The actual scrolling/overscrolling happens in |
| 1933 | * {@link #onCustomOverScrolled(int, boolean)} (absolute scrolling) or |
| 1934 | * {@link #onCustomOverScrolledBy(int, boolean)} (anchor scrolling). |
| 1935 | * |
| 1936 | * @param deltaY The (signed) number of pixels to scroll. |
| 1937 | * @param scrollY The current scroll position (absolute scrolling only). |
| 1938 | * @param scrollRangeY The maximum allowable scroll position (absolute scrolling only). |
| 1939 | * @param maxOverScrollY The current (unsigned) limit on number of pixels to overscroll by. |
| 1940 | */ |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1941 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1942 | private void customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, int maxOverScrollY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1943 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 1944 | boolean clampedY = false; |
| 1945 | if (deltaY < 0) { |
| 1946 | int maxScrollAmount = getMaxNegativeScrollAmount(); |
| 1947 | if (maxScrollAmount > Integer.MIN_VALUE) { |
| 1948 | maxScrollAmount -= maxOverScrollY; |
| 1949 | if (deltaY < maxScrollAmount) { |
| 1950 | deltaY = maxScrollAmount; |
| 1951 | clampedY = true; |
| 1952 | } |
| 1953 | } |
| 1954 | } else { |
| 1955 | int maxScrollAmount = getMaxPositiveScrollAmount(); |
| 1956 | if (maxScrollAmount < Integer.MAX_VALUE) { |
| 1957 | maxScrollAmount += maxOverScrollY; |
| 1958 | if (deltaY > maxScrollAmount) { |
| 1959 | deltaY = maxScrollAmount; |
| 1960 | clampedY = true; |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | onCustomOverScrolledBy(deltaY, clampedY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1965 | } else { |
| 1966 | int newScrollY = scrollY + deltaY; |
| 1967 | final int top = -maxOverScrollY; |
| 1968 | final int bottom = maxOverScrollY + scrollRangeY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1969 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1970 | boolean clampedY = false; |
| 1971 | if (newScrollY > bottom) { |
| 1972 | newScrollY = bottom; |
| 1973 | clampedY = true; |
| 1974 | } else if (newScrollY < top) { |
| 1975 | newScrollY = top; |
| 1976 | clampedY = true; |
| 1977 | } |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1978 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 1979 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1980 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | /** |
| 1984 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1985 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1986 | * same overScroll edge. |
| 1987 | * |
| 1988 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 1989 | * the rubber-banding logic. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 1990 | * @param onTop Should the effect be applied on top of the scroller. |
| 1991 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1992 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 1993 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1994 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1995 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | /** |
| 1999 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2000 | * By default this will also cancel animations on the same overScroll edge. |
| 2001 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2002 | * @param amount The amount to overScroll by. |
| 2003 | * @param onTop Should the effect be applied on top of the scroller. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2004 | * @param animate Should an animation be performed. |
| 2005 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2006 | |
| 2007 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2008 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 2009 | setOverScrollAmount(amount, onTop, animate, true); |
| 2010 | } |
| 2011 | |
| 2012 | /** |
| 2013 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2014 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2015 | * @param amount The amount to overScroll by. |
| 2016 | * @param onTop Should the effect be applied on top of the scroller. |
| 2017 | * @param animate Should an animation be performed. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2018 | * @param cancelAnimators Should running animations be cancelled. |
| 2019 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2020 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2021 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2022 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2023 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 2024 | } |
| 2025 | |
| 2026 | /** |
| 2027 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 2028 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2029 | * @param amount The amount to overScroll by. |
| 2030 | * @param onTop Should the effect be applied on top of the scroller. |
| 2031 | * @param animate Should an animation be performed. |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2032 | * @param cancelAnimators Should running animations be cancelled. |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2033 | * @param isRubberbanded The value which will be passed to |
| 2034 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2035 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2036 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2037 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 2038 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2039 | if (cancelAnimators) { |
| 2040 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 2041 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2042 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2043 | } |
| 2044 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2045 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2046 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 2047 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2048 | amount = Math.max(0, amount); |
| 2049 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2050 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2051 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2052 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2053 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2054 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2055 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2056 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2057 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2061 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2062 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2063 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 2064 | if (mDontReportNextOverScroll) { |
| 2065 | mDontReportNextOverScroll = false; |
| 2066 | return; |
| 2067 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2068 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2069 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2073 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2074 | public void setOverscrollTopChangedListener( |
| 2075 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 2076 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 2077 | } |
| 2078 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2079 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2080 | public float getCurrentOverScrollAmount(boolean top) { |
| 2081 | return mAmbientState.getOverScrollAmount(top); |
| 2082 | } |
| 2083 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2084 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2085 | public float getCurrentOverScrolledPixels(boolean top) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2086 | return top ? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2087 | } |
| 2088 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2089 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2090 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2091 | if (onTop) { |
| 2092 | mOverScrolledTopPixels = amount; |
| 2093 | } else { |
| 2094 | mOverScrolledBottomPixels = amount; |
| 2095 | } |
| 2096 | } |
| 2097 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2098 | /** |
| 2099 | * Scrolls by the given delta, overscrolling if needed. If called during a fling and the delta |
| 2100 | * would cause us to exceed the provided maximum overscroll, springs back instead. |
| 2101 | * |
| 2102 | * @param deltaY The (signed) number of pixels to scroll. |
| 2103 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2104 | * the overscroll limit. |
| 2105 | */ |
| 2106 | private void onCustomOverScrolledBy(int deltaY, boolean clampedY) { |
| 2107 | assert ANCHOR_SCROLLING; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2108 | mScrollAnchorViewY -= deltaY; |
| 2109 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2110 | if (!mScroller.isFinished()) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2111 | if (clampedY) { |
| 2112 | springBack(); |
| 2113 | } else { |
| 2114 | float overScrollTop = getCurrentOverScrollAmount(true /* top */); |
| 2115 | if (isScrolledToTop() && mScrollAnchorViewY > 0) { |
| 2116 | notifyOverscrollTopListener(mScrollAnchorViewY, |
| 2117 | isRubberbanded(true /* onTop */)); |
| 2118 | } else { |
| 2119 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true /* onTop */)); |
| 2120 | } |
| 2121 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2122 | } |
| 2123 | updateScrollAnchor(); |
| 2124 | updateOnScrollChange(); |
| 2125 | } |
| 2126 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2127 | /** |
| 2128 | * Scrolls to the given position, overscrolling if needed. If called during a fling and the |
| 2129 | * position exceeds the provided maximum overscroll, springs back instead. |
| 2130 | * |
| 2131 | * @param scrollY The target scroll position. |
| 2132 | * @param clampedY Whether this value was clamped by the calling method, meaning we've reached |
| 2133 | * the overscroll limit. |
| 2134 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2135 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2136 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2137 | assert !ANCHOR_SCROLLING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2138 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2139 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2140 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2141 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2142 | springBack(); |
| 2143 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2144 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2145 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2146 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2147 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2148 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2149 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2150 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2151 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2152 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2156 | /** |
| 2157 | * Springs back from an overscroll by stopping the {@link #mScroller} and animating the |
| 2158 | * overscroll amount back to zero. |
| 2159 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2160 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2161 | private void springBack() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2162 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2163 | boolean overScrolledTop = isScrolledToTop() && mScrollAnchorViewY > 0; |
| 2164 | int maxPositiveScrollAmount = getMaxPositiveScrollAmount(); |
| 2165 | boolean overscrolledBottom = maxPositiveScrollAmount < 0; |
| 2166 | if (overScrolledTop || overscrolledBottom) { |
| 2167 | float newAmount; |
| 2168 | if (overScrolledTop) { |
| 2169 | newAmount = mScrollAnchorViewY; |
| 2170 | mScrollAnchorViewY = 0; |
| 2171 | mDontReportNextOverScroll = true; |
| 2172 | } else { |
| 2173 | newAmount = -maxPositiveScrollAmount; |
| 2174 | mScrollAnchorViewY -= maxPositiveScrollAmount; |
| 2175 | } |
| 2176 | setOverScrollAmount(newAmount, overScrolledTop, false); |
| 2177 | setOverScrollAmount(0.0f, overScrolledTop, true); |
| 2178 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2179 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2180 | } else { |
| 2181 | int scrollRange = getScrollRange(); |
| 2182 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2183 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2184 | if (overScrolledTop || overScrolledBottom) { |
| 2185 | boolean onTop; |
| 2186 | float newAmount; |
| 2187 | if (overScrolledTop) { |
| 2188 | onTop = true; |
| 2189 | newAmount = -mOwnScrollY; |
| 2190 | setOwnScrollY(0); |
| 2191 | mDontReportNextOverScroll = true; |
| 2192 | } else { |
| 2193 | onTop = false; |
| 2194 | newAmount = mOwnScrollY - scrollRange; |
| 2195 | setOwnScrollY(scrollRange); |
| 2196 | } |
| 2197 | setOverScrollAmount(newAmount, onTop, false); |
| 2198 | setOverScrollAmount(0.0f, onTop, true); |
| 2199 | mScroller.forceFinished(true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2200 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2201 | } |
| 2202 | } |
| 2203 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2204 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2205 | private int getScrollRange() { |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2206 | // In current design, it only use the top HUN to treat all of HUNs |
| 2207 | // although there are more than one HUNs |
| 2208 | int contentHeight = mContentHeight; |
| 2209 | if (!isExpanded() && mHeadsUpManager.hasPinnedHeadsUp()) { |
| 2210 | contentHeight = mHeadsUpInset + getTopHeadsUpPinnedHeight(); |
| 2211 | } |
| 2212 | int scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2213 | int imeInset = getImeInset(); |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 2214 | scrollRange += Math.min(imeInset, Math.max(0, contentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2215 | return scrollRange; |
| 2216 | } |
| 2217 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2218 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2219 | private int getImeInset() { |
| 2220 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2221 | } |
| 2222 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2223 | /** |
| 2224 | * @return the first child which has visibility unequal to GONE |
| 2225 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2226 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2227 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2228 | int childCount = getChildCount(); |
| 2229 | for (int i = 0; i < childCount; i++) { |
| 2230 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2231 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2232 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | return null; |
| 2236 | } |
| 2237 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2238 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2239 | * @return the child before the given view which has visibility unequal to GONE |
| 2240 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2241 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2242 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2243 | ExpandableView previousView = null; |
| 2244 | int childCount = getChildCount(); |
| 2245 | for (int i = 0; i < childCount; i++) { |
| 2246 | View child = getChildAt(i); |
| 2247 | if (child == view) { |
| 2248 | return previousView; |
| 2249 | } |
| 2250 | if (child.getVisibility() != View.GONE) { |
| 2251 | previousView = (ExpandableView) child; |
| 2252 | } |
| 2253 | } |
| 2254 | return null; |
| 2255 | } |
| 2256 | |
| 2257 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2258 | * @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] | 2259 | * given translationY or equal to it. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2260 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2261 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2262 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2263 | int childCount = getChildCount(); |
| 2264 | for (int i = 0; i < childCount; i++) { |
| 2265 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2266 | if (child.getVisibility() == View.GONE) { |
| 2267 | continue; |
| 2268 | } |
| 2269 | float rowTranslation = child.getTranslationY(); |
| 2270 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2271 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2272 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2273 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2274 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2275 | List<ExpandableNotificationRow> notificationChildren = |
| 2276 | row.getNotificationChildren(); |
| 2277 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2278 | childIndex++) { |
| 2279 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2280 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2281 | return rowChild; |
| 2282 | } |
| 2283 | } |
| 2284 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | return null; |
| 2288 | } |
| 2289 | |
| 2290 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2291 | * @return the last child which has visibility unequal to GONE |
| 2292 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2293 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2294 | public ExpandableView getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2295 | int childCount = getChildCount(); |
| 2296 | for (int i = childCount - 1; i >= 0; i--) { |
| 2297 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2298 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2299 | return (ExpandableView) child; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | return null; |
| 2303 | } |
| 2304 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2305 | private ExpandableNotificationRow getLastRowNotGone() { |
| 2306 | int childCount = getChildCount(); |
| 2307 | for (int i = childCount - 1; i >= 0; i--) { |
| 2308 | View child = getChildAt(i); |
| 2309 | if (child instanceof ExpandableNotificationRow && child.getVisibility() != View.GONE) { |
| 2310 | return (ExpandableNotificationRow) child; |
| 2311 | } |
| 2312 | } |
| 2313 | return null; |
| 2314 | } |
| 2315 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2316 | /** |
| 2317 | * @return the number of children which have visibility unequal to GONE |
| 2318 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2319 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2320 | public int getNotGoneChildCount() { |
| 2321 | int childCount = getChildCount(); |
| 2322 | int count = 0; |
| 2323 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2324 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2325 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2326 | count++; |
| 2327 | } |
| 2328 | } |
| 2329 | return count; |
| 2330 | } |
| 2331 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2332 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2333 | private void updateContentHeight() { |
| 2334 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2335 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2336 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2337 | int numShownItems = 0; |
| 2338 | boolean finish = false; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2339 | int maxDisplayedNotifications = mMaxDisplayedNotifications; |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2340 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2341 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2342 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2343 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2344 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2345 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2346 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2347 | && numShownItems >= maxDisplayedNotifications; |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 2348 | if (limitReached) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2349 | expandableView = mShelf; |
| 2350 | finish = true; |
| 2351 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2352 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2353 | float padding; |
| 2354 | if (increasedPaddingAmount >= 0.0f) { |
| 2355 | padding = (int) NotificationUtils.interpolate( |
| 2356 | previousPaddingRequest, |
| 2357 | mIncreasedPaddingBetweenElements, |
| 2358 | increasedPaddingAmount); |
| 2359 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2360 | mPaddingBetweenElements, |
| 2361 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2362 | increasedPaddingAmount); |
| 2363 | } else { |
| 2364 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2365 | 0, |
| 2366 | mPaddingBetweenElements, |
| 2367 | 1.0f + increasedPaddingAmount); |
| 2368 | if (previousPaddingAmount > 0.0f) { |
| 2369 | padding = (int) NotificationUtils.interpolate( |
| 2370 | ownPadding, |
| 2371 | mIncreasedPaddingBetweenElements, |
| 2372 | previousPaddingAmount); |
| 2373 | } else { |
| 2374 | padding = ownPadding; |
| 2375 | } |
| 2376 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2377 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2378 | if (height != 0) { |
| 2379 | height += padding; |
| 2380 | } |
| 2381 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2382 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2383 | numShownItems++; |
| 2384 | if (finish) { |
| 2385 | break; |
| 2386 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2387 | } |
| 2388 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2389 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2390 | |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 2391 | mContentHeight = height + mTopPadding + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2392 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2393 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2394 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2397 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2398 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2399 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2400 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2403 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2404 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2405 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2406 | if (scrollable != mScrollable) { |
| 2407 | mScrollable = scrollable; |
| 2408 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2409 | updateForwardAndBackwardScrollability(); |
| 2410 | } |
| 2411 | } |
| 2412 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2413 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2414 | private void updateForwardAndBackwardScrollability() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2415 | boolean forwardScrollable = mScrollable && !isScrolledToBottom(); |
| 2416 | boolean backwardsScrollable = mScrollable && !isScrolledToTop(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2417 | boolean changed = forwardScrollable != mForwardScrollable |
| 2418 | || backwardsScrollable != mBackwardScrollable; |
| 2419 | mForwardScrollable = forwardScrollable; |
| 2420 | mBackwardScrollable = backwardsScrollable; |
| 2421 | if (changed) { |
| 2422 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2423 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2424 | } |
| 2425 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2426 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2427 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2428 | // 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] | 2429 | if (!mShouldDrawNotificationBackground || mAmbientState.isFullyDark()) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2430 | return; |
| 2431 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2432 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2433 | updateBackgroundBounds(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2434 | if (didSectionBoundsChange()) { |
| 2435 | boolean animate = mAnimateNextSectionBoundsChange || mAnimateNextBackgroundTop |
| 2436 | || mAnimateNextBackgroundBottom || areSectionBoundsAnimating(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2437 | if (!isExpanded()) { |
| 2438 | abortBackgroundAnimators(); |
| 2439 | animate = false; |
| 2440 | } |
| 2441 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2442 | startBackgroundAnimation(); |
| 2443 | } else { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2444 | for (NotificationSection section : mSections) { |
| 2445 | section.resetCurrentBounds(); |
| 2446 | } |
Lucas Dupin | 90a38dd | 2018-09-05 09:37:37 -0700 | [diff] [blame] | 2447 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2448 | } |
| 2449 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2450 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2451 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2452 | mAnimateNextBackgroundTop = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2453 | mAnimateNextBackgroundBottom = false; |
| 2454 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2455 | } |
| 2456 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2457 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2458 | private void abortBackgroundAnimators() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2459 | for (NotificationSection section : mSections) { |
| 2460 | section.cancelAnimators(); |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2464 | private boolean didSectionBoundsChange() { |
| 2465 | for (NotificationSection section : mSections) { |
| 2466 | if (section.didBoundsChange()) { |
| 2467 | return true; |
| 2468 | } |
| 2469 | } |
| 2470 | return false; |
| 2471 | } |
| 2472 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2473 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2474 | private boolean areSectionBoundsAnimating() { |
| 2475 | for (NotificationSection section : mSections) { |
| 2476 | if (section.areBoundsAnimating()) { |
| 2477 | return true; |
| 2478 | } |
| 2479 | } |
| 2480 | return false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2481 | } |
| 2482 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2483 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2484 | private void startBackgroundAnimation() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2485 | // TODO(kprevas): do we still need separate fields for top/bottom? |
| 2486 | // or can each section manage its own animation state? |
| 2487 | NotificationSection firstVisibleSection = getFirstVisibleSection(); |
| 2488 | NotificationSection lastVisibleSection = getLastVisibleSection(); |
| 2489 | for (NotificationSection section : mSections) { |
| 2490 | section.startBackgroundAnimation( |
| 2491 | section == firstVisibleSection |
| 2492 | ? mAnimateNextBackgroundTop |
| 2493 | : mAnimateNextSectionBoundsChange, |
| 2494 | section == lastVisibleSection |
| 2495 | ? mAnimateNextBackgroundBottom |
| 2496 | : mAnimateNextSectionBoundsChange); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2497 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | /** |
| 2501 | * Update the background bounds to the new desired bounds |
| 2502 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2503 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2504 | private void updateBackgroundBounds() { |
shawnlin | 2771672 | 2019-04-17 20:09:45 +0800 | [diff] [blame] | 2505 | int left = mSidePaddings; |
| 2506 | int right = getWidth() - mSidePaddings; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2507 | for (NotificationSection section : mSections) { |
| 2508 | section.getBounds().left = left; |
| 2509 | section.getBounds().right = right; |
| 2510 | } |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2511 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2512 | if (!mIsExpanded) { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2513 | for (NotificationSection section : mSections) { |
| 2514 | section.getBounds().top = 0; |
| 2515 | section.getBounds().bottom = 0; |
| 2516 | } |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2517 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2518 | } |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2519 | int minTopPosition = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2520 | NotificationSection lastSection = getLastVisibleSection(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 2521 | if (mStatusBarState != StatusBarState.KEYGUARD) { |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2522 | minTopPosition = (int) (mTopPadding + mStackTranslation); |
| 2523 | } else if (lastSection == null) { |
| 2524 | minTopPosition = mTopPadding; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2525 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2526 | boolean shiftPulsingWithFirst = mAmbientPulseManager.getAllEntries().count() <= 1; |
Selim Cinek | 3fe7e7e | 2019-02-15 18:40:53 -0800 | [diff] [blame] | 2527 | for (NotificationSection section : mSections) { |
| 2528 | int minBottomPosition = minTopPosition; |
| 2529 | if (section == lastSection) { |
| 2530 | // 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] | 2531 | minBottomPosition = (int) (ViewState.getFinalTranslationY(mShelf) |
| 2532 | + mShelf.getIntrinsicHeight()); |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2533 | } |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 2534 | minTopPosition = section.updateBounds(minTopPosition, minBottomPosition, |
| 2535 | shiftPulsingWithFirst); |
| 2536 | shiftPulsingWithFirst = false; |
Gus Prevas | e83700cb | 2018-12-14 11:42:51 -0500 | [diff] [blame] | 2537 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2540 | private NotificationSection getFirstVisibleSection() { |
| 2541 | for (NotificationSection section : mSections) { |
| 2542 | if (section.getFirstVisibleChild() != null) { |
| 2543 | return section; |
| 2544 | } |
| 2545 | } |
| 2546 | return null; |
| 2547 | } |
| 2548 | |
| 2549 | private NotificationSection getLastVisibleSection() { |
| 2550 | for (int i = mSections.length - 1; i >= 0; i--) { |
| 2551 | NotificationSection section = mSections[i]; |
| 2552 | if (section.getLastVisibleChild() != null) { |
| 2553 | return section; |
| 2554 | } |
| 2555 | } |
| 2556 | return null; |
| 2557 | } |
| 2558 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2559 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2560 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2561 | int childCount = getChildCount(); |
| 2562 | for (int i = childCount - 1; i >= 0; i--) { |
| 2563 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2564 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2565 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2566 | return (ActivatableNotificationView) child; |
| 2567 | } |
| 2568 | } |
| 2569 | return null; |
| 2570 | } |
| 2571 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2572 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2573 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2574 | int childCount = getChildCount(); |
| 2575 | for (int i = 0; i < childCount; i++) { |
| 2576 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2577 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2578 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2579 | return (ActivatableNotificationView) child; |
| 2580 | } |
| 2581 | } |
| 2582 | return null; |
| 2583 | } |
| 2584 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2585 | /** |
| 2586 | * Fling the scroll view |
| 2587 | * |
| 2588 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2589 | * numbers mean that the finger/cursor is moving down the screen, |
| 2590 | * which means we want to scroll towards the top. |
| 2591 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2592 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2593 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2594 | if (getChildCount() > 0) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2595 | float topAmount = getCurrentOverScrollAmount(true); |
| 2596 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2597 | if (velocityY < 0 && topAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2598 | if (ANCHOR_SCROLLING) { |
| 2599 | mScrollAnchorViewY += topAmount; |
| 2600 | } else { |
| 2601 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
| 2602 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2603 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2604 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2605 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2606 | * mOverflingDistance + topAmount; |
| 2607 | } else if (velocityY > 0 && bottomAmount > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2608 | if (ANCHOR_SCROLLING) { |
| 2609 | mScrollAnchorViewY -= bottomAmount; |
| 2610 | } else { |
| 2611 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
| 2612 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2613 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2614 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2615 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2616 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2617 | } else { |
| 2618 | // it will be set once we reach the boundary |
| 2619 | mMaxOverScroll = 0.0f; |
| 2620 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2621 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2622 | flingScroller(velocityY); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 2623 | } else { |
| 2624 | int scrollRange = getScrollRange(); |
| 2625 | int minScrollY = Math.max(0, scrollRange); |
| 2626 | if (mExpandedInThisMotion) { |
| 2627 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2628 | } |
| 2629 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2630 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2631 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2632 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2633 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2637 | /** |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 2638 | * Flings the overscroller with the given velocity (anchor-based scrolling). |
| 2639 | * |
| 2640 | * Because anchor-based scrolling can't track the current scroll position, the overscroller is |
| 2641 | * always started at startY = 0, and we interpret the positions it computes as relative to the |
| 2642 | * start of the scroll. |
| 2643 | */ |
| 2644 | private void flingScroller(int velocityY) { |
| 2645 | assert ANCHOR_SCROLLING; |
| 2646 | mIsScrollerBoundSet = false; |
| 2647 | maybeFlingScroller(velocityY, true /* always fling */); |
| 2648 | } |
| 2649 | |
| 2650 | private void maybeFlingScroller(int velocityY, boolean alwaysFling) { |
| 2651 | assert ANCHOR_SCROLLING; |
| 2652 | // Attempt to determine the maximum amount to scroll before we reach the end. |
| 2653 | // If the first view is not materialized (for an upwards scroll) or the last view is either |
| 2654 | // not materialized or is pinned to the shade (for a downwards scroll), we don't know this |
| 2655 | // amount, so we do an unbounded fling and rely on {@link #maybeReflingScroller()} to update |
| 2656 | // the scroller once we approach the start/end of the list. |
| 2657 | int minY = Integer.MIN_VALUE; |
| 2658 | int maxY = Integer.MAX_VALUE; |
| 2659 | if (velocityY < 0) { |
| 2660 | minY = getMaxNegativeScrollAmount(); |
| 2661 | if (minY > Integer.MIN_VALUE) { |
| 2662 | mIsScrollerBoundSet = true; |
| 2663 | } |
| 2664 | } else { |
| 2665 | maxY = getMaxPositiveScrollAmount(); |
| 2666 | if (maxY < Integer.MAX_VALUE) { |
| 2667 | mIsScrollerBoundSet = true; |
| 2668 | } |
| 2669 | } |
| 2670 | if (mIsScrollerBoundSet || alwaysFling) { |
| 2671 | mLastScrollerY = 0; |
| 2672 | // x velocity is set to 1 to avoid overscroller bug |
| 2673 | mScroller.fling(0, 0, 1, velocityY, 0, 0, minY, maxY, 0, |
| 2674 | mExpandedInThisMotion && !isScrolledToTop() ? 0 : Integer.MAX_VALUE / 2); |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | /** |
| 2679 | * Returns the maximum number of pixels we can scroll in the positive direction (downwards) |
| 2680 | * before reaching the bottom of the list (discounting overscroll). |
| 2681 | * |
| 2682 | * If the return value is negative then we have overscrolled; this is a transient state which |
| 2683 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2684 | * the bottom overscroll amount. |
| 2685 | * |
| 2686 | * If we don't know how many pixels we have left to scroll (because the last row has not been |
| 2687 | * materialized, or it's in the shelf so it doesn't have its "natural" position), we return |
| 2688 | * {@link Integer#MAX_VALUE}. |
| 2689 | */ |
| 2690 | private int getMaxPositiveScrollAmount() { |
| 2691 | assert ANCHOR_SCROLLING; |
| 2692 | // TODO: once we're recycling we need to check the adapter position of the last child. |
| 2693 | ExpandableNotificationRow lastRow = getLastRowNotGone(); |
| 2694 | if (mScrollAnchorView != null && lastRow != null && !lastRow.isInShelf()) { |
| 2695 | // distance from bottom of last child to bottom of notifications area is: |
| 2696 | // distance from bottom of last child |
| 2697 | return (int) (lastRow.getTranslationY() + lastRow.getActualHeight() |
| 2698 | // to top of anchor view |
| 2699 | - mScrollAnchorView.getTranslationY() |
| 2700 | // plus distance from anchor view to top of notifications area |
| 2701 | + mScrollAnchorViewY |
| 2702 | // minus height of notifications area. |
| 2703 | - (mMaxLayoutHeight - getIntrinsicPadding() - mFooterView.getActualHeight())); |
| 2704 | } else { |
| 2705 | return Integer.MAX_VALUE; |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * Returns the maximum number of pixels (as a negative number) we can scroll in the negative |
| 2711 | * direction (upwards) before reaching the top of the list (discounting overscroll). |
| 2712 | * |
| 2713 | * If the return value is positive then we have overscrolled; this is a transient state which |
| 2714 | * should immediately be handled by adjusting the anchor position and adding the extra space to |
| 2715 | * the top overscroll amount. |
| 2716 | * |
| 2717 | * If we don't know how many pixels we have left to scroll (because the first row has not been |
| 2718 | * materialized), we return {@link Integer#MIN_VALUE}. |
| 2719 | */ |
| 2720 | private int getMaxNegativeScrollAmount() { |
| 2721 | assert ANCHOR_SCROLLING; |
| 2722 | // TODO: once we're recycling we need to check the adapter position of the first child. |
| 2723 | ExpandableView firstChild = getFirstChildNotGone(); |
| 2724 | if (mScrollAnchorView != null && firstChild != null) { |
| 2725 | // distance from top of first child to top of notifications area is: |
| 2726 | // distance from top of anchor view |
| 2727 | return (int) -(mScrollAnchorView.getTranslationY() |
| 2728 | // to top of first child |
| 2729 | - firstChild.getTranslationY() |
| 2730 | // minus distance from top of anchor view to top of notifications area. |
| 2731 | - mScrollAnchorViewY); |
| 2732 | } else { |
| 2733 | return Integer.MIN_VALUE; |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | /** |
| 2738 | * During a fling, if we were unable to set the bounds of the fling due to the top/bottom view |
| 2739 | * not being materialized or being pinned to the shelf, we need to check on every frame if we're |
| 2740 | * able to set the bounds. If we are, we fling the scroller again with the newly computed |
| 2741 | * bounds. |
| 2742 | */ |
| 2743 | private void maybeReflingScroller() { |
| 2744 | if (!mIsScrollerBoundSet) { |
| 2745 | // Because mScroller is a flywheel scroller, we fling with the minimum possible |
| 2746 | // velocity to establish direction, so as not to perceptibly affect the velocity. |
| 2747 | maybeFlingScroller((int) Math.signum(mScroller.getCurrVelocity()), |
| 2748 | false /* alwaysFling */); |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | /** |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2753 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2754 | * overScroll view (i.e QS). |
| 2755 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2756 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2757 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2758 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2759 | return mScrolledToTopOnFirstDown |
| 2760 | && !mExpandedInThisMotion |
| 2761 | && topOverScroll > mMinTopOverScrollToEscape |
| 2762 | && initialVelocity > 0; |
| 2763 | } |
| 2764 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2765 | /** |
| 2766 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2767 | * account. |
| 2768 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2769 | * @param qsHeight the top padding imposed by the quick settings panel |
| 2770 | * @param animate whether to animate the change |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2771 | * @param ignoreIntrinsicPadding if true, {@link #getIntrinsicPadding()} is ignored and |
| 2772 | * {@code qsHeight} is the final top padding |
| 2773 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2774 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 2775 | public void updateTopPadding(float qsHeight, boolean animate, |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2776 | boolean ignoreIntrinsicPadding) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2777 | int topPadding = (int) qsHeight; |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2778 | int minStackHeight = getLayoutMinHeight(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2779 | if (topPadding + minStackHeight > getHeight()) { |
| 2780 | mTopPaddingOverflow = topPadding + minStackHeight - getHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2781 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2782 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2783 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2784 | setTopPadding(ignoreIntrinsicPadding ? topPadding : clampPadding(topPadding), |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2785 | animate); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2786 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2787 | } |
| 2788 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2789 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2790 | public void setMaxTopPadding(int maxTopPadding) { |
| 2791 | mMaxTopPadding = maxTopPadding; |
| 2792 | } |
| 2793 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2794 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2795 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2796 | if (isHeadsUpTransition()) { |
| 2797 | return getTopHeadsUpPinnedHeight(); |
| 2798 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2799 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2802 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2803 | public float getTopPaddingOverflow() { |
| 2804 | return mTopPaddingOverflow; |
| 2805 | } |
| 2806 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2807 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2808 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2809 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2810 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2811 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2812 | int shelfHeight = 0; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 2813 | if (getLastVisibleSection() != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2814 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2815 | } |
| 2816 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2817 | } |
| 2818 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2819 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2820 | private int clampPadding(int desiredPadding) { |
| 2821 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2822 | } |
| 2823 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2824 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2825 | private float getRubberBandFactor(boolean onTop) { |
| 2826 | if (!onTop) { |
| 2827 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2828 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2829 | if (mExpandedInThisMotion) { |
| 2830 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2831 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2832 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2833 | } else if (mScrolledToTopOnFirstDown) { |
| 2834 | return 1.0f; |
| 2835 | } |
| 2836 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2837 | } |
| 2838 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2839 | /** |
| 2840 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2841 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2842 | * overscroll view (e.g. expand QS). |
| 2843 | */ |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 2844 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2845 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2846 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2847 | || !mScrolledToTopOnFirstDown; |
| 2848 | } |
| 2849 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2850 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2851 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2852 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2853 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 2854 | Assert.isMainThread(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2855 | mChildTransferInProgress = childTransferInProgress; |
| 2856 | } |
| 2857 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2858 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2859 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2860 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2861 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2862 | // we only call our internal methods if this is actually a removal and not just a |
| 2863 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2864 | if (!mChildTransferInProgress) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2865 | onViewRemovedInternal((ExpandableView) child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2869 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2870 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2871 | public void cleanUpViewStateForEntry(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 2872 | View child = entry.getRow(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 2873 | if (child == mSwipeHelper.getTranslatingParentView()) { |
| 2874 | mSwipeHelper.clearTranslatingParentView(); |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2875 | } |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2876 | } |
| 2877 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2878 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2879 | private void onViewRemovedInternal(ExpandableView child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2880 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2881 | // This is only a position change, don't do anything special |
| 2882 | return; |
| 2883 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2884 | child.setOnHeightChangedListener(null); |
| 2885 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2886 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2887 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2888 | if (!mSwipedOutViews.contains(child) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2889 | || Math.abs(child.getTranslation()) != child.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2890 | container.addTransientView(child, 0); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2891 | child.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2892 | } |
| 2893 | } else { |
| 2894 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2895 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2896 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2897 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2898 | focusNextViewIfFocused(child); |
| 2899 | } |
| 2900 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2901 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2902 | private void focusNextViewIfFocused(View view) { |
| 2903 | if (view instanceof ExpandableNotificationRow) { |
| 2904 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2905 | if (row.shouldRefocusOnDismiss()) { |
| 2906 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 2907 | if (nextView == null) { |
| 2908 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 2909 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 2910 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2911 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2912 | } |
| 2913 | if (nextView != null) { |
| 2914 | nextView.requestAccessibilityFocus(); |
| 2915 | } |
| 2916 | } |
| 2917 | } |
| 2918 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2919 | } |
| 2920 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2921 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2922 | private boolean isChildInGroup(View child) { |
| 2923 | return child instanceof ExpandableNotificationRow |
| 2924 | && mGroupManager.isChildInGroupWithSummary( |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2925 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2926 | } |
| 2927 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2928 | /** |
| 2929 | * Generate a remove animation for a child view. |
| 2930 | * |
| 2931 | * @param child The view to generate the remove animation for. |
| 2932 | * @return Whether an animation was generated. |
| 2933 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2934 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2935 | private boolean generateRemoveAnimation(ExpandableView child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2936 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2937 | mAddedHeadsUpChildren.remove(child); |
| 2938 | return false; |
| 2939 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2940 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 2941 | // An animation is already running, add it transiently |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 2942 | mClearTransientViewsWhenFinished.add(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2943 | return true; |
| 2944 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2945 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2946 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2947 | // Generate Animations |
| 2948 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2949 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2950 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2951 | } else { |
| 2952 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2953 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2954 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2955 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2956 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2957 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2958 | } |
| 2959 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2960 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2961 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2962 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2965 | /** |
| 2966 | * Remove a removed child view from the heads up animations if it was just added there |
| 2967 | * |
| 2968 | * @return whether any child was removed from the list to animate |
| 2969 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2970 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2971 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 2972 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2973 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 2974 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2975 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2976 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2977 | mTmpList.add(eventPair); |
| 2978 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2979 | } |
| 2980 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2981 | if (hasAddEvent) { |
| 2982 | // This child was just added lets remove all events. |
| 2983 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 2984 | ((ExpandableNotificationRow) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2985 | } |
| 2986 | mTmpList.clear(); |
| 2987 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2990 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2991 | * @param child the child to query |
| 2992 | * @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] | 2993 | * not expanded |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2994 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 2995 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2996 | private boolean isChildInInvisibleGroup(View child) { |
| 2997 | if (child instanceof ExpandableNotificationRow) { |
| 2998 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 2999 | NotificationEntry groupSummary = |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3000 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 3001 | if (groupSummary != null && groupSummary.getRow() != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 3002 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | return false; |
| 3006 | } |
| 3007 | |
| 3008 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3009 | * Updates the scroll position when a child was removed |
| 3010 | * |
| 3011 | * @param removedChild the removed child |
| 3012 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3013 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3014 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3015 | if (ANCHOR_SCROLLING) { |
| 3016 | if (removedChild == mScrollAnchorView) { |
| 3017 | ExpandableView firstChild = getFirstChildNotGone(); |
| 3018 | if (firstChild != null) { |
| 3019 | mScrollAnchorView = firstChild; |
| 3020 | } else { |
| 3021 | mScrollAnchorView = mShelf; |
| 3022 | } |
| 3023 | // Adjust anchor view Y by the distance between the old and new anchors |
| 3024 | // so that there's no visible change. |
| 3025 | mScrollAnchorViewY += |
| 3026 | mScrollAnchorView.getTranslationY() - removedChild.getTranslationY(); |
| 3027 | } |
| 3028 | updateScrollAnchor(); |
| 3029 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3030 | if (mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY > 0) { |
| 3031 | mScrollAnchorViewY = 0; |
| 3032 | } |
| 3033 | updateOnScrollChange(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3034 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3035 | int startingPosition = getPositionInLinearLayout(removedChild); |
| 3036 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 3037 | int padding; |
| 3038 | if (increasedPaddingAmount >= 0) { |
| 3039 | padding = (int) NotificationUtils.interpolate( |
| 3040 | mPaddingBetweenElements, |
| 3041 | mIncreasedPaddingBetweenElements, |
| 3042 | increasedPaddingAmount); |
| 3043 | } else { |
| 3044 | padding = (int) NotificationUtils.interpolate( |
| 3045 | 0, |
| 3046 | mPaddingBetweenElements, |
| 3047 | 1.0f + increasedPaddingAmount); |
| 3048 | } |
| 3049 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
| 3050 | int endPosition = startingPosition + childHeight; |
| 3051 | if (endPosition <= mOwnScrollY) { |
| 3052 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 3053 | // scrollPosition |
| 3054 | setOwnScrollY(mOwnScrollY - childHeight); |
| 3055 | } else if (startingPosition < mOwnScrollY) { |
| 3056 | // This child is currently being scrolled into, set the scroll position to the |
| 3057 | // start of this child |
| 3058 | setOwnScrollY(startingPosition); |
| 3059 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3060 | } |
| 3061 | } |
| 3062 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3063 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 3064 | private int getIntrinsicHeight(View view) { |
| 3065 | if (view instanceof ExpandableView) { |
| 3066 | ExpandableView expandableView = (ExpandableView) view; |
| 3067 | return expandableView.getIntrinsicHeight(); |
| 3068 | } |
| 3069 | return view.getHeight(); |
| 3070 | } |
| 3071 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3072 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3073 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3074 | ExpandableNotificationRow childInGroup = null; |
| 3075 | ExpandableNotificationRow requestedRow = null; |
| 3076 | if (isChildInGroup(requestedView)) { |
| 3077 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 3078 | // then within the parent. |
| 3079 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 3080 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 3081 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3082 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3083 | float previousPaddingRequest = mPaddingBetweenElements; |
| 3084 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3085 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3086 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3087 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 3088 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3089 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3090 | float padding; |
| 3091 | if (increasedPaddingAmount >= 0.0f) { |
| 3092 | padding = (int) NotificationUtils.interpolate( |
| 3093 | previousPaddingRequest, |
| 3094 | mIncreasedPaddingBetweenElements, |
| 3095 | increasedPaddingAmount); |
| 3096 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 3097 | mPaddingBetweenElements, |
| 3098 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3099 | increasedPaddingAmount); |
| 3100 | } else { |
| 3101 | int ownPadding = (int) NotificationUtils.interpolate( |
| 3102 | 0, |
| 3103 | mPaddingBetweenElements, |
| 3104 | 1.0f + increasedPaddingAmount); |
| 3105 | if (previousPaddingAmount > 0.0f) { |
| 3106 | padding = (int) NotificationUtils.interpolate( |
| 3107 | ownPadding, |
| 3108 | mIncreasedPaddingBetweenElements, |
| 3109 | previousPaddingAmount); |
| 3110 | } else { |
| 3111 | padding = ownPadding; |
| 3112 | } |
| 3113 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3114 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3115 | if (position != 0) { |
| 3116 | position += padding; |
| 3117 | } |
| 3118 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3119 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3120 | if (child == requestedView) { |
| 3121 | if (requestedRow != null) { |
| 3122 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3123 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3124 | return position; |
| 3125 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3126 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3127 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3134 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3135 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3136 | super.onViewAdded(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3137 | onViewAddedInternal((ExpandableView) child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3138 | } |
| 3139 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3140 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3141 | private void updateFirstAndLastBackgroundViews() { |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3142 | NotificationSection firstSection = getFirstVisibleSection(); |
| 3143 | NotificationSection lastSection = getLastVisibleSection(); |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3144 | ActivatableNotificationView previousFirstChild = |
| 3145 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 3146 | ActivatableNotificationView previousLastChild = |
| 3147 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3148 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3149 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3150 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 3151 | boolean sectionViewsChanged = mSectionsManager.updateFirstAndLastViewsInSections( |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3152 | mSections[0], mSections[1], firstChild, lastChild); |
| 3153 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3154 | if (mAnimationsEnabled && mIsExpanded) { |
Gus Prevas | da13cfa | 2018-11-20 14:58:48 -0500 | [diff] [blame] | 3155 | mAnimateNextBackgroundTop = firstChild != previousFirstChild; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3156 | mAnimateNextBackgroundBottom = lastChild != previousLastChild || mAnimateBottomOnLayout; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3157 | mAnimateNextSectionBoundsChange = sectionViewsChanged; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3158 | } else { |
| 3159 | mAnimateNextBackgroundTop = false; |
| 3160 | mAnimateNextBackgroundBottom = false; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3161 | mAnimateNextSectionBoundsChange = false; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3162 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3163 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 3164 | mRoundnessManager.updateRoundedChildren(mSections); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 3165 | mAnimateBottomOnLayout = false; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3166 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3167 | } |
| 3168 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3169 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3170 | private void onViewAddedInternal(ExpandableView child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3171 | updateHideSensitiveForChild(child); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3172 | child.setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3173 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3174 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3175 | updateChronometerForChild(child); |
Gus Prevas | a18dc57 | 2019-01-14 16:11:22 -0500 | [diff] [blame] | 3176 | if (child instanceof ExpandableNotificationRow) { |
| 3177 | ((ExpandableNotificationRow) child).setDismissRtl(mDismissRtl); |
| 3178 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3179 | if (ANCHOR_SCROLLING) { |
| 3180 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 3181 | if (child == getFirstChildNotGone() && (isScrolledToTop() || !mIsExpanded)) { |
| 3182 | // New child was added at the top while we're scrolled to the top; |
| 3183 | // make it the new anchor view so that we stay at the top. |
| 3184 | mScrollAnchorView = child; |
| 3185 | } |
| 3186 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3187 | } |
| 3188 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3189 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3190 | private void updateHideSensitiveForChild(ExpandableView child) { |
| 3191 | child.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3194 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3195 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3196 | public void notifyGroupChildRemoved(ExpandableView row, ViewGroup childrenContainer) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3197 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3198 | } |
| 3199 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3200 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3201 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3202 | public void notifyGroupChildAdded(ExpandableView row) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3203 | onViewAddedInternal(row); |
| 3204 | } |
| 3205 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3206 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3207 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3208 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3209 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3210 | if (!animationsEnabled) { |
| 3211 | mSwipedOutViews.clear(); |
| 3212 | mChildrenToRemoveAnimated.clear(); |
| 3213 | clearTemporaryViewsInGroup(this); |
| 3214 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3215 | } |
| 3216 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3217 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3218 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3219 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3220 | mShelf.setAnimationsEnabled(running); |
Lucas Dupin | 9d6172b | 2019-06-04 15:14:25 -0700 | [diff] [blame] | 3221 | mIconAreaController.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3222 | int childCount = getChildCount(); |
| 3223 | for (int i = 0; i < childCount; i++) { |
| 3224 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3225 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3226 | updateAnimationState(running, child); |
| 3227 | } |
| 3228 | } |
| 3229 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3230 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3231 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3232 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3233 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3234 | } |
| 3235 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3236 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3237 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3238 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3239 | mAmbientState.setExpandingNotification(row); |
| 3240 | requestChildrenUpdate(); |
| 3241 | } |
| 3242 | |
| 3243 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3244 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3245 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3246 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3247 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3248 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3249 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | @Override |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 3253 | public boolean containsView(View v) { |
| 3254 | return v.getParent() == this; |
| 3255 | } |
| 3256 | |
| 3257 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3258 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3259 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3260 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3261 | requestChildrenUpdate(); |
| 3262 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3263 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3264 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3265 | private void updateAnimationState(boolean running, View child) { |
| 3266 | if (child instanceof ExpandableNotificationRow) { |
| 3267 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3268 | row.setIconAnimationRunning(running); |
| 3269 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3270 | } |
| 3271 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3272 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3273 | public boolean isAddOrRemoveAnimationPending() { |
| 3274 | return mNeedsAnimation |
| 3275 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3276 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3277 | |
| 3278 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3279 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3280 | public void generateAddAnimation(ExpandableView child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3281 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3282 | // Generate Animations |
| 3283 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3284 | if (fromMoreCard) { |
| 3285 | mFromMoreCardAdditions.add(child); |
| 3286 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3287 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3288 | } |
Selim Cinek | f306d9b | 2017-02-21 11:45:13 -0800 | [diff] [blame] | 3289 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3290 | mAddedHeadsUpChildren.add(child); |
| 3291 | mChildrenToAddAnimated.remove(child); |
| 3292 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3293 | } |
| 3294 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3295 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3296 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3297 | public void changeViewPosition(ExpandableView child, int newIndex) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 3298 | Assert.isMainThread(); |
| 3299 | if (mChangePositionInProgress) { |
| 3300 | throw new IllegalStateException("Reentrant call to changeViewPosition"); |
| 3301 | } |
| 3302 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3303 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3304 | |
| 3305 | if (currentIndex == -1) { |
| 3306 | boolean isTransient = false; |
| 3307 | if (child instanceof ExpandableNotificationRow |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3308 | && ((ExpandableNotificationRow) child).getTransientContainer() != null) { |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3309 | isTransient = true; |
| 3310 | } |
| 3311 | Log.e(TAG, "Attempting to re-position " |
| 3312 | + (isTransient ? "transient" : "") |
| 3313 | + " view {" |
| 3314 | + child |
| 3315 | + "}"); |
| 3316 | return; |
| 3317 | } |
| 3318 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3319 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3320 | mChangePositionInProgress = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3321 | ((ExpandableView) child).setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3322 | removeView(child); |
| 3323 | addView(child, newIndex); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3324 | ((ExpandableView) child).setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3325 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3326 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3327 | mChildrenChangingPositions.add(child); |
| 3328 | mNeedsAnimation = true; |
| 3329 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3330 | } |
| 3331 | } |
| 3332 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3333 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3334 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3335 | if (mNeedsAnimation) { |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3336 | generateAllAnimationEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3337 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3338 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3339 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3340 | setAnimationRunning(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3341 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3342 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3343 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3344 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3345 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3346 | } else { |
| 3347 | applyCurrentState(); |
| 3348 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3349 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3350 | } |
| 3351 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3352 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | b9d500a | 2018-06-25 16:27:16 -0700 | [diff] [blame] | 3353 | private void generateAllAnimationEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3354 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3355 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3356 | generateChildAdditionEvents(); |
| 3357 | generatePositionChangeEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3358 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3359 | generateActivateEvent(); |
| 3360 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3361 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3362 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3363 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3364 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3365 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3366 | generateAnimateEverythingEvent(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3367 | } |
| 3368 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3369 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3370 | private void generateHeadsUpAnimationEvents() { |
| 3371 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3372 | ExpandableNotificationRow row = eventPair.first; |
| 3373 | boolean isHeadsUp = eventPair.second; |
| 3374 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3375 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3376 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3377 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3378 | type = row.wasJustClicked() |
| 3379 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3380 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3381 | if (row.isChildInGroup()) { |
| 3382 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3383 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3384 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3385 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3386 | } else { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3387 | ExpandableViewState viewState = row.getViewState(); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3388 | if (viewState == null) { |
| 3389 | // A view state was never generated for this view, so we don't need to animate |
| 3390 | // this. This may happen with notification children. |
| 3391 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3392 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3393 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3394 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3395 | // Our custom add animation |
| 3396 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3397 | } else { |
| 3398 | // Normal add animation |
| 3399 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3400 | } |
| 3401 | onBottom = !pinnedAndClosed; |
| 3402 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3403 | } |
| 3404 | AnimationEvent event = new AnimationEvent(row, type); |
| 3405 | event.headsUpFromBottom = onBottom; |
| 3406 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3407 | } |
| 3408 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3409 | mAddedHeadsUpChildren.clear(); |
| 3410 | } |
| 3411 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3412 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3413 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3414 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3415 | return false; |
| 3416 | } |
| 3417 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3418 | } |
| 3419 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3420 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3421 | private void generateGroupExpansionEvent() { |
| 3422 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3423 | if (mExpandedGroupView != null) { |
| 3424 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3425 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3426 | mExpandedGroupView = null; |
| 3427 | } |
| 3428 | } |
| 3429 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3430 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3431 | private void generateViewResizeEvent() { |
| 3432 | if (mNeedViewResizeAnimation) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3433 | boolean hasDisappearAnimation = false; |
| 3434 | for (AnimationEvent animationEvent : mAnimationEvents) { |
| 3435 | final int type = animationEvent.animationType; |
| 3436 | if (type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 3437 | || type == AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
felkachang | d7835b0 | 2018-07-17 18:18:13 +0800 | [diff] [blame] | 3438 | hasDisappearAnimation = true; |
| 3439 | break; |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | if (!hasDisappearAnimation) { |
| 3444 | mAnimationEvents.add( |
| 3445 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3446 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3447 | } |
| 3448 | mNeedViewResizeAnimation = false; |
| 3449 | } |
| 3450 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3451 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3452 | private void generateChildRemovalEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3453 | for (ExpandableView child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3454 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3455 | |
| 3456 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3457 | float removedTranslation = child.getTranslationY(); |
| 3458 | boolean ignoreChildren = true; |
| 3459 | if (child instanceof ExpandableNotificationRow) { |
| 3460 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3461 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3462 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3463 | ignoreChildren = false; |
| 3464 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3465 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3466 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3467 | if (!childWasSwipedOut) { |
| 3468 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3469 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3470 | |
| 3471 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3472 | // Clean up any potential transient views if the child has already been swiped |
| 3473 | // out, as we won't be animating it further (due to its height already being |
| 3474 | // clipped to 0. |
| 3475 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3476 | if (transientContainer != null) { |
| 3477 | transientContainer.removeTransientView(child); |
| 3478 | } |
| 3479 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3480 | } |
| 3481 | int animationType = childWasSwipedOut |
| 3482 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3483 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3484 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3485 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3486 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3487 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3488 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3489 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3490 | mChildrenToRemoveAnimated.clear(); |
| 3491 | } |
| 3492 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3493 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3494 | private void generatePositionChangeEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3495 | for (ExpandableView child : mChildrenChangingPositions) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3496 | mAnimationEvents.add(new AnimationEvent(child, |
| 3497 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3498 | } |
| 3499 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3500 | if (mGenerateChildOrderChangedEvent) { |
| 3501 | mAnimationEvents.add(new AnimationEvent(null, |
| 3502 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3503 | mGenerateChildOrderChangedEvent = false; |
| 3504 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3505 | } |
| 3506 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3507 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3508 | private void generateChildAdditionEvents() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3509 | for (ExpandableView child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3510 | if (mFromMoreCardAdditions.contains(child)) { |
| 3511 | mAnimationEvents.add(new AnimationEvent(child, |
| 3512 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3513 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3514 | } else { |
| 3515 | mAnimationEvents.add(new AnimationEvent(child, |
| 3516 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3517 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3518 | } |
| 3519 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3520 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3521 | } |
| 3522 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3523 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3524 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3525 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3526 | AnimationEvent event; |
| 3527 | if (mAmbientState.isDark()) { |
| 3528 | event = new AnimationEvent(null /* view */, |
| 3529 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3530 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3531 | } else { |
| 3532 | event = new AnimationEvent(null /* view */, |
| 3533 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3534 | } |
| 3535 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3536 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3537 | mTopPaddingNeedsAnimation = false; |
| 3538 | } |
| 3539 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3540 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3541 | private void generateActivateEvent() { |
| 3542 | if (mActivateNeedsAnimation) { |
| 3543 | mAnimationEvents.add( |
| 3544 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3545 | } |
| 3546 | mActivateNeedsAnimation = false; |
| 3547 | } |
| 3548 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3549 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3550 | private void generateAnimateEverythingEvent() { |
| 3551 | if (mEverythingNeedsAnimation) { |
| 3552 | mAnimationEvents.add( |
| 3553 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3554 | } |
| 3555 | mEverythingNeedsAnimation = false; |
| 3556 | } |
| 3557 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3558 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3559 | private void generateDimmedEvent() { |
| 3560 | if (mDimmedNeedsAnimation) { |
| 3561 | mAnimationEvents.add( |
| 3562 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3563 | } |
| 3564 | mDimmedNeedsAnimation = false; |
| 3565 | } |
| 3566 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3567 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3568 | private void generateHideSensitiveEvent() { |
| 3569 | if (mHideSensitiveNeedsAnimation) { |
| 3570 | mAnimationEvents.add( |
| 3571 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3572 | } |
| 3573 | mHideSensitiveNeedsAnimation = false; |
| 3574 | } |
| 3575 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3576 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3577 | private void generateDarkEvent() { |
| 3578 | if (mDarkNeedsAnimation) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 3579 | AnimationEvent ev = new AnimationEvent(null, |
| 3580 | AnimationEvent.ANIMATION_TYPE_DARK, |
| 3581 | new AnimationFilter() |
| 3582 | .animateDark() |
| 3583 | .animateY(mShelf)); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3584 | ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex; |
| 3585 | mAnimationEvents.add(ev); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3586 | } |
| 3587 | mDarkNeedsAnimation = false; |
| 3588 | } |
| 3589 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3590 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3591 | private void generateGoToFullShadeEvent() { |
| 3592 | if (mGoToFullShadeNeedsAnimation) { |
| 3593 | mAnimationEvents.add( |
| 3594 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3595 | } |
| 3596 | mGoToFullShadeNeedsAnimation = false; |
| 3597 | } |
| 3598 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3599 | @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) |
| 3600 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 3601 | return new StackScrollAlgorithm(context, this); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * @return Whether a y coordinate is inside the content. |
| 3606 | */ |
| 3607 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 3608 | public boolean isInContentBounds(float y) { |
| 3609 | return y < getHeight() - getEmptyBottomMargin(); |
| 3610 | } |
| 3611 | |
| 3612 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3613 | public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) { |
| 3614 | mLongPressListener = listener; |
| 3615 | } |
| 3616 | |
| 3617 | @Override |
| 3618 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3619 | public boolean onTouchEvent(MotionEvent ev) { |
| 3620 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 3621 | || ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3622 | handleEmptySpaceClick(ev); |
| 3623 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3624 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3625 | if (mIsExpanded && !swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3626 | if (isCancelOrUp) { |
| 3627 | mExpandHelper.onlyObserveMovements(false); |
| 3628 | } |
| 3629 | boolean wasExpandingBefore = mExpandingNotification; |
| 3630 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
| 3631 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 3632 | && !mDisallowScrollingInThisMotion) { |
| 3633 | dispatchDownEventToScroller(ev); |
| 3634 | } |
| 3635 | } |
| 3636 | boolean scrollerWantsIt = false; |
| 3637 | if (mIsExpanded && !swipingInProgress && !mExpandingNotification |
| 3638 | && !mDisallowScrollingInThisMotion) { |
| 3639 | scrollerWantsIt = onScrollTouch(ev); |
| 3640 | } |
| 3641 | boolean horizontalSwipeWantsIt = false; |
| 3642 | if (!mIsBeingDragged |
| 3643 | && !mExpandingNotification |
| 3644 | && !mExpandedInThisMotion |
| 3645 | && !mOnlyScrollingInThisMotion |
| 3646 | && !mDisallowDismissInThisMotion) { |
| 3647 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 3648 | } |
| 3649 | |
| 3650 | // Check if we need to clear any snooze leavebehinds |
| 3651 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3652 | if (guts != null && !NotificationSwipeHelper.isTouchInView(ev, guts) |
| 3653 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 3654 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 3655 | if ((ns.isExpanded() && isCancelOrUp) |
| 3656 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 3657 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 3658 | // clear it on the next non-horizontal swipe or expand event. |
| 3659 | checkSnoozeLeavebehind(); |
| 3660 | } |
| 3661 | } |
| 3662 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3663 | mCheckForLeavebehind = true; |
| 3664 | } |
| 3665 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 3666 | } |
| 3667 | |
| 3668 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3669 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 3670 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 3671 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 3672 | onScrollTouch(downEvent); |
| 3673 | downEvent.recycle(); |
| 3674 | } |
| 3675 | |
| 3676 | @Override |
| 3677 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3678 | public boolean onGenericMotionEvent(MotionEvent event) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3679 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3680 | || mDisallowScrollingInThisMotion) { |
| 3681 | return false; |
| 3682 | } |
| 3683 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3684 | switch (event.getAction()) { |
| 3685 | case MotionEvent.ACTION_SCROLL: { |
| 3686 | if (!mIsBeingDragged) { |
| 3687 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 3688 | if (vscroll != 0) { |
| 3689 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3690 | if (ANCHOR_SCROLLING) { |
| 3691 | mScrollAnchorViewY -= delta; |
| 3692 | updateScrollAnchor(); |
| 3693 | clampScrollPosition(); |
| 3694 | updateOnScrollChange(); |
| 3695 | } else { |
| 3696 | final int range = getScrollRange(); |
| 3697 | int oldScrollY = mOwnScrollY; |
| 3698 | int newScrollY = oldScrollY - delta; |
| 3699 | if (newScrollY < 0) { |
| 3700 | newScrollY = 0; |
| 3701 | } else if (newScrollY > range) { |
| 3702 | newScrollY = range; |
| 3703 | } |
| 3704 | if (newScrollY != oldScrollY) { |
| 3705 | setOwnScrollY(newScrollY); |
| 3706 | return true; |
| 3707 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3708 | } |
| 3709 | } |
| 3710 | } |
| 3711 | } |
| 3712 | } |
| 3713 | } |
| 3714 | return super.onGenericMotionEvent(event); |
| 3715 | } |
| 3716 | |
| 3717 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3718 | private boolean onScrollTouch(MotionEvent ev) { |
| 3719 | if (!isScrollingEnabled()) { |
| 3720 | return false; |
| 3721 | } |
| 3722 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
| 3723 | return false; |
| 3724 | } |
| 3725 | mForcedScroll = null; |
| 3726 | initVelocityTrackerIfNotExists(); |
| 3727 | mVelocityTracker.addMovement(ev); |
| 3728 | |
| 3729 | final int action = ev.getAction(); |
| 3730 | |
| 3731 | switch (action & MotionEvent.ACTION_MASK) { |
| 3732 | case MotionEvent.ACTION_DOWN: { |
| 3733 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
| 3734 | return false; |
| 3735 | } |
| 3736 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3737 | setIsBeingDragged(isBeingDragged); |
| 3738 | /* |
| 3739 | * If being flinged and user touches, stop the fling. isFinished |
| 3740 | * will be false if being flinged. |
| 3741 | */ |
| 3742 | if (!mScroller.isFinished()) { |
| 3743 | mScroller.forceFinished(true); |
| 3744 | } |
| 3745 | |
| 3746 | // Remember where the motion event started |
| 3747 | mLastMotionY = (int) ev.getY(); |
| 3748 | mDownX = (int) ev.getX(); |
| 3749 | mActivePointerId = ev.getPointerId(0); |
| 3750 | break; |
| 3751 | } |
| 3752 | case MotionEvent.ACTION_MOVE: |
| 3753 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 3754 | if (activePointerIndex == -1) { |
| 3755 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 3756 | break; |
| 3757 | } |
| 3758 | |
| 3759 | final int y = (int) ev.getY(activePointerIndex); |
| 3760 | final int x = (int) ev.getX(activePointerIndex); |
| 3761 | int deltaY = mLastMotionY - y; |
| 3762 | final int xDiff = Math.abs(x - mDownX); |
| 3763 | final int yDiff = Math.abs(deltaY); |
| 3764 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
| 3765 | setIsBeingDragged(true); |
| 3766 | if (deltaY > 0) { |
| 3767 | deltaY -= mTouchSlop; |
| 3768 | } else { |
| 3769 | deltaY += mTouchSlop; |
| 3770 | } |
| 3771 | } |
| 3772 | if (mIsBeingDragged) { |
| 3773 | // Scroll to follow the motion event |
| 3774 | mLastMotionY = y; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3775 | float scrollAmount; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3776 | int range; |
| 3777 | if (ANCHOR_SCROLLING) { |
| 3778 | range = 0; // unused in the methods it's being passed to |
| 3779 | } else { |
| 3780 | range = getScrollRange(); |
| 3781 | if (mExpandedInThisMotion) { |
| 3782 | range = Math.min(range, mMaxScrollAfterExpand); |
| 3783 | } |
| 3784 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3785 | if (deltaY < 0) { |
| 3786 | scrollAmount = overScrollDown(deltaY); |
| 3787 | } else { |
| 3788 | scrollAmount = overScrollUp(deltaY, range); |
| 3789 | } |
| 3790 | |
| 3791 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 3792 | // sets the scrolling if applicable. |
| 3793 | if (scrollAmount != 0.0f) { |
| 3794 | // The scrolling motion could not be compensated with the |
| 3795 | // existing overScroll, we have to scroll the view |
| 3796 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 3797 | range, getHeight() / 2); |
| 3798 | // If we're scrolling, leavebehinds should be dismissed |
| 3799 | checkSnoozeLeavebehind(); |
| 3800 | } |
| 3801 | } |
| 3802 | break; |
| 3803 | case MotionEvent.ACTION_UP: |
| 3804 | if (mIsBeingDragged) { |
| 3805 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 3806 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 3807 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 3808 | |
| 3809 | if (shouldOverScrollFling(initialVelocity)) { |
| 3810 | onOverScrollFling(true, initialVelocity); |
| 3811 | } else { |
| 3812 | if (getChildCount() > 0) { |
| 3813 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 3814 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 3815 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 3816 | fling(-initialVelocity); |
| 3817 | } else { |
| 3818 | onOverScrollFling(false, initialVelocity); |
| 3819 | } |
| 3820 | } else { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3821 | if (ANCHOR_SCROLLING) { |
| 3822 | // TODO |
| 3823 | } else { |
| 3824 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3825 | getScrollRange())) { |
| 3826 | animateScroll(); |
| 3827 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3828 | } |
| 3829 | } |
| 3830 | } |
| 3831 | } |
| 3832 | mActivePointerId = INVALID_POINTER; |
| 3833 | endDrag(); |
| 3834 | } |
| 3835 | |
| 3836 | break; |
| 3837 | case MotionEvent.ACTION_CANCEL: |
| 3838 | if (mIsBeingDragged && getChildCount() > 0) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 3839 | if (ANCHOR_SCROLLING) { |
| 3840 | // TODO |
| 3841 | } else { |
| 3842 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 3843 | getScrollRange())) { |
| 3844 | animateScroll(); |
| 3845 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3846 | } |
| 3847 | mActivePointerId = INVALID_POINTER; |
| 3848 | endDrag(); |
| 3849 | } |
| 3850 | break; |
| 3851 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 3852 | final int index = ev.getActionIndex(); |
| 3853 | mLastMotionY = (int) ev.getY(index); |
| 3854 | mDownX = (int) ev.getX(index); |
| 3855 | mActivePointerId = ev.getPointerId(index); |
| 3856 | break; |
| 3857 | } |
| 3858 | case MotionEvent.ACTION_POINTER_UP: |
| 3859 | onSecondaryPointerUp(ev); |
| 3860 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
| 3861 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
| 3862 | break; |
| 3863 | } |
| 3864 | return true; |
| 3865 | } |
| 3866 | |
| 3867 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3868 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 3869 | return ev.getY() < mQsContainer.getBottom(); |
| 3870 | } |
| 3871 | |
| 3872 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3873 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 3874 | if (mOverscrollTopChangedListener != null) { |
| 3875 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 3876 | } |
| 3877 | mDontReportNextOverScroll = true; |
| 3878 | setOverScrollAmount(0.0f, true, false); |
| 3879 | } |
| 3880 | |
| 3881 | |
| 3882 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3883 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 3884 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 3885 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 3886 | final int pointerId = ev.getPointerId(pointerIndex); |
| 3887 | if (pointerId == mActivePointerId) { |
| 3888 | // This was our active pointer going up. Choose a new |
| 3889 | // active pointer and adjust accordingly. |
| 3890 | // TODO: Make this decision more intelligent. |
| 3891 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 3892 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 3893 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 3894 | if (mVelocityTracker != null) { |
| 3895 | mVelocityTracker.clear(); |
| 3896 | } |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3901 | private void endDrag() { |
| 3902 | setIsBeingDragged(false); |
| 3903 | |
| 3904 | recycleVelocityTracker(); |
| 3905 | |
| 3906 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 3907 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 3908 | } |
| 3909 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 3910 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 3911 | } |
| 3912 | } |
| 3913 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3914 | @Override |
| 3915 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3916 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 3917 | initDownStates(ev); |
| 3918 | handleEmptySpaceClick(ev); |
| 3919 | boolean expandWantsIt = false; |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 3920 | boolean swipingInProgress = mSwipingInProgress; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 3921 | if (!swipingInProgress && !mOnlyScrollingInThisMotion) { |
| 3922 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 3923 | } |
| 3924 | boolean scrollWantsIt = false; |
| 3925 | if (!swipingInProgress && !mExpandingNotification) { |
| 3926 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 3927 | } |
| 3928 | boolean swipeWantsIt = false; |
| 3929 | if (!mIsBeingDragged |
| 3930 | && !mExpandingNotification |
| 3931 | && !mExpandedInThisMotion |
| 3932 | && !mOnlyScrollingInThisMotion |
| 3933 | && !mDisallowDismissInThisMotion) { |
| 3934 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 3935 | } |
| 3936 | // Check if we need to clear any snooze leavebehinds |
| 3937 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
| 3938 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 3939 | if (!NotificationSwipeHelper.isTouchInView(ev, guts) && isUp && !swipeWantsIt && |
| 3940 | !expandWantsIt && !scrollWantsIt) { |
| 3941 | mCheckForLeavebehind = false; |
| 3942 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 3943 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 3944 | false /* resetMenu */); |
| 3945 | } |
| 3946 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 3947 | mCheckForLeavebehind = true; |
| 3948 | } |
| 3949 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 3950 | } |
| 3951 | |
| 3952 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3953 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 3954 | switch (ev.getActionMasked()) { |
| 3955 | case MotionEvent.ACTION_MOVE: |
| 3956 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 3957 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop)) { |
| 3958 | mTouchIsClick = false; |
| 3959 | } |
| 3960 | break; |
| 3961 | case MotionEvent.ACTION_UP: |
| 3962 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
| 3963 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 3964 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 3965 | } |
| 3966 | break; |
| 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3971 | private void initDownStates(MotionEvent ev) { |
| 3972 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3973 | mExpandedInThisMotion = false; |
| 3974 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
| 3975 | mDisallowScrollingInThisMotion = false; |
| 3976 | mDisallowDismissInThisMotion = false; |
| 3977 | mTouchIsClick = true; |
| 3978 | mInitialTouchX = ev.getX(); |
| 3979 | mInitialTouchY = ev.getY(); |
| 3980 | } |
| 3981 | } |
| 3982 | |
| 3983 | @Override |
| 3984 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 3985 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 3986 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 3987 | if (disallowIntercept) { |
| 3988 | cancelLongPress(); |
| 3989 | } |
| 3990 | } |
| 3991 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 3992 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3993 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3994 | if (!isScrollingEnabled()) { |
| 3995 | return false; |
| 3996 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3997 | /* |
| 3998 | * This method JUST determines whether we want to intercept the motion. |
| 3999 | * If we return true, onMotionEvent will be called and we do the actual |
| 4000 | * scrolling there. |
| 4001 | */ |
| 4002 | |
| 4003 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4004 | * Shortcut the most recurring case: the user is in the dragging |
| 4005 | * state and is moving their finger. We want to intercept this |
| 4006 | * motion. |
| 4007 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4008 | final int action = ev.getAction(); |
| 4009 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 4010 | return true; |
| 4011 | } |
| 4012 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4013 | switch (action & MotionEvent.ACTION_MASK) { |
| 4014 | case MotionEvent.ACTION_MOVE: { |
| 4015 | /* |
| 4016 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 4017 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4018 | */ |
| 4019 | |
| 4020 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4021 | * Locally do absolute value. mLastMotionY is set to the y value |
| 4022 | * of the down event. |
| 4023 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4024 | final int activePointerId = mActivePointerId; |
| 4025 | if (activePointerId == INVALID_POINTER) { |
| 4026 | // If we don't have a valid id, the touch down wasn't on content. |
| 4027 | break; |
| 4028 | } |
| 4029 | |
| 4030 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 4031 | if (pointerIndex == -1) { |
| 4032 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 4033 | + " in onInterceptTouchEvent"); |
| 4034 | break; |
| 4035 | } |
| 4036 | |
| 4037 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4038 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4039 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4040 | final int xDiff = Math.abs(x - mDownX); |
| 4041 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4042 | setIsBeingDragged(true); |
| 4043 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4044 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4045 | initVelocityTrackerIfNotExists(); |
| 4046 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4047 | } |
| 4048 | break; |
| 4049 | } |
| 4050 | |
| 4051 | case MotionEvent.ACTION_DOWN: { |
| 4052 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 4053 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 4054 | if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4055 | setIsBeingDragged(false); |
| 4056 | recycleVelocityTracker(); |
| 4057 | break; |
| 4058 | } |
| 4059 | |
| 4060 | /* |
| 4061 | * Remember location of down touch. |
| 4062 | * ACTION_DOWN always refers to pointer index 0. |
| 4063 | */ |
| 4064 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4065 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4066 | mActivePointerId = ev.getPointerId(0); |
| 4067 | |
| 4068 | initOrResetVelocityTracker(); |
| 4069 | mVelocityTracker.addMovement(ev); |
| 4070 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4071 | * If being flinged and user touches the screen, initiate drag; |
| 4072 | * otherwise don't. mScroller.isFinished should be false when |
| 4073 | * being flinged. |
| 4074 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4075 | boolean isBeingDragged = !mScroller.isFinished(); |
| 4076 | setIsBeingDragged(isBeingDragged); |
| 4077 | break; |
| 4078 | } |
| 4079 | |
| 4080 | case MotionEvent.ACTION_CANCEL: |
| 4081 | case MotionEvent.ACTION_UP: |
| 4082 | /* Release the drag */ |
| 4083 | setIsBeingDragged(false); |
| 4084 | mActivePointerId = INVALID_POINTER; |
| 4085 | recycleVelocityTracker(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4086 | if (ANCHOR_SCROLLING) { |
| 4087 | // TODO |
| 4088 | } else { |
| 4089 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 4090 | animateScroll(); |
| 4091 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4092 | } |
| 4093 | break; |
| 4094 | case MotionEvent.ACTION_POINTER_UP: |
| 4095 | onSecondaryPointerUp(ev); |
| 4096 | break; |
| 4097 | } |
| 4098 | |
| 4099 | /* |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4100 | * The only time we want to intercept motion events is if we are in the |
| 4101 | * drag mode. |
| 4102 | */ |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4103 | return mIsBeingDragged; |
| 4104 | } |
| 4105 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4106 | /** |
| 4107 | * @return Whether the specified motion event is actually happening over the content. |
| 4108 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4109 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4110 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 4111 | return isInContentBounds(event.getY()); |
| 4112 | } |
| 4113 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 4114 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4115 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4116 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4117 | void setIsBeingDragged(boolean isDragged) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4118 | mIsBeingDragged = isDragged; |
| 4119 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4120 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4121 | cancelLongPress(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4122 | resetExposedMenuView(true /* animate */, true /* force */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4123 | } |
| 4124 | } |
| 4125 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4126 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4127 | public void requestDisallowLongPress() { |
| 4128 | cancelLongPress(); |
| 4129 | } |
| 4130 | |
| 4131 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4132 | public void requestDisallowDismiss() { |
| 4133 | mDisallowDismissInThisMotion = true; |
| 4134 | } |
| 4135 | |
| 4136 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4137 | public void cancelLongPress() { |
| 4138 | mSwipeHelper.cancelLongPress(); |
| 4139 | } |
| 4140 | |
| 4141 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4142 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 4143 | mOnEmptySpaceClickListener = listener; |
| 4144 | } |
| 4145 | |
| 4146 | /** @hide */ |
| 4147 | @Override |
| 4148 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4149 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4150 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4151 | return true; |
| 4152 | } |
| 4153 | if (!isEnabled()) { |
| 4154 | return false; |
| 4155 | } |
| 4156 | int direction = -1; |
| 4157 | switch (action) { |
| 4158 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4159 | // fall through |
| 4160 | case android.R.id.accessibilityActionScrollDown: |
| 4161 | direction = 1; |
| 4162 | // fall through |
| 4163 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4164 | // fall through |
| 4165 | case android.R.id.accessibilityActionScrollUp: |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4166 | if (ANCHOR_SCROLLING) { |
| 4167 | // TODO |
| 4168 | } else { |
| 4169 | final int viewportHeight = |
| 4170 | getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
| 4171 | - mShelf.getIntrinsicHeight(); |
| 4172 | final int targetScrollY = Math.max(0, |
| 4173 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4174 | if (targetScrollY != mOwnScrollY) { |
| 4175 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, |
| 4176 | targetScrollY - mOwnScrollY); |
| 4177 | animateScroll(); |
| 4178 | return true; |
| 4179 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4180 | } |
| 4181 | break; |
| 4182 | } |
| 4183 | return false; |
| 4184 | } |
| 4185 | |
| 4186 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4187 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4188 | NotificationGuts guts = mNotificationGutsManager.getExposedGuts(); |
| 4189 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 4190 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 4191 | View view = null; |
| 4192 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4193 | // Only close visible guts if they're not a leavebehind. |
| 4194 | view = guts; |
| 4195 | } else if (menuRow != null && menuRow.isMenuVisible() |
| 4196 | && translatingParentView != null) { |
| 4197 | // Checking menu |
| 4198 | view = translatingParentView; |
| 4199 | } |
| 4200 | if (view != null && !NotificationSwipeHelper.isTouchInView(ev, view)) { |
| 4201 | // Touch was outside visible guts / menu notification, close what's visible |
| 4202 | mNotificationGutsManager.closeAndSaveGuts(false /* removeLeavebehind */, |
| 4203 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4204 | false /* resetMenu */); |
| 4205 | resetExposedMenuView(true /* animate */, true /* force */); |
| 4206 | } |
| 4207 | } |
| 4208 | |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 4209 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 4210 | private void setSwipingInProgress(boolean swiping) { |
| 4211 | mSwipingInProgress = swiping; |
| 4212 | if (swiping) { |
| 4213 | requestDisallowInterceptTouchEvent(true); |
| 4214 | } |
| 4215 | } |
| 4216 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4217 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4218 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4219 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4220 | super.onWindowFocusChanged(hasWindowFocus); |
| 4221 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 4222 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 4223 | } |
| 4224 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4225 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 4226 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4227 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 4228 | public void clearChildFocus(View child) { |
| 4229 | super.clearChildFocus(child); |
| 4230 | if (mForcedScroll == child) { |
| 4231 | mForcedScroll = null; |
| 4232 | } |
| 4233 | } |
| 4234 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4235 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4236 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4237 | public boolean isScrolledToTop() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4238 | if (ANCHOR_SCROLLING) { |
| 4239 | updateScrollAnchor(); |
| 4240 | // TODO: once we're recycling this will need to check the adapter position of the child |
| 4241 | return mScrollAnchorView == getFirstChildNotGone() && mScrollAnchorViewY >= 0; |
| 4242 | } else { |
| 4243 | return mOwnScrollY == 0; |
| 4244 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4248 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4249 | public boolean isScrolledToBottom() { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4250 | if (ANCHOR_SCROLLING) { |
Gus Prevas | cdc9834 | 2019-01-14 14:29:44 -0500 | [diff] [blame] | 4251 | return getMaxPositiveScrollAmount() <= 0; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4252 | } else { |
| 4253 | return mOwnScrollY >= getScrollRange(); |
| 4254 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4258 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 4259 | public View getHostView() { |
| 4260 | return this; |
| 4261 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4262 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4263 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4264 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4265 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4268 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4269 | public void checkSnoozeLeavebehind() { |
| 4270 | if (mCheckForLeavebehind) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 4271 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4272 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4273 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4274 | mCheckForLeavebehind = false; |
| 4275 | } |
| 4276 | } |
| 4277 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4278 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4279 | public void resetCheckSnoozeLeavebehind() { |
| 4280 | mCheckForLeavebehind = true; |
| 4281 | } |
| 4282 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4283 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4284 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4285 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4286 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4287 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4288 | } |
| 4289 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4290 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4291 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4292 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4293 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4294 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4295 | if (!mIsExpanded) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4296 | resetScrollPosition(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4297 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4298 | clearTemporaryViews(); |
| 4299 | clearUserLockedViews(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4300 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 4301 | if (draggedViews.size() > 0) { |
| 4302 | draggedViews.clear(); |
| 4303 | updateContinuousShadowDrawing(); |
| 4304 | } |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4305 | } |
| 4306 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 4307 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4308 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4309 | private void clearUserLockedViews() { |
| 4310 | for (int i = 0; i < getChildCount(); i++) { |
| 4311 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4312 | if (child instanceof ExpandableNotificationRow) { |
| 4313 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4314 | row.setUserLocked(false); |
| 4315 | } |
| 4316 | } |
| 4317 | } |
| 4318 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4319 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4320 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4321 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4322 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4323 | for (int i = 0; i < getChildCount(); i++) { |
| 4324 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4325 | if (child instanceof ExpandableNotificationRow) { |
| 4326 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4327 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4328 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 4329 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4330 | } |
| 4331 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4332 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 4333 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4334 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 4335 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4336 | } |
| 4337 | } |
| 4338 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4339 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4340 | public void onPanelTrackingStarted() { |
| 4341 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4342 | mAmbientState.setPanelTracking(true); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4343 | resetExposedMenuView(true /* animate */, true /* force */); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4344 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4345 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4346 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4347 | public void onPanelTrackingStopped() { |
| 4348 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4349 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4352 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4353 | public void resetScrollPosition() { |
| 4354 | mScroller.abortAnimation(); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4355 | if (ANCHOR_SCROLLING) { |
| 4356 | // TODO: once we're recycling this will need to modify the adapter position instead |
| 4357 | mScrollAnchorView = getFirstChildNotGone(); |
| 4358 | mScrollAnchorViewY = 0; |
| 4359 | updateOnScrollChange(); |
| 4360 | } else { |
| 4361 | setOwnScrollY(0); |
| 4362 | } |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 4363 | } |
| 4364 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4365 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4366 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4367 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4368 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4369 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 4370 | mAmbientState.setShadeExpanded(isExpanded); |
| 4371 | mStateAnimator.setShadeExpanded(isExpanded); |
shawnlin | 3a950c3 | 2019-05-15 20:06:10 +0800 | [diff] [blame] | 4372 | mSwipeHelper.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4373 | if (changed) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4374 | if (!mIsExpanded) { |
| 4375 | mGroupManager.collapseAllGroups(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 4376 | mExpandHelper.cancelImmediately(); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 4377 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4378 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4379 | updateChronometers(); |
Selim Cinek | f3fa685 | 2016-12-20 18:36:02 +0100 | [diff] [blame] | 4380 | requestChildrenUpdate(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4381 | } |
| 4382 | } |
| 4383 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4384 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4385 | private void updateChronometers() { |
| 4386 | int childCount = getChildCount(); |
| 4387 | for (int i = 0; i < childCount; i++) { |
| 4388 | updateChronometerForChild(getChildAt(i)); |
| 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 updateChronometerForChild(View child) { |
| 4394 | if (child instanceof ExpandableNotificationRow) { |
| 4395 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 4396 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 4397 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 4398 | } |
| 4399 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4400 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4401 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4402 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4403 | updateScrollPositionOnExpandInBottom(view); |
| 4404 | clampScrollPosition(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4405 | notifyHeightChangeListener(view, needsAnimation); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4406 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 4407 | ? (ExpandableNotificationRow) view |
| 4408 | : null; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4409 | NotificationSection firstSection = getFirstVisibleSection(); |
| 4410 | ActivatableNotificationView firstVisibleChild = |
| 4411 | firstSection == null ? null : firstSection.getFirstVisibleChild(); |
| 4412 | if (row != null) { |
| 4413 | if (row == firstVisibleChild |
| 4414 | || row.getNotificationParent() == firstVisibleChild) { |
| 4415 | updateAlgorithmLayoutMinHeight(); |
| 4416 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4417 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4418 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 4419 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4420 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4421 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4422 | } |
| 4423 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4424 | @Override |
| 4425 | public void onReset(ExpandableView view) { |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 4426 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 4427 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4428 | } |
| 4429 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4430 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4431 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 4432 | if (view instanceof ExpandableNotificationRow && !onKeyguard()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4433 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4434 | // 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] | 4435 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4436 | if (row.isSummaryWithChildren()) { |
| 4437 | return; |
| 4438 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4439 | // We are actually expanding this view |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4440 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4441 | if (row.isChildInGroup()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 4442 | endPosition += row.getNotificationParent().getTranslationY(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 4443 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4444 | int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 4445 | NotificationSection lastSection = getLastVisibleSection(); |
| 4446 | ActivatableNotificationView lastVisibleChild = |
| 4447 | lastSection == null ? null : lastSection.getLastVisibleChild(); |
| 4448 | if (row != lastVisibleChild && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 4449 | layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements; |
| 4450 | } |
| 4451 | if (endPosition > layoutEnd) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 4452 | if (ANCHOR_SCROLLING) { |
| 4453 | mScrollAnchorViewY -= (endPosition - layoutEnd); |
| 4454 | updateScrollAnchor(); |
| 4455 | updateOnScrollChange(); |
| 4456 | } else { |
| 4457 | setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd)); |
| 4458 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 4459 | mDisallowScrollingInThisMotion = true; |
| 4460 | } |
| 4461 | } |
| 4462 | } |
| 4463 | } |
| 4464 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4465 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 4466 | public void setOnHeightChangedListener( |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 4467 | ExpandableView.OnHeightChangedListener onHeightChangedListener) { |
| 4468 | this.mOnHeightChangedListener = onHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4469 | } |
| 4470 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4471 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4472 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4473 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 4474 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4475 | runAnimationFinishedRunnables(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4476 | clearTransient(); |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4477 | clearHeadsUpDisappearRunning(); |
| 4478 | } |
| 4479 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4480 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4481 | private void clearHeadsUpDisappearRunning() { |
| 4482 | for (int i = 0; i < getChildCount(); i++) { |
| 4483 | View view = getChildAt(i); |
| 4484 | if (view instanceof ExpandableNotificationRow) { |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4485 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4486 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4487 | if (row.isSummaryWithChildren()) { |
| 4488 | for (ExpandableNotificationRow child : row.getNotificationChildren()) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4489 | child.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 4490 | } |
| 4491 | } |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 4492 | } |
| 4493 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4494 | } |
| 4495 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4496 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4497 | private void clearTransient() { |
| 4498 | for (ExpandableView view : mClearTransientViewsWhenFinished) { |
| 4499 | StackStateAnimator.removeTransientView(view); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 4500 | } |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 4501 | mClearTransientViewsWhenFinished.clear(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4504 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4505 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4506 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 4507 | runnable.run(); |
| 4508 | } |
| 4509 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4510 | } |
| 4511 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4512 | /** |
| 4513 | * See {@link AmbientState#setDimmed}. |
| 4514 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4515 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4516 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4517 | dimmed &= onKeyguard(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4518 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4519 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4520 | mDimmedNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4521 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4522 | animateDimmed(dimmed); |
| 4523 | } else { |
| 4524 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4525 | } |
| 4526 | requestChildrenUpdate(); |
| 4527 | } |
| 4528 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4529 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4530 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 4531 | boolean isDimmed() { |
| 4532 | return mAmbientState.isDimmed(); |
| 4533 | } |
| 4534 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4535 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4536 | private void setDimAmount(float dimAmount) { |
| 4537 | mDimAmount = dimAmount; |
| 4538 | updateBackgroundDimming(); |
| 4539 | } |
| 4540 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4541 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 4542 | private void animateDimmed(boolean dimmed) { |
| 4543 | if (mDimAnimator != null) { |
| 4544 | mDimAnimator.cancel(); |
| 4545 | } |
| 4546 | float target = dimmed ? 1.0f : 0.0f; |
| 4547 | if (target == mDimAmount) { |
| 4548 | return; |
| 4549 | } |
| 4550 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 4551 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 4552 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 4553 | mDimAnimator.addListener(mDimEndListener); |
| 4554 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 4555 | mDimAnimator.start(); |
| 4556 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4557 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4558 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 4559 | private void setHideSensitive(boolean hideSensitive, boolean animate) { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4560 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 4561 | int childCount = getChildCount(); |
| 4562 | for (int i = 0; i < childCount; i++) { |
| 4563 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 4564 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 4565 | } |
| 4566 | mAmbientState.setHideSensitive(hideSensitive); |
| 4567 | if (animate && mAnimationsEnabled) { |
| 4568 | mHideSensitiveNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4569 | mNeedsAnimation = true; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4570 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 4571 | updateContentHeight(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4572 | requestChildrenUpdate(); |
| 4573 | } |
| 4574 | } |
| 4575 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4576 | /** |
| 4577 | * See {@link AmbientState#setActivatedChild}. |
| 4578 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4579 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4580 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4581 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4582 | if (mAnimationsEnabled) { |
| 4583 | mActivateNeedsAnimation = true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4584 | mNeedsAnimation = true; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 4585 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4586 | requestChildrenUpdate(); |
| 4587 | } |
| 4588 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4589 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 4590 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4591 | return mAmbientState.getActivatedChild(); |
| 4592 | } |
| 4593 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4594 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4595 | private void applyCurrentState() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 4596 | int numChildren = getChildCount(); |
| 4597 | for (int i = 0; i < numChildren; i++) { |
| 4598 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4599 | child.applyViewState(); |
| 4600 | } |
| 4601 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4602 | if (mListener != null) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4603 | mListener.onChildLocationsChanged(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 4604 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 4605 | runAnimationFinishedRunnables(); |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 4606 | setAnimationRunning(false); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4607 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4608 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 4609 | updateClippingToTopRoundedCorner(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4610 | } |
| 4611 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4612 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4613 | private void updateViewShadows() { |
| 4614 | // we need to work around an issue where the shadow would not cast between siblings when |
| 4615 | // their z difference is between 0 and 0.1 |
| 4616 | |
| 4617 | // Lefts first sort by Z difference |
| 4618 | for (int i = 0; i < getChildCount(); i++) { |
| 4619 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4620 | if (child.getVisibility() != GONE) { |
| 4621 | mTmpSortedChildren.add(child); |
| 4622 | } |
| 4623 | } |
| 4624 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 4625 | |
| 4626 | // Now lets update the shadow for the views |
| 4627 | ExpandableView previous = null; |
| 4628 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 4629 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 4630 | float translationZ = expandableView.getTranslationZ(); |
| 4631 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 4632 | float diff = otherZ - translationZ; |
| 4633 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 4634 | // There is no fake shadow to be drawn |
| 4635 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 4636 | } else { |
| 4637 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 4638 | expandableView.getTranslationY() - previous.getExtraBottomPadding(); |
| 4639 | expandableView.setFakeShadowIntensity( |
| 4640 | diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4641 | previous.getOutlineAlpha(), (int) yLocation, |
| 4642 | previous.getOutlineTranslation()); |
| 4643 | } |
| 4644 | previous = expandableView; |
| 4645 | } |
| 4646 | |
| 4647 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4648 | } |
| 4649 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4650 | /** |
| 4651 | * Update colors of "dismiss" and "empty shade" views. |
| 4652 | * |
| 4653 | * @param lightTheme True if light theme should be used. |
| 4654 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4655 | @ShadeViewRefactor(RefactorComponent.DECORATOR) |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4656 | public void updateDecorViews(boolean lightTheme) { |
| 4657 | if (lightTheme == mUsingLightTheme) { |
| 4658 | return; |
| 4659 | } |
| 4660 | mUsingLightTheme = lightTheme; |
| 4661 | Context context = new ContextThemeWrapper(mContext, |
| 4662 | lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 4663 | final int textColor = Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4664 | mFooterView.setTextColor(textColor); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 4665 | mEmptyShadeView.setTextColor(textColor); |
| 4666 | } |
| 4667 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4668 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4669 | public void goToFullShade(long delay) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4670 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4671 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4672 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4673 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 4674 | } |
| 4675 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4676 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4677 | public void cancelExpandHelper() { |
| 4678 | mExpandHelper.cancel(); |
| 4679 | } |
| 4680 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4681 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4682 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 4683 | mIntrinsicPadding = intrinsicPadding; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 4684 | mAmbientState.setIntrinsicPadding(intrinsicPadding); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4685 | } |
| 4686 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4687 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 4688 | public int getIntrinsicPadding() { |
| 4689 | return mIntrinsicPadding; |
| 4690 | } |
| 4691 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 4692 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4693 | * @return the y position of the first notification |
| 4694 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4695 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4696 | public float getNotificationsTopY() { |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4697 | return mTopPadding + getStackTranslation(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4698 | } |
| 4699 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4700 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4701 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 4702 | public boolean shouldDelayChildPressedState() { |
| 4703 | return true; |
| 4704 | } |
| 4705 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 4706 | /** |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4707 | * See {@link AmbientState#setDark}. |
| 4708 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4709 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4710 | public void setDark(boolean dark, boolean animate, @Nullable PointF touchWakeUpScreenLocation) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 4711 | if (mAmbientState.isDark() == dark) { |
| 4712 | return; |
| 4713 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4714 | mAmbientState.setDark(dark); |
| 4715 | if (animate && mAnimationsEnabled) { |
| 4716 | mDarkNeedsAnimation = true; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4717 | mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4718 | mNeedsAnimation = true; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4719 | } else { |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4720 | setDarkAmount(dark ? 1f : 0f); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4721 | updateBackground(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4722 | } |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4723 | requestChildrenUpdate(); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4724 | updateWillNotDraw(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4725 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4726 | } |
| 4727 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4728 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4729 | private void updatePanelTranslation() { |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 4730 | setTranslationX(mHorizontalPanelTranslation + mAntiBurnInOffsetX * mInterpolatedDarkAmount); |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4731 | } |
| 4732 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4733 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | b46d0a2 | 2019-01-11 16:57:16 -0800 | [diff] [blame] | 4734 | public void setHorizontalPanelTranslation(float verticalPanelTranslation) { |
| 4735 | mHorizontalPanelTranslation = verticalPanelTranslation; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4736 | updatePanelTranslation(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 4737 | } |
| 4738 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4739 | /** |
| 4740 | * Updates whether or not this Layout will perform its own custom drawing (i.e. whether or |
| 4741 | * not {@link #onDraw(Canvas)} is called). This method should be called whenever the |
| 4742 | * {@link #mAmbientState}'s dark mode is toggled. |
| 4743 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4744 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4745 | private void updateWillNotDraw() { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4746 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 4747 | setWillNotDraw(!willDraw); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4748 | } |
| 4749 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4750 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4751 | private void setDarkAmount(float darkAmount) { |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4752 | setDarkAmount(darkAmount, darkAmount); |
| 4753 | } |
| 4754 | |
| 4755 | /** |
| 4756 | * Sets the current dark amount. |
| 4757 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4758 | * @param linearDarkAmount The dark amount that follows linear interpoloation in the |
| 4759 | * animation, |
| 4760 | * 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] | 4761 | * @param interpolatedDarkAmount The dark amount that follows the actual interpolation of the |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4762 | * animation curve. |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4763 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4764 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4765 | public void setDarkAmount(float linearDarkAmount, float interpolatedDarkAmount) { |
| 4766 | mLinearDarkAmount = linearDarkAmount; |
| 4767 | mInterpolatedDarkAmount = interpolatedDarkAmount; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4768 | boolean wasFullyDark = mAmbientState.isFullyDark(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4769 | boolean wasDarkAtAll = mAmbientState.isDarkAtAll(); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4770 | mAmbientState.setDarkAmount(interpolatedDarkAmount); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4771 | boolean nowFullyDark = mAmbientState.isFullyDark(); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4772 | boolean nowDarkAtAll = mAmbientState.isDarkAtAll(); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4773 | if (nowFullyDark != wasFullyDark) { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4774 | updateContentHeight(); |
Selim Cinek | 1e05927 | 2019-05-21 18:15:00 -0700 | [diff] [blame] | 4775 | if (nowFullyDark) { |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4776 | updateDarkShelfVisibility(); |
| 4777 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4778 | } |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 4779 | if (!wasDarkAtAll && nowDarkAtAll) { |
| 4780 | resetExposedMenuView(true /* animate */, true /* animate */); |
| 4781 | } |
Lucas Dupin | 64e2f57 | 2019-03-21 14:21:14 -0700 | [diff] [blame] | 4782 | if (nowFullyDark != wasFullyDark || wasDarkAtAll != nowDarkAtAll) { |
| 4783 | invalidateOutline(); |
| 4784 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4785 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4786 | updateBackgroundDimming(); |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4787 | updatePanelTranslation(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4788 | requestChildrenUpdate(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4789 | } |
| 4790 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 4791 | private void updateDarkShelfVisibility() { |
| 4792 | DozeParameters dozeParameters = DozeParameters.getInstance(mContext); |
| 4793 | if (dozeParameters.shouldControlScreenOff()) { |
| 4794 | mShelf.fadeInTranslating(); |
| 4795 | } |
| 4796 | updateClipping(); |
| 4797 | } |
| 4798 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4799 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4800 | public void notifyDarkAnimationStart(boolean dark) { |
| 4801 | // We only swap the scaling factor if we're fully dark or fully awake to avoid |
| 4802 | // interpolation issues when playing with the power button. |
| 4803 | if (mInterpolatedDarkAmount == 0 || mInterpolatedDarkAmount == 1) { |
| 4804 | mBackgroundXFactor = dark ? 1.8f : 1.5f; |
| 4805 | mDarkXInterpolator = dark |
| 4806 | ? Interpolators.FAST_OUT_SLOW_IN_REVERSE |
| 4807 | : Interpolators.FAST_OUT_SLOW_IN; |
| 4808 | } |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4809 | } |
| 4810 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4811 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4812 | private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4813 | if (screenLocation == null || screenLocation.y < mTopPadding) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4814 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4815 | } |
| 4816 | if (screenLocation.y > getBottomMostNotificationBottom()) { |
| 4817 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW; |
| 4818 | } |
| 4819 | View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y); |
| 4820 | if (child != null) { |
| 4821 | return getNotGoneIndex(child); |
| 4822 | } else { |
| 4823 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4824 | } |
| 4825 | } |
| 4826 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4827 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4828 | private int getNotGoneIndex(View child) { |
| 4829 | int count = getChildCount(); |
| 4830 | int notGoneIndex = 0; |
| 4831 | for (int i = 0; i < count; i++) { |
| 4832 | View v = getChildAt(i); |
| 4833 | if (child == v) { |
| 4834 | return notGoneIndex; |
| 4835 | } |
| 4836 | if (v.getVisibility() != View.GONE) { |
| 4837 | notGoneIndex++; |
| 4838 | } |
| 4839 | } |
| 4840 | return -1; |
| 4841 | } |
| 4842 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4843 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4844 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4845 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4846 | if (mFooterView != null) { |
| 4847 | index = indexOfChild(mFooterView); |
| 4848 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4849 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4850 | mFooterView = footerView; |
| 4851 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4852 | } |
| 4853 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4854 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4855 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4856 | int index = -1; |
| 4857 | if (mEmptyShadeView != null) { |
| 4858 | index = indexOfChild(mEmptyShadeView); |
| 4859 | removeView(mEmptyShadeView); |
| 4860 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4861 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4862 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4863 | } |
| 4864 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4865 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4866 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4867 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4868 | |
| 4869 | int oldTextRes = mEmptyShadeView.getTextResource(); |
| 4870 | int newTextRes = mStatusBar.areNotificationsHidden() |
| 4871 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4872 | if (oldTextRes != newTextRes) { |
| 4873 | mEmptyShadeView.setText(newTextRes); |
| 4874 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4875 | } |
| 4876 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4877 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4878 | public void updateFooterView(boolean visible, boolean showDismissView) { |
| 4879 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4880 | return; |
| 4881 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4882 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 4883 | mFooterView.setVisible(visible, animate); |
| 4884 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4885 | } |
| 4886 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4887 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4888 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 4889 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4890 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4891 | handleDismissAllClipping(); |
| 4892 | } |
| 4893 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4894 | @ShadeViewRefactor(RefactorComponent.ADAPTER) |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4895 | private void handleDismissAllClipping() { |
| 4896 | final int count = getChildCount(); |
| 4897 | boolean previousChildWillBeDismissed = false; |
| 4898 | for (int i = 0; i < count; i++) { |
| 4899 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4900 | if (child.getVisibility() == GONE) { |
| 4901 | continue; |
| 4902 | } |
| 4903 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 4904 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 4905 | } else { |
| 4906 | child.setMinClipTopAmount(0); |
| 4907 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 4908 | previousChildWillBeDismissed = StackScrollAlgorithm.canChildBeDismissed(child); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4909 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 4910 | } |
| 4911 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4912 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4913 | public boolean isFooterViewNotGone() { |
| 4914 | return mFooterView != null |
| 4915 | && mFooterView.getVisibility() != View.GONE |
| 4916 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4917 | } |
| 4918 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4919 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 4920 | public boolean isFooterViewContentVisible() { |
| 4921 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4922 | } |
| 4923 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4924 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4925 | public int getFooterViewHeight() { |
| 4926 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4927 | } |
| 4928 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4929 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 4930 | public int getEmptyShadeViewHeight() { |
| 4931 | return mEmptyShadeView.getHeight(); |
| 4932 | } |
| 4933 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4934 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4935 | public float getBottomMostNotificationBottom() { |
| 4936 | final int count = getChildCount(); |
| 4937 | float max = 0; |
| 4938 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 4939 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 4940 | if (child.getVisibility() == GONE) { |
| 4941 | continue; |
| 4942 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4943 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 4944 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4945 | if (bottom > max) { |
| 4946 | max = bottom; |
| 4947 | } |
| 4948 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4949 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4950 | } |
| 4951 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4952 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4953 | public void setStatusBar(StatusBar statusBar) { |
| 4954 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 4955 | } |
| 4956 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4957 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4958 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 4959 | this.mGroupManager = groupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 4960 | mGroupManager.addOnGroupChangeListener(mOnGroupChangeListener); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4963 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4964 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4965 | if (mIsExpanded && mAnimationsEnabled) { |
| 4966 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4967 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4968 | requestChildrenUpdate(); |
| 4969 | } |
| 4970 | } |
| 4971 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 4972 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4973 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4974 | int childCount = getChildCount(); |
| 4975 | for (int i = childCount - 1; i >= 0; i--) { |
| 4976 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4977 | if (child.getVisibility() != View.GONE) { |
| 4978 | float childTop = child.getY(); |
| 4979 | if (childTop > touchY) { |
| 4980 | // we are above a notification entirely let's abort |
| 4981 | return false; |
| 4982 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4983 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 4984 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4985 | if (child == mFooterView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4986 | if (!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
| 4987 | touchY - childTop)) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4988 | // We clicked on the dismiss button |
| 4989 | return false; |
| 4990 | } |
| 4991 | } else if (child == mEmptyShadeView) { |
| 4992 | // We arrived at the empty shade view, for which we accept all clicks |
| 4993 | return true; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 4994 | } else if (!belowChild) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4995 | // We are on a child |
| 4996 | return false; |
| 4997 | } |
| 4998 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4999 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 5000 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5001 | } |
| 5002 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5003 | /** @hide */ |
| 5004 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5005 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5006 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 5007 | super.onInitializeAccessibilityEventInternal(event); |
| 5008 | event.setScrollable(mScrollable); |
| 5009 | event.setScrollX(mScrollX); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5010 | event.setMaxScrollX(mScrollX); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5011 | if (ANCHOR_SCROLLING) { |
| 5012 | // TODO |
| 5013 | } else { |
| 5014 | event.setScrollY(mOwnScrollY); |
| 5015 | event.setMaxScrollY(getScrollRange()); |
| 5016 | } |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5020 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5021 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 5022 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5023 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5024 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5025 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5026 | info.addAction( |
| 5027 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 5028 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 5029 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5030 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5031 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 5032 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 5033 | } |
| 5034 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 5035 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 5036 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5039 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5040 | public void generateChildOrderChangedEvent() { |
| 5041 | if (mIsExpanded && mAnimationsEnabled) { |
| 5042 | mGenerateChildOrderChangedEvent = true; |
| 5043 | mNeedsAnimation = true; |
| 5044 | requestChildrenUpdate(); |
| 5045 | } |
| 5046 | } |
| 5047 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5048 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5049 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5050 | public int getContainerChildCount() { |
| 5051 | return getChildCount(); |
| 5052 | } |
| 5053 | |
| 5054 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5055 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5056 | public View getContainerChildAt(int i) { |
| 5057 | return getChildAt(i); |
| 5058 | } |
| 5059 | |
| 5060 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5061 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5062 | public void removeContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5063 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5064 | removeView(v); |
| 5065 | } |
| 5066 | |
| 5067 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5068 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5069 | public void addContainerView(View v) { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 5070 | Assert.isMainThread(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5071 | addView(v); |
| 5072 | } |
| 5073 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5074 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 5075 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5076 | mAnimationFinishedRunnables.add(runnable); |
| 5077 | } |
| 5078 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5079 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5080 | public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5081 | mHeadsUpManager = headsUpManager; |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 5082 | mHeadsUpManager.addListener(mRoundnessManager); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 5083 | mHeadsUpManager.setAnimationStateHandler(this::setHeadsUpGoingAwayAnimationsAllowed); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 5086 | public void generateHeadsUpAnimation(NotificationEntry entry, boolean isHeadsUp) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 5087 | ExpandableNotificationRow row = entry.getHeadsUpAnimationView(); |
| 5088 | generateHeadsUpAnimation(row, isHeadsUp); |
| 5089 | } |
| 5090 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5091 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5092 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5093 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5094 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 5095 | mNeedsAnimation = true; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5096 | if (!mIsExpanded && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5097 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 5098 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5099 | requestChildrenUpdate(); |
| 5100 | } |
| 5101 | } |
| 5102 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5103 | /** |
| 5104 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 5105 | * position. |
| 5106 | * |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5107 | * @param height the height of the screen |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5108 | * @param bottomBarHeight the height of the bar on the bottom |
| 5109 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5110 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5111 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 5112 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 5113 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5114 | requestChildrenUpdate(); |
| 5115 | } |
| 5116 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5117 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5118 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 5119 | mTrackingHeadsUp = row != null; |
| 5120 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5123 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5124 | public void setScrimController(ScrimController scrimController) { |
| 5125 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 5126 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5129 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5130 | public void forceNoOverlappingRendering(boolean force) { |
| 5131 | mForceNoOverlappingRendering = force; |
| 5132 | } |
| 5133 | |
| 5134 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5135 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 5136 | public boolean hasOverlappingRendering() { |
| 5137 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 5138 | } |
| 5139 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5140 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5141 | public void setAnimationRunning(boolean animationRunning) { |
| 5142 | if (animationRunning != mAnimationRunning) { |
| 5143 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5144 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5145 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5146 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5147 | } |
| 5148 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5149 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 5150 | } |
| 5151 | } |
| 5152 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5153 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 5154 | public boolean isExpanded() { |
| 5155 | return mIsExpanded; |
| 5156 | } |
| 5157 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5158 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5159 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 5160 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 5161 | return; |
| 5162 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5163 | mPulsing = pulsing; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 5164 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | d0b48e3 | 2019-05-24 20:49:23 -0700 | [diff] [blame] | 5165 | mSwipeHelper.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5166 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 5167 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 5168 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 5169 | requestChildrenUpdate(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5170 | notifyHeightChangeListener(null, animated); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5173 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5174 | public void setQsExpanded(boolean qsExpanded) { |
| 5175 | mQsExpanded = qsExpanded; |
| 5176 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 5177 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 5178 | } |
| 5179 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5180 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5181 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 5182 | mQsExpansionFraction = qsExpansionFraction; |
| 5183 | } |
| 5184 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5185 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5186 | private void setOwnScrollY(int ownScrollY) { |
| 5187 | assert !ANCHOR_SCROLLING; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5188 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 5189 | // We still want to call the normal scrolled changed for accessibility reasons |
| 5190 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5191 | mOwnScrollY = ownScrollY; |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5192 | updateOnScrollChange(); |
| 5193 | } |
| 5194 | } |
| 5195 | |
| 5196 | private void updateOnScrollChange() { |
| 5197 | updateForwardAndBackwardScrollability(); |
| 5198 | requestChildrenUpdate(); |
| 5199 | } |
| 5200 | |
| 5201 | private void updateScrollAnchor() { |
| 5202 | int anchorIndex = indexOfChild(mScrollAnchorView); |
| 5203 | // If the anchor view has been scrolled off the top, move to the next view. |
| 5204 | while (mScrollAnchorViewY < 0) { |
| 5205 | View nextAnchor = null; |
| 5206 | for (int i = anchorIndex + 1; i < getChildCount(); i++) { |
| 5207 | View child = getChildAt(i); |
| 5208 | if (child.getVisibility() != View.GONE |
| 5209 | && child instanceof ExpandableNotificationRow) { |
| 5210 | anchorIndex = i; |
| 5211 | nextAnchor = child; |
| 5212 | break; |
| 5213 | } |
| 5214 | } |
| 5215 | if (nextAnchor == null) { |
| 5216 | break; |
| 5217 | } |
| 5218 | mScrollAnchorViewY += |
| 5219 | (int) (nextAnchor.getTranslationY() - mScrollAnchorView.getTranslationY()); |
| 5220 | mScrollAnchorView = nextAnchor; |
| 5221 | } |
| 5222 | // If the view above the anchor view is fully visible, make it the anchor view. |
| 5223 | while (anchorIndex > 0 && mScrollAnchorViewY > 0) { |
| 5224 | View prevAnchor = null; |
| 5225 | for (int i = anchorIndex - 1; i >= 0; i--) { |
| 5226 | View child = getChildAt(i); |
| 5227 | if (child.getVisibility() != View.GONE |
| 5228 | && child instanceof ExpandableNotificationRow) { |
| 5229 | anchorIndex = i; |
| 5230 | prevAnchor = child; |
| 5231 | break; |
| 5232 | } |
| 5233 | } |
| 5234 | if (prevAnchor == null) { |
| 5235 | break; |
| 5236 | } |
| 5237 | float distanceToPreviousAnchor = |
| 5238 | mScrollAnchorView.getTranslationY() - prevAnchor.getTranslationY(); |
| 5239 | if (distanceToPreviousAnchor < mScrollAnchorViewY) { |
| 5240 | mScrollAnchorViewY -= (int) distanceToPreviousAnchor; |
| 5241 | mScrollAnchorView = prevAnchor; |
| 5242 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 5243 | } |
| 5244 | } |
| 5245 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5246 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5247 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5248 | int index = -1; |
| 5249 | if (mShelf != null) { |
| 5250 | index = indexOfChild(mShelf); |
| 5251 | removeView(mShelf); |
| 5252 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 5253 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5254 | addView(mShelf, index); |
| 5255 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 5256 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 5257 | shelf.bind(mAmbientState, this); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 5258 | if (ANCHOR_SCROLLING) { |
| 5259 | mScrollAnchorView = mShelf; |
| 5260 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5263 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 5264 | public NotificationShelf getNotificationShelf() { |
| 5265 | return mShelf; |
| 5266 | } |
| 5267 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5268 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 5269 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 5270 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 5271 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 5272 | updateContentHeight(); |
| 5273 | notifyHeightChangeListener(mShelf); |
| 5274 | } |
| 5275 | } |
| 5276 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5277 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5278 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5279 | mShouldShowShelfOnly = shouldShowShelfOnly; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5280 | updateAlgorithmLayoutMinHeight(); |
| 5281 | } |
| 5282 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5283 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5284 | public int getMinExpansionHeight() { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 5285 | return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 5286 | } |
| 5287 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5288 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5289 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 5290 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 5291 | updateClipping(); |
| 5292 | } |
| 5293 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5294 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 5295 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 5296 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 5297 | updateClipping(); |
| 5298 | } |
| 5299 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5300 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5301 | @VisibleForTesting |
| 5302 | protected void setStatusBarState(int statusBarState) { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5303 | mStatusBarState = statusBarState; |
| 5304 | mAmbientState.setStatusBarState(statusBarState); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | private void onStatePostChange() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5308 | boolean onKeyguard = onKeyguard(); |
| 5309 | boolean publicMode = mLockscreenUserManager.isAnyProfilePublicMode(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5310 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5311 | if (mHeadsUpAppearanceController != null) { |
| 5312 | mHeadsUpAppearanceController.setPublicMode(publicMode); |
| 5313 | } |
| 5314 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 5315 | SysuiStatusBarStateController state = (SysuiStatusBarStateController) |
| 5316 | Dependency.get(StatusBarStateController.class); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 5317 | setHideSensitive(publicMode, state.goingToFullShade() /* animate */); |
| 5318 | setDimmed(onKeyguard, state.fromShadeLocked() /* animate */); |
| 5319 | setExpandingEnabled(!onKeyguard); |
| 5320 | ActivatableNotificationView activatedChild = getActivatedChild(); |
| 5321 | setActivatedChild(null); |
| 5322 | if (activatedChild != null) { |
| 5323 | activatedChild.makeInactive(false /* animate */); |
| 5324 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5325 | updateFooter(); |
Dave Mankoff | 5744580 | 2018-10-10 14:47:34 -0400 | [diff] [blame] | 5326 | requestChildrenUpdate(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5327 | onUpdateRowStates(); |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 5328 | |
| 5329 | mEntryManager.updateNotifications(); |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 5330 | } |
| 5331 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5332 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 5333 | public void setExpandingVelocity(float expandingVelocity) { |
| 5334 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 5335 | } |
| 5336 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5337 | @ShadeViewRefactor(RefactorComponent.COORDINATOR) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5338 | public float getOpeningHeight() { |
| 5339 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 5340 | return getMinExpansionHeight(); |
| 5341 | } else { |
| 5342 | return getAppearEndPosition(); |
| 5343 | } |
| 5344 | } |
| 5345 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5346 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 5347 | public void setIsFullWidth(boolean isFullWidth) { |
| 5348 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 5349 | } |
| 5350 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5351 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 5352 | public void setUnlockHintRunning(boolean running) { |
| 5353 | mAmbientState.setUnlockHintRunning(running); |
| 5354 | } |
| 5355 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5356 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5357 | public void setQsCustomizerShowing(boolean isShowing) { |
| 5358 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 5359 | requestChildrenUpdate(); |
| 5360 | } |
| 5361 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5362 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 5363 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 5364 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 5365 | } |
| 5366 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5367 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 5368 | public void setAntiBurnInOffsetX(int antiBurnInOffsetX) { |
| 5369 | mAntiBurnInOffsetX = antiBurnInOffsetX; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 5370 | updatePanelTranslation(); |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 5371 | } |
| 5372 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5373 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5374 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 5375 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5376 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 5377 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5378 | this.getClass().getSimpleName(), |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5379 | mPulsing ? "T" : "f", |
| 5380 | mAmbientState.isQsCustomizerShowing() ? "T" : "f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5381 | getVisibility() == View.VISIBLE ? "visible" |
| 5382 | : getVisibility() == View.GONE ? "gone" |
| 5383 | : "invisible", |
| 5384 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5385 | mAmbientState.getScrollY(), |
| 5386 | mMaxTopPadding, |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5387 | mShouldShowShelfOnly ? "T" : "f", |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 5388 | mQsExpansionFraction)); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5389 | int childCount = getChildCount(); |
| 5390 | pw.println(" Number of children: " + childCount); |
| 5391 | pw.println(); |
| 5392 | |
| 5393 | for (int i = 0; i < childCount; i++) { |
| 5394 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 5395 | child.dump(fd, pw, args); |
| 5396 | if (!(child instanceof ExpandableNotificationRow)) { |
| 5397 | pw.println(" " + child.getClass().getSimpleName()); |
| 5398 | // 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] | 5399 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5400 | if (viewState == null) { |
| 5401 | pw.println(" no viewState!!!"); |
| 5402 | } else { |
| 5403 | pw.print(" "); |
| 5404 | viewState.dump(fd, pw, args); |
| 5405 | pw.println(); |
| 5406 | pw.println(); |
| 5407 | } |
| 5408 | } |
| 5409 | } |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5410 | int transientViewCount = getTransientViewCount(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5411 | pw.println(" Transient Views: " + transientViewCount); |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 5412 | for (int i = 0; i < transientViewCount; i++) { |
| 5413 | ExpandableView child = (ExpandableView) getTransientView(i); |
| 5414 | child.dump(fd, pw, args); |
| 5415 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 5416 | ArrayList<ExpandableView> draggedViews = mAmbientState.getDraggedViews(); |
Selim Cinek | d4c3230 | 2018-11-19 19:43:14 -0800 | [diff] [blame] | 5417 | int draggedCount = draggedViews.size(); |
| 5418 | pw.println(" Dragged Views: " + draggedCount); |
| 5419 | for (int i = 0; i < draggedCount; i++) { |
| 5420 | ExpandableView child = (ExpandableView) draggedViews.get(i); |
| 5421 | child.dump(fd, pw, args); |
| 5422 | } |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 5423 | } |
| 5424 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5425 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 5426 | public boolean isFullyDark() { |
| 5427 | return mAmbientState.isFullyDark(); |
| 5428 | } |
| 5429 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 5430 | /** |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5431 | * Add a listener whenever the expanded height changes. The first value passed as an argument |
| 5432 | * is the expanded height and the second one is the appearFraction. |
| 5433 | * |
| 5434 | * @param listener the listener to notify. |
| 5435 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5436 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5437 | public void addOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 5438 | mExpandedHeightListeners.add(listener); |
| 5439 | } |
| 5440 | |
| 5441 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5442 | * Stop a listener from listening to the expandedHeight. |
| 5443 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5444 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5445 | public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 5446 | mExpandedHeightListeners.remove(listener); |
| 5447 | } |
| 5448 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5449 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 5450 | public void setHeadsUpAppearanceController( |
| 5451 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 5452 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 5453 | } |
| 5454 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5455 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 5456 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 5457 | mIconAreaController = controller; |
| 5458 | } |
| 5459 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5460 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5461 | public void manageNotifications(View v) { |
| 5462 | Intent intent = new Intent(Settings.ACTION_ALL_APPS_NOTIFICATION_SETTINGS); |
| 5463 | mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 5464 | } |
| 5465 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5466 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5467 | private void clearNotifications( |
| 5468 | @SelectedRows int selection, |
| 5469 | boolean closeShade) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5470 | // animate-swipe all dismissable notifications, then animate the shade closed |
| 5471 | int numChildren = getChildCount(); |
| 5472 | |
| 5473 | final ArrayList<View> viewsToHide = new ArrayList<>(numChildren); |
| 5474 | final ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>(numChildren); |
| 5475 | for (int i = 0; i < numChildren; i++) { |
| 5476 | final View child = getChildAt(i); |
| 5477 | if (child instanceof ExpandableNotificationRow) { |
| 5478 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 5479 | boolean parentVisible = false; |
| 5480 | boolean hasClipBounds = child.getClipBounds(mTmpRect); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5481 | if (includeChildInDismissAll(row, selection)) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5482 | viewsToRemove.add(row); |
| 5483 | if (child.getVisibility() == View.VISIBLE |
| 5484 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5485 | viewsToHide.add(child); |
| 5486 | parentVisible = true; |
| 5487 | } |
| 5488 | } else if (child.getVisibility() == View.VISIBLE |
| 5489 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5490 | parentVisible = true; |
| 5491 | } |
| 5492 | List<ExpandableNotificationRow> children = row.getNotificationChildren(); |
| 5493 | if (children != null) { |
| 5494 | for (ExpandableNotificationRow childRow : children) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5495 | if (includeChildInDismissAll(row, selection)) { |
| 5496 | viewsToRemove.add(childRow); |
| 5497 | if (parentVisible && row.areChildrenExpanded()) { |
| 5498 | hasClipBounds = childRow.getClipBounds(mTmpRect); |
| 5499 | if (childRow.getVisibility() == View.VISIBLE |
| 5500 | && (!hasClipBounds || mTmpRect.height() > 0)) { |
| 5501 | viewsToHide.add(childRow); |
| 5502 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5503 | } |
| 5504 | } |
| 5505 | } |
| 5506 | } |
| 5507 | } |
| 5508 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5509 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5510 | if (viewsToRemove.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5511 | if (closeShade) { |
| 5512 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5513 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5514 | return; |
| 5515 | } |
| 5516 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5517 | performDismissAllAnimations(viewsToHide, closeShade, () -> { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5518 | for (ExpandableNotificationRow rowToRemove : viewsToRemove) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5519 | if (StackScrollAlgorithm.canChildBeDismissed(rowToRemove)) { |
| 5520 | if (selection == ROWS_ALL) { |
| 5521 | // TODO: This is a listener method; we shouldn't be calling it. Can we just |
| 5522 | // call performRemoveNotification as below? |
| 5523 | mEntryManager.removeNotification( |
| 5524 | rowToRemove.getEntry().key, |
| 5525 | null /* ranking */, |
| 5526 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5527 | } else { |
| 5528 | mEntryManager.performRemoveNotification( |
| 5529 | rowToRemove.getEntry().notification, |
| 5530 | NotificationListenerService.REASON_CANCEL_ALL); |
| 5531 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5532 | } else { |
| 5533 | rowToRemove.resetTranslation(); |
| 5534 | } |
| 5535 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5536 | if (selection == ROWS_ALL) { |
| 5537 | try { |
| 5538 | mBarService.onClearAllNotifications(mLockscreenUserManager.getCurrentUserId()); |
| 5539 | } catch (Exception ex) { |
| 5540 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5541 | } |
| 5542 | }); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5543 | } |
| 5544 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5545 | private boolean includeChildInDismissAll( |
| 5546 | ExpandableNotificationRow row, |
| 5547 | @SelectedRows int selection) { |
| 5548 | return StackScrollAlgorithm.canChildBeDismissed(row) && matchesSelection(row, selection); |
| 5549 | } |
| 5550 | |
| 5551 | /** |
| 5552 | * Given a list of rows, animates them away in a staggered fashion as if they were dismissed. |
| 5553 | * Doesn't actually dismiss them, though -- that must be done in the onAnimationComplete |
| 5554 | * handler. |
| 5555 | * |
| 5556 | * @param hideAnimatedList List of rows to animated away. Should only be views that are |
| 5557 | * currently visible, or else the stagger will look funky. |
| 5558 | * @param closeShade Whether to close the shade after the stagger animation completes. |
| 5559 | * @param onAnimationComplete Called after the entire animation completes (including the shade |
| 5560 | * closing if appropriate). The rows must be dismissed for real here. |
| 5561 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5562 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5563 | private void performDismissAllAnimations( |
| 5564 | final ArrayList<View> hideAnimatedList, |
| 5565 | final boolean closeShade, |
| 5566 | final Runnable onAnimationComplete) { |
| 5567 | |
| 5568 | final Runnable onSlideAwayAnimationComplete = () -> { |
| 5569 | if (closeShade) { |
| 5570 | mShadeController.addPostCollapseAction(() -> { |
| 5571 | setDismissAllInProgress(false); |
| 5572 | onAnimationComplete.run(); |
| 5573 | }); |
| 5574 | mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
| 5575 | } else { |
| 5576 | setDismissAllInProgress(false); |
| 5577 | onAnimationComplete.run(); |
| 5578 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5579 | }; |
| 5580 | |
| 5581 | if (hideAnimatedList.isEmpty()) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5582 | onSlideAwayAnimationComplete.run(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5583 | return; |
| 5584 | } |
| 5585 | |
| 5586 | // let's disable our normal animations |
| 5587 | setDismissAllInProgress(true); |
| 5588 | |
| 5589 | // Decrease the delay for every row we animate to give the sense of |
| 5590 | // accelerating the swipes |
| 5591 | int rowDelayDecrement = 10; |
| 5592 | int currentDelay = 140; |
| 5593 | int totalDelay = 180; |
| 5594 | int numItems = hideAnimatedList.size(); |
| 5595 | for (int i = numItems - 1; i >= 0; i--) { |
| 5596 | View view = hideAnimatedList.get(i); |
| 5597 | Runnable endRunnable = null; |
| 5598 | if (i == 0) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5599 | endRunnable = onSlideAwayAnimationComplete; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5600 | } |
Lucas Dupin | fb8bdbb | 2018-12-02 15:09:37 -0800 | [diff] [blame] | 5601 | dismissViewAnimated(view, endRunnable, totalDelay, ANIMATION_DURATION_SWIPE); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5602 | currentDelay = Math.max(50, currentDelay - rowDelayDecrement); |
| 5603 | totalDelay += currentDelay; |
| 5604 | } |
| 5605 | } |
| 5606 | |
| 5607 | @VisibleForTesting |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5608 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5609 | protected void inflateFooterView() { |
| 5610 | FooterView footerView = (FooterView) LayoutInflater.from(mContext).inflate( |
| 5611 | R.layout.status_bar_notification_footer, this, false); |
| 5612 | footerView.setDismissButtonClickListener(v -> { |
| 5613 | mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5614 | clearNotifications(ROWS_ALL, true /* closeShade */); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5615 | }); |
| 5616 | footerView.setManageButtonClickListener(this::manageNotifications); |
| 5617 | setFooterView(footerView); |
| 5618 | } |
| 5619 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5620 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5621 | private void inflateEmptyShadeView() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5622 | EmptyShadeView view = (EmptyShadeView) LayoutInflater.from(mContext).inflate( |
| 5623 | R.layout.status_bar_no_notifications, this, false); |
| 5624 | view.setText(R.string.empty_shade_text); |
| 5625 | setEmptyShadeView(view); |
| 5626 | } |
| 5627 | |
| 5628 | /** |
| 5629 | * Updates expanded, dimmed and locked states of notification rows. |
| 5630 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5631 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5632 | public void onUpdateRowStates() { |
| 5633 | changeViewPosition(mFooterView, -1); |
| 5634 | |
| 5635 | // The following views will be moved to the end of mStackScroller. This counter represents |
| 5636 | // the offset from the last child. Initialized to 1 for the very last position. It is post- |
| 5637 | // incremented in the following "changeViewPosition" calls so that its value is correct for |
| 5638 | // subsequent calls. |
| 5639 | int offsetFromEnd = 1; |
| 5640 | changeViewPosition(mEmptyShadeView, |
| 5641 | getChildCount() - offsetFromEnd++); |
| 5642 | |
| 5643 | // No post-increment for this call because it is the last one. Make sure to add one if |
| 5644 | // another "changeViewPosition" call is ever added. |
| 5645 | changeViewPosition(mShelf, |
| 5646 | getChildCount() - offsetFromEnd); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5647 | } |
| 5648 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5649 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5650 | public void setNotificationPanel(NotificationPanelView notificationPanelView) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5651 | mNotificationPanel = notificationPanelView; |
| 5652 | } |
| 5653 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 5654 | public void updateIconAreaViews() { |
| 5655 | mIconAreaController.updateNotificationIcons(); |
| 5656 | } |
| 5657 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 5658 | /** |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5659 | * Set how far the wake up is when waking up from pulsing. This is a height and will adjust the |
| 5660 | * notification positions accordingly. |
| 5661 | * @param height the new wake up height |
| 5662 | * @return the overflow how much the height is further than he lowest notification |
| 5663 | */ |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 5664 | public float setPulseHeight(float height) { |
| 5665 | mAmbientState.setPulseHeight(height); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5666 | requestChildrenUpdate(); |
| 5667 | return Math.max(0, height - mAmbientState.getInnerHeight(true /* ignorePulseHeight */)); |
| 5668 | } |
| 5669 | |
| 5670 | /** |
| 5671 | * Set the amount how much we're dozing. This is different from how dark the shade is, when |
| 5672 | * the notification is pulsing. |
| 5673 | */ |
| 5674 | public void setDozeAmount(float dozeAmount) { |
| 5675 | mAmbientState.setDozeAmount(dozeAmount); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5676 | updateContinuousBackgroundDrawing(); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5677 | requestChildrenUpdate(); |
| 5678 | } |
| 5679 | |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5680 | public void wakeUpFromPulse() { |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 5681 | setPulseHeight(getPulseHeight()); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5682 | // Let's place the hidden views at the end of the pulsing notification to make sure we have |
| 5683 | // a smooth animation |
| 5684 | boolean firstVisibleView = true; |
| 5685 | float wakeUplocation = -1f; |
| 5686 | int childCount = getChildCount(); |
| 5687 | for (int i = 0; i < childCount; i++) { |
| 5688 | ExpandableView view = (ExpandableView) getChildAt(i); |
| 5689 | if (view.getVisibility() == View.GONE) { |
| 5690 | continue; |
| 5691 | } |
| 5692 | boolean isShelf = view == mShelf; |
| 5693 | if (!(view instanceof ExpandableNotificationRow) && !isShelf) { |
| 5694 | continue; |
| 5695 | } |
| 5696 | if (view.getVisibility() == View.VISIBLE && !isShelf) { |
| 5697 | if (firstVisibleView) { |
| 5698 | firstVisibleView = false; |
| 5699 | wakeUplocation = view.getTranslationY() |
| 5700 | + view.getActualHeight() - mShelf.getIntrinsicHeight(); |
| 5701 | } |
| 5702 | } else if (!firstVisibleView) { |
| 5703 | view.setTranslationY(wakeUplocation); |
| 5704 | } |
| 5705 | } |
Selim Cinek | f434a74 | 2019-05-28 17:39:49 -0700 | [diff] [blame] | 5706 | mDimmedNeedsAnimation = true; |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 5707 | } |
| 5708 | |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 5709 | @Override |
| 5710 | public void onDynamicPrivacyChanged() { |
| 5711 | if (mIsExpanded) { |
| 5712 | // The bottom might change because we're using the final actual height of the view |
| 5713 | mAnimateBottomOnLayout = true; |
| 5714 | } |
| 5715 | } |
| 5716 | |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 5717 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5718 | * A listener that is notified when the empty space below the notifications is clicked on |
| 5719 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5720 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5721 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 5722 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5726 | * A listener that gets notified when the overscroll at the top has changed. |
| 5727 | */ |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5728 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5729 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 5730 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5731 | /** |
| 5732 | * Notifies a listener that the overscroll has changed. |
| 5733 | * |
| 5734 | * @param amount the amount of overscroll, in pixels |
| 5735 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 5736 | * unrubberbanded motion to directly expand overscroll view (e.g |
| 5737 | * expand |
| 5738 | * QS) |
| 5739 | */ |
| 5740 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 5741 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5742 | /** |
| 5743 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 5744 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 5745 | * |
| 5746 | * @param velocity The velocity that the Scroller had when over flinging |
| 5747 | * @param open Should the fling open or close the overscroll view. |
| 5748 | */ |
| 5749 | void flingTopOverscroll(float velocity, boolean open); |
| 5750 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 5751 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5752 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 5753 | public boolean hasActiveNotifications() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5754 | return !mEntryManager.getNotificationData().getActiveNotifications().isEmpty(); |
| 5755 | } |
| 5756 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 5757 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5758 | public void updateSpeedBumpIndex() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5759 | int speedBumpIndex = 0; |
| 5760 | int currentIndex = 0; |
| 5761 | final int N = getChildCount(); |
| 5762 | for (int i = 0; i < N; i++) { |
| 5763 | View view = getChildAt(i); |
| 5764 | if (view.getVisibility() == View.GONE || !(view instanceof ExpandableNotificationRow)) { |
| 5765 | continue; |
| 5766 | } |
| 5767 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 5768 | currentIndex++; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5769 | boolean beforeSpeedBump; |
Selim Cinek | 3c9b054 | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5770 | if (mHighPriorityBeforeSpeedBump) { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 5771 | beforeSpeedBump = row.getEntry().isHighPriority(); |
Selim Cinek | 3c9b054 | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 5772 | } else { |
| 5773 | beforeSpeedBump = !row.getEntry().ambient; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 5774 | } |
| 5775 | if (beforeSpeedBump) { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5776 | speedBumpIndex = currentIndex; |
| 5777 | } |
| 5778 | } |
| 5779 | boolean noAmbient = speedBumpIndex == N; |
| 5780 | updateSpeedBumpIndex(speedBumpIndex, noAmbient); |
| 5781 | } |
| 5782 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5783 | /** Updates the indices of the boundaries between sections. */ |
| 5784 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 5785 | public void updateSectionBoundaries() { |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 5786 | mSectionsManager.updateSectionBoundaries(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 5787 | } |
| 5788 | |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 5789 | private void updateContinuousBackgroundDrawing() { |
| 5790 | boolean continuousBackground = !mAmbientState.isFullyAwake() |
| 5791 | && !mAmbientState.getDraggedViews().isEmpty(); |
| 5792 | if (continuousBackground != mContinuousBackgroundUpdate) { |
| 5793 | mContinuousBackgroundUpdate = continuousBackground; |
| 5794 | if (continuousBackground) { |
| 5795 | getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater); |
| 5796 | } else { |
| 5797 | getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater); |
| 5798 | } |
| 5799 | } |
| 5800 | } |
| 5801 | |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5802 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5803 | private void updateContinuousShadowDrawing() { |
| 5804 | boolean continuousShadowUpdate = mAnimationRunning |
| 5805 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 5806 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 5807 | if (continuousShadowUpdate) { |
| 5808 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 5809 | } else { |
| 5810 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 5811 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 5812 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 5813 | } |
| 5814 | } |
| 5815 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 5816 | @Override |
Aaron Heuckroth | 441b7dd | 2018-08-24 15:52:49 -0400 | [diff] [blame] | 5817 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 5818 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 5819 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 5820 | } |
| 5821 | |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 5822 | private static boolean matchesSelection( |
| 5823 | ExpandableNotificationRow row, |
| 5824 | @SelectedRows int selection) { |
| 5825 | switch (selection) { |
| 5826 | case ROWS_ALL: |
| 5827 | return true; |
| 5828 | case ROWS_HIGH_PRIORITY: |
| 5829 | return row.getEntry().isHighPriority(); |
| 5830 | case ROWS_GENTLE: |
| 5831 | return !row.getEntry().isHighPriority(); |
| 5832 | default: |
| 5833 | throw new IllegalArgumentException("Unknown selection: " + selection); |
| 5834 | } |
| 5835 | } |
| 5836 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 5837 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 5838 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5839 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5840 | static AnimationFilter[] FILTERS = new AnimationFilter[]{ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5841 | |
| 5842 | // ANIMATION_TYPE_ADD |
| 5843 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5844 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5845 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5846 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5847 | .animateZ() |
| 5848 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5849 | |
| 5850 | // ANIMATION_TYPE_REMOVE |
| 5851 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5852 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5853 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5854 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5855 | .animateZ() |
| 5856 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5857 | |
| 5858 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5859 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5860 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5861 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5862 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5863 | .animateZ() |
| 5864 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5865 | |
| 5866 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5867 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5868 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5869 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5870 | .animateY() |
| 5871 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5872 | .animateZ(), |
| 5873 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5874 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5875 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5876 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5877 | |
| 5878 | // ANIMATION_TYPE_DIMMED |
| 5879 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5880 | .animateDimmed(), |
| 5881 | |
| 5882 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5883 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5884 | .animateAlpha() // maybe the children change positions |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5885 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 5886 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5887 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5888 | .animateZ(), |
| 5889 | |
| 5890 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5891 | null, // Unused |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5892 | |
| 5893 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5894 | new AnimationFilter() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5895 | .animateHeight() |
| 5896 | .animateTopInset() |
| 5897 | .animateY() |
| 5898 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5899 | .animateZ() |
| 5900 | .hasDelays(), |
| 5901 | |
| 5902 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5903 | new AnimationFilter() |
| 5904 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5905 | |
| 5906 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5907 | new AnimationFilter() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5908 | .animateHeight() |
| 5909 | .animateTopInset() |
| 5910 | .animateY() |
| 5911 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5912 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5913 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 5914 | new AnimationFilter() |
| 5915 | .animateAlpha() |
| 5916 | .animateHeight() |
| 5917 | .animateTopInset() |
| 5918 | .animateY() |
| 5919 | .animateZ(), |
| 5920 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5921 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5922 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5923 | .animateHeight() |
| 5924 | .animateTopInset() |
| 5925 | .animateY() |
| 5926 | .animateZ(), |
| 5927 | |
| 5928 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5929 | new AnimationFilter() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5930 | .animateHeight() |
| 5931 | .animateTopInset() |
| 5932 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 5933 | .animateZ() |
| 5934 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5935 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5936 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5937 | new AnimationFilter() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5938 | .animateHeight() |
| 5939 | .animateTopInset() |
| 5940 | .animateY() |
| 5941 | .animateZ() |
| 5942 | .hasDelays(), |
| 5943 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5944 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5945 | new AnimationFilter() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5946 | .animateHeight() |
| 5947 | .animateTopInset() |
| 5948 | .animateY() |
| 5949 | .animateZ(), |
| 5950 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5951 | // ANIMATION_TYPE_EVERYTHING |
| 5952 | new AnimationFilter() |
| 5953 | .animateAlpha() |
| 5954 | .animateDark() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5955 | .animateDimmed() |
| 5956 | .animateHideSensitive() |
| 5957 | .animateHeight() |
| 5958 | .animateTopInset() |
| 5959 | .animateY() |
| 5960 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5961 | }; |
| 5962 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 5963 | static int[] LENGTHS = new int[]{ |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5964 | |
| 5965 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5966 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5967 | |
| 5968 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5969 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5970 | |
| 5971 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5972 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5973 | |
| 5974 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5975 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5976 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5977 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5978 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 5979 | |
| 5980 | // ANIMATION_TYPE_DIMMED |
| 5981 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5982 | |
| 5983 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5984 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5985 | |
| 5986 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5987 | StackStateAnimator.ANIMATION_DURATION_WAKEUP, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5988 | |
| 5989 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5990 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5991 | |
| 5992 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5993 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5994 | |
| 5995 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5996 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5997 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5998 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 5999 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 6000 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 6001 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 6002 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 6003 | |
| 6004 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 6005 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6006 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 6007 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 6008 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 6009 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6010 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 6011 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 6012 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 6013 | // ANIMATION_TYPE_EVERYTHING |
| 6014 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6015 | }; |
| 6016 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6017 | static final int ANIMATION_TYPE_ADD = 0; |
| 6018 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 6019 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 6020 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
Selim Cinek | ff2ffec | 2018-11-19 18:52:01 -0800 | [diff] [blame] | 6021 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 4; |
| 6022 | static final int ANIMATION_TYPE_DIMMED = 5; |
| 6023 | static final int ANIMATION_TYPE_CHANGE_POSITION = 6; |
| 6024 | static final int ANIMATION_TYPE_DARK = 7; |
| 6025 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 8; |
| 6026 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 9; |
| 6027 | static final int ANIMATION_TYPE_VIEW_RESIZE = 10; |
| 6028 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 11; |
| 6029 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 12; |
| 6030 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 13; |
| 6031 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 14; |
| 6032 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 15; |
| 6033 | static final int ANIMATION_TYPE_EVERYTHING = 16; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 6034 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 6035 | static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1; |
| 6036 | static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2; |
| 6037 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6038 | final long eventStartTime; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6039 | final ExpandableView mChangingView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6040 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 6041 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6042 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 6043 | View viewAfterChangingView; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 6044 | int darkAnimationOriginIndex; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 6045 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6046 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6047 | AnimationEvent(ExpandableView view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6048 | this(view, type, LENGTHS[type]); |
| 6049 | } |
| 6050 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6051 | AnimationEvent(ExpandableView view, int type, AnimationFilter filter) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6052 | this(view, type, LENGTHS[type], filter); |
| 6053 | } |
| 6054 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6055 | AnimationEvent(ExpandableView view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6056 | this(view, type, length, FILTERS[type]); |
| 6057 | } |
| 6058 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6059 | AnimationEvent(ExpandableView view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6060 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6061 | mChangingView = view; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6062 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 6063 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 6064 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | /** |
| 6068 | * Combines the length of several animation events into a single value. |
| 6069 | * |
| 6070 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6071 | * @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] | 6072 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6073 | */ |
| 6074 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 6075 | long length = 0; |
| 6076 | int size = events.size(); |
| 6077 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 6078 | AnimationEvent event = events.get(i); |
| 6079 | length = Math.max(length, event.length); |
| 6080 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 6081 | return event.length; |
| 6082 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 6083 | } |
| 6084 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 6085 | } |
| 6086 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6087 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6088 | @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) |
| 6089 | private final StateListener mStateListener = new StateListener() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6090 | @Override |
| 6091 | public void onStatePreChange(int oldState, int newState) { |
| 6092 | if (oldState == StatusBarState.SHADE_LOCKED && newState == StatusBarState.KEYGUARD) { |
| 6093 | requestAnimateEverything(); |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | @Override |
| 6098 | public void onStateChanged(int newState) { |
| 6099 | setStatusBarState(newState); |
| 6100 | } |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6101 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6102 | @Override |
| 6103 | public void onStatePostChange() { |
Evan Laird | 91d0f10 | 2018-09-18 17:39:55 -0400 | [diff] [blame] | 6104 | NotificationStackScrollLayout.this.onStatePostChange(); |
| 6105 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6106 | }; |
| 6107 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6108 | @VisibleForTesting |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6109 | @ShadeViewRefactor(RefactorComponent.INPUT) |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6110 | protected final OnMenuEventListener mMenuEventListener = new OnMenuEventListener() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6111 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6112 | public void onMenuClicked(View view, int x, int y, MenuItem item) { |
| 6113 | if (mLongPressListener == null) { |
| 6114 | return; |
| 6115 | } |
| 6116 | if (view instanceof ExpandableNotificationRow) { |
| 6117 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6118 | mMetricsLogger.write(row.getStatusBarNotification().getLogMaker() |
| 6119 | .setCategory(MetricsEvent.ACTION_TOUCH_GEAR) |
| 6120 | .setType(MetricsEvent.TYPE_ACTION) |
| 6121 | ); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6122 | } |
| 6123 | mLongPressListener.onLongPress(view, x, y, item); |
| 6124 | } |
| 6125 | |
| 6126 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6127 | public void onMenuReset(View row) { |
| 6128 | View translatingParentView = mSwipeHelper.getTranslatingParentView(); |
| 6129 | if (translatingParentView != null && row == translatingParentView) { |
| 6130 | mSwipeHelper.clearExposedMenuView(); |
| 6131 | mSwipeHelper.clearTranslatingParentView(); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6132 | if (row instanceof ExpandableNotificationRow) { |
| 6133 | mHeadsUpManager.setMenuShown( |
| 6134 | ((ExpandableNotificationRow) row).getEntry(), false); |
| 6135 | |
| 6136 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6141 | public void onMenuShown(View row) { |
| 6142 | if (row instanceof ExpandableNotificationRow) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6143 | ExpandableNotificationRow notificationRow = (ExpandableNotificationRow) row; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 6144 | mMetricsLogger.write(notificationRow.getStatusBarNotification().getLogMaker() |
| 6145 | .setCategory(MetricsEvent.ACTION_REVEAL_GEAR) |
| 6146 | .setType(MetricsEvent.TYPE_ACTION)); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 6147 | mHeadsUpManager.setMenuShown(notificationRow.getEntry(), true); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6148 | mSwipeHelper.onMenuShown(row); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6149 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6150 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6151 | false /* resetMenu */); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6152 | |
| 6153 | // Check to see if we want to go directly to the notfication guts |
| 6154 | NotificationMenuRowPlugin provider = notificationRow.getProvider(); |
| 6155 | if (provider.shouldShowGutsOnSnapOpen()) { |
| 6156 | MenuItem item = provider.menuItemToExposeOnSnap(); |
| 6157 | if (item != null) { |
| 6158 | Point origin = provider.getRevealAnimationOrigin(); |
Steve Elliott | ff6c25e | 2019-05-30 17:38:52 -0400 | [diff] [blame] | 6159 | mNotificationGutsManager.openGuts(row, origin.x, origin.y, item); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 6160 | } else { |
| 6161 | Log.e(TAG, "Provider has shouldShowGutsOnSnapOpen, but provided no " |
| 6162 | + "menu item in menuItemtoExposeOnSnap. Skipping."); |
| 6163 | } |
| 6164 | |
| 6165 | // Close the menu row since we went directly to the guts |
| 6166 | resetExposedMenuView(false, true); |
| 6167 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6168 | } |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6169 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6170 | }; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6171 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6172 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6173 | private final NotificationSwipeHelper.NotificationCallback mNotificationCallback = |
| 6174 | new NotificationSwipeHelper.NotificationCallback() { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6175 | @Override |
| 6176 | public void onDismiss() { |
| 6177 | mNotificationGutsManager.closeAndSaveGuts(true /* removeLeavebehind */, |
| 6178 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 6179 | false /* resetMenu */); |
| 6180 | } |
| 6181 | |
| 6182 | @Override |
| 6183 | public void onSnooze(StatusBarNotification sbn, |
| 6184 | NotificationSwipeActionHelper.SnoozeOption snoozeOption) { |
| 6185 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
| 6186 | } |
| 6187 | |
| 6188 | @Override |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6189 | public boolean shouldDismissQuickly() { |
| 6190 | return NotificationStackScrollLayout.this.isExpanded() && mAmbientState.isFullyAwake(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6194 | public void onDragCancelled(View v) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6195 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6196 | mFalsingManager.onNotificatonStopDismissing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /** |
| 6200 | * Handles cleanup after the given {@code view} has been fully swiped out (including |
| 6201 | * re-invoking dismiss logic in case the notification has not made its way out yet). |
| 6202 | */ |
| 6203 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6204 | public void onChildDismissed(View view) { |
| 6205 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6206 | if (!row.isDismissed()) { |
| 6207 | handleChildViewDismissed(view); |
| 6208 | } |
| 6209 | ViewGroup transientContainer = row.getTransientContainer(); |
| 6210 | if (transientContainer != null) { |
| 6211 | transientContainer.removeTransientView(view); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | /** |
| 6216 | * Starts up notification dismiss and tells the notification, if any, to remove itself from |
| 6217 | * layout. |
| 6218 | * |
| 6219 | * @param view view (e.g. notification) to dismiss from the layout |
| 6220 | */ |
| 6221 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6222 | public void handleChildViewDismissed(View view) { |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6223 | setSwipingInProgress(false); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6224 | if (mDismissAllInProgress) { |
| 6225 | return; |
| 6226 | } |
| 6227 | |
| 6228 | boolean isBlockingHelperShown = false; |
| 6229 | |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6230 | mAmbientState.onDragFinished(view); |
| 6231 | updateContinuousShadowDrawing(); |
| 6232 | |
| 6233 | if (view instanceof ExpandableNotificationRow) { |
| 6234 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 6235 | if (row.isHeadsUp()) { |
| 6236 | mHeadsUpManager.addSwipedOutNotification( |
| 6237 | row.getStatusBarNotification().getKey()); |
| 6238 | } |
| 6239 | isBlockingHelperShown = |
| 6240 | row.performDismissWithBlockingHelper(false /* fromAccessibility */); |
| 6241 | } |
| 6242 | |
| 6243 | if (!isBlockingHelperShown) { |
| 6244 | mSwipedOutViews.add(view); |
| 6245 | } |
| 6246 | mFalsingManager.onNotificationDismissed(); |
| 6247 | if (mFalsingManager.shouldEnforceBouncer()) { |
| 6248 | mStatusBar.executeRunnableDismissingKeyguard( |
| 6249 | null, |
| 6250 | null /* cancelAction */, |
| 6251 | false /* dismissShade */, |
| 6252 | true /* afterKeyguardGone */, |
| 6253 | false /* deferred */); |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6258 | public boolean isAntiFalsingNeeded() { |
| 6259 | return onKeyguard(); |
| 6260 | } |
| 6261 | |
| 6262 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6263 | public View getChildAtPosition(MotionEvent ev) { |
| 6264 | View child = NotificationStackScrollLayout.this.getChildAtPosition(ev.getX(), |
| 6265 | ev.getY()); |
| 6266 | if (child instanceof ExpandableNotificationRow) { |
| 6267 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 6268 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 6269 | if (parent != null && parent.areChildrenExpanded() |
| 6270 | && (parent.areGutsExposed() |
| 6271 | || mSwipeHelper.getExposedMenuView() == parent |
| 6272 | || (parent.getNotificationChildren().size() == 1 |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 6273 | && parent.getEntry().isClearable()))) { |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6274 | // In this case the group is expanded and showing the menu for the |
| 6275 | // group, further interaction should apply to the group, not any |
| 6276 | // child notifications so we use the parent of the child. We also do the same |
| 6277 | // if we only have a single child. |
| 6278 | child = parent; |
| 6279 | } |
| 6280 | } |
| 6281 | return child; |
| 6282 | } |
| 6283 | |
| 6284 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6285 | public void onBeginDrag(View v) { |
| 6286 | mFalsingManager.onNotificatonStartDismissing(); |
Aaron Heuckroth | 9dc9d4f | 2018-11-15 11:04:01 -0500 | [diff] [blame] | 6287 | setSwipingInProgress(true); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 6288 | mAmbientState.onBeginDrag((ExpandableView) v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6289 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6290 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6291 | requestChildrenUpdate(); |
| 6292 | } |
| 6293 | |
| 6294 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6295 | public void onChildSnappedBack(View animView, float targetLeft) { |
| 6296 | mAmbientState.onDragFinished(animView); |
| 6297 | updateContinuousShadowDrawing(); |
Selim Cinek | ae55d83 | 2019-02-22 17:43:43 -0800 | [diff] [blame] | 6298 | updateContinuousBackgroundDrawing(); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6302 | public boolean updateSwipeProgress(View animView, boolean dismissable, |
| 6303 | float swipeProgress) { |
| 6304 | // Returning true prevents alpha fading. |
| 6305 | return !mFadeNotificationsOnDismiss; |
| 6306 | } |
| 6307 | |
| 6308 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6309 | public float getFalsingThresholdFactor() { |
| 6310 | return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
| 6311 | } |
| 6312 | |
| 6313 | @Override |
Gus Prevas | c4e68d4 | 2019-01-17 15:45:21 -0500 | [diff] [blame] | 6314 | public int getConstrainSwipeStartPosition() { |
| 6315 | NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow(); |
| 6316 | if (menuRow != null) { |
| 6317 | return Math.abs(menuRow.getMenuSnapTarget()); |
| 6318 | } |
| 6319 | return 0; |
| 6320 | } |
| 6321 | |
| 6322 | @Override |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6323 | public boolean canChildBeDismissed(View v) { |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6324 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6325 | } |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6326 | |
| 6327 | @Override |
| 6328 | public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) { |
Evan Laird | 30b9b16 | 2019-04-24 15:22:24 -0400 | [diff] [blame] | 6329 | //TODO: b/131242807 for why this doesn't do anything with direction |
| 6330 | return canChildBeDismissed(v); |
Gus Prevas | 37d67e2 | 2018-11-02 14:48:55 -0400 | [diff] [blame] | 6331 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6332 | }; |
| 6333 | |
| 6334 | // ---------------------- DragDownHelper.OnDragDownListener ------------------------------------ |
| 6335 | |
| 6336 | @ShadeViewRefactor(RefactorComponent.INPUT) |
| 6337 | private final DragDownCallback mDragDownCallback = new DragDownCallback() { |
| 6338 | |
| 6339 | /* Only ever called as a consequence of a lockscreen expansion gesture. */ |
| 6340 | @Override |
| 6341 | public boolean onDraggedDown(View startingChild, int dragLengthY) { |
| 6342 | if (mStatusBarState == StatusBarState.KEYGUARD |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6343 | && hasActiveNotifications()) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6344 | mLockscreenGestureLogger.write( |
| 6345 | MetricsEvent.ACTION_LS_SHADE, |
| 6346 | (int) (dragLengthY / mDisplayMetrics.density), |
| 6347 | 0 /* velocityDp - N/A */); |
| 6348 | |
Lucas Dupin | c780404 | 2018-12-21 12:26:33 -0800 | [diff] [blame] | 6349 | if (!mAmbientState.isDark() || startingChild != null) { |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6350 | // We have notifications, go to locked shade. |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 6351 | mShadeController.goToLockedShade(startingChild); |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6352 | if (startingChild instanceof ExpandableNotificationRow) { |
| 6353 | ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild; |
| 6354 | row.onExpandedByGesture(true /* drag down is always an open */); |
| 6355 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6356 | } |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 6357 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6358 | return true; |
| 6359 | } else { |
| 6360 | // abort gesture. |
| 6361 | return false; |
| 6362 | } |
| 6363 | } |
| 6364 | |
| 6365 | @Override |
| 6366 | public void onDragDownReset() { |
| 6367 | setDimmed(true /* dimmed */, true /* animated */); |
| 6368 | resetScrollPosition(); |
| 6369 | resetCheckSnoozeLeavebehind(); |
| 6370 | } |
| 6371 | |
| 6372 | @Override |
| 6373 | public void onCrossedThreshold(boolean above) { |
| 6374 | setDimmed(!above /* dimmed */, true /* animate */); |
| 6375 | } |
| 6376 | |
| 6377 | @Override |
| 6378 | public void onTouchSlopExceeded() { |
| 6379 | cancelLongPress(); |
| 6380 | checkSnoozeLeavebehind(); |
| 6381 | } |
| 6382 | |
| 6383 | @Override |
| 6384 | public void setEmptyDragAmount(float amount) { |
| 6385 | mNotificationPanel.setEmptyDragAmount(amount); |
| 6386 | } |
| 6387 | |
| 6388 | @Override |
| 6389 | public boolean isFalsingCheckNeeded() { |
| 6390 | return mStatusBarState == StatusBarState.KEYGUARD; |
| 6391 | } |
| 6392 | }; |
| 6393 | |
| 6394 | public DragDownCallback getDragDownCallback() { return mDragDownCallback; } |
| 6395 | |
| 6396 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6397 | private final HeadsUpTouchHelper.Callback mHeadsUpCallback = new HeadsUpTouchHelper.Callback() { |
| 6398 | @Override |
| 6399 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6400 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6401 | } |
| 6402 | |
| 6403 | @Override |
| 6404 | public boolean isExpanded() { |
| 6405 | return mIsExpanded; |
| 6406 | } |
| 6407 | |
| 6408 | @Override |
| 6409 | public Context getContext() { |
| 6410 | return mContext; |
| 6411 | } |
| 6412 | }; |
| 6413 | |
| 6414 | public HeadsUpTouchHelper.Callback getHeadsUpCallback() { return mHeadsUpCallback; } |
| 6415 | |
| 6416 | |
| 6417 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6418 | private final OnGroupChangeListener mOnGroupChangeListener = new OnGroupChangeListener() { |
| 6419 | @Override |
| 6420 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
| 6421 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 6422 | && (mIsExpanded || changedRow.isPinned()); |
| 6423 | if (animated) { |
| 6424 | mExpandedGroupView = changedRow; |
| 6425 | mNeedsAnimation = true; |
| 6426 | } |
| 6427 | changedRow.setChildrenExpanded(expanded, animated); |
| 6428 | if (!mGroupExpandedForMeasure) { |
| 6429 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 6430 | } |
| 6431 | runAfterAnimationFinished(new Runnable() { |
| 6432 | @Override |
| 6433 | public void run() { |
| 6434 | changedRow.onFinishedExpansionChange(); |
| 6435 | } |
| 6436 | }); |
| 6437 | } |
| 6438 | |
| 6439 | @Override |
| 6440 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
| 6441 | mStatusBar.requestNotificationUpdate(); |
| 6442 | } |
| 6443 | |
| 6444 | @Override |
| 6445 | public void onGroupsChanged() { |
| 6446 | mStatusBar.requestNotificationUpdate(); |
| 6447 | } |
| 6448 | }; |
| 6449 | |
| 6450 | @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) |
| 6451 | private ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { |
| 6452 | @Override |
| 6453 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
| 6454 | return NotificationStackScrollLayout.this.getChildAtPosition(touchX, touchY); |
| 6455 | } |
| 6456 | |
| 6457 | @Override |
| 6458 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
| 6459 | return NotificationStackScrollLayout.this.getChildAtRawPosition(touchX, touchY); |
| 6460 | } |
| 6461 | |
| 6462 | @Override |
| 6463 | public boolean canChildBeExpanded(View v) { |
| 6464 | return v instanceof ExpandableNotificationRow |
| 6465 | && ((ExpandableNotificationRow) v).isExpandable() |
| 6466 | && !((ExpandableNotificationRow) v).areGutsExposed() |
| 6467 | && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned()); |
| 6468 | } |
| 6469 | |
| 6470 | /* Only ever called as a consequence of an expansion gesture in the shade. */ |
| 6471 | @Override |
| 6472 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 6473 | if (v instanceof ExpandableNotificationRow) { |
| 6474 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 6475 | if (userExpanded && onKeyguard()) { |
| 6476 | // Due to a race when locking the screen while touching, a notification may be |
| 6477 | // expanded even after we went back to keyguard. An example of this happens if |
| 6478 | // you click in the empty space while expanding a group. |
| 6479 | |
| 6480 | // We also need to un-user lock it here, since otherwise the content height |
| 6481 | // calculated might be wrong. We also can't invert the two calls since |
| 6482 | // un-userlocking it will trigger a layout switch in the content view. |
| 6483 | row.setUserLocked(false); |
| 6484 | updateContentHeight(); |
| 6485 | notifyHeightChangeListener(row); |
| 6486 | return; |
| 6487 | } |
| 6488 | row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */); |
| 6489 | row.onExpandedByGesture(userExpanded); |
| 6490 | } |
| 6491 | } |
| 6492 | |
| 6493 | @Override |
| 6494 | public void setExpansionCancelled(View v) { |
| 6495 | if (v instanceof ExpandableNotificationRow) { |
| 6496 | ((ExpandableNotificationRow) v).setGroupExpansionChanging(false); |
| 6497 | } |
| 6498 | } |
| 6499 | |
| 6500 | @Override |
| 6501 | public void setUserLockedChild(View v, boolean userLocked) { |
| 6502 | if (v instanceof ExpandableNotificationRow) { |
| 6503 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 6504 | } |
| 6505 | cancelLongPress(); |
| 6506 | requestDisallowInterceptTouchEvent(true); |
| 6507 | } |
| 6508 | |
| 6509 | @Override |
| 6510 | public void expansionStateChanged(boolean isExpanding) { |
| 6511 | mExpandingNotification = isExpanding; |
| 6512 | if (!mExpandedInThisMotion) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 6513 | if (ANCHOR_SCROLLING) { |
| 6514 | // TODO |
| 6515 | } else { |
| 6516 | mMaxScrollAfterExpand = mOwnScrollY; |
| 6517 | } |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 6518 | mExpandedInThisMotion = true; |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | @Override |
| 6523 | public int getMaxExpandHeight(ExpandableView view) { |
| 6524 | return view.getMaxContentHeight(); |
| 6525 | } |
| 6526 | }; |
| 6527 | |
| 6528 | public ExpandHelper.Callback getExpandHelperCallback() { |
| 6529 | return mExpandHelperCallback; |
Aaron Heuckroth | 45d20be | 2018-09-18 13:47:26 -0400 | [diff] [blame] | 6530 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 6531 | |
| 6532 | /** Enum for selecting some or all notification rows (does not included non-notif views). */ |
| 6533 | @Retention(SOURCE) |
| 6534 | @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE}) |
| 6535 | public @interface SelectedRows {} |
| 6536 | /** All rows representing notifs. */ |
| 6537 | public static final int ROWS_ALL = 0; |
| 6538 | /** Only rows where entry.isHighPriority() is true. */ |
| 6539 | public static final int ROWS_HIGH_PRIORITY = 1; |
| 6540 | /** Only rows where entry.isHighPriority() is false. */ |
| 6541 | public static final int ROWS_GENTLE = 2; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 6542 | } |