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