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) { |
| 1077 | Bubble b = mBubbleData.getSelectedBubble(); |
| 1078 | TextView description = mUserEducationView.findViewById(R.id.user_education_description); |
| 1079 | description.setText(mContext.getString( |
| 1080 | R.string.bubbles_user_education_description, b.getAppName())); |
| 1081 | |
| 1082 | mUserEducationView.setAlpha(0); |
| 1083 | mUserEducationView.setVisibility(VISIBLE); |
| 1084 | // Post so we have height of mUserEducationView |
| 1085 | mUserEducationView.post(() -> { |
| 1086 | final int viewHeight = mUserEducationView.getHeight(); |
| 1087 | PointF stackPosition = mStackAnimationController.getDefaultStartPosition(); |
| 1088 | final float translationY = stackPosition.y + (mBubbleSize / 2) - (viewHeight / 2); |
| 1089 | mUserEducationView.setTranslationY(translationY); |
| 1090 | mUserEducationView.animate() |
| 1091 | .setDuration(ANIMATE_STACK_USER_EDUCATION_DURATION) |
| 1092 | .setInterpolator(FAST_OUT_SLOW_IN) |
| 1093 | .alpha(1); |
| 1094 | }); |
| 1095 | Prefs.putBoolean(getContext(), HAS_SEEN_BUBBLES_EDUCATION, true); |
| 1096 | return true; |
| 1097 | } |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * If necessary, hides the user education view for the bubble stack. |
| 1103 | * |
| 1104 | * @param fromExpansion if true this indicates the hide is happening due to the bubble being |
| 1105 | * expanded, false if due to a touch outside of the bubble stack. |
| 1106 | */ |
| 1107 | void hideStackUserEducation(boolean fromExpansion) { |
| 1108 | if (mShouldShowUserEducation |
| 1109 | && mUserEducationView.getVisibility() == VISIBLE |
| 1110 | && !mAnimatingEducationAway) { |
| 1111 | mAnimatingEducationAway = true; |
| 1112 | mUserEducationView.animate() |
| 1113 | .alpha(0) |
| 1114 | .setDuration(fromExpansion |
| 1115 | ? ANIMATE_STACK_USER_EDUCATION_DURATION_SHORT |
| 1116 | : ANIMATE_STACK_USER_EDUCATION_DURATION) |
| 1117 | .withEndAction(() -> { |
| 1118 | mAnimatingEducationAway = false; |
| 1119 | mShouldShowUserEducation = shouldShowBubblesEducation(); |
| 1120 | mUserEducationView.setVisibility(GONE); |
| 1121 | }); |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * If necessary, toggles the user education view for the manage button. This is shown when the |
| 1127 | * bubble stack is expanded for the first time. |
| 1128 | * |
| 1129 | * @param show whether the user education view should show or not. |
| 1130 | */ |
| 1131 | void maybeShowManageEducation(boolean show) { |
| 1132 | if (mManageEducationView == null) { |
| 1133 | return; |
| 1134 | } |
| 1135 | if (show |
| 1136 | && mShouldShowManageEducation |
| 1137 | && mManageEducationView.getVisibility() != VISIBLE |
| 1138 | && mIsExpanded) { |
| 1139 | mManageEducationView.setAlpha(0); |
| 1140 | mManageEducationView.setVisibility(VISIBLE); |
| 1141 | mManageEducationView.post(() -> { |
| 1142 | final Rect position = |
| 1143 | mExpandedBubble.getExpandedView().getManageButtonLocationOnScreen(); |
| 1144 | final int viewHeight = mManageEducationView.getManageViewHeight(); |
| 1145 | final int inset = getResources().getDimensionPixelSize( |
| 1146 | R.dimen.bubbles_manage_education_top_inset); |
| 1147 | mManageEducationView.bringToFront(); |
| 1148 | mManageEducationView.setManageViewPosition(position.left, |
| 1149 | position.top - viewHeight + inset); |
| 1150 | mManageEducationView.setPointerPosition(position.centerX() - position.left); |
| 1151 | mManageEducationView.animate() |
| 1152 | .setDuration(ANIMATE_STACK_USER_EDUCATION_DURATION) |
| 1153 | .setInterpolator(FAST_OUT_SLOW_IN).alpha(1); |
| 1154 | }); |
| 1155 | Prefs.putBoolean(getContext(), HAS_SEEN_BUBBLES_MANAGE_EDUCATION, true); |
| 1156 | } else if (!show |
| 1157 | && mManageEducationView.getVisibility() == VISIBLE |
| 1158 | && !mAnimatingManageEducationAway) { |
| 1159 | mManageEducationView.animate() |
| 1160 | .alpha(0) |
| 1161 | .setDuration(mIsExpansionAnimating |
| 1162 | ? ANIMATE_STACK_USER_EDUCATION_DURATION_SHORT |
| 1163 | : ANIMATE_STACK_USER_EDUCATION_DURATION) |
| 1164 | .withEndAction(() -> { |
| 1165 | mAnimatingManageEducationAway = false; |
| 1166 | mShouldShowManageEducation = shouldShowManageEducation(); |
| 1167 | mManageEducationView.setVisibility(GONE); |
| 1168 | }); |
| 1169 | } |
| 1170 | } |
| 1171 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 1172 | /* |
| 1173 | * Sets the action to run to dismiss the currently dragging object (either the stack or an |
| 1174 | * individual bubble). |
| 1175 | */ |
| 1176 | public void setReleasedInDismissTargetAction(Runnable action) { |
| 1177 | mReleasedInDismissTargetAction = action; |
| 1178 | } |
| 1179 | |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1180 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1181 | * Dismiss the stack of bubbles. |
Lyn Han | 1b4f25e | 2019-06-11 13:56:34 -0700 | [diff] [blame] | 1182 | * |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1183 | * @deprecated |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1184 | */ |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1185 | @Deprecated |
Mady Mellor | c3d7d06 | 2019-03-28 16:13:05 -0700 | [diff] [blame] | 1186 | void stackDismissed(int reason) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1187 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1188 | Log.d(TAG, "stackDismissed: reason=" + reason); |
| 1189 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1190 | mBubbleData.dismissAll(reason); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1191 | logBubbleEvent(null /* no bubble associated with bubble stack dismiss */, |
Muhammad Qureshi | 9bced7d | 2020-01-16 15:22:12 -0800 | [diff] [blame] | 1192 | SysUiStatsLog.BUBBLE_UICHANGED__ACTION__STACK_DISMISSED); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1196 | * @return the view the touch event is on |
| 1197 | */ |
| 1198 | @Nullable |
| 1199 | public View getTargetView(MotionEvent event) { |
| 1200 | float x = event.getRawX(); |
| 1201 | float y = event.getRawY(); |
| 1202 | if (mIsExpanded) { |
| 1203 | if (isIntersecting(mBubbleContainer, x, y)) { |
Lyn Han | 8cc4bf8 | 2020-03-05 16:34:37 -0800 | [diff] [blame] | 1204 | if (BubbleExperimentConfig.allowBubbleOverflow(mContext) |
| 1205 | && isIntersecting(mBubbleOverflow.getBtn(), x, y)) { |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1206 | return mBubbleOverflow.getBtn(); |
Lyn Han | 99e457f | 2020-01-31 10:14:19 -0800 | [diff] [blame] | 1207 | } |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 1208 | // Could be tapping or dragging a bubble while expanded |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 1209 | for (int i = 0; i < getBubbleCount(); i++) { |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1210 | BadgedImageView view = (BadgedImageView) mBubbleContainer.getChildAt(i); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1211 | if (isIntersecting(view, x, y)) { |
| 1212 | return view; |
| 1213 | } |
| 1214 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1215 | } |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 1216 | BubbleExpandedView bev = (BubbleExpandedView) mExpandedViewContainer.getChildAt(0); |
| 1217 | if (bev.intersectingTouchableContent((int) x, (int) y)) { |
| 1218 | return bev; |
| 1219 | } |
| 1220 | // Outside of the parts we care about. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1221 | return null; |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1222 | } else if (mFlyout.getVisibility() == VISIBLE && isIntersecting(mFlyout, x, y)) { |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1223 | return mFlyout; |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1224 | } else if (mUserEducationView != null && mUserEducationView.getVisibility() == VISIBLE) { |
| 1225 | View bubbleChild = mBubbleContainer.getChildAt(0); |
| 1226 | if (isIntersecting(bubbleChild, x, y)) { |
| 1227 | return this; |
| 1228 | } else if (isIntersecting(mUserEducationView, x, y)) { |
| 1229 | return mUserEducationView; |
| 1230 | } else { |
| 1231 | return null; |
| 1232 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1233 | } |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1234 | |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1235 | // 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] | 1236 | return this; |
| 1237 | } |
| 1238 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1239 | View getFlyoutView() { |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1240 | return mFlyout; |
| 1241 | } |
| 1242 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1243 | /** |
Joshua Tsuji | f5c6a9c | 2020-02-25 17:47:59 -0500 | [diff] [blame] | 1244 | * @deprecated use {@link #setExpanded(boolean)} and |
| 1245 | * {@link BubbleData#setSelectedBubble(Bubble)} |
Mark Renouf | c6ab73d | 2019-04-09 16:42:22 -0400 | [diff] [blame] | 1246 | */ |
| 1247 | @Deprecated |
| 1248 | @MainThread |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 1249 | void collapseStack(Runnable endRunnable) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1250 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1251 | Log.d(TAG, "collapseStack(endRunnable)"); |
| 1252 | } |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1253 | mBubbleData.setExpanded(false); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 1254 | // TODO - use the runnable at end of animation |
| 1255 | endRunnable.run(); |
| 1256 | } |
| 1257 | |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1258 | void showExpandedViewContents(int displayId) { |
| 1259 | if (mExpandedBubble != null |
| 1260 | && mExpandedBubble.getExpandedView().getVirtualDisplayId() == displayId) { |
| 1261 | mExpandedBubble.setContentVisibility(true); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1262 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1263 | } |
| 1264 | |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1265 | private void beforeExpandedViewAnimation() { |
| 1266 | hideFlyoutImmediate(); |
| 1267 | updateExpandedBubble(); |
| 1268 | updateExpandedView(); |
| 1269 | mIsExpansionAnimating = true; |
| 1270 | } |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1271 | |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1272 | private void afterExpandedViewAnimation() { |
| 1273 | updateExpandedView(); |
| 1274 | mIsExpansionAnimating = false; |
| 1275 | requestUpdate(); |
| 1276 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1277 | |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1278 | private void animateCollapse() { |
| 1279 | mIsExpanded = false; |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1280 | final BubbleViewProvider previouslySelected = mExpandedBubble; |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1281 | beforeExpandedViewAnimation(); |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1282 | maybeShowManageEducation(false); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1283 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1284 | if (DEBUG_BUBBLE_STACK_VIEW) { |
| 1285 | Log.d(TAG, "animateCollapse"); |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1286 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(getBubblesOnScreen(), |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1287 | mExpandedBubble)); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1288 | } |
| 1289 | updateOverflowBtnVisibility(/* apply */ false); |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1290 | mBubbleContainer.cancelAllAnimations(); |
| 1291 | mExpandedAnimationController.collapseBackToStack( |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 1292 | mStackAnimationController.getStackPositionAlongNearestHorizontalEdge() |
| 1293 | /* collapseTo */, |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1294 | () -> { |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 1295 | mBubbleContainer.setActiveController(mStackAnimationController); |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1296 | afterExpandedViewAnimation(); |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1297 | previouslySelected.setContentVisibility(false); |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1298 | }); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1299 | |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1300 | mExpandedViewXAnim.animateToFinalPosition(getCollapsedX()); |
| 1301 | mExpandedViewYAnim.animateToFinalPosition(getCollapsedY()); |
| 1302 | mExpandedViewContainer.animate() |
| 1303 | .setDuration(100) |
| 1304 | .alpha(0f); |
| 1305 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1306 | |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1307 | private void animateExpansion() { |
| 1308 | mIsExpanded = true; |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1309 | hideStackUserEducation(true /* fromExpansion */); |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1310 | beforeExpandedViewAnimation(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1311 | |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 1312 | mBubbleContainer.setActiveController(mExpandedAnimationController); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1313 | updateOverflowBtnVisibility(/* apply */ false); |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 1314 | mExpandedAnimationController.expandFromStack(() -> { |
| 1315 | updatePointerPosition(); |
| 1316 | afterExpandedViewAnimation(); |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1317 | maybeShowManageEducation(true); |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 1318 | } /* after */); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1319 | |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1320 | mExpandedViewContainer.setTranslationX(getCollapsedX()); |
| 1321 | mExpandedViewContainer.setTranslationY(getCollapsedY()); |
| 1322 | mExpandedViewContainer.setAlpha(0f); |
| 1323 | |
| 1324 | mExpandedViewXAnim.animateToFinalPosition(0f); |
| 1325 | mExpandedViewYAnim.animateToFinalPosition(getExpandedViewY()); |
| 1326 | mExpandedViewContainer.animate() |
| 1327 | .setDuration(100) |
| 1328 | .alpha(1f); |
| 1329 | } |
| 1330 | |
| 1331 | private float getCollapsedX() { |
| 1332 | return mStackAnimationController.getStackPosition().x < getWidth() / 2 |
| 1333 | ? -mExpandedAnimateXDistance |
| 1334 | : mExpandedAnimateXDistance; |
| 1335 | } |
| 1336 | |
| 1337 | private float getCollapsedY() { |
| 1338 | return Math.min(mStackAnimationController.getStackPosition().y, |
| 1339 | mExpandedAnimateYDistance); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1340 | } |
| 1341 | |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1342 | private void notifyExpansionChanged(BubbleViewProvider bubble, boolean expanded) { |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 1343 | if (mExpandListener != null && bubble != null) { |
| 1344 | mExpandListener.onBubbleExpandChanged(expanded, bubble.getKey()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1348 | /** Return the BubbleView at the given index from the bubble container. */ |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1349 | public BadgedImageView getBubbleAt(int i) { |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 1350 | return getBubbleCount() > i |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1351 | ? (BadgedImageView) mBubbleContainer.getChildAt(i) |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1352 | : null; |
| 1353 | } |
| 1354 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1355 | /** Moves the bubbles out of the way if they're going to be over the keyboard. */ |
| 1356 | public void onImeVisibilityChanged(boolean visible, int height) { |
Mady Mellor | df611cf | 2019-08-21 17:28:49 -0700 | [diff] [blame] | 1357 | mStackAnimationController.setImeHeight(visible ? height + mImeOffset : 0); |
Joshua Tsuji | 4b39591 | 2019-04-19 17:18:40 -0400 | [diff] [blame] | 1358 | |
Joshua Tsuji | ff6b0f2 | 2020-03-09 14:55:19 -0400 | [diff] [blame] | 1359 | if (!mIsExpanded && getBubbleCount() > 0) { |
| 1360 | final float stackDestinationY = |
| 1361 | mStackAnimationController.animateForImeVisibility(visible); |
| 1362 | |
| 1363 | // How far the stack is animating due to IME, we'll just animate the flyout by that |
| 1364 | // much too. |
| 1365 | final float stackDy = |
| 1366 | stackDestinationY - mStackAnimationController.getStackPosition().y; |
| 1367 | |
| 1368 | // If the flyout is visible, translate it along with the bubble stack. |
| 1369 | if (mFlyout.getVisibility() == VISIBLE) { |
| 1370 | PhysicsAnimator.getInstance(mFlyout) |
| 1371 | .spring(DynamicAnimation.TRANSLATION_Y, |
| 1372 | mFlyout.getTranslationY() + stackDy, |
| 1373 | FLYOUT_IME_ANIMATION_SPRING_CONFIG) |
| 1374 | .start(); |
| 1375 | } |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1376 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1379 | /** Called when the collapsed stack is tapped on. */ |
| 1380 | void onStackTapped() { |
| 1381 | if (!maybeShowStackUserEducation()) { |
| 1382 | mBubbleData.setExpanded(true); |
| 1383 | } |
| 1384 | } |
| 1385 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1386 | /** Called when a drag operation on an individual bubble has started. */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1387 | public void onBubbleDragStart(View bubble) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1388 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1389 | Log.d(TAG, "onBubbleDragStart: bubble=" + bubble); |
| 1390 | } |
Joshua Tsuji | bc7744b | 2020-03-04 15:04:59 -0500 | [diff] [blame] | 1391 | |
Joshua Tsuji | a2433db | 2020-03-12 17:56:22 -0400 | [diff] [blame] | 1392 | if (mBubbleOverflow != null && bubble.equals(mBubbleOverflow.getIconView())) { |
Joshua Tsuji | bc7744b | 2020-03-04 15:04:59 -0500 | [diff] [blame] | 1393 | return; |
| 1394 | } |
| 1395 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 1396 | mExpandedAnimationController.prepareForBubbleDrag(bubble, mMagneticTarget); |
| 1397 | |
| 1398 | // We're dragging an individual bubble, so set the magnetized object to the magnetized |
| 1399 | // bubble. |
| 1400 | mMagnetizedObject = mExpandedAnimationController.getMagnetizedBubbleDraggingOut(); |
| 1401 | mMagnetizedObject.setMagnetListener(mIndividualBubbleMagnetListener); |
Joshua Tsuji | db1d2e88 | 2020-03-10 15:09:08 -0400 | [diff] [blame] | 1402 | |
| 1403 | maybeShowManageEducation(false); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /** Called with the coordinates to which an individual bubble has been dragged. */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1407 | public void onBubbleDragged(View bubble, float x, float y) { |
Joshua Tsuji | a2433db | 2020-03-12 17:56:22 -0400 | [diff] [blame] | 1408 | if (!mIsExpanded || mIsExpansionAnimating |
| 1409 | || (mBubbleOverflow != null && bubble.equals(mBubbleOverflow.getIconView()))) { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1410 | return; |
| 1411 | } |
| 1412 | |
| 1413 | mExpandedAnimationController.dragBubbleOut(bubble, x, y); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1414 | springInDismissTarget(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /** Called when a drag operation on an individual bubble has finished. */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1418 | public void onBubbleDragFinish( |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1419 | View bubble, float x, float y, float velX, float velY) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1420 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1421 | Log.d(TAG, "onBubbleDragFinish: bubble=" + bubble); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1422 | } |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1423 | |
Joshua Tsuji | a2433db | 2020-03-12 17:56:22 -0400 | [diff] [blame] | 1424 | if (!mIsExpanded || mIsExpansionAnimating |
| 1425 | || (mBubbleOverflow != null && bubble.equals(mBubbleOverflow.getIconView()))) { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1426 | return; |
| 1427 | } |
| 1428 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1429 | mExpandedAnimationController.snapBubbleBack(bubble, velX, velY); |
Lyn Han | 634483c | 2019-06-28 16:52:47 -0700 | [diff] [blame] | 1430 | hideDismissTarget(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1431 | } |
| 1432 | |
Joshua Tsuji | 7be4c61 | 2020-03-04 14:58:14 -0500 | [diff] [blame] | 1433 | /** Expands the clicked bubble. */ |
| 1434 | public void expandBubble(Bubble bubble) { |
| 1435 | if (bubble.equals(mBubbleData.getSelectedBubble())) { |
| 1436 | // If the bubble we're supposed to expand is the selected bubble, that means the |
| 1437 | // overflow bubble is currently expanded. Don't tell BubbleData to set this bubble as |
| 1438 | // selected, since it already is. Just call the stack's setSelectedBubble to expand it. |
| 1439 | setSelectedBubble(bubble); |
| 1440 | } else { |
| 1441 | mBubbleData.setSelectedBubble(bubble); |
| 1442 | } |
| 1443 | } |
| 1444 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1445 | void onDragStart() { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1446 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1447 | Log.d(TAG, "onDragStart()"); |
| 1448 | } |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1449 | if (mIsExpanded || mIsExpansionAnimating) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1450 | if (DEBUG_BUBBLE_STACK_VIEW) { |
| 1451 | Log.d(TAG, "mIsExpanded or mIsExpansionAnimating"); |
| 1452 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1453 | return; |
| 1454 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1455 | mStackAnimationController.cancelStackPositionAnimations(); |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 1456 | mBubbleContainer.setActiveController(mStackAnimationController); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1457 | hideFlyoutImmediate(); |
| 1458 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 1459 | // Since we're dragging the stack, set the magnetized object to the magnetized stack. |
| 1460 | mMagnetizedObject = mStackAnimationController.getMagnetizedStack(mMagneticTarget); |
| 1461 | mMagnetizedObject.setMagnetListener(mStackMagnetListener); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | void onDragged(float x, float y) { |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1465 | if (mIsExpanded || mIsExpansionAnimating) { |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1466 | return; |
| 1467 | } |
| 1468 | |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1469 | hideStackUserEducation(false /* fromExpansion */); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1470 | springInDismissTarget(); |
| 1471 | mStackAnimationController.moveStackFromTouch(x, y); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | void onDragFinish(float x, float y, float velX, float velY) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1475 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1476 | Log.d(TAG, "onDragFinish"); |
| 1477 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1478 | |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1479 | if (mIsExpanded || mIsExpansionAnimating) { |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1480 | return; |
| 1481 | } |
| 1482 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1483 | final float newStackX = mStackAnimationController.flingStackThenSpringToEdge(x, velX, velY); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1484 | logBubbleEvent(null /* no bubble associated with bubble stack move */, |
Muhammad Qureshi | 9bced7d | 2020-01-16 15:22:12 -0800 | [diff] [blame] | 1485 | SysUiStatsLog.BUBBLE_UICHANGED__ACTION__STACK_MOVED); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1486 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1487 | mStackOnLeftOrWillBe = newStackX <= 0; |
Joshua Tsuji | 2862f2e | 2019-07-29 12:32:33 -0400 | [diff] [blame] | 1488 | updateBubbleZOrdersAndDotPosition(true /* animate */); |
Lyn Han | 634483c | 2019-06-28 16:52:47 -0700 | [diff] [blame] | 1489 | hideDismissTarget(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1490 | } |
| 1491 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1492 | void onFlyoutDragStart() { |
| 1493 | mFlyout.removeCallbacks(mHideFlyout); |
| 1494 | } |
| 1495 | |
| 1496 | void onFlyoutDragged(float deltaX) { |
Joshua Tsuji | 8e05aab | 2019-08-22 14:57:50 -0400 | [diff] [blame] | 1497 | // This shouldn't happen, but if it does, just wait until the flyout lays out. This method |
| 1498 | // is continually called. |
| 1499 | if (mFlyout.getWidth() <= 0) { |
| 1500 | return; |
| 1501 | } |
| 1502 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1503 | final boolean onLeft = mStackAnimationController.isStackOnLeftSide(); |
| 1504 | mFlyoutDragDeltaX = deltaX; |
| 1505 | |
| 1506 | final float collapsePercent = |
| 1507 | onLeft ? -deltaX / mFlyout.getWidth() : deltaX / mFlyout.getWidth(); |
| 1508 | mFlyout.setCollapsePercent(Math.min(1f, Math.max(0f, collapsePercent))); |
| 1509 | |
Lyn Han | 61d5d56 | 2019-07-01 17:39:38 -0700 | [diff] [blame] | 1510 | // 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] | 1511 | float overscrollTranslation = 0f; |
| 1512 | if (collapsePercent < 0f || collapsePercent > 1f) { |
| 1513 | // Whether we are more than 100% transitioned to the dot. |
| 1514 | final boolean overscrollingPastDot = collapsePercent > 1f; |
| 1515 | |
| 1516 | // Whether we are overscrolling physically to the left - this can either be pulling the |
| 1517 | // flyout away from the stack (if the stack is on the right) or pushing it to the left |
| 1518 | // after it has already become the dot. |
| 1519 | final boolean overscrollingLeft = |
| 1520 | (onLeft && collapsePercent > 1f) || (!onLeft && collapsePercent < 0f); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1521 | overscrollTranslation = |
| 1522 | (overscrollingPastDot ? collapsePercent - 1f : collapsePercent * -1) |
| 1523 | * (overscrollingLeft ? -1 : 1) |
| 1524 | * (mFlyout.getWidth() / (FLYOUT_OVERSCROLL_ATTENUATION_FACTOR |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 1525 | // Attenuate the smaller dot less than the larger flyout. |
| 1526 | / (overscrollingPastDot ? 2 : 1))); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | mFlyout.setTranslationX(mFlyout.getRestingTranslationX() + overscrollTranslation); |
| 1530 | } |
| 1531 | |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1532 | void onFlyoutTapped() { |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1533 | if (maybeShowStackUserEducation()) { |
| 1534 | // If we're showing user education, don't open the bubble show the education first |
| 1535 | mBubbleToExpandAfterFlyoutCollapse = null; |
| 1536 | } else { |
| 1537 | mBubbleToExpandAfterFlyoutCollapse = mBubbleData.getSelectedBubble(); |
| 1538 | } |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1539 | |
| 1540 | mFlyout.removeCallbacks(mHideFlyout); |
| 1541 | mHideFlyout.run(); |
| 1542 | } |
| 1543 | |
| 1544 | /** |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1545 | * Called when the flyout drag has finished, and returns true if the gesture successfully |
| 1546 | * dismissed the flyout. |
| 1547 | */ |
| 1548 | void onFlyoutDragFinished(float deltaX, float velX) { |
| 1549 | final boolean onLeft = mStackAnimationController.isStackOnLeftSide(); |
| 1550 | final boolean metRequiredVelocity = |
| 1551 | onLeft ? velX < -FLYOUT_DISMISS_VELOCITY : velX > FLYOUT_DISMISS_VELOCITY; |
| 1552 | final boolean metRequiredDeltaX = |
| 1553 | onLeft |
| 1554 | ? deltaX < -mFlyout.getWidth() * FLYOUT_DRAG_PERCENT_DISMISS |
| 1555 | : deltaX > mFlyout.getWidth() * FLYOUT_DRAG_PERCENT_DISMISS; |
| 1556 | final boolean isCancelFling = onLeft ? velX > 0 : velX < 0; |
| 1557 | final boolean shouldDismiss = metRequiredVelocity || (metRequiredDeltaX && !isCancelFling); |
| 1558 | |
| 1559 | mFlyout.removeCallbacks(mHideFlyout); |
| 1560 | animateFlyoutCollapsed(shouldDismiss, velX); |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1561 | |
| 1562 | maybeShowStackUserEducation(); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | /** |
| 1566 | * Called when the first touch event of a gesture (stack drag, bubble drag, flyout drag, etc.) |
| 1567 | * is received. |
| 1568 | */ |
| 1569 | void onGestureStart() { |
| 1570 | mIsGestureInProgress = true; |
| 1571 | } |
| 1572 | |
| 1573 | /** Called when a gesture is completed or cancelled. */ |
| 1574 | void onGestureFinished() { |
| 1575 | mIsGestureInProgress = false; |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 1576 | |
| 1577 | if (mIsExpanded) { |
| 1578 | mExpandedAnimationController.onGestureFinished(); |
| 1579 | } |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1580 | } |
| 1581 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 1582 | /** Passes the MotionEvent to the magnetized object and returns true if it was consumed. */ |
| 1583 | boolean passEventToMagnetizedObject(MotionEvent event) { |
| 1584 | return mMagnetizedObject != null && mMagnetizedObject.maybeConsumeMotionEvent(event); |
| 1585 | } |
| 1586 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1587 | /** Prepares and starts the desaturate/darken animation on the bubble stack. */ |
| 1588 | private void animateDesaturateAndDarken(View targetView, boolean desaturateAndDarken) { |
| 1589 | mDesaturateAndDarkenTargetView = targetView; |
| 1590 | |
| 1591 | if (desaturateAndDarken) { |
| 1592 | // Use the animated paint for the bubbles. |
| 1593 | mDesaturateAndDarkenTargetView.setLayerType( |
| 1594 | View.LAYER_TYPE_HARDWARE, mDesaturateAndDarkenPaint); |
| 1595 | mDesaturateAndDarkenAnimator.removeAllListeners(); |
| 1596 | mDesaturateAndDarkenAnimator.start(); |
| 1597 | } else { |
| 1598 | mDesaturateAndDarkenAnimator.removeAllListeners(); |
| 1599 | mDesaturateAndDarkenAnimator.addListener(new AnimatorListenerAdapter() { |
| 1600 | @Override |
| 1601 | public void onAnimationEnd(Animator animation) { |
| 1602 | super.onAnimationEnd(animation); |
| 1603 | // Stop using the animated paint. |
| 1604 | resetDesaturationAndDarken(); |
| 1605 | } |
| 1606 | }); |
| 1607 | mDesaturateAndDarkenAnimator.reverse(); |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | private void resetDesaturationAndDarken() { |
| 1612 | mDesaturateAndDarkenAnimator.removeAllListeners(); |
| 1613 | mDesaturateAndDarkenAnimator.cancel(); |
| 1614 | mDesaturateAndDarkenTargetView.setLayerType(View.LAYER_TYPE_NONE, null); |
| 1615 | } |
| 1616 | |
Lyn Han | 634483c | 2019-06-28 16:52:47 -0700 | [diff] [blame] | 1617 | /** Animates in the dismiss target. */ |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1618 | private void springInDismissTarget() { |
| 1619 | if (mShowingDismiss) { |
| 1620 | return; |
| 1621 | } |
| 1622 | |
| 1623 | mShowingDismiss = true; |
| 1624 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 1625 | mDismissTargetContainer.bringToFront(); |
| 1626 | mDismissTargetContainer.setZ(Short.MAX_VALUE - 1); |
| 1627 | mDismissTargetContainer.setVisibility(VISIBLE); |
| 1628 | |
| 1629 | mDismissTargetAnimator.cancel(); |
| 1630 | mDismissTargetAnimator |
| 1631 | .spring(DynamicAnimation.TRANSLATION_Y, 0f, mDismissTargetSpring) |
| 1632 | .start(); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | /** |
| 1636 | * Animates the dismiss target out, as well as the circle that encircles the bubbles, if they |
| 1637 | * were dragged into the target and encircled. |
| 1638 | */ |
Lyn Han | 634483c | 2019-06-28 16:52:47 -0700 | [diff] [blame] | 1639 | private void hideDismissTarget() { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1640 | if (!mShowingDismiss) { |
| 1641 | return; |
| 1642 | } |
| 1643 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1644 | mShowingDismiss = false; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 1645 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 1646 | mDismissTargetAnimator |
| 1647 | .spring(DynamicAnimation.TRANSLATION_Y, mDismissTargetContainer.getHeight(), |
| 1648 | mDismissTargetSpring) |
| 1649 | .withEndActions(() -> mDismissTargetContainer.setVisibility(View.INVISIBLE)) |
| 1650 | .start(); |
Joshua Tsuji | 19e22e424 | 2019-04-17 13:29:10 -0400 | [diff] [blame] | 1651 | } |
| 1652 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1653 | /** Animates the flyout collapsed (to dot), or the reverse, starting with the given velocity. */ |
| 1654 | private void animateFlyoutCollapsed(boolean collapsed, float velX) { |
| 1655 | final boolean onLeft = mStackAnimationController.isStackOnLeftSide(); |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1656 | // If the flyout was tapped, we want a higher stiffness for the collapse animation so it's |
| 1657 | // faster. |
| 1658 | mFlyoutTransitionSpring.getSpring().setStiffness( |
| 1659 | (mBubbleToExpandAfterFlyoutCollapse != null) |
| 1660 | ? SpringForce.STIFFNESS_MEDIUM |
| 1661 | : SpringForce.STIFFNESS_LOW); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1662 | mFlyoutTransitionSpring |
| 1663 | .setStartValue(mFlyoutDragDeltaX) |
| 1664 | .setStartVelocity(velX) |
| 1665 | .animateToFinalPosition(collapsed |
| 1666 | ? (onLeft ? -mFlyout.getWidth() : mFlyout.getWidth()) |
| 1667 | : 0f); |
| 1668 | } |
| 1669 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1670 | /** |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 1671 | * Calculates the y position of the expanded view when it is expanded. |
| 1672 | */ |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1673 | float getExpandedViewY() { |
Lyn Han | 4a8efe3 | 2019-05-30 09:43:27 -0700 | [diff] [blame] | 1674 | return getStatusBarHeight() + mBubbleSize + mBubblePaddingTop + mPointerHeight; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | /** |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1678 | * Animates in the flyout for the given bubble, if available, and then hides it after some time. |
| 1679 | */ |
| 1680 | @VisibleForTesting |
| 1681 | void animateInFlyoutForBubble(Bubble bubble) { |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 1682 | Bubble.FlyoutMessage flyoutMessage = bubble.getFlyoutMessage(); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1683 | final BadgedImageView bubbleView = bubble.getIconView(); |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 1684 | if (flyoutMessage == null |
| 1685 | || flyoutMessage.message == null |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1686 | || !bubble.showFlyout() |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1687 | || (mUserEducationView != null && mUserEducationView.getVisibility() == VISIBLE) |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 1688 | || isExpanded() |
| 1689 | || mIsExpansionAnimating |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1690 | || mIsGestureInProgress |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1691 | || mBubbleToExpandAfterFlyoutCollapse != null |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1692 | || bubbleView == null) { |
| 1693 | if (bubbleView != null) { |
| 1694 | bubbleView.setDotState(DOT_STATE_DEFAULT); |
| 1695 | } |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1696 | // 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] | 1697 | // 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] | 1698 | return; |
| 1699 | } |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1700 | |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1701 | mFlyoutDragDeltaX = 0f; |
| 1702 | clearFlyoutOnHide(); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1703 | mAfterFlyoutHidden = () -> { |
| 1704 | // Null it out to ensure it runs once. |
| 1705 | mAfterFlyoutHidden = null; |
| 1706 | |
| 1707 | if (mBubbleToExpandAfterFlyoutCollapse != null) { |
| 1708 | // User tapped on the flyout and we should expand |
| 1709 | mBubbleData.setSelectedBubble(mBubbleToExpandAfterFlyoutCollapse); |
| 1710 | mBubbleData.setExpanded(true); |
| 1711 | mBubbleToExpandAfterFlyoutCollapse = null; |
Joshua Tsuji | 36b1b2c | 2019-04-18 16:27:35 -0400 | [diff] [blame] | 1712 | } |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1713 | bubbleView.setDotState(DOT_STATE_DEFAULT); |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1714 | }; |
| 1715 | mFlyout.setVisibility(INVISIBLE); |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1716 | |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1717 | // Don't show the dot when we're animating the flyout |
| 1718 | bubbleView.setDotState(DOT_STATE_SUPPRESSED_FOR_FLYOUT); |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1719 | |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1720 | // Start flyout expansion. Post in case layout isn't complete and getWidth returns 0. |
| 1721 | post(() -> { |
| 1722 | // An auto-expanding bubble could have been posted during the time it takes to |
| 1723 | // layout. |
| 1724 | if (isExpanded()) { |
| 1725 | return; |
| 1726 | } |
| 1727 | final Runnable expandFlyoutAfterDelay = () -> { |
| 1728 | mAnimateInFlyout = () -> { |
| 1729 | mFlyout.setVisibility(VISIBLE); |
| 1730 | mFlyoutDragDeltaX = |
| 1731 | mStackAnimationController.isStackOnLeftSide() |
| 1732 | ? -mFlyout.getWidth() |
| 1733 | : mFlyout.getWidth(); |
| 1734 | animateFlyoutCollapsed(false /* collapsed */, 0 /* velX */); |
| 1735 | mFlyout.postDelayed(mHideFlyout, FLYOUT_HIDE_AFTER); |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1736 | }; |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1737 | mFlyout.postDelayed(mAnimateInFlyout, 200); |
| 1738 | }; |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 1739 | mFlyout.setupFlyoutStartingAsDot(flyoutMessage, |
| 1740 | mStackAnimationController.getStackPosition(), getWidth(), |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1741 | mStackAnimationController.isStackOnLeftSide(), |
Mady Mellor | 05e860b | 2019-10-30 22:48:15 -0700 | [diff] [blame] | 1742 | bubble.getIconView().getDotColor() /* dotColor */, |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1743 | expandFlyoutAfterDelay /* onLayoutComplete */, |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1744 | mAfterFlyoutHidden, |
| 1745 | bubble.getIconView().getDotCenter(), |
| 1746 | !bubble.showDot()); |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1747 | mFlyout.bringToFront(); |
| 1748 | }); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 1749 | mFlyout.removeCallbacks(mHideFlyout); |
| 1750 | mFlyout.postDelayed(mHideFlyout, FLYOUT_HIDE_AFTER); |
Muhammad Qureshi | 9bced7d | 2020-01-16 15:22:12 -0800 | [diff] [blame] | 1751 | logBubbleEvent(bubble, SysUiStatsLog.BUBBLE_UICHANGED__ACTION__FLYOUT); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | /** Hide the flyout immediately and cancel any pending hide runnables. */ |
| 1755 | private void hideFlyoutImmediate() { |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1756 | clearFlyoutOnHide(); |
Joshua Tsuji | 14e6855 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 1757 | mFlyout.removeCallbacks(mAnimateInFlyout); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1758 | mFlyout.removeCallbacks(mHideFlyout); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1759 | mFlyout.hideFlyout(); |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1760 | } |
| 1761 | |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1762 | private void clearFlyoutOnHide() { |
| 1763 | mFlyout.removeCallbacks(mAnimateInFlyout); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1764 | if (mAfterFlyoutHidden == null) { |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1765 | return; |
| 1766 | } |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1767 | mAfterFlyoutHidden.run(); |
| 1768 | mAfterFlyoutHidden = null; |
Lyn Han | f1f2c33 | 2019-08-23 17:06:56 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1771 | @Override |
| 1772 | public void getBoundsOnScreen(Rect outRect) { |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1773 | if (mUserEducationView != null && mUserEducationView.getVisibility() == VISIBLE) { |
| 1774 | // When user education shows then capture all touches |
| 1775 | outRect.set(0, 0, getWidth(), getHeight()); |
| 1776 | return; |
| 1777 | } |
| 1778 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1779 | if (!mIsExpanded) { |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 1780 | if (getBubbleCount() > 0) { |
Mady Mellor | 217b2e9 | 2019-02-27 11:44:16 -0800 | [diff] [blame] | 1781 | mBubbleContainer.getChildAt(0).getBoundsOnScreen(outRect); |
| 1782 | } |
Mady Mellor | e9371bc | 2019-07-10 18:50:59 -0700 | [diff] [blame] | 1783 | // Increase the touch target size of the bubble |
| 1784 | outRect.top -= mBubbleTouchPadding; |
| 1785 | outRect.left -= mBubbleTouchPadding; |
| 1786 | outRect.right += mBubbleTouchPadding; |
| 1787 | outRect.bottom += mBubbleTouchPadding; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1788 | } else { |
| 1789 | mBubbleContainer.getBoundsOnScreen(outRect); |
| 1790 | } |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1791 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1792 | if (mFlyout.getVisibility() == View.VISIBLE) { |
Joshua Tsuji | 614b1df | 2019-03-26 13:57:05 -0400 | [diff] [blame] | 1793 | final Rect flyoutBounds = new Rect(); |
| 1794 | mFlyout.getBoundsOnScreen(flyoutBounds); |
| 1795 | outRect.union(flyoutBounds); |
| 1796 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | private int getStatusBarHeight() { |
| 1800 | if (getRootWindowInsets() != null) { |
Joshua Tsuji | 0fee768 | 2019-01-25 11:37:49 -0500 | [diff] [blame] | 1801 | WindowInsets insets = getRootWindowInsets(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1802 | return Math.max( |
Joshua Tsuji | f44347f | 2019-02-12 14:28:06 -0500 | [diff] [blame] | 1803 | mStatusBarHeight, |
Joshua Tsuji | 0fee768 | 2019-01-25 11:37:49 -0500 | [diff] [blame] | 1804 | insets.getDisplayCutout() != null |
| 1805 | ? insets.getDisplayCutout().getSafeInsetTop() |
| 1806 | : 0); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | return 0; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | private boolean isIntersecting(View view, float x, float y) { |
| 1813 | mTempLoc = view.getLocationOnScreen(); |
| 1814 | mTempRect.set(mTempLoc[0], mTempLoc[1], mTempLoc[0] + view.getWidth(), |
| 1815 | mTempLoc[1] + view.getHeight()); |
| 1816 | return mTempRect.contains(x, y); |
| 1817 | } |
| 1818 | |
| 1819 | private void requestUpdate() { |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1820 | if (mViewUpdatedRequested || mIsExpansionAnimating) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1821 | return; |
| 1822 | } |
| 1823 | mViewUpdatedRequested = true; |
| 1824 | getViewTreeObserver().addOnPreDrawListener(mViewUpdater); |
| 1825 | invalidate(); |
| 1826 | } |
| 1827 | |
| 1828 | private void updateExpandedBubble() { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1829 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1830 | Log.d(TAG, "updateExpandedBubble()"); |
| 1831 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1832 | mExpandedViewContainer.removeAllViews(); |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1833 | if (mIsExpanded && mExpandedBubble != null) { |
| 1834 | BubbleExpandedView bev = mExpandedBubble.getExpandedView(); |
Lyn Han | a0bb02e | 2020-01-28 17:57:27 -0800 | [diff] [blame] | 1835 | mExpandedViewContainer.addView(bev); |
| 1836 | bev.populateExpandedView(); |
| 1837 | mExpandedViewContainer.setVisibility(VISIBLE); |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 1838 | mExpandedViewContainer.setAlpha(1.0f); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1842 | private void updateExpandedView() { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1843 | if (DEBUG_BUBBLE_STACK_VIEW) { |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1844 | Log.d(TAG, "updateExpandedView: mIsExpanded=" + mIsExpanded); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1845 | } |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1846 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1847 | mExpandedViewContainer.setVisibility(mIsExpanded ? VISIBLE : GONE); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1848 | if (mIsExpanded) { |
Lyn Han | 285ad30 | 2019-05-29 19:01:39 -0700 | [diff] [blame] | 1849 | final float y = getExpandedViewY(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 1850 | if (!mExpandedViewYAnim.isRunning()) { |
| 1851 | // We're not animating so set the value |
| 1852 | mExpandedViewContainer.setTranslationY(y); |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1853 | if (mExpandedBubble != null) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1854 | mExpandedBubble.getExpandedView().updateView(); |
| 1855 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 1856 | } else { |
Mady Mellor | bc078c2 | 2019-03-26 17:10:34 -0700 | [diff] [blame] | 1857 | // We are animating so update the value; there is an end listener on the animator |
| 1858 | // that will ensure expandedeView.updateView gets called. |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 1859 | mExpandedViewYAnim.animateToFinalPosition(y); |
| 1860 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1861 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1862 | |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1863 | mStackOnLeftOrWillBe = mStackAnimationController.isStackOnLeftSide(); |
Joshua Tsuji | 2862f2e | 2019-07-29 12:32:33 -0400 | [diff] [blame] | 1864 | updateBubbleZOrdersAndDotPosition(false); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | /** 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] | 1868 | private void updateBubbleZOrdersAndDotPosition(boolean animate) { |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 1869 | int bubbleCount = getBubbleCount(); |
Lyn Han | 1b4f25e | 2019-06-11 13:56:34 -0700 | [diff] [blame] | 1870 | for (int i = 0; i < bubbleCount; i++) { |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1871 | BadgedImageView bv = (BadgedImageView) mBubbleContainer.getChildAt(i); |
Mady Mellor | 7095854 | 2019-09-24 17:12:46 -0700 | [diff] [blame] | 1872 | bv.setZ((mMaxBubbles * mBubbleElevation) - i); |
Joshua Tsuji | 6549e70 | 2019-05-02 13:13:16 -0400 | [diff] [blame] | 1873 | // If the dot is on the left, and so is the stack, we need to change the dot position. |
| 1874 | if (bv.getDotPositionOnLeft() == mStackOnLeftOrWillBe) { |
| 1875 | bv.setDotPosition(!mStackOnLeftOrWillBe, animate); |
| 1876 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | |
Mady Mellor | de2d4d2 | 2019-01-29 14:15:34 -0800 | [diff] [blame] | 1880 | private void updatePointerPosition() { |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1881 | if (mExpandedBubble == null) { |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 1882 | return; |
Mady Mellor | de2d4d2 | 2019-01-29 14:15:34 -0800 | [diff] [blame] | 1883 | } |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1884 | int index = getBubbleIndex(mExpandedBubble); |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 1885 | float bubbleLeftFromScreenLeft = mExpandedAnimationController.getBubbleLeft(index); |
| 1886 | float halfBubble = mBubbleSize / 2f; |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 1887 | float bubbleCenter = bubbleLeftFromScreenLeft + halfBubble; |
| 1888 | // Padding might be adjusted for insets, so get it directly from the view |
| 1889 | bubbleCenter -= mExpandedViewContainer.getPaddingLeft(); |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1890 | mExpandedBubble.getExpandedView().setPointerPosition(bubbleCenter); |
Mady Mellor | de2d4d2 | 2019-01-29 14:15:34 -0800 | [diff] [blame] | 1891 | } |
| 1892 | |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1893 | /** |
| 1894 | * @return the number of bubbles in the stack view. |
| 1895 | */ |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 1896 | public int getBubbleCount() { |
Lyn Han | 8cc4bf8 | 2020-03-05 16:34:37 -0800 | [diff] [blame] | 1897 | if (BubbleExperimentConfig.allowBubbleOverflow(mContext)) { |
| 1898 | // Subtract 1 for the overflow button that is always in the bubble container. |
| 1899 | return mBubbleContainer.getChildCount() - 1; |
| 1900 | } |
| 1901 | return mBubbleContainer.getChildCount(); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | /** |
| 1905 | * Finds the bubble index within the stack. |
| 1906 | * |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1907 | * @param provider the bubble view provider with the bubble to look up. |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1908 | * @return the index of the bubble view within the bubble stack. The range of the position |
| 1909 | * is between 0 and the bubble count minus 1. |
| 1910 | */ |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1911 | int getBubbleIndex(@Nullable BubbleViewProvider provider) { |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1912 | if (provider == null) { |
Steven Wu | a62cb6a | 2019-02-15 17:12:51 -0500 | [diff] [blame] | 1913 | return 0; |
| 1914 | } |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1915 | return mBubbleContainer.indexOfChild(provider.getIconView()); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | /** |
| 1919 | * @return the normalized x-axis position of the bubble stack rounded to 4 decimal places. |
| 1920 | */ |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 1921 | public float getNormalizedXPosition() { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1922 | return new BigDecimal(getStackPosition().x / mDisplaySize.x) |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1923 | .setScale(4, RoundingMode.CEILING.HALF_UP) |
| 1924 | .floatValue(); |
| 1925 | } |
| 1926 | |
| 1927 | /** |
| 1928 | * @return the normalized y-axis position of the bubble stack rounded to 4 decimal places. |
| 1929 | */ |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 1930 | public float getNormalizedYPosition() { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 1931 | return new BigDecimal(getStackPosition().y / mDisplaySize.y) |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1932 | .setScale(4, RoundingMode.CEILING.HALF_UP) |
| 1933 | .floatValue(); |
| 1934 | } |
| 1935 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1936 | public PointF getStackPosition() { |
| 1937 | return mStackAnimationController.getStackPosition(); |
| 1938 | } |
| 1939 | |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1940 | /** |
| 1941 | * Logs the bubble UI event. |
| 1942 | * |
| 1943 | * @param bubble the bubble that is being interacted on. Null value indicates that |
| 1944 | * the user interaction is not specific to one bubble. |
| 1945 | * @param action the user interaction enum. |
| 1946 | */ |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1947 | private void logBubbleEvent(@Nullable BubbleViewProvider bubble, int action) { |
| 1948 | if (bubble == null) { |
| 1949 | return; |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1950 | } |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1951 | bubble.logUIEvent(getBubbleCount(), action, getNormalizedXPosition(), |
| 1952 | getNormalizedYPosition(), getBubbleIndex(bubble)); |
Steven Wu | a254dab | 2019-01-29 11:30:39 -0500 | [diff] [blame] | 1953 | } |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 1954 | |
| 1955 | /** |
| 1956 | * Called when a back gesture should be directed to the Bubbles stack. When expanded, |
| 1957 | * a back key down/up event pair is forwarded to the bubble Activity. |
| 1958 | */ |
| 1959 | boolean performBackPressIfNeeded() { |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1960 | if (!isExpanded() || mExpandedBubble == null) { |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 1961 | return false; |
| 1962 | } |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 1963 | return mExpandedBubble.getExpandedView().performBackPressIfNeeded(); |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 1964 | } |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1965 | |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 1966 | /** Whether the educational view should appear for bubbles. **/ |
| 1967 | private boolean shouldShowBubblesEducation() { |
| 1968 | return BubbleDebugConfig.forceShowUserEducation(getContext()) |
| 1969 | || !Prefs.getBoolean(getContext(), HAS_SEEN_BUBBLES_EDUCATION, false); |
| 1970 | } |
| 1971 | |
| 1972 | /** Whether the educational view should appear for the expanded view "manage" button. **/ |
| 1973 | private boolean shouldShowManageEducation() { |
| 1974 | return BubbleDebugConfig.forceShowUserEducation(getContext()) |
| 1975 | || !Prefs.getBoolean(getContext(), HAS_SEEN_BUBBLES_MANAGE_EDUCATION, false); |
| 1976 | } |
| 1977 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1978 | /** For debugging only */ |
| 1979 | List<Bubble> getBubblesOnScreen() { |
| 1980 | List<Bubble> bubbles = new ArrayList<>(); |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 1981 | for (int i = 0; i < getBubbleCount(); i++) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1982 | View child = mBubbleContainer.getChildAt(i); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1983 | if (child instanceof BadgedImageView) { |
| 1984 | String key = ((BadgedImageView) child).getKey(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1985 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 1986 | bubbles.add(bubble); |
| 1987 | } |
| 1988 | } |
| 1989 | return bubbles; |
| 1990 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1991 | } |