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