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