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