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 | |
| 17 | package com.android.systemui.statusbar.stack; |
| 18 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 19 | import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator |
| 20 | .ExpandAnimationParameters; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 21 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 22 | import android.animation.Animator; |
| 23 | import android.animation.AnimatorListenerAdapter; |
| 24 | import android.animation.ObjectAnimator; |
| 25 | import android.animation.PropertyValuesHolder; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 26 | import android.animation.TimeAnimator; |
| 27 | import android.animation.ValueAnimator; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 28 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 29 | import android.annotation.FloatRange; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 30 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.res.Configuration; |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 33 | import android.content.res.Resources; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 34 | import android.graphics.Canvas; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 35 | import android.graphics.Color; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 36 | import android.graphics.Paint; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 37 | import android.graphics.Path; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 38 | import android.graphics.PointF; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 39 | import android.graphics.PorterDuff; |
| 40 | import android.graphics.PorterDuffXfermode; |
| 41 | import android.graphics.Rect; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 43 | import android.os.Handler; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 44 | import android.service.notification.StatusBarNotification; |
Aurimas Liutikas | fd52c14 | 2018-04-17 09:50:46 -0700 | [diff] [blame] | 45 | import androidx.annotation.NonNull; |
| 46 | import androidx.annotation.VisibleForTesting; |
| 47 | import androidx.core.graphics.ColorUtils; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 48 | import android.util.AttributeSet; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 49 | import android.util.FloatProperty; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 50 | import android.util.Log; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 51 | import android.util.MathUtils; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 52 | import android.util.Pair; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 53 | import android.util.Property; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 54 | import android.view.ContextThemeWrapper; |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 55 | import android.view.InputDevice; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 56 | import android.view.MotionEvent; |
| 57 | import android.view.VelocityTracker; |
| 58 | import android.view.View; |
| 59 | import android.view.ViewConfiguration; |
| 60 | import android.view.ViewGroup; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 61 | import android.view.ViewTreeObserver; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 62 | import android.view.WindowInsets; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 63 | import android.view.accessibility.AccessibilityEvent; |
| 64 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 65 | import android.view.animation.AnimationUtils; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 66 | import android.view.animation.Interpolator; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 67 | import android.widget.OverScroller; |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 68 | import android.widget.ScrollView; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 69 | |
Mady Mellor | a41587b | 2016-02-11 18:43:06 -0800 | [diff] [blame] | 70 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 71 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 72 | import com.android.keyguard.KeyguardSliceView; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 73 | import com.android.settingslib.Utils; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 74 | import com.android.systemui.Dependency; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 75 | import com.android.systemui.ExpandHelper; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 76 | import com.android.systemui.Interpolators; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 77 | import com.android.systemui.R; |
| 78 | import com.android.systemui.SwipeHelper; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 79 | import com.android.systemui.classifier.FalsingManager; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 80 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
| 81 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; |
| 82 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 83 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 84 | import com.android.systemui.statusbar.EmptyShadeView; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 85 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 86 | import com.android.systemui.statusbar.ExpandableView; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 87 | import com.android.systemui.statusbar.FooterView; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 88 | import com.android.systemui.statusbar.NotificationBlockingHelperManager; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 89 | import com.android.systemui.statusbar.NotificationData; |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 90 | import com.android.systemui.statusbar.NotificationGuts; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 91 | import com.android.systemui.statusbar.NotificationListContainer; |
| 92 | import com.android.systemui.statusbar.NotificationLogger; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 93 | import com.android.systemui.statusbar.NotificationShelf; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 94 | import com.android.systemui.statusbar.NotificationSnooze; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 95 | import com.android.systemui.statusbar.StackScrollerDecorView; |
Selim Cinek | cb2b673 | 2014-09-05 16:17:22 +0200 | [diff] [blame] | 96 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 97 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 98 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 99 | import com.android.systemui.statusbar.notification.VisibilityLocationProvider; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 100 | import com.android.systemui.statusbar.phone.DozeParameters; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 101 | import com.android.systemui.statusbar.phone.HeadsUpAppearanceController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 102 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 103 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 104 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 105 | import com.android.systemui.statusbar.phone.ScrimController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 106 | import com.android.systemui.statusbar.phone.StatusBar; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 107 | import com.android.systemui.statusbar.policy.HeadsUpUtil; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 108 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 109 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 110 | import java.io.FileDescriptor; |
| 111 | import java.io.PrintWriter; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 112 | import java.util.ArrayList; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 113 | import java.util.Collections; |
| 114 | import java.util.Comparator; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 115 | import java.util.HashSet; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 116 | import java.util.List; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 117 | import java.util.function.BiConsumer; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 118 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 119 | /** |
| 120 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 121 | */ |
| 122 | public class NotificationStackScrollLayout extends ViewGroup |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 123 | implements SwipeHelper.Callback, ExpandHelper.Callback, ScrollAdapter, |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 124 | ExpandableView.OnHeightChangedListener, NotificationGroupManager.OnGroupChangeListener, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 125 | NotificationMenuRowPlugin.OnMenuEventListener, VisibilityLocationProvider, |
| 126 | NotificationListContainer { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 127 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 128 | public static final float BACKGROUND_ALPHA_DIMMED = 0.7f; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 129 | private static final String TAG = "StackScroller"; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 130 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 131 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 132 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 133 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 134 | /** |
| 135 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 136 | */ |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 137 | private static final int INVALID_POINTER = -1; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 138 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 139 | private ExpandHelper mExpandHelper; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 140 | private NotificationSwipeHelper mSwipeHelper; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 141 | private boolean mSwipingInProgress; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 142 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 143 | private final Paint mBackgroundPaint = new Paint(); |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 144 | private final boolean mShouldDrawNotificationBackground; |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 145 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 146 | private float mExpandedHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 147 | private int mOwnScrollY; |
| 148 | private int mMaxLayoutHeight; |
| 149 | |
| 150 | private VelocityTracker mVelocityTracker; |
| 151 | private OverScroller mScroller; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 152 | private Runnable mFinishScrollingCallback; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 153 | private int mTouchSlop; |
| 154 | private int mMinimumVelocity; |
| 155 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 156 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 157 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 158 | private boolean mIsBeingDragged; |
| 159 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 160 | private int mDownX; |
Dong-wan Kim | b926666 | 2016-09-21 13:08:30 -0700 | [diff] [blame] | 161 | private int mActivePointerId = INVALID_POINTER; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 162 | private boolean mTouchIsClick; |
| 163 | private float mInitialTouchX; |
| 164 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 165 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 166 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 167 | private int mContentHeight; |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 168 | private int mIntrinsicContentHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 169 | private int mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 170 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 171 | private int mIncreasedPaddingBetweenElements; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 172 | private int mMaxTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 173 | private int mRegularTopPadding; |
| 174 | private int mDarkTopPadding; |
| 175 | // Current padding, will be either mRegularTopPadding or mDarkTopPadding |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 176 | private int mTopPadding; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 177 | // Distance between AOD separator and shelf |
| 178 | private int mDarkSeparatorPadding; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 179 | private int mBottomMargin; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 180 | private int mBottomInset = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 181 | private float mQsExpansionFraction; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 182 | |
| 183 | /** |
| 184 | * The algorithm which calculates the properties for our children |
| 185 | */ |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 186 | protected final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * The current State this Layout is in |
| 190 | */ |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 191 | private StackScrollState mCurrentStackScrollState = new StackScrollState(this); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 192 | private final AmbientState mAmbientState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 193 | private NotificationGroupManager mGroupManager; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 194 | private HashSet<View> mChildrenToAddAnimated = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 195 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
| 196 | private ArrayList<View> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 197 | private ArrayList<View> mSnappedBackChildren = new ArrayList<>(); |
| 198 | private ArrayList<View> mDragAnimPendingChildren = new ArrayList<>(); |
| 199 | private ArrayList<View> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 200 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 201 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 202 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 203 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 204 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 205 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 206 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 207 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 208 | /** |
| 209 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 210 | */ |
| 211 | private float mOverScrolledTopPixels; |
| 212 | |
| 213 | /** |
| 214 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 215 | */ |
| 216 | private float mOverScrolledBottomPixels; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 217 | private NotificationLogger.OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 218 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 219 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 220 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 221 | private boolean mNeedsAnimation; |
| 222 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 223 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 224 | private boolean mHideSensitiveNeedsAnimation; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 225 | private boolean mDarkNeedsAnimation; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 226 | private int mDarkAnimationOriginIndex; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 227 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 228 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 229 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 230 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 231 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 232 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 233 | private boolean mExpandingNotification; |
| 234 | private boolean mExpandedInThisMotion; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 235 | private boolean mShouldShowShelfOnly; |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 236 | protected boolean mScrollingEnabled; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 237 | protected FooterView mFooterView; |
Muyuan Li | dd9ae75 | 2016-05-13 16:45:43 -0700 | [diff] [blame] | 238 | protected EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 239 | private boolean mDismissAllInProgress; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 240 | private boolean mFadeNotificationsOnDismiss; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Was the scroller scrolled to the top when the down motion was observed? |
| 244 | */ |
| 245 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 246 | /** |
| 247 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 248 | * when over scrolling on a expanded card. |
| 249 | */ |
| 250 | private float mMinTopOverScrollToEscape; |
| 251 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 252 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 253 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 254 | private boolean mDontReportNextOverScroll; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 255 | private boolean mDontClampNextScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 256 | private boolean mNeedViewResizeAnimation; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 257 | private View mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 258 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 259 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 260 | /** |
| 261 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 262 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 263 | * motion. |
| 264 | */ |
| 265 | private int mMaxScrollAfterExpand; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 266 | private ExpandableNotificationRow.LongPressListener mLongPressListener; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 267 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 268 | private NotificationMenuRowPlugin mCurrMenuRow; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 269 | private View mTranslatingParentView; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 270 | private View mMenuExposedView; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 271 | boolean mCheckForLeavebehind; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 275 | * animating. |
| 276 | */ |
| 277 | private boolean mOnlyScrollingInThisMotion; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 278 | private boolean mDisallowDismissInThisMotion; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 279 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 280 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 281 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 282 | = new ViewTreeObserver.OnPreDrawListener() { |
| 283 | @Override |
| 284 | public boolean onPreDraw() { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 285 | updateForcedScroll(); |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 286 | updateChildren(); |
| 287 | mChildrenUpdateRequested = false; |
| 288 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | }; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 292 | private StatusBar mStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 293 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 294 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 295 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 296 | private HashSet<ExpandableView> mClearTransientViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 297 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 298 | = new HashSet<>(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 299 | private HeadsUpManagerPhone mHeadsUpManager; |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 300 | private NotificationRoundnessManager mRoundnessManager = new NotificationRoundnessManager(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 301 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 302 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 303 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 304 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 305 | private FalsingManager mFalsingManager; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 306 | private boolean mAnimationRunning; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 307 | private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 308 | = new ViewTreeObserver.OnPreDrawListener() { |
| 309 | @Override |
| 310 | public boolean onPreDraw() { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 311 | onPreDrawDuringAnimation(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 312 | return true; |
| 313 | } |
| 314 | }; |
| 315 | private Rect mBackgroundBounds = new Rect(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 316 | private Rect mStartAnimationRect = new Rect(); |
| 317 | private Rect mEndAnimationRect = new Rect(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 318 | private Rect mCurrentBounds = new Rect(-1, -1, -1, -1); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 319 | private boolean mAnimateNextBackgroundBottom; |
| 320 | private boolean mAnimateNextBackgroundTop; |
| 321 | private ObjectAnimator mBottomAnimator = null; |
| 322 | private ObjectAnimator mTopAnimator = null; |
| 323 | private ActivatableNotificationView mFirstVisibleBackgroundChild = null; |
| 324 | private ActivatableNotificationView mLastVisibleBackgroundChild = null; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 325 | private int mBgColor; |
| 326 | private float mDimAmount; |
| 327 | private ValueAnimator mDimAnimator; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 328 | private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 329 | private Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { |
| 330 | @Override |
| 331 | public void onAnimationEnd(Animator animation) { |
| 332 | mDimAnimator = null; |
| 333 | } |
| 334 | }; |
| 335 | private ValueAnimator.AnimatorUpdateListener mDimUpdateListener |
| 336 | = new ValueAnimator.AnimatorUpdateListener() { |
| 337 | |
| 338 | @Override |
| 339 | public void onAnimationUpdate(ValueAnimator animation) { |
| 340 | setDimAmount((Float) animation.getAnimatedValue()); |
| 341 | } |
| 342 | }; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 343 | protected ViewGroup mQsContainer; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 344 | private boolean mContinuousShadowUpdate; |
| 345 | private ViewTreeObserver.OnPreDrawListener mShadowUpdater |
| 346 | = new ViewTreeObserver.OnPreDrawListener() { |
| 347 | |
| 348 | @Override |
| 349 | public boolean onPreDraw() { |
| 350 | updateViewShadows(); |
| 351 | return true; |
| 352 | } |
| 353 | }; |
| 354 | private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() { |
| 355 | @Override |
| 356 | public int compare(ExpandableView view, ExpandableView otherView) { |
| 357 | float endY = view.getTranslationY() + view.getActualHeight(); |
| 358 | float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); |
| 359 | if (endY < otherEndY) { |
| 360 | return -1; |
| 361 | } else if (endY > otherEndY) { |
| 362 | return 1; |
| 363 | } else { |
| 364 | // The two notifications end at the same location |
| 365 | return 0; |
| 366 | } |
| 367 | } |
| 368 | }; |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 369 | private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 370 | private boolean mPulsing; |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 371 | private boolean mDrawBackgroundAsSrc; |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 372 | private boolean mFadingOut; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 373 | private boolean mParentNotFullyVisible; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 374 | private boolean mGroupExpandedForMeasure; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 375 | private boolean mScrollable; |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 376 | private View mForcedScroll; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 377 | private View mNeedingPulseAnimation; |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 378 | private float mDarkAmount = 0f; |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 379 | |
| 380 | /** |
| 381 | * How fast the background scales in the X direction as a factor of the Y expansion. |
| 382 | */ |
| 383 | private float mBackgroundXFactor = 1f; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 384 | private static final Property<NotificationStackScrollLayout, Float> DARK_AMOUNT = |
| 385 | new FloatProperty<NotificationStackScrollLayout>("darkAmount") { |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 386 | @Override |
| 387 | public void setValue(NotificationStackScrollLayout object, float value) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 388 | object.setDarkAmount(value); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public Float get(NotificationStackScrollLayout object) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 393 | return object.getDarkAmount(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 394 | } |
| 395 | }; |
Lucas Dupin | b98ddb4 | 2018-05-29 17:26:35 -0700 | [diff] [blame] | 396 | private ObjectAnimator mDarkAmountAnimator; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 397 | private boolean mUsingLightTheme; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 398 | private boolean mQsExpanded; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 399 | private boolean mForwardScrollable; |
| 400 | private boolean mBackwardScrollable; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 401 | private NotificationShelf mShelf; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 402 | private int mMaxDisplayedNotifications = -1; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 403 | private int mStatusBarHeight; |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 404 | private int mMinInteractionHeight; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 405 | private boolean mNoAmbient; |
| 406 | private final Rect mClipRect = new Rect(); |
| 407 | private boolean mIsClipped; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 408 | private Rect mRequestedClipBounds; |
| 409 | private boolean mInHeadsUpPinnedMode; |
| 410 | private boolean mHeadsUpAnimatingAway; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 411 | private int mStatusBarState; |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 412 | private int mCachedBackgroundColor; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 413 | private boolean mHeadsUpGoingAwayAnimationsAllowed = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 414 | private Runnable mAnimateScroll = this::animateScroll; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 415 | private int mCornerRadius; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 416 | private int mSidePaddings; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 417 | private final int mSeparatorWidth; |
| 418 | private final int mSeparatorThickness; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 419 | private final Rect mBackgroundAnimationRect = new Rect(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 420 | private int mAntiBurnInOffsetX; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 421 | private ArrayList<BiConsumer<Float, Float>> mExpandedHeightListeners = new ArrayList<>(); |
| 422 | private int mHeadsUpInset; |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 423 | private HeadsUpAppearanceController mHeadsUpAppearanceController; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 424 | private NotificationIconAreaController mIconAreaController; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 425 | private float mVerticalPanelTranslation; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 426 | |
| 427 | public NotificationStackScrollLayout(Context context) { |
| 428 | this(context, null); |
| 429 | } |
| 430 | |
| 431 | public NotificationStackScrollLayout(Context context, AttributeSet attrs) { |
| 432 | this(context, attrs, 0); |
| 433 | } |
| 434 | |
| 435 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) { |
| 436 | this(context, attrs, defStyleAttr, 0); |
| 437 | } |
| 438 | |
| 439 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr, |
| 440 | int defStyleRes) { |
| 441 | super(context, attrs, defStyleAttr, defStyleRes); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 442 | Resources res = getResources(); |
| 443 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 444 | mAmbientState = new AmbientState(context); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 445 | mBgColor = context.getColor(R.color.notification_shade_background_color); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 446 | int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 447 | int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height); |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 448 | mExpandHelper = new ExpandHelper(getContext(), this, |
| 449 | minHeight, maxHeight); |
| 450 | mExpandHelper.setEventSource(this); |
| 451 | mExpandHelper.setScrollAdapter(this); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 452 | mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, this, getContext()); |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 453 | mStackScrollAlgorithm = createStackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 454 | initView(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 455 | mFalsingManager = FalsingManager.getInstance(context); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 456 | mShouldDrawNotificationBackground = |
| 457 | res.getBoolean(R.bool.config_drawNotificationBackground); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 458 | mFadeNotificationsOnDismiss = |
| 459 | res.getBoolean(R.bool.config_fadeNotificationsOnDismiss); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 460 | mSeparatorWidth = res.getDimensionPixelSize(R.dimen.widget_separator_width); |
| 461 | mSeparatorThickness = res.getDimensionPixelSize(R.dimen.widget_separator_thickness); |
| 462 | mDarkSeparatorPadding = res.getDimensionPixelSize(R.dimen.widget_bottom_separator_padding); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 463 | mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated); |
| 464 | mRoundnessManager.setOnRoundingChangedCallback(this::invalidate); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 465 | addOnExpandedHeightListener(mRoundnessManager::setExpanded); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 466 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 467 | // Blocking helper manager wants to know the expanded state, update as well. |
| 468 | NotificationBlockingHelperManager blockingHelperManager = |
| 469 | Dependency.get(NotificationBlockingHelperManager.class); |
| 470 | addOnExpandedHeightListener((height, unused) -> { |
| 471 | blockingHelperManager.setNotificationShadeExpanded(height); |
| 472 | }); |
| 473 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 474 | updateWillNotDraw(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 475 | mBackgroundPaint.setAntiAlias(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 476 | if (DEBUG) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 477 | mDebugPaint = new Paint(); |
| 478 | mDebugPaint.setColor(0xffff0000); |
| 479 | mDebugPaint.setStrokeWidth(2); |
| 480 | mDebugPaint.setStyle(Paint.Style.STROKE); |
| 481 | } |
| 482 | } |
| 483 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 484 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 485 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 486 | return mSwipeHelper; |
| 487 | } |
| 488 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 489 | @Override |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 490 | public void onMenuClicked(View view, int x, int y, MenuItem item) { |
| 491 | if (mLongPressListener == null) { |
| 492 | return; |
| 493 | } |
| 494 | if (view instanceof ExpandableNotificationRow) { |
| 495 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Mady Mellor | a41587b | 2016-02-11 18:43:06 -0800 | [diff] [blame] | 496 | MetricsLogger.action(mContext, MetricsEvent.ACTION_TOUCH_GEAR, |
| 497 | row.getStatusBarNotification().getPackageName()); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 498 | } |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 499 | mLongPressListener.onLongPress(view, x, y, item); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | @Override |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 503 | public void onMenuReset(View row) { |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 504 | if (mTranslatingParentView != null && row == mTranslatingParentView) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 505 | mMenuExposedView = null; |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 506 | mTranslatingParentView = null; |
| 507 | } |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 511 | public void onMenuShown(View row) { |
| 512 | mMenuExposedView = mTranslatingParentView; |
| 513 | if (row instanceof ExpandableNotificationRow) { |
| 514 | MetricsLogger.action(mContext, MetricsEvent.ACTION_REVEAL_GEAR, |
| 515 | ((ExpandableNotificationRow) row).getStatusBarNotification() |
| 516 | .getPackageName()); |
| 517 | } |
| 518 | mSwipeHelper.onMenuShown(row); |
| 519 | } |
| 520 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 521 | protected void onDraw(Canvas canvas) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 522 | if (mShouldDrawNotificationBackground |
| 523 | && (mCurrentBounds.top < mCurrentBounds.bottom || mAmbientState.isDark())) { |
| 524 | drawBackground(canvas); |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 525 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 526 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 527 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 528 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 529 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 530 | y = getLayoutHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 531 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 532 | y = getHeight() - getEmptyBottomMargin(); |
| 533 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 537 | private void drawBackground(Canvas canvas) { |
| 538 | final int lockScreenLeft = mSidePaddings; |
| 539 | final int lockScreenRight = getWidth() - mSidePaddings; |
| 540 | final int lockScreenTop = mCurrentBounds.top; |
| 541 | final int lockScreenBottom = mCurrentBounds.bottom; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 542 | int separatorWidth = 0; |
| 543 | int separatorThickness = 0; |
| 544 | if (mIconAreaController.hasShelfIconsWhenFullyDark()) { |
| 545 | separatorThickness = mSeparatorThickness; |
| 546 | separatorWidth = mSeparatorWidth; |
| 547 | } |
| 548 | final int darkLeft = getWidth() / 2 - separatorWidth / 2; |
| 549 | final int darkRight = darkLeft + separatorWidth; |
| 550 | final int darkTop = (int) (mRegularTopPadding + separatorThickness / 2f); |
| 551 | final int darkBottom = darkTop + separatorThickness; |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 552 | |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 553 | if (mAmbientState.hasPulsingNotifications()) { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 554 | // No divider, we have a notification icon instead |
| 555 | } else if (mAmbientState.isFullyDark()) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 556 | // Only draw divider on AOD if we actually have notifications |
| 557 | if (mFirstVisibleBackgroundChild != null) { |
| 558 | canvas.drawRect(darkLeft, darkTop, darkRight, darkBottom, mBackgroundPaint); |
| 559 | } |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 560 | } else { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 561 | float inverseDark = 1 - mDarkAmount; |
| 562 | float yProgress = Interpolators.FAST_OUT_SLOW_IN.getInterpolation(inverseDark); |
| 563 | float xProgress = Interpolators.FAST_OUT_SLOW_IN |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 564 | .getInterpolation(inverseDark * mBackgroundXFactor); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 565 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 566 | mBackgroundAnimationRect.set( |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 567 | (int) MathUtils.lerp(darkLeft, lockScreenLeft, xProgress), |
| 568 | (int) MathUtils.lerp(darkTop, lockScreenTop, yProgress), |
| 569 | (int) MathUtils.lerp(darkRight, lockScreenRight, xProgress), |
| 570 | (int) MathUtils.lerp(darkBottom, lockScreenBottom, yProgress)); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 571 | if (!mAmbientState.isDark() || mFirstVisibleBackgroundChild != null) { |
| 572 | canvas.drawRoundRect(mBackgroundAnimationRect.left, mBackgroundAnimationRect.top, |
| 573 | mBackgroundAnimationRect.right, mBackgroundAnimationRect.bottom, |
| 574 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 575 | } |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 576 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 577 | updateClipping(); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 580 | private void updateBackgroundDimming() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 581 | // No need to update the background color if it's not being drawn. |
| 582 | if (!mShouldDrawNotificationBackground) { |
| 583 | return; |
| 584 | } |
| 585 | |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 586 | float alpha = |
| 587 | BACKGROUND_ALPHA_DIMMED + (1 - BACKGROUND_ALPHA_DIMMED) * (1.0f - mDimAmount); |
| 588 | alpha *= 1f - mDarkAmount; |
| 589 | // We need to manually blend in the background color. |
| 590 | int scrimColor = mScrimController.getBackgroundColor(); |
| 591 | int awakeColor = ColorUtils.blendARGB(scrimColor, mBgColor, alpha); |
| 592 | |
| 593 | // Interpolate between semi-transparent notification panel background color |
| 594 | // and white AOD separator. |
| 595 | float colorInterpolation = Interpolators.DECELERATE_QUINT.getInterpolation(mDarkAmount); |
| 596 | int color = ColorUtils.blendARGB(awakeColor, Color.WHITE, colorInterpolation); |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 597 | |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 598 | if (mCachedBackgroundColor != color) { |
| 599 | mCachedBackgroundColor = color; |
| 600 | mBackgroundPaint.setColor(color); |
| 601 | invalidate(); |
| 602 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 603 | } |
| 604 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 605 | private void initView(Context context) { |
| 606 | mScroller = new OverScroller(getContext()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 607 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 608 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 609 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 610 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 611 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 612 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 613 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 614 | |
| 615 | Resources res = context.getResources(); |
| 616 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 617 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 618 | mAmbientState.reload(context); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 619 | mPaddingBetweenElements = Math.max(1, |
| 620 | res.getDimensionPixelSize(R.dimen.notification_divider_height)); |
| 621 | mIncreasedPaddingBetweenElements = |
| 622 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 623 | mMinTopOverScrollToEscape = res.getDimensionPixelSize( |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 624 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 625 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 626 | mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 627 | mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 628 | mMinInteractionHeight = res.getDimensionPixelSize( |
| 629 | R.dimen.notification_min_interaction_height); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 630 | mCornerRadius = res.getDimensionPixelSize( |
| 631 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 632 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 633 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 634 | } |
| 635 | |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 636 | public void setDrawBackgroundAsSrc(boolean asSrc) { |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 637 | mDrawBackgroundAsSrc = asSrc; |
| 638 | updateSrcDrawing(); |
| 639 | } |
| 640 | |
| 641 | private void updateSrcDrawing() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 642 | if (!mShouldDrawNotificationBackground) { |
| 643 | return; |
| 644 | } |
| 645 | |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 646 | mBackgroundPaint.setXfermode(mDrawBackgroundAsSrc && !mFadingOut && !mParentNotFullyVisible |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 647 | ? mSrcMode : null); |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 648 | invalidate(); |
| 649 | } |
| 650 | |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 651 | private void notifyHeightChangeListener(ExpandableView view) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 652 | notifyHeightChangeListener(view, false /* needsAnimation */); |
| 653 | } |
| 654 | |
| 655 | private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) { |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 656 | if (mOnHeightChangedListener != null) { |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 657 | mOnHeightChangedListener.onHeightChanged(view, needsAnimation); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 658 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | @Override |
| 662 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 663 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 664 | |
| 665 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 666 | int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2, |
| 667 | MeasureSpec.getMode(widthMeasureSpec)); |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame^] | 668 | // Don't constrain the height of the children so we know how big they'd like to be |
| 669 | int childHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), |
| 670 | MeasureSpec.UNSPECIFIED); |
| 671 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 672 | // We need to measure all children even the GONE ones, such that the heights are calculated |
| 673 | // correctly as they are used to calculate how many we can fit on the screen. |
| 674 | final int size = getChildCount(); |
| 675 | for (int i = 0; i < size; i++) { |
Evan Laird | eb7dbd5 | 2018-06-28 13:17:25 -0400 | [diff] [blame^] | 676 | measureChild(getChildAt(i), childWidthSpec, childHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 677 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | @Override |
| 681 | 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] | 682 | // we layout all our children centered on the top |
| 683 | float centerX = getWidth() / 2.0f; |
| 684 | for (int i = 0; i < getChildCount(); i++) { |
| 685 | View child = getChildAt(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 686 | // We need to layout all children even the GONE ones, such that the heights are |
| 687 | // 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] | 688 | float width = child.getMeasuredWidth(); |
| 689 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 690 | child.layout((int) (centerX - width / 2.0f), |
| 691 | 0, |
| 692 | (int) (centerX + width / 2.0f), |
| 693 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 694 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 695 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 696 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 697 | clampScrollPosition(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 698 | requestChildrenUpdate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 699 | updateFirstAndLastBackgroundViews(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 700 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 701 | } |
| 702 | |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 703 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 704 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 705 | mNeedViewResizeAnimation = true; |
| 706 | mNeedsAnimation = true; |
| 707 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 710 | public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) { |
| 711 | mAmbientState.setSpeedBumpIndex(newIndex); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 712 | mNoAmbient = noAmbient; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 713 | } |
| 714 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 715 | @Override |
| 716 | public void setChildLocationsChangedListener( |
| 717 | NotificationLogger.OnChildLocationsChangedListener listener) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 718 | mListener = listener; |
| 719 | } |
| 720 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 721 | @Override |
| 722 | public boolean isInVisibleLocation(ExpandableNotificationRow row) { |
| 723 | ExpandableViewState childViewState = mCurrentStackScrollState.getViewStateForView(row); |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 724 | if (childViewState == null) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 725 | return false; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 726 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 727 | if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 728 | return false; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 729 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 730 | if (row.getVisibility() != View.VISIBLE) { |
| 731 | return false; |
| 732 | } |
| 733 | return true; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 734 | } |
| 735 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 736 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 737 | mMaxLayoutHeight = maxLayoutHeight; |
Selim Cinek | 9458b19 | 2016-10-25 19:02:42 -0700 | [diff] [blame] | 738 | mShelf.setMaxLayoutHeight(maxLayoutHeight); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 739 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 742 | private void updateAlgorithmHeightAndPadding() { |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 743 | mTopPadding = (int) MathUtils.lerp(mRegularTopPadding, mDarkTopPadding, mDarkAmount); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 744 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 745 | updateAlgorithmLayoutMinHeight(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 746 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 749 | private void updateAlgorithmLayoutMinHeight() { |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 750 | mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition() |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 751 | ? getLayoutMinHeight() : 0); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 754 | /** |
| 755 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 756 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 757 | */ |
| 758 | private void updateChildren() { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 759 | updateScrollStateForAddedChildren(); |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 760 | mAmbientState.setCurrentScrollVelocity(mScroller.isFinished() |
| 761 | ? 0 |
| 762 | : mScroller.getCurrVelocity()); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 763 | mAmbientState.setScrollY(mOwnScrollY); |
| 764 | mStackScrollAlgorithm.getStackScrollState(mAmbientState, mCurrentStackScrollState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 765 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 766 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 767 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 768 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 772 | private void onPreDrawDuringAnimation() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 773 | mShelf.updateAppearance(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 774 | updateClippingToTopRoundedCorner(); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 775 | if (!mNeedsAnimation && !mChildrenUpdateRequested) { |
| 776 | updateBackground(); |
| 777 | } |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 780 | private void updateClippingToTopRoundedCorner() { |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 781 | Float clipStart = (float) mTopPadding |
| 782 | + mStackTranslation |
| 783 | + mAmbientState.getExpandAnimationTopChange(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 784 | Float clipEnd = clipStart + mCornerRadius; |
| 785 | boolean first = true; |
| 786 | for (int i = 0; i < getChildCount(); i++) { |
| 787 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 788 | if (child.getVisibility() == GONE) { |
| 789 | continue; |
| 790 | } |
| 791 | float start = child.getTranslationY(); |
Arthur Hung | c0ef565 | 2018-05-22 14:00:42 +0800 | [diff] [blame] | 792 | float end = start + child.getActualHeight(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 793 | boolean clip = clipStart > start && clipStart < end |
| 794 | || clipEnd >= start && clipEnd <= end; |
| 795 | clip &= !(first && mOwnScrollY == 0); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 796 | child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0) |
| 797 | : ExpandableView.NO_ROUNDNESS); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 798 | first = false; |
| 799 | } |
| 800 | } |
| 801 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 802 | private void updateScrollStateForAddedChildren() { |
| 803 | if (mChildrenToAddAnimated.isEmpty()) { |
| 804 | return; |
| 805 | } |
| 806 | for (int i = 0; i < getChildCount(); i++) { |
| 807 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 808 | if (mChildrenToAddAnimated.contains(child)) { |
| 809 | int startingPosition = getPositionInLinearLayout(child); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 810 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
| 811 | int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements |
| 812 | : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 813 | int childHeight = getIntrinsicHeight(child) + padding; |
| 814 | if (startingPosition < mOwnScrollY) { |
| 815 | // This child starts off screen, so let's keep it offscreen to keep the others visible |
| 816 | |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 817 | setOwnScrollY(mOwnScrollY + childHeight); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | } |
| 821 | clampScrollPosition(); |
| 822 | } |
| 823 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 824 | private void updateForcedScroll() { |
| 825 | if (mForcedScroll != null && (!mForcedScroll.hasFocus() |
| 826 | || !mForcedScroll.isAttachedToWindow())) { |
| 827 | mForcedScroll = null; |
| 828 | } |
| 829 | if (mForcedScroll != null) { |
| 830 | ExpandableView expandableView = (ExpandableView) mForcedScroll; |
| 831 | int positionInLinearLayout = getPositionInLinearLayout(expandableView); |
| 832 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 833 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 834 | |
| 835 | targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange())); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 836 | |
| 837 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 838 | // that it is not visible anymore. |
| 839 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 840 | setOwnScrollY(targetScroll); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 845 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 846 | if (!mChildrenUpdateRequested) { |
| 847 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 848 | mChildrenUpdateRequested = true; |
| 849 | invalidate(); |
| 850 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 851 | } |
| 852 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 853 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 854 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 855 | } |
| 856 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 857 | private void clampScrollPosition() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 858 | int scrollRange = getScrollRange(); |
| 859 | if (scrollRange < mOwnScrollY) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 860 | setOwnScrollY(scrollRange); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 864 | public int getTopPadding() { |
| 865 | return mTopPadding; |
| 866 | } |
| 867 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 868 | private void setTopPadding(int topPadding, boolean animate) { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 869 | if (mRegularTopPadding != topPadding) { |
| 870 | mRegularTopPadding = topPadding; |
| 871 | mDarkTopPadding = topPadding + mDarkSeparatorPadding; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 872 | mAmbientState.setDarkTopPadding(mDarkTopPadding); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 873 | updateAlgorithmHeightAndPadding(); |
| 874 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 875 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 876 | mTopPaddingNeedsAnimation = true; |
| 877 | mNeedsAnimation = true; |
| 878 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 879 | requestChildrenUpdate(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 880 | notifyHeightChangeListener(null, animate); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
| 884 | /** |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 885 | * Update the height of the panel. |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 886 | * |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 887 | * @param height the expanded height of the panel |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 888 | */ |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 889 | public void setExpandedHeight(float height) { |
| 890 | mExpandedHeight = height; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 891 | setIsExpanded(height > 0); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 892 | int minExpansionHeight = getMinExpansionHeight(); |
| 893 | if (height < minExpansionHeight) { |
| 894 | mClipRect.left = 0; |
| 895 | mClipRect.right = getWidth(); |
| 896 | mClipRect.top = 0; |
| 897 | mClipRect.bottom = (int) height; |
| 898 | height = minExpansionHeight; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 899 | setRequestedClipBounds(mClipRect); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 900 | } else { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 901 | setRequestedClipBounds(null); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 902 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 903 | int stackHeight; |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 904 | float translationY; |
| 905 | float appearEndPosition = getAppearEndPosition(); |
| 906 | float appearStartPosition = getAppearStartPosition(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 907 | float appearFraction = 1.0f; |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 908 | boolean appearing = height < appearEndPosition; |
| 909 | mAmbientState.setAppearing(appearing); |
| 910 | if (!appearing) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 911 | translationY = 0; |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 912 | if (mShouldShowShelfOnly) { |
| 913 | stackHeight = mTopPadding + mShelf.getIntrinsicHeight(); |
| 914 | } else if (mQsExpanded) { |
| 915 | int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding; |
| 916 | int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight(); |
| 917 | if (stackStartPosition <= stackEndPosition) { |
| 918 | stackHeight = stackEndPosition; |
| 919 | } else { |
| 920 | stackHeight = (int) NotificationUtils.interpolate(stackStartPosition, |
| 921 | stackEndPosition, mQsExpansionFraction); |
| 922 | } |
| 923 | } else { |
| 924 | stackHeight = (int) height; |
| 925 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 926 | } else { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 927 | appearFraction = getAppearFraction(height); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 928 | if (appearFraction >= 0) { |
| 929 | translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0, |
| 930 | appearFraction); |
| 931 | } else { |
| 932 | // This may happen when pushing up a heads up. We linearly push it up from the |
| 933 | // start |
| 934 | translationY = height - appearStartPosition + getExpandTranslationStart(); |
| 935 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 936 | if (isHeadsUpTransition()) { |
| 937 | stackHeight = mFirstVisibleBackgroundChild.getPinnedHeadsUpHeight(); |
| 938 | translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction); |
| 939 | } else { |
| 940 | stackHeight = (int) (height - translationY); |
| 941 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 942 | } |
| 943 | if (stackHeight != mCurrentStackHeight) { |
| 944 | mCurrentStackHeight = stackHeight; |
| 945 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 946 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 947 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 948 | setStackTranslation(translationY); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 949 | for (int i = 0; i < mExpandedHeightListeners.size(); i++) { |
| 950 | BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i); |
| 951 | listener.accept(mExpandedHeight, appearFraction); |
| 952 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | private void setRequestedClipBounds(Rect clipRect) { |
| 956 | mRequestedClipBounds = clipRect; |
| 957 | updateClipping(); |
| 958 | } |
| 959 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 960 | /** |
| 961 | * Return the height of the content ignoring the footer. |
| 962 | */ |
| 963 | public int getIntrinsicContentHeight() { |
| 964 | return mIntrinsicContentHeight; |
| 965 | } |
| 966 | |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 967 | public void updateClipping() { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 968 | boolean animatingClipping = mDarkAmount > 0 && mDarkAmount < 1; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 969 | boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode |
| 970 | && !mHeadsUpAnimatingAway; |
| 971 | if (mIsClipped != clipped) { |
| 972 | mIsClipped = clipped; |
| 973 | updateFadingState(); |
| 974 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 975 | |
| 976 | if (animatingClipping) { |
| 977 | setClipBounds(mBackgroundAnimationRect); |
| 978 | } else if (clipped) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 979 | setClipBounds(mRequestedClipBounds); |
| 980 | } else { |
| 981 | setClipBounds(null); |
| 982 | } |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | /** |
| 986 | * @return The translation at the beginning when expanding. |
| 987 | * Measured relative to the resting position. |
| 988 | */ |
| 989 | private float getExpandTranslationStart() { |
Selim Cinek | 5bb958d | 2018-06-18 19:38:11 -0700 | [diff] [blame] | 990 | return -mTopPadding + getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /** |
| 994 | * @return the position from where the appear transition starts when expanding. |
| 995 | * Measured in absolute height. |
| 996 | */ |
| 997 | private float getAppearStartPosition() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 998 | if (isHeadsUpTransition()) { |
| 999 | return mHeadsUpInset + mFirstVisibleBackgroundChild.getPinnedHeadsUpHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1000 | } |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 1001 | return getMinExpansionHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1005 | * @return the height of the top heads up notification when pinned. This is different from the |
| 1006 | * intrinsic height, which also includes whether the notification is system expanded and |
| 1007 | * is mainly used when dragging down from a heads up notification. |
| 1008 | */ |
| 1009 | private int getTopHeadsUpPinnedHeight() { |
| 1010 | NotificationData.Entry topEntry = mHeadsUpManager.getTopEntry(); |
| 1011 | if (topEntry == null) { |
| 1012 | return 0; |
| 1013 | } |
| 1014 | ExpandableNotificationRow row = topEntry.row; |
| 1015 | if (row.isChildInGroup()) { |
| 1016 | final ExpandableNotificationRow groupSummary |
| 1017 | = mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 1018 | if (groupSummary != null) { |
| 1019 | row = groupSummary; |
| 1020 | } |
| 1021 | } |
| 1022 | return row.getPinnedHeadsUpHeight(); |
| 1023 | } |
| 1024 | |
| 1025 | /** |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1026 | * @return the position from where the appear transition ends when expanding. |
| 1027 | * Measured in absolute height. |
| 1028 | */ |
| 1029 | private float getAppearEndPosition() { |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1030 | int appearPosition; |
Selim Cinek | 66440cf | 2017-05-26 13:48:47 -0700 | [diff] [blame] | 1031 | int notGoneChildCount = getNotGoneChildCount(); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 1032 | if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1033 | if (isHeadsUpTransition() |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 1034 | || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDark())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1035 | appearPosition = getTopHeadsUpPinnedHeight(); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1036 | } else { |
| 1037 | appearPosition = 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1038 | if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) { |
| 1039 | appearPosition += mShelf.getIntrinsicHeight(); |
| 1040 | } |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1041 | } |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1042 | } else { |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 1043 | appearPosition = mEmptyShadeView.getHeight(); |
Selim Cinek | aa417da | 2016-10-27 18:17:08 -0700 | [diff] [blame] | 1044 | } |
| 1045 | return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1048 | private boolean isHeadsUpTransition() { |
| 1049 | return mTrackingHeadsUp && mFirstVisibleBackgroundChild != null |
| 1050 | && mAmbientState.isAboveShelf(mFirstVisibleBackgroundChild); |
| 1051 | } |
| 1052 | |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 1053 | /** |
| 1054 | * @param height the height of the panel |
| 1055 | * @return the fraction of the appear animation that has been performed |
| 1056 | */ |
| 1057 | public float getAppearFraction(float height) { |
| 1058 | float appearEndPosition = getAppearEndPosition(); |
| 1059 | float appearStartPosition = getAppearStartPosition(); |
| 1060 | return (height - appearStartPosition) |
| 1061 | / (appearEndPosition - appearStartPosition); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1064 | public float getStackTranslation() { |
| 1065 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 1068 | private void setStackTranslation(float stackTranslation) { |
| 1069 | if (stackTranslation != mStackTranslation) { |
| 1070 | mStackTranslation = stackTranslation; |
| 1071 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1072 | requestChildrenUpdate(); |
| 1073 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1077 | * 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] | 1078 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 1079 | * |
| 1080 | * @return either the layout height or the externally defined height, whichever is smaller |
| 1081 | */ |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1082 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1083 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 1084 | } |
| 1085 | |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1086 | public int getFirstItemMinHeight() { |
| 1087 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1088 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 1091 | public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) { |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1092 | mLongPressListener = listener; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1095 | public void setQsContainer(ViewGroup qsContainer) { |
| 1096 | mQsContainer = qsContainer; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1099 | /** |
| 1100 | * Handles cleanup after the given {@code view} has been fully swiped out (including |
| 1101 | * re-invoking dismiss logic in case the notification has not made its way out yet). |
| 1102 | */ |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1103 | @Override |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1104 | public void onChildDismissed(View view) { |
| 1105 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 1106 | if (!row.isDismissed()) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1107 | handleChildViewDismissed(view); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 1108 | } |
| 1109 | ViewGroup transientContainer = row.getTransientContainer(); |
| 1110 | if (transientContainer != null) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1111 | transientContainer.removeTransientView(view); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1115 | /** |
| 1116 | * Starts up notification dismiss and tells the notification, if any, to remove itself from |
| 1117 | * layout. |
| 1118 | * |
| 1119 | * @param view view (e.g. notification) to dismiss from the layout |
| 1120 | */ |
| 1121 | private void handleChildViewDismissed(View view) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1122 | if (mDismissAllInProgress) { |
| 1123 | return; |
| 1124 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1125 | |
| 1126 | boolean isBlockingHelperShown = false; |
| 1127 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1128 | setSwipingInProgress(false); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1129 | if (mDragAnimPendingChildren.contains(view)) { |
| 1130 | // We start the swipe and finish it in the same frame; we don't want a drag animation. |
| 1131 | mDragAnimPendingChildren.remove(view); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1132 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1133 | mAmbientState.onDragFinished(view); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 1134 | updateContinuousShadowDrawing(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1135 | |
| 1136 | if (view instanceof ExpandableNotificationRow) { |
| 1137 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1138 | if (row.isHeadsUp()) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1139 | mHeadsUpManager.addSwipedOutNotification(row.getStatusBarNotification().getKey()); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1140 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1141 | isBlockingHelperShown = |
| 1142 | row.performDismissWithBlockingHelper(false /* fromAccessibility */); |
yoshiki iguchi | 85ccbbc | 2018-01-22 12:33:21 +0900 | [diff] [blame] | 1143 | } |
Blazej Magnowski | 7232332 | 2015-07-24 11:49:40 -0700 | [diff] [blame] | 1144 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1145 | if (!isBlockingHelperShown) { |
| 1146 | mSwipedOutViews.add(view); |
| 1147 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1148 | mFalsingManager.onNotificationDismissed(); |
| 1149 | if (mFalsingManager.shouldEnforceBouncer()) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1150 | mStatusBar.executeRunnableDismissingKeyguard( |
| 1151 | null, |
| 1152 | null /* cancelAction */, |
| 1153 | false /* dismissShade */, |
| 1154 | true /* afterKeyguardGone */, |
| 1155 | false /* deferred */); |
Blazej Magnowski | 7232332 | 2015-07-24 11:49:40 -0700 | [diff] [blame] | 1156 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | @Override |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1160 | public void onChildSnappedBack(View animView, float targetLeft) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1161 | mAmbientState.onDragFinished(animView); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 1162 | updateContinuousShadowDrawing(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1163 | if (!mDragAnimPendingChildren.contains(animView)) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1164 | if (mAnimationsEnabled) { |
| 1165 | mSnappedBackChildren.add(animView); |
| 1166 | mNeedsAnimation = true; |
| 1167 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1168 | requestChildrenUpdate(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1169 | } else { |
| 1170 | // We start the swipe and snap back in the same frame, we don't want any animation |
| 1171 | mDragAnimPendingChildren.remove(animView); |
| 1172 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1173 | if (mCurrMenuRow != null && targetLeft == 0) { |
| 1174 | mCurrMenuRow.resetMenu(); |
| 1175 | mCurrMenuRow = null; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1176 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1177 | } |
| 1178 | |
Adrian Roos | 5d9cc66 | 2014-05-28 17:08:13 +0200 | [diff] [blame] | 1179 | @Override |
| 1180 | public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) { |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1181 | // Returning true prevents alpha fading. |
| 1182 | return !mFadeNotificationsOnDismiss; |
Adrian Roos | 5d9cc66 | 2014-05-28 17:08:13 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1185 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1186 | public void onBeginDrag(View v) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1187 | mFalsingManager.onNotificatonStartDismissing(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1188 | setSwipingInProgress(true); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1189 | mAmbientState.onBeginDrag(v); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 1190 | updateContinuousShadowDrawing(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1191 | if (mAnimationsEnabled && (mIsExpanded || !isPinnedHeadsUp(v))) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1192 | mDragAnimPendingChildren.add(v); |
| 1193 | mNeedsAnimation = true; |
| 1194 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1195 | requestChildrenUpdate(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1198 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1199 | if (v instanceof ExpandableNotificationRow) { |
| 1200 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1201 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1202 | } |
| 1203 | return false; |
| 1204 | } |
| 1205 | |
| 1206 | private boolean isHeadsUp(View v) { |
| 1207 | if (v instanceof ExpandableNotificationRow) { |
| 1208 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1209 | return row.isHeadsUp(); |
| 1210 | } |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1214 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1215 | public void onDragCancelled(View v) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1216 | mFalsingManager.onNotificatonStopDismissing(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1217 | setSwipingInProgress(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1218 | } |
| 1219 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1220 | @Override |
| 1221 | public float getFalsingThresholdFactor() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1222 | return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1225 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1226 | public View getChildAtPosition(MotionEvent ev) { |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1227 | View child = getChildAtPosition(ev.getX(), ev.getY()); |
| 1228 | if (child instanceof ExpandableNotificationRow) { |
| 1229 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 1230 | ExpandableNotificationRow parent = row.getNotificationParent(); |
Selim Cinek | 43d30f0 | 2016-03-04 10:51:32 -0800 | [diff] [blame] | 1231 | if (parent != null && parent.areChildrenExpanded() |
Selim Cinek | 38d429f | 2016-06-03 11:46:56 -0700 | [diff] [blame] | 1232 | && (parent.areGutsExposed() |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1233 | || mMenuExposedView == parent |
Selim Cinek | 43d30f0 | 2016-03-04 10:51:32 -0800 | [diff] [blame] | 1234 | || (parent.getNotificationChildren().size() == 1 |
| 1235 | && parent.isClearable()))) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1236 | // In this case the group is expanded and showing the menu for the |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1237 | // group, further interaction should apply to the group, not any |
Selim Cinek | 43d30f0 | 2016-03-04 10:51:32 -0800 | [diff] [blame] | 1238 | // child notifications so we use the parent of the child. We also do the same |
| 1239 | // if we only have a single child. |
| 1240 | child = parent; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1241 | } |
| 1242 | } |
| 1243 | return child; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1244 | } |
| 1245 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1246 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 1247 | getLocationOnScreen(mTempInt2); |
| 1248 | float localTouchY = touchY - mTempInt2[1]; |
| 1249 | |
| 1250 | ExpandableView closestChild = null; |
| 1251 | float minDist = Float.MAX_VALUE; |
| 1252 | |
| 1253 | // find the view closest to the location, accounting for GONE views |
| 1254 | final int count = getChildCount(); |
| 1255 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 1256 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 1257 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1258 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1259 | continue; |
| 1260 | } |
| 1261 | float childTop = slidingChild.getTranslationY(); |
| 1262 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1263 | float bottom = childTop + slidingChild.getActualHeight() |
| 1264 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1265 | |
| 1266 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 1267 | if (dist < minDist) { |
| 1268 | closestChild = slidingChild; |
| 1269 | minDist = dist; |
| 1270 | } |
| 1271 | } |
| 1272 | return closestChild; |
| 1273 | } |
| 1274 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1275 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1276 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 1277 | getLocationOnScreen(mTempInt2); |
| 1278 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1281 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1282 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1283 | return getChildAtPosition(touchX, touchY, true /* requireMinHeight */); |
| 1284 | |
| 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | * Get the child at a certain screen location. |
| 1289 | * |
| 1290 | * @param touchX the x coordinate |
| 1291 | * @param touchY the y coordinate |
| 1292 | * @param requireMinHeight Whether a minimum height is required for a child to be returned. |
| 1293 | * @return the child at the given location. |
| 1294 | */ |
| 1295 | private ExpandableView getChildAtPosition(float touchX, float touchY, |
| 1296 | boolean requireMinHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1297 | // find the view under the pointer, accounting for GONE views |
| 1298 | final int count = getChildCount(); |
| 1299 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1300 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1301 | if (slidingChild.getVisibility() != VISIBLE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame] | 1302 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1303 | continue; |
| 1304 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 1305 | float childTop = slidingChild.getTranslationY(); |
| 1306 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1307 | float bottom = childTop + slidingChild.getActualHeight() |
| 1308 | - slidingChild.getClipBottomAmount(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 1309 | |
| 1310 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 1311 | // camera affordance). |
| 1312 | int left = 0; |
| 1313 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1314 | |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 1315 | if ((bottom - top >= mMinInteractionHeight || !requireMinHeight) |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 1316 | && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1317 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 1318 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1319 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1320 | && mHeadsUpManager.getTopEntry().row != row |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1321 | && mGroupManager.getGroupSummary( |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1322 | mHeadsUpManager.getTopEntry().row.getStatusBarNotification()) |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 1323 | != row) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1324 | continue; |
| 1325 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1326 | return row.getViewAtPosition(touchY - childTop); |
| 1327 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1328 | return slidingChild; |
| 1329 | } |
| 1330 | } |
| 1331 | return null; |
| 1332 | } |
| 1333 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1334 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1335 | public boolean canChildBeExpanded(View v) { |
| 1336 | return v instanceof ExpandableNotificationRow |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1337 | && ((ExpandableNotificationRow) v).isExpandable() |
Selim Cinek | 38d429f | 2016-06-03 11:46:56 -0700 | [diff] [blame] | 1338 | && !((ExpandableNotificationRow) v).areGutsExposed() |
Selim Cinek | 166f7c4 | 2016-03-03 16:21:37 -0800 | [diff] [blame] | 1339 | && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1340 | } |
| 1341 | |
Chris Wren | 6abeeb9 | 2016-05-26 14:44:38 -0400 | [diff] [blame] | 1342 | /* Only ever called as a consequence of an expansion gesture in the shade. */ |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1343 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1344 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 1345 | if (v instanceof ExpandableNotificationRow) { |
Chris Wren | 6abeeb9 | 2016-05-26 14:44:38 -0400 | [diff] [blame] | 1346 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 740c111 | 2016-12-22 16:39:54 +0100 | [diff] [blame] | 1347 | if (userExpanded && onKeyguard()) { |
| 1348 | // Due to a race when locking the screen while touching, a notification may be |
| 1349 | // expanded even after we went back to keyguard. An example of this happens if |
| 1350 | // you click in the empty space while expanding a group. |
| 1351 | |
| 1352 | // We also need to un-user lock it here, since otherwise the content height |
| 1353 | // calculated might be wrong. We also can't invert the two calls since |
| 1354 | // un-userlocking it will trigger a layout switch in the content view. |
| 1355 | row.setUserLocked(false); |
| 1356 | updateContentHeight(); |
| 1357 | notifyHeightChangeListener(row); |
| 1358 | return; |
| 1359 | } |
Chris Wren | 6abeeb9 | 2016-05-26 14:44:38 -0400 | [diff] [blame] | 1360 | row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */); |
| 1361 | row.onExpandedByGesture(userExpanded); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1365 | @Override |
| 1366 | public void setExpansionCancelled(View v) { |
| 1367 | if (v instanceof ExpandableNotificationRow) { |
| 1368 | ((ExpandableNotificationRow) v).setGroupExpansionChanging(false); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1373 | public void setUserLockedChild(View v, boolean userLocked) { |
| 1374 | if (v instanceof ExpandableNotificationRow) { |
| 1375 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 1376 | } |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 1377 | cancelLongPress(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1378 | requestDisallowInterceptTouchEvent(true); |
| 1379 | } |
| 1380 | |
| 1381 | @Override |
| 1382 | public void expansionStateChanged(boolean isExpanding) { |
| 1383 | mExpandingNotification = isExpanding; |
| 1384 | if (!mExpandedInThisMotion) { |
| 1385 | mMaxScrollAfterExpand = mOwnScrollY; |
| 1386 | mExpandedInThisMotion = true; |
| 1387 | } |
| 1388 | } |
| 1389 | |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1390 | @Override |
| 1391 | public int getMaxExpandHeight(ExpandableView view) { |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 1392 | return view.getMaxContentHeight(); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1395 | public void setScrollingEnabled(boolean enable) { |
| 1396 | mScrollingEnabled = enable; |
| 1397 | } |
| 1398 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1399 | public void lockScrollTo(View v) { |
| 1400 | if (mForcedScroll == v) { |
| 1401 | return; |
| 1402 | } |
| 1403 | mForcedScroll = v; |
| 1404 | scrollTo(v); |
| 1405 | } |
| 1406 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1407 | public boolean scrollTo(View v) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1408 | ExpandableView expandableView = (ExpandableView) v; |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1409 | int positionInLinearLayout = getPositionInLinearLayout(v); |
| 1410 | int targetScroll = targetScrollForView(expandableView, positionInLinearLayout); |
| 1411 | int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1412 | |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1413 | // Only apply the scroll if we're scrolling the view upwards, or the view is so far up |
| 1414 | // that it is not visible anymore. |
| 1415 | if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1416 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY); |
| 1417 | mDontReportNextOverScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1418 | animateScroll(); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1419 | return true; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1420 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1421 | return false; |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1424 | /** |
| 1425 | * @return the scroll necessary to make the bottom edge of {@param v} align with the top of |
| 1426 | * the IME. |
| 1427 | */ |
| 1428 | private int targetScrollForView(ExpandableView v, int positionInLinearLayout) { |
| 1429 | return positionInLinearLayout + v.getIntrinsicHeight() + |
| 1430 | getImeInset() - getHeight() + getTopPadding(); |
| 1431 | } |
| 1432 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1433 | @Override |
| 1434 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1435 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1436 | |
| 1437 | int range = getScrollRange(); |
| 1438 | if (mOwnScrollY > range) { |
| 1439 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1440 | // animating away. To work around that we'll wait until things have settled. |
| 1441 | removeCallbacks(mReclamp); |
| 1442 | postDelayed(mReclamp, 50); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1443 | } else if (mForcedScroll != null) { |
| 1444 | // The scroll was requested before we got the actual inset - in case we need |
| 1445 | // to scroll up some more do so now. |
| 1446 | scrollTo(mForcedScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1447 | } |
| 1448 | return insets; |
| 1449 | } |
| 1450 | |
| 1451 | private Runnable mReclamp = new Runnable() { |
| 1452 | @Override |
| 1453 | public void run() { |
| 1454 | int range = getScrollRange(); |
| 1455 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1456 | mDontReportNextOverScroll = true; |
| 1457 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1458 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1459 | } |
| 1460 | }; |
| 1461 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1462 | public void setExpandingEnabled(boolean enable) { |
| 1463 | mExpandHelper.setEnabled(enable); |
| 1464 | } |
| 1465 | |
| 1466 | private boolean isScrollingEnabled() { |
| 1467 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1468 | } |
| 1469 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1470 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1471 | public boolean canChildBeDismissed(View v) { |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 1472 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1473 | } |
| 1474 | |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1475 | @Override |
| 1476 | public boolean isAntiFalsingNeeded() { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1477 | return onKeyguard(); |
| 1478 | } |
| 1479 | |
| 1480 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1481 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1482 | } |
| 1483 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1484 | private void setSwipingInProgress(boolean isSwiped) { |
| 1485 | mSwipingInProgress = isSwiped; |
| 1486 | if(isSwiped) { |
| 1487 | requestDisallowInterceptTouchEvent(true); |
| 1488 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | @Override |
| 1492 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1493 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1494 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1495 | float densityScale = getResources().getDisplayMetrics().density; |
| 1496 | mSwipeHelper.setDensityScale(densityScale); |
| 1497 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1498 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1499 | initView(getContext()); |
| 1500 | } |
| 1501 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1502 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1503 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1504 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1505 | } |
| 1506 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1507 | @Override |
Mady Mellor | 86889c2 | 2016-04-18 16:37:06 -0700 | [diff] [blame] | 1508 | public void snapViewIfNeeded(ExpandableNotificationRow child) { |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1509 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1510 | // If the child is showing the notification menu snap to that |
| 1511 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
Mady Mellor | 86889c2 | 2016-04-18 16:37:06 -0700 | [diff] [blame] | 1512 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1513 | } |
| 1514 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1515 | @Override |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1516 | public ViewGroup getViewParentForNotification(NotificationData.Entry entry) { |
| 1517 | return this; |
| 1518 | } |
| 1519 | |
| 1520 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1521 | public boolean onTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1522 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 1523 | || ev.getActionMasked()== MotionEvent.ACTION_UP; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1524 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1525 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 1526 | if (mIsExpanded && !mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1527 | if (isCancelOrUp) { |
| 1528 | mExpandHelper.onlyObserveMovements(false); |
| 1529 | } |
| 1530 | boolean wasExpandingBefore = mExpandingNotification; |
| 1531 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1532 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 1533 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1534 | dispatchDownEventToScroller(ev); |
| 1535 | } |
| 1536 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1537 | boolean scrollerWantsIt = false; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1538 | if (mIsExpanded && !mSwipingInProgress && !mExpandingNotification |
| 1539 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1540 | scrollerWantsIt = onScrollTouch(ev); |
| 1541 | } |
| 1542 | boolean horizontalSwipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1543 | if (!mIsBeingDragged |
| 1544 | && !mExpandingNotification |
| 1545 | && !mExpandedInThisMotion |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 1546 | && !mOnlyScrollingInThisMotion |
| 1547 | && !mDisallowDismissInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1548 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 1549 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1550 | |
| 1551 | // Check if we need to clear any snooze leavebehinds |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 1552 | NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1553 | if (guts != null && !isTouchInView(ev, guts) |
| 1554 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 1555 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 1556 | if ((ns.isExpanded() && isCancelOrUp) |
| 1557 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 1558 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 1559 | // clear it on the next non-horizontal swipe or expand event. |
| 1560 | checkSnoozeLeavebehind(); |
| 1561 | } |
| 1562 | } |
| 1563 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 1564 | mCheckForLeavebehind = true; |
| 1565 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1566 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 1567 | } |
| 1568 | |
| 1569 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 1570 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 1571 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 1572 | onScrollTouch(downEvent); |
| 1573 | downEvent.recycle(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 1576 | @Override |
| 1577 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 1578 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
| 1579 | || mDisallowScrollingInThisMotion) { |
| 1580 | return false; |
| 1581 | } |
| 1582 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 1583 | switch (event.getAction()) { |
| 1584 | case MotionEvent.ACTION_SCROLL: { |
| 1585 | if (!mIsBeingDragged) { |
| 1586 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 1587 | if (vscroll != 0) { |
| 1588 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
| 1589 | final int range = getScrollRange(); |
| 1590 | int oldScrollY = mOwnScrollY; |
| 1591 | int newScrollY = oldScrollY - delta; |
| 1592 | if (newScrollY < 0) { |
| 1593 | newScrollY = 0; |
| 1594 | } else if (newScrollY > range) { |
| 1595 | newScrollY = range; |
| 1596 | } |
| 1597 | if (newScrollY != oldScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1598 | setOwnScrollY(newScrollY); |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 1599 | return true; |
| 1600 | } |
| 1601 | } |
| 1602 | } |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | return super.onGenericMotionEvent(event); |
| 1607 | } |
| 1608 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1609 | private boolean onScrollTouch(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1610 | if (!isScrollingEnabled()) { |
| 1611 | return false; |
| 1612 | } |
Adrian Roos | feb9725 | 2016-09-29 17:05:58 -0700 | [diff] [blame] | 1613 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1614 | return false; |
| 1615 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1616 | mForcedScroll = null; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1617 | initVelocityTrackerIfNotExists(); |
| 1618 | mVelocityTracker.addMovement(ev); |
| 1619 | |
| 1620 | final int action = ev.getAction(); |
| 1621 | |
| 1622 | switch (action & MotionEvent.ACTION_MASK) { |
| 1623 | case MotionEvent.ACTION_DOWN: { |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 1624 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1625 | return false; |
| 1626 | } |
| 1627 | boolean isBeingDragged = !mScroller.isFinished(); |
| 1628 | setIsBeingDragged(isBeingDragged); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1629 | /* |
| 1630 | * If being flinged and user touches, stop the fling. isFinished |
| 1631 | * will be false if being flinged. |
| 1632 | */ |
| 1633 | if (!mScroller.isFinished()) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1634 | mScroller.forceFinished(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | // Remember where the motion event started |
| 1638 | mLastMotionY = (int) ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1639 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1640 | mActivePointerId = ev.getPointerId(0); |
| 1641 | break; |
| 1642 | } |
| 1643 | case MotionEvent.ACTION_MOVE: |
| 1644 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 1645 | if (activePointerIndex == -1) { |
| 1646 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 1647 | break; |
| 1648 | } |
| 1649 | |
| 1650 | final int y = (int) ev.getY(activePointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1651 | final int x = (int) ev.getX(activePointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1652 | int deltaY = mLastMotionY - y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1653 | final int xDiff = Math.abs(x - mDownX); |
| 1654 | final int yDiff = Math.abs(deltaY); |
| 1655 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1656 | setIsBeingDragged(true); |
| 1657 | if (deltaY > 0) { |
| 1658 | deltaY -= mTouchSlop; |
| 1659 | } else { |
| 1660 | deltaY += mTouchSlop; |
| 1661 | } |
| 1662 | } |
| 1663 | if (mIsBeingDragged) { |
| 1664 | // Scroll to follow the motion event |
| 1665 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1666 | int range = getScrollRange(); |
| 1667 | if (mExpandedInThisMotion) { |
| 1668 | range = Math.min(range, mMaxScrollAfterExpand); |
| 1669 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1670 | |
| 1671 | float scrollAmount; |
| 1672 | if (deltaY < 0) { |
| 1673 | scrollAmount = overScrollDown(deltaY); |
| 1674 | } else { |
| 1675 | scrollAmount = overScrollUp(deltaY, range); |
| 1676 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1677 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1678 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 1679 | // sets the scrolling if applicable. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1680 | if (scrollAmount != 0.0f) { |
| 1681 | // The scrolling motion could not be compensated with the |
| 1682 | // existing overScroll, we have to scroll the view |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1683 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 1684 | range, getHeight() / 2); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1685 | // If we're scrolling, leavebehinds should be dismissed |
| 1686 | checkSnoozeLeavebehind(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1687 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1688 | } |
| 1689 | break; |
| 1690 | case MotionEvent.ACTION_UP: |
| 1691 | if (mIsBeingDragged) { |
| 1692 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 1693 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 1694 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 1695 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1696 | if (shouldOverScrollFling(initialVelocity)) { |
| 1697 | onOverScrollFling(true, initialVelocity); |
| 1698 | } else { |
| 1699 | if (getChildCount() > 0) { |
| 1700 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 1701 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 1702 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 1703 | fling(-initialVelocity); |
| 1704 | } else { |
| 1705 | onOverScrollFling(false, initialVelocity); |
| 1706 | } |
| 1707 | } else { |
| 1708 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 1709 | getScrollRange())) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1710 | animateScroll(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1711 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1712 | } |
| 1713 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1714 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 1715 | mActivePointerId = INVALID_POINTER; |
| 1716 | endDrag(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1717 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 1718 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1719 | break; |
| 1720 | case MotionEvent.ACTION_CANCEL: |
| 1721 | if (mIsBeingDragged && getChildCount() > 0) { |
| 1722 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1723 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1724 | } |
| 1725 | mActivePointerId = INVALID_POINTER; |
| 1726 | endDrag(); |
| 1727 | } |
| 1728 | break; |
| 1729 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 1730 | final int index = ev.getActionIndex(); |
| 1731 | mLastMotionY = (int) ev.getY(index); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1732 | mDownX = (int) ev.getX(index); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1733 | mActivePointerId = ev.getPointerId(index); |
| 1734 | break; |
| 1735 | } |
| 1736 | case MotionEvent.ACTION_POINTER_UP: |
| 1737 | onSecondaryPointerUp(ev); |
| 1738 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1739 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1740 | break; |
| 1741 | } |
| 1742 | return true; |
| 1743 | } |
| 1744 | |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 1745 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 1746 | return ev.getY() < mQsContainer.getBottom(); |
| 1747 | } |
| 1748 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1749 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 1750 | if (mOverscrollTopChangedListener != null) { |
| 1751 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 1752 | } |
| 1753 | mDontReportNextOverScroll = true; |
| 1754 | setOverScrollAmount(0.0f, true, false); |
| 1755 | } |
| 1756 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1757 | /** |
| 1758 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1759 | * |
| 1760 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1761 | * @return The amount of scrolling to be performed by the scroller, |
| 1762 | * not handled by the overScroll amount. |
| 1763 | */ |
| 1764 | private float overScrollUp(int deltaY, int range) { |
| 1765 | deltaY = Math.max(deltaY, 0); |
| 1766 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1767 | float newTopAmount = currentTopAmount - deltaY; |
| 1768 | if (currentTopAmount > 0) { |
| 1769 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1770 | false /* animate */); |
| 1771 | } |
| 1772 | // Top overScroll might not grab all scrolling motion, |
| 1773 | // we have to scroll as well. |
| 1774 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1775 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1776 | if (newScrollY > range) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1777 | if (!mExpandedInThisMotion) { |
| 1778 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1779 | // We overScroll on the top |
| 1780 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1781 | false /* onTop */, |
| 1782 | false /* animate */); |
| 1783 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 1784 | setOwnScrollY(range); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1785 | scrollAmount = 0.0f; |
| 1786 | } |
| 1787 | return scrollAmount; |
| 1788 | } |
| 1789 | |
| 1790 | /** |
| 1791 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1792 | * |
| 1793 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1794 | * @return The amount of scrolling to be performed by the scroller, |
| 1795 | * not handled by the overScroll amount. |
| 1796 | */ |
| 1797 | private float overScrollDown(int deltaY) { |
| 1798 | deltaY = Math.min(deltaY, 0); |
| 1799 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1800 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1801 | if (currentBottomAmount > 0) { |
| 1802 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1803 | false /* animate */); |
| 1804 | } |
| 1805 | // Bottom overScroll might not grab all scrolling motion, |
| 1806 | // we have to scroll as well. |
| 1807 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1808 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1809 | if (newScrollY < 0) { |
| 1810 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1811 | // We overScroll on the top |
| 1812 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1813 | true /* onTop */, |
| 1814 | false /* animate */); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 1815 | setOwnScrollY(0); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1816 | scrollAmount = 0.0f; |
| 1817 | } |
| 1818 | return scrollAmount; |
| 1819 | } |
| 1820 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1821 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 1822 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 1823 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 1824 | final int pointerId = ev.getPointerId(pointerIndex); |
| 1825 | if (pointerId == mActivePointerId) { |
| 1826 | // This was our active pointer going up. Choose a new |
| 1827 | // active pointer and adjust accordingly. |
| 1828 | // TODO: Make this decision more intelligent. |
| 1829 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 1830 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 1831 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 1832 | if (mVelocityTracker != null) { |
| 1833 | mVelocityTracker.clear(); |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | private void initVelocityTrackerIfNotExists() { |
| 1839 | if (mVelocityTracker == null) { |
| 1840 | mVelocityTracker = VelocityTracker.obtain(); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | private void recycleVelocityTracker() { |
| 1845 | if (mVelocityTracker != null) { |
| 1846 | mVelocityTracker.recycle(); |
| 1847 | mVelocityTracker = null; |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | private void initOrResetVelocityTracker() { |
| 1852 | if (mVelocityTracker == null) { |
| 1853 | mVelocityTracker = VelocityTracker.obtain(); |
| 1854 | } else { |
| 1855 | mVelocityTracker.clear(); |
| 1856 | } |
| 1857 | } |
| 1858 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1859 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1860 | mFinishScrollingCallback = runnable; |
| 1861 | } |
| 1862 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1863 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1864 | if (mScroller.computeScrollOffset()) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1865 | int oldY = mOwnScrollY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1866 | int y = mScroller.getCurrY(); |
| 1867 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1868 | if (oldY != y) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1869 | int range = getScrollRange(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1870 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
| 1871 | float currVelocity = mScroller.getCurrVelocity(); |
Selim Cinek | ba81962 | 2014-05-13 17:55:53 +0200 | [diff] [blame] | 1872 | if (currVelocity >= mMinimumVelocity) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1873 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
| 1874 | } |
| 1875 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1876 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1877 | if (mDontClampNextScroll) { |
| 1878 | range = Math.max(range, oldY); |
| 1879 | } |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1880 | customOverScrollBy(y - oldY, oldY, range, |
| 1881 | (int) (mMaxOverScroll)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1884 | postOnAnimation(mAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1885 | } else { |
| 1886 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1887 | if (mFinishScrollingCallback != null) { |
| 1888 | mFinishScrollingCallback.run(); |
| 1889 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1890 | } |
| 1891 | } |
| 1892 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1893 | private boolean customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, |
| 1894 | int maxOverScrollY) { |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1895 | |
| 1896 | int newScrollY = scrollY + deltaY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1897 | final int top = -maxOverScrollY; |
| 1898 | final int bottom = maxOverScrollY + scrollRangeY; |
| 1899 | |
| 1900 | boolean clampedY = false; |
| 1901 | if (newScrollY > bottom) { |
| 1902 | newScrollY = bottom; |
| 1903 | clampedY = true; |
| 1904 | } else if (newScrollY < top) { |
| 1905 | newScrollY = top; |
| 1906 | clampedY = true; |
| 1907 | } |
| 1908 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1909 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1910 | |
| 1911 | return clampedY; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | /** |
| 1915 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1916 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1917 | * same overScroll edge. |
| 1918 | * |
| 1919 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 1920 | * the rubber-banding logic. |
| 1921 | * @param onTop Should the effect be applied on top of the scroller. |
| 1922 | * @param animate Should an animation be performed. |
| 1923 | */ |
| 1924 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1925 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | /** |
| 1929 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1930 | * By default this will also cancel animations on the same overScroll edge. |
| 1931 | * |
| 1932 | * @param amount The amount to overScroll by. |
| 1933 | * @param onTop Should the effect be applied on top of the scroller. |
| 1934 | * @param animate Should an animation be performed. |
| 1935 | */ |
| 1936 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 1937 | setOverScrollAmount(amount, onTop, animate, true); |
| 1938 | } |
| 1939 | |
| 1940 | /** |
| 1941 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1942 | * |
| 1943 | * @param amount The amount to overScroll by. |
| 1944 | * @param onTop Should the effect be applied on top of the scroller. |
| 1945 | * @param animate Should an animation be performed. |
| 1946 | * @param cancelAnimators Should running animations be cancelled. |
| 1947 | */ |
| 1948 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1949 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1950 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 1951 | } |
| 1952 | |
| 1953 | /** |
| 1954 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1955 | * |
| 1956 | * @param amount The amount to overScroll by. |
| 1957 | * @param onTop Should the effect be applied on top of the scroller. |
| 1958 | * @param animate Should an animation be performed. |
| 1959 | * @param cancelAnimators Should running animations be cancelled. |
| 1960 | * @param isRubberbanded The value which will be passed to |
| 1961 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
| 1962 | */ |
| 1963 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1964 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1965 | if (cancelAnimators) { |
| 1966 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 1967 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1968 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1969 | } |
| 1970 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1971 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 1972 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1973 | amount = Math.max(0, amount); |
| 1974 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1975 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1976 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1977 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1978 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1979 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1980 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1981 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1982 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1983 | } |
| 1984 | } |
| 1985 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1986 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1987 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 1988 | if (mDontReportNextOverScroll) { |
| 1989 | mDontReportNextOverScroll = false; |
| 1990 | return; |
| 1991 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1992 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1993 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | public void setOverscrollTopChangedListener( |
| 1998 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 1999 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 2000 | } |
| 2001 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2002 | public float getCurrentOverScrollAmount(boolean top) { |
| 2003 | return mAmbientState.getOverScrollAmount(top); |
| 2004 | } |
| 2005 | |
| 2006 | public float getCurrentOverScrolledPixels(boolean top) { |
| 2007 | return top? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
| 2008 | } |
| 2009 | |
| 2010 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2011 | if (onTop) { |
| 2012 | mOverScrolledTopPixels = amount; |
| 2013 | } else { |
| 2014 | mOverScrolledBottomPixels = amount; |
| 2015 | } |
| 2016 | } |
| 2017 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2018 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2019 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2020 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2021 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2022 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2023 | springBack(); |
| 2024 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2025 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2026 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2027 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2028 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2029 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2030 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2031 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2032 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2033 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2034 | } |
| 2035 | } |
| 2036 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2037 | private void springBack() { |
| 2038 | int scrollRange = getScrollRange(); |
| 2039 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2040 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2041 | if (overScrolledTop || overScrolledBottom) { |
| 2042 | boolean onTop; |
| 2043 | float newAmount; |
| 2044 | if (overScrolledTop) { |
| 2045 | onTop = true; |
| 2046 | newAmount = -mOwnScrollY; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2047 | setOwnScrollY(0); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2048 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2049 | } else { |
| 2050 | onTop = false; |
| 2051 | newAmount = mOwnScrollY - scrollRange; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2052 | setOwnScrollY(scrollRange); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2053 | } |
| 2054 | setOverScrollAmount(newAmount, onTop, false); |
| 2055 | setOverScrollAmount(0.0f, onTop, true); |
| 2056 | mScroller.forceFinished(true); |
| 2057 | } |
| 2058 | } |
| 2059 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2060 | private int getScrollRange() { |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2061 | int scrollRange = Math.max(0, mContentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2062 | int imeInset = getImeInset(); |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2063 | scrollRange += Math.min(imeInset, Math.max(0, mContentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2064 | return scrollRange; |
| 2065 | } |
| 2066 | |
| 2067 | private int getImeInset() { |
| 2068 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2069 | } |
| 2070 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2071 | /** |
| 2072 | * @return the first child which has visibility unequal to GONE |
| 2073 | */ |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2074 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2075 | int childCount = getChildCount(); |
| 2076 | for (int i = 0; i < childCount; i++) { |
| 2077 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2078 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2079 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | return null; |
| 2083 | } |
| 2084 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2085 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2086 | * @return the child before the given view which has visibility unequal to GONE |
| 2087 | */ |
| 2088 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2089 | ExpandableView previousView = null; |
| 2090 | int childCount = getChildCount(); |
| 2091 | for (int i = 0; i < childCount; i++) { |
| 2092 | View child = getChildAt(i); |
| 2093 | if (child == view) { |
| 2094 | return previousView; |
| 2095 | } |
| 2096 | if (child.getVisibility() != View.GONE) { |
| 2097 | previousView = (ExpandableView) child; |
| 2098 | } |
| 2099 | } |
| 2100 | return null; |
| 2101 | } |
| 2102 | |
| 2103 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2104 | * @return The first child which has visibility unequal to GONE which is currently below the |
| 2105 | * given translationY or equal to it. |
| 2106 | */ |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2107 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2108 | int childCount = getChildCount(); |
| 2109 | for (int i = 0; i < childCount; i++) { |
| 2110 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2111 | if (child.getVisibility() == View.GONE) { |
| 2112 | continue; |
| 2113 | } |
| 2114 | float rowTranslation = child.getTranslationY(); |
| 2115 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2116 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2117 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2118 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2119 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2120 | List<ExpandableNotificationRow> notificationChildren = |
| 2121 | row.getNotificationChildren(); |
| 2122 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2123 | childIndex++) { |
| 2124 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2125 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2126 | return rowChild; |
| 2127 | } |
| 2128 | } |
| 2129 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | return null; |
| 2133 | } |
| 2134 | |
| 2135 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2136 | * @return the last child which has visibility unequal to GONE |
| 2137 | */ |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2138 | public View getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2139 | int childCount = getChildCount(); |
| 2140 | for (int i = childCount - 1; i >= 0; i--) { |
| 2141 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2142 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2143 | return child; |
| 2144 | } |
| 2145 | } |
| 2146 | return null; |
| 2147 | } |
| 2148 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2149 | /** |
| 2150 | * @return the number of children which have visibility unequal to GONE |
| 2151 | */ |
| 2152 | public int getNotGoneChildCount() { |
| 2153 | int childCount = getChildCount(); |
| 2154 | int count = 0; |
| 2155 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2156 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2157 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2158 | count++; |
| 2159 | } |
| 2160 | } |
| 2161 | return count; |
| 2162 | } |
| 2163 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2164 | private void updateContentHeight() { |
| 2165 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2166 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2167 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2168 | int numShownItems = 0; |
| 2169 | boolean finish = false; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 2170 | int maxDisplayedNotifications = mAmbientState.isFullyDark() |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2171 | ? (hasPulsingNotifications() ? 1 : 0) |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2172 | : mMaxDisplayedNotifications; |
| 2173 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2174 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2175 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2176 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2177 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2178 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2179 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2180 | && numShownItems >= maxDisplayedNotifications; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 2181 | boolean notificationOnAmbientThatIsNotPulsing = mAmbientState.isFullyDark() |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2182 | && hasPulsingNotifications() |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2183 | && expandableView instanceof ExpandableNotificationRow |
| 2184 | && !isPulsing(((ExpandableNotificationRow) expandableView).getEntry()); |
| 2185 | if (limitReached || notificationOnAmbientThatIsNotPulsing) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2186 | expandableView = mShelf; |
| 2187 | finish = true; |
| 2188 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2189 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2190 | float padding; |
| 2191 | if (increasedPaddingAmount >= 0.0f) { |
| 2192 | padding = (int) NotificationUtils.interpolate( |
| 2193 | previousPaddingRequest, |
| 2194 | mIncreasedPaddingBetweenElements, |
| 2195 | increasedPaddingAmount); |
| 2196 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2197 | mPaddingBetweenElements, |
| 2198 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2199 | increasedPaddingAmount); |
| 2200 | } else { |
| 2201 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2202 | 0, |
| 2203 | mPaddingBetweenElements, |
| 2204 | 1.0f + increasedPaddingAmount); |
| 2205 | if (previousPaddingAmount > 0.0f) { |
| 2206 | padding = (int) NotificationUtils.interpolate( |
| 2207 | ownPadding, |
| 2208 | mIncreasedPaddingBetweenElements, |
| 2209 | previousPaddingAmount); |
| 2210 | } else { |
| 2211 | padding = ownPadding; |
| 2212 | } |
| 2213 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2214 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2215 | if (height != 0) { |
| 2216 | height += padding; |
| 2217 | } |
| 2218 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2219 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2220 | numShownItems++; |
| 2221 | if (finish) { |
| 2222 | break; |
| 2223 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2224 | } |
| 2225 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2226 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2227 | |
| 2228 | // We don't want to use the toppadding since that might be interpolated and we want |
| 2229 | // to take the final value of the animation. |
| 2230 | int topPadding = mAmbientState.isFullyDark() ? mDarkTopPadding : mRegularTopPadding; |
| 2231 | mContentHeight = height + topPadding + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2232 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2233 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2234 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2237 | private boolean isPulsing(NotificationData.Entry entry) { |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 2238 | return mAmbientState.isPulsing(entry); |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2241 | @Override |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2242 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2243 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2246 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2247 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2248 | if (scrollable != mScrollable) { |
| 2249 | mScrollable = scrollable; |
| 2250 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2251 | updateForwardAndBackwardScrollability(); |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | private void updateForwardAndBackwardScrollability() { |
| 2256 | boolean forwardScrollable = mScrollable && mOwnScrollY < getScrollRange(); |
| 2257 | boolean backwardsScrollable = mScrollable && mOwnScrollY > 0; |
| 2258 | boolean changed = forwardScrollable != mForwardScrollable |
| 2259 | || backwardsScrollable != mBackwardScrollable; |
| 2260 | mForwardScrollable = forwardScrollable; |
| 2261 | mBackwardScrollable = backwardsScrollable; |
| 2262 | if (changed) { |
| 2263 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2264 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2265 | } |
| 2266 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2267 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2268 | // 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] | 2269 | if (!mShouldDrawNotificationBackground || mAmbientState.isFullyDark()) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2270 | return; |
| 2271 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2272 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2273 | updateBackgroundBounds(); |
| 2274 | if (!mCurrentBounds.equals(mBackgroundBounds)) { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2275 | boolean animate = mAnimateNextBackgroundTop || mAnimateNextBackgroundBottom |
| 2276 | || areBoundsAnimating(); |
| 2277 | if (!isExpanded()) { |
| 2278 | abortBackgroundAnimators(); |
| 2279 | animate = false; |
| 2280 | } |
| 2281 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2282 | startBackgroundAnimation(); |
| 2283 | } else { |
| 2284 | mCurrentBounds.set(mBackgroundBounds); |
| 2285 | applyCurrentBackgroundBounds(); |
| 2286 | } |
| 2287 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2288 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2289 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2290 | mAnimateNextBackgroundBottom = false; |
| 2291 | mAnimateNextBackgroundTop = false; |
| 2292 | } |
| 2293 | |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2294 | private void abortBackgroundAnimators() { |
| 2295 | if (mBottomAnimator != null) { |
| 2296 | mBottomAnimator.cancel(); |
| 2297 | } |
| 2298 | if (mTopAnimator != null) { |
| 2299 | mTopAnimator.cancel(); |
| 2300 | } |
| 2301 | } |
| 2302 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2303 | private boolean areBoundsAnimating() { |
| 2304 | return mBottomAnimator != null || mTopAnimator != null; |
| 2305 | } |
| 2306 | |
| 2307 | private void startBackgroundAnimation() { |
Selim Cinek | 01e4019 | 2016-05-12 14:57:22 -0700 | [diff] [blame] | 2308 | // left and right are always instantly applied |
| 2309 | mCurrentBounds.left = mBackgroundBounds.left; |
| 2310 | mCurrentBounds.right = mBackgroundBounds.right; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2311 | startBottomAnimation(); |
| 2312 | startTopAnimation(); |
| 2313 | } |
| 2314 | |
| 2315 | private void startTopAnimation() { |
| 2316 | int previousEndValue = mEndAnimationRect.top; |
| 2317 | int newEndValue = mBackgroundBounds.top; |
| 2318 | ObjectAnimator previousAnimator = mTopAnimator; |
| 2319 | if (previousAnimator != null && previousEndValue == newEndValue) { |
| 2320 | return; |
| 2321 | } |
| 2322 | if (!mAnimateNextBackgroundTop) { |
| 2323 | // just a local update was performed |
| 2324 | if (previousAnimator != null) { |
| 2325 | // we need to increase all animation keyframes of the previous animator by the |
| 2326 | // relative change to the end value |
| 2327 | int previousStartValue = mStartAnimationRect.top; |
| 2328 | PropertyValuesHolder[] values = previousAnimator.getValues(); |
| 2329 | values[0].setIntValues(previousStartValue, newEndValue); |
| 2330 | mStartAnimationRect.top = previousStartValue; |
| 2331 | mEndAnimationRect.top = newEndValue; |
| 2332 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 2333 | return; |
| 2334 | } else { |
| 2335 | // no new animation needed, let's just apply the value |
| 2336 | setBackgroundTop(newEndValue); |
| 2337 | return; |
| 2338 | } |
| 2339 | } |
| 2340 | if (previousAnimator != null) { |
| 2341 | previousAnimator.cancel(); |
| 2342 | } |
| 2343 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundTop", |
| 2344 | mCurrentBounds.top, newEndValue); |
| 2345 | Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN; |
| 2346 | animator.setInterpolator(interpolator); |
| 2347 | animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 2348 | // remove the tag when the animation is finished |
| 2349 | animator.addListener(new AnimatorListenerAdapter() { |
| 2350 | @Override |
| 2351 | public void onAnimationEnd(Animator animation) { |
| 2352 | mStartAnimationRect.top = -1; |
| 2353 | mEndAnimationRect.top = -1; |
| 2354 | mTopAnimator = null; |
| 2355 | } |
| 2356 | }); |
| 2357 | animator.start(); |
| 2358 | mStartAnimationRect.top = mCurrentBounds.top; |
| 2359 | mEndAnimationRect.top = newEndValue; |
| 2360 | mTopAnimator = animator; |
| 2361 | } |
| 2362 | |
| 2363 | private void startBottomAnimation() { |
| 2364 | int previousStartValue = mStartAnimationRect.bottom; |
| 2365 | int previousEndValue = mEndAnimationRect.bottom; |
| 2366 | int newEndValue = mBackgroundBounds.bottom; |
| 2367 | ObjectAnimator previousAnimator = mBottomAnimator; |
| 2368 | if (previousAnimator != null && previousEndValue == newEndValue) { |
| 2369 | return; |
| 2370 | } |
| 2371 | if (!mAnimateNextBackgroundBottom) { |
| 2372 | // just a local update was performed |
| 2373 | if (previousAnimator != null) { |
| 2374 | // we need to increase all animation keyframes of the previous animator by the |
| 2375 | // relative change to the end value |
| 2376 | PropertyValuesHolder[] values = previousAnimator.getValues(); |
| 2377 | values[0].setIntValues(previousStartValue, newEndValue); |
| 2378 | mStartAnimationRect.bottom = previousStartValue; |
| 2379 | mEndAnimationRect.bottom = newEndValue; |
| 2380 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 2381 | return; |
| 2382 | } else { |
| 2383 | // no new animation needed, let's just apply the value |
| 2384 | setBackgroundBottom(newEndValue); |
| 2385 | return; |
| 2386 | } |
| 2387 | } |
| 2388 | if (previousAnimator != null) { |
| 2389 | previousAnimator.cancel(); |
| 2390 | } |
| 2391 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom", |
| 2392 | mCurrentBounds.bottom, newEndValue); |
| 2393 | Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN; |
| 2394 | animator.setInterpolator(interpolator); |
| 2395 | animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 2396 | // remove the tag when the animation is finished |
| 2397 | animator.addListener(new AnimatorListenerAdapter() { |
| 2398 | @Override |
| 2399 | public void onAnimationEnd(Animator animation) { |
| 2400 | mStartAnimationRect.bottom = -1; |
| 2401 | mEndAnimationRect.bottom = -1; |
| 2402 | mBottomAnimator = null; |
| 2403 | } |
| 2404 | }); |
| 2405 | animator.start(); |
| 2406 | mStartAnimationRect.bottom = mCurrentBounds.bottom; |
| 2407 | mEndAnimationRect.bottom = newEndValue; |
| 2408 | mBottomAnimator = animator; |
| 2409 | } |
| 2410 | |
| 2411 | private void setBackgroundTop(int top) { |
| 2412 | mCurrentBounds.top = top; |
| 2413 | applyCurrentBackgroundBounds(); |
| 2414 | } |
| 2415 | |
| 2416 | public void setBackgroundBottom(int bottom) { |
| 2417 | mCurrentBounds.bottom = bottom; |
| 2418 | applyCurrentBackgroundBounds(); |
| 2419 | } |
| 2420 | |
| 2421 | private void applyCurrentBackgroundBounds() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2422 | // If the background of the notification is not being drawn, then there is no need to |
| 2423 | // exclude an area in the scrim. Rather, the scrim's color should serve as the background. |
| 2424 | if (!mShouldDrawNotificationBackground) { |
| 2425 | return; |
| 2426 | } |
| 2427 | |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 2428 | final boolean awake = mDarkAmount != 0 || mAmbientState.isDark(); |
Selim Cinek | 9bfba9c | 2016-08-08 15:20:06 -0700 | [diff] [blame] | 2429 | mScrimController.setExcludedBackgroundArea( |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 2430 | mFadingOut || mParentNotFullyVisible || awake || mIsClipped ? null |
Selim Cinek | 9bfba9c | 2016-08-08 15:20:06 -0700 | [diff] [blame] | 2431 | : mCurrentBounds); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2432 | invalidate(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | /** |
| 2436 | * Update the background bounds to the new desired bounds |
| 2437 | */ |
| 2438 | private void updateBackgroundBounds() { |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2439 | getLocationInWindow(mTempInt2); |
| 2440 | mBackgroundBounds.left = mTempInt2[0] + mSidePaddings; |
| 2441 | mBackgroundBounds.right = mTempInt2[0] + getWidth() - mSidePaddings; |
| 2442 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2443 | if (!mIsExpanded) { |
| 2444 | mBackgroundBounds.top = 0; |
| 2445 | mBackgroundBounds.bottom = 0; |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2446 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2447 | } |
| 2448 | ActivatableNotificationView firstView = mFirstVisibleBackgroundChild; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2449 | int top = 0; |
| 2450 | if (firstView != null) { |
Lucas Dupin | 4f67be7 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 2451 | // Round Y up to avoid seeing the background during animation |
| 2452 | int finalTranslationY = (int) Math.ceil(ViewState.getFinalTranslationY(firstView)); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2453 | if (mAnimateNextBackgroundTop |
| 2454 | || mTopAnimator == null && mCurrentBounds.top == finalTranslationY |
| 2455 | || mTopAnimator != null && mEndAnimationRect.top == finalTranslationY) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2456 | // we're ending up at the same location as we are now, lets just skip the animation |
| 2457 | top = finalTranslationY; |
| 2458 | } else { |
Lucas Dupin | 4f67be7 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 2459 | top = (int) Math.ceil(firstView.getTranslationY()); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2460 | } |
| 2461 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2462 | ActivatableNotificationView lastView = |
| 2463 | mShelf.hasItemsInStableShelf() && mShelf.getVisibility() != GONE |
| 2464 | ? mShelf |
| 2465 | : mLastVisibleBackgroundChild; |
| 2466 | int bottom; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2467 | if (lastView != null) { |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 2468 | int finalTranslationY; |
| 2469 | if (lastView == mShelf) { |
| 2470 | finalTranslationY = (int) mShelf.getTranslationY(); |
| 2471 | } else { |
| 2472 | finalTranslationY = (int) ViewState.getFinalTranslationY(lastView); |
| 2473 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2474 | int finalHeight = ExpandableViewState.getFinalActualHeight(lastView); |
Selim Cinek | c519dcf | 2016-11-22 13:45:39 -0800 | [diff] [blame] | 2475 | int finalBottom = finalTranslationY + finalHeight - lastView.getClipBottomAmount(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2476 | if (mAnimateNextBackgroundBottom |
| 2477 | || mBottomAnimator == null && mCurrentBounds.bottom == finalBottom |
| 2478 | || mBottomAnimator != null && mEndAnimationRect.bottom == finalBottom) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2479 | // we're ending up at the same location as we are now, lets just skip the animation |
| 2480 | bottom = finalBottom; |
| 2481 | } else { |
Selim Cinek | c519dcf | 2016-11-22 13:45:39 -0800 | [diff] [blame] | 2482 | bottom = (int) (lastView.getTranslationY() + lastView.getActualHeight() |
| 2483 | - lastView.getClipBottomAmount()); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2484 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2485 | } else { |
Selim Cinek | d393d5c | 2016-08-03 16:18:12 -0700 | [diff] [blame] | 2486 | top = mTopPadding; |
Selim Cinek | 7db4298 | 2016-02-02 15:21:41 -0800 | [diff] [blame] | 2487 | bottom = top; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2488 | } |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 2489 | if (mStatusBarState != StatusBarState.KEYGUARD) { |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 2490 | top = (int) Math.max(mTopPadding + mStackTranslation, top); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2491 | } else { |
| 2492 | // otherwise the animation from the shade to the keyguard will jump as it's maxed |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 2493 | top = Math.max(0, top); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2494 | } |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 2495 | mBackgroundBounds.top = top; |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 2496 | mBackgroundBounds.bottom = Math.max(bottom, top); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2497 | } |
| 2498 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2499 | private ActivatableNotificationView getFirstPinnedHeadsUp() { |
| 2500 | int childCount = getChildCount(); |
| 2501 | for (int i = 0; i < childCount; i++) { |
| 2502 | View child = getChildAt(i); |
| 2503 | if (child.getVisibility() != View.GONE |
| 2504 | && child instanceof ExpandableNotificationRow) { |
| 2505 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2506 | if (row.isPinned()) { |
| 2507 | return row; |
| 2508 | } |
| 2509 | } |
| 2510 | } |
| 2511 | return null; |
| 2512 | } |
| 2513 | |
| 2514 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2515 | int childCount = getChildCount(); |
| 2516 | for (int i = childCount - 1; i >= 0; i--) { |
| 2517 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2518 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2519 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2520 | return (ActivatableNotificationView) child; |
| 2521 | } |
| 2522 | } |
| 2523 | return null; |
| 2524 | } |
| 2525 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2526 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2527 | int childCount = getChildCount(); |
| 2528 | for (int i = 0; i < childCount; i++) { |
| 2529 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2530 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2531 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2532 | return (ActivatableNotificationView) child; |
| 2533 | } |
| 2534 | } |
| 2535 | return null; |
| 2536 | } |
| 2537 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2538 | /** |
| 2539 | * Fling the scroll view |
| 2540 | * |
| 2541 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2542 | * numbers mean that the finger/cursor is moving down the screen, |
| 2543 | * which means we want to scroll towards the top. |
| 2544 | */ |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2545 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2546 | if (getChildCount() > 0) { |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2547 | int scrollRange = getScrollRange(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2548 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2549 | float topAmount = getCurrentOverScrollAmount(true); |
| 2550 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2551 | if (velocityY < 0 && topAmount > 0) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2552 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2553 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2554 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2555 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2556 | * mOverflingDistance + topAmount; |
| 2557 | } else if (velocityY > 0 && bottomAmount > 0) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2558 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2559 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2560 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2561 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
| 2562 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2563 | } else { |
| 2564 | // it will be set once we reach the boundary |
| 2565 | mMaxOverScroll = 0.0f; |
| 2566 | } |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2567 | int minScrollY = Math.max(0, scrollRange); |
| 2568 | if (mExpandedInThisMotion) { |
| 2569 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2570 | } |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2571 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2572 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2573 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2574 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2575 | } |
| 2576 | } |
| 2577 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2578 | /** |
| 2579 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2580 | * overScroll view (i.e QS). |
| 2581 | */ |
| 2582 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2583 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2584 | return mScrolledToTopOnFirstDown |
| 2585 | && !mExpandedInThisMotion |
| 2586 | && topOverScroll > mMinTopOverScrollToEscape |
| 2587 | && initialVelocity > 0; |
| 2588 | } |
| 2589 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2590 | /** |
| 2591 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2592 | * account. |
| 2593 | * |
| 2594 | * @param qsHeight the top padding imposed by the quick settings panel |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2595 | * @param animate whether to animate the change |
| 2596 | * @param ignoreIntrinsicPadding if true, {@link #getIntrinsicPadding()} is ignored and |
| 2597 | * {@code qsHeight} is the final top padding |
| 2598 | */ |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 2599 | public void updateTopPadding(float qsHeight, boolean animate, |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2600 | boolean ignoreIntrinsicPadding) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2601 | int topPadding = (int) qsHeight; |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2602 | int minStackHeight = getLayoutMinHeight(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2603 | if (topPadding + minStackHeight > getHeight()) { |
| 2604 | mTopPaddingOverflow = topPadding + minStackHeight - getHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2605 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2606 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2607 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2608 | setTopPadding(ignoreIntrinsicPadding ? topPadding : clampPadding(topPadding), |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2609 | animate); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2610 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2611 | } |
| 2612 | |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2613 | public void setMaxTopPadding(int maxTopPadding) { |
| 2614 | mMaxTopPadding = maxTopPadding; |
| 2615 | } |
| 2616 | |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2617 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2618 | if (isHeadsUpTransition()) { |
| 2619 | return getTopHeadsUpPinnedHeight(); |
| 2620 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2621 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 2624 | public int getFirstChildIntrinsicHeight() { |
| 2625 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 2626 | int firstChildMinHeight = firstChild != null |
| 2627 | ? firstChild.getIntrinsicHeight() |
| 2628 | : mEmptyShadeView != null |
| 2629 | ? mEmptyShadeView.getIntrinsicHeight() |
| 2630 | : mCollapsedSize; |
| 2631 | if (mOwnScrollY > 0) { |
| 2632 | firstChildMinHeight = Math.max(firstChildMinHeight - mOwnScrollY, mCollapsedSize); |
| 2633 | } |
| 2634 | return firstChildMinHeight; |
| 2635 | } |
| 2636 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2637 | public float getTopPaddingOverflow() { |
| 2638 | return mTopPaddingOverflow; |
| 2639 | } |
| 2640 | |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2641 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2642 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2643 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2644 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2645 | int shelfHeight = 0; |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2646 | if (mLastVisibleBackgroundChild != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2647 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2648 | } |
| 2649 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2650 | } |
| 2651 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2652 | private int clampPadding(int desiredPadding) { |
| 2653 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2654 | } |
| 2655 | |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2656 | private float getRubberBandFactor(boolean onTop) { |
| 2657 | if (!onTop) { |
| 2658 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2659 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2660 | if (mExpandedInThisMotion) { |
| 2661 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2662 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2663 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2664 | } else if (mScrolledToTopOnFirstDown) { |
| 2665 | return 1.0f; |
| 2666 | } |
| 2667 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2668 | } |
| 2669 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2670 | /** |
| 2671 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2672 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2673 | * overscroll view (e.g. expand QS). |
| 2674 | */ |
| 2675 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2676 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2677 | || !mScrolledToTopOnFirstDown; |
| 2678 | } |
| 2679 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2680 | private void endDrag() { |
| 2681 | setIsBeingDragged(false); |
| 2682 | |
| 2683 | recycleVelocityTracker(); |
| 2684 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2685 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 2686 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 2687 | } |
| 2688 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 2689 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 2690 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2691 | } |
| 2692 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 2693 | private void transformTouchEvent(MotionEvent ev, View sourceView, View targetView) { |
| 2694 | ev.offsetLocation(sourceView.getX(), sourceView.getY()); |
| 2695 | ev.offsetLocation(-targetView.getX(), -targetView.getY()); |
| 2696 | } |
| 2697 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2698 | @Override |
| 2699 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2700 | initDownStates(ev); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2701 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2702 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 2703 | if (!mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2704 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 2705 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2706 | boolean scrollWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2707 | if (!mSwipingInProgress && !mExpandingNotification) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2708 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 2709 | } |
| 2710 | boolean swipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2711 | if (!mIsBeingDragged |
| 2712 | && !mExpandingNotification |
| 2713 | && !mExpandedInThisMotion |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 2714 | && !mOnlyScrollingInThisMotion |
| 2715 | && !mDisallowDismissInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2716 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 2717 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 2718 | // Check if we need to clear any snooze leavebehinds |
| 2719 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 2720 | NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 2721 | if (!isTouchInView(ev, guts) && isUp && !swipeWantsIt && !expandWantsIt |
| 2722 | && !scrollWantsIt) { |
| 2723 | mCheckForLeavebehind = false; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 2724 | mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */, |
| 2725 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 2726 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 2727 | } |
| 2728 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 2729 | mCheckForLeavebehind = true; |
| 2730 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2731 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 2732 | } |
| 2733 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2734 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 2735 | switch (ev.getActionMasked()) { |
| 2736 | case MotionEvent.ACTION_MOVE: |
| 2737 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 2738 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop )) { |
| 2739 | mTouchIsClick = false; |
| 2740 | } |
| 2741 | break; |
| 2742 | case MotionEvent.ACTION_UP: |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 2743 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2744 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 2745 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 2746 | } |
| 2747 | break; |
| 2748 | } |
| 2749 | } |
| 2750 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2751 | private void initDownStates(MotionEvent ev) { |
| 2752 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 2753 | mExpandedInThisMotion = false; |
| 2754 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2755 | mDisallowScrollingInThisMotion = false; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 2756 | mDisallowDismissInThisMotion = false; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2757 | mTouchIsClick = true; |
| 2758 | mInitialTouchX = ev.getX(); |
| 2759 | mInitialTouchY = ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2760 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2761 | } |
| 2762 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2763 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
| 2764 | mChildTransferInProgress = childTransferInProgress; |
| 2765 | } |
| 2766 | |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2767 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2768 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2769 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2770 | // we only call our internal methods if this is actually a removal and not just a |
| 2771 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2772 | if (!mChildTransferInProgress) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2773 | onViewRemovedInternal(child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2777 | @Override |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2778 | public void cleanUpViewState(View child) { |
| 2779 | if (child == mTranslatingParentView) { |
| 2780 | mTranslatingParentView = null; |
| 2781 | } |
| 2782 | mCurrentStackScrollState.removeViewStateForView(child); |
| 2783 | } |
| 2784 | |
Selim Cinek | 197823d | 2016-03-24 13:06:00 -0700 | [diff] [blame] | 2785 | @Override |
| 2786 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 2787 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 2788 | if (disallowIntercept) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 2789 | cancelLongPress(); |
Selim Cinek | 197823d | 2016-03-24 13:06:00 -0700 | [diff] [blame] | 2790 | } |
| 2791 | } |
| 2792 | |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2793 | private void onViewRemovedInternal(View child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2794 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2795 | // This is only a position change, don't do anything special |
| 2796 | return; |
| 2797 | } |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2798 | ExpandableView expandableView = (ExpandableView) child; |
| 2799 | expandableView.setOnHeightChangedListener(null); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2800 | mCurrentStackScrollState.removeViewStateForView(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2801 | updateScrollStateForRemovedChild(expandableView); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2802 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2803 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2804 | if (!mSwipedOutViews.contains(child) |
| 2805 | || Math.abs(expandableView.getTranslation()) != expandableView.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2806 | container.addTransientView(child, 0); |
| 2807 | expandableView.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2808 | } |
| 2809 | } else { |
| 2810 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2811 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2812 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2813 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2814 | focusNextViewIfFocused(child); |
| 2815 | } |
| 2816 | |
| 2817 | private void focusNextViewIfFocused(View view) { |
| 2818 | if (view instanceof ExpandableNotificationRow) { |
| 2819 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2820 | if (row.shouldRefocusOnDismiss()) { |
| 2821 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 2822 | if (nextView == null) { |
| 2823 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 2824 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 2825 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2826 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2827 | } |
| 2828 | if (nextView != null) { |
| 2829 | nextView.requestAccessibilityFocus(); |
| 2830 | } |
| 2831 | } |
| 2832 | } |
| 2833 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2834 | } |
| 2835 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2836 | private boolean isChildInGroup(View child) { |
| 2837 | return child instanceof ExpandableNotificationRow |
| 2838 | && mGroupManager.isChildInGroupWithSummary( |
| 2839 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
| 2840 | } |
| 2841 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2842 | /** |
| 2843 | * Generate a remove animation for a child view. |
| 2844 | * |
| 2845 | * @param child The view to generate the remove animation for. |
| 2846 | * @return Whether an animation was generated. |
| 2847 | */ |
| 2848 | private boolean generateRemoveAnimation(View child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2849 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2850 | mAddedHeadsUpChildren.remove(child); |
| 2851 | return false; |
| 2852 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2853 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 2854 | // An animation is already running, add it transiently |
| 2855 | mClearTransientViewsWhenFinished.add((ExpandableView) child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2856 | return true; |
| 2857 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2858 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2859 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2860 | // Generate Animations |
| 2861 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2862 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2863 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2864 | } else { |
| 2865 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2866 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2867 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2868 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2869 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2870 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2871 | } |
| 2872 | |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2873 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2874 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2877 | /** |
| 2878 | * Remove a removed child view from the heads up animations if it was just added there |
| 2879 | * |
| 2880 | * @return whether any child was removed from the list to animate |
| 2881 | */ |
| 2882 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 2883 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2884 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 2885 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2886 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2887 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2888 | mTmpList.add(eventPair); |
| 2889 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2890 | } |
| 2891 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2892 | if (hasAddEvent) { |
| 2893 | // This child was just added lets remove all events. |
| 2894 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 2895 | ((ExpandableNotificationRow ) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2896 | } |
| 2897 | mTmpList.clear(); |
| 2898 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2901 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2902 | * @param child the child to query |
| 2903 | * @return whether a view is not a top level child but a child notification and that group is |
| 2904 | * not expanded |
| 2905 | */ |
| 2906 | private boolean isChildInInvisibleGroup(View child) { |
| 2907 | if (child instanceof ExpandableNotificationRow) { |
| 2908 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2909 | ExpandableNotificationRow groupSummary = |
| 2910 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 2911 | if (groupSummary != null && groupSummary != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2912 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2913 | } |
| 2914 | } |
| 2915 | return false; |
| 2916 | } |
| 2917 | |
| 2918 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2919 | * Updates the scroll position when a child was removed |
| 2920 | * |
| 2921 | * @param removedChild the removed child |
| 2922 | */ |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2923 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2924 | int startingPosition = getPositionInLinearLayout(removedChild); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2925 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 2926 | int padding; |
| 2927 | if (increasedPaddingAmount >= 0) { |
| 2928 | padding = (int) NotificationUtils.interpolate( |
| 2929 | mPaddingBetweenElements, |
| 2930 | mIncreasedPaddingBetweenElements, |
| 2931 | increasedPaddingAmount); |
| 2932 | } else { |
| 2933 | padding = (int) NotificationUtils.interpolate( |
| 2934 | 0, |
| 2935 | mPaddingBetweenElements, |
| 2936 | 1.0f + increasedPaddingAmount); |
| 2937 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2938 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2939 | int endPosition = startingPosition + childHeight; |
| 2940 | if (endPosition <= mOwnScrollY) { |
| 2941 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 2942 | // scrollPosition |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2943 | setOwnScrollY(mOwnScrollY - childHeight); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2944 | } else if (startingPosition < mOwnScrollY) { |
| 2945 | // This child is currently being scrolled into, set the scroll position to the start of |
| 2946 | // this child |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2947 | setOwnScrollY(startingPosition); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 2951 | private int getIntrinsicHeight(View view) { |
| 2952 | if (view instanceof ExpandableView) { |
| 2953 | ExpandableView expandableView = (ExpandableView) view; |
| 2954 | return expandableView.getIntrinsicHeight(); |
| 2955 | } |
| 2956 | return view.getHeight(); |
| 2957 | } |
| 2958 | |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 2959 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 2960 | ExpandableNotificationRow childInGroup = null; |
| 2961 | ExpandableNotificationRow requestedRow = null; |
| 2962 | if (isChildInGroup(requestedView)) { |
| 2963 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 2964 | // then within the parent. |
| 2965 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 2966 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 2967 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2968 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2969 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2970 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2971 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2972 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 2973 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2974 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2975 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2976 | float padding; |
| 2977 | if (increasedPaddingAmount >= 0.0f) { |
| 2978 | padding = (int) NotificationUtils.interpolate( |
| 2979 | previousPaddingRequest, |
| 2980 | mIncreasedPaddingBetweenElements, |
| 2981 | increasedPaddingAmount); |
| 2982 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2983 | mPaddingBetweenElements, |
| 2984 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2985 | increasedPaddingAmount); |
| 2986 | } else { |
| 2987 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2988 | 0, |
| 2989 | mPaddingBetweenElements, |
| 2990 | 1.0f + increasedPaddingAmount); |
| 2991 | if (previousPaddingAmount > 0.0f) { |
| 2992 | padding = (int) NotificationUtils.interpolate( |
| 2993 | ownPadding, |
| 2994 | mIncreasedPaddingBetweenElements, |
| 2995 | previousPaddingAmount); |
| 2996 | } else { |
| 2997 | padding = ownPadding; |
| 2998 | } |
| 2999 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3000 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 3001 | if (position != 0) { |
| 3002 | position += padding; |
| 3003 | } |
| 3004 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3005 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3006 | if (child == requestedView) { |
| 3007 | if (requestedRow != null) { |
| 3008 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3009 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3010 | return position; |
| 3011 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3012 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3013 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3014 | } |
| 3015 | } |
| 3016 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3020 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3021 | super.onViewAdded(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3022 | onViewAddedInternal(child); |
| 3023 | } |
| 3024 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3025 | private void updateFirstAndLastBackgroundViews() { |
| 3026 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3027 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
| 3028 | if (mAnimationsEnabled && mIsExpanded) { |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 3029 | mAnimateNextBackgroundTop = firstChild != mFirstVisibleBackgroundChild; |
| 3030 | mAnimateNextBackgroundBottom = lastChild != mLastVisibleBackgroundChild; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3031 | } else { |
| 3032 | mAnimateNextBackgroundTop = false; |
| 3033 | mAnimateNextBackgroundBottom = false; |
| 3034 | } |
| 3035 | mFirstVisibleBackgroundChild = firstChild; |
| 3036 | mLastVisibleBackgroundChild = lastChild; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3037 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 3038 | mRoundnessManager.setFirstAndLastBackgroundChild(mFirstVisibleBackgroundChild, |
| 3039 | mLastVisibleBackgroundChild); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3040 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3041 | } |
| 3042 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3043 | private void onViewAddedInternal(View child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3044 | updateHideSensitiveForChild(child); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3045 | ((ExpandableView) child).setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3046 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3047 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3048 | updateChronometerForChild(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3049 | } |
| 3050 | |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3051 | private void updateHideSensitiveForChild(View child) { |
Selim Cinek | cfcd23e | 2016-05-05 12:31:42 -0400 | [diff] [blame] | 3052 | if (child instanceof ExpandableView) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3053 | ExpandableView expandableView = (ExpandableView) child; |
Selim Cinek | cfcd23e | 2016-05-05 12:31:42 -0400 | [diff] [blame] | 3054 | expandableView.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | } |
| 3057 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3058 | @Override |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3059 | public void notifyGroupChildRemoved(View row, ViewGroup childrenContainer) { |
| 3060 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3061 | } |
| 3062 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3063 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3064 | public void notifyGroupChildAdded(View row) { |
| 3065 | onViewAddedInternal(row); |
| 3066 | } |
| 3067 | |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3068 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3069 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3070 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3071 | if (!animationsEnabled) { |
| 3072 | mSwipedOutViews.clear(); |
| 3073 | mChildrenToRemoveAnimated.clear(); |
| 3074 | clearTemporaryViewsInGroup(this); |
| 3075 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3079 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3080 | mShelf.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3081 | int childCount = getChildCount(); |
| 3082 | for (int i = 0; i < childCount; i++) { |
| 3083 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3084 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3085 | updateAnimationState(running, child); |
| 3086 | } |
| 3087 | } |
| 3088 | |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3089 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3090 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3091 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3092 | } |
| 3093 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3094 | @Override |
| 3095 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3096 | mAmbientState.setExpandingNotification(row); |
| 3097 | requestChildrenUpdate(); |
| 3098 | } |
| 3099 | |
| 3100 | @Override |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3101 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3102 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3103 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3104 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3105 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | @Override |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3109 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3110 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3111 | requestChildrenUpdate(); |
| 3112 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3113 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3114 | private void updateAnimationState(boolean running, View child) { |
| 3115 | if (child instanceof ExpandableNotificationRow) { |
| 3116 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3117 | row.setIconAnimationRunning(running); |
| 3118 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | public boolean isAddOrRemoveAnimationPending() { |
| 3122 | return mNeedsAnimation |
| 3123 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3124 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3125 | |
| 3126 | @Override |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3127 | public void generateAddAnimation(View child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3128 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3129 | // Generate Animations |
| 3130 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3131 | if (fromMoreCard) { |
| 3132 | mFromMoreCardAdditions.add(child); |
| 3133 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3134 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3135 | } |
Selim Cinek | f306d9b | 2017-02-21 11:45:13 -0800 | [diff] [blame] | 3136 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3137 | mAddedHeadsUpChildren.add(child); |
| 3138 | mChildrenToAddAnimated.remove(child); |
| 3139 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3140 | } |
| 3141 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3142 | @Override |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3143 | public void changeViewPosition(View child, int newIndex) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3144 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3145 | |
| 3146 | if (currentIndex == -1) { |
| 3147 | boolean isTransient = false; |
| 3148 | if (child instanceof ExpandableNotificationRow |
| 3149 | && ((ExpandableNotificationRow)child).getTransientContainer() != null) { |
| 3150 | isTransient = true; |
| 3151 | } |
| 3152 | Log.e(TAG, "Attempting to re-position " |
| 3153 | + (isTransient ? "transient" : "") |
| 3154 | + " view {" |
| 3155 | + child |
| 3156 | + "}"); |
| 3157 | return; |
| 3158 | } |
| 3159 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3160 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3161 | mChangePositionInProgress = true; |
Adrian Roos | 14503e2 | 2016-03-09 14:01:24 -0800 | [diff] [blame] | 3162 | ((ExpandableView)child).setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3163 | removeView(child); |
| 3164 | addView(child, newIndex); |
Adrian Roos | 14503e2 | 2016-03-09 14:01:24 -0800 | [diff] [blame] | 3165 | ((ExpandableView)child).setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3166 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3167 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3168 | mChildrenChangingPositions.add(child); |
| 3169 | mNeedsAnimation = true; |
| 3170 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3171 | } |
| 3172 | } |
| 3173 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3174 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3175 | if (mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3176 | generateChildHierarchyEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3177 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3178 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3179 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3180 | setAnimationRunning(true); |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3181 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mCurrentStackScrollState, |
| 3182 | mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3183 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3184 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3185 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3186 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3187 | } else { |
| 3188 | applyCurrentState(); |
| 3189 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3190 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | private void generateChildHierarchyEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3194 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3195 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3196 | generateChildAdditionEvents(); |
| 3197 | generatePositionChangeEvents(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3198 | generateSnapBackEvents(); |
| 3199 | generateDragEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3200 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3201 | generateActivateEvent(); |
| 3202 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3203 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3204 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3205 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3206 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3207 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3208 | generateAnimateEverythingEvent(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 3209 | generatePulsingAnimationEvent(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3210 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3211 | } |
| 3212 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3213 | private void generateHeadsUpAnimationEvents() { |
| 3214 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3215 | ExpandableNotificationRow row = eventPair.first; |
| 3216 | boolean isHeadsUp = eventPair.second; |
| 3217 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3218 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3219 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3220 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3221 | type = row.wasJustClicked() |
| 3222 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3223 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3224 | if (row.isChildInGroup()) { |
| 3225 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3226 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3227 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3228 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3229 | } else { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3230 | ExpandableViewState viewState = mCurrentStackScrollState.getViewStateForView(row); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3231 | if (viewState == null) { |
| 3232 | // A view state was never generated for this view, so we don't need to animate |
| 3233 | // this. This may happen with notification children. |
| 3234 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3235 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3236 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3237 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3238 | // Our custom add animation |
| 3239 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3240 | } else { |
| 3241 | // Normal add animation |
| 3242 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3243 | } |
| 3244 | onBottom = !pinnedAndClosed; |
| 3245 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3246 | } |
| 3247 | AnimationEvent event = new AnimationEvent(row, type); |
| 3248 | event.headsUpFromBottom = onBottom; |
| 3249 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3250 | } |
| 3251 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3252 | mAddedHeadsUpChildren.clear(); |
| 3253 | } |
| 3254 | |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3255 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3256 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3257 | return false; |
| 3258 | } |
| 3259 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3262 | private void generateGroupExpansionEvent() { |
| 3263 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3264 | if (mExpandedGroupView != null) { |
| 3265 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3266 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3267 | mExpandedGroupView = null; |
| 3268 | } |
| 3269 | } |
| 3270 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3271 | private void generateViewResizeEvent() { |
| 3272 | if (mNeedViewResizeAnimation) { |
| 3273 | mAnimationEvents.add( |
| 3274 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3275 | } |
| 3276 | mNeedViewResizeAnimation = false; |
| 3277 | } |
| 3278 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3279 | private void generateSnapBackEvents() { |
| 3280 | for (View child : mSnappedBackChildren) { |
| 3281 | mAnimationEvents.add(new AnimationEvent(child, |
| 3282 | AnimationEvent.ANIMATION_TYPE_SNAP_BACK)); |
| 3283 | } |
| 3284 | mSnappedBackChildren.clear(); |
| 3285 | } |
| 3286 | |
| 3287 | private void generateDragEvents() { |
| 3288 | for (View child : mDragAnimPendingChildren) { |
| 3289 | mAnimationEvents.add(new AnimationEvent(child, |
| 3290 | AnimationEvent.ANIMATION_TYPE_START_DRAG)); |
| 3291 | } |
| 3292 | mDragAnimPendingChildren.clear(); |
| 3293 | } |
| 3294 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3295 | private void generateChildRemovalEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3296 | for (View child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3297 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3298 | |
| 3299 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3300 | float removedTranslation = child.getTranslationY(); |
| 3301 | boolean ignoreChildren = true; |
| 3302 | if (child instanceof ExpandableNotificationRow) { |
| 3303 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3304 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3305 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3306 | ignoreChildren = false; |
| 3307 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3308 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3309 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3310 | if (!childWasSwipedOut) { |
| 3311 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3312 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3313 | |
| 3314 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3315 | // Clean up any potential transient views if the child has already been swiped |
| 3316 | // out, as we won't be animating it further (due to its height already being |
| 3317 | // clipped to 0. |
| 3318 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3319 | if (transientContainer != null) { |
| 3320 | transientContainer.removeTransientView(child); |
| 3321 | } |
| 3322 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3323 | } |
| 3324 | int animationType = childWasSwipedOut |
| 3325 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3326 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3327 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3328 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3329 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3330 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3331 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3332 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3333 | mChildrenToRemoveAnimated.clear(); |
| 3334 | } |
| 3335 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3336 | private void generatePositionChangeEvents() { |
| 3337 | for (View child : mChildrenChangingPositions) { |
| 3338 | mAnimationEvents.add(new AnimationEvent(child, |
| 3339 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3340 | } |
| 3341 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3342 | if (mGenerateChildOrderChangedEvent) { |
| 3343 | mAnimationEvents.add(new AnimationEvent(null, |
| 3344 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3345 | mGenerateChildOrderChangedEvent = false; |
| 3346 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3347 | } |
| 3348 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3349 | private void generateChildAdditionEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3350 | for (View child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3351 | if (mFromMoreCardAdditions.contains(child)) { |
| 3352 | mAnimationEvents.add(new AnimationEvent(child, |
| 3353 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3354 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3355 | } else { |
| 3356 | mAnimationEvents.add(new AnimationEvent(child, |
| 3357 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3358 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3359 | } |
| 3360 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3361 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3362 | } |
| 3363 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3364 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3365 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3366 | AnimationEvent event; |
| 3367 | if (mAmbientState.isDark()) { |
| 3368 | event = new AnimationEvent(null /* view */, |
| 3369 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3370 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3371 | } else { |
| 3372 | event = new AnimationEvent(null /* view */, |
| 3373 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3374 | } |
| 3375 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3376 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3377 | mTopPaddingNeedsAnimation = false; |
| 3378 | } |
| 3379 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3380 | private void generateActivateEvent() { |
| 3381 | if (mActivateNeedsAnimation) { |
| 3382 | mAnimationEvents.add( |
| 3383 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3384 | } |
| 3385 | mActivateNeedsAnimation = false; |
| 3386 | } |
| 3387 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3388 | private void generateAnimateEverythingEvent() { |
| 3389 | if (mEverythingNeedsAnimation) { |
| 3390 | mAnimationEvents.add( |
| 3391 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3392 | } |
| 3393 | mEverythingNeedsAnimation = false; |
| 3394 | } |
| 3395 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3396 | private void generateDimmedEvent() { |
| 3397 | if (mDimmedNeedsAnimation) { |
| 3398 | mAnimationEvents.add( |
| 3399 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3400 | } |
| 3401 | mDimmedNeedsAnimation = false; |
| 3402 | } |
| 3403 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3404 | private void generateHideSensitiveEvent() { |
| 3405 | if (mHideSensitiveNeedsAnimation) { |
| 3406 | mAnimationEvents.add( |
| 3407 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3408 | } |
| 3409 | mHideSensitiveNeedsAnimation = false; |
| 3410 | } |
| 3411 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3412 | private void generateDarkEvent() { |
| 3413 | if (mDarkNeedsAnimation) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 3414 | AnimationEvent ev = new AnimationEvent(null, |
| 3415 | AnimationEvent.ANIMATION_TYPE_DARK, |
| 3416 | new AnimationFilter() |
| 3417 | .animateDark() |
| 3418 | .animateY(mShelf)); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3419 | ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex; |
| 3420 | mAnimationEvents.add(ev); |
Lucas Dupin | b98ddb4 | 2018-05-29 17:26:35 -0700 | [diff] [blame] | 3421 | startDarkAmountAnimation(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3422 | } |
| 3423 | mDarkNeedsAnimation = false; |
| 3424 | } |
| 3425 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3426 | private void generateGoToFullShadeEvent() { |
| 3427 | if (mGoToFullShadeNeedsAnimation) { |
| 3428 | mAnimationEvents.add( |
| 3429 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3430 | } |
| 3431 | mGoToFullShadeNeedsAnimation = false; |
| 3432 | } |
| 3433 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3434 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3435 | if (!isScrollingEnabled()) { |
| 3436 | return false; |
| 3437 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3438 | /* |
| 3439 | * This method JUST determines whether we want to intercept the motion. |
| 3440 | * If we return true, onMotionEvent will be called and we do the actual |
| 3441 | * scrolling there. |
| 3442 | */ |
| 3443 | |
| 3444 | /* |
| 3445 | * Shortcut the most recurring case: the user is in the dragging |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 3446 | * state and is moving their finger. We want to intercept this |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3447 | * motion. |
| 3448 | */ |
| 3449 | final int action = ev.getAction(); |
| 3450 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 3451 | return true; |
| 3452 | } |
| 3453 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3454 | switch (action & MotionEvent.ACTION_MASK) { |
| 3455 | case MotionEvent.ACTION_MOVE: { |
| 3456 | /* |
| 3457 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 3458 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3459 | */ |
| 3460 | |
| 3461 | /* |
| 3462 | * Locally do absolute value. mLastMotionY is set to the y value |
| 3463 | * of the down event. |
| 3464 | */ |
| 3465 | final int activePointerId = mActivePointerId; |
| 3466 | if (activePointerId == INVALID_POINTER) { |
| 3467 | // If we don't have a valid id, the touch down wasn't on content. |
| 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 3472 | if (pointerIndex == -1) { |
| 3473 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 3474 | + " in onInterceptTouchEvent"); |
| 3475 | break; |
| 3476 | } |
| 3477 | |
| 3478 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3479 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3480 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3481 | final int xDiff = Math.abs(x - mDownX); |
| 3482 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3483 | setIsBeingDragged(true); |
| 3484 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3485 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3486 | initVelocityTrackerIfNotExists(); |
| 3487 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3488 | } |
| 3489 | break; |
| 3490 | } |
| 3491 | |
| 3492 | case MotionEvent.ACTION_DOWN: { |
| 3493 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 3494 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 3495 | if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3496 | setIsBeingDragged(false); |
| 3497 | recycleVelocityTracker(); |
| 3498 | break; |
| 3499 | } |
| 3500 | |
| 3501 | /* |
| 3502 | * Remember location of down touch. |
| 3503 | * ACTION_DOWN always refers to pointer index 0. |
| 3504 | */ |
| 3505 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3506 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3507 | mActivePointerId = ev.getPointerId(0); |
| 3508 | |
| 3509 | initOrResetVelocityTracker(); |
| 3510 | mVelocityTracker.addMovement(ev); |
| 3511 | /* |
| 3512 | * If being flinged and user touches the screen, initiate drag; |
| 3513 | * otherwise don't. mScroller.isFinished should be false when |
| 3514 | * being flinged. |
| 3515 | */ |
| 3516 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3517 | setIsBeingDragged(isBeingDragged); |
| 3518 | break; |
| 3519 | } |
| 3520 | |
| 3521 | case MotionEvent.ACTION_CANCEL: |
| 3522 | case MotionEvent.ACTION_UP: |
| 3523 | /* Release the drag */ |
| 3524 | setIsBeingDragged(false); |
| 3525 | mActivePointerId = INVALID_POINTER; |
| 3526 | recycleVelocityTracker(); |
| 3527 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 3528 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3529 | } |
| 3530 | break; |
| 3531 | case MotionEvent.ACTION_POINTER_UP: |
| 3532 | onSecondaryPointerUp(ev); |
| 3533 | break; |
| 3534 | } |
| 3535 | |
| 3536 | /* |
| 3537 | * The only time we want to intercept motion events is if we are in the |
| 3538 | * drag mode. |
| 3539 | */ |
| 3540 | return mIsBeingDragged; |
| 3541 | } |
| 3542 | |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 3543 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
| 3544 | return new StackScrollAlgorithm(context); |
| 3545 | } |
| 3546 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 3547 | /** |
| 3548 | * @return Whether the specified motion event is actually happening over the content. |
| 3549 | */ |
| 3550 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 3551 | return isInContentBounds(event.getY()); |
| 3552 | } |
| 3553 | |
| 3554 | /** |
| 3555 | * @return Whether a y coordinate is inside the content. |
| 3556 | */ |
| 3557 | public boolean isInContentBounds(float y) { |
| 3558 | return y < getHeight() - getEmptyBottomMargin(); |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 3559 | } |
| 3560 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3561 | private void setIsBeingDragged(boolean isDragged) { |
| 3562 | mIsBeingDragged = isDragged; |
| 3563 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3564 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3565 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3566 | } |
| 3567 | } |
| 3568 | |
| 3569 | @Override |
| 3570 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 3571 | super.onWindowFocusChanged(hasWindowFocus); |
| 3572 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3573 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3574 | } |
| 3575 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 3576 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 3577 | @Override |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 3578 | public void clearChildFocus(View child) { |
| 3579 | super.clearChildFocus(child); |
| 3580 | if (mForcedScroll == child) { |
| 3581 | mForcedScroll = null; |
| 3582 | } |
| 3583 | } |
| 3584 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 3585 | public void requestDisallowLongPress() { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3586 | cancelLongPress(); |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 3589 | public void requestDisallowDismiss() { |
| 3590 | mDisallowDismissInThisMotion = true; |
| 3591 | } |
| 3592 | |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3593 | public void cancelLongPress() { |
| 3594 | mSwipeHelper.cancelLongPress(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3595 | } |
| 3596 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 3597 | @Override |
| 3598 | public boolean isScrolledToTop() { |
| 3599 | return mOwnScrollY == 0; |
| 3600 | } |
| 3601 | |
| 3602 | @Override |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3603 | public boolean isScrolledToBottom() { |
| 3604 | return mOwnScrollY >= getScrollRange(); |
| 3605 | } |
| 3606 | |
| 3607 | @Override |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 3608 | public View getHostView() { |
| 3609 | return this; |
| 3610 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 3611 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3612 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3613 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3614 | } |
| 3615 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3616 | public void checkSnoozeLeavebehind() { |
| 3617 | if (mCheckForLeavebehind) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 3618 | mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */, |
| 3619 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 3620 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3621 | mCheckForLeavebehind = false; |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | public void resetCheckSnoozeLeavebehind() { |
| 3626 | mCheckForLeavebehind = true; |
| 3627 | } |
| 3628 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3629 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3630 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3631 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3632 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3636 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3637 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3638 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 3639 | if (!mIsExpanded) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 3640 | setOwnScrollY(0); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 3641 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3642 | clearTemporaryViews(); |
| 3643 | clearUserLockedViews(); |
| 3644 | } |
| 3645 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 3646 | |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3647 | private void clearUserLockedViews() { |
| 3648 | for (int i = 0; i < getChildCount(); i++) { |
| 3649 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3650 | if (child instanceof ExpandableNotificationRow) { |
| 3651 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3652 | row.setUserLocked(false); |
| 3653 | } |
| 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3658 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3659 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3660 | for (int i = 0; i < getChildCount(); i++) { |
| 3661 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3662 | if (child instanceof ExpandableNotificationRow) { |
| 3663 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3664 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3665 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 3666 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3667 | } |
| 3668 | |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3669 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3670 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 3671 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 3675 | public void onPanelTrackingStarted() { |
| 3676 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3677 | mAmbientState.setPanelTracking(true); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 3678 | } |
| 3679 | public void onPanelTrackingStopped() { |
| 3680 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3681 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 3684 | public void resetScrollPosition() { |
| 3685 | mScroller.abortAnimation(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 3686 | setOwnScrollY(0); |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 3689 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3690 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3691 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3692 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3693 | if (changed) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 3694 | if (!mIsExpanded) { |
| 3695 | mGroupManager.collapseAllGroups(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3696 | mExpandHelper.cancelImmediately(); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 3697 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3698 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3699 | updateChronometers(); |
Selim Cinek | f3fa685 | 2016-12-20 18:36:02 +0100 | [diff] [blame] | 3700 | requestChildrenUpdate(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3701 | } |
| 3702 | } |
| 3703 | |
| 3704 | private void updateChronometers() { |
| 3705 | int childCount = getChildCount(); |
| 3706 | for (int i = 0; i < childCount; i++) { |
| 3707 | updateChronometerForChild(getChildAt(i)); |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | private void updateChronometerForChild(View child) { |
| 3712 | if (child instanceof ExpandableNotificationRow) { |
| 3713 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3714 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3715 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3716 | } |
| 3717 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3718 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3719 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3720 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3721 | updateScrollPositionOnExpandInBottom(view); |
| 3722 | clampScrollPosition(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 3723 | notifyHeightChangeListener(view, needsAnimation); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 3724 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 3725 | ? (ExpandableNotificationRow) view |
| 3726 | : null; |
| 3727 | if (row != null && (row == mFirstVisibleBackgroundChild |
| 3728 | || row.getNotificationParent() == mFirstVisibleBackgroundChild)) { |
| 3729 | updateAlgorithmLayoutMinHeight(); |
| 3730 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3731 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 3732 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3733 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3734 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3735 | } |
| 3736 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3737 | @Override |
| 3738 | public void onReset(ExpandableView view) { |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3739 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3740 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3741 | } |
| 3742 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3743 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 3744 | if (view instanceof ExpandableNotificationRow && !onKeyguard()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3745 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 3746 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 3747 | if (row.isSummaryWithChildren()) { |
| 3748 | return; |
| 3749 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3750 | // We are actually expanding this view |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 3751 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 3752 | if (row.isChildInGroup()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 3753 | endPosition += row.getNotificationParent().getTranslationY(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 3754 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3755 | int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation; |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 3756 | if (row != mLastVisibleBackgroundChild && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3757 | layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements; |
| 3758 | } |
| 3759 | if (endPosition > layoutEnd) { |
| 3760 | setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd)); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3761 | mDisallowScrollingInThisMotion = true; |
| 3762 | } |
| 3763 | } |
| 3764 | } |
| 3765 | } |
| 3766 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3767 | public void setOnHeightChangedListener( |
| 3768 | ExpandableView.OnHeightChangedListener mOnHeightChangedListener) { |
| 3769 | this.mOnHeightChangedListener = mOnHeightChangedListener; |
| 3770 | } |
| 3771 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 3772 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 3773 | mOnEmptySpaceClickListener = listener; |
| 3774 | } |
| 3775 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3776 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3777 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 3778 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 3779 | runAnimationFinishedRunnables(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3780 | clearTransient(); |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 3781 | clearHeadsUpDisappearRunning(); |
| 3782 | } |
| 3783 | |
| 3784 | private void clearHeadsUpDisappearRunning() { |
| 3785 | for (int i = 0; i < getChildCount(); i++) { |
| 3786 | View view = getChildAt(i); |
| 3787 | if (view instanceof ExpandableNotificationRow) { |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3788 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3789 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3790 | if (row.isSummaryWithChildren()) { |
| 3791 | for (ExpandableNotificationRow child : row.getNotificationChildren()) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3792 | child.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3793 | } |
| 3794 | } |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 3795 | } |
| 3796 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3799 | private void clearTransient() { |
| 3800 | for (ExpandableView view : mClearTransientViewsWhenFinished) { |
| 3801 | StackStateAnimator.removeTransientView(view); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3802 | } |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3803 | mClearTransientViewsWhenFinished.clear(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3807 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 3808 | runnable.run(); |
| 3809 | } |
| 3810 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3811 | } |
| 3812 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3813 | /** |
| 3814 | * See {@link AmbientState#setDimmed}. |
| 3815 | */ |
| 3816 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 3817 | dimmed &= onKeyguard(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3818 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3819 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3820 | mDimmedNeedsAnimation = true; |
| 3821 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 3822 | animateDimmed(dimmed); |
| 3823 | } else { |
| 3824 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3825 | } |
| 3826 | requestChildrenUpdate(); |
| 3827 | } |
| 3828 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 3829 | @VisibleForTesting |
| 3830 | boolean isDimmed() { |
| 3831 | return mAmbientState.isDimmed(); |
| 3832 | } |
| 3833 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 3834 | private void setDimAmount(float dimAmount) { |
| 3835 | mDimAmount = dimAmount; |
| 3836 | updateBackgroundDimming(); |
| 3837 | } |
| 3838 | |
| 3839 | private void animateDimmed(boolean dimmed) { |
| 3840 | if (mDimAnimator != null) { |
| 3841 | mDimAnimator.cancel(); |
| 3842 | } |
| 3843 | float target = dimmed ? 1.0f : 0.0f; |
| 3844 | if (target == mDimAmount) { |
| 3845 | return; |
| 3846 | } |
| 3847 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 3848 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 3849 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 3850 | mDimAnimator.addListener(mDimEndListener); |
| 3851 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 3852 | mDimAnimator.start(); |
| 3853 | } |
| 3854 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3855 | public void setHideSensitive(boolean hideSensitive, boolean animate) { |
| 3856 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 3857 | int childCount = getChildCount(); |
| 3858 | for (int i = 0; i < childCount; i++) { |
| 3859 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 3860 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 3861 | } |
| 3862 | mAmbientState.setHideSensitive(hideSensitive); |
| 3863 | if (animate && mAnimationsEnabled) { |
| 3864 | mHideSensitiveNeedsAnimation = true; |
| 3865 | mNeedsAnimation = true; |
| 3866 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 3867 | updateContentHeight(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3868 | requestChildrenUpdate(); |
| 3869 | } |
| 3870 | } |
| 3871 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3872 | /** |
| 3873 | * See {@link AmbientState#setActivatedChild}. |
| 3874 | */ |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 3875 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3876 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3877 | if (mAnimationsEnabled) { |
| 3878 | mActivateNeedsAnimation = true; |
| 3879 | mNeedsAnimation = true; |
| 3880 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3881 | requestChildrenUpdate(); |
| 3882 | } |
| 3883 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 3884 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3885 | return mAmbientState.getActivatedChild(); |
| 3886 | } |
| 3887 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3888 | private void applyCurrentState() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3889 | mCurrentStackScrollState.apply(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3890 | if (mListener != null) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3891 | mListener.onChildLocationsChanged(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3892 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 3893 | runAnimationFinishedRunnables(); |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3894 | setAnimationRunning(false); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3895 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3896 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3897 | updateClippingToTopRoundedCorner(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | private void updateViewShadows() { |
| 3901 | // we need to work around an issue where the shadow would not cast between siblings when |
| 3902 | // their z difference is between 0 and 0.1 |
| 3903 | |
| 3904 | // Lefts first sort by Z difference |
| 3905 | for (int i = 0; i < getChildCount(); i++) { |
| 3906 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3907 | if (child.getVisibility() != GONE) { |
| 3908 | mTmpSortedChildren.add(child); |
| 3909 | } |
| 3910 | } |
| 3911 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 3912 | |
| 3913 | // Now lets update the shadow for the views |
| 3914 | ExpandableView previous = null; |
| 3915 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 3916 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 3917 | float translationZ = expandableView.getTranslationZ(); |
| 3918 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 3919 | float diff = otherZ - translationZ; |
| 3920 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 3921 | // There is no fake shadow to be drawn |
| 3922 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 3923 | } else { |
| 3924 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 3925 | expandableView.getTranslationY() - previous.getExtraBottomPadding(); |
| 3926 | expandableView.setFakeShadowIntensity( |
| 3927 | diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3928 | previous.getOutlineAlpha(), (int) yLocation, |
| 3929 | previous.getOutlineTranslation()); |
| 3930 | } |
| 3931 | previous = expandableView; |
| 3932 | } |
| 3933 | |
| 3934 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3935 | } |
| 3936 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 3937 | /** |
| 3938 | * Update colors of "dismiss" and "empty shade" views. |
| 3939 | * |
| 3940 | * @param lightTheme True if light theme should be used. |
| 3941 | */ |
| 3942 | public void updateDecorViews(boolean lightTheme) { |
| 3943 | if (lightTheme == mUsingLightTheme) { |
| 3944 | return; |
| 3945 | } |
| 3946 | mUsingLightTheme = lightTheme; |
| 3947 | Context context = new ContextThemeWrapper(mContext, |
| 3948 | lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 3949 | final int textColor = Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 3950 | mFooterView.setTextColor(textColor); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 3951 | mEmptyShadeView.setTextColor(textColor); |
| 3952 | } |
| 3953 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3954 | public void goToFullShade(long delay) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3955 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3956 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3957 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3958 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3959 | } |
| 3960 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3961 | public void cancelExpandHelper() { |
| 3962 | mExpandHelper.cancel(); |
| 3963 | } |
| 3964 | |
| 3965 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 3966 | mIntrinsicPadding = intrinsicPadding; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3967 | mAmbientState.setIntrinsicPadding(intrinsicPadding); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3968 | } |
| 3969 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 3970 | public int getIntrinsicPadding() { |
| 3971 | return mIntrinsicPadding; |
| 3972 | } |
| 3973 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 3974 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 3975 | * @return the y position of the first notification |
| 3976 | */ |
| 3977 | public float getNotificationsTopY() { |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 3978 | return mTopPadding + getStackTranslation(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 3979 | } |
| 3980 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 3981 | @Override |
| 3982 | public boolean shouldDelayChildPressedState() { |
| 3983 | return true; |
| 3984 | } |
| 3985 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 3986 | /** |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3987 | * See {@link AmbientState#setDark}. |
| 3988 | */ |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3989 | public void setDark(boolean dark, boolean animate, @Nullable PointF touchWakeUpScreenLocation) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 3990 | if (mAmbientState.isDark() == dark) { |
| 3991 | return; |
| 3992 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3993 | mAmbientState.setDark(dark); |
| 3994 | if (animate && mAnimationsEnabled) { |
| 3995 | mDarkNeedsAnimation = true; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3996 | mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3997 | mNeedsAnimation = true; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3998 | } else { |
Lucas Dupin | b98ddb4 | 2018-05-29 17:26:35 -0700 | [diff] [blame] | 3999 | if (mDarkAmountAnimator != null) { |
| 4000 | mDarkAmountAnimator.cancel(); |
| 4001 | } |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4002 | setDarkAmount(dark ? 1f : 0f); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4003 | updateBackground(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4004 | } |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 4005 | requestChildrenUpdate(); |
| 4006 | applyCurrentBackgroundBounds(); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4007 | updateWillNotDraw(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4008 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4009 | } |
| 4010 | |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4011 | private void updatePanelTranslation() { |
| 4012 | setTranslationX(mVerticalPanelTranslation + mAntiBurnInOffsetX * mDarkAmount); |
| 4013 | } |
| 4014 | |
| 4015 | public void setVerticalPanelTranslation(float verticalPanelTranslation) { |
| 4016 | mVerticalPanelTranslation = verticalPanelTranslation; |
| 4017 | updatePanelTranslation(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 4018 | } |
| 4019 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4020 | /** |
| 4021 | * Updates whether or not this Layout will perform its own custom drawing (i.e. whether or |
| 4022 | * not {@link #onDraw(Canvas)} is called). This method should be called whenever the |
| 4023 | * {@link #mAmbientState}'s dark mode is toggled. |
| 4024 | */ |
| 4025 | private void updateWillNotDraw() { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4026 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 4027 | setWillNotDraw(!willDraw); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4028 | } |
| 4029 | |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4030 | private void setDarkAmount(float darkAmount) { |
| 4031 | mDarkAmount = darkAmount; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4032 | boolean wasFullyDark = mAmbientState.isFullyDark(); |
| 4033 | mAmbientState.setDarkAmount(darkAmount); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4034 | boolean nowFullyDark = mAmbientState.isFullyDark(); |
| 4035 | if (nowFullyDark != wasFullyDark) { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4036 | updateContentHeight(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4037 | DozeParameters dozeParameters = DozeParameters.getInstance(mContext); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4038 | if (nowFullyDark && dozeParameters.shouldControlScreenOff()) { |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4039 | mShelf.fadeInTranslating(); |
| 4040 | } |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4041 | if (mIconAreaController != null) { |
| 4042 | mIconAreaController.setFullyDark(nowFullyDark); |
| 4043 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4044 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4045 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4046 | updateBackgroundDimming(); |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4047 | updatePanelTranslation(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4048 | requestChildrenUpdate(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4049 | } |
| 4050 | |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4051 | public float getDarkAmount() { |
| 4052 | return mDarkAmount; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 4055 | /** |
| 4056 | * Cancel any previous dark animations - to avoid race conditions - and creates a new one. |
| 4057 | * This function also sets {@code mBackgroundXFactor} based on the current {@code mDarkAmount}. |
| 4058 | */ |
Lucas Dupin | b98ddb4 | 2018-05-29 17:26:35 -0700 | [diff] [blame] | 4059 | private void startDarkAmountAnimation() { |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 4060 | boolean dark = mAmbientState.isDark(); |
| 4061 | if (mDarkAmountAnimator != null) { |
| 4062 | mDarkAmountAnimator.cancel(); |
| 4063 | } |
| 4064 | |
| 4065 | long duration = StackStateAnimator.ANIMATION_DURATION_WAKEUP; |
| 4066 | // Longer animation when sleeping with more than 1 notification |
| 4067 | if (dark && getNotGoneChildCount() > 2) { |
| 4068 | duration *= 1.2f; |
| 4069 | } |
| 4070 | |
| 4071 | mDarkAmountAnimator = ObjectAnimator.ofFloat(this, DARK_AMOUNT, mDarkAmount, |
| 4072 | dark ? 1f : 0); |
| 4073 | // We only swap the scaling factor if we're fully dark or fully awake to avoid |
| 4074 | // interpolation issues when playing with the power button. |
| 4075 | if (mDarkAmount == 0 || mDarkAmount == 1) { |
| 4076 | mBackgroundXFactor = dark ? 2.5f : 1.5f; |
| 4077 | } |
| 4078 | mDarkAmountAnimator.setDuration(duration); |
| 4079 | mDarkAmountAnimator.setInterpolator(Interpolators.LINEAR); |
| 4080 | mDarkAmountAnimator.addListener(new AnimatorListenerAdapter() { |
Lucas Dupin | b98ddb4 | 2018-05-29 17:26:35 -0700 | [diff] [blame] | 4081 | @Override |
| 4082 | public void onAnimationEnd(Animator animation) { |
| 4083 | mDarkAmountAnimator = null; |
| 4084 | } |
| 4085 | }); |
Lucas Dupin | b98ddb4 | 2018-05-29 17:26:35 -0700 | [diff] [blame] | 4086 | mDarkAmountAnimator.start(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4089 | private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4090 | if (screenLocation == null || screenLocation.y < mTopPadding) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4091 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4092 | } |
| 4093 | if (screenLocation.y > getBottomMostNotificationBottom()) { |
| 4094 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW; |
| 4095 | } |
| 4096 | View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y); |
| 4097 | if (child != null) { |
| 4098 | return getNotGoneIndex(child); |
| 4099 | } else { |
| 4100 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4101 | } |
| 4102 | } |
| 4103 | |
| 4104 | private int getNotGoneIndex(View child) { |
| 4105 | int count = getChildCount(); |
| 4106 | int notGoneIndex = 0; |
| 4107 | for (int i = 0; i < count; i++) { |
| 4108 | View v = getChildAt(i); |
| 4109 | if (child == v) { |
| 4110 | return notGoneIndex; |
| 4111 | } |
| 4112 | if (v.getVisibility() != View.GONE) { |
| 4113 | notGoneIndex++; |
| 4114 | } |
| 4115 | } |
| 4116 | return -1; |
| 4117 | } |
| 4118 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4119 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4120 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4121 | if (mFooterView != null) { |
| 4122 | index = indexOfChild(mFooterView); |
| 4123 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4124 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4125 | mFooterView = footerView; |
| 4126 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4127 | } |
| 4128 | |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4129 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4130 | int index = -1; |
| 4131 | if (mEmptyShadeView != null) { |
| 4132 | index = indexOfChild(mEmptyShadeView); |
| 4133 | removeView(mEmptyShadeView); |
| 4134 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4135 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4136 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4140 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4141 | |
| 4142 | int oldTextRes = mEmptyShadeView.getTextResource(); |
| 4143 | int newTextRes = mStatusBar.areNotificationsHidden() |
| 4144 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4145 | if (oldTextRes != newTextRes) { |
| 4146 | mEmptyShadeView.setText(newTextRes); |
| 4147 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4148 | } |
| 4149 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4150 | public void updateFooterView(boolean visible, boolean showDismissView) { |
| 4151 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4152 | return; |
| 4153 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4154 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 4155 | mFooterView.setVisible(visible, animate); |
| 4156 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 4160 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4161 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4162 | handleDismissAllClipping(); |
| 4163 | } |
| 4164 | |
| 4165 | private void handleDismissAllClipping() { |
| 4166 | final int count = getChildCount(); |
| 4167 | boolean previousChildWillBeDismissed = false; |
| 4168 | for (int i = 0; i < count; i++) { |
| 4169 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4170 | if (child.getVisibility() == GONE) { |
| 4171 | continue; |
| 4172 | } |
| 4173 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 4174 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 4175 | } else { |
| 4176 | child.setMinClipTopAmount(0); |
| 4177 | } |
| 4178 | previousChildWillBeDismissed = canChildBeDismissed(child); |
| 4179 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4182 | public boolean isFooterViewNotGone() { |
| 4183 | return mFooterView != null |
| 4184 | && mFooterView.getVisibility() != View.GONE |
| 4185 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4186 | } |
| 4187 | |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 4188 | public boolean isFooterViewContentVisible() { |
| 4189 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4190 | } |
| 4191 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4192 | public int getFooterViewHeight() { |
| 4193 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4194 | } |
| 4195 | |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 4196 | public int getEmptyShadeViewHeight() { |
| 4197 | return mEmptyShadeView.getHeight(); |
| 4198 | } |
| 4199 | |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4200 | public float getBottomMostNotificationBottom() { |
| 4201 | final int count = getChildCount(); |
| 4202 | float max = 0; |
| 4203 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 4204 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 4205 | if (child.getVisibility() == GONE) { |
| 4206 | continue; |
| 4207 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4208 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 4209 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4210 | if (bottom > max) { |
| 4211 | max = bottom; |
| 4212 | } |
| 4213 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4214 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4215 | } |
| 4216 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4217 | public void setStatusBar(StatusBar statusBar) { |
| 4218 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 4219 | } |
| 4220 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4221 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 4222 | this.mGroupManager = groupManager; |
| 4223 | } |
| 4224 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4225 | public void onGoToKeyguard() { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4226 | requestAnimateEverything(); |
| 4227 | } |
| 4228 | |
| 4229 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4230 | if (mIsExpanded && mAnimationsEnabled) { |
| 4231 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4232 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4233 | requestChildrenUpdate(); |
| 4234 | } |
| 4235 | } |
| 4236 | |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4237 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4238 | int childCount = getChildCount(); |
| 4239 | for (int i = childCount - 1; i >= 0; i--) { |
| 4240 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4241 | if (child.getVisibility() != View.GONE) { |
| 4242 | float childTop = child.getY(); |
| 4243 | if (childTop > touchY) { |
| 4244 | // we are above a notification entirely let's abort |
| 4245 | return false; |
| 4246 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4247 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 4248 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4249 | if (child == mFooterView) { |
| 4250 | if(!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4251 | touchY - childTop)) { |
| 4252 | // We clicked on the dismiss button |
| 4253 | return false; |
| 4254 | } |
| 4255 | } else if (child == mEmptyShadeView) { |
| 4256 | // We arrived at the empty shade view, for which we accept all clicks |
| 4257 | return true; |
| 4258 | } else if (!belowChild){ |
| 4259 | // We are on a child |
| 4260 | return false; |
| 4261 | } |
| 4262 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4263 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4264 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4265 | } |
| 4266 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4267 | @Override |
| 4268 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 4269 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 4270 | && (mIsExpanded || changedRow.isPinned()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4271 | if (animated) { |
| 4272 | mExpandedGroupView = changedRow; |
| 4273 | mNeedsAnimation = true; |
| 4274 | } |
| 4275 | changedRow.setChildrenExpanded(expanded, animated); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 4276 | if (!mGroupExpandedForMeasure) { |
| 4277 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 4278 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 4279 | runAfterAnimationFinished(new Runnable() { |
| 4280 | @Override |
| 4281 | public void run() { |
| 4282 | changedRow.onFinishedExpansionChange(); |
| 4283 | } |
| 4284 | }); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4288 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4289 | mStatusBar.requestNotificationUpdate(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 4290 | } |
| 4291 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4292 | /** @hide */ |
| 4293 | @Override |
| 4294 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 4295 | super.onInitializeAccessibilityEventInternal(event); |
| 4296 | event.setScrollable(mScrollable); |
| 4297 | event.setScrollX(mScrollX); |
| 4298 | event.setScrollY(mOwnScrollY); |
| 4299 | event.setMaxScrollX(mScrollX); |
| 4300 | event.setMaxScrollY(getScrollRange()); |
| 4301 | } |
| 4302 | |
| 4303 | @Override |
| 4304 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 4305 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4306 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4307 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4308 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4309 | info.addAction( |
| 4310 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 4311 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 4312 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4313 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4314 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 4315 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 4316 | } |
| 4317 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 4318 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 4319 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | /** @hide */ |
| 4323 | @Override |
| 4324 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4325 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4326 | return true; |
| 4327 | } |
| 4328 | if (!isEnabled()) { |
| 4329 | return false; |
| 4330 | } |
| 4331 | int direction = -1; |
| 4332 | switch (action) { |
| 4333 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4334 | // fall through |
| 4335 | case android.R.id.accessibilityActionScrollDown: |
| 4336 | direction = 1; |
| 4337 | // fall through |
| 4338 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4339 | // fall through |
| 4340 | case android.R.id.accessibilityActionScrollUp: |
| 4341 | final int viewportHeight = getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 4342 | - mShelf.getIntrinsicHeight(); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4343 | final int targetScrollY = Math.max(0, |
| 4344 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4345 | if (targetScrollY != mOwnScrollY) { |
| 4346 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScrollY - mOwnScrollY); |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 4347 | animateScroll(); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4348 | return true; |
| 4349 | } |
| 4350 | break; |
| 4351 | } |
| 4352 | return false; |
| 4353 | } |
| 4354 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 4355 | @Override |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 4356 | public void onGroupsChanged() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4357 | mStatusBar.requestNotificationUpdate(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | public void generateChildOrderChangedEvent() { |
| 4361 | if (mIsExpanded && mAnimationsEnabled) { |
| 4362 | mGenerateChildOrderChangedEvent = true; |
| 4363 | mNeedsAnimation = true; |
| 4364 | requestChildrenUpdate(); |
| 4365 | } |
| 4366 | } |
| 4367 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4368 | @Override |
| 4369 | public int getContainerChildCount() { |
| 4370 | return getChildCount(); |
| 4371 | } |
| 4372 | |
| 4373 | @Override |
| 4374 | public View getContainerChildAt(int i) { |
| 4375 | return getChildAt(i); |
| 4376 | } |
| 4377 | |
| 4378 | @Override |
| 4379 | public void removeContainerView(View v) { |
| 4380 | removeView(v); |
| 4381 | } |
| 4382 | |
| 4383 | @Override |
| 4384 | public void addContainerView(View v) { |
| 4385 | addView(v); |
| 4386 | } |
| 4387 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 4388 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4389 | mAnimationFinishedRunnables.add(runnable); |
| 4390 | } |
| 4391 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 4392 | public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4393 | mHeadsUpManager = headsUpManager; |
| 4394 | mAmbientState.setHeadsUpManager(headsUpManager); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 4395 | mHeadsUpManager.addListener(mRoundnessManager); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 4399 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4400 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 4401 | mNeedsAnimation = true; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 4402 | if (!mIsExpanded && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4403 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 4404 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4405 | requestChildrenUpdate(); |
| 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | public void setShadeExpanded(boolean shadeExpanded) { |
| 4410 | mAmbientState.setShadeExpanded(shadeExpanded); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 4411 | mStateAnimator.setShadeExpanded(shadeExpanded); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4412 | } |
| 4413 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 4414 | /** |
| 4415 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 4416 | * position. |
| 4417 | * |
| 4418 | * @param height the height of the screen |
| 4419 | * @param bottomBarHeight the height of the bar on the bottom |
| 4420 | */ |
| 4421 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 4422 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 4423 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4424 | requestChildrenUpdate(); |
| 4425 | } |
| 4426 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 4427 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 4428 | mTrackingHeadsUp = row != null; |
| 4429 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4430 | } |
| 4431 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 4432 | public void setScrimController(ScrimController scrimController) { |
| 4433 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 4434 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 4437 | public void forceNoOverlappingRendering(boolean force) { |
| 4438 | mForceNoOverlappingRendering = force; |
| 4439 | } |
| 4440 | |
| 4441 | @Override |
| 4442 | public boolean hasOverlappingRendering() { |
| 4443 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 4444 | } |
| 4445 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4446 | public void setAnimationRunning(boolean animationRunning) { |
| 4447 | if (animationRunning != mAnimationRunning) { |
| 4448 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 4449 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4450 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 4451 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4452 | } |
| 4453 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4454 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4455 | } |
| 4456 | } |
| 4457 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 4458 | public boolean isExpanded() { |
| 4459 | return mIsExpanded; |
| 4460 | } |
| 4461 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 4462 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 4463 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 4464 | return; |
| 4465 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 4466 | mPulsing = pulsing; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 4467 | mNeedingPulseAnimation = animated ? getFirstChildNotGone() : null; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 4468 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 4469 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 4470 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4471 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4472 | requestChildrenUpdate(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 4473 | notifyHeightChangeListener(null, animated); |
| 4474 | mNeedsAnimation |= animated; |
| 4475 | } |
| 4476 | |
| 4477 | private void generatePulsingAnimationEvent() { |
| 4478 | if (mNeedingPulseAnimation != null) { |
| 4479 | int type = mPulsing ? AnimationEvent.ANIMATION_TYPE_PULSE_APPEAR |
| 4480 | : AnimationEvent.ANIMATION_TYPE_PULSE_DISAPPEAR; |
| 4481 | mAnimationEvents.add(new AnimationEvent(mNeedingPulseAnimation, type)); |
| 4482 | mNeedingPulseAnimation = null; |
| 4483 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4486 | public void setFadingOut(boolean fadingOut) { |
| 4487 | if (fadingOut != mFadingOut) { |
| 4488 | mFadingOut = fadingOut; |
| 4489 | updateFadingState(); |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 4490 | } |
| 4491 | } |
| 4492 | |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 4493 | public void setParentNotFullyVisible(boolean parentNotFullyVisible) { |
| 4494 | if (mScrimController == null) { |
| 4495 | // we're not set up yet. |
| 4496 | return; |
| 4497 | } |
| 4498 | if (parentNotFullyVisible != mParentNotFullyVisible) { |
| 4499 | mParentNotFullyVisible = parentNotFullyVisible; |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4500 | updateFadingState(); |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | private void updateFadingState() { |
Selim Cinek | 9bfba9c | 2016-08-08 15:20:06 -0700 | [diff] [blame] | 4505 | applyCurrentBackgroundBounds(); |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4506 | updateSrcDrawing(); |
| 4507 | } |
| 4508 | |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 4509 | @Override |
| 4510 | public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) { |
| 4511 | super.setAlpha(alpha); |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4512 | setFadingOut(alpha != 1.0f); |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 4513 | } |
| 4514 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4515 | public void setQsExpanded(boolean qsExpanded) { |
| 4516 | mQsExpanded = qsExpanded; |
| 4517 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 4518 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4519 | } |
| 4520 | |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4521 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 4522 | mQsExpansionFraction = qsExpansionFraction; |
| 4523 | } |
| 4524 | |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4525 | public void setOwnScrollY(int ownScrollY) { |
| 4526 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 4527 | // We still want to call the normal scrolled changed for accessibility reasons |
| 4528 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4529 | mOwnScrollY = ownScrollY; |
| 4530 | updateForwardAndBackwardScrollability(); |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 4531 | requestChildrenUpdate(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4535 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4536 | int index = -1; |
| 4537 | if (mShelf != null) { |
| 4538 | index = indexOfChild(mShelf); |
| 4539 | removeView(mShelf); |
| 4540 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 4541 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4542 | addView(mShelf, index); |
| 4543 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 4544 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 4545 | shelf.bind(mAmbientState, this); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | public NotificationShelf getNotificationShelf() { |
| 4549 | return mShelf; |
| 4550 | } |
| 4551 | |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 4552 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 4553 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 4554 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 4555 | updateContentHeight(); |
| 4556 | notifyHeightChangeListener(mShelf); |
| 4557 | } |
| 4558 | } |
| 4559 | |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4560 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
| 4561 | mShouldShowShelfOnly = shouldShowShelfOnly; |
| 4562 | updateAlgorithmLayoutMinHeight(); |
| 4563 | } |
| 4564 | |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 4565 | public int getMinExpansionHeight() { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 4566 | return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 4567 | } |
| 4568 | |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4569 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 4570 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 4571 | updateClipping(); |
| 4572 | } |
| 4573 | |
| 4574 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 4575 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 4576 | updateClipping(); |
| 4577 | } |
| 4578 | |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 4579 | public void setStatusBarState(int statusBarState) { |
| 4580 | mStatusBarState = statusBarState; |
| 4581 | mAmbientState.setStatusBarState(statusBarState); |
| 4582 | } |
| 4583 | |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4584 | public void setExpandingVelocity(float expandingVelocity) { |
| 4585 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 4586 | } |
| 4587 | |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 4588 | public float getOpeningHeight() { |
| 4589 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 4590 | return getMinExpansionHeight(); |
| 4591 | } else { |
| 4592 | return getAppearEndPosition(); |
| 4593 | } |
| 4594 | } |
| 4595 | |
| 4596 | public void setIsFullWidth(boolean isFullWidth) { |
| 4597 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 4598 | } |
| 4599 | |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 4600 | public void setUnlockHintRunning(boolean running) { |
| 4601 | mAmbientState.setUnlockHintRunning(running); |
| 4602 | } |
| 4603 | |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 4604 | public void setQsCustomizerShowing(boolean isShowing) { |
| 4605 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 4606 | requestChildrenUpdate(); |
| 4607 | } |
| 4608 | |
| 4609 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 4610 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 4611 | } |
| 4612 | |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 4613 | public void setAntiBurnInOffsetX(int antiBurnInOffsetX) { |
| 4614 | mAntiBurnInOffsetX = antiBurnInOffsetX; |
Bill Lin | e60aa1e | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4615 | updatePanelTranslation(); |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 4616 | } |
| 4617 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4618 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 4619 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4620 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 4621 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4622 | this.getClass().getSimpleName(), |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 4623 | mPulsing ? "T":"f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4624 | mAmbientState.isQsCustomizerShowing() ? "T":"f", |
| 4625 | getVisibility() == View.VISIBLE ? "visible" |
| 4626 | : getVisibility() == View.GONE ? "gone" |
| 4627 | : "invisible", |
| 4628 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4629 | mAmbientState.getScrollY(), |
| 4630 | mMaxTopPadding, |
| 4631 | mShouldShowShelfOnly ? "T":"f", |
| 4632 | mQsExpansionFraction)); |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4633 | } |
| 4634 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4635 | public boolean isFullyDark() { |
| 4636 | return mAmbientState.isFullyDark(); |
| 4637 | } |
| 4638 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 4639 | /** |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 4640 | * Add a listener whenever the expanded height changes. The first value passed as an argument |
| 4641 | * is the expanded height and the second one is the appearFraction. |
| 4642 | * |
| 4643 | * @param listener the listener to notify. |
| 4644 | */ |
| 4645 | public void addOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 4646 | mExpandedHeightListeners.add(listener); |
| 4647 | } |
| 4648 | |
| 4649 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 4650 | * Stop a listener from listening to the expandedHeight. |
| 4651 | */ |
| 4652 | public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 4653 | mExpandedHeightListeners.remove(listener); |
| 4654 | } |
| 4655 | |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 4656 | public void setHeadsUpAppearanceController( |
| 4657 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 4658 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 4659 | } |
| 4660 | |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4661 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 4662 | mIconAreaController = controller; |
| 4663 | } |
| 4664 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 4665 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4666 | * A listener that is notified when the empty space below the notifications is clicked on |
| 4667 | */ |
| 4668 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4669 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 4673 | * A listener that gets notified when the overscroll at the top has changed. |
| 4674 | */ |
| 4675 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 4676 | |
| 4677 | /** |
| 4678 | * Notifies a listener that the overscroll has changed. |
| 4679 | * |
| 4680 | * @param amount the amount of overscroll, in pixels |
| 4681 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 4682 | * unrubberbanded motion to directly expand overscroll view (e.g expand |
| 4683 | * QS) |
| 4684 | */ |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4685 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4686 | |
| 4687 | /** |
| 4688 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 4689 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 4690 | * |
| 4691 | * @param velocity The velocity that the Scroller had when over flinging |
| 4692 | * @param open Should the fling open or close the overscroll view. |
| 4693 | */ |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4694 | void flingTopOverscroll(float velocity, boolean open); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 4695 | } |
| 4696 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4697 | private class NotificationSwipeHelper extends SwipeHelper |
| 4698 | implements NotificationSwipeActionHelper { |
| 4699 | private static final long COVER_MENU_DELAY = 4000; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4700 | private Runnable mFalsingCheck; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4701 | private Handler mHandler; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4702 | |
| 4703 | public NotificationSwipeHelper(int swipeDirection, Callback callback, Context context) { |
| 4704 | super(swipeDirection, callback, context); |
| 4705 | mHandler = new Handler(); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4706 | mFalsingCheck = new Runnable() { |
| 4707 | @Override |
| 4708 | public void run() { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4709 | resetExposedMenuView(true /* animate */, true /* force */); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4710 | } |
| 4711 | }; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4715 | public void onDownUpdate(View currView, MotionEvent ev) { |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4716 | mTranslatingParentView = currView; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4717 | if (mCurrMenuRow != null) { |
| 4718 | mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */); |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4719 | } |
Mady Mellor | 89e15ec | 2017-06-28 17:08:21 -0700 | [diff] [blame] | 4720 | mCurrMenuRow = null; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4721 | mHandler.removeCallbacks(mFalsingCheck); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4722 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4723 | // Slide back any notifications that might be showing a menu |
| 4724 | resetExposedMenuView(true /* animate */, false /* force */); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4725 | |
| 4726 | if (currView instanceof ExpandableNotificationRow) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4727 | ExpandableNotificationRow row = (ExpandableNotificationRow) currView; |
Aaron Heuckroth | 1dd67cb | 2018-06-14 14:28:08 -0400 | [diff] [blame] | 4728 | |
| 4729 | if (row.getEntry().hasFinishedInitialization()) { |
| 4730 | mCurrMenuRow = row.createMenu(); |
| 4731 | mCurrMenuRow.setSwipeActionHelper(NotificationSwipeHelper.this); |
| 4732 | mCurrMenuRow.setMenuClickListener(NotificationStackScrollLayout.this); |
| 4733 | mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */); |
| 4734 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4735 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4739 | public void onMoveUpdate(View view, MotionEvent ev, float translation, float delta) { |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4740 | mHandler.removeCallbacks(mFalsingCheck); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4741 | if (mCurrMenuRow != null) { |
| 4742 | mCurrMenuRow.onTouchEvent(view, ev, 0 /* velocity */); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4743 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4744 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4745 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4746 | @Override |
| 4747 | public boolean handleUpEvent(MotionEvent ev, View animView, float velocity, |
| 4748 | float translation) { |
| 4749 | if (mCurrMenuRow != null) { |
| 4750 | return mCurrMenuRow.onTouchEvent(animView, ev, velocity); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4751 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4752 | return false; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | @Override |
Mady Mellor | dc6c97d | 2016-03-31 14:18:35 -0700 | [diff] [blame] | 4756 | public void dismissChild(final View view, float velocity, |
| 4757 | boolean useAccelerateInterpolator) { |
| 4758 | super.dismissChild(view, velocity, useAccelerateInterpolator); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4759 | if (mIsExpanded) { |
| 4760 | // We don't want to quick-dismiss when it's a heads up as this might lead to closing |
| 4761 | // of the panel early. |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 4762 | handleChildViewDismissed(view); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4763 | } |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4764 | mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */, |
| 4765 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4766 | false /* resetMenu */); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4767 | handleMenuCoveredOrDismissed(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | @Override |
| 4771 | public void snapChild(final View animView, final float targetLeft, float velocity) { |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4772 | super.snapChild(animView, targetLeft, velocity); |
| 4773 | onDragCancelled(animView); |
| 4774 | if (targetLeft == 0) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4775 | handleMenuCoveredOrDismissed(); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4776 | } |
| 4777 | } |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4778 | |
| 4779 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4780 | public void snooze(StatusBarNotification sbn, SnoozeOption snoozeOption) { |
| 4781 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
Mady Mellor | bd70749 | 2017-05-10 17:51:25 -0700 | [diff] [blame] | 4784 | public boolean isFalseGesture(MotionEvent ev) { |
| 4785 | return super.isFalseGesture(ev); |
| 4786 | } |
| 4787 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4788 | private void handleMenuCoveredOrDismissed() { |
| 4789 | if (mMenuExposedView != null && mMenuExposedView == mTranslatingParentView) { |
| 4790 | mMenuExposedView = null; |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4791 | } |
| 4792 | } |
| 4793 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4794 | @Override |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4795 | public Animator getViewTranslationAnimator(View v, float target, |
| 4796 | AnimatorUpdateListener listener) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 4797 | if (v instanceof ExpandableNotificationRow) { |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 4798 | return ((ExpandableNotificationRow) v).getTranslateViewAnimator(target, listener); |
| 4799 | } else { |
| 4800 | return super.getViewTranslationAnimator(v, target, listener); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4801 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | @Override |
| 4805 | public void setTranslation(View v, float translate) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 4806 | ((ExpandableView) v).setTranslation(translate); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | @Override |
| 4810 | public float getTranslation(View v) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 4811 | return ((ExpandableView) v).getTranslation(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4812 | } |
| 4813 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4814 | @Override |
| 4815 | public void dismiss(View animView, float velocity) { |
| 4816 | dismissChild(animView, velocity, |
| 4817 | !swipedFastEnough(0, 0) /* useAccelerateInterpolator */); |
| 4818 | } |
| 4819 | |
| 4820 | @Override |
| 4821 | public void snap(View animView, float targetLeft, float velocity) { |
| 4822 | snapChild(animView, targetLeft, velocity); |
| 4823 | } |
| 4824 | |
| 4825 | @Override |
| 4826 | public boolean swipedFarEnough(float translation, float viewSize) { |
| 4827 | return swipedFarEnough(); |
| 4828 | } |
| 4829 | |
| 4830 | @Override |
| 4831 | public boolean swipedFastEnough(float translation, float velocity) { |
| 4832 | return swipedFastEnough(); |
| 4833 | } |
| 4834 | |
| 4835 | @Override |
| 4836 | public float getMinDismissVelocity() { |
| 4837 | return getEscapeVelocity(); |
| 4838 | } |
| 4839 | |
| 4840 | public void onMenuShown(View animView) { |
| 4841 | onDragCancelled(animView); |
| 4842 | |
| 4843 | // If we're on the lockscreen we want to false this. |
| 4844 | if (isAntiFalsingNeeded()) { |
| 4845 | mHandler.removeCallbacks(mFalsingCheck); |
| 4846 | mHandler.postDelayed(mFalsingCheck, COVER_MENU_DELAY); |
| 4847 | } |
| 4848 | } |
| 4849 | |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4850 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4851 | NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts(); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4852 | View view = null; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4853 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4854 | // Only close visible guts if they're not a leavebehind. |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4855 | view = guts; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4856 | } else if (mCurrMenuRow != null && mCurrMenuRow.isMenuVisible() |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4857 | && mTranslatingParentView != null) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4858 | // Checking menu |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4859 | view = mTranslatingParentView; |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4860 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4861 | if (view != null && !isTouchInView(ev, view)) { |
| 4862 | // Touch was outside visible guts / menu notification, close what's visible |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4863 | mStatusBar.getGutsManager().closeAndSaveGuts(false /* removeLeavebehind */, |
| 4864 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4865 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4866 | resetExposedMenuView(true /* animate */, true /* force */); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4867 | } |
| 4868 | } |
| 4869 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4870 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 4871 | if (mMenuExposedView == null |
| 4872 | || (!force && mMenuExposedView == mTranslatingParentView)) { |
| 4873 | // If no menu is showing or it's showing for this view we do nothing. |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4874 | return; |
| 4875 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4876 | final View prevMenuExposedView = mMenuExposedView; |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4877 | if (animate) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4878 | Animator anim = getViewTranslationAnimator(prevMenuExposedView, |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4879 | 0 /* leftTarget */, null /* updateListener */); |
| 4880 | if (anim != null) { |
| 4881 | anim.start(); |
| 4882 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4883 | } else if (mMenuExposedView instanceof ExpandableNotificationRow) { |
Selim Cinek | b2e0f33 | 2017-08-18 12:24:38 -0700 | [diff] [blame] | 4884 | ExpandableNotificationRow row = (ExpandableNotificationRow) mMenuExposedView; |
| 4885 | if (!row.isRemoved()) { |
| 4886 | row.resetTranslation(); |
| 4887 | } |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4888 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4889 | mMenuExposedView = null; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4890 | } |
| 4891 | } |
| 4892 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4893 | private boolean isTouchInView(MotionEvent ev, View view) { |
| 4894 | if (view == null) { |
| 4895 | return false; |
| 4896 | } |
| 4897 | final int height = (view instanceof ExpandableView) |
| 4898 | ? ((ExpandableView) view).getActualHeight() |
| 4899 | : view.getHeight(); |
| 4900 | final int rx = (int) ev.getRawX(); |
| 4901 | final int ry = (int) ev.getRawY(); |
| 4902 | view.getLocationOnScreen(mTempInt2); |
| 4903 | final int x = mTempInt2[0]; |
| 4904 | final int y = mTempInt2[1]; |
| 4905 | Rect rect = new Rect(x, y, x + view.getWidth(), y + height); |
| 4906 | boolean ret = rect.contains(rx, ry); |
| 4907 | return ret; |
| 4908 | } |
| 4909 | |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4910 | private void updateContinuousShadowDrawing() { |
| 4911 | boolean continuousShadowUpdate = mAnimationRunning |
| 4912 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 4913 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 4914 | if (continuousShadowUpdate) { |
| 4915 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 4916 | } else { |
| 4917 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 4918 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 4919 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4920 | } |
| 4921 | } |
| 4922 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4923 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4924 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 4925 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4929 | mSwipeHelper.closeControlsIfOutsideTouch(ev); |
| 4930 | } |
| 4931 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 4932 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4933 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4934 | static AnimationFilter[] FILTERS = new AnimationFilter[] { |
| 4935 | |
| 4936 | // ANIMATION_TYPE_ADD |
| 4937 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4938 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4939 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4940 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4941 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4942 | .animateZ() |
| 4943 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4944 | |
| 4945 | // ANIMATION_TYPE_REMOVE |
| 4946 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4947 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4948 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4949 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4950 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4951 | .animateZ() |
| 4952 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4953 | |
| 4954 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 4955 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4956 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4957 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4958 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4959 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4960 | .animateZ() |
| 4961 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4962 | |
| 4963 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 4964 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4965 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4966 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4967 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4968 | .animateY() |
| 4969 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4970 | .animateZ(), |
| 4971 | |
| 4972 | // ANIMATION_TYPE_START_DRAG |
| 4973 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4974 | .animateShadowAlpha(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4975 | |
| 4976 | // ANIMATION_TYPE_SNAP_BACK |
| 4977 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4978 | .animateShadowAlpha() |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4979 | .animateHeight(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4980 | |
| 4981 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 4982 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4983 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4984 | |
| 4985 | // ANIMATION_TYPE_DIMMED |
| 4986 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4987 | .animateDimmed(), |
| 4988 | |
| 4989 | // ANIMATION_TYPE_CHANGE_POSITION |
| 4990 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4991 | .animateAlpha() // maybe the children change positions |
| 4992 | .animateShadowAlpha() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4993 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4994 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4995 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4996 | .animateZ(), |
| 4997 | |
| 4998 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 4999 | null, // Unused |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5000 | |
| 5001 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5002 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5003 | .animateShadowAlpha() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5004 | .animateHeight() |
| 5005 | .animateTopInset() |
| 5006 | .animateY() |
| 5007 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5008 | .animateZ() |
| 5009 | .hasDelays(), |
| 5010 | |
| 5011 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5012 | new AnimationFilter() |
| 5013 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5014 | |
| 5015 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5016 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5017 | .animateShadowAlpha() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5018 | .animateHeight() |
| 5019 | .animateTopInset() |
| 5020 | .animateY() |
| 5021 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5022 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5023 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 5024 | new AnimationFilter() |
| 5025 | .animateAlpha() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5026 | .animateShadowAlpha() |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5027 | .animateHeight() |
| 5028 | .animateTopInset() |
| 5029 | .animateY() |
| 5030 | .animateZ(), |
| 5031 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5032 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5033 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5034 | .animateShadowAlpha() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5035 | .animateHeight() |
| 5036 | .animateTopInset() |
| 5037 | .animateY() |
| 5038 | .animateZ(), |
| 5039 | |
| 5040 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5041 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5042 | .animateShadowAlpha() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5043 | .animateHeight() |
| 5044 | .animateTopInset() |
| 5045 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 5046 | .animateZ() |
| 5047 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5048 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5049 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5050 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5051 | .animateShadowAlpha() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5052 | .animateHeight() |
| 5053 | .animateTopInset() |
| 5054 | .animateY() |
| 5055 | .animateZ() |
| 5056 | .hasDelays(), |
| 5057 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5058 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5059 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5060 | .animateShadowAlpha() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5061 | .animateHeight() |
| 5062 | .animateTopInset() |
| 5063 | .animateY() |
| 5064 | .animateZ(), |
| 5065 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5066 | // ANIMATION_TYPE_EVERYTHING |
| 5067 | new AnimationFilter() |
| 5068 | .animateAlpha() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5069 | .animateShadowAlpha() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5070 | .animateDark() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5071 | .animateDimmed() |
| 5072 | .animateHideSensitive() |
| 5073 | .animateHeight() |
| 5074 | .animateTopInset() |
| 5075 | .animateY() |
| 5076 | .animateZ(), |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5077 | |
| 5078 | // ANIMATION_TYPE_PULSE_APPEAR |
| 5079 | new AnimationFilter() |
| 5080 | .animateAlpha() |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5081 | .hasDelays() |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5082 | .animateY(), |
| 5083 | |
| 5084 | // ANIMATION_TYPE_PULSE_DISAPPEAR |
| 5085 | new AnimationFilter() |
| 5086 | .animateAlpha() |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5087 | .hasDelays() |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5088 | .animateY(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5089 | }; |
| 5090 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5091 | static int[] LENGTHS = new int[] { |
| 5092 | |
| 5093 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5094 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5095 | |
| 5096 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5097 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5098 | |
| 5099 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5100 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5101 | |
| 5102 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5103 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5104 | |
| 5105 | // ANIMATION_TYPE_START_DRAG |
| 5106 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5107 | |
| 5108 | // ANIMATION_TYPE_SNAP_BACK |
| 5109 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5110 | |
| 5111 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5112 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 5113 | |
| 5114 | // ANIMATION_TYPE_DIMMED |
| 5115 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5116 | |
| 5117 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5118 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5119 | |
| 5120 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5121 | StackStateAnimator.ANIMATION_DURATION_WAKEUP, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5122 | |
| 5123 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5124 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5125 | |
| 5126 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5127 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5128 | |
| 5129 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5130 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5131 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5132 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 5133 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5134 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5135 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5136 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 5137 | |
| 5138 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5139 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 5140 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5141 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5142 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 5143 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5144 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5145 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5146 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5147 | // ANIMATION_TYPE_EVERYTHING |
| 5148 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5149 | |
| 5150 | // ANIMATION_TYPE_PULSE_APPEAR |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5151 | StackStateAnimator.ANIMATION_DURATION_PULSE_APPEAR, |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5152 | |
| 5153 | // ANIMATION_TYPE_PULSE_DISAPPEAR |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5154 | StackStateAnimator.ANIMATION_DURATION_PULSE_APPEAR / 2, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5155 | }; |
| 5156 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5157 | static final int ANIMATION_TYPE_ADD = 0; |
| 5158 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 5159 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 5160 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
| 5161 | static final int ANIMATION_TYPE_START_DRAG = 4; |
| 5162 | static final int ANIMATION_TYPE_SNAP_BACK = 5; |
| 5163 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 6; |
| 5164 | static final int ANIMATION_TYPE_DIMMED = 7; |
| 5165 | static final int ANIMATION_TYPE_CHANGE_POSITION = 8; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5166 | static final int ANIMATION_TYPE_DARK = 9; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5167 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 10; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5168 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 11; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5169 | static final int ANIMATION_TYPE_VIEW_RESIZE = 12; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5170 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 13; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5171 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 14; |
| 5172 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 15; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5173 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 16; |
| 5174 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 17; |
| 5175 | static final int ANIMATION_TYPE_EVERYTHING = 18; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5176 | static final int ANIMATION_TYPE_PULSE_APPEAR = 19; |
| 5177 | static final int ANIMATION_TYPE_PULSE_DISAPPEAR = 20; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 5178 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 5179 | static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1; |
| 5180 | static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2; |
| 5181 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5182 | final long eventStartTime; |
| 5183 | final View changingView; |
| 5184 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5185 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5186 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5187 | View viewAfterChangingView; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 5188 | int darkAnimationOriginIndex; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5189 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5190 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 5191 | AnimationEvent(View view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 5192 | this(view, type, LENGTHS[type]); |
| 5193 | } |
| 5194 | |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5195 | AnimationEvent(View view, int type, AnimationFilter filter) { |
| 5196 | this(view, type, LENGTHS[type], filter); |
| 5197 | } |
| 5198 | |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 5199 | AnimationEvent(View view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5200 | this(view, type, length, FILTERS[type]); |
| 5201 | } |
| 5202 | |
| 5203 | AnimationEvent(View view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5204 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
| 5205 | changingView = view; |
| 5206 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 5207 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5208 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | /** |
| 5212 | * Combines the length of several animation events into a single value. |
| 5213 | * |
| 5214 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5215 | * @return The combined length. Depending on the event types, this might be the maximum of |
| 5216 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5217 | */ |
| 5218 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 5219 | long length = 0; |
| 5220 | int size = events.size(); |
| 5221 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5222 | AnimationEvent event = events.get(i); |
| 5223 | length = Math.max(length, event.length); |
| 5224 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 5225 | return event.length; |
| 5226 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5227 | } |
| 5228 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5229 | } |
| 5230 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 5231 | } |