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