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