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