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