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 | a14377a | 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 | cb2b6737 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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 | aa9db1f3 | 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() + |
| 1424 | getImeInset() - getHeight() + getTopPadding(); |
| 1425 | } |
| 1426 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1427 | @Override |
| 1428 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 1429 | mBottomInset = insets.getSystemWindowInsetBottom(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1430 | |
| 1431 | int range = getScrollRange(); |
| 1432 | if (mOwnScrollY > range) { |
| 1433 | // HACK: We're repeatedly getting staggered insets here while the IME is |
| 1434 | // animating away. To work around that we'll wait until things have settled. |
| 1435 | removeCallbacks(mReclamp); |
| 1436 | postDelayed(mReclamp, 50); |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1437 | } else if (mForcedScroll != null) { |
| 1438 | // The scroll was requested before we got the actual inset - in case we need |
| 1439 | // to scroll up some more do so now. |
| 1440 | scrollTo(mForcedScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1441 | } |
| 1442 | return insets; |
| 1443 | } |
| 1444 | |
| 1445 | private Runnable mReclamp = new Runnable() { |
| 1446 | @Override |
| 1447 | public void run() { |
| 1448 | int range = getScrollRange(); |
| 1449 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY); |
| 1450 | mDontReportNextOverScroll = true; |
| 1451 | mDontClampNextScroll = true; |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1452 | animateScroll(); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1453 | } |
| 1454 | }; |
| 1455 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1456 | public void setExpandingEnabled(boolean enable) { |
| 1457 | mExpandHelper.setEnabled(enable); |
| 1458 | } |
| 1459 | |
| 1460 | private boolean isScrollingEnabled() { |
| 1461 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1462 | } |
| 1463 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1464 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1465 | public boolean canChildBeDismissed(View v) { |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 1466 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1469 | @Override |
| 1470 | public boolean isAntiFalsingNeeded() { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 1471 | return onKeyguard(); |
| 1472 | } |
| 1473 | |
| 1474 | private boolean onKeyguard() { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 1475 | return mStatusBarState == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 1476 | } |
| 1477 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1478 | private void setSwipingInProgress(boolean isSwiped) { |
| 1479 | mSwipingInProgress = isSwiped; |
| 1480 | if(isSwiped) { |
| 1481 | requestDisallowInterceptTouchEvent(true); |
| 1482 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | @Override |
| 1486 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1487 | super.onConfigurationChanged(newConfig); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 1488 | mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1489 | float densityScale = getResources().getDisplayMetrics().density; |
| 1490 | mSwipeHelper.setDensityScale(densityScale); |
| 1491 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 1492 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 1493 | initView(getContext()); |
| 1494 | } |
| 1495 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1496 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 1497 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration, |
| 1498 | true /* isDismissAll */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1501 | @Override |
Mady Mellor | 86889c2 | 2016-04-18 16:37:06 -0700 | [diff] [blame] | 1502 | public void snapViewIfNeeded(ExpandableNotificationRow child) { |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1503 | boolean animate = mIsExpanded || isPinnedHeadsUp(child); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1504 | // If the child is showing the notification menu snap to that |
| 1505 | float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0; |
Mady Mellor | 86889c2 | 2016-04-18 16:37:06 -0700 | [diff] [blame] | 1506 | mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft); |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 1507 | } |
| 1508 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1509 | @Override |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1510 | public ViewGroup getViewParentForNotification(NotificationData.Entry entry) { |
| 1511 | return this; |
| 1512 | } |
| 1513 | |
| 1514 | @Override |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1515 | public boolean onTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1516 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 1517 | || ev.getActionMasked()== MotionEvent.ACTION_UP; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1518 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1519 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 1520 | if (mIsExpanded && !mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1521 | if (isCancelOrUp) { |
| 1522 | mExpandHelper.onlyObserveMovements(false); |
| 1523 | } |
| 1524 | boolean wasExpandingBefore = mExpandingNotification; |
| 1525 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1526 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 1527 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1528 | dispatchDownEventToScroller(ev); |
| 1529 | } |
| 1530 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1531 | boolean scrollerWantsIt = false; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1532 | if (mIsExpanded && !mSwipingInProgress && !mExpandingNotification |
| 1533 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1534 | scrollerWantsIt = onScrollTouch(ev); |
| 1535 | } |
| 1536 | boolean horizontalSwipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1537 | if (!mIsBeingDragged |
| 1538 | && !mExpandingNotification |
| 1539 | && !mExpandedInThisMotion |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 1540 | && !mOnlyScrollingInThisMotion |
| 1541 | && !mDisallowDismissInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1542 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 1543 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1544 | |
| 1545 | // Check if we need to clear any snooze leavebehinds |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 1546 | NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1547 | if (guts != null && !isTouchInView(ev, guts) |
| 1548 | && guts.getGutsContent() instanceof NotificationSnooze) { |
| 1549 | NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent(); |
| 1550 | if ((ns.isExpanded() && isCancelOrUp) |
| 1551 | || (!horizontalSwipeWantsIt && scrollerWantsIt)) { |
| 1552 | // If the leavebehind is expanded we clear it on the next up event, otherwise we |
| 1553 | // clear it on the next non-horizontal swipe or expand event. |
| 1554 | checkSnoozeLeavebehind(); |
| 1555 | } |
| 1556 | } |
| 1557 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 1558 | mCheckForLeavebehind = true; |
| 1559 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1560 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 1561 | } |
| 1562 | |
| 1563 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 1564 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 1565 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 1566 | onScrollTouch(downEvent); |
| 1567 | downEvent.recycle(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1568 | } |
| 1569 | |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 1570 | @Override |
| 1571 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 1572 | if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification |
| 1573 | || mDisallowScrollingInThisMotion) { |
| 1574 | return false; |
| 1575 | } |
| 1576 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 1577 | switch (event.getAction()) { |
| 1578 | case MotionEvent.ACTION_SCROLL: { |
| 1579 | if (!mIsBeingDragged) { |
| 1580 | final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 1581 | if (vscroll != 0) { |
| 1582 | final int delta = (int) (vscroll * getVerticalScrollFactor()); |
| 1583 | final int range = getScrollRange(); |
| 1584 | int oldScrollY = mOwnScrollY; |
| 1585 | int newScrollY = oldScrollY - delta; |
| 1586 | if (newScrollY < 0) { |
| 1587 | newScrollY = 0; |
| 1588 | } else if (newScrollY > range) { |
| 1589 | newScrollY = range; |
| 1590 | } |
| 1591 | if (newScrollY != oldScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1592 | setOwnScrollY(newScrollY); |
Selim Cinek | 11e3323 | 2016-08-05 15:30:53 -0700 | [diff] [blame] | 1593 | return true; |
| 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | return super.onGenericMotionEvent(event); |
| 1601 | } |
| 1602 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1603 | private boolean onScrollTouch(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1604 | if (!isScrollingEnabled()) { |
| 1605 | return false; |
| 1606 | } |
Adrian Roos | feb9725 | 2016-09-29 17:05:58 -0700 | [diff] [blame] | 1607 | if (isInsideQsContainer(ev) && !mIsBeingDragged) { |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 1608 | return false; |
| 1609 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 1610 | mForcedScroll = null; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1611 | initVelocityTrackerIfNotExists(); |
| 1612 | mVelocityTracker.addMovement(ev); |
| 1613 | |
| 1614 | final int action = ev.getAction(); |
| 1615 | |
| 1616 | switch (action & MotionEvent.ACTION_MASK) { |
| 1617 | case MotionEvent.ACTION_DOWN: { |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 1618 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | boolean isBeingDragged = !mScroller.isFinished(); |
| 1622 | setIsBeingDragged(isBeingDragged); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1623 | /* |
| 1624 | * If being flinged and user touches, stop the fling. isFinished |
| 1625 | * will be false if being flinged. |
| 1626 | */ |
| 1627 | if (!mScroller.isFinished()) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1628 | mScroller.forceFinished(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | // Remember where the motion event started |
| 1632 | mLastMotionY = (int) ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1633 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1634 | mActivePointerId = ev.getPointerId(0); |
| 1635 | break; |
| 1636 | } |
| 1637 | case MotionEvent.ACTION_MOVE: |
| 1638 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 1639 | if (activePointerIndex == -1) { |
| 1640 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 1641 | break; |
| 1642 | } |
| 1643 | |
| 1644 | final int y = (int) ev.getY(activePointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1645 | final int x = (int) ev.getX(activePointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1646 | int deltaY = mLastMotionY - y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1647 | final int xDiff = Math.abs(x - mDownX); |
| 1648 | final int yDiff = Math.abs(deltaY); |
| 1649 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1650 | setIsBeingDragged(true); |
| 1651 | if (deltaY > 0) { |
| 1652 | deltaY -= mTouchSlop; |
| 1653 | } else { |
| 1654 | deltaY += mTouchSlop; |
| 1655 | } |
| 1656 | } |
| 1657 | if (mIsBeingDragged) { |
| 1658 | // Scroll to follow the motion event |
| 1659 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1660 | int range = getScrollRange(); |
| 1661 | if (mExpandedInThisMotion) { |
| 1662 | range = Math.min(range, mMaxScrollAfterExpand); |
| 1663 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1664 | |
| 1665 | float scrollAmount; |
| 1666 | if (deltaY < 0) { |
| 1667 | scrollAmount = overScrollDown(deltaY); |
| 1668 | } else { |
| 1669 | scrollAmount = overScrollUp(deltaY, range); |
| 1670 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1671 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1672 | // Calling customOverScrollBy will call onCustomOverScrolled, which |
| 1673 | // sets the scrolling if applicable. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1674 | if (scrollAmount != 0.0f) { |
| 1675 | // The scrolling motion could not be compensated with the |
| 1676 | // existing overScroll, we have to scroll the view |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1677 | customOverScrollBy((int) scrollAmount, mOwnScrollY, |
| 1678 | range, getHeight() / 2); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1679 | // If we're scrolling, leavebehinds should be dismissed |
| 1680 | checkSnoozeLeavebehind(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1681 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1682 | } |
| 1683 | break; |
| 1684 | case MotionEvent.ACTION_UP: |
| 1685 | if (mIsBeingDragged) { |
| 1686 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 1687 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 1688 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 1689 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1690 | if (shouldOverScrollFling(initialVelocity)) { |
| 1691 | onOverScrollFling(true, initialVelocity); |
| 1692 | } else { |
| 1693 | if (getChildCount() > 0) { |
| 1694 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 1695 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 1696 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 1697 | fling(-initialVelocity); |
| 1698 | } else { |
| 1699 | onOverScrollFling(false, initialVelocity); |
| 1700 | } |
| 1701 | } else { |
| 1702 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 1703 | getScrollRange())) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1704 | animateScroll(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1705 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1706 | } |
| 1707 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1708 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 1709 | mActivePointerId = INVALID_POINTER; |
| 1710 | endDrag(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1711 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 1712 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1713 | break; |
| 1714 | case MotionEvent.ACTION_CANCEL: |
| 1715 | if (mIsBeingDragged && getChildCount() > 0) { |
| 1716 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1717 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1718 | } |
| 1719 | mActivePointerId = INVALID_POINTER; |
| 1720 | endDrag(); |
| 1721 | } |
| 1722 | break; |
| 1723 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 1724 | final int index = ev.getActionIndex(); |
| 1725 | mLastMotionY = (int) ev.getY(index); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1726 | mDownX = (int) ev.getX(index); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1727 | mActivePointerId = ev.getPointerId(index); |
| 1728 | break; |
| 1729 | } |
| 1730 | case MotionEvent.ACTION_POINTER_UP: |
| 1731 | onSecondaryPointerUp(ev); |
| 1732 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1733 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1734 | break; |
| 1735 | } |
| 1736 | return true; |
| 1737 | } |
| 1738 | |
Muyuan Li | 84b4561 | 2016-06-01 11:05:08 -0700 | [diff] [blame] | 1739 | protected boolean isInsideQsContainer(MotionEvent ev) { |
| 1740 | return ev.getY() < mQsContainer.getBottom(); |
| 1741 | } |
| 1742 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1743 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 1744 | if (mOverscrollTopChangedListener != null) { |
| 1745 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 1746 | } |
| 1747 | mDontReportNextOverScroll = true; |
| 1748 | setOverScrollAmount(0.0f, true, false); |
| 1749 | } |
| 1750 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1751 | /** |
| 1752 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 1753 | * |
| 1754 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 1755 | * @return The amount of scrolling to be performed by the scroller, |
| 1756 | * not handled by the overScroll amount. |
| 1757 | */ |
| 1758 | private float overScrollUp(int deltaY, int range) { |
| 1759 | deltaY = Math.max(deltaY, 0); |
| 1760 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 1761 | float newTopAmount = currentTopAmount - deltaY; |
| 1762 | if (currentTopAmount > 0) { |
| 1763 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 1764 | false /* animate */); |
| 1765 | } |
| 1766 | // Top overScroll might not grab all scrolling motion, |
| 1767 | // we have to scroll as well. |
| 1768 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 1769 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1770 | if (newScrollY > range) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1771 | if (!mExpandedInThisMotion) { |
| 1772 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 1773 | // We overScroll on the top |
| 1774 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 1775 | false /* onTop */, |
| 1776 | false /* animate */); |
| 1777 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 1778 | setOwnScrollY(range); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1779 | scrollAmount = 0.0f; |
| 1780 | } |
| 1781 | return scrollAmount; |
| 1782 | } |
| 1783 | |
| 1784 | /** |
| 1785 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1786 | * |
| 1787 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1788 | * @return The amount of scrolling to be performed by the scroller, |
| 1789 | * not handled by the overScroll amount. |
| 1790 | */ |
| 1791 | private float overScrollDown(int deltaY) { |
| 1792 | deltaY = Math.min(deltaY, 0); |
| 1793 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1794 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1795 | if (currentBottomAmount > 0) { |
| 1796 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1797 | false /* animate */); |
| 1798 | } |
| 1799 | // Bottom overScroll might not grab all scrolling motion, |
| 1800 | // we have to scroll as well. |
| 1801 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1802 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1803 | if (newScrollY < 0) { |
| 1804 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1805 | // We overScroll on the top |
| 1806 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1807 | true /* onTop */, |
| 1808 | false /* animate */); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 1809 | setOwnScrollY(0); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1810 | scrollAmount = 0.0f; |
| 1811 | } |
| 1812 | return scrollAmount; |
| 1813 | } |
| 1814 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1815 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 1816 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 1817 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 1818 | final int pointerId = ev.getPointerId(pointerIndex); |
| 1819 | if (pointerId == mActivePointerId) { |
| 1820 | // This was our active pointer going up. Choose a new |
| 1821 | // active pointer and adjust accordingly. |
| 1822 | // TODO: Make this decision more intelligent. |
| 1823 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 1824 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 1825 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 1826 | if (mVelocityTracker != null) { |
| 1827 | mVelocityTracker.clear(); |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | private void initVelocityTrackerIfNotExists() { |
| 1833 | if (mVelocityTracker == null) { |
| 1834 | mVelocityTracker = VelocityTracker.obtain(); |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | private void recycleVelocityTracker() { |
| 1839 | if (mVelocityTracker != null) { |
| 1840 | mVelocityTracker.recycle(); |
| 1841 | mVelocityTracker = null; |
| 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | private void initOrResetVelocityTracker() { |
| 1846 | if (mVelocityTracker == null) { |
| 1847 | mVelocityTracker = VelocityTracker.obtain(); |
| 1848 | } else { |
| 1849 | mVelocityTracker.clear(); |
| 1850 | } |
| 1851 | } |
| 1852 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1853 | public void setFinishScrollingCallback(Runnable runnable) { |
| 1854 | mFinishScrollingCallback = runnable; |
| 1855 | } |
| 1856 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1857 | private void animateScroll() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1858 | if (mScroller.computeScrollOffset()) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1859 | int oldY = mOwnScrollY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1860 | int y = mScroller.getCurrY(); |
| 1861 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1862 | if (oldY != y) { |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1863 | int range = getScrollRange(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1864 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
| 1865 | float currVelocity = mScroller.getCurrVelocity(); |
Selim Cinek | ba81962 | 2014-05-13 17:55:53 +0200 | [diff] [blame] | 1866 | if (currVelocity >= mMinimumVelocity) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1867 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
| 1868 | } |
| 1869 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1870 | |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1871 | if (mDontClampNextScroll) { |
| 1872 | range = Math.max(range, oldY); |
| 1873 | } |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1874 | customOverScrollBy(y - oldY, oldY, range, |
| 1875 | (int) (mMaxOverScroll)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1876 | } |
| 1877 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1878 | postOnAnimation(mAnimateScroll); |
Adrian Roos | 5153d4a | 2016-03-22 10:01:56 -0700 | [diff] [blame] | 1879 | } else { |
| 1880 | mDontClampNextScroll = false; |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1881 | if (mFinishScrollingCallback != null) { |
| 1882 | mFinishScrollingCallback.run(); |
| 1883 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1884 | } |
| 1885 | } |
| 1886 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1887 | private boolean customOverScrollBy(int deltaY, int scrollY, int scrollRangeY, |
| 1888 | int maxOverScrollY) { |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1889 | |
| 1890 | int newScrollY = scrollY + deltaY; |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1891 | final int top = -maxOverScrollY; |
| 1892 | final int bottom = maxOverScrollY + scrollRangeY; |
| 1893 | |
| 1894 | boolean clampedY = false; |
| 1895 | if (newScrollY > bottom) { |
| 1896 | newScrollY = bottom; |
| 1897 | clampedY = true; |
| 1898 | } else if (newScrollY < top) { |
| 1899 | newScrollY = top; |
| 1900 | clampedY = true; |
| 1901 | } |
| 1902 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 1903 | onCustomOverScrolled(newScrollY, clampedY); |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1904 | |
| 1905 | return clampedY; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | /** |
| 1909 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1910 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1911 | * same overScroll edge. |
| 1912 | * |
| 1913 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 1914 | * the rubber-banding logic. |
| 1915 | * @param onTop Should the effect be applied on top of the scroller. |
| 1916 | * @param animate Should an animation be performed. |
| 1917 | */ |
| 1918 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1919 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | /** |
| 1923 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1924 | * By default this will also cancel animations on the same overScroll edge. |
| 1925 | * |
| 1926 | * @param amount The amount to overScroll by. |
| 1927 | * @param onTop Should the effect be applied on top of the scroller. |
| 1928 | * @param animate Should an animation be performed. |
| 1929 | */ |
| 1930 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 1931 | setOverScrollAmount(amount, onTop, animate, true); |
| 1932 | } |
| 1933 | |
| 1934 | /** |
| 1935 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1936 | * |
| 1937 | * @param amount The amount to overScroll by. |
| 1938 | * @param onTop Should the effect be applied on top of the scroller. |
| 1939 | * @param animate Should an animation be performed. |
| 1940 | * @param cancelAnimators Should running animations be cancelled. |
| 1941 | */ |
| 1942 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1943 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1944 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 1945 | } |
| 1946 | |
| 1947 | /** |
| 1948 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1949 | * |
| 1950 | * @param amount The amount to overScroll by. |
| 1951 | * @param onTop Should the effect be applied on top of the scroller. |
| 1952 | * @param animate Should an animation be performed. |
| 1953 | * @param cancelAnimators Should running animations be cancelled. |
| 1954 | * @param isRubberbanded The value which will be passed to |
| 1955 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
| 1956 | */ |
| 1957 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1958 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1959 | if (cancelAnimators) { |
| 1960 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 1961 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1962 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1963 | } |
| 1964 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1965 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 1966 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1967 | amount = Math.max(0, amount); |
| 1968 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1969 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1970 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1971 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1972 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1973 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1974 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1975 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1976 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1980 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1981 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 1982 | if (mDontReportNextOverScroll) { |
| 1983 | mDontReportNextOverScroll = false; |
| 1984 | return; |
| 1985 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1986 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1987 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | public void setOverscrollTopChangedListener( |
| 1992 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 1993 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 1994 | } |
| 1995 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1996 | public float getCurrentOverScrollAmount(boolean top) { |
| 1997 | return mAmbientState.getOverScrollAmount(top); |
| 1998 | } |
| 1999 | |
| 2000 | public float getCurrentOverScrolledPixels(boolean top) { |
| 2001 | return top? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
| 2002 | } |
| 2003 | |
| 2004 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 2005 | if (onTop) { |
| 2006 | mOverScrolledTopPixels = amount; |
| 2007 | } else { |
| 2008 | mOverScrolledBottomPixels = amount; |
| 2009 | } |
| 2010 | } |
| 2011 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2012 | private void onCustomOverScrolled(int scrollY, boolean clampedY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2013 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 2014 | if (!mScroller.isFinished()) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2015 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2016 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2017 | springBack(); |
| 2018 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2019 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 2020 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2021 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2022 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2023 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2024 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2025 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2026 | } else { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2027 | setOwnScrollY(scrollY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2031 | private void springBack() { |
| 2032 | int scrollRange = getScrollRange(); |
| 2033 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 2034 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 2035 | if (overScrolledTop || overScrolledBottom) { |
| 2036 | boolean onTop; |
| 2037 | float newAmount; |
| 2038 | if (overScrolledTop) { |
| 2039 | onTop = true; |
| 2040 | newAmount = -mOwnScrollY; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2041 | setOwnScrollY(0); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2042 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2043 | } else { |
| 2044 | onTop = false; |
| 2045 | newAmount = mOwnScrollY - scrollRange; |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2046 | setOwnScrollY(scrollRange); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2047 | } |
| 2048 | setOverScrollAmount(newAmount, onTop, false); |
| 2049 | setOverScrollAmount(0.0f, onTop, true); |
| 2050 | mScroller.forceFinished(true); |
| 2051 | } |
| 2052 | } |
| 2053 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2054 | private int getScrollRange() { |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2055 | int scrollRange = Math.max(0, mContentHeight - mMaxLayoutHeight); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2056 | int imeInset = getImeInset(); |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2057 | scrollRange += Math.min(imeInset, Math.max(0, mContentHeight - (getHeight() - imeInset))); |
Selim Cinek | a424c50 | 2016-04-05 13:07:54 -0700 | [diff] [blame] | 2058 | return scrollRange; |
| 2059 | } |
| 2060 | |
| 2061 | private int getImeInset() { |
| 2062 | return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight())); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2063 | } |
| 2064 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2065 | /** |
| 2066 | * @return the first child which has visibility unequal to GONE |
| 2067 | */ |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2068 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2069 | int childCount = getChildCount(); |
| 2070 | for (int i = 0; i < childCount; i++) { |
| 2071 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2072 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2073 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 2074 | } |
| 2075 | } |
| 2076 | return null; |
| 2077 | } |
| 2078 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2079 | /** |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2080 | * @return the child before the given view which has visibility unequal to GONE |
| 2081 | */ |
| 2082 | public ExpandableView getViewBeforeView(ExpandableView view) { |
| 2083 | ExpandableView previousView = null; |
| 2084 | int childCount = getChildCount(); |
| 2085 | for (int i = 0; i < childCount; i++) { |
| 2086 | View child = getChildAt(i); |
| 2087 | if (child == view) { |
| 2088 | return previousView; |
| 2089 | } |
| 2090 | if (child.getVisibility() != View.GONE) { |
| 2091 | previousView = (ExpandableView) child; |
| 2092 | } |
| 2093 | } |
| 2094 | return null; |
| 2095 | } |
| 2096 | |
| 2097 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2098 | * @return The first child which has visibility unequal to GONE which is currently below the |
| 2099 | * given translationY or equal to it. |
| 2100 | */ |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2101 | private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2102 | int childCount = getChildCount(); |
| 2103 | for (int i = 0; i < childCount; i++) { |
| 2104 | View child = getChildAt(i); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2105 | if (child.getVisibility() == View.GONE) { |
| 2106 | continue; |
| 2107 | } |
| 2108 | float rowTranslation = child.getTranslationY(); |
| 2109 | if (rowTranslation >= translationY) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2110 | return child; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2111 | } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) { |
| 2112 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2113 | if (row.isSummaryWithChildren() && row.areChildrenExpanded()) { |
| 2114 | List<ExpandableNotificationRow> notificationChildren = |
| 2115 | row.getNotificationChildren(); |
| 2116 | for (int childIndex = 0; childIndex < notificationChildren.size(); |
| 2117 | childIndex++) { |
| 2118 | ExpandableNotificationRow rowChild = notificationChildren.get(childIndex); |
| 2119 | if (rowChild.getTranslationY() + rowTranslation >= translationY) { |
| 2120 | return rowChild; |
| 2121 | } |
| 2122 | } |
| 2123 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2124 | } |
| 2125 | } |
| 2126 | return null; |
| 2127 | } |
| 2128 | |
| 2129 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2130 | * @return the last child which has visibility unequal to GONE |
| 2131 | */ |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2132 | public View getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2133 | int childCount = getChildCount(); |
| 2134 | for (int i = childCount - 1; i >= 0; i--) { |
| 2135 | View child = getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2136 | if (child.getVisibility() != View.GONE && child != mShelf) { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2137 | return child; |
| 2138 | } |
| 2139 | } |
| 2140 | return null; |
| 2141 | } |
| 2142 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2143 | /** |
| 2144 | * @return the number of children which have visibility unequal to GONE |
| 2145 | */ |
| 2146 | public int getNotGoneChildCount() { |
| 2147 | int childCount = getChildCount(); |
| 2148 | int count = 0; |
| 2149 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2150 | ExpandableView child = (ExpandableView) getChildAt(i); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2151 | if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 2152 | count++; |
| 2153 | } |
| 2154 | } |
| 2155 | return count; |
| 2156 | } |
| 2157 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2158 | private void updateContentHeight() { |
| 2159 | int height = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2160 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2161 | float previousPaddingAmount = 0.0f; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2162 | int numShownItems = 0; |
| 2163 | boolean finish = false; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 2164 | int maxDisplayedNotifications = mAmbientState.isFullyDark() |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2165 | ? (hasPulsingNotifications() ? 1 : 0) |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 2166 | : mMaxDisplayedNotifications; |
| 2167 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2168 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2169 | ExpandableView expandableView = (ExpandableView) getChildAt(i); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2170 | boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2171 | if (expandableView.getVisibility() != View.GONE |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2172 | && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) { |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2173 | boolean limitReached = maxDisplayedNotifications != -1 |
| 2174 | && numShownItems >= maxDisplayedNotifications; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 2175 | boolean notificationOnAmbientThatIsNotPulsing = mAmbientState.isFullyDark() |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2176 | && hasPulsingNotifications() |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2177 | && expandableView instanceof ExpandableNotificationRow |
| 2178 | && !isPulsing(((ExpandableNotificationRow) expandableView).getEntry()); |
| 2179 | if (limitReached || notificationOnAmbientThatIsNotPulsing) { |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2180 | expandableView = mShelf; |
| 2181 | finish = true; |
| 2182 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2183 | float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2184 | float padding; |
| 2185 | if (increasedPaddingAmount >= 0.0f) { |
| 2186 | padding = (int) NotificationUtils.interpolate( |
| 2187 | previousPaddingRequest, |
| 2188 | mIncreasedPaddingBetweenElements, |
| 2189 | increasedPaddingAmount); |
| 2190 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2191 | mPaddingBetweenElements, |
| 2192 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2193 | increasedPaddingAmount); |
| 2194 | } else { |
| 2195 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2196 | 0, |
| 2197 | mPaddingBetweenElements, |
| 2198 | 1.0f + increasedPaddingAmount); |
| 2199 | if (previousPaddingAmount > 0.0f) { |
| 2200 | padding = (int) NotificationUtils.interpolate( |
| 2201 | ownPadding, |
| 2202 | mIncreasedPaddingBetweenElements, |
| 2203 | previousPaddingAmount); |
| 2204 | } else { |
| 2205 | padding = ownPadding; |
| 2206 | } |
| 2207 | previousPaddingRequest = ownPadding; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2208 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2209 | if (height != 0) { |
| 2210 | height += padding; |
| 2211 | } |
| 2212 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2213 | height += expandableView.getIntrinsicHeight(); |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2214 | numShownItems++; |
| 2215 | if (finish) { |
| 2216 | break; |
| 2217 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2218 | } |
| 2219 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 2220 | mIntrinsicContentHeight = height; |
Selim Cinek | f4b04ae | 2018-06-13 18:23:45 -0700 | [diff] [blame] | 2221 | |
| 2222 | // We don't want to use the toppadding since that might be interpolated and we want |
| 2223 | // to take the final value of the animation. |
| 2224 | int topPadding = mAmbientState.isFullyDark() ? mDarkTopPadding : mRegularTopPadding; |
| 2225 | mContentHeight = height + topPadding + mBottomMargin; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2226 | updateScrollability(); |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 2227 | clampScrollPosition(); |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 2228 | mAmbientState.setLayoutMaxHeight(mContentHeight); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2231 | private boolean isPulsing(NotificationData.Entry entry) { |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 2232 | return mAmbientState.isPulsing(entry); |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2235 | @Override |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 2236 | public boolean hasPulsingNotifications() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2237 | return mPulsing; |
Adrian Roos | 7d062c4 | 2017-03-30 15:11:43 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2240 | private void updateScrollability() { |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 2241 | boolean scrollable = !mQsExpanded && getScrollRange() > 0; |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2242 | if (scrollable != mScrollable) { |
| 2243 | mScrollable = scrollable; |
| 2244 | setFocusable(scrollable); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2245 | updateForwardAndBackwardScrollability(); |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | private void updateForwardAndBackwardScrollability() { |
| 2250 | boolean forwardScrollable = mScrollable && mOwnScrollY < getScrollRange(); |
| 2251 | boolean backwardsScrollable = mScrollable && mOwnScrollY > 0; |
| 2252 | boolean changed = forwardScrollable != mForwardScrollable |
| 2253 | || backwardsScrollable != mBackwardScrollable; |
| 2254 | mForwardScrollable = forwardScrollable; |
| 2255 | mBackwardScrollable = backwardsScrollable; |
| 2256 | if (changed) { |
| 2257 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 2258 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2259 | } |
| 2260 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2261 | private void updateBackground() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2262 | // 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] | 2263 | if (!mShouldDrawNotificationBackground || mAmbientState.isFullyDark()) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2264 | return; |
| 2265 | } |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2266 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2267 | updateBackgroundBounds(); |
| 2268 | if (!mCurrentBounds.equals(mBackgroundBounds)) { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2269 | boolean animate = mAnimateNextBackgroundTop || mAnimateNextBackgroundBottom |
| 2270 | || areBoundsAnimating(); |
| 2271 | if (!isExpanded()) { |
| 2272 | abortBackgroundAnimators(); |
| 2273 | animate = false; |
| 2274 | } |
| 2275 | if (animate) { |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2276 | startBackgroundAnimation(); |
| 2277 | } else { |
| 2278 | mCurrentBounds.set(mBackgroundBounds); |
| 2279 | applyCurrentBackgroundBounds(); |
| 2280 | } |
| 2281 | } else { |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2282 | abortBackgroundAnimators(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2283 | } |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2284 | mAnimateNextBackgroundBottom = false; |
| 2285 | mAnimateNextBackgroundTop = false; |
| 2286 | } |
| 2287 | |
Selim Cinek | 5468090 | 2016-10-19 16:49:44 -0700 | [diff] [blame] | 2288 | private void abortBackgroundAnimators() { |
| 2289 | if (mBottomAnimator != null) { |
| 2290 | mBottomAnimator.cancel(); |
| 2291 | } |
| 2292 | if (mTopAnimator != null) { |
| 2293 | mTopAnimator.cancel(); |
| 2294 | } |
| 2295 | } |
| 2296 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2297 | private boolean areBoundsAnimating() { |
| 2298 | return mBottomAnimator != null || mTopAnimator != null; |
| 2299 | } |
| 2300 | |
| 2301 | private void startBackgroundAnimation() { |
Selim Cinek | 01e4019 | 2016-05-12 14:57:22 -0700 | [diff] [blame] | 2302 | // left and right are always instantly applied |
| 2303 | mCurrentBounds.left = mBackgroundBounds.left; |
| 2304 | mCurrentBounds.right = mBackgroundBounds.right; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2305 | startBottomAnimation(); |
| 2306 | startTopAnimation(); |
| 2307 | } |
| 2308 | |
| 2309 | private void startTopAnimation() { |
| 2310 | int previousEndValue = mEndAnimationRect.top; |
| 2311 | int newEndValue = mBackgroundBounds.top; |
| 2312 | ObjectAnimator previousAnimator = mTopAnimator; |
| 2313 | if (previousAnimator != null && previousEndValue == newEndValue) { |
| 2314 | return; |
| 2315 | } |
| 2316 | if (!mAnimateNextBackgroundTop) { |
| 2317 | // just a local update was performed |
| 2318 | if (previousAnimator != null) { |
| 2319 | // we need to increase all animation keyframes of the previous animator by the |
| 2320 | // relative change to the end value |
| 2321 | int previousStartValue = mStartAnimationRect.top; |
| 2322 | PropertyValuesHolder[] values = previousAnimator.getValues(); |
| 2323 | values[0].setIntValues(previousStartValue, newEndValue); |
| 2324 | mStartAnimationRect.top = previousStartValue; |
| 2325 | mEndAnimationRect.top = newEndValue; |
| 2326 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 2327 | return; |
| 2328 | } else { |
| 2329 | // no new animation needed, let's just apply the value |
| 2330 | setBackgroundTop(newEndValue); |
| 2331 | return; |
| 2332 | } |
| 2333 | } |
| 2334 | if (previousAnimator != null) { |
| 2335 | previousAnimator.cancel(); |
| 2336 | } |
| 2337 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundTop", |
| 2338 | mCurrentBounds.top, newEndValue); |
| 2339 | Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN; |
| 2340 | animator.setInterpolator(interpolator); |
| 2341 | animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 2342 | // remove the tag when the animation is finished |
| 2343 | animator.addListener(new AnimatorListenerAdapter() { |
| 2344 | @Override |
| 2345 | public void onAnimationEnd(Animator animation) { |
| 2346 | mStartAnimationRect.top = -1; |
| 2347 | mEndAnimationRect.top = -1; |
| 2348 | mTopAnimator = null; |
| 2349 | } |
| 2350 | }); |
| 2351 | animator.start(); |
| 2352 | mStartAnimationRect.top = mCurrentBounds.top; |
| 2353 | mEndAnimationRect.top = newEndValue; |
| 2354 | mTopAnimator = animator; |
| 2355 | } |
| 2356 | |
| 2357 | private void startBottomAnimation() { |
| 2358 | int previousStartValue = mStartAnimationRect.bottom; |
| 2359 | int previousEndValue = mEndAnimationRect.bottom; |
| 2360 | int newEndValue = mBackgroundBounds.bottom; |
| 2361 | ObjectAnimator previousAnimator = mBottomAnimator; |
| 2362 | if (previousAnimator != null && previousEndValue == newEndValue) { |
| 2363 | return; |
| 2364 | } |
| 2365 | if (!mAnimateNextBackgroundBottom) { |
| 2366 | // just a local update was performed |
| 2367 | if (previousAnimator != null) { |
| 2368 | // we need to increase all animation keyframes of the previous animator by the |
| 2369 | // relative change to the end value |
| 2370 | PropertyValuesHolder[] values = previousAnimator.getValues(); |
| 2371 | values[0].setIntValues(previousStartValue, newEndValue); |
| 2372 | mStartAnimationRect.bottom = previousStartValue; |
| 2373 | mEndAnimationRect.bottom = newEndValue; |
| 2374 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 2375 | return; |
| 2376 | } else { |
| 2377 | // no new animation needed, let's just apply the value |
| 2378 | setBackgroundBottom(newEndValue); |
| 2379 | return; |
| 2380 | } |
| 2381 | } |
| 2382 | if (previousAnimator != null) { |
| 2383 | previousAnimator.cancel(); |
| 2384 | } |
| 2385 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom", |
| 2386 | mCurrentBounds.bottom, newEndValue); |
| 2387 | Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN; |
| 2388 | animator.setInterpolator(interpolator); |
| 2389 | animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 2390 | // remove the tag when the animation is finished |
| 2391 | animator.addListener(new AnimatorListenerAdapter() { |
| 2392 | @Override |
| 2393 | public void onAnimationEnd(Animator animation) { |
| 2394 | mStartAnimationRect.bottom = -1; |
| 2395 | mEndAnimationRect.bottom = -1; |
| 2396 | mBottomAnimator = null; |
| 2397 | } |
| 2398 | }); |
| 2399 | animator.start(); |
| 2400 | mStartAnimationRect.bottom = mCurrentBounds.bottom; |
| 2401 | mEndAnimationRect.bottom = newEndValue; |
| 2402 | mBottomAnimator = animator; |
| 2403 | } |
| 2404 | |
| 2405 | private void setBackgroundTop(int top) { |
| 2406 | mCurrentBounds.top = top; |
| 2407 | applyCurrentBackgroundBounds(); |
| 2408 | } |
| 2409 | |
| 2410 | public void setBackgroundBottom(int bottom) { |
| 2411 | mCurrentBounds.bottom = bottom; |
| 2412 | applyCurrentBackgroundBounds(); |
| 2413 | } |
| 2414 | |
| 2415 | private void applyCurrentBackgroundBounds() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 2416 | // If the background of the notification is not being drawn, then there is no need to |
| 2417 | // exclude an area in the scrim. Rather, the scrim's color should serve as the background. |
| 2418 | if (!mShouldDrawNotificationBackground) { |
| 2419 | return; |
| 2420 | } |
| 2421 | |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 2422 | final boolean awake = mInterpolatedDarkAmount != 0 || mAmbientState.isDark(); |
Selim Cinek | 9bfba9c | 2016-08-08 15:20:06 -0700 | [diff] [blame] | 2423 | mScrimController.setExcludedBackgroundArea( |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 2424 | mFadingOut || mParentNotFullyVisible || awake || mIsClipped ? null |
Selim Cinek | 9bfba9c | 2016-08-08 15:20:06 -0700 | [diff] [blame] | 2425 | : mCurrentBounds); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2426 | invalidate(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | /** |
| 2430 | * Update the background bounds to the new desired bounds |
| 2431 | */ |
| 2432 | private void updateBackgroundBounds() { |
shawnlin | 3a2a2e2 | 2018-05-04 17:09:50 +0800 | [diff] [blame] | 2433 | getLocationInWindow(mTempInt2); |
| 2434 | mBackgroundBounds.left = mTempInt2[0] + mSidePaddings; |
| 2435 | mBackgroundBounds.right = mTempInt2[0] + getWidth() - mSidePaddings; |
| 2436 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2437 | if (!mIsExpanded) { |
| 2438 | mBackgroundBounds.top = 0; |
| 2439 | mBackgroundBounds.bottom = 0; |
Selim Cinek | 1791f50 | 2016-10-07 17:38:03 -0400 | [diff] [blame] | 2440 | return; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2441 | } |
| 2442 | ActivatableNotificationView firstView = mFirstVisibleBackgroundChild; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2443 | int top = 0; |
| 2444 | if (firstView != null) { |
Lucas Dupin | 4f67be7 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 2445 | // Round Y up to avoid seeing the background during animation |
| 2446 | int finalTranslationY = (int) Math.ceil(ViewState.getFinalTranslationY(firstView)); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2447 | if (mAnimateNextBackgroundTop |
| 2448 | || mTopAnimator == null && mCurrentBounds.top == finalTranslationY |
| 2449 | || mTopAnimator != null && mEndAnimationRect.top == finalTranslationY) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2450 | // we're ending up at the same location as we are now, lets just skip the animation |
| 2451 | top = finalTranslationY; |
| 2452 | } else { |
Lucas Dupin | 4f67be7 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 2453 | top = (int) Math.ceil(firstView.getTranslationY()); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2454 | } |
| 2455 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2456 | ActivatableNotificationView lastView = |
| 2457 | mShelf.hasItemsInStableShelf() && mShelf.getVisibility() != GONE |
| 2458 | ? mShelf |
| 2459 | : mLastVisibleBackgroundChild; |
| 2460 | int bottom; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2461 | if (lastView != null) { |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 2462 | int finalTranslationY; |
| 2463 | if (lastView == mShelf) { |
| 2464 | finalTranslationY = (int) mShelf.getTranslationY(); |
| 2465 | } else { |
| 2466 | finalTranslationY = (int) ViewState.getFinalTranslationY(lastView); |
| 2467 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2468 | int finalHeight = ExpandableViewState.getFinalActualHeight(lastView); |
Selim Cinek | c519dcf | 2016-11-22 13:45:39 -0800 | [diff] [blame] | 2469 | int finalBottom = finalTranslationY + finalHeight - lastView.getClipBottomAmount(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2470 | if (mAnimateNextBackgroundBottom |
| 2471 | || mBottomAnimator == null && mCurrentBounds.bottom == finalBottom |
| 2472 | || mBottomAnimator != null && mEndAnimationRect.bottom == finalBottom) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2473 | // we're ending up at the same location as we are now, lets just skip the animation |
| 2474 | bottom = finalBottom; |
| 2475 | } else { |
Selim Cinek | c519dcf | 2016-11-22 13:45:39 -0800 | [diff] [blame] | 2476 | bottom = (int) (lastView.getTranslationY() + lastView.getActualHeight() |
| 2477 | - lastView.getClipBottomAmount()); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2478 | } |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2479 | } else { |
Selim Cinek | d393d5c | 2016-08-03 16:18:12 -0700 | [diff] [blame] | 2480 | top = mTopPadding; |
Selim Cinek | 7db4298 | 2016-02-02 15:21:41 -0800 | [diff] [blame] | 2481 | bottom = top; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2482 | } |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 2483 | if (mStatusBarState != StatusBarState.KEYGUARD) { |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 2484 | top = (int) Math.max(mTopPadding + mStackTranslation, top); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2485 | } else { |
| 2486 | // 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] | 2487 | top = Math.max(0, top); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2488 | } |
Selim Cinek | d381bc3 | 2016-08-15 12:40:57 -0700 | [diff] [blame] | 2489 | mBackgroundBounds.top = top; |
shawnlin | c345791 | 2018-05-15 16:39:56 +0800 | [diff] [blame] | 2490 | mBackgroundBounds.bottom = Math.max(bottom, top); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2493 | private ActivatableNotificationView getFirstPinnedHeadsUp() { |
| 2494 | int childCount = getChildCount(); |
| 2495 | for (int i = 0; i < childCount; i++) { |
| 2496 | View child = getChildAt(i); |
| 2497 | if (child.getVisibility() != View.GONE |
| 2498 | && child instanceof ExpandableNotificationRow) { |
| 2499 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2500 | if (row.isPinned()) { |
| 2501 | return row; |
| 2502 | } |
| 2503 | } |
| 2504 | } |
| 2505 | return null; |
| 2506 | } |
| 2507 | |
| 2508 | private ActivatableNotificationView getLastChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2509 | int childCount = getChildCount(); |
| 2510 | for (int i = childCount - 1; i >= 0; i--) { |
| 2511 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2512 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2513 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2514 | return (ActivatableNotificationView) child; |
| 2515 | } |
| 2516 | } |
| 2517 | return null; |
| 2518 | } |
| 2519 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 2520 | private ActivatableNotificationView getFirstChildWithBackground() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2521 | int childCount = getChildCount(); |
| 2522 | for (int i = 0; i < childCount; i++) { |
| 2523 | View child = getChildAt(i); |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 2524 | if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView |
| 2525 | && child != mShelf) { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 2526 | return (ActivatableNotificationView) child; |
| 2527 | } |
| 2528 | } |
| 2529 | return null; |
| 2530 | } |
| 2531 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2532 | /** |
| 2533 | * Fling the scroll view |
| 2534 | * |
| 2535 | * @param velocityY The initial velocity in the Y direction. Positive |
| 2536 | * numbers mean that the finger/cursor is moving down the screen, |
| 2537 | * which means we want to scroll towards the top. |
| 2538 | */ |
Muyuan Li | 26e30ae | 2016-04-11 17:31:42 -0700 | [diff] [blame] | 2539 | protected void fling(int velocityY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2540 | if (getChildCount() > 0) { |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 2541 | int scrollRange = getScrollRange(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2542 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2543 | float topAmount = getCurrentOverScrollAmount(true); |
| 2544 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 2545 | if (velocityY < 0 && topAmount > 0) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2546 | setOwnScrollY(mOwnScrollY - (int) topAmount); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2547 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2548 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2549 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2550 | * mOverflingDistance + topAmount; |
| 2551 | } else if (velocityY > 0 && bottomAmount > 0) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2552 | setOwnScrollY((int) (mOwnScrollY + bottomAmount)); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2553 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2554 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 2555 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
| 2556 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2557 | } else { |
| 2558 | // it will be set once we reach the boundary |
| 2559 | mMaxOverScroll = 0.0f; |
| 2560 | } |
Selim Cinek | 94ab18c | 2016-02-25 12:35:51 -0800 | [diff] [blame] | 2561 | int minScrollY = Math.max(0, scrollRange); |
| 2562 | if (mExpandedInThisMotion) { |
| 2563 | minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand); |
| 2564 | } |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2565 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0, |
| 2566 | mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2567 | |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 2568 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2569 | } |
| 2570 | } |
| 2571 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2572 | /** |
| 2573 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 2574 | * overScroll view (i.e QS). |
| 2575 | */ |
| 2576 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 2577 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 2578 | return mScrolledToTopOnFirstDown |
| 2579 | && !mExpandedInThisMotion |
| 2580 | && topOverScroll > mMinTopOverScrollToEscape |
| 2581 | && initialVelocity > 0; |
| 2582 | } |
| 2583 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2584 | /** |
| 2585 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 2586 | * account. |
| 2587 | * |
| 2588 | * @param qsHeight the top padding imposed by the quick settings panel |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2589 | * @param animate whether to animate the change |
| 2590 | * @param ignoreIntrinsicPadding if true, {@link #getIntrinsicPadding()} is ignored and |
| 2591 | * {@code qsHeight} is the final top padding |
| 2592 | */ |
Jason Monk | 16ac377 | 2016-02-10 15:39:21 -0500 | [diff] [blame] | 2593 | public void updateTopPadding(float qsHeight, boolean animate, |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2594 | boolean ignoreIntrinsicPadding) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2595 | int topPadding = (int) qsHeight; |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2596 | int minStackHeight = getLayoutMinHeight(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2597 | if (topPadding + minStackHeight > getHeight()) { |
| 2598 | mTopPaddingOverflow = topPadding + minStackHeight - getHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2599 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2600 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2601 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2602 | setTopPadding(ignoreIntrinsicPadding ? topPadding : clampPadding(topPadding), |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 2603 | animate); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 2604 | setExpandedHeight(mExpandedHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2605 | } |
| 2606 | |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 2607 | public void setMaxTopPadding(int maxTopPadding) { |
| 2608 | mMaxTopPadding = maxTopPadding; |
| 2609 | } |
| 2610 | |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 2611 | public int getLayoutMinHeight() { |
Selim Cinek | aa9db1f3 | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2612 | if (isHeadsUpTransition()) { |
| 2613 | return getTopHeadsUpPinnedHeight(); |
| 2614 | } |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2615 | return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight(); |
Selim Cinek | 94c2d82 | 2016-07-13 18:50:04 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 2618 | public int getFirstChildIntrinsicHeight() { |
| 2619 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 2620 | int firstChildMinHeight = firstChild != null |
| 2621 | ? firstChild.getIntrinsicHeight() |
| 2622 | : mEmptyShadeView != null |
| 2623 | ? mEmptyShadeView.getIntrinsicHeight() |
| 2624 | : mCollapsedSize; |
| 2625 | if (mOwnScrollY > 0) { |
| 2626 | firstChildMinHeight = Math.max(firstChildMinHeight - mOwnScrollY, mCollapsedSize); |
| 2627 | } |
| 2628 | return firstChildMinHeight; |
| 2629 | } |
| 2630 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2631 | public float getTopPaddingOverflow() { |
| 2632 | return mTopPaddingOverflow; |
| 2633 | } |
| 2634 | |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2635 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2636 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2637 | final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2638 | : mCollapsedSize; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2639 | int shelfHeight = 0; |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 2640 | if (mLastVisibleBackgroundChild != null && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 2641 | shelfHeight = mShelf.getIntrinsicHeight(); |
| 2642 | } |
| 2643 | return mIntrinsicPadding + firstChildMinHeight + shelfHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 2644 | } |
| 2645 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2646 | private int clampPadding(int desiredPadding) { |
| 2647 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 2648 | } |
| 2649 | |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 2650 | private float getRubberBandFactor(boolean onTop) { |
| 2651 | if (!onTop) { |
| 2652 | return RUBBER_BAND_FACTOR_NORMAL; |
| 2653 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2654 | if (mExpandedInThisMotion) { |
| 2655 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2656 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 2657 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 2658 | } else if (mScrolledToTopOnFirstDown) { |
| 2659 | return 1.0f; |
| 2660 | } |
| 2661 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2662 | } |
| 2663 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2664 | /** |
| 2665 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 2666 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 2667 | * overscroll view (e.g. expand QS). |
| 2668 | */ |
| 2669 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2670 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2671 | || !mScrolledToTopOnFirstDown; |
| 2672 | } |
| 2673 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2674 | private void endDrag() { |
| 2675 | setIsBeingDragged(false); |
| 2676 | |
| 2677 | recycleVelocityTracker(); |
| 2678 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 2679 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 2680 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 2681 | } |
| 2682 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 2683 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 2684 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2685 | } |
| 2686 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 2687 | private void transformTouchEvent(MotionEvent ev, View sourceView, View targetView) { |
| 2688 | ev.offsetLocation(sourceView.getX(), sourceView.getY()); |
| 2689 | ev.offsetLocation(-targetView.getX(), -targetView.getY()); |
| 2690 | } |
| 2691 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2692 | @Override |
| 2693 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2694 | initDownStates(ev); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2695 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2696 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 2697 | if (!mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2698 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 2699 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2700 | boolean scrollWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2701 | if (!mSwipingInProgress && !mExpandingNotification) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2702 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 2703 | } |
| 2704 | boolean swipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2705 | if (!mIsBeingDragged |
| 2706 | && !mExpandingNotification |
| 2707 | && !mExpandedInThisMotion |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 2708 | && !mOnlyScrollingInThisMotion |
| 2709 | && !mDisallowDismissInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2710 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 2711 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 2712 | // Check if we need to clear any snooze leavebehinds |
| 2713 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 2714 | NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 2715 | if (!isTouchInView(ev, guts) && isUp && !swipeWantsIt && !expandWantsIt |
| 2716 | && !scrollWantsIt) { |
| 2717 | mCheckForLeavebehind = false; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 2718 | mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */, |
| 2719 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 2720 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 2721 | } |
| 2722 | if (ev.getActionMasked() == MotionEvent.ACTION_UP) { |
| 2723 | mCheckForLeavebehind = true; |
| 2724 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2725 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 2726 | } |
| 2727 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2728 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 2729 | switch (ev.getActionMasked()) { |
| 2730 | case MotionEvent.ACTION_MOVE: |
| 2731 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 2732 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop )) { |
| 2733 | mTouchIsClick = false; |
| 2734 | } |
| 2735 | break; |
| 2736 | case MotionEvent.ACTION_UP: |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 2737 | if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick && |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2738 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 2739 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 2740 | } |
| 2741 | break; |
| 2742 | } |
| 2743 | } |
| 2744 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2745 | private void initDownStates(MotionEvent ev) { |
| 2746 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 2747 | mExpandedInThisMotion = false; |
| 2748 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2749 | mDisallowScrollingInThisMotion = false; |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 2750 | mDisallowDismissInThisMotion = false; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2751 | mTouchIsClick = true; |
| 2752 | mInitialTouchX = ev.getX(); |
| 2753 | mInitialTouchY = ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2754 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2755 | } |
| 2756 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2757 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
| 2758 | mChildTransferInProgress = childTransferInProgress; |
| 2759 | } |
| 2760 | |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2761 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 2762 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2763 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2764 | // we only call our internal methods if this is actually a removal and not just a |
| 2765 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2766 | if (!mChildTransferInProgress) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2767 | onViewRemovedInternal(child, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2768 | } |
| 2769 | } |
| 2770 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 2771 | @Override |
Mady Mellor | 4c97b0a | 2017-02-15 11:16:13 -0800 | [diff] [blame] | 2772 | public void cleanUpViewState(View child) { |
| 2773 | if (child == mTranslatingParentView) { |
| 2774 | mTranslatingParentView = null; |
| 2775 | } |
| 2776 | mCurrentStackScrollState.removeViewStateForView(child); |
| 2777 | } |
| 2778 | |
Selim Cinek | 197823d | 2016-03-24 13:06:00 -0700 | [diff] [blame] | 2779 | @Override |
| 2780 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 2781 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 2782 | if (disallowIntercept) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 2783 | cancelLongPress(); |
Selim Cinek | 197823d | 2016-03-24 13:06:00 -0700 | [diff] [blame] | 2784 | } |
| 2785 | } |
| 2786 | |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2787 | private void onViewRemovedInternal(View child, ViewGroup container) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 2788 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2789 | // This is only a position change, don't do anything special |
| 2790 | return; |
| 2791 | } |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2792 | ExpandableView expandableView = (ExpandableView) child; |
| 2793 | expandableView.setOnHeightChangedListener(null); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2794 | mCurrentStackScrollState.removeViewStateForView(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2795 | updateScrollStateForRemovedChild(expandableView); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 2796 | boolean animationGenerated = generateRemoveAnimation(child); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2797 | if (animationGenerated) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2798 | if (!mSwipedOutViews.contains(child) |
| 2799 | || Math.abs(expandableView.getTranslation()) != expandableView.getWidth()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2800 | container.addTransientView(child, 0); |
| 2801 | expandableView.setTransientContainer(container); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 2802 | } |
| 2803 | } else { |
| 2804 | mSwipedOutViews.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2805 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2806 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 2807 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2808 | focusNextViewIfFocused(child); |
| 2809 | } |
| 2810 | |
| 2811 | private void focusNextViewIfFocused(View view) { |
| 2812 | if (view instanceof ExpandableNotificationRow) { |
| 2813 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2814 | if (row.shouldRefocusOnDismiss()) { |
| 2815 | View nextView = row.getChildAfterViewWhenDismissed(); |
| 2816 | if (nextView == null) { |
| 2817 | View groupParentWhenDismissed = row.getGroupParentWhenDismissed(); |
| 2818 | nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null |
| 2819 | ? groupParentWhenDismissed.getTranslationY() |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 2820 | : view.getTranslationY(), true /* ignoreChildren */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2821 | } |
| 2822 | if (nextView != null) { |
| 2823 | nextView.requestAccessibilityFocus(); |
| 2824 | } |
| 2825 | } |
| 2826 | } |
| 2827 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2828 | } |
| 2829 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2830 | private boolean isChildInGroup(View child) { |
| 2831 | return child instanceof ExpandableNotificationRow |
| 2832 | && mGroupManager.isChildInGroupWithSummary( |
| 2833 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
| 2834 | } |
| 2835 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2836 | /** |
| 2837 | * Generate a remove animation for a child view. |
| 2838 | * |
| 2839 | * @param child The view to generate the remove animation for. |
| 2840 | * @return Whether an animation was generated. |
| 2841 | */ |
| 2842 | private boolean generateRemoveAnimation(View child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2843 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2844 | mAddedHeadsUpChildren.remove(child); |
| 2845 | return false; |
| 2846 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2847 | if (isClickedHeadsUp(child)) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 2848 | // An animation is already running, add it transiently |
| 2849 | mClearTransientViewsWhenFinished.add((ExpandableView) child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2850 | return true; |
| 2851 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2852 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 2853 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2854 | // Generate Animations |
| 2855 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2856 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2857 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2858 | } else { |
| 2859 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2860 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2861 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2862 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2863 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2864 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2865 | } |
| 2866 | |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2867 | private boolean isClickedHeadsUp(View child) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 2868 | return HeadsUpUtil.isClickedHeadsUpNotification(child); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2871 | /** |
| 2872 | * Remove a removed child view from the heads up animations if it was just added there |
| 2873 | * |
| 2874 | * @return whether any child was removed from the list to animate |
| 2875 | */ |
| 2876 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 2877 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2878 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 2879 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2880 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2881 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2882 | mTmpList.add(eventPair); |
| 2883 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2884 | } |
| 2885 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2886 | if (hasAddEvent) { |
| 2887 | // This child was just added lets remove all events. |
| 2888 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 2889 | ((ExpandableNotificationRow ) child).setHeadsUpAnimatingAway(false); |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 2890 | } |
| 2891 | mTmpList.clear(); |
| 2892 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2895 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2896 | * @param child the child to query |
| 2897 | * @return whether a view is not a top level child but a child notification and that group is |
| 2898 | * not expanded |
| 2899 | */ |
| 2900 | private boolean isChildInInvisibleGroup(View child) { |
| 2901 | if (child instanceof ExpandableNotificationRow) { |
| 2902 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2903 | ExpandableNotificationRow groupSummary = |
| 2904 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 2905 | if (groupSummary != null && groupSummary != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2906 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | return false; |
| 2910 | } |
| 2911 | |
| 2912 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2913 | * Updates the scroll position when a child was removed |
| 2914 | * |
| 2915 | * @param removedChild the removed child |
| 2916 | */ |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2917 | private void updateScrollStateForRemovedChild(ExpandableView removedChild) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2918 | int startingPosition = getPositionInLinearLayout(removedChild); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2919 | float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount(); |
| 2920 | int padding; |
| 2921 | if (increasedPaddingAmount >= 0) { |
| 2922 | padding = (int) NotificationUtils.interpolate( |
| 2923 | mPaddingBetweenElements, |
| 2924 | mIncreasedPaddingBetweenElements, |
| 2925 | increasedPaddingAmount); |
| 2926 | } else { |
| 2927 | padding = (int) NotificationUtils.interpolate( |
| 2928 | 0, |
| 2929 | mPaddingBetweenElements, |
| 2930 | 1.0f + increasedPaddingAmount); |
| 2931 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2932 | int childHeight = getIntrinsicHeight(removedChild) + padding; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2933 | int endPosition = startingPosition + childHeight; |
| 2934 | if (endPosition <= mOwnScrollY) { |
| 2935 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 2936 | // scrollPosition |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2937 | setOwnScrollY(mOwnScrollY - childHeight); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2938 | } else if (startingPosition < mOwnScrollY) { |
| 2939 | // This child is currently being scrolled into, set the scroll position to the start of |
| 2940 | // this child |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 2941 | setOwnScrollY(startingPosition); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 2945 | private int getIntrinsicHeight(View view) { |
| 2946 | if (view instanceof ExpandableView) { |
| 2947 | ExpandableView expandableView = (ExpandableView) view; |
| 2948 | return expandableView.getIntrinsicHeight(); |
| 2949 | } |
| 2950 | return view.getHeight(); |
| 2951 | } |
| 2952 | |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 2953 | public int getPositionInLinearLayout(View requestedView) { |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 2954 | ExpandableNotificationRow childInGroup = null; |
| 2955 | ExpandableNotificationRow requestedRow = null; |
| 2956 | if (isChildInGroup(requestedView)) { |
| 2957 | // We're asking for a child in a group. Calculate the position of the parent first, |
| 2958 | // then within the parent. |
| 2959 | childInGroup = (ExpandableNotificationRow) requestedView; |
| 2960 | requestedView = requestedRow = childInGroup.getNotificationParent(); |
| 2961 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2962 | int position = 0; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2963 | float previousPaddingRequest = mPaddingBetweenElements; |
| 2964 | float previousPaddingAmount = 0.0f; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2965 | for (int i = 0; i < getChildCount(); i++) { |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2966 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 2967 | boolean notGone = child.getVisibility() != View.GONE; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2968 | if (notGone && !child.hasNoContentHeight()) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2969 | float increasedPaddingAmount = child.getIncreasedPaddingAmount(); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2970 | float padding; |
| 2971 | if (increasedPaddingAmount >= 0.0f) { |
| 2972 | padding = (int) NotificationUtils.interpolate( |
| 2973 | previousPaddingRequest, |
| 2974 | mIncreasedPaddingBetweenElements, |
| 2975 | increasedPaddingAmount); |
| 2976 | previousPaddingRequest = (int) NotificationUtils.interpolate( |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2977 | mPaddingBetweenElements, |
| 2978 | mIncreasedPaddingBetweenElements, |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2979 | increasedPaddingAmount); |
| 2980 | } else { |
| 2981 | int ownPadding = (int) NotificationUtils.interpolate( |
| 2982 | 0, |
| 2983 | mPaddingBetweenElements, |
| 2984 | 1.0f + increasedPaddingAmount); |
| 2985 | if (previousPaddingAmount > 0.0f) { |
| 2986 | padding = (int) NotificationUtils.interpolate( |
| 2987 | ownPadding, |
| 2988 | mIncreasedPaddingBetweenElements, |
| 2989 | previousPaddingAmount); |
| 2990 | } else { |
| 2991 | padding = ownPadding; |
| 2992 | } |
| 2993 | previousPaddingRequest = ownPadding; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2994 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2995 | if (position != 0) { |
| 2996 | position += padding; |
| 2997 | } |
| 2998 | previousPaddingAmount = increasedPaddingAmount; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2999 | } |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 3000 | if (child == requestedView) { |
| 3001 | if (requestedRow != null) { |
| 3002 | position += requestedRow.getPositionOfChild(childInGroup); |
| 3003 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3004 | return position; |
| 3005 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 3006 | if (notGone) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 3007 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 3014 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3015 | super.onViewAdded(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3016 | onViewAddedInternal(child); |
| 3017 | } |
| 3018 | |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3019 | private void updateFirstAndLastBackgroundViews() { |
| 3020 | ActivatableNotificationView firstChild = getFirstChildWithBackground(); |
| 3021 | ActivatableNotificationView lastChild = getLastChildWithBackground(); |
| 3022 | if (mAnimationsEnabled && mIsExpanded) { |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 3023 | mAnimateNextBackgroundTop = firstChild != mFirstVisibleBackgroundChild; |
| 3024 | mAnimateNextBackgroundBottom = lastChild != mLastVisibleBackgroundChild; |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3025 | } else { |
| 3026 | mAnimateNextBackgroundTop = false; |
| 3027 | mAnimateNextBackgroundBottom = false; |
| 3028 | } |
| 3029 | mFirstVisibleBackgroundChild = firstChild; |
| 3030 | mLastVisibleBackgroundChild = lastChild; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3031 | mAmbientState.setLastVisibleBackgroundChild(lastChild); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 3032 | mRoundnessManager.setFirstAndLastBackgroundChild(mFirstVisibleBackgroundChild, |
| 3033 | mLastVisibleBackgroundChild); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 3034 | invalidate(); |
Selim Cinek | 614576e | 2016-01-20 10:54:09 -0800 | [diff] [blame] | 3035 | } |
| 3036 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3037 | private void onViewAddedInternal(View child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3038 | updateHideSensitiveForChild(child); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3039 | ((ExpandableView) child).setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3040 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3041 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3042 | updateChronometerForChild(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3043 | } |
| 3044 | |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3045 | private void updateHideSensitiveForChild(View child) { |
Selim Cinek | cfcd23e | 2016-05-05 12:31:42 -0400 | [diff] [blame] | 3046 | if (child instanceof ExpandableView) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3047 | ExpandableView expandableView = (ExpandableView) child; |
Selim Cinek | cfcd23e | 2016-05-05 12:31:42 -0400 | [diff] [blame] | 3048 | expandableView.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive()); |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3052 | @Override |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3053 | public void notifyGroupChildRemoved(View row, ViewGroup childrenContainer) { |
| 3054 | onViewRemovedInternal(row, childrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3055 | } |
| 3056 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3057 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3058 | public void notifyGroupChildAdded(View row) { |
| 3059 | onViewAddedInternal(row); |
| 3060 | } |
| 3061 | |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3062 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 3063 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3064 | updateNotificationAnimationStates(); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3065 | if (!animationsEnabled) { |
| 3066 | mSwipedOutViews.clear(); |
| 3067 | mChildrenToRemoveAnimated.clear(); |
| 3068 | clearTemporaryViewsInGroup(this); |
| 3069 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | private void updateNotificationAnimationStates() { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3073 | boolean running = mAnimationsEnabled || hasPulsingNotifications(); |
Selim Cinek | 09bd29d | 2017-02-03 15:30:28 -0800 | [diff] [blame] | 3074 | mShelf.setAnimationsEnabled(running); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3075 | int childCount = getChildCount(); |
| 3076 | for (int i = 0; i < childCount; i++) { |
| 3077 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 3078 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3079 | updateAnimationState(running, child); |
| 3080 | } |
| 3081 | } |
| 3082 | |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3083 | private void updateAnimationState(View child) { |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 3084 | updateAnimationState((mAnimationsEnabled || hasPulsingNotifications()) |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 3085 | && (mIsExpanded || isPinnedHeadsUp(child)), child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3088 | @Override |
| 3089 | public void setExpandingNotification(ExpandableNotificationRow row) { |
| 3090 | mAmbientState.setExpandingNotification(row); |
| 3091 | requestChildrenUpdate(); |
| 3092 | } |
| 3093 | |
| 3094 | @Override |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3095 | public void bindRow(ExpandableNotificationRow row) { |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 3096 | row.setHeadsUpAnimatingAwayListener(animatingAway -> { |
| 3097 | mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway); |
| 3098 | mHeadsUpAppearanceController.updateHeader(row.getEntry()); |
| 3099 | }); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | @Override |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 3103 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 3104 | mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange()); |
| 3105 | requestChildrenUpdate(); |
| 3106 | } |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3107 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3108 | private void updateAnimationState(boolean running, View child) { |
| 3109 | if (child instanceof ExpandableNotificationRow) { |
| 3110 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3111 | row.setIconAnimationRunning(running); |
| 3112 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | public boolean isAddOrRemoveAnimationPending() { |
| 3116 | return mNeedsAnimation |
| 3117 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 3118 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3119 | |
| 3120 | @Override |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3121 | public void generateAddAnimation(View child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3122 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3123 | // Generate Animations |
| 3124 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 3125 | if (fromMoreCard) { |
| 3126 | mFromMoreCardAdditions.add(child); |
| 3127 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3128 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3129 | } |
Selim Cinek | f306d9b | 2017-02-21 11:45:13 -0800 | [diff] [blame] | 3130 | if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3131 | mAddedHeadsUpChildren.add(child); |
| 3132 | mChildrenToAddAnimated.remove(child); |
| 3133 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3134 | } |
| 3135 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3136 | @Override |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3137 | public void changeViewPosition(View child, int newIndex) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3138 | int currentIndex = indexOfChild(child); |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3139 | |
| 3140 | if (currentIndex == -1) { |
| 3141 | boolean isTransient = false; |
| 3142 | if (child instanceof ExpandableNotificationRow |
| 3143 | && ((ExpandableNotificationRow)child).getTransientContainer() != null) { |
| 3144 | isTransient = true; |
| 3145 | } |
| 3146 | Log.e(TAG, "Attempting to re-position " |
| 3147 | + (isTransient ? "transient" : "") |
| 3148 | + " view {" |
| 3149 | + child |
| 3150 | + "}"); |
| 3151 | return; |
| 3152 | } |
| 3153 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3154 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3155 | mChangePositionInProgress = true; |
Adrian Roos | 14503e2 | 2016-03-09 14:01:24 -0800 | [diff] [blame] | 3156 | ((ExpandableView)child).setChangingPosition(true); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3157 | removeView(child); |
| 3158 | addView(child, newIndex); |
Adrian Roos | 14503e2 | 2016-03-09 14:01:24 -0800 | [diff] [blame] | 3159 | ((ExpandableView)child).setChangingPosition(false); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3160 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 3161 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 3162 | mChildrenChangingPositions.add(child); |
| 3163 | mNeedsAnimation = true; |
| 3164 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3165 | } |
| 3166 | } |
| 3167 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3168 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3169 | if (mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3170 | generateChildHierarchyEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3171 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3172 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3173 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3174 | setAnimationRunning(true); |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3175 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mCurrentStackScrollState, |
| 3176 | mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3177 | mAnimationEvents.clear(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3178 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3179 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3180 | updateClippingToTopRoundedCorner(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3181 | } else { |
| 3182 | applyCurrentState(); |
| 3183 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3184 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | private void generateChildHierarchyEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3188 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3189 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3190 | generateChildAdditionEvents(); |
| 3191 | generatePositionChangeEvents(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3192 | generateSnapBackEvents(); |
| 3193 | generateDragEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3194 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3195 | generateActivateEvent(); |
| 3196 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3197 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3198 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3199 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3200 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3201 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3202 | generateAnimateEverythingEvent(); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 3203 | generatePulsingAnimationEvent(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3204 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3205 | } |
| 3206 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3207 | private void generateHeadsUpAnimationEvents() { |
| 3208 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3209 | ExpandableNotificationRow row = eventPair.first; |
| 3210 | boolean isHeadsUp = eventPair.second; |
| 3211 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 3212 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 3213 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 3214 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3215 | type = row.wasJustClicked() |
| 3216 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3217 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3218 | if (row.isChildInGroup()) { |
| 3219 | // We can otherwise get stuck in there if it was just isolated |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3220 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 3221 | continue; |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3222 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3223 | } else { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3224 | ExpandableViewState viewState = mCurrentStackScrollState.getViewStateForView(row); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3225 | if (viewState == null) { |
| 3226 | // A view state was never generated for this view, so we don't need to animate |
| 3227 | // this. This may happen with notification children. |
| 3228 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3229 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 3230 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 3231 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 3232 | // Our custom add animation |
| 3233 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 3234 | } else { |
| 3235 | // Normal add animation |
| 3236 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 3237 | } |
| 3238 | onBottom = !pinnedAndClosed; |
| 3239 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3240 | } |
| 3241 | AnimationEvent event = new AnimationEvent(row, type); |
| 3242 | event.headsUpFromBottom = onBottom; |
| 3243 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3244 | } |
| 3245 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3246 | mAddedHeadsUpChildren.clear(); |
| 3247 | } |
| 3248 | |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 3249 | private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3250 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 3251 | return false; |
| 3252 | } |
| 3253 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3256 | private void generateGroupExpansionEvent() { |
| 3257 | // Generate a group expansion/collapsing event if there is such a group at all |
| 3258 | if (mExpandedGroupView != null) { |
| 3259 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 3260 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 3261 | mExpandedGroupView = null; |
| 3262 | } |
| 3263 | } |
| 3264 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3265 | private void generateViewResizeEvent() { |
| 3266 | if (mNeedViewResizeAnimation) { |
| 3267 | mAnimationEvents.add( |
| 3268 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 3269 | } |
| 3270 | mNeedViewResizeAnimation = false; |
| 3271 | } |
| 3272 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3273 | private void generateSnapBackEvents() { |
| 3274 | for (View child : mSnappedBackChildren) { |
| 3275 | mAnimationEvents.add(new AnimationEvent(child, |
| 3276 | AnimationEvent.ANIMATION_TYPE_SNAP_BACK)); |
| 3277 | } |
| 3278 | mSnappedBackChildren.clear(); |
| 3279 | } |
| 3280 | |
| 3281 | private void generateDragEvents() { |
| 3282 | for (View child : mDragAnimPendingChildren) { |
| 3283 | mAnimationEvents.add(new AnimationEvent(child, |
| 3284 | AnimationEvent.ANIMATION_TYPE_START_DRAG)); |
| 3285 | } |
| 3286 | mDragAnimPendingChildren.clear(); |
| 3287 | } |
| 3288 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3289 | private void generateChildRemovalEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3290 | for (View child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3291 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3292 | |
| 3293 | // we need to know the view after this one |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3294 | float removedTranslation = child.getTranslationY(); |
| 3295 | boolean ignoreChildren = true; |
| 3296 | if (child instanceof ExpandableNotificationRow) { |
| 3297 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3298 | if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) { |
| 3299 | removedTranslation = row.getTranslationWhenRemoved(); |
| 3300 | ignoreChildren = false; |
| 3301 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3302 | childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth(); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3303 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3304 | if (!childWasSwipedOut) { |
| 3305 | Rect clipBounds = child.getClipBounds(); |
Selim Cinek | e5832ee | 2017-11-06 14:46:48 -0800 | [diff] [blame] | 3306 | childWasSwipedOut = clipBounds != null && clipBounds.height() == 0; |
Rohan Shah | a759496 | 2018-05-22 10:59:30 -0700 | [diff] [blame] | 3307 | |
| 3308 | if (childWasSwipedOut && child instanceof ExpandableView) { |
| 3309 | // Clean up any potential transient views if the child has already been swiped |
| 3310 | // out, as we won't be animating it further (due to its height already being |
| 3311 | // clipped to 0. |
| 3312 | ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer(); |
| 3313 | if (transientContainer != null) { |
| 3314 | transientContainer.removeTransientView(child); |
| 3315 | } |
| 3316 | } |
Selim Cinek | 5105204 | 2017-07-04 12:07:55 +0200 | [diff] [blame] | 3317 | } |
| 3318 | int animationType = childWasSwipedOut |
| 3319 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3320 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
| 3321 | AnimationEvent event = new AnimationEvent(child, animationType); |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 3322 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation, |
| 3323 | ignoreChildren); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3324 | mAnimationEvents.add(event); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3325 | mSwipedOutViews.remove(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3326 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3327 | mChildrenToRemoveAnimated.clear(); |
| 3328 | } |
| 3329 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3330 | private void generatePositionChangeEvents() { |
| 3331 | for (View child : mChildrenChangingPositions) { |
| 3332 | mAnimationEvents.add(new AnimationEvent(child, |
| 3333 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3334 | } |
| 3335 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3336 | if (mGenerateChildOrderChangedEvent) { |
| 3337 | mAnimationEvents.add(new AnimationEvent(null, |
| 3338 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 3339 | mGenerateChildOrderChangedEvent = false; |
| 3340 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3341 | } |
| 3342 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3343 | private void generateChildAdditionEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 3344 | for (View child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3345 | if (mFromMoreCardAdditions.contains(child)) { |
| 3346 | mAnimationEvents.add(new AnimationEvent(child, |
| 3347 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 3348 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 3349 | } else { |
| 3350 | mAnimationEvents.add(new AnimationEvent(child, |
| 3351 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 3352 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3353 | } |
| 3354 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3355 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 3356 | } |
| 3357 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3358 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3359 | if (mTopPaddingNeedsAnimation) { |
Lucas Dupin | c445dcc | 2018-05-07 16:00:11 -0700 | [diff] [blame] | 3360 | AnimationEvent event; |
| 3361 | if (mAmbientState.isDark()) { |
| 3362 | event = new AnimationEvent(null /* view */, |
| 3363 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED, |
| 3364 | KeyguardSliceView.DEFAULT_ANIM_DURATION); |
| 3365 | } else { |
| 3366 | event = new AnimationEvent(null /* view */, |
| 3367 | AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED); |
| 3368 | } |
| 3369 | mAnimationEvents.add(event); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 3370 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3371 | mTopPaddingNeedsAnimation = false; |
| 3372 | } |
| 3373 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3374 | private void generateActivateEvent() { |
| 3375 | if (mActivateNeedsAnimation) { |
| 3376 | mAnimationEvents.add( |
| 3377 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 3378 | } |
| 3379 | mActivateNeedsAnimation = false; |
| 3380 | } |
| 3381 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3382 | private void generateAnimateEverythingEvent() { |
| 3383 | if (mEverythingNeedsAnimation) { |
| 3384 | mAnimationEvents.add( |
| 3385 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 3386 | } |
| 3387 | mEverythingNeedsAnimation = false; |
| 3388 | } |
| 3389 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3390 | private void generateDimmedEvent() { |
| 3391 | if (mDimmedNeedsAnimation) { |
| 3392 | mAnimationEvents.add( |
| 3393 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 3394 | } |
| 3395 | mDimmedNeedsAnimation = false; |
| 3396 | } |
| 3397 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3398 | private void generateHideSensitiveEvent() { |
| 3399 | if (mHideSensitiveNeedsAnimation) { |
| 3400 | mAnimationEvents.add( |
| 3401 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 3402 | } |
| 3403 | mHideSensitiveNeedsAnimation = false; |
| 3404 | } |
| 3405 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3406 | private void generateDarkEvent() { |
| 3407 | if (mDarkNeedsAnimation) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 3408 | AnimationEvent ev = new AnimationEvent(null, |
| 3409 | AnimationEvent.ANIMATION_TYPE_DARK, |
| 3410 | new AnimationFilter() |
| 3411 | .animateDark() |
| 3412 | .animateY(mShelf)); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3413 | ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex; |
| 3414 | mAnimationEvents.add(ev); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3415 | } |
| 3416 | mDarkNeedsAnimation = false; |
| 3417 | } |
| 3418 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3419 | private void generateGoToFullShadeEvent() { |
| 3420 | if (mGoToFullShadeNeedsAnimation) { |
| 3421 | mAnimationEvents.add( |
| 3422 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 3423 | } |
| 3424 | mGoToFullShadeNeedsAnimation = false; |
| 3425 | } |
| 3426 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3427 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3428 | if (!isScrollingEnabled()) { |
| 3429 | return false; |
| 3430 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3431 | /* |
| 3432 | * This method JUST determines whether we want to intercept the motion. |
| 3433 | * If we return true, onMotionEvent will be called and we do the actual |
| 3434 | * scrolling there. |
| 3435 | */ |
| 3436 | |
| 3437 | /* |
| 3438 | * Shortcut the most recurring case: the user is in the dragging |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 3439 | * state and is moving their finger. We want to intercept this |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3440 | * motion. |
| 3441 | */ |
| 3442 | final int action = ev.getAction(); |
| 3443 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 3444 | return true; |
| 3445 | } |
| 3446 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3447 | switch (action & MotionEvent.ACTION_MASK) { |
| 3448 | case MotionEvent.ACTION_MOVE: { |
| 3449 | /* |
| 3450 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 3451 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3452 | */ |
| 3453 | |
| 3454 | /* |
| 3455 | * Locally do absolute value. mLastMotionY is set to the y value |
| 3456 | * of the down event. |
| 3457 | */ |
| 3458 | final int activePointerId = mActivePointerId; |
| 3459 | if (activePointerId == INVALID_POINTER) { |
| 3460 | // If we don't have a valid id, the touch down wasn't on content. |
| 3461 | break; |
| 3462 | } |
| 3463 | |
| 3464 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 3465 | if (pointerIndex == -1) { |
| 3466 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 3467 | + " in onInterceptTouchEvent"); |
| 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3472 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3473 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3474 | final int xDiff = Math.abs(x - mDownX); |
| 3475 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3476 | setIsBeingDragged(true); |
| 3477 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3478 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3479 | initVelocityTrackerIfNotExists(); |
| 3480 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3481 | } |
| 3482 | break; |
| 3483 | } |
| 3484 | |
| 3485 | case MotionEvent.ACTION_DOWN: { |
| 3486 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 3487 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 34ed7c0 | 2017-09-08 15:03:12 -0700 | [diff] [blame] | 3488 | if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3489 | setIsBeingDragged(false); |
| 3490 | recycleVelocityTracker(); |
| 3491 | break; |
| 3492 | } |
| 3493 | |
| 3494 | /* |
| 3495 | * Remember location of down touch. |
| 3496 | * ACTION_DOWN always refers to pointer index 0. |
| 3497 | */ |
| 3498 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3499 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3500 | mActivePointerId = ev.getPointerId(0); |
| 3501 | |
| 3502 | initOrResetVelocityTracker(); |
| 3503 | mVelocityTracker.addMovement(ev); |
| 3504 | /* |
| 3505 | * If being flinged and user touches the screen, initiate drag; |
| 3506 | * otherwise don't. mScroller.isFinished should be false when |
| 3507 | * being flinged. |
| 3508 | */ |
| 3509 | boolean isBeingDragged = !mScroller.isFinished(); |
| 3510 | setIsBeingDragged(isBeingDragged); |
| 3511 | break; |
| 3512 | } |
| 3513 | |
| 3514 | case MotionEvent.ACTION_CANCEL: |
| 3515 | case MotionEvent.ACTION_UP: |
| 3516 | /* Release the drag */ |
| 3517 | setIsBeingDragged(false); |
| 3518 | mActivePointerId = INVALID_POINTER; |
| 3519 | recycleVelocityTracker(); |
| 3520 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 3521 | animateScroll(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3522 | } |
| 3523 | break; |
| 3524 | case MotionEvent.ACTION_POINTER_UP: |
| 3525 | onSecondaryPointerUp(ev); |
| 3526 | break; |
| 3527 | } |
| 3528 | |
| 3529 | /* |
| 3530 | * The only time we want to intercept motion events is if we are in the |
| 3531 | * drag mode. |
| 3532 | */ |
| 3533 | return mIsBeingDragged; |
| 3534 | } |
| 3535 | |
Muyuan Li | 333a4fc | 2016-04-16 17:13:46 -0700 | [diff] [blame] | 3536 | protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) { |
| 3537 | return new StackScrollAlgorithm(context); |
| 3538 | } |
| 3539 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 3540 | /** |
| 3541 | * @return Whether the specified motion event is actually happening over the content. |
| 3542 | */ |
| 3543 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 3544 | return isInContentBounds(event.getY()); |
| 3545 | } |
| 3546 | |
| 3547 | /** |
| 3548 | * @return Whether a y coordinate is inside the content. |
| 3549 | */ |
| 3550 | public boolean isInContentBounds(float y) { |
| 3551 | return y < getHeight() - getEmptyBottomMargin(); |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 3552 | } |
| 3553 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3554 | private void setIsBeingDragged(boolean isDragged) { |
| 3555 | mIsBeingDragged = isDragged; |
| 3556 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3557 | requestDisallowInterceptTouchEvent(true); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3558 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | @Override |
| 3563 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 3564 | super.onWindowFocusChanged(hasWindowFocus); |
| 3565 | if (!hasWindowFocus) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3566 | cancelLongPress(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3567 | } |
| 3568 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 3569 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 3570 | @Override |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 3571 | public void clearChildFocus(View child) { |
| 3572 | super.clearChildFocus(child); |
| 3573 | if (mForcedScroll == child) { |
| 3574 | mForcedScroll = null; |
| 3575 | } |
| 3576 | } |
| 3577 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 3578 | public void requestDisallowLongPress() { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3579 | cancelLongPress(); |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Adrian Roos | fa13975 | 2016-04-27 09:59:08 -0700 | [diff] [blame] | 3582 | public void requestDisallowDismiss() { |
| 3583 | mDisallowDismissInThisMotion = true; |
| 3584 | } |
| 3585 | |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 3586 | public void cancelLongPress() { |
| 3587 | mSwipeHelper.cancelLongPress(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3588 | } |
| 3589 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 3590 | @Override |
| 3591 | public boolean isScrolledToTop() { |
| 3592 | return mOwnScrollY == 0; |
| 3593 | } |
| 3594 | |
| 3595 | @Override |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3596 | public boolean isScrolledToBottom() { |
| 3597 | return mOwnScrollY >= getScrollRange(); |
| 3598 | } |
| 3599 | |
| 3600 | @Override |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 3601 | public View getHostView() { |
| 3602 | return this; |
| 3603 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 3604 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3605 | public int getEmptyBottomMargin() { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3606 | return Math.max(mMaxLayoutHeight - mContentHeight, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 3607 | } |
| 3608 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3609 | public void checkSnoozeLeavebehind() { |
| 3610 | if (mCheckForLeavebehind) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 3611 | mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */, |
| 3612 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 3613 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3614 | mCheckForLeavebehind = false; |
| 3615 | } |
| 3616 | } |
| 3617 | |
| 3618 | public void resetCheckSnoozeLeavebehind() { |
| 3619 | mCheckForLeavebehind = true; |
| 3620 | } |
| 3621 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3622 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3623 | mIsExpansionChanging = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3624 | mAmbientState.setExpansionChanging(true); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3625 | checkSnoozeLeavebehind(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3629 | mIsExpansionChanging = false; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 3630 | resetCheckSnoozeLeavebehind(); |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3631 | mAmbientState.setExpansionChanging(false); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 3632 | if (!mIsExpanded) { |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 3633 | setOwnScrollY(0); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 3634 | mStatusBar.resetUserExpandedStates(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3635 | clearTemporaryViews(); |
| 3636 | clearUserLockedViews(); |
| 3637 | } |
| 3638 | } |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 3639 | |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3640 | private void clearUserLockedViews() { |
| 3641 | for (int i = 0; i < getChildCount(); i++) { |
| 3642 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3643 | if (child instanceof ExpandableNotificationRow) { |
| 3644 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3645 | row.setUserLocked(false); |
| 3646 | } |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | private void clearTemporaryViews() { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3651 | // lets make sure nothing is transient anymore |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3652 | clearTemporaryViewsInGroup(this); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3653 | for (int i = 0; i < getChildCount(); i++) { |
| 3654 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3655 | if (child instanceof ExpandableNotificationRow) { |
| 3656 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3657 | clearTemporaryViewsInGroup(row.getChildrenContainer()); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3658 | } |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 3659 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3660 | } |
| 3661 | |
Rohan Shah | 8ee5365 | 2018-04-05 11:13:50 -0700 | [diff] [blame] | 3662 | private void clearTemporaryViewsInGroup(ViewGroup viewGroup) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3663 | while (viewGroup != null && viewGroup.getTransientViewCount() != 0) { |
Selim Cinek | 81f26d3 | 2016-05-09 18:54:10 -0400 | [diff] [blame] | 3664 | viewGroup.removeTransientView(viewGroup.getTransientView(0)); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 3665 | } |
| 3666 | } |
| 3667 | |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 3668 | public void onPanelTrackingStarted() { |
| 3669 | mPanelTracking = true; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3670 | mAmbientState.setPanelTracking(true); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 3671 | } |
| 3672 | public void onPanelTrackingStopped() { |
| 3673 | mPanelTracking = false; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 3674 | mAmbientState.setPanelTracking(false); |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 3677 | public void resetScrollPosition() { |
| 3678 | mScroller.abortAnimation(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 3679 | setOwnScrollY(0); |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 3682 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3683 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3684 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3685 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3686 | if (changed) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 3687 | if (!mIsExpanded) { |
| 3688 | mGroupManager.collapseAllGroups(); |
Selim Cinek | 5b1591a | 2017-07-03 17:05:01 +0200 | [diff] [blame] | 3689 | mExpandHelper.cancelImmediately(); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 3690 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3691 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3692 | updateChronometers(); |
Selim Cinek | f3fa685 | 2016-12-20 18:36:02 +0100 | [diff] [blame] | 3693 | requestChildrenUpdate(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | private void updateChronometers() { |
| 3698 | int childCount = getChildCount(); |
| 3699 | for (int i = 0; i < childCount; i++) { |
| 3700 | updateChronometerForChild(getChildAt(i)); |
| 3701 | } |
| 3702 | } |
| 3703 | |
| 3704 | private void updateChronometerForChild(View child) { |
| 3705 | if (child instanceof ExpandableNotificationRow) { |
| 3706 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 3707 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 3708 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 3709 | } |
| 3710 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3711 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3712 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3713 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3714 | updateScrollPositionOnExpandInBottom(view); |
| 3715 | clampScrollPosition(); |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 3716 | notifyHeightChangeListener(view, needsAnimation); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 3717 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 3718 | ? (ExpandableNotificationRow) view |
| 3719 | : null; |
| 3720 | if (row != null && (row == mFirstVisibleBackgroundChild |
| 3721 | || row.getNotificationParent() == mFirstVisibleBackgroundChild)) { |
| 3722 | updateAlgorithmLayoutMinHeight(); |
| 3723 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3724 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 3725 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3726 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3727 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3728 | } |
| 3729 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3730 | @Override |
| 3731 | public void onReset(ExpandableView view) { |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 3732 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 3733 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3734 | } |
| 3735 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3736 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
Selim Cinek | 51d2197 | 2017-07-19 17:39:20 -0700 | [diff] [blame] | 3737 | if (view instanceof ExpandableNotificationRow && !onKeyguard()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3738 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 3739 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 3740 | if (row.isSummaryWithChildren()) { |
| 3741 | return; |
| 3742 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3743 | // We are actually expanding this view |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 3744 | float endPosition = row.getTranslationY() + row.getActualHeight(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 3745 | if (row.isChildInGroup()) { |
Selim Cinek | 4e4cac3 | 2016-03-11 16:45:52 -0800 | [diff] [blame] | 3746 | endPosition += row.getNotificationParent().getTranslationY(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 3747 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3748 | int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation; |
Anthony Chen | 9e05d46 | 2017-04-07 10:10:21 -0700 | [diff] [blame] | 3749 | if (row != mLastVisibleBackgroundChild && mShelf.getVisibility() != GONE) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 3750 | layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements; |
| 3751 | } |
| 3752 | if (endPosition > layoutEnd) { |
| 3753 | setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd)); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 3754 | mDisallowScrollingInThisMotion = true; |
| 3755 | } |
| 3756 | } |
| 3757 | } |
| 3758 | } |
| 3759 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 3760 | public void setOnHeightChangedListener( |
| 3761 | ExpandableView.OnHeightChangedListener mOnHeightChangedListener) { |
| 3762 | this.mOnHeightChangedListener = mOnHeightChangedListener; |
| 3763 | } |
| 3764 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 3765 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 3766 | mOnEmptySpaceClickListener = listener; |
| 3767 | } |
| 3768 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3769 | public void onChildAnimationFinished() { |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3770 | setAnimationRunning(false); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 3771 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 3772 | runAnimationFinishedRunnables(); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3773 | clearTransient(); |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 3774 | clearHeadsUpDisappearRunning(); |
| 3775 | } |
| 3776 | |
| 3777 | private void clearHeadsUpDisappearRunning() { |
| 3778 | for (int i = 0; i < getChildCount(); i++) { |
| 3779 | View view = getChildAt(i); |
| 3780 | if (view instanceof ExpandableNotificationRow) { |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3781 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3782 | row.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3783 | if (row.isSummaryWithChildren()) { |
| 3784 | for (ExpandableNotificationRow child : row.getNotificationChildren()) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 3785 | child.setHeadsUpAnimatingAway(false); |
Selim Cinek | 76e813c | 2016-07-14 11:16:58 -0700 | [diff] [blame] | 3786 | } |
| 3787 | } |
Selim Cinek | 8fc7875 | 2016-07-13 14:34:56 -0700 | [diff] [blame] | 3788 | } |
| 3789 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3792 | private void clearTransient() { |
| 3793 | for (ExpandableView view : mClearTransientViewsWhenFinished) { |
| 3794 | StackStateAnimator.removeTransientView(view); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 3795 | } |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 3796 | mClearTransientViewsWhenFinished.clear(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3800 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 3801 | runnable.run(); |
| 3802 | } |
| 3803 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3804 | } |
| 3805 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3806 | /** |
| 3807 | * See {@link AmbientState#setDimmed}. |
| 3808 | */ |
| 3809 | public void setDimmed(boolean dimmed, boolean animate) { |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 3810 | dimmed &= onKeyguard(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3811 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3812 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3813 | mDimmedNeedsAnimation = true; |
| 3814 | mNeedsAnimation = true; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 3815 | animateDimmed(dimmed); |
| 3816 | } else { |
| 3817 | setDimAmount(dimmed ? 1.0f : 0.0f); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3818 | } |
| 3819 | requestChildrenUpdate(); |
| 3820 | } |
| 3821 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 3822 | @VisibleForTesting |
| 3823 | boolean isDimmed() { |
| 3824 | return mAmbientState.isDimmed(); |
| 3825 | } |
| 3826 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 3827 | private void setDimAmount(float dimAmount) { |
| 3828 | mDimAmount = dimAmount; |
| 3829 | updateBackgroundDimming(); |
| 3830 | } |
| 3831 | |
| 3832 | private void animateDimmed(boolean dimmed) { |
| 3833 | if (mDimAnimator != null) { |
| 3834 | mDimAnimator.cancel(); |
| 3835 | } |
| 3836 | float target = dimmed ? 1.0f : 0.0f; |
| 3837 | if (target == mDimAmount) { |
| 3838 | return; |
| 3839 | } |
| 3840 | mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target); |
| 3841 | mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED); |
| 3842 | mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 3843 | mDimAnimator.addListener(mDimEndListener); |
| 3844 | mDimAnimator.addUpdateListener(mDimUpdateListener); |
| 3845 | mDimAnimator.start(); |
| 3846 | } |
| 3847 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3848 | public void setHideSensitive(boolean hideSensitive, boolean animate) { |
| 3849 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 3850 | int childCount = getChildCount(); |
| 3851 | for (int i = 0; i < childCount; i++) { |
| 3852 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 3853 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 3854 | } |
| 3855 | mAmbientState.setHideSensitive(hideSensitive); |
| 3856 | if (animate && mAnimationsEnabled) { |
| 3857 | mHideSensitiveNeedsAnimation = true; |
| 3858 | mNeedsAnimation = true; |
| 3859 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 3860 | updateContentHeight(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3861 | requestChildrenUpdate(); |
| 3862 | } |
| 3863 | } |
| 3864 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3865 | /** |
| 3866 | * See {@link AmbientState#setActivatedChild}. |
| 3867 | */ |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 3868 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3869 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 3870 | if (mAnimationsEnabled) { |
| 3871 | mActivateNeedsAnimation = true; |
| 3872 | mNeedsAnimation = true; |
| 3873 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3874 | requestChildrenUpdate(); |
| 3875 | } |
| 3876 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 3877 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3878 | return mAmbientState.getActivatedChild(); |
| 3879 | } |
| 3880 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3881 | private void applyCurrentState() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3882 | mCurrentStackScrollState.apply(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3883 | if (mListener != null) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 3884 | mListener.onChildLocationsChanged(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 3885 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 3886 | runAnimationFinishedRunnables(); |
Selim Cinek | ea66ca0 | 2016-05-24 13:33:47 -0700 | [diff] [blame] | 3887 | setAnimationRunning(false); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3888 | updateBackground(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3889 | updateViewShadows(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 3890 | updateClippingToTopRoundedCorner(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | private void updateViewShadows() { |
| 3894 | // we need to work around an issue where the shadow would not cast between siblings when |
| 3895 | // their z difference is between 0 and 0.1 |
| 3896 | |
| 3897 | // Lefts first sort by Z difference |
| 3898 | for (int i = 0; i < getChildCount(); i++) { |
| 3899 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 3900 | if (child.getVisibility() != GONE) { |
| 3901 | mTmpSortedChildren.add(child); |
| 3902 | } |
| 3903 | } |
| 3904 | Collections.sort(mTmpSortedChildren, mViewPositionComparator); |
| 3905 | |
| 3906 | // Now lets update the shadow for the views |
| 3907 | ExpandableView previous = null; |
| 3908 | for (int i = 0; i < mTmpSortedChildren.size(); i++) { |
| 3909 | ExpandableView expandableView = mTmpSortedChildren.get(i); |
| 3910 | float translationZ = expandableView.getTranslationZ(); |
| 3911 | float otherZ = previous == null ? translationZ : previous.getTranslationZ(); |
| 3912 | float diff = otherZ - translationZ; |
| 3913 | if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) { |
| 3914 | // There is no fake shadow to be drawn |
| 3915 | expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
| 3916 | } else { |
| 3917 | float yLocation = previous.getTranslationY() + previous.getActualHeight() - |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 3918 | expandableView.getTranslationY() - previous.getExtraBottomPadding(); |
| 3919 | expandableView.setFakeShadowIntensity( |
| 3920 | diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD, |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 3921 | previous.getOutlineAlpha(), (int) yLocation, |
| 3922 | previous.getOutlineTranslation()); |
| 3923 | } |
| 3924 | previous = expandableView; |
| 3925 | } |
| 3926 | |
| 3927 | mTmpSortedChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3928 | } |
| 3929 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 3930 | /** |
| 3931 | * Update colors of "dismiss" and "empty shade" views. |
| 3932 | * |
| 3933 | * @param lightTheme True if light theme should be used. |
| 3934 | */ |
| 3935 | public void updateDecorViews(boolean lightTheme) { |
| 3936 | if (lightTheme == mUsingLightTheme) { |
| 3937 | return; |
| 3938 | } |
| 3939 | mUsingLightTheme = lightTheme; |
| 3940 | Context context = new ContextThemeWrapper(mContext, |
| 3941 | lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI); |
| 3942 | final int textColor = Utils.getColorAttr(context, R.attr.wallpaperTextColor); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 3943 | mFooterView.setTextColor(textColor); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 3944 | mEmptyShadeView.setTextColor(textColor); |
| 3945 | } |
| 3946 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3947 | public void goToFullShade(long delay) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3948 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 3949 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3950 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3951 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 3952 | } |
| 3953 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3954 | public void cancelExpandHelper() { |
| 3955 | mExpandHelper.cancel(); |
| 3956 | } |
| 3957 | |
| 3958 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 3959 | mIntrinsicPadding = intrinsicPadding; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 3960 | mAmbientState.setIntrinsicPadding(intrinsicPadding); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 3961 | } |
| 3962 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 3963 | public int getIntrinsicPadding() { |
| 3964 | return mIntrinsicPadding; |
| 3965 | } |
| 3966 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 3967 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 3968 | * @return the y position of the first notification |
| 3969 | */ |
| 3970 | public float getNotificationsTopY() { |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 3971 | return mTopPadding + getStackTranslation(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 3972 | } |
| 3973 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 3974 | @Override |
| 3975 | public boolean shouldDelayChildPressedState() { |
| 3976 | return true; |
| 3977 | } |
| 3978 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 3979 | /** |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3980 | * See {@link AmbientState#setDark}. |
| 3981 | */ |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3982 | public void setDark(boolean dark, boolean animate, @Nullable PointF touchWakeUpScreenLocation) { |
Adrian Roos | 260c1f7 | 2017-08-07 15:52:26 +0200 | [diff] [blame] | 3983 | if (mAmbientState.isDark() == dark) { |
| 3984 | return; |
| 3985 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3986 | mAmbientState.setDark(dark); |
| 3987 | if (animate && mAnimationsEnabled) { |
| 3988 | mDarkNeedsAnimation = true; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3989 | mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 3990 | mNeedsAnimation = true; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3991 | } else { |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 3992 | setDarkAmount(dark ? 1f : 0f); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3993 | updateBackground(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 3994 | } |
Lucas Dupin | 8e9fa2d | 2018-01-29 15:36:35 -0800 | [diff] [blame] | 3995 | requestChildrenUpdate(); |
| 3996 | applyCurrentBackgroundBounds(); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 3997 | updateWillNotDraw(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 3998 | notifyHeightChangeListener(mShelf); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3999 | } |
| 4000 | |
Bill Lin | 278e7d6 | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4001 | private void updatePanelTranslation() { |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4002 | setTranslationX(mVerticalPanelTranslation + mAntiBurnInOffsetX * mInterpolatedDarkAmount); |
Bill Lin | 278e7d6 | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | public void setVerticalPanelTranslation(float verticalPanelTranslation) { |
| 4006 | mVerticalPanelTranslation = verticalPanelTranslation; |
| 4007 | updatePanelTranslation(); |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 4008 | } |
| 4009 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4010 | /** |
| 4011 | * Updates whether or not this Layout will perform its own custom drawing (i.e. whether or |
| 4012 | * not {@link #onDraw(Canvas)} is called). This method should be called whenever the |
| 4013 | * {@link #mAmbientState}'s dark mode is toggled. |
| 4014 | */ |
| 4015 | private void updateWillNotDraw() { |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4016 | boolean willDraw = mShouldDrawNotificationBackground || DEBUG; |
Adrian Roos | f0b4f96 | 2017-05-25 11:53:11 -0700 | [diff] [blame] | 4017 | setWillNotDraw(!willDraw); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4018 | } |
| 4019 | |
Lucas Dupin | d285cf0 | 2018-01-18 09:18:23 -0800 | [diff] [blame] | 4020 | private void setDarkAmount(float darkAmount) { |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4021 | setDarkAmount(darkAmount, darkAmount); |
| 4022 | } |
| 4023 | |
| 4024 | /** |
| 4025 | * Sets the current dark amount. |
| 4026 | * |
| 4027 | * @param linearDarkAmount The dark amount that follows linear interpoloation in the animation, |
| 4028 | * i.e. animates from 0 to 1 or vice-versa in a linear manner. |
| 4029 | * @param interpolatedDarkAmount The dark amount that follows the actual interpolation of the |
| 4030 | * animation curve. |
| 4031 | */ |
| 4032 | public void setDarkAmount(float linearDarkAmount, float interpolatedDarkAmount) { |
| 4033 | mLinearDarkAmount = linearDarkAmount; |
| 4034 | mInterpolatedDarkAmount = interpolatedDarkAmount; |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4035 | boolean wasFullyDark = mAmbientState.isFullyDark(); |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4036 | mAmbientState.setDarkAmount(interpolatedDarkAmount); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4037 | boolean nowFullyDark = mAmbientState.isFullyDark(); |
| 4038 | if (nowFullyDark != wasFullyDark) { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4039 | updateContentHeight(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4040 | DozeParameters dozeParameters = DozeParameters.getInstance(mContext); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4041 | if (nowFullyDark && dozeParameters.shouldControlScreenOff()) { |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4042 | mShelf.fadeInTranslating(); |
| 4043 | } |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4044 | if (mIconAreaController != null) { |
| 4045 | mIconAreaController.setFullyDark(nowFullyDark); |
| 4046 | } |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4047 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 4048 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4049 | updateBackgroundDimming(); |
Bill Lin | 278e7d6 | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4050 | updatePanelTranslation(); |
Lucas Dupin | b561eda | 2018-04-09 17:25:04 -0700 | [diff] [blame] | 4051 | requestChildrenUpdate(); |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4054 | public void notifyDarkAnimationStart(boolean dark) { |
| 4055 | // We only swap the scaling factor if we're fully dark or fully awake to avoid |
| 4056 | // interpolation issues when playing with the power button. |
| 4057 | if (mInterpolatedDarkAmount == 0 || mInterpolatedDarkAmount == 1) { |
| 4058 | mBackgroundXFactor = dark ? 1.8f : 1.5f; |
| 4059 | mDarkXInterpolator = dark |
| 4060 | ? Interpolators.FAST_OUT_SLOW_IN_REVERSE |
| 4061 | : Interpolators.FAST_OUT_SLOW_IN; |
| 4062 | } |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4063 | } |
| 4064 | |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4065 | public long getDarkAnimationDuration(boolean dark) { |
Lucas Dupin | 439bd44 | 2018-06-12 15:05:28 -0700 | [diff] [blame] | 4066 | long duration = StackStateAnimator.ANIMATION_DURATION_WAKEUP; |
| 4067 | // Longer animation when sleeping with more than 1 notification |
| 4068 | if (dark && getNotGoneChildCount() > 2) { |
| 4069 | duration *= 1.2f; |
| 4070 | } |
Jorim Jaggi | c4cf07a | 2018-07-05 18:28:12 +0200 | [diff] [blame] | 4071 | return duration; |
Selim Cinek | 972123d | 2016-05-03 14:25:58 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4074 | private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) { |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4075 | if (screenLocation == null || screenLocation.y < mTopPadding) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 4076 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4077 | } |
| 4078 | if (screenLocation.y > getBottomMostNotificationBottom()) { |
| 4079 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW; |
| 4080 | } |
| 4081 | View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y); |
| 4082 | if (child != null) { |
| 4083 | return getNotGoneIndex(child); |
| 4084 | } else { |
| 4085 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | private int getNotGoneIndex(View child) { |
| 4090 | int count = getChildCount(); |
| 4091 | int notGoneIndex = 0; |
| 4092 | for (int i = 0; i < count; i++) { |
| 4093 | View v = getChildAt(i); |
| 4094 | if (child == v) { |
| 4095 | return notGoneIndex; |
| 4096 | } |
| 4097 | if (v.getVisibility() != View.GONE) { |
| 4098 | notGoneIndex++; |
| 4099 | } |
| 4100 | } |
| 4101 | return -1; |
| 4102 | } |
| 4103 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4104 | public void setFooterView(@NonNull FooterView footerView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4105 | int index = -1; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4106 | if (mFooterView != null) { |
| 4107 | index = indexOfChild(mFooterView); |
| 4108 | removeView(mFooterView); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4109 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4110 | mFooterView = footerView; |
| 4111 | addView(mFooterView, index); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4112 | } |
| 4113 | |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4114 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4115 | int index = -1; |
| 4116 | if (mEmptyShadeView != null) { |
| 4117 | index = indexOfChild(mEmptyShadeView); |
| 4118 | removeView(mEmptyShadeView); |
| 4119 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4120 | mEmptyShadeView = emptyShadeView; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 4121 | addView(mEmptyShadeView, index); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | public void updateEmptyShadeView(boolean visible) { |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4125 | mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled); |
Lucas Dupin | c9274ff | 2018-05-09 17:40:20 -0700 | [diff] [blame] | 4126 | |
| 4127 | int oldTextRes = mEmptyShadeView.getTextResource(); |
| 4128 | int newTextRes = mStatusBar.areNotificationsHidden() |
| 4129 | ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text; |
| 4130 | if (oldTextRes != newTextRes) { |
| 4131 | mEmptyShadeView.setText(newTextRes); |
| 4132 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 4133 | } |
| 4134 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4135 | public void updateFooterView(boolean visible, boolean showDismissView) { |
| 4136 | if (mFooterView == null) { |
Anthony Chen | 5e3742e | 2017-04-07 14:28:44 -0700 | [diff] [blame] | 4137 | return; |
| 4138 | } |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 4139 | boolean animate = mIsExpanded && mAnimationsEnabled; |
| 4140 | mFooterView.setVisible(visible, animate); |
| 4141 | mFooterView.setSecondaryVisible(showDismissView, animate); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 4145 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4146 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 4147 | handleDismissAllClipping(); |
| 4148 | } |
| 4149 | |
| 4150 | private void handleDismissAllClipping() { |
| 4151 | final int count = getChildCount(); |
| 4152 | boolean previousChildWillBeDismissed = false; |
| 4153 | for (int i = 0; i < count; i++) { |
| 4154 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4155 | if (child.getVisibility() == GONE) { |
| 4156 | continue; |
| 4157 | } |
| 4158 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 4159 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 4160 | } else { |
| 4161 | child.setMinClipTopAmount(0); |
| 4162 | } |
| 4163 | previousChildWillBeDismissed = canChildBeDismissed(child); |
| 4164 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 4165 | } |
| 4166 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4167 | public boolean isFooterViewNotGone() { |
| 4168 | return mFooterView != null |
| 4169 | && mFooterView.getVisibility() != View.GONE |
| 4170 | && !mFooterView.willBeGone(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4171 | } |
| 4172 | |
Selim Cinek | 3847544 | 2018-05-18 11:11:46 -0700 | [diff] [blame] | 4173 | public boolean isFooterViewContentVisible() { |
| 4174 | return mFooterView != null && mFooterView.isContentVisible(); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4175 | } |
| 4176 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4177 | public int getFooterViewHeight() { |
| 4178 | return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 4179 | } |
| 4180 | |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 4181 | public int getEmptyShadeViewHeight() { |
| 4182 | return mEmptyShadeView.getHeight(); |
| 4183 | } |
| 4184 | |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4185 | public float getBottomMostNotificationBottom() { |
| 4186 | final int count = getChildCount(); |
| 4187 | float max = 0; |
| 4188 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 4189 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 4190 | if (child.getVisibility() == GONE) { |
| 4191 | continue; |
| 4192 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4193 | float bottom = child.getTranslationY() + child.getActualHeight() |
| 4194 | - child.getClipBottomAmount(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4195 | if (bottom > max) { |
| 4196 | max = bottom; |
| 4197 | } |
| 4198 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 4199 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 4200 | } |
| 4201 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4202 | public void setStatusBar(StatusBar statusBar) { |
| 4203 | this.mStatusBar = statusBar; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 4204 | } |
| 4205 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4206 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 4207 | this.mGroupManager = groupManager; |
| 4208 | } |
| 4209 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4210 | public void onGoToKeyguard() { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4211 | requestAnimateEverything(); |
| 4212 | } |
| 4213 | |
| 4214 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4215 | if (mIsExpanded && mAnimationsEnabled) { |
| 4216 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 4217 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 4218 | requestChildrenUpdate(); |
| 4219 | } |
| 4220 | } |
| 4221 | |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4222 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4223 | int childCount = getChildCount(); |
| 4224 | for (int i = childCount - 1; i >= 0; i--) { |
| 4225 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 4226 | if (child.getVisibility() != View.GONE) { |
| 4227 | float childTop = child.getY(); |
| 4228 | if (childTop > touchY) { |
| 4229 | // we are above a notification entirely let's abort |
| 4230 | return false; |
| 4231 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 4232 | boolean belowChild = touchY > childTop + child.getActualHeight() |
| 4233 | - child.getClipBottomAmount(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 4234 | if (child == mFooterView) { |
| 4235 | if(!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(), |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 4236 | touchY - childTop)) { |
| 4237 | // We clicked on the dismiss button |
| 4238 | return false; |
| 4239 | } |
| 4240 | } else if (child == mEmptyShadeView) { |
| 4241 | // We arrived at the empty shade view, for which we accept all clicks |
| 4242 | return true; |
| 4243 | } else if (!belowChild){ |
| 4244 | // We are on a child |
| 4245 | return false; |
| 4246 | } |
| 4247 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4248 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 4249 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4250 | } |
| 4251 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4252 | @Override |
| 4253 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 4254 | boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled |
| 4255 | && (mIsExpanded || changedRow.isPinned()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4256 | if (animated) { |
| 4257 | mExpandedGroupView = changedRow; |
| 4258 | mNeedsAnimation = true; |
| 4259 | } |
| 4260 | changedRow.setChildrenExpanded(expanded, animated); |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 4261 | if (!mGroupExpandedForMeasure) { |
| 4262 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 4263 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 4264 | runAfterAnimationFinished(new Runnable() { |
| 4265 | @Override |
| 4266 | public void run() { |
| 4267 | changedRow.onFinishedExpansionChange(); |
| 4268 | } |
| 4269 | }); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4273 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4274 | mStatusBar.requestNotificationUpdate(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 4275 | } |
| 4276 | |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4277 | /** @hide */ |
| 4278 | @Override |
| 4279 | public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
| 4280 | super.onInitializeAccessibilityEventInternal(event); |
| 4281 | event.setScrollable(mScrollable); |
| 4282 | event.setScrollX(mScrollX); |
| 4283 | event.setScrollY(mOwnScrollY); |
| 4284 | event.setMaxScrollX(mScrollX); |
| 4285 | event.setMaxScrollY(getScrollRange()); |
| 4286 | } |
| 4287 | |
| 4288 | @Override |
| 4289 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 4290 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4291 | if (mScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4292 | info.setScrollable(true); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4293 | if (mBackwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4294 | info.addAction( |
| 4295 | AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD); |
| 4296 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP); |
| 4297 | } |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4298 | if (mForwardScrollable) { |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4299 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD); |
| 4300 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN); |
| 4301 | } |
| 4302 | } |
Selim Cinek | 41fe89a | 2016-06-02 15:27:56 -0700 | [diff] [blame] | 4303 | // Talkback only listenes to scroll events of certain classes, let's make us a scrollview |
| 4304 | info.setClassName(ScrollView.class.getName()); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | /** @hide */ |
| 4308 | @Override |
| 4309 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 4310 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 4311 | return true; |
| 4312 | } |
| 4313 | if (!isEnabled()) { |
| 4314 | return false; |
| 4315 | } |
| 4316 | int direction = -1; |
| 4317 | switch (action) { |
| 4318 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 4319 | // fall through |
| 4320 | case android.R.id.accessibilityActionScrollDown: |
| 4321 | direction = 1; |
| 4322 | // fall through |
| 4323 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 4324 | // fall through |
| 4325 | case android.R.id.accessibilityActionScrollUp: |
| 4326 | final int viewportHeight = getHeight() - mPaddingBottom - mTopPadding - mPaddingTop |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 4327 | - mShelf.getIntrinsicHeight(); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4328 | final int targetScrollY = Math.max(0, |
| 4329 | Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange())); |
| 4330 | if (targetScrollY != mOwnScrollY) { |
| 4331 | mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScrollY - mOwnScrollY); |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 4332 | animateScroll(); |
Selim Cinek | c22fff6 | 2016-05-20 12:44:30 -0700 | [diff] [blame] | 4333 | return true; |
| 4334 | } |
| 4335 | break; |
| 4336 | } |
| 4337 | return false; |
| 4338 | } |
| 4339 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 4340 | @Override |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 4341 | public void onGroupsChanged() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4342 | mStatusBar.requestNotificationUpdate(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | public void generateChildOrderChangedEvent() { |
| 4346 | if (mIsExpanded && mAnimationsEnabled) { |
| 4347 | mGenerateChildOrderChangedEvent = true; |
| 4348 | mNeedsAnimation = true; |
| 4349 | requestChildrenUpdate(); |
| 4350 | } |
| 4351 | } |
| 4352 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4353 | @Override |
| 4354 | public int getContainerChildCount() { |
| 4355 | return getChildCount(); |
| 4356 | } |
| 4357 | |
| 4358 | @Override |
| 4359 | public View getContainerChildAt(int i) { |
| 4360 | return getChildAt(i); |
| 4361 | } |
| 4362 | |
| 4363 | @Override |
| 4364 | public void removeContainerView(View v) { |
| 4365 | removeView(v); |
| 4366 | } |
| 4367 | |
| 4368 | @Override |
| 4369 | public void addContainerView(View v) { |
| 4370 | addView(v); |
| 4371 | } |
| 4372 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 4373 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4374 | mAnimationFinishedRunnables.add(runnable); |
| 4375 | } |
| 4376 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 4377 | public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4378 | mHeadsUpManager = headsUpManager; |
| 4379 | mAmbientState.setHeadsUpManager(headsUpManager); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 4380 | mHeadsUpManager.addListener(mRoundnessManager); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 4384 | if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4385 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 4386 | mNeedsAnimation = true; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 4387 | if (!mIsExpanded && !isHeadsUp) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4388 | row.setHeadsUpAnimatingAway(true); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 4389 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4390 | requestChildrenUpdate(); |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | public void setShadeExpanded(boolean shadeExpanded) { |
| 4395 | mAmbientState.setShadeExpanded(shadeExpanded); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 4396 | mStateAnimator.setShadeExpanded(shadeExpanded); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4397 | } |
| 4398 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 4399 | /** |
| 4400 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 4401 | * position. |
| 4402 | * |
| 4403 | * @param height the height of the screen |
| 4404 | * @param bottomBarHeight the height of the bar on the bottom |
| 4405 | */ |
| 4406 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 4407 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 4408 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4409 | requestChildrenUpdate(); |
| 4410 | } |
| 4411 | |
Selim Cinek | aa9db1f3 | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 4412 | public void setTrackingHeadsUp(ExpandableNotificationRow row) { |
| 4413 | mTrackingHeadsUp = row != null; |
| 4414 | mRoundnessManager.setTrackingHeadsUp(row); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 4417 | public void setScrimController(ScrimController scrimController) { |
| 4418 | mScrimController = scrimController; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 4419 | mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 4422 | public void forceNoOverlappingRendering(boolean force) { |
| 4423 | mForceNoOverlappingRendering = force; |
| 4424 | } |
| 4425 | |
| 4426 | @Override |
| 4427 | public boolean hasOverlappingRendering() { |
| 4428 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 4429 | } |
| 4430 | |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4431 | public void setAnimationRunning(boolean animationRunning) { |
| 4432 | if (animationRunning != mAnimationRunning) { |
| 4433 | if (animationRunning) { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 4434 | getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4435 | } else { |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 4436 | getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4437 | } |
| 4438 | mAnimationRunning = animationRunning; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4439 | updateContinuousShadowDrawing(); |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 4443 | public boolean isExpanded() { |
| 4444 | return mIsExpanded; |
| 4445 | } |
| 4446 | |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 4447 | public void setPulsing(boolean pulsing, boolean animated) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 4448 | if (!mPulsing && !pulsing) { |
Adrian Roos | b2a8729 | 2017-02-13 15:05:03 +0100 | [diff] [blame] | 4449 | return; |
| 4450 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 4451 | mPulsing = pulsing; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 4452 | mNeedingPulseAnimation = animated ? getFirstChildNotGone() : null; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 4453 | mAmbientState.setPulsing(pulsing); |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 4454 | updateNotificationAnimationStates(); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 4455 | updateAlgorithmHeightAndPadding(); |
Adrian Roos | 7a9551a | 2017-01-11 12:27:49 -0800 | [diff] [blame] | 4456 | updateContentHeight(); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4457 | requestChildrenUpdate(); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 4458 | notifyHeightChangeListener(null, animated); |
| 4459 | mNeedsAnimation |= animated; |
| 4460 | } |
| 4461 | |
| 4462 | private void generatePulsingAnimationEvent() { |
| 4463 | if (mNeedingPulseAnimation != null) { |
| 4464 | int type = mPulsing ? AnimationEvent.ANIMATION_TYPE_PULSE_APPEAR |
| 4465 | : AnimationEvent.ANIMATION_TYPE_PULSE_DISAPPEAR; |
| 4466 | mAnimationEvents.add(new AnimationEvent(mNeedingPulseAnimation, type)); |
| 4467 | mNeedingPulseAnimation = null; |
| 4468 | } |
Selim Cinek | cd5b22f | 2016-03-08 16:15:41 -0800 | [diff] [blame] | 4469 | } |
| 4470 | |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4471 | public void setFadingOut(boolean fadingOut) { |
| 4472 | if (fadingOut != mFadingOut) { |
| 4473 | mFadingOut = fadingOut; |
| 4474 | updateFadingState(); |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 4475 | } |
| 4476 | } |
| 4477 | |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 4478 | public void setParentNotFullyVisible(boolean parentNotFullyVisible) { |
| 4479 | if (mScrimController == null) { |
| 4480 | // we're not set up yet. |
| 4481 | return; |
| 4482 | } |
| 4483 | if (parentNotFullyVisible != mParentNotFullyVisible) { |
| 4484 | mParentNotFullyVisible = parentNotFullyVisible; |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4485 | updateFadingState(); |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | private void updateFadingState() { |
Selim Cinek | 9bfba9c | 2016-08-08 15:20:06 -0700 | [diff] [blame] | 4490 | applyCurrentBackgroundBounds(); |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4491 | updateSrcDrawing(); |
| 4492 | } |
| 4493 | |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 4494 | @Override |
| 4495 | public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) { |
| 4496 | super.setAlpha(alpha); |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 4497 | setFadingOut(alpha != 1.0f); |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4500 | public void setQsExpanded(boolean qsExpanded) { |
| 4501 | mQsExpanded = qsExpanded; |
| 4502 | updateAlgorithmLayoutMinHeight(); |
Riddle Hsu | 065c01c | 2018-05-10 23:14:19 +0800 | [diff] [blame] | 4503 | updateScrollability(); |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4506 | public void setQsExpansionFraction(float qsExpansionFraction) { |
| 4507 | mQsExpansionFraction = qsExpansionFraction; |
| 4508 | } |
| 4509 | |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4510 | public void setOwnScrollY(int ownScrollY) { |
| 4511 | if (ownScrollY != mOwnScrollY) { |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 4512 | // We still want to call the normal scrolled changed for accessibility reasons |
| 4513 | onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4514 | mOwnScrollY = ownScrollY; |
| 4515 | updateForwardAndBackwardScrollability(); |
Selim Cinek | 9212de8 | 2017-02-06 16:04:28 -0800 | [diff] [blame] | 4516 | requestChildrenUpdate(); |
Selim Cinek | ef40606 | 2016-09-29 17:33:13 -0700 | [diff] [blame] | 4517 | } |
| 4518 | } |
| 4519 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4520 | public void setShelf(NotificationShelf shelf) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4521 | int index = -1; |
| 4522 | if (mShelf != null) { |
| 4523 | index = indexOfChild(mShelf); |
| 4524 | removeView(mShelf); |
| 4525 | } |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 4526 | mShelf = shelf; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4527 | addView(mShelf, index); |
| 4528 | mAmbientState.setShelf(shelf); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 4529 | mStateAnimator.setShelf(shelf); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 4530 | shelf.bind(mAmbientState, this); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | public NotificationShelf getNotificationShelf() { |
| 4534 | return mShelf; |
| 4535 | } |
| 4536 | |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 4537 | public void setMaxDisplayedNotifications(int maxDisplayedNotifications) { |
| 4538 | if (mMaxDisplayedNotifications != maxDisplayedNotifications) { |
| 4539 | mMaxDisplayedNotifications = maxDisplayedNotifications; |
| 4540 | updateContentHeight(); |
| 4541 | notifyHeightChangeListener(mShelf); |
| 4542 | } |
| 4543 | } |
| 4544 | |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4545 | public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) { |
| 4546 | mShouldShowShelfOnly = shouldShowShelfOnly; |
| 4547 | updateAlgorithmLayoutMinHeight(); |
| 4548 | } |
| 4549 | |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 4550 | public int getMinExpansionHeight() { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 4551 | return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2; |
Selim Cinek | 48ff9b4 | 2016-11-09 19:31:51 -0800 | [diff] [blame] | 4552 | } |
| 4553 | |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 4554 | public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) { |
| 4555 | mInHeadsUpPinnedMode = inHeadsUpPinnedMode; |
| 4556 | updateClipping(); |
| 4557 | } |
| 4558 | |
| 4559 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 4560 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
| 4561 | updateClipping(); |
| 4562 | } |
| 4563 | |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 4564 | public void setStatusBarState(int statusBarState) { |
| 4565 | mStatusBarState = statusBarState; |
| 4566 | mAmbientState.setStatusBarState(statusBarState); |
| 4567 | } |
| 4568 | |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 4569 | public void setExpandingVelocity(float expandingVelocity) { |
| 4570 | mAmbientState.setExpandingVelocity(expandingVelocity); |
| 4571 | } |
| 4572 | |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 4573 | public float getOpeningHeight() { |
| 4574 | if (mEmptyShadeView.getVisibility() == GONE) { |
| 4575 | return getMinExpansionHeight(); |
| 4576 | } else { |
| 4577 | return getAppearEndPosition(); |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | public void setIsFullWidth(boolean isFullWidth) { |
| 4582 | mAmbientState.setPanelFullWidth(isFullWidth); |
| 4583 | } |
| 4584 | |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 4585 | public void setUnlockHintRunning(boolean running) { |
| 4586 | mAmbientState.setUnlockHintRunning(running); |
| 4587 | } |
| 4588 | |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 4589 | public void setQsCustomizerShowing(boolean isShowing) { |
| 4590 | mAmbientState.setQsCustomizerShowing(isShowing); |
| 4591 | requestChildrenUpdate(); |
| 4592 | } |
| 4593 | |
| 4594 | public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) { |
| 4595 | mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed; |
| 4596 | } |
| 4597 | |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 4598 | public void setAntiBurnInOffsetX(int antiBurnInOffsetX) { |
| 4599 | mAntiBurnInOffsetX = antiBurnInOffsetX; |
Bill Lin | 278e7d6 | 2018-06-13 18:07:15 +0800 | [diff] [blame] | 4600 | updatePanelTranslation(); |
Adrian Roos | dc747bd | 2017-06-01 16:09:15 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4603 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 4604 | pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s" |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4605 | + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s" |
| 4606 | + " qsExpandFraction=%f]", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4607 | this.getClass().getSimpleName(), |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 4608 | mPulsing ? "T":"f", |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4609 | mAmbientState.isQsCustomizerShowing() ? "T":"f", |
| 4610 | getVisibility() == View.VISIBLE ? "visible" |
| 4611 | : getVisibility() == View.GONE ? "gone" |
| 4612 | : "invisible", |
| 4613 | getAlpha(), |
shawnlin | 8e4e92c | 2018-04-12 18:47:24 +0800 | [diff] [blame] | 4614 | mAmbientState.getScrollY(), |
| 4615 | mMaxTopPadding, |
| 4616 | mShouldShowShelfOnly ? "T":"f", |
| 4617 | mQsExpansionFraction)); |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 4618 | } |
| 4619 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 4620 | public boolean isFullyDark() { |
| 4621 | return mAmbientState.isFullyDark(); |
| 4622 | } |
| 4623 | |
Selim Cinek | 7103fd4 | 2016-05-09 22:22:33 -0400 | [diff] [blame] | 4624 | /** |
Selim Cinek | aa9db1f3 | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 4625 | * Add a listener whenever the expanded height changes. The first value passed as an argument |
| 4626 | * is the expanded height and the second one is the appearFraction. |
| 4627 | * |
| 4628 | * @param listener the listener to notify. |
| 4629 | */ |
| 4630 | public void addOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 4631 | mExpandedHeightListeners.add(listener); |
| 4632 | } |
| 4633 | |
| 4634 | /** |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 4635 | * Stop a listener from listening to the expandedHeight. |
| 4636 | */ |
| 4637 | public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) { |
| 4638 | mExpandedHeightListeners.remove(listener); |
| 4639 | } |
| 4640 | |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 4641 | public void setHeadsUpAppearanceController( |
| 4642 | HeadsUpAppearanceController headsUpAppearanceController) { |
| 4643 | mHeadsUpAppearanceController = headsUpAppearanceController; |
| 4644 | } |
| 4645 | |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 4646 | public void setIconAreaController(NotificationIconAreaController controller) { |
| 4647 | mIconAreaController = controller; |
| 4648 | } |
| 4649 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 4650 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4651 | * A listener that is notified when the empty space below the notifications is clicked on |
| 4652 | */ |
| 4653 | public interface OnEmptySpaceClickListener { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4654 | void onEmptySpaceClicked(float x, float y); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 4658 | * A listener that gets notified when the overscroll at the top has changed. |
| 4659 | */ |
| 4660 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 4661 | |
| 4662 | /** |
| 4663 | * Notifies a listener that the overscroll has changed. |
| 4664 | * |
| 4665 | * @param amount the amount of overscroll, in pixels |
| 4666 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 4667 | * unrubberbanded motion to directly expand overscroll view (e.g expand |
| 4668 | * QS) |
| 4669 | */ |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4670 | void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 4671 | |
| 4672 | /** |
| 4673 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 4674 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 4675 | * |
| 4676 | * @param velocity The velocity that the Scroller had when over flinging |
| 4677 | * @param open Should the fling open or close the overscroll view. |
| 4678 | */ |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 4679 | void flingTopOverscroll(float velocity, boolean open); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 4680 | } |
| 4681 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4682 | private class NotificationSwipeHelper extends SwipeHelper |
| 4683 | implements NotificationSwipeActionHelper { |
| 4684 | private static final long COVER_MENU_DELAY = 4000; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4685 | private Runnable mFalsingCheck; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4686 | private Handler mHandler; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4687 | |
| 4688 | public NotificationSwipeHelper(int swipeDirection, Callback callback, Context context) { |
| 4689 | super(swipeDirection, callback, context); |
| 4690 | mHandler = new Handler(); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4691 | mFalsingCheck = new Runnable() { |
| 4692 | @Override |
| 4693 | public void run() { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4694 | resetExposedMenuView(true /* animate */, true /* force */); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4695 | } |
| 4696 | }; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4700 | public void onDownUpdate(View currView, MotionEvent ev) { |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4701 | mTranslatingParentView = currView; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4702 | if (mCurrMenuRow != null) { |
| 4703 | mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */); |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4704 | } |
Mady Mellor | 89e15ec | 2017-06-28 17:08:21 -0700 | [diff] [blame] | 4705 | mCurrMenuRow = null; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4706 | mHandler.removeCallbacks(mFalsingCheck); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4707 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4708 | // Slide back any notifications that might be showing a menu |
| 4709 | resetExposedMenuView(true /* animate */, false /* force */); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4710 | |
| 4711 | if (currView instanceof ExpandableNotificationRow) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4712 | ExpandableNotificationRow row = (ExpandableNotificationRow) currView; |
| 4713 | mCurrMenuRow = row.createMenu(); |
| 4714 | mCurrMenuRow.setSwipeActionHelper(NotificationSwipeHelper.this); |
| 4715 | mCurrMenuRow.setMenuClickListener(NotificationStackScrollLayout.this); |
Mady Mellor | 89e15ec | 2017-06-28 17:08:21 -0700 | [diff] [blame] | 4716 | mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4717 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4721 | public void onMoveUpdate(View view, MotionEvent ev, float translation, float delta) { |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 4722 | mHandler.removeCallbacks(mFalsingCheck); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4723 | if (mCurrMenuRow != null) { |
| 4724 | mCurrMenuRow.onTouchEvent(view, ev, 0 /* velocity */); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4725 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4726 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4727 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4728 | @Override |
| 4729 | public boolean handleUpEvent(MotionEvent ev, View animView, float velocity, |
| 4730 | float translation) { |
| 4731 | if (mCurrMenuRow != null) { |
| 4732 | return mCurrMenuRow.onTouchEvent(animView, ev, velocity); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4733 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4734 | return false; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | @Override |
Mady Mellor | dc6c97d | 2016-03-31 14:18:35 -0700 | [diff] [blame] | 4738 | public void dismissChild(final View view, float velocity, |
| 4739 | boolean useAccelerateInterpolator) { |
| 4740 | super.dismissChild(view, velocity, useAccelerateInterpolator); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4741 | if (mIsExpanded) { |
| 4742 | // We don't want to quick-dismiss when it's a heads up as this might lead to closing |
| 4743 | // of the panel early. |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 4744 | handleChildViewDismissed(view); |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 4745 | } |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4746 | mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */, |
| 4747 | false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */, |
| 4748 | false /* resetMenu */); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4749 | handleMenuCoveredOrDismissed(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | @Override |
| 4753 | public void snapChild(final View animView, final float targetLeft, float velocity) { |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4754 | super.snapChild(animView, targetLeft, velocity); |
| 4755 | onDragCancelled(animView); |
| 4756 | if (targetLeft == 0) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4757 | handleMenuCoveredOrDismissed(); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4758 | } |
| 4759 | } |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4760 | |
| 4761 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4762 | public void snooze(StatusBarNotification sbn, SnoozeOption snoozeOption) { |
| 4763 | mStatusBar.setNotificationSnoozed(sbn, snoozeOption); |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4764 | } |
| 4765 | |
Mady Mellor | bd70749 | 2017-05-10 17:51:25 -0700 | [diff] [blame] | 4766 | public boolean isFalseGesture(MotionEvent ev) { |
| 4767 | return super.isFalseGesture(ev); |
| 4768 | } |
| 4769 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4770 | private void handleMenuCoveredOrDismissed() { |
| 4771 | if (mMenuExposedView != null && mMenuExposedView == mTranslatingParentView) { |
| 4772 | mMenuExposedView = null; |
Mady Mellor | 3a5e8dd | 2016-03-12 00:13:23 +0000 | [diff] [blame] | 4773 | } |
| 4774 | } |
| 4775 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4776 | @Override |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4777 | public Animator getViewTranslationAnimator(View v, float target, |
| 4778 | AnimatorUpdateListener listener) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 4779 | if (v instanceof ExpandableNotificationRow) { |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 4780 | return ((ExpandableNotificationRow) v).getTranslateViewAnimator(target, listener); |
| 4781 | } else { |
| 4782 | return super.getViewTranslationAnimator(v, target, listener); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4783 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | @Override |
| 4787 | public void setTranslation(View v, float translate) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 4788 | ((ExpandableView) v).setTranslation(translate); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | @Override |
| 4792 | public float getTranslation(View v) { |
Mady Mellor | 9c2c496 | 2016-04-05 10:43:08 -0700 | [diff] [blame] | 4793 | return ((ExpandableView) v).getTranslation(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4794 | } |
| 4795 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4796 | @Override |
| 4797 | public void dismiss(View animView, float velocity) { |
| 4798 | dismissChild(animView, velocity, |
| 4799 | !swipedFastEnough(0, 0) /* useAccelerateInterpolator */); |
| 4800 | } |
| 4801 | |
| 4802 | @Override |
| 4803 | public void snap(View animView, float targetLeft, float velocity) { |
| 4804 | snapChild(animView, targetLeft, velocity); |
| 4805 | } |
| 4806 | |
| 4807 | @Override |
| 4808 | public boolean swipedFarEnough(float translation, float viewSize) { |
| 4809 | return swipedFarEnough(); |
| 4810 | } |
| 4811 | |
| 4812 | @Override |
| 4813 | public boolean swipedFastEnough(float translation, float velocity) { |
| 4814 | return swipedFastEnough(); |
| 4815 | } |
| 4816 | |
| 4817 | @Override |
| 4818 | public float getMinDismissVelocity() { |
| 4819 | return getEscapeVelocity(); |
| 4820 | } |
| 4821 | |
| 4822 | public void onMenuShown(View animView) { |
| 4823 | onDragCancelled(animView); |
| 4824 | |
| 4825 | // If we're on the lockscreen we want to false this. |
| 4826 | if (isAntiFalsingNeeded()) { |
| 4827 | mHandler.removeCallbacks(mFalsingCheck); |
| 4828 | mHandler.postDelayed(mFalsingCheck, COVER_MENU_DELAY); |
| 4829 | } |
| 4830 | } |
| 4831 | |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4832 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4833 | NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts(); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4834 | View view = null; |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4835 | if (guts != null && !guts.getGutsContent().isLeavebehind()) { |
| 4836 | // Only close visible guts if they're not a leavebehind. |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4837 | view = guts; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4838 | } else if (mCurrMenuRow != null && mCurrMenuRow.isMenuVisible() |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4839 | && mTranslatingParentView != null) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4840 | // Checking menu |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4841 | view = mTranslatingParentView; |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4842 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4843 | if (view != null && !isTouchInView(ev, view)) { |
| 4844 | // Touch was outside visible guts / menu notification, close what's visible |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 4845 | mStatusBar.getGutsManager().closeAndSaveGuts(false /* removeLeavebehind */, |
| 4846 | false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */, |
| 4847 | false /* resetMenu */); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4848 | resetExposedMenuView(true /* animate */, true /* force */); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4849 | } |
| 4850 | } |
| 4851 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4852 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 4853 | if (mMenuExposedView == null |
| 4854 | || (!force && mMenuExposedView == mTranslatingParentView)) { |
| 4855 | // 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] | 4856 | return; |
| 4857 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4858 | final View prevMenuExposedView = mMenuExposedView; |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4859 | if (animate) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4860 | Animator anim = getViewTranslationAnimator(prevMenuExposedView, |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4861 | 0 /* leftTarget */, null /* updateListener */); |
| 4862 | if (anim != null) { |
| 4863 | anim.start(); |
| 4864 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4865 | } else if (mMenuExposedView instanceof ExpandableNotificationRow) { |
Selim Cinek | b2e0f33 | 2017-08-18 12:24:38 -0700 | [diff] [blame] | 4866 | ExpandableNotificationRow row = (ExpandableNotificationRow) mMenuExposedView; |
| 4867 | if (!row.isRemoved()) { |
| 4868 | row.resetTranslation(); |
| 4869 | } |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4870 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4871 | mMenuExposedView = null; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 4872 | } |
| 4873 | } |
| 4874 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 4875 | private boolean isTouchInView(MotionEvent ev, View view) { |
| 4876 | if (view == null) { |
| 4877 | return false; |
| 4878 | } |
| 4879 | final int height = (view instanceof ExpandableView) |
| 4880 | ? ((ExpandableView) view).getActualHeight() |
| 4881 | : view.getHeight(); |
| 4882 | final int rx = (int) ev.getRawX(); |
| 4883 | final int ry = (int) ev.getRawY(); |
| 4884 | view.getLocationOnScreen(mTempInt2); |
| 4885 | final int x = mTempInt2[0]; |
| 4886 | final int y = mTempInt2[1]; |
| 4887 | Rect rect = new Rect(x, y, x + view.getWidth(), y + height); |
| 4888 | boolean ret = rect.contains(rx, ry); |
| 4889 | return ret; |
| 4890 | } |
| 4891 | |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4892 | private void updateContinuousShadowDrawing() { |
| 4893 | boolean continuousShadowUpdate = mAnimationRunning |
| 4894 | || !mAmbientState.getDraggedViews().isEmpty(); |
| 4895 | if (continuousShadowUpdate != mContinuousShadowUpdate) { |
| 4896 | if (continuousShadowUpdate) { |
| 4897 | getViewTreeObserver().addOnPreDrawListener(mShadowUpdater); |
| 4898 | } else { |
| 4899 | getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater); |
| 4900 | } |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 4901 | mContinuousShadowUpdate = continuousShadowUpdate; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 4902 | } |
| 4903 | } |
| 4904 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 4905 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 4906 | public void resetExposedMenuView(boolean animate, boolean force) { |
| 4907 | mSwipeHelper.resetExposedMenuView(animate, force); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | public void closeControlsIfOutsideTouch(MotionEvent ev) { |
| 4911 | mSwipeHelper.closeControlsIfOutsideTouch(ev); |
| 4912 | } |
| 4913 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 4914 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 4915 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4916 | static AnimationFilter[] FILTERS = new AnimationFilter[] { |
| 4917 | |
| 4918 | // ANIMATION_TYPE_ADD |
| 4919 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4920 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4921 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4922 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4923 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4924 | .animateZ() |
| 4925 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4926 | |
| 4927 | // ANIMATION_TYPE_REMOVE |
| 4928 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4929 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4930 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4931 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4932 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4933 | .animateZ() |
| 4934 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4935 | |
| 4936 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 4937 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4938 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4939 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4940 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4941 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4942 | .animateZ() |
| 4943 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4944 | |
| 4945 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 4946 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4947 | .animateShadowAlpha() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4948 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4949 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4950 | .animateY() |
| 4951 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4952 | .animateZ(), |
| 4953 | |
| 4954 | // ANIMATION_TYPE_START_DRAG |
| 4955 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4956 | .animateShadowAlpha(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4957 | |
| 4958 | // ANIMATION_TYPE_SNAP_BACK |
| 4959 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4960 | .animateShadowAlpha() |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 4961 | .animateHeight(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4962 | |
| 4963 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 4964 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4965 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 4966 | |
| 4967 | // ANIMATION_TYPE_DIMMED |
| 4968 | new AnimationFilter() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4969 | .animateDimmed(), |
| 4970 | |
| 4971 | // ANIMATION_TYPE_CHANGE_POSITION |
| 4972 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4973 | .animateAlpha() // maybe the children change positions |
| 4974 | .animateShadowAlpha() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4975 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 4976 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 4977 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 4978 | .animateZ(), |
| 4979 | |
| 4980 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 4981 | null, // Unused |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4982 | |
| 4983 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 4984 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4985 | .animateShadowAlpha() |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 4986 | .animateHeight() |
| 4987 | .animateTopInset() |
| 4988 | .animateY() |
| 4989 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 4990 | .animateZ() |
| 4991 | .hasDelays(), |
| 4992 | |
| 4993 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 4994 | new AnimationFilter() |
| 4995 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 4996 | |
| 4997 | // ANIMATION_TYPE_VIEW_RESIZE |
| 4998 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 4999 | .animateShadowAlpha() |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5000 | .animateHeight() |
| 5001 | .animateTopInset() |
| 5002 | .animateY() |
| 5003 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5004 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5005 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 5006 | new AnimationFilter() |
| 5007 | .animateAlpha() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5008 | .animateShadowAlpha() |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5009 | .animateHeight() |
| 5010 | .animateTopInset() |
| 5011 | .animateY() |
| 5012 | .animateZ(), |
| 5013 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5014 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5015 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5016 | .animateShadowAlpha() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5017 | .animateHeight() |
| 5018 | .animateTopInset() |
| 5019 | .animateY() |
| 5020 | .animateZ(), |
| 5021 | |
| 5022 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5023 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5024 | .animateShadowAlpha() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5025 | .animateHeight() |
| 5026 | .animateTopInset() |
| 5027 | .animateY() |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 5028 | .animateZ() |
| 5029 | .hasDelays(), |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5030 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5031 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5032 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5033 | .animateShadowAlpha() |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5034 | .animateHeight() |
| 5035 | .animateTopInset() |
| 5036 | .animateY() |
| 5037 | .animateZ() |
| 5038 | .hasDelays(), |
| 5039 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5040 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5041 | new AnimationFilter() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5042 | .animateShadowAlpha() |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5043 | .animateHeight() |
| 5044 | .animateTopInset() |
| 5045 | .animateY() |
| 5046 | .animateZ(), |
| 5047 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5048 | // ANIMATION_TYPE_EVERYTHING |
| 5049 | new AnimationFilter() |
| 5050 | .animateAlpha() |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 5051 | .animateShadowAlpha() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5052 | .animateDark() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5053 | .animateDimmed() |
| 5054 | .animateHideSensitive() |
| 5055 | .animateHeight() |
| 5056 | .animateTopInset() |
| 5057 | .animateY() |
| 5058 | .animateZ(), |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5059 | |
| 5060 | // ANIMATION_TYPE_PULSE_APPEAR |
| 5061 | new AnimationFilter() |
| 5062 | .animateAlpha() |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5063 | .hasDelays() |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5064 | .animateY(), |
| 5065 | |
| 5066 | // ANIMATION_TYPE_PULSE_DISAPPEAR |
| 5067 | new AnimationFilter() |
| 5068 | .animateAlpha() |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5069 | .hasDelays() |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5070 | .animateY(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5071 | }; |
| 5072 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5073 | static int[] LENGTHS = new int[] { |
| 5074 | |
| 5075 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5076 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5077 | |
| 5078 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5079 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5080 | |
| 5081 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 5082 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5083 | |
| 5084 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 5085 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5086 | |
| 5087 | // ANIMATION_TYPE_START_DRAG |
| 5088 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5089 | |
| 5090 | // ANIMATION_TYPE_SNAP_BACK |
| 5091 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5092 | |
| 5093 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 5094 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 5095 | |
| 5096 | // ANIMATION_TYPE_DIMMED |
| 5097 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5098 | |
| 5099 | // ANIMATION_TYPE_CHANGE_POSITION |
| 5100 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5101 | |
| 5102 | // ANIMATION_TYPE_DARK |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5103 | StackStateAnimator.ANIMATION_DURATION_WAKEUP, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5104 | |
| 5105 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 5106 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5107 | |
| 5108 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 5109 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5110 | |
| 5111 | // ANIMATION_TYPE_VIEW_RESIZE |
| 5112 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5113 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5114 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 5115 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5116 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5117 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 5118 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 5119 | |
| 5120 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 5121 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 5122 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5123 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 5124 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 5125 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5126 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 5127 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 5128 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 5129 | // ANIMATION_TYPE_EVERYTHING |
| 5130 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5131 | |
| 5132 | // ANIMATION_TYPE_PULSE_APPEAR |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5133 | StackStateAnimator.ANIMATION_DURATION_PULSE_APPEAR, |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5134 | |
| 5135 | // ANIMATION_TYPE_PULSE_DISAPPEAR |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 5136 | StackStateAnimator.ANIMATION_DURATION_PULSE_APPEAR / 2, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5137 | }; |
| 5138 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5139 | static final int ANIMATION_TYPE_ADD = 0; |
| 5140 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 5141 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 5142 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
| 5143 | static final int ANIMATION_TYPE_START_DRAG = 4; |
| 5144 | static final int ANIMATION_TYPE_SNAP_BACK = 5; |
| 5145 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 6; |
| 5146 | static final int ANIMATION_TYPE_DIMMED = 7; |
| 5147 | static final int ANIMATION_TYPE_CHANGE_POSITION = 8; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 5148 | static final int ANIMATION_TYPE_DARK = 9; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5149 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 10; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 5150 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 11; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 5151 | static final int ANIMATION_TYPE_VIEW_RESIZE = 12; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 5152 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 13; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 5153 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 14; |
| 5154 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 15; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 5155 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 16; |
| 5156 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 17; |
| 5157 | static final int ANIMATION_TYPE_EVERYTHING = 18; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 5158 | static final int ANIMATION_TYPE_PULSE_APPEAR = 19; |
| 5159 | static final int ANIMATION_TYPE_PULSE_DISAPPEAR = 20; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 5160 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 5161 | static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1; |
| 5162 | static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2; |
| 5163 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5164 | final long eventStartTime; |
| 5165 | final View changingView; |
| 5166 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 5167 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5168 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 5169 | View viewAfterChangingView; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 5170 | int darkAnimationOriginIndex; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 5171 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5172 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 5173 | AnimationEvent(View view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 5174 | this(view, type, LENGTHS[type]); |
| 5175 | } |
| 5176 | |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5177 | AnimationEvent(View view, int type, AnimationFilter filter) { |
| 5178 | this(view, type, LENGTHS[type], filter); |
| 5179 | } |
| 5180 | |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 5181 | AnimationEvent(View view, int type, long length) { |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5182 | this(view, type, length, FILTERS[type]); |
| 5183 | } |
| 5184 | |
| 5185 | AnimationEvent(View view, int type, long length, AnimationFilter filter) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5186 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
| 5187 | changingView = view; |
| 5188 | animationType = type; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 5189 | this.length = length; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 5190 | this.filter = filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5191 | } |
| 5192 | |
| 5193 | /** |
| 5194 | * Combines the length of several animation events into a single value. |
| 5195 | * |
| 5196 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5197 | * @return The combined length. Depending on the event types, this might be the maximum of |
| 5198 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5199 | */ |
| 5200 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 5201 | long length = 0; |
| 5202 | int size = events.size(); |
| 5203 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 5204 | AnimationEvent event = events.get(i); |
| 5205 | length = Math.max(length, event.length); |
| 5206 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 5207 | return event.length; |
| 5208 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 5209 | } |
| 5210 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 5211 | } |
| 5212 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 5213 | } |