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