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