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