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