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