Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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.bubbles; |
| 18 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 19 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 20 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| 21 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 22 | import android.animation.Animator; |
| 23 | import android.animation.AnimatorListenerAdapter; |
| 24 | import android.animation.ValueAnimator; |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 26 | import android.app.Notification; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.res.Resources; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 29 | import android.graphics.ColorMatrix; |
| 30 | import android.graphics.ColorMatrixColorFilter; |
Joshua Tsuji | 580c0bf | 2019-01-28 13:28:21 -0500 | [diff] [blame] | 31 | import android.graphics.Outline; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 32 | import android.graphics.Paint; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 33 | import android.graphics.Point; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 34 | import android.graphics.PointF; |
| 35 | import android.graphics.Rect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 36 | import android.graphics.RectF; |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 37 | import android.os.Bundle; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 38 | import android.os.VibrationEffect; |
| 39 | import android.os.Vibrator; |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 40 | import android.service.notification.StatusBarNotification; |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 41 | import android.util.Log; |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 42 | import android.util.StatsLog; |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 43 | import android.view.Choreographer; |
Joshua Tsuji | 36b1b2c | 2019-04-18 16:27:35 -0400 | [diff] [blame] | 44 | import android.view.Gravity; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 45 | import android.view.LayoutInflater; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 46 | import android.view.MotionEvent; |
| 47 | import android.view.View; |
Joshua Tsuji | 580c0bf | 2019-01-28 13:28:21 -0500 | [diff] [blame] | 48 | import android.view.ViewOutlineProvider; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 49 | import android.view.ViewTreeObserver; |
Joshua Tsuji | 0fee768 | 2019-01-25 11:37:49 -0500 | [diff] [blame] | 50 | import android.view.WindowInsets; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 51 | import android.view.WindowManager; |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 52 | import android.view.accessibility.AccessibilityNodeInfo; |
Lyn Han | e68d091 | 2019-05-02 18:28:01 -0700 | [diff] [blame] | 53 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 54 | import android.view.animation.AccelerateDecelerateInterpolator; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 55 | import android.widget.FrameLayout; |
| 56 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 57 | import androidx.annotation.MainThread; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 58 | import androidx.annotation.Nullable; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 59 | import androidx.dynamicanimation.animation.DynamicAnimation; |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 60 | import androidx.dynamicanimation.animation.FloatPropertyCompat; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 61 | import androidx.dynamicanimation.animation.SpringAnimation; |
| 62 | import androidx.dynamicanimation.animation.SpringForce; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 63 | |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 64 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 65 | import com.android.internal.widget.ViewClippingUtil; |
| 66 | import com.android.systemui.R; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 67 | import com.android.systemui.bubbles.animation.ExpandedAnimationController; |
| 68 | import com.android.systemui.bubbles.animation.PhysicsAnimationLayout; |
| 69 | import com.android.systemui.bubbles.animation.StackAnimationController; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 71 | |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 72 | import java.math.BigDecimal; |
| 73 | import java.math.RoundingMode; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 74 | import java.util.ArrayList; |
Mark Renouf | 821e678 | 2019-04-01 14:17:37 -0400 | [diff] [blame] | 75 | import java.util.Collections; |
| 76 | import java.util.List; |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 77 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 78 | /** |
| 79 | * Renders bubbles in a stack and handles animating expanded and collapsed states. |
| 80 | */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 81 | public class BubbleStackView extends FrameLayout { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 82 | private static final String TAG = "BubbleStackView"; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 83 | private static final boolean DEBUG = false; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 84 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 85 | /** How far the flyout needs to be dragged before it's dismissed regardless of velocity. */ |
| 86 | static final float FLYOUT_DRAG_PERCENT_DISMISS = 0.25f; |
| 87 | |
| 88 | /** Velocity required to dismiss the flyout via drag. */ |
| 89 | private static final float FLYOUT_DISMISS_VELOCITY = 2000f; |
| 90 | |
| 91 | /** |
| 92 | * Factor for attenuating translation when the flyout is overscrolled (8f = flyout moves 1 pixel |
| 93 | * for every 8 pixels overscrolled). |
| 94 | */ |
| 95 | private static final float FLYOUT_OVERSCROLL_ATTENUATION_FACTOR = 8f; |
| 96 | |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 97 | /** Duration of the flyout alpha animations. */ |
| 98 | private static final int FLYOUT_ALPHA_ANIMATION_DURATION = 100; |
| 99 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 100 | /** Percent to darken the bubbles when they're in the dismiss target. */ |
| 101 | private static final float DARKEN_PERCENT = 0.3f; |
| 102 | |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 103 | /** How long to wait, in milliseconds, before hiding the flyout. */ |
| 104 | @VisibleForTesting |
| 105 | static final int FLYOUT_HIDE_AFTER = 5000; |
| 106 | |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 107 | /** |
| 108 | * Interface to synchronize {@link View} state and the screen. |
| 109 | * |
| 110 | * {@hide} |
| 111 | */ |
| 112 | interface SurfaceSynchronizer { |
| 113 | /** |
| 114 | * Wait until requested change on a {@link View} is reflected on the screen. |
| 115 | * |
| 116 | * @param callback callback to run after the change is reflected on the screen. |
| 117 | */ |
| 118 | void syncSurfaceAndRun(Runnable callback); |
| 119 | } |
| 120 | |
| 121 | private static final SurfaceSynchronizer DEFAULT_SURFACE_SYNCHRONIZER = |
| 122 | new SurfaceSynchronizer() { |
| 123 | @Override |
| 124 | public void syncSurfaceAndRun(Runnable callback) { |
| 125 | Choreographer.getInstance().postFrameCallback(new Choreographer.FrameCallback() { |
| 126 | // Just wait 2 frames. There is no guarantee, but this is usually enough time that |
| 127 | // the requested change is reflected on the screen. |
| 128 | // TODO: Once SurfaceFlinger provide APIs to sync the state of {@code View} and |
| 129 | // surfaces, rewrite this logic with them. |
| 130 | private int mFrameWait = 2; |
| 131 | |
| 132 | @Override |
| 133 | public void doFrame(long frameTimeNanos) { |
| 134 | if (--mFrameWait > 0) { |
| 135 | Choreographer.getInstance().postFrameCallback(this); |
| 136 | } else { |
| 137 | callback.run(); |
| 138 | } |
| 139 | } |
| 140 | }); |
| 141 | } |
| 142 | }; |
| 143 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 144 | private Point mDisplaySize; |
| 145 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 146 | private final SpringAnimation mExpandedViewXAnim; |
| 147 | private final SpringAnimation mExpandedViewYAnim; |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 148 | private final BubbleData mBubbleData; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 149 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 150 | private final Vibrator mVibrator; |
| 151 | private final ValueAnimator mDesaturateAndDarkenAnimator; |
| 152 | private final Paint mDesaturateAndDarkenPaint = new Paint(); |
| 153 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 154 | private PhysicsAnimationLayout mBubbleContainer; |
| 155 | private StackAnimationController mStackAnimationController; |
| 156 | private ExpandedAnimationController mExpandedAnimationController; |
| 157 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 158 | private FrameLayout mExpandedViewContainer; |
| 159 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 160 | private BubbleFlyoutView mFlyout; |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 161 | /** Runnable that fades out the flyout and then sets it to GONE. */ |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 162 | private Runnable mHideFlyout = () -> animateFlyoutCollapsed(true, 0 /* velX */); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 163 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 164 | /** Layout change listener that moves the stack to the nearest valid position on rotation. */ |
| 165 | private OnLayoutChangeListener mMoveStackToValidPositionOnLayoutListener; |
| 166 | /** Whether the stack was on the left side of the screen prior to rotation. */ |
| 167 | private boolean mWasOnLeftBeforeRotation = false; |
| 168 | /** |
| 169 | * How far down the screen the stack was before rotation, in terms of percentage of the way down |
| 170 | * the allowable region. Defaults to -1 if not set. |
| 171 | */ |
| 172 | private float mVerticalPosPercentBeforeRotation = -1; |
| 173 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 174 | private int mBubbleSize; |
| 175 | private int mBubblePadding; |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 176 | private int mExpandedViewPadding; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 177 | private int mExpandedAnimateXDistance; |
| 178 | private int mExpandedAnimateYDistance; |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 179 | private int mPointerHeight; |
Joshua Tsuji | f44347f | 2019-02-12 14:28:06 -0500 | [diff] [blame] | 180 | private int mStatusBarHeight; |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 181 | private int mPipDismissHeight; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 182 | private int mImeOffset; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 183 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 184 | private Bubble mExpandedBubble; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 185 | private boolean mIsExpanded; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 186 | private boolean mImeVisible; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 187 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 188 | /** Whether the stack is currently on the left side of the screen, or animating there. */ |
| 189 | private boolean mStackOnLeftOrWillBe = false; |
| 190 | |
| 191 | /** Whether a touch gesture, such as a stack/bubble drag or flyout drag, is in progress. */ |
| 192 | private boolean mIsGestureInProgress = false; |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 193 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 194 | private BubbleTouchHandler mTouchHandler; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 195 | private BubbleController.BubbleExpandListener mExpandListener; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 196 | private BubbleExpandedView.OnBubbleBlockedListener mBlockedListener; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 197 | |
| 198 | private boolean mViewUpdatedRequested = false; |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 199 | private boolean mIsExpansionAnimating = false; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 200 | private boolean mShowingDismiss = false; |
| 201 | |
| 202 | /** |
| 203 | * Whether the user is currently dragging their finger within the dismiss target. In this state |
| 204 | * the stack will be magnetized to the center of the target, so we shouldn't move it until the |
| 205 | * touch exits the dismiss target area. |
| 206 | */ |
| 207 | private boolean mDraggingInDismissTarget = false; |
| 208 | |
| 209 | /** Whether the stack is magneting towards the dismiss target. */ |
| 210 | private boolean mAnimatingMagnet = false; |
| 211 | |
| 212 | /** The view to desaturate/darken when magneted to the dismiss target. */ |
| 213 | private View mDesaturateAndDarkenTargetView; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 214 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 215 | private LayoutInflater mInflater; |
| 216 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 217 | // Used for determining view / touch intersection |
| 218 | int[] mTempLoc = new int[2]; |
| 219 | RectF mTempRect = new RectF(); |
| 220 | |
Mark Renouf | 821e678 | 2019-04-01 14:17:37 -0400 | [diff] [blame] | 221 | private final List<Rect> mSystemGestureExclusionRects = Collections.singletonList(new Rect()); |
| 222 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 223 | private ViewTreeObserver.OnPreDrawListener mViewUpdater = |
| 224 | new ViewTreeObserver.OnPreDrawListener() { |
| 225 | @Override |
| 226 | public boolean onPreDraw() { |
| 227 | getViewTreeObserver().removeOnPreDrawListener(mViewUpdater); |
| 228 | applyCurrentState(); |
| 229 | mViewUpdatedRequested = false; |
| 230 | return true; |
| 231 | } |
| 232 | }; |
| 233 | |
Mark Renouf | 821e678 | 2019-04-01 14:17:37 -0400 | [diff] [blame] | 234 | private ViewTreeObserver.OnDrawListener mSystemGestureExcludeUpdater = |
| 235 | this::updateSystemGestureExcludeRects; |
| 236 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 237 | private ViewClippingUtil.ClippingParameters mClippingParameters = |
| 238 | new ViewClippingUtil.ClippingParameters() { |
| 239 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 240 | @Override |
| 241 | public boolean shouldFinish(View view) { |
| 242 | return false; |
| 243 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 244 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 245 | @Override |
| 246 | public boolean isClippingEnablingAllowed(View view) { |
| 247 | return !mIsExpanded; |
| 248 | } |
| 249 | }; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 250 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 251 | /** Float property that 'drags' the flyout. */ |
| 252 | private final FloatPropertyCompat mFlyoutCollapseProperty = |
| 253 | new FloatPropertyCompat("FlyoutCollapseSpring") { |
| 254 | @Override |
| 255 | public float getValue(Object o) { |
| 256 | return mFlyoutDragDeltaX; |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void setValue(Object o, float v) { |
| 261 | onFlyoutDragged(v); |
| 262 | } |
| 263 | }; |
| 264 | |
| 265 | /** SpringAnimation that springs the flyout collapsed via onFlyoutDragged. */ |
| 266 | private final SpringAnimation mFlyoutTransitionSpring = |
| 267 | new SpringAnimation(this, mFlyoutCollapseProperty); |
| 268 | |
| 269 | /** Distance the flyout has been dragged in the X axis. */ |
| 270 | private float mFlyoutDragDeltaX = 0f; |
| 271 | |
| 272 | /** |
| 273 | * End listener for the flyout spring that either posts a runnable to hide the flyout, or hides |
| 274 | * it immediately. |
| 275 | */ |
| 276 | private final DynamicAnimation.OnAnimationEndListener mAfterFlyoutTransitionSpring = |
| 277 | (dynamicAnimation, b, v, v1) -> { |
| 278 | if (mFlyoutDragDeltaX == 0) { |
| 279 | mFlyout.postDelayed(mHideFlyout, FLYOUT_HIDE_AFTER); |
| 280 | } else { |
| 281 | mFlyout.hideFlyout(); |
| 282 | } |
| 283 | }; |
| 284 | |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 285 | @NonNull private final SurfaceSynchronizer mSurfaceSynchronizer; |
| 286 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 287 | private BubbleDismissView mDismissContainer; |
| 288 | private Runnable mAfterMagnet; |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 289 | |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 290 | private boolean mSuppressNewDot = false; |
| 291 | private boolean mSuppressFlyout = false; |
| 292 | |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 293 | public BubbleStackView(Context context, BubbleData data, |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 294 | @Nullable SurfaceSynchronizer synchronizer) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 295 | super(context); |
| 296 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 297 | mBubbleData = data; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 298 | mInflater = LayoutInflater.from(context); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 299 | mTouchHandler = new BubbleTouchHandler(this, data, context); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 300 | setOnTouchListener(mTouchHandler); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 301 | mInflater = LayoutInflater.from(context); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 302 | |
| 303 | Resources res = getResources(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 304 | mBubbleSize = res.getDimensionPixelSize(R.dimen.individual_bubble_size); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 305 | mBubblePadding = res.getDimensionPixelSize(R.dimen.bubble_padding); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 306 | mExpandedAnimateXDistance = |
| 307 | res.getDimensionPixelSize(R.dimen.bubble_expanded_animate_x_distance); |
| 308 | mExpandedAnimateYDistance = |
| 309 | res.getDimensionPixelSize(R.dimen.bubble_expanded_animate_y_distance); |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 310 | mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
| 311 | |
Joshua Tsuji | f44347f | 2019-02-12 14:28:06 -0500 | [diff] [blame] | 312 | mStatusBarHeight = |
| 313 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 314 | mPipDismissHeight = mContext.getResources().getDimensionPixelSize( |
| 315 | R.dimen.pip_dismiss_gradient_height); |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 316 | mImeOffset = res.getDimensionPixelSize(R.dimen.pip_ime_offset); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 317 | |
| 318 | mDisplaySize = new Point(); |
| 319 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| 320 | wm.getDefaultDisplay().getSize(mDisplaySize); |
| 321 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 322 | mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); |
| 323 | |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 324 | mExpandedViewPadding = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 325 | int elevation = res.getDimensionPixelSize(R.dimen.bubble_elevation); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 326 | |
| 327 | mStackAnimationController = new StackAnimationController(); |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 328 | mExpandedAnimationController = new ExpandedAnimationController( |
| 329 | mDisplaySize, mExpandedViewPadding); |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 330 | mSurfaceSynchronizer = synchronizer != null ? synchronizer : DEFAULT_SURFACE_SYNCHRONIZER; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 331 | |
| 332 | mBubbleContainer = new PhysicsAnimationLayout(context); |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 333 | mBubbleContainer.setActiveController(mStackAnimationController); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 334 | mBubbleContainer.setElevation(elevation); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 335 | mBubbleContainer.setClipChildren(false); |
| 336 | addView(mBubbleContainer, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
| 337 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 338 | mExpandedViewContainer = new FrameLayout(context); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 339 | mExpandedViewContainer.setElevation(elevation); |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 340 | mExpandedViewContainer.setPadding(mExpandedViewPadding, mExpandedViewPadding, |
| 341 | mExpandedViewPadding, mExpandedViewPadding); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 342 | mExpandedViewContainer.setClipChildren(false); |
| 343 | addView(mExpandedViewContainer); |
| 344 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 345 | mFlyout = new BubbleFlyoutView(context); |
| 346 | mFlyout.setVisibility(GONE); |
| 347 | mFlyout.animate() |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 348 | .setDuration(FLYOUT_ALPHA_ANIMATION_DURATION) |
| 349 | .setInterpolator(new AccelerateDecelerateInterpolator()); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 350 | addView(mFlyout, new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 351 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 352 | mFlyoutTransitionSpring.setSpring(new SpringForce() |
| 353 | .setStiffness(SpringForce.STIFFNESS_MEDIUM) |
| 354 | .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY)); |
| 355 | mFlyoutTransitionSpring.addEndListener(mAfterFlyoutTransitionSpring); |
| 356 | |
| 357 | mDismissContainer = new BubbleDismissView(mContext); |
| 358 | mDismissContainer.setLayoutParams(new FrameLayout.LayoutParams( |
| 359 | MATCH_PARENT, |
| 360 | getResources().getDimensionPixelSize(R.dimen.pip_dismiss_gradient_height), |
| 361 | Gravity.BOTTOM)); |
| 362 | addView(mDismissContainer); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 363 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 364 | mDismissContainer = new BubbleDismissView(mContext); |
| 365 | mDismissContainer.setLayoutParams(new FrameLayout.LayoutParams( |
| 366 | MATCH_PARENT, |
| 367 | getResources().getDimensionPixelSize(R.dimen.pip_dismiss_gradient_height), |
| 368 | Gravity.BOTTOM)); |
| 369 | addView(mDismissContainer); |
| 370 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 371 | mExpandedViewXAnim = |
| 372 | new SpringAnimation(mExpandedViewContainer, DynamicAnimation.TRANSLATION_X); |
| 373 | mExpandedViewXAnim.setSpring( |
| 374 | new SpringForce() |
| 375 | .setStiffness(SpringForce.STIFFNESS_LOW) |
| 376 | .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY)); |
| 377 | |
| 378 | mExpandedViewYAnim = |
| 379 | new SpringAnimation(mExpandedViewContainer, DynamicAnimation.TRANSLATION_Y); |
| 380 | mExpandedViewYAnim.setSpring( |
| 381 | new SpringForce() |
| 382 | .setStiffness(SpringForce.STIFFNESS_LOW) |
| 383 | .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY)); |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 384 | mExpandedViewYAnim.addEndListener((anim, cancelled, value, velocity) -> { |
| 385 | if (mIsExpanded && mExpandedBubble != null) { |
| 386 | mExpandedBubble.expandedView.updateView(); |
| 387 | } |
| 388 | }); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 389 | |
| 390 | setClipChildren(false); |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 391 | setFocusable(true); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 392 | mBubbleContainer.bringToFront(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 393 | |
| 394 | setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> { |
| 395 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 396 | - insets.getStableInsetBottom(); |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 397 | if (!mIsExpanded || mIsExpansionAnimating) { |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 398 | return view.onApplyWindowInsets(insets); |
| 399 | } |
| 400 | mImeVisible = keyboardHeight != 0; |
| 401 | |
| 402 | float newY = getYPositionForExpandedView(); |
| 403 | if (newY < 0) { |
| 404 | // TODO: This means our expanded content is too big to fit on screen. Right now |
| 405 | // we'll let it translate off but we should be clipping it & pushing the header |
| 406 | // down so that it always remains visible. |
| 407 | } |
| 408 | mExpandedViewYAnim.animateToFinalPosition(newY); |
| 409 | mExpandedAnimationController.updateYPosition( |
| 410 | // Update the insets after we're done translating otherwise position |
| 411 | // calculation for them won't be correct. |
| 412 | () -> mExpandedBubble.expandedView.updateInsets(insets)); |
| 413 | return view.onApplyWindowInsets(insets); |
| 414 | }); |
Mark Renouf | 821e678 | 2019-04-01 14:17:37 -0400 | [diff] [blame] | 415 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 416 | mMoveStackToValidPositionOnLayoutListener = |
| 417 | (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { |
| 418 | if (mVerticalPosPercentBeforeRotation >= 0) { |
| 419 | mStackAnimationController.moveStackToSimilarPositionAfterRotation( |
| 420 | mWasOnLeftBeforeRotation, mVerticalPosPercentBeforeRotation); |
| 421 | } |
| 422 | removeOnLayoutChangeListener(mMoveStackToValidPositionOnLayoutListener); |
| 423 | }; |
| 424 | |
Mark Renouf | 821e678 | 2019-04-01 14:17:37 -0400 | [diff] [blame] | 425 | // This must be a separate OnDrawListener since it should be called for every draw. |
| 426 | getViewTreeObserver().addOnDrawListener(mSystemGestureExcludeUpdater); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 427 | |
| 428 | final ColorMatrix animatedMatrix = new ColorMatrix(); |
| 429 | final ColorMatrix darkenMatrix = new ColorMatrix(); |
| 430 | |
| 431 | mDesaturateAndDarkenAnimator = ValueAnimator.ofFloat(1f, 0f); |
| 432 | mDesaturateAndDarkenAnimator.addUpdateListener(animation -> { |
| 433 | final float animatedValue = (float) animation.getAnimatedValue(); |
| 434 | animatedMatrix.setSaturation(animatedValue); |
| 435 | |
| 436 | final float animatedDarkenValue = (1f - animatedValue) * DARKEN_PERCENT; |
| 437 | darkenMatrix.setScale( |
| 438 | 1f - animatedDarkenValue /* red */, |
| 439 | 1f - animatedDarkenValue /* green */, |
| 440 | 1f - animatedDarkenValue /* blue */, |
| 441 | 1f /* alpha */); |
| 442 | |
| 443 | // Concat the matrices so that the animatedMatrix both desaturates and darkens. |
| 444 | animatedMatrix.postConcat(darkenMatrix); |
| 445 | |
| 446 | // Update the paint and apply it to the bubble container. |
| 447 | mDesaturateAndDarkenPaint.setColorFilter(new ColorMatrixColorFilter(animatedMatrix)); |
| 448 | mDesaturateAndDarkenTargetView.setLayerPaint(mDesaturateAndDarkenPaint); |
| 449 | }); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 452 | /** |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 453 | * Handle theme changes. |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 454 | */ |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 455 | public void onThemeChanged() { |
Lyn Han | 76e803d | 2019-03-26 17:31:33 -0700 | [diff] [blame] | 456 | for (Bubble b: mBubbleData.getBubbles()) { |
Lyn Han | 80b8011 | 2019-04-04 14:03:40 -0700 | [diff] [blame] | 457 | b.iconView.updateViews(); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 458 | b.expandedView.applyThemeAttrs(); |
Mady Mellor | e37f60b | 2019-03-25 14:48:34 -0700 | [diff] [blame] | 459 | } |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 462 | /** Respond to the phone being rotated by repositioning the stack and hiding any flyouts. */ |
| 463 | public void onOrientationChanged() { |
| 464 | final RectF allowablePos = mStackAnimationController.getAllowableStackPositionRegion(); |
| 465 | mWasOnLeftBeforeRotation = mStackAnimationController.isStackOnLeftSide(); |
| 466 | mVerticalPosPercentBeforeRotation = |
| 467 | (mStackAnimationController.getStackPosition().y - allowablePos.top) |
| 468 | / (allowablePos.bottom - allowablePos.top); |
| 469 | addOnLayoutChangeListener(mMoveStackToValidPositionOnLayoutListener); |
| 470 | |
| 471 | hideFlyoutImmediate(); |
| 472 | } |
| 473 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 474 | @Override |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 475 | public void getBoundsOnScreen(Rect outRect, boolean clipToParent) { |
| 476 | getBoundsOnScreen(outRect); |
| 477 | } |
| 478 | |
| 479 | @Override |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 480 | protected void onDetachedFromWindow() { |
| 481 | super.onDetachedFromWindow(); |
| 482 | getViewTreeObserver().removeOnPreDrawListener(mViewUpdater); |
| 483 | } |
| 484 | |
| 485 | @Override |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 486 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 487 | float x = ev.getRawX(); |
| 488 | float y = ev.getRawY(); |
| 489 | // If we're expanded only intercept if the tap is outside of the widget container |
| 490 | if (mIsExpanded && isIntersecting(mExpandedViewContainer, x, y)) { |
| 491 | return false; |
| 492 | } else { |
| 493 | return isIntersecting(mBubbleContainer, x, y); |
| 494 | } |
| 495 | } |
| 496 | |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 497 | @Override |
| 498 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 499 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Lyn Han | e68d091 | 2019-05-02 18:28:01 -0700 | [diff] [blame] | 500 | |
| 501 | // Custom actions. |
| 502 | AccessibilityAction moveTopLeft = new AccessibilityAction(R.id.action_move_top_left, |
| 503 | getContext().getResources() |
| 504 | .getString(R.string.bubble_accessibility_action_move_top_left)); |
| 505 | info.addAction(moveTopLeft); |
| 506 | |
| 507 | AccessibilityAction moveTopRight = new AccessibilityAction(R.id.action_move_top_right, |
| 508 | getContext().getResources() |
| 509 | .getString(R.string.bubble_accessibility_action_move_top_right)); |
| 510 | info.addAction(moveTopRight); |
| 511 | |
| 512 | AccessibilityAction moveBottomLeft = new AccessibilityAction(R.id.action_move_bottom_left, |
| 513 | getContext().getResources() |
| 514 | .getString(R.string.bubble_accessibility_action_move_bottom_left)); |
| 515 | info.addAction(moveBottomLeft); |
| 516 | |
| 517 | AccessibilityAction moveBottomRight = new AccessibilityAction(R.id.action_move_bottom_right, |
| 518 | getContext().getResources() |
| 519 | .getString(R.string.bubble_accessibility_action_move_bottom_right)); |
| 520 | info.addAction(moveBottomRight); |
| 521 | |
| 522 | // Default actions. |
| 523 | info.addAction(AccessibilityAction.ACTION_DISMISS); |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 524 | if (mIsExpanded) { |
Lyn Han | e68d091 | 2019-05-02 18:28:01 -0700 | [diff] [blame] | 525 | info.addAction(AccessibilityAction.ACTION_COLLAPSE); |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 526 | } else { |
Lyn Han | e68d091 | 2019-05-02 18:28:01 -0700 | [diff] [blame] | 527 | info.addAction(AccessibilityAction.ACTION_EXPAND); |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 533 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 534 | return true; |
| 535 | } |
Lyn Han | e68d091 | 2019-05-02 18:28:01 -0700 | [diff] [blame] | 536 | final RectF stackBounds = mStackAnimationController.getAllowableStackPositionRegion(); |
| 537 | |
| 538 | // R constants are not final so we cannot use switch-case here. |
| 539 | if (action == AccessibilityNodeInfo.ACTION_DISMISS) { |
| 540 | mBubbleData.dismissAll(BubbleController.DISMISS_ACCESSIBILITY_ACTION); |
| 541 | return true; |
| 542 | } else if (action == AccessibilityNodeInfo.ACTION_COLLAPSE) { |
| 543 | mBubbleData.setExpanded(false); |
| 544 | return true; |
| 545 | } else if (action == AccessibilityNodeInfo.ACTION_EXPAND) { |
| 546 | mBubbleData.setExpanded(true); |
| 547 | return true; |
| 548 | } else if (action == R.id.action_move_top_left) { |
| 549 | mStackAnimationController.springStack(stackBounds.left, stackBounds.top); |
| 550 | return true; |
| 551 | } else if (action == R.id.action_move_top_right) { |
| 552 | mStackAnimationController.springStack(stackBounds.right, stackBounds.top); |
| 553 | return true; |
| 554 | } else if (action == R.id.action_move_bottom_left) { |
| 555 | mStackAnimationController.springStack(stackBounds.left, stackBounds.bottom); |
| 556 | return true; |
| 557 | } else if (action == R.id.action_move_bottom_right) { |
| 558 | mStackAnimationController.springStack(stackBounds.right, stackBounds.bottom); |
| 559 | return true; |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 560 | } |
| 561 | return false; |
| 562 | } |
| 563 | |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 564 | /** |
| 565 | * Update content description for a11y TalkBack. |
| 566 | */ |
| 567 | public void updateContentDescription() { |
| 568 | if (mBubbleData.getBubbles().isEmpty()) { |
| 569 | return; |
| 570 | } |
| 571 | Bubble topBubble = mBubbleData.getBubbles().get(0); |
| 572 | String appName = topBubble.getAppName(); |
| 573 | Notification notification = topBubble.entry.notification.getNotification(); |
| 574 | CharSequence titleCharSeq = notification.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 575 | String titleStr = getResources().getString(R.string.stream_notification); |
| 576 | if (titleCharSeq != null) { |
| 577 | titleStr = titleCharSeq.toString(); |
| 578 | } |
| 579 | int moreCount = mBubbleContainer.getChildCount() - 1; |
| 580 | |
| 581 | // Example: Title from app name. |
| 582 | String singleDescription = getResources().getString( |
| 583 | R.string.bubble_content_description_single, titleStr, appName); |
| 584 | |
| 585 | // Example: Title from app name and 4 more. |
| 586 | String stackDescription = getResources().getString( |
| 587 | R.string.bubble_content_description_stack, titleStr, appName, moreCount); |
| 588 | |
| 589 | if (mIsExpanded) { |
| 590 | // TODO(b/129522932) - update content description for each bubble in expanded view. |
| 591 | } else { |
| 592 | // Collapsed stack. |
| 593 | if (moreCount > 0) { |
| 594 | mBubbleContainer.setContentDescription(stackDescription); |
| 595 | } else { |
| 596 | mBubbleContainer.setContentDescription(singleDescription); |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
Mark Renouf | 821e678 | 2019-04-01 14:17:37 -0400 | [diff] [blame] | 601 | private void updateSystemGestureExcludeRects() { |
| 602 | // Exclude the region occupied by the first BubbleView in the stack |
| 603 | Rect excludeZone = mSystemGestureExclusionRects.get(0); |
| 604 | if (mBubbleContainer.getChildCount() > 0) { |
| 605 | View firstBubble = mBubbleContainer.getChildAt(0); |
| 606 | excludeZone.set(firstBubble.getLeft(), firstBubble.getTop(), firstBubble.getRight(), |
| 607 | firstBubble.getBottom()); |
| 608 | excludeZone.offset((int) (firstBubble.getTranslationX() + 0.5f), |
| 609 | (int) (firstBubble.getTranslationY() + 0.5f)); |
| 610 | mBubbleContainer.setSystemGestureExclusionRects(mSystemGestureExclusionRects); |
| 611 | } else { |
| 612 | excludeZone.setEmpty(); |
| 613 | mBubbleContainer.setSystemGestureExclusionRects(Collections.emptyList()); |
| 614 | } |
| 615 | } |
| 616 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 617 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 618 | * Updates the visibility of the 'dot' indicating an update on the bubble. |
| 619 | * @param key the {@link NotificationEntry#key} associated with the bubble. |
| 620 | */ |
| 621 | public void updateDotVisibility(String key) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 622 | Bubble b = mBubbleData.getBubbleWithKey(key); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 623 | if (b != null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 624 | b.updateDotVisibility(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 629 | * Sets the listener to notify when the bubble stack is expanded. |
| 630 | */ |
| 631 | public void setExpandListener(BubbleController.BubbleExpandListener listener) { |
| 632 | mExpandListener = listener; |
| 633 | } |
| 634 | |
| 635 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 636 | * Whether the stack of bubbles is expanded or not. |
| 637 | */ |
| 638 | public boolean isExpanded() { |
| 639 | return mIsExpanded; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * The {@link BubbleView} that is expanded, null if one does not exist. |
| 644 | */ |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 645 | BubbleView getExpandedBubbleView() { |
| 646 | return mExpandedBubble != null ? mExpandedBubble.iconView : null; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * The {@link Bubble} that is expanded, null if one does not exist. |
| 651 | */ |
| 652 | Bubble getExpandedBubble() { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 653 | return mExpandedBubble; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Sets the bubble that should be expanded and expands if needed. |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 658 | * |
| 659 | * @param key the {@link NotificationEntry#key} associated with the bubble to expand. |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 660 | * @deprecated replaced by setSelectedBubble(Bubble) + setExpanded(true) |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 661 | */ |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 662 | @Deprecated |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 663 | void setExpandedBubble(String key) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 664 | Bubble bubbleToExpand = mBubbleData.getBubbleWithKey(key); |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 665 | if (bubbleToExpand != null) { |
| 666 | setSelectedBubble(bubbleToExpand); |
| 667 | bubbleToExpand.entry.setShowInShadeWhenBubble(false); |
| 668 | setExpanded(true); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 669 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | /** |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 673 | * Sets the entry that should be expanded and expands if needed. |
| 674 | */ |
| 675 | @VisibleForTesting |
Mady Mellor | c3d7d06 | 2019-03-28 16:13:05 -0700 | [diff] [blame] | 676 | void setExpandedBubble(NotificationEntry entry) { |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 677 | for (int i = 0; i < mBubbleContainer.getChildCount(); i++) { |
| 678 | BubbleView bv = (BubbleView) mBubbleContainer.getChildAt(i); |
| 679 | if (entry.equals(bv.getEntry())) { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 680 | setExpandedBubble(entry.key); |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 685 | // via BubbleData.Listener |
| 686 | void addBubble(Bubble bubble) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 687 | if (DEBUG) { |
| 688 | Log.d(TAG, "addBubble: " + bubble); |
| 689 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 690 | bubble.inflate(mInflater, this); |
| 691 | mBubbleContainer.addView(bubble.iconView, 0, |
| 692 | new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); |
| 693 | ViewClippingUtil.setClippingDeactivated(bubble.iconView, true, mClippingParameters); |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 694 | if (bubble.iconView != null) { |
| 695 | bubble.iconView.setSuppressDot(mSuppressNewDot, false /* animate */); |
| 696 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 697 | animateInFlyoutForBubble(bubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 698 | requestUpdate(); |
| 699 | logBubbleEvent(bubble, StatsLog.BUBBLE_UICHANGED__ACTION__POSTED); |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 700 | updatePointerPosition(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // via BubbleData.Listener |
| 704 | void removeBubble(Bubble bubble) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 705 | if (DEBUG) { |
| 706 | Log.d(TAG, "removeBubble: " + bubble); |
| 707 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 708 | // Remove it from the views |
| 709 | int removedIndex = mBubbleContainer.indexOfChild(bubble.iconView); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 710 | if (removedIndex >= 0) { |
| 711 | mBubbleContainer.removeViewAt(removedIndex); |
| 712 | logBubbleEvent(bubble, StatsLog.BUBBLE_UICHANGED__ACTION__DISMISSED); |
| 713 | } else { |
| 714 | Log.d(TAG, "was asked to remove Bubble, but didn't find the view! " + bubble); |
| 715 | } |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 716 | updatePointerPosition(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | // via BubbleData.Listener |
| 720 | void updateBubble(Bubble bubble) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 721 | animateInFlyoutForBubble(bubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 722 | requestUpdate(); |
| 723 | logBubbleEvent(bubble, StatsLog.BUBBLE_UICHANGED__ACTION__UPDATED); |
| 724 | } |
| 725 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 726 | public void updateBubbleOrder(List<Bubble> bubbles) { |
| 727 | for (int i = 0; i < bubbles.size(); i++) { |
| 728 | Bubble bubble = bubbles.get(i); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 729 | mBubbleContainer.reorderView(bubble.iconView, i); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 733 | /** |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 734 | * Changes the currently selected bubble. If the stack is already expanded, the newly selected |
| 735 | * bubble will be shown immediately. This does not change the expanded state or change the |
| 736 | * position of any bubble. |
| 737 | */ |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 738 | // via BubbleData.Listener |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 739 | public void setSelectedBubble(@Nullable Bubble bubbleToSelect) { |
| 740 | if (DEBUG) { |
| 741 | Log.d(TAG, "setSelectedBubble: " + bubbleToSelect); |
| 742 | } |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 743 | if (mExpandedBubble != null && mExpandedBubble.equals(bubbleToSelect)) { |
| 744 | return; |
| 745 | } |
| 746 | final Bubble previouslySelected = mExpandedBubble; |
| 747 | mExpandedBubble = bubbleToSelect; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 748 | |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 749 | if (mIsExpanded) { |
| 750 | // Make the container of the expanded view transparent before removing the expanded view |
| 751 | // from it. Otherwise a punch hole created by {@link android.view.SurfaceView} in the |
| 752 | // expanded view becomes visible on the screen. See b/126856255 |
| 753 | mExpandedViewContainer.setAlpha(0.0f); |
| 754 | mSurfaceSynchronizer.syncSurfaceAndRun(() -> { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 755 | if (previouslySelected != null) { |
| 756 | previouslySelected.setContentVisibility(false); |
| 757 | } |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 758 | updateExpandedBubble(); |
| 759 | updatePointerPosition(); |
| 760 | requestUpdate(); |
| 761 | logBubbleEvent(previouslySelected, StatsLog.BUBBLE_UICHANGED__ACTION__COLLAPSED); |
| 762 | logBubbleEvent(bubbleToSelect, StatsLog.BUBBLE_UICHANGED__ACTION__EXPANDED); |
| 763 | notifyExpansionChanged(previouslySelected.entry, false /* expanded */); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 764 | notifyExpansionChanged(bubbleToSelect == null ? null : bubbleToSelect.entry, |
| 765 | true /* expanded */); |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 766 | }); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * Changes the expanded state of the stack. |
| 772 | * |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 773 | * @param shouldExpand whether the bubble stack should appear expanded |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 774 | */ |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 775 | // via BubbleData.Listener |
| 776 | public void setExpanded(boolean shouldExpand) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 777 | if (DEBUG) { |
| 778 | Log.d(TAG, "setExpanded: " + shouldExpand); |
| 779 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 780 | boolean wasExpanded = mIsExpanded; |
| 781 | if (shouldExpand == wasExpanded) { |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 782 | return; |
| 783 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 784 | if (wasExpanded) { |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 785 | // Collapse the stack |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 786 | mExpandedViewContainer.setAlpha(0.0f); |
| 787 | // TODO: In order to prevent flicker, code below should be executed after the alpha |
| 788 | // value set on the mExpandedViewContainer is reflected on the screen. However, we |
| 789 | // cannot just postpone the execution like #setSelectedBubble(), since some of member |
| 790 | // variables referred by the code are overridden before the execution. |
| 791 | if (mExpandedBubble != null) { |
| 792 | mExpandedBubble.setContentVisibility(false); |
| 793 | } |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 794 | animateExpansion(false /* expand */); |
| 795 | logBubbleEvent(mExpandedBubble, StatsLog.BUBBLE_UICHANGED__ACTION__COLLAPSED); |
| 796 | } else { |
| 797 | // Expand the stack |
| 798 | animateExpansion(true /* expand */); |
| 799 | // TODO: move next line to BubbleData |
| 800 | logBubbleEvent(mExpandedBubble, StatsLog.BUBBLE_UICHANGED__ACTION__EXPANDED); |
| 801 | logBubbleEvent(mExpandedBubble, StatsLog.BUBBLE_UICHANGED__ACTION__STACK_EXPANDED); |
| 802 | } |
| 803 | notifyExpansionChanged(mExpandedBubble.entry, mIsExpanded); |
| 804 | } |
| 805 | |
| 806 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 807 | * Dismiss the stack of bubbles. |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 808 | * @deprecated |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 809 | */ |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 810 | @Deprecated |
Mady Mellor | c3d7d06 | 2019-03-28 16:13:05 -0700 | [diff] [blame] | 811 | void stackDismissed(int reason) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 812 | if (DEBUG) { |
| 813 | Log.d(TAG, "stackDismissed: reason=" + reason); |
| 814 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 815 | mBubbleData.dismissAll(reason); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 816 | logBubbleEvent(null /* no bubble associated with bubble stack dismiss */, |
| 817 | StatsLog.BUBBLE_UICHANGED__ACTION__STACK_DISMISSED); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 821 | * @return the view the touch event is on |
| 822 | */ |
| 823 | @Nullable |
| 824 | public View getTargetView(MotionEvent event) { |
| 825 | float x = event.getRawX(); |
| 826 | float y = event.getRawY(); |
| 827 | if (mIsExpanded) { |
| 828 | if (isIntersecting(mBubbleContainer, x, y)) { |
| 829 | for (int i = 0; i < mBubbleContainer.getChildCount(); i++) { |
| 830 | BubbleView view = (BubbleView) mBubbleContainer.getChildAt(i); |
| 831 | if (isIntersecting(view, x, y)) { |
| 832 | return view; |
| 833 | } |
| 834 | } |
| 835 | } else if (isIntersecting(mExpandedViewContainer, x, y)) { |
| 836 | return mExpandedViewContainer; |
| 837 | } |
| 838 | // Outside parts of view we care about. |
| 839 | return null; |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 840 | } else if (mFlyout.getVisibility() == VISIBLE && isIntersecting(mFlyout, x, y)) { |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 841 | return mFlyout; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 842 | } |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 843 | |
| 844 | // If it wasn't an individual bubble in the expanded state, or the flyout, it's the stack. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 845 | return this; |
| 846 | } |
| 847 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 848 | View getFlyoutView() { |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 849 | return mFlyout; |
| 850 | } |
| 851 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 852 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 853 | * Collapses the stack of bubbles. |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 854 | * <p> |
| 855 | * Must be called from the main thread. |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 856 | * |
| 857 | * @deprecated use {@link #setExpanded(boolean)} and {@link #setSelectedBubble(Bubble)} |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 858 | */ |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 859 | @Deprecated |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 860 | @MainThread |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 861 | void collapseStack() { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 862 | if (DEBUG) { |
| 863 | Log.d(TAG, "collapseStack()"); |
| 864 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 865 | mBubbleData.setExpanded(false); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 868 | /** |
| 869 | * @deprecated use {@link #setExpanded(boolean)} and {@link #setSelectedBubble(Bubble)} |
| 870 | */ |
| 871 | @Deprecated |
| 872 | @MainThread |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 873 | void collapseStack(Runnable endRunnable) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 874 | if (DEBUG) { |
| 875 | Log.d(TAG, "collapseStack(endRunnable)"); |
| 876 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 877 | collapseStack(); |
| 878 | // TODO - use the runnable at end of animation |
| 879 | endRunnable.run(); |
| 880 | } |
| 881 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 882 | /** |
Mady Mellor | 94d94a7 | 2019-03-05 18:16:59 -0800 | [diff] [blame] | 883 | * Expands the stack of bubbles. |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 884 | * <p> |
| 885 | * Must be called from the main thread. |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 886 | * |
| 887 | * @deprecated use {@link #setExpanded(boolean)} and {@link #setSelectedBubble(Bubble)} |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 888 | */ |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 889 | @Deprecated |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 890 | @MainThread |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 891 | void expandStack() { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 892 | if (DEBUG) { |
| 893 | Log.d(TAG, "expandStack()"); |
| 894 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 895 | mBubbleData.setExpanded(true); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 899 | * Tell the stack to animate to collapsed or expanded state. |
| 900 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 901 | private void animateExpansion(boolean shouldExpand) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 902 | if (DEBUG) { |
| 903 | Log.d(TAG, "animateExpansion: shouldExpand=" + shouldExpand); |
| 904 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 905 | if (mIsExpanded != shouldExpand) { |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 906 | hideFlyoutImmediate(); |
| 907 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 908 | mIsExpanded = shouldExpand; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 909 | updateExpandedBubble(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 910 | applyCurrentState(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 911 | |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 912 | mIsExpansionAnimating = true; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 913 | |
| 914 | Runnable updateAfter = () -> { |
| 915 | applyCurrentState(); |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 916 | mIsExpansionAnimating = false; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 917 | requestUpdate(); |
| 918 | }; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 919 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 920 | if (shouldExpand) { |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 921 | mBubbleContainer.setActiveController(mExpandedAnimationController); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 922 | mExpandedAnimationController.expandFromStack(() -> { |
| 923 | updatePointerPosition(); |
| 924 | updateAfter.run(); |
| 925 | } /* after */); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 926 | } else { |
| 927 | mBubbleContainer.cancelAllAnimations(); |
| 928 | mExpandedAnimationController.collapseBackToStack( |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 929 | mStackAnimationController.getStackPositionAlongNearestHorizontalEdge(), |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 930 | () -> { |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 931 | mBubbleContainer.setActiveController(mStackAnimationController); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 932 | updateAfter.run(); |
| 933 | }); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 934 | } |
| 935 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 936 | final float xStart = |
| 937 | mStackAnimationController.getStackPosition().x < getWidth() / 2 |
| 938 | ? -mExpandedAnimateXDistance |
| 939 | : mExpandedAnimateXDistance; |
| 940 | |
| 941 | final float yStart = Math.min( |
| 942 | mStackAnimationController.getStackPosition().y, |
| 943 | mExpandedAnimateYDistance); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 944 | final float yDest = getYPositionForExpandedView(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 945 | |
| 946 | if (shouldExpand) { |
| 947 | mExpandedViewContainer.setTranslationX(xStart); |
| 948 | mExpandedViewContainer.setTranslationY(yStart); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 949 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 950 | |
| 951 | mExpandedViewXAnim.animateToFinalPosition(shouldExpand ? 0f : xStart); |
| 952 | mExpandedViewYAnim.animateToFinalPosition(shouldExpand ? yDest : yStart); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 956 | private void notifyExpansionChanged(NotificationEntry entry, boolean expanded) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 957 | if (mExpandListener != null) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 958 | mExpandListener.onBubbleExpandChanged(expanded, entry != null ? entry.key : null); |
| 959 | } |
| 960 | } |
| 961 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 962 | /** Return the BubbleView at the given index from the bubble container. */ |
| 963 | public BubbleView getBubbleAt(int i) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 964 | return mBubbleContainer.getChildCount() > i |
| 965 | ? (BubbleView) mBubbleContainer.getChildAt(i) |
| 966 | : null; |
| 967 | } |
| 968 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 969 | /** Moves the bubbles out of the way if they're going to be over the keyboard. */ |
| 970 | public void onImeVisibilityChanged(boolean visible, int height) { |
Joshua Tsuji | 4b39591 | 2019-04-19 17:18:40 -0400 | [diff] [blame] | 971 | mStackAnimationController.setImeHeight(height + mImeOffset); |
| 972 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 973 | if (!mIsExpanded) { |
Joshua Tsuji | 4b39591 | 2019-04-19 17:18:40 -0400 | [diff] [blame] | 974 | mStackAnimationController.animateForImeVisibility(visible); |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 975 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /** Called when a drag operation on an individual bubble has started. */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 979 | public void onBubbleDragStart(View bubble) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 980 | if (DEBUG) { |
| 981 | Log.d(TAG, "onBubbleDragStart: bubble=" + bubble); |
| 982 | } |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 983 | mExpandedAnimationController.prepareForBubbleDrag(bubble); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /** Called with the coordinates to which an individual bubble has been dragged. */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 987 | public void onBubbleDragged(View bubble, float x, float y) { |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 988 | if (!mIsExpanded || mIsExpansionAnimating) { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 989 | return; |
| 990 | } |
| 991 | |
| 992 | mExpandedAnimationController.dragBubbleOut(bubble, x, y); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 993 | springInDismissTarget(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /** Called when a drag operation on an individual bubble has finished. */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 997 | public void onBubbleDragFinish( |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 998 | View bubble, float x, float y, float velX, float velY) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 999 | if (DEBUG) { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1000 | Log.d(TAG, "onBubbleDragFinish: bubble=" + bubble); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1001 | } |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1002 | |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1003 | if (!mIsExpanded || mIsExpansionAnimating) { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1004 | return; |
| 1005 | } |
| 1006 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1007 | mExpandedAnimationController.snapBubbleBack(bubble, velX, velY); |
| 1008 | springOutDismissTargetAndHideCircle(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | void onDragStart() { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1012 | if (DEBUG) { |
| 1013 | Log.d(TAG, "onDragStart()"); |
| 1014 | } |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1015 | if (mIsExpanded || mIsExpansionAnimating) { |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1016 | return; |
| 1017 | } |
| 1018 | |
| 1019 | mStackAnimationController.cancelStackPositionAnimations(); |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 1020 | mBubbleContainer.setActiveController(mStackAnimationController); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1021 | hideFlyoutImmediate(); |
| 1022 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1023 | mDraggingInDismissTarget = false; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | void onDragged(float x, float y) { |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1027 | if (mIsExpanded || mIsExpansionAnimating) { |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1028 | return; |
| 1029 | } |
| 1030 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1031 | springInDismissTarget(); |
| 1032 | mStackAnimationController.moveStackFromTouch(x, y); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | void onDragFinish(float x, float y, float velX, float velY) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1036 | if (DEBUG) { |
| 1037 | Log.d(TAG, "onDragFinish"); |
| 1038 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1039 | |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1040 | if (mIsExpanded || mIsExpansionAnimating) { |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1041 | return; |
| 1042 | } |
| 1043 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1044 | final float newStackX = mStackAnimationController.flingStackThenSpringToEdge(x, velX, velY); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1045 | logBubbleEvent(null /* no bubble associated with bubble stack move */, |
| 1046 | StatsLog.BUBBLE_UICHANGED__ACTION__STACK_MOVED); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1047 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1048 | mStackOnLeftOrWillBe = newStackX <= 0; |
| 1049 | updateBubbleShadowsAndDotPosition(true /* animate */); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1050 | springOutDismissTargetAndHideCircle(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1053 | void onFlyoutDragStart() { |
| 1054 | mFlyout.removeCallbacks(mHideFlyout); |
| 1055 | } |
| 1056 | |
| 1057 | void onFlyoutDragged(float deltaX) { |
| 1058 | final boolean onLeft = mStackAnimationController.isStackOnLeftSide(); |
| 1059 | mFlyoutDragDeltaX = deltaX; |
| 1060 | |
| 1061 | final float collapsePercent = |
| 1062 | onLeft ? -deltaX / mFlyout.getWidth() : deltaX / mFlyout.getWidth(); |
| 1063 | mFlyout.setCollapsePercent(Math.min(1f, Math.max(0f, collapsePercent))); |
| 1064 | |
| 1065 | // Calculate how to translate the flyout if it has been dragged too far in etiher direction. |
| 1066 | float overscrollTranslation = 0f; |
| 1067 | if (collapsePercent < 0f || collapsePercent > 1f) { |
| 1068 | // Whether we are more than 100% transitioned to the dot. |
| 1069 | final boolean overscrollingPastDot = collapsePercent > 1f; |
| 1070 | |
| 1071 | // Whether we are overscrolling physically to the left - this can either be pulling the |
| 1072 | // flyout away from the stack (if the stack is on the right) or pushing it to the left |
| 1073 | // after it has already become the dot. |
| 1074 | final boolean overscrollingLeft = |
| 1075 | (onLeft && collapsePercent > 1f) || (!onLeft && collapsePercent < 0f); |
| 1076 | |
| 1077 | overscrollTranslation = |
| 1078 | (overscrollingPastDot ? collapsePercent - 1f : collapsePercent * -1) |
| 1079 | * (overscrollingLeft ? -1 : 1) |
| 1080 | * (mFlyout.getWidth() / (FLYOUT_OVERSCROLL_ATTENUATION_FACTOR |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 1081 | // Attenuate the smaller dot less than the larger flyout. |
| 1082 | / (overscrollingPastDot ? 2 : 1))); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | mFlyout.setTranslationX(mFlyout.getRestingTranslationX() + overscrollTranslation); |
| 1086 | } |
| 1087 | |
| 1088 | /** |
| 1089 | * Called when the flyout drag has finished, and returns true if the gesture successfully |
| 1090 | * dismissed the flyout. |
| 1091 | */ |
| 1092 | void onFlyoutDragFinished(float deltaX, float velX) { |
| 1093 | final boolean onLeft = mStackAnimationController.isStackOnLeftSide(); |
| 1094 | final boolean metRequiredVelocity = |
| 1095 | onLeft ? velX < -FLYOUT_DISMISS_VELOCITY : velX > FLYOUT_DISMISS_VELOCITY; |
| 1096 | final boolean metRequiredDeltaX = |
| 1097 | onLeft |
| 1098 | ? deltaX < -mFlyout.getWidth() * FLYOUT_DRAG_PERCENT_DISMISS |
| 1099 | : deltaX > mFlyout.getWidth() * FLYOUT_DRAG_PERCENT_DISMISS; |
| 1100 | final boolean isCancelFling = onLeft ? velX > 0 : velX < 0; |
| 1101 | final boolean shouldDismiss = metRequiredVelocity || (metRequiredDeltaX && !isCancelFling); |
| 1102 | |
| 1103 | mFlyout.removeCallbacks(mHideFlyout); |
| 1104 | animateFlyoutCollapsed(shouldDismiss, velX); |
| 1105 | } |
| 1106 | |
| 1107 | /** |
| 1108 | * Called when the first touch event of a gesture (stack drag, bubble drag, flyout drag, etc.) |
| 1109 | * is received. |
| 1110 | */ |
| 1111 | void onGestureStart() { |
| 1112 | mIsGestureInProgress = true; |
| 1113 | } |
| 1114 | |
| 1115 | /** Called when a gesture is completed or cancelled. */ |
| 1116 | void onGestureFinished() { |
| 1117 | mIsGestureInProgress = false; |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 1118 | |
| 1119 | if (mIsExpanded) { |
| 1120 | mExpandedAnimationController.onGestureFinished(); |
| 1121 | } |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1122 | } |
| 1123 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1124 | /** Prepares and starts the desaturate/darken animation on the bubble stack. */ |
| 1125 | private void animateDesaturateAndDarken(View targetView, boolean desaturateAndDarken) { |
| 1126 | mDesaturateAndDarkenTargetView = targetView; |
| 1127 | |
| 1128 | if (desaturateAndDarken) { |
| 1129 | // Use the animated paint for the bubbles. |
| 1130 | mDesaturateAndDarkenTargetView.setLayerType( |
| 1131 | View.LAYER_TYPE_HARDWARE, mDesaturateAndDarkenPaint); |
| 1132 | mDesaturateAndDarkenAnimator.removeAllListeners(); |
| 1133 | mDesaturateAndDarkenAnimator.start(); |
| 1134 | } else { |
| 1135 | mDesaturateAndDarkenAnimator.removeAllListeners(); |
| 1136 | mDesaturateAndDarkenAnimator.addListener(new AnimatorListenerAdapter() { |
| 1137 | @Override |
| 1138 | public void onAnimationEnd(Animator animation) { |
| 1139 | super.onAnimationEnd(animation); |
| 1140 | // Stop using the animated paint. |
| 1141 | resetDesaturationAndDarken(); |
| 1142 | } |
| 1143 | }); |
| 1144 | mDesaturateAndDarkenAnimator.reverse(); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | private void resetDesaturationAndDarken() { |
| 1149 | mDesaturateAndDarkenAnimator.removeAllListeners(); |
| 1150 | mDesaturateAndDarkenAnimator.cancel(); |
| 1151 | mDesaturateAndDarkenTargetView.setLayerType(View.LAYER_TYPE_NONE, null); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Magnets the stack to the target, while also transforming the target to encircle the stack and |
| 1156 | * desaturating/darkening the bubbles. |
| 1157 | */ |
| 1158 | void animateMagnetToDismissTarget( |
| 1159 | View magnetView, boolean toTarget, float x, float y, float velX, float velY) { |
| 1160 | mDraggingInDismissTarget = toTarget; |
| 1161 | |
| 1162 | if (toTarget) { |
| 1163 | // The Y-value for the bubble stack to be positioned in the center of the dismiss target |
| 1164 | final float destY = mDismissContainer.getDismissTargetCenterY() - mBubbleSize / 2f; |
| 1165 | |
| 1166 | mAnimatingMagnet = true; |
| 1167 | |
| 1168 | final Runnable afterMagnet = () -> { |
| 1169 | mAnimatingMagnet = false; |
| 1170 | if (mAfterMagnet != null) { |
| 1171 | mAfterMagnet.run(); |
| 1172 | } |
| 1173 | }; |
| 1174 | |
| 1175 | if (magnetView == this) { |
| 1176 | mStackAnimationController.magnetToDismiss(velX, velY, destY, afterMagnet); |
| 1177 | animateDesaturateAndDarken(mBubbleContainer, true); |
| 1178 | } else { |
| 1179 | mExpandedAnimationController.magnetBubbleToDismiss( |
| 1180 | magnetView, velX, velY, destY, afterMagnet); |
| 1181 | |
| 1182 | animateDesaturateAndDarken(magnetView, true); |
| 1183 | } |
| 1184 | |
| 1185 | mDismissContainer.animateEncircleCenterWithX(true); |
| 1186 | |
| 1187 | } else { |
| 1188 | mAnimatingMagnet = false; |
| 1189 | |
| 1190 | if (magnetView == this) { |
| 1191 | mStackAnimationController.demagnetizeFromDismissToPoint(x, y, velX, velY); |
| 1192 | animateDesaturateAndDarken(mBubbleContainer, false); |
| 1193 | } else { |
| 1194 | mExpandedAnimationController.demagnetizeBubbleTo(x, y, velX, velY); |
| 1195 | animateDesaturateAndDarken(magnetView, false); |
| 1196 | } |
| 1197 | |
| 1198 | mDismissContainer.animateEncircleCenterWithX(false); |
| 1199 | } |
| 1200 | |
| 1201 | mVibrator.vibrate(VibrationEffect.get(toTarget |
| 1202 | ? VibrationEffect.EFFECT_CLICK |
| 1203 | : VibrationEffect.EFFECT_TICK)); |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * Magnets the stack to the dismiss target if it's not already there. Then, dismiss the stack |
| 1208 | * using the 'implode' animation and animate out the target. |
| 1209 | */ |
| 1210 | void magnetToStackIfNeededThenAnimateDismissal( |
| 1211 | View touchedView, float velX, float velY, Runnable after) { |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 1212 | final View draggedOutBubble = mExpandedAnimationController.getDraggedOutBubble(); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1213 | final Runnable animateDismissal = () -> { |
| 1214 | mAfterMagnet = null; |
| 1215 | |
| 1216 | mVibrator.vibrate(VibrationEffect.get(VibrationEffect.EFFECT_CLICK)); |
| 1217 | mDismissContainer.animateEncirclingCircleDisappearance(); |
| 1218 | |
| 1219 | // 'Implode' the stack and then hide the dismiss target. |
| 1220 | if (touchedView == this) { |
| 1221 | mStackAnimationController.implodeStack( |
| 1222 | () -> { |
| 1223 | mAnimatingMagnet = false; |
| 1224 | mShowingDismiss = false; |
| 1225 | mDraggingInDismissTarget = false; |
| 1226 | after.run(); |
| 1227 | resetDesaturationAndDarken(); |
| 1228 | }); |
| 1229 | } else { |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 1230 | mExpandedAnimationController.dismissDraggedOutBubble(draggedOutBubble, () -> { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1231 | mAnimatingMagnet = false; |
| 1232 | mShowingDismiss = false; |
| 1233 | mDraggingInDismissTarget = false; |
| 1234 | resetDesaturationAndDarken(); |
| 1235 | after.run(); |
| 1236 | }); |
| 1237 | } |
| 1238 | }; |
| 1239 | |
| 1240 | if (mAnimatingMagnet) { |
| 1241 | // If the magnet animation is currently playing, dismiss the stack after it's done. This |
| 1242 | // happens if the stack is flung towards the target. |
| 1243 | mAfterMagnet = animateDismissal; |
| 1244 | } else if (mDraggingInDismissTarget) { |
| 1245 | // If we're in the dismiss target, but not animating, we already magneted - dismiss |
| 1246 | // immediately. |
| 1247 | animateDismissal.run(); |
| 1248 | } else { |
| 1249 | // Otherwise, we need to start the magnet animation and then dismiss afterward. |
| 1250 | animateMagnetToDismissTarget(touchedView, true, -1 /* x */, -1 /* y */, velX, velY); |
| 1251 | mAfterMagnet = animateDismissal; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | /** Animates in the dismiss target, including the gradient behind it. */ |
| 1256 | private void springInDismissTarget() { |
| 1257 | if (mShowingDismiss) { |
| 1258 | return; |
| 1259 | } |
| 1260 | |
| 1261 | mShowingDismiss = true; |
| 1262 | |
| 1263 | // Show the dismiss container and bring it to the front so the bubbles will go behind it. |
| 1264 | mDismissContainer.springIn(); |
| 1265 | mDismissContainer.bringToFront(); |
| 1266 | mDismissContainer.setZ(Short.MAX_VALUE - 1); |
| 1267 | } |
| 1268 | |
| 1269 | /** |
| 1270 | * Animates the dismiss target out, as well as the circle that encircles the bubbles, if they |
| 1271 | * were dragged into the target and encircled. |
| 1272 | */ |
| 1273 | private void springOutDismissTargetAndHideCircle() { |
| 1274 | if (!mShowingDismiss) { |
| 1275 | return; |
| 1276 | } |
| 1277 | |
| 1278 | mDismissContainer.springOut(); |
| 1279 | mShowingDismiss = false; |
| 1280 | } |
| 1281 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1282 | /** Whether the location of the given MotionEvent is within the dismiss target area. */ |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1283 | boolean isInDismissTarget(MotionEvent ev) { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1284 | return isIntersecting(mDismissContainer.getDismissTarget(), ev.getRawX(), ev.getRawY()); |
Joshua Tsuji | 19e22e424 | 2019-04-17 13:29:10 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1287 | /** Animates the flyout collapsed (to dot), or the reverse, starting with the given velocity. */ |
| 1288 | private void animateFlyoutCollapsed(boolean collapsed, float velX) { |
| 1289 | final boolean onLeft = mStackAnimationController.isStackOnLeftSide(); |
| 1290 | mFlyoutTransitionSpring |
| 1291 | .setStartValue(mFlyoutDragDeltaX) |
| 1292 | .setStartVelocity(velX) |
| 1293 | .animateToFinalPosition(collapsed |
| 1294 | ? (onLeft ? -mFlyout.getWidth() : mFlyout.getWidth()) |
| 1295 | : 0f); |
| 1296 | } |
| 1297 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1298 | /** |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 1299 | * Calculates how large the expanded view of the bubble can be. This takes into account the |
| 1300 | * y position when the bubbles are expanded as well as the bounds of the dismiss target. |
| 1301 | */ |
| 1302 | int getMaxExpandedHeight() { |
| 1303 | int expandedY = (int) mExpandedAnimationController.getExpandedY(); |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 1304 | // PIP dismiss view uses FLAG_LAYOUT_IN_SCREEN so we need to subtract the bottom inset |
| 1305 | int pipDismissHeight = mPipDismissHeight - getBottomInset(); |
| 1306 | return mDisplaySize.y - expandedY - mBubbleSize - pipDismissHeight; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | /** |
| 1310 | * Calculates the y position of the expanded view when it is expanded. |
| 1311 | */ |
| 1312 | float getYPositionForExpandedView() { |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 1313 | return getStatusBarHeight() + mBubbleSize + mBubblePadding + mPointerHeight; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * Called when the height of the currently expanded view has changed (not via an |
| 1318 | * update to the bubble's desired height but for some other reason, e.g. permission view |
| 1319 | * goes away). |
| 1320 | */ |
| 1321 | void onExpandedHeightChanged() { |
| 1322 | if (mIsExpanded) { |
| 1323 | requestUpdate(); |
| 1324 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1327 | /** Sets whether all bubbles in the stack should not show the 'new' dot. */ |
| 1328 | void setSuppressNewDot(boolean suppressNewDot) { |
| 1329 | mSuppressNewDot = suppressNewDot; |
| 1330 | |
| 1331 | for (int i = 0; i < mBubbleContainer.getChildCount(); i++) { |
| 1332 | BubbleView bv = (BubbleView) mBubbleContainer.getChildAt(i); |
| 1333 | bv.setSuppressDot(suppressNewDot, true /* animate */); |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | /** |
| 1338 | * Sets whether the flyout should not appear, even if the notif otherwise would generate one. |
| 1339 | */ |
| 1340 | void setSuppressFlyout(boolean suppressFlyout) { |
| 1341 | mSuppressFlyout = suppressFlyout; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * Callback to run after the flyout hides. Also called if a new flyout is shown before the |
| 1346 | * previous one animates out. |
| 1347 | */ |
| 1348 | private Runnable mAfterFlyoutHides; |
| 1349 | |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1350 | /** |
| 1351 | * Animates in the flyout for the given bubble, if available, and then hides it after some time. |
| 1352 | */ |
| 1353 | @VisibleForTesting |
| 1354 | void animateInFlyoutForBubble(Bubble bubble) { |
| 1355 | final CharSequence updateMessage = bubble.entry.getUpdateMessage(getContext()); |
| 1356 | |
| 1357 | // Show the message if one exists, and we're not expanded or animating expansion. |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1358 | if (updateMessage != null |
| 1359 | && !isExpanded() |
| 1360 | && !mIsExpansionAnimating |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1361 | && !mIsGestureInProgress |
| 1362 | && !mSuppressFlyout) { |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1363 | if (bubble.iconView != null) { |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1364 | // Temporarily suppress the dot while the flyout is visible. |
| 1365 | bubble.iconView.setSuppressDot( |
| 1366 | true /* suppressDot */, false /* animate */); |
| 1367 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1368 | mFlyoutDragDeltaX = 0f; |
| 1369 | mFlyout.setAlpha(0f); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1370 | |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1371 | if (mAfterFlyoutHides != null) { |
| 1372 | mAfterFlyoutHides.run(); |
| 1373 | } |
| 1374 | |
| 1375 | mAfterFlyoutHides = () -> { |
| 1376 | if (bubble.iconView == null) { |
| 1377 | return; |
| 1378 | } |
| 1379 | |
| 1380 | // If we're going to suppress the dot, make it visible first so it'll |
| 1381 | // visibly animate away. |
| 1382 | if (mSuppressNewDot) { |
| 1383 | bubble.iconView.setSuppressDot( |
| 1384 | false /* suppressDot */, false /* animate */); |
| 1385 | } |
| 1386 | |
| 1387 | // Reset dot suppression. If we're not suppressing due to DND, then |
| 1388 | // stop suppressing it with no animation (since the flyout has |
| 1389 | // transformed into the dot). If we are suppressing due to DND, animate |
| 1390 | // it away. |
| 1391 | bubble.iconView.setSuppressDot( |
| 1392 | mSuppressNewDot /* suppressDot */, |
| 1393 | mSuppressNewDot /* animate */); |
| 1394 | }; |
| 1395 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1396 | // Post in case layout isn't complete and getWidth returns 0. |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 1397 | post(() -> { |
| 1398 | // An auto-expanding bubble could have been posted during the time it takes to |
| 1399 | // layout. |
| 1400 | if (isExpanded()) { |
| 1401 | return; |
| 1402 | } |
| 1403 | |
| 1404 | mFlyout.showFlyout( |
| 1405 | updateMessage, mStackAnimationController.getStackPosition(), getWidth(), |
| 1406 | mStackAnimationController.isStackOnLeftSide(), |
| 1407 | bubble.iconView.getBadgeColor(), mAfterFlyoutHides); |
| 1408 | }); |
Joshua Tsuji | 36b1b2c | 2019-04-18 16:27:35 -0400 | [diff] [blame] | 1409 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1410 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1411 | mFlyout.removeCallbacks(mHideFlyout); |
| 1412 | mFlyout.postDelayed(mHideFlyout, FLYOUT_HIDE_AFTER); |
Steven Wu | 1684f2d | 2019-04-11 14:10:42 -0400 | [diff] [blame] | 1413 | logBubbleEvent(bubble, StatsLog.BUBBLE_UICHANGED__ACTION__FLYOUT); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | /** Hide the flyout immediately and cancel any pending hide runnables. */ |
| 1418 | private void hideFlyoutImmediate() { |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1419 | if (mAfterFlyoutHides != null) { |
| 1420 | mAfterFlyoutHides.run(); |
| 1421 | } |
| 1422 | |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1423 | mFlyout.removeCallbacks(mHideFlyout); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1424 | mFlyout.hideFlyout(); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1425 | } |
| 1426 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1427 | @Override |
| 1428 | public void getBoundsOnScreen(Rect outRect) { |
| 1429 | if (!mIsExpanded) { |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 1430 | if (mBubbleContainer.getChildCount() > 0) { |
| 1431 | mBubbleContainer.getChildAt(0).getBoundsOnScreen(outRect); |
| 1432 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1433 | } else { |
| 1434 | mBubbleContainer.getBoundsOnScreen(outRect); |
| 1435 | } |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1436 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1437 | if (mFlyout.getVisibility() == View.VISIBLE) { |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1438 | final Rect flyoutBounds = new Rect(); |
| 1439 | mFlyout.getBoundsOnScreen(flyoutBounds); |
| 1440 | outRect.union(flyoutBounds); |
| 1441 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | private int getStatusBarHeight() { |
| 1445 | if (getRootWindowInsets() != null) { |
Joshua Tsuji | 0fee768 | 2019-01-25 11:37:49 -0500 | [diff] [blame] | 1446 | WindowInsets insets = getRootWindowInsets(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1447 | return Math.max( |
Joshua Tsuji | f44347f | 2019-02-12 14:28:06 -0500 | [diff] [blame] | 1448 | mStatusBarHeight, |
Joshua Tsuji | 0fee768 | 2019-01-25 11:37:49 -0500 | [diff] [blame] | 1449 | insets.getDisplayCutout() != null |
| 1450 | ? insets.getDisplayCutout().getSafeInsetTop() |
| 1451 | : 0); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | return 0; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1455 | } |
| 1456 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 1457 | private int getBottomInset() { |
| 1458 | if (getRootWindowInsets() != null) { |
| 1459 | WindowInsets insets = getRootWindowInsets(); |
| 1460 | return insets.getSystemWindowInsetBottom(); |
| 1461 | } |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1465 | private boolean isIntersecting(View view, float x, float y) { |
| 1466 | mTempLoc = view.getLocationOnScreen(); |
| 1467 | mTempRect.set(mTempLoc[0], mTempLoc[1], mTempLoc[0] + view.getWidth(), |
| 1468 | mTempLoc[1] + view.getHeight()); |
| 1469 | return mTempRect.contains(x, y); |
| 1470 | } |
| 1471 | |
| 1472 | private void requestUpdate() { |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1473 | if (mViewUpdatedRequested || mIsExpansionAnimating) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1474 | return; |
| 1475 | } |
| 1476 | mViewUpdatedRequested = true; |
| 1477 | getViewTreeObserver().addOnPreDrawListener(mViewUpdater); |
| 1478 | invalidate(); |
| 1479 | } |
| 1480 | |
| 1481 | private void updateExpandedBubble() { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1482 | if (DEBUG) { |
| 1483 | Log.d(TAG, "updateExpandedBubble()"); |
| 1484 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1485 | mExpandedViewContainer.removeAllViews(); |
| 1486 | if (mExpandedBubble != null && mIsExpanded) { |
| 1487 | mExpandedViewContainer.addView(mExpandedBubble.expandedView); |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 1488 | mExpandedBubble.expandedView.populateExpandedView(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1489 | mExpandedViewContainer.setVisibility(mIsExpanded ? VISIBLE : GONE); |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 1490 | mExpandedViewContainer.setAlpha(1.0f); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | private void applyCurrentState() { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1495 | if (DEBUG) { |
| 1496 | Log.d(TAG, "applyCurrentState: mIsExpanded=" + mIsExpanded); |
| 1497 | } |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1498 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1499 | mExpandedViewContainer.setVisibility(mIsExpanded ? VISIBLE : GONE); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1500 | if (mIsExpanded) { |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 1501 | // First update the view so that it calculates a new height (ensuring the y position |
| 1502 | // calculation is correct) |
| 1503 | mExpandedBubble.expandedView.updateView(); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 1504 | final float y = getYPositionForExpandedView(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 1505 | if (!mExpandedViewYAnim.isRunning()) { |
| 1506 | // We're not animating so set the value |
| 1507 | mExpandedViewContainer.setTranslationY(y); |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1508 | mExpandedBubble.expandedView.updateView(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 1509 | } else { |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1510 | // We are animating so update the value; there is an end listener on the animator |
| 1511 | // that will ensure expandedeView.updateView gets called. |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 1512 | mExpandedViewYAnim.animateToFinalPosition(y); |
| 1513 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1514 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1515 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1516 | mStackOnLeftOrWillBe = mStackAnimationController.isStackOnLeftSide(); |
| 1517 | updateBubbleShadowsAndDotPosition(false); |
| 1518 | } |
| 1519 | |
| 1520 | /** Sets the appropriate Z-order and dot position for each bubble in the stack. */ |
| 1521 | private void updateBubbleShadowsAndDotPosition(boolean animate) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1522 | int bubbsCount = mBubbleContainer.getChildCount(); |
| 1523 | for (int i = 0; i < bubbsCount; i++) { |
| 1524 | BubbleView bv = (BubbleView) mBubbleContainer.getChildAt(i); |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1525 | bv.updateDotVisibility(true /* animate */); |
Joshua Tsuji | 25a4b7b | 2019-03-22 14:11:06 -0400 | [diff] [blame] | 1526 | bv.setZ((BubbleController.MAX_BUBBLES |
| 1527 | * getResources().getDimensionPixelSize(R.dimen.bubble_elevation)) - i); |
Joshua Tsuji | 580c0bf | 2019-01-28 13:28:21 -0500 | [diff] [blame] | 1528 | |
| 1529 | // Draw the shadow around the circle inscribed within the bubble's bounds. This |
| 1530 | // (intentionally) does not draw a shadow behind the update dot, which should be drawing |
| 1531 | // its own shadow since it's on a different (higher) plane. |
| 1532 | bv.setOutlineProvider(new ViewOutlineProvider() { |
| 1533 | @Override |
| 1534 | public void getOutline(View view, Outline outline) { |
| 1535 | outline.setOval(0, 0, mBubbleSize, mBubbleSize); |
| 1536 | } |
| 1537 | }); |
| 1538 | bv.setClipToOutline(false); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1539 | |
| 1540 | // If the dot is on the left, and so is the stack, we need to change the dot position. |
| 1541 | if (bv.getDotPositionOnLeft() == mStackOnLeftOrWillBe) { |
| 1542 | bv.setDotPosition(!mStackOnLeftOrWillBe, animate); |
| 1543 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
Mady Mellor | de2d4d2 | 2019-01-29 14:15:34 -0800 | [diff] [blame] | 1547 | private void updatePointerPosition() { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1548 | if (DEBUG) { |
| 1549 | Log.d(TAG, "updatePointerPosition()"); |
| 1550 | } |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 1551 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 1552 | Bubble expandedBubble = getExpandedBubble(); |
| 1553 | if (expandedBubble == null) { |
| 1554 | return; |
Mady Mellor | de2d4d2 | 2019-01-29 14:15:34 -0800 | [diff] [blame] | 1555 | } |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 1556 | |
| 1557 | int index = getBubbleIndex(expandedBubble); |
| 1558 | float bubbleLeftFromScreenLeft = mExpandedAnimationController.getBubbleLeft(index); |
| 1559 | float halfBubble = mBubbleSize / 2f; |
| 1560 | |
| 1561 | // Bubbles live in expanded view container (x includes expanded view padding). |
| 1562 | // Pointer lives in expanded view, which has padding (x does not include padding). |
| 1563 | // Remove padding when deriving pointer location from bubbles. |
| 1564 | float bubbleCenter = bubbleLeftFromScreenLeft + halfBubble - mExpandedViewPadding; |
| 1565 | |
| 1566 | expandedBubble.expandedView.setPointerPosition(bubbleCenter); |
Mady Mellor | de2d4d2 | 2019-01-29 14:15:34 -0800 | [diff] [blame] | 1567 | } |
| 1568 | |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1569 | /** |
| 1570 | * @return the number of bubbles in the stack view. |
| 1571 | */ |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 1572 | public int getBubbleCount() { |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1573 | return mBubbleContainer.getChildCount(); |
| 1574 | } |
| 1575 | |
| 1576 | /** |
| 1577 | * Finds the bubble index within the stack. |
| 1578 | * |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1579 | * @param bubble the bubble to look up. |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1580 | * @return the index of the bubble view within the bubble stack. The range of the position |
| 1581 | * is between 0 and the bubble count minus 1. |
| 1582 | */ |
Steven Wu | a62cb6a | 2019-02-15 17:12:51 -0500 | [diff] [blame] | 1583 | int getBubbleIndex(@Nullable Bubble bubble) { |
| 1584 | if (bubble == null) { |
| 1585 | return 0; |
| 1586 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1587 | return mBubbleContainer.indexOfChild(bubble.iconView); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * @return the normalized x-axis position of the bubble stack rounded to 4 decimal places. |
| 1592 | */ |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 1593 | public float getNormalizedXPosition() { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1594 | return new BigDecimal(getStackPosition().x / mDisplaySize.x) |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1595 | .setScale(4, RoundingMode.CEILING.HALF_UP) |
| 1596 | .floatValue(); |
| 1597 | } |
| 1598 | |
| 1599 | /** |
| 1600 | * @return the normalized y-axis position of the bubble stack rounded to 4 decimal places. |
| 1601 | */ |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 1602 | public float getNormalizedYPosition() { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1603 | return new BigDecimal(getStackPosition().y / mDisplaySize.y) |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1604 | .setScale(4, RoundingMode.CEILING.HALF_UP) |
| 1605 | .floatValue(); |
| 1606 | } |
| 1607 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1608 | public PointF getStackPosition() { |
| 1609 | return mStackAnimationController.getStackPosition(); |
| 1610 | } |
| 1611 | |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1612 | /** |
| 1613 | * Logs the bubble UI event. |
| 1614 | * |
| 1615 | * @param bubble the bubble that is being interacted on. Null value indicates that |
| 1616 | * the user interaction is not specific to one bubble. |
| 1617 | * @param action the user interaction enum. |
| 1618 | */ |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1619 | private void logBubbleEvent(@Nullable Bubble bubble, int action) { |
Steven Wu | 1684f2d | 2019-04-11 14:10:42 -0400 | [diff] [blame] | 1620 | if (bubble == null || bubble.entry == null |
| 1621 | || bubble.entry.notification == null) { |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1622 | StatsLog.write(StatsLog.BUBBLE_UI_CHANGED, |
| 1623 | null /* package name */, |
| 1624 | null /* notification channel */, |
| 1625 | 0 /* notification ID */, |
| 1626 | 0 /* bubble position */, |
| 1627 | getBubbleCount(), |
| 1628 | action, |
| 1629 | getNormalizedXPosition(), |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 1630 | getNormalizedYPosition(), |
Steven Wu | 8ba8ca9 | 2019-04-11 10:47:42 -0400 | [diff] [blame] | 1631 | false /* unread bubble */, |
| 1632 | false /* on-going bubble */, |
| 1633 | false /* foreground bubble */); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1634 | } else { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1635 | StatusBarNotification notification = bubble.entry.notification; |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1636 | StatsLog.write(StatsLog.BUBBLE_UI_CHANGED, |
| 1637 | notification.getPackageName(), |
| 1638 | notification.getNotification().getChannelId(), |
| 1639 | notification.getId(), |
| 1640 | getBubbleIndex(bubble), |
| 1641 | getBubbleCount(), |
| 1642 | action, |
| 1643 | getNormalizedXPosition(), |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 1644 | getNormalizedYPosition(), |
Steven Wu | 8ba8ca9 | 2019-04-11 10:47:42 -0400 | [diff] [blame] | 1645 | bubble.entry.showInShadeWhenBubble(), |
| 1646 | bubble.entry.isForegroundService(), |
| 1647 | BubbleController.isForegroundApp(mContext, notification.getPackageName())); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1648 | } |
| 1649 | } |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 1650 | |
| 1651 | /** |
| 1652 | * Called when a back gesture should be directed to the Bubbles stack. When expanded, |
| 1653 | * a back key down/up event pair is forwarded to the bubble Activity. |
| 1654 | */ |
| 1655 | boolean performBackPressIfNeeded() { |
| 1656 | if (!isExpanded()) { |
| 1657 | return false; |
| 1658 | } |
| 1659 | return mExpandedBubble.expandedView.performBackPressIfNeeded(); |
| 1660 | } |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1661 | |
| 1662 | /** For debugging only */ |
| 1663 | List<Bubble> getBubblesOnScreen() { |
| 1664 | List<Bubble> bubbles = new ArrayList<>(); |
| 1665 | for (int i = 0; i < mBubbleContainer.getChildCount(); i++) { |
| 1666 | View child = mBubbleContainer.getChildAt(i); |
| 1667 | if (child instanceof BubbleView) { |
| 1668 | String key = ((BubbleView) child).getKey(); |
| 1669 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 1670 | bubbles.add(bubble); |
| 1671 | } |
| 1672 | } |
| 1673 | return bubbles; |
| 1674 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1675 | } |