Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.animation; |
| 18 | |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 19 | import android.content.res.Configuration; |
Joshua Tsuji | f44347f | 2019-02-12 14:28:06 -0500 | [diff] [blame] | 20 | import android.content.res.Resources; |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 21 | import android.graphics.Path; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 22 | import android.graphics.Point; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 23 | import android.graphics.PointF; |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 24 | import android.view.DisplayCutout; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 25 | import android.view.View; |
| 26 | import android.view.WindowInsets; |
| 27 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 28 | import androidx.annotation.NonNull; |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 29 | import androidx.annotation.Nullable; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 30 | import androidx.dynamicanimation.animation.DynamicAnimation; |
| 31 | import androidx.dynamicanimation.animation.SpringForce; |
| 32 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 33 | import com.android.systemui.Interpolators; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 34 | import com.android.systemui.R; |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 35 | import com.android.systemui.util.magnetictarget.MagnetizedObject; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 36 | |
| 37 | import com.google.android.collect.Sets; |
| 38 | |
Joshua Tsuji | 395bcfe | 2019-07-02 19:23:23 -0400 | [diff] [blame] | 39 | import java.io.FileDescriptor; |
| 40 | import java.io.PrintWriter; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 41 | import java.util.Set; |
| 42 | |
| 43 | /** |
| 44 | * Animation controller for bubbles when they're in their expanded state, or animating to/from the |
| 45 | * expanded state. This controls the expansion animation as well as bubbles 'dragging out' to be |
| 46 | * dismissed. |
| 47 | */ |
| 48 | public class ExpandedAnimationController |
| 49 | extends PhysicsAnimationLayout.PhysicsAnimationController { |
| 50 | |
| 51 | /** |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 52 | * How much to translate the bubbles when they're animating in/out. This value is multiplied by |
| 53 | * the bubble size. |
| 54 | */ |
| 55 | private static final int ANIMATE_TRANSLATION_FACTOR = 4; |
| 56 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 57 | /** Duration of the expand/collapse target path animation. */ |
| 58 | private static final int EXPAND_COLLAPSE_TARGET_ANIM_DURATION = 175; |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 59 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 60 | /** Stiffness for the expand/collapse path-following animation. */ |
| 61 | private static final int EXPAND_COLLAPSE_ANIM_STIFFNESS = 1000; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 62 | |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 63 | /** What percentage of the screen to use when centering the bubbles in landscape. */ |
| 64 | private static final float CENTER_BUBBLES_LANDSCAPE_PERCENT = 0.66f; |
| 65 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 66 | /** |
| 67 | * Velocity required to dismiss an individual bubble without dragging it into the dismiss |
| 68 | * target. |
| 69 | */ |
| 70 | private static final float FLING_TO_DISMISS_MIN_VELOCITY = 6000f; |
| 71 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 72 | /** Horizontal offset between bubbles, which we need to know to re-stack them. */ |
| 73 | private float mStackOffsetPx; |
Lyn Han | 4a8efe3 | 2019-05-30 09:43:27 -0700 | [diff] [blame] | 74 | /** Space between status bar and bubbles in the expanded state. */ |
| 75 | private float mBubblePaddingTop; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 76 | /** Size of each bubble. */ |
| 77 | private float mBubbleSizePx; |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 78 | /** Space between bubbles in row above expanded view. */ |
| 79 | private float mSpaceBetweenBubbles; |
Joshua Tsuji | f44347f | 2019-02-12 14:28:06 -0500 | [diff] [blame] | 80 | /** Height of the status bar. */ |
| 81 | private float mStatusBarHeight; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 82 | /** Size of display. */ |
| 83 | private Point mDisplaySize; |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 84 | /** Max number of bubbles shown in row above expanded view. */ |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 85 | private int mBubblesMaxRendered; |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 86 | /** What the current screen orientation is. */ |
| 87 | private int mScreenOrientation; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 88 | |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 89 | private boolean mAnimatingExpand = false; |
| 90 | private boolean mAnimatingCollapse = false; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 91 | private @Nullable Runnable mAfterExpand; |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 92 | private Runnable mAfterCollapse; |
| 93 | private PointF mCollapsePoint; |
| 94 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 95 | /** |
| 96 | * Whether the dragged out bubble is springing towards the touch point, rather than using the |
| 97 | * default behavior of moving directly to the touch point. |
| 98 | * |
| 99 | * This happens when the user's finger exits the dismiss area while the bubble is magnetized to |
| 100 | * the center. Since the touch point differs from the bubble location, we need to animate the |
| 101 | * bubble back to the touch point to avoid a jarring instant location change from the center of |
| 102 | * the target to the touch point just outside the target bounds. |
| 103 | */ |
| 104 | private boolean mSpringingBubbleToTouch = false; |
| 105 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 106 | /** |
| 107 | * Whether to spring the bubble to the next touch event coordinates. This is used to animate the |
| 108 | * bubble out of the magnetic dismiss target to the touch location. |
| 109 | * |
| 110 | * Once it 'catches up' and the animation ends, we'll revert to moving it directly. |
| 111 | */ |
| 112 | private boolean mSpringToTouchOnNextMotionEvent = false; |
| 113 | |
| 114 | /** The bubble currently being dragged out of the row (to potentially be dismissed). */ |
| 115 | private MagnetizedObject<View> mMagnetizedBubbleDraggingOut; |
| 116 | |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 117 | private int mExpandedViewPadding; |
| 118 | |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 119 | public ExpandedAnimationController(Point displaySize, int expandedViewPadding, |
| 120 | int orientation) { |
Lyn Han | b4b0613 | 2020-05-11 09:25:20 -0700 | [diff] [blame] | 121 | updateResources(orientation, displaySize); |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 122 | mExpandedViewPadding = expandedViewPadding; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 123 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 124 | |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 125 | /** |
| 126 | * Whether the individual bubble has been dragged out of the row of bubbles far enough to cause |
| 127 | * the rest of the bubbles to animate to fill the gap. |
| 128 | */ |
| 129 | private boolean mBubbleDraggedOutEnough = false; |
| 130 | |
Joshua Tsuji | 5084b66 | 2020-04-10 12:54:05 -0400 | [diff] [blame] | 131 | /** End action to run when the lead bubble's expansion animation completes. */ |
| 132 | @Nullable private Runnable mLeadBubbleEndAction; |
| 133 | |
| 134 | /** |
| 135 | * Animates expanding the bubbles into a row along the top of the screen, optionally running an |
| 136 | * end action when the entire animation completes, and an end action when the lead bubble's |
| 137 | * animation ends. |
| 138 | */ |
| 139 | public void expandFromStack( |
| 140 | @Nullable Runnable after, @Nullable Runnable leadBubbleEndAction) { |
| 141 | mAnimatingCollapse = false; |
| 142 | mAnimatingExpand = true; |
| 143 | mAfterExpand = after; |
| 144 | mLeadBubbleEndAction = leadBubbleEndAction; |
| 145 | |
| 146 | startOrUpdatePathAnimation(true /* expanding */); |
| 147 | } |
| 148 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 149 | /** |
| 150 | * Animates expanding the bubbles into a row along the top of the screen. |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 151 | */ |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 152 | public void expandFromStack(@Nullable Runnable after) { |
Joshua Tsuji | 5084b66 | 2020-04-10 12:54:05 -0400 | [diff] [blame] | 153 | expandFromStack(after, null /* leadBubbleEndAction */); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /** Animate collapsing the bubbles back to their stacked position. */ |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 157 | public void collapseBackToStack(PointF collapsePoint, Runnable after) { |
| 158 | mAnimatingExpand = false; |
| 159 | mAnimatingCollapse = true; |
| 160 | mAfterCollapse = after; |
| 161 | mCollapsePoint = collapsePoint; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 162 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 163 | startOrUpdatePathAnimation(false /* expanding */); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 166 | /** |
| 167 | * Update effective screen width based on current orientation. |
| 168 | * @param orientation Landscape or portrait. |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 169 | * @param displaySize Updated display size. |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 170 | */ |
Lyn Han | b4b0613 | 2020-05-11 09:25:20 -0700 | [diff] [blame] | 171 | public void updateResources(int orientation, Point displaySize) { |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 172 | mScreenOrientation = orientation; |
| 173 | mDisplaySize = displaySize; |
Mady Mellor | 818eef0 | 2019-08-16 16:12:29 -0700 | [diff] [blame] | 174 | if (mLayout != null) { |
| 175 | Resources res = mLayout.getContext().getResources(); |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 176 | mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top); |
Mady Mellor | 818eef0 | 2019-08-16 16:12:29 -0700 | [diff] [blame] | 177 | mStatusBarHeight = res.getDimensionPixelSize( |
| 178 | com.android.internal.R.dimen.status_bar_height); |
Mady Mellor | 818eef0 | 2019-08-16 16:12:29 -0700 | [diff] [blame] | 179 | } |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 182 | /** |
| 183 | * Animates the bubbles along a curved path, either to expand them along the top or collapse |
| 184 | * them back into a stack. |
| 185 | */ |
| 186 | private void startOrUpdatePathAnimation(boolean expanding) { |
| 187 | Runnable after; |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 188 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 189 | if (expanding) { |
| 190 | after = () -> { |
| 191 | mAnimatingExpand = false; |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 192 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 193 | if (mAfterExpand != null) { |
| 194 | mAfterExpand.run(); |
| 195 | } |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 196 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 197 | mAfterExpand = null; |
| 198 | }; |
| 199 | } else { |
| 200 | after = () -> { |
| 201 | mAnimatingCollapse = false; |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 202 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 203 | if (mAfterCollapse != null) { |
| 204 | mAfterCollapse.run(); |
| 205 | } |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 206 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 207 | mAfterCollapse = null; |
| 208 | }; |
| 209 | } |
| 210 | |
| 211 | // Animate each bubble individually, since each path will end in a different spot. |
| 212 | animationsForChildrenFromIndex(0, (index, animation) -> { |
| 213 | final View bubble = mLayout.getChildAt(index); |
| 214 | |
| 215 | // Start a path at the bubble's current position. |
| 216 | final Path path = new Path(); |
| 217 | path.moveTo(bubble.getTranslationX(), bubble.getTranslationY()); |
| 218 | |
| 219 | final float expandedY = getExpandedY(); |
| 220 | if (expanding) { |
| 221 | // If we're expanding, first draw a line from the bubble's current position to the |
| 222 | // top of the screen. |
| 223 | path.lineTo(bubble.getTranslationX(), expandedY); |
| 224 | |
| 225 | // Then, draw a line across the screen to the bubble's resting position. |
| 226 | path.lineTo(getBubbleLeft(index), expandedY); |
| 227 | } else { |
| 228 | final float sideMultiplier = |
| 229 | mLayout.isFirstChildXLeftOfCenter(mCollapsePoint.x) ? -1 : 1; |
| 230 | final float stackedX = mCollapsePoint.x + (sideMultiplier * index * mStackOffsetPx); |
| 231 | |
| 232 | // If we're collapsing, draw a line from the bubble's current position to the side |
| 233 | // of the screen where the bubble will be stacked. |
| 234 | path.lineTo(stackedX, expandedY); |
| 235 | |
| 236 | // Then, draw a line down to the stack position. |
| 237 | path.lineTo(stackedX, mCollapsePoint.y); |
| 238 | } |
| 239 | |
| 240 | // The lead bubble should be the bubble with the longest distance to travel when we're |
| 241 | // expanding, and the bubble with the shortest distance to travel when we're collapsing. |
| 242 | // During expansion from the left side, the last bubble has to travel to the far right |
| 243 | // side, so we have it lead and 'pull' the rest of the bubbles into place. From the |
| 244 | // right side, the first bubble is traveling to the top left, so it leads. During |
| 245 | // collapse to the left, the first bubble has the shortest travel time back to the stack |
| 246 | // position, so it leads (and vice versa). |
| 247 | final boolean firstBubbleLeads = |
| 248 | (expanding && !mLayout.isFirstChildXLeftOfCenter(bubble.getTranslationX())) |
| 249 | || (!expanding && mLayout.isFirstChildXLeftOfCenter(mCollapsePoint.x)); |
| 250 | final int startDelay = firstBubbleLeads |
| 251 | ? (index * 10) |
| 252 | : ((mLayout.getChildCount() - index) * 10); |
| 253 | |
Joshua Tsuji | 5084b66 | 2020-04-10 12:54:05 -0400 | [diff] [blame] | 254 | final boolean isLeadBubble = |
| 255 | (firstBubbleLeads && index == 0) |
| 256 | || (!firstBubbleLeads && index == mLayout.getChildCount() - 1); |
| 257 | |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 258 | animation |
| 259 | .followAnimatedTargetAlongPath( |
| 260 | path, |
| 261 | EXPAND_COLLAPSE_TARGET_ANIM_DURATION /* targetAnimDuration */, |
Joshua Tsuji | 5084b66 | 2020-04-10 12:54:05 -0400 | [diff] [blame] | 262 | Interpolators.LINEAR /* targetAnimInterpolator */, |
| 263 | isLeadBubble ? mLeadBubbleEndAction : null /* endAction */, |
| 264 | () -> mLeadBubbleEndAction = null /* endAction */) |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 265 | .withStartDelay(startDelay) |
| 266 | .withStiffness(EXPAND_COLLAPSE_ANIM_STIFFNESS); |
| 267 | }).startAll(after); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 270 | /** Notifies the controller that the dragged-out bubble was unstuck from the magnetic target. */ |
| 271 | public void onUnstuckFromTarget() { |
| 272 | mSpringToTouchOnNextMotionEvent = true; |
| 273 | } |
| 274 | |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 275 | /** |
| 276 | * Prepares the given bubble view to be dragged out, using the provided magnetic target and |
| 277 | * listener. |
| 278 | */ |
| 279 | public void prepareForBubbleDrag( |
| 280 | View bubble, |
| 281 | MagnetizedObject.MagneticTarget target, |
| 282 | MagnetizedObject.MagnetListener listener) { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 283 | mLayout.cancelAnimationsOnView(bubble); |
| 284 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 285 | bubble.setTranslationZ(Short.MAX_VALUE); |
| 286 | mMagnetizedBubbleDraggingOut = new MagnetizedObject<View>( |
| 287 | mLayout.getContext(), bubble, |
| 288 | DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y) { |
| 289 | @Override |
| 290 | public float getWidth(@NonNull View underlyingObject) { |
| 291 | return mBubbleSizePx; |
| 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public float getHeight(@NonNull View underlyingObject) { |
| 296 | return mBubbleSizePx; |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public void getLocationOnScreen(@NonNull View underlyingObject, @NonNull int[] loc) { |
| 301 | loc[0] = (int) bubble.getTranslationX(); |
| 302 | loc[1] = (int) bubble.getTranslationY(); |
| 303 | } |
| 304 | }; |
| 305 | mMagnetizedBubbleDraggingOut.addTarget(target); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 306 | mMagnetizedBubbleDraggingOut.setMagnetListener(listener); |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 307 | mMagnetizedBubbleDraggingOut.setHapticsEnabled(true); |
| 308 | mMagnetizedBubbleDraggingOut.setFlingToTargetMinVelocity(FLING_TO_DISMISS_MIN_VELOCITY); |
| 309 | } |
| 310 | |
| 311 | private void springBubbleTo(View bubble, float x, float y) { |
| 312 | animationForChild(bubble) |
| 313 | .translationX(x) |
| 314 | .translationY(y) |
| 315 | .withStiffness(SpringForce.STIFFNESS_HIGH) |
| 316 | .start(); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Drags an individual bubble to the given coordinates. Bubbles to the right will animate to |
| 321 | * take its place once it's dragged out of the row of bubbles, and animate out of the way if the |
| 322 | * bubble is dragged back into the row. |
| 323 | */ |
| 324 | public void dragBubbleOut(View bubbleView, float x, float y) { |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 325 | if (mSpringToTouchOnNextMotionEvent) { |
| 326 | springBubbleTo(mMagnetizedBubbleDraggingOut.getUnderlyingObject(), x, y); |
| 327 | mSpringToTouchOnNextMotionEvent = false; |
| 328 | mSpringingBubbleToTouch = true; |
| 329 | } else if (mSpringingBubbleToTouch) { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 330 | if (mLayout.arePropertiesAnimatingOnView( |
| 331 | bubbleView, DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y)) { |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 332 | springBubbleTo(mMagnetizedBubbleDraggingOut.getUnderlyingObject(), x, y); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 333 | } else { |
| 334 | mSpringingBubbleToTouch = false; |
| 335 | } |
| 336 | } |
| 337 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 338 | if (!mSpringingBubbleToTouch && !mMagnetizedBubbleDraggingOut.getObjectStuckToTarget()) { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 339 | bubbleView.setTranslationX(x); |
| 340 | bubbleView.setTranslationY(y); |
| 341 | } |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 342 | |
| 343 | final boolean draggedOutEnough = |
| 344 | y > getExpandedY() + mBubbleSizePx || y < getExpandedY() - mBubbleSizePx; |
| 345 | if (draggedOutEnough != mBubbleDraggedOutEnough) { |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 346 | updateBubblePositions(); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 347 | mBubbleDraggedOutEnough = draggedOutEnough; |
| 348 | } |
| 349 | } |
| 350 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 351 | /** Plays a dismiss animation on the dragged out bubble. */ |
Joshua Tsuji | 79a58ee | 2020-03-27 17:55:37 -0400 | [diff] [blame] | 352 | public void dismissDraggedOutBubble(View bubble, float translationYBy, Runnable after) { |
Mady Mellor | 12c9095 | 2020-04-06 12:29:07 -0700 | [diff] [blame] | 353 | if (bubble == null) { |
| 354 | return; |
| 355 | } |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 356 | animationForChild(bubble) |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 357 | .withStiffness(SpringForce.STIFFNESS_HIGH) |
| 358 | .scaleX(1.1f) |
| 359 | .scaleY(1.1f) |
Joshua Tsuji | 79a58ee | 2020-03-27 17:55:37 -0400 | [diff] [blame] | 360 | .translationY(bubble.getTranslationY() + translationYBy) |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 361 | .alpha(0f, after) |
| 362 | .start(); |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 363 | |
| 364 | updateBubblePositions(); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 367 | @Nullable public View getDraggedOutBubble() { |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 368 | return mMagnetizedBubbleDraggingOut == null |
| 369 | ? null |
| 370 | : mMagnetizedBubbleDraggingOut.getUnderlyingObject(); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 371 | } |
| 372 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 373 | /** Returns the MagnetizedObject instance for the dragging-out bubble. */ |
| 374 | public MagnetizedObject<View> getMagnetizedBubbleDraggingOut() { |
| 375 | return mMagnetizedBubbleDraggingOut; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 376 | } |
| 377 | |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 378 | /** |
| 379 | * Snaps a bubble back to its position within the bubble row, and animates the rest of the |
| 380 | * bubbles to accommodate it if it was previously dragged out past the threshold. |
| 381 | */ |
| 382 | public void snapBubbleBack(View bubbleView, float velX, float velY) { |
| 383 | final int index = mLayout.indexOfChild(bubbleView); |
| 384 | |
Joshua Tsuji | c110843 | 2019-02-22 16:10:12 -0500 | [diff] [blame] | 385 | animationForChildAtIndex(index) |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 386 | .position(getBubbleLeft(index), getExpandedY()) |
| 387 | .withPositionStartVelocities(velX, velY) |
| 388 | .start(() -> bubbleView.setTranslationZ(0f) /* after */); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 389 | |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 390 | mMagnetizedBubbleDraggingOut = null; |
| 391 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 392 | updateBubblePositions(); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 393 | } |
| 394 | |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 395 | /** Resets bubble drag out gesture flags. */ |
| 396 | public void onGestureFinished() { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 397 | mBubbleDraggedOutEnough = false; |
Lyn Han | f44562b | 2020-03-30 16:40:46 -0700 | [diff] [blame] | 398 | mMagnetizedBubbleDraggingOut = null; |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 399 | updateBubblePositions(); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 403 | * Animates the bubbles to {@link #getExpandedY()} position. Used in response to IME showing. |
| 404 | */ |
| 405 | public void updateYPosition(Runnable after) { |
| 406 | if (mLayout == null) return; |
Joshua Tsuji | c110843 | 2019-02-22 16:10:12 -0500 | [diff] [blame] | 407 | animationsForChildrenFromIndex( |
| 408 | 0, (i, anim) -> anim.translationY(getExpandedY())).startAll(after); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 411 | /** The Y value of the row of expanded bubbles. */ |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 412 | public float getExpandedY() { |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 413 | if (mLayout == null || mLayout.getRootWindowInsets() == null) { |
| 414 | return 0; |
| 415 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 416 | final WindowInsets insets = mLayout.getRootWindowInsets(); |
Lyn Han | 4a8efe3 | 2019-05-30 09:43:27 -0700 | [diff] [blame] | 417 | return mBubblePaddingTop + Math.max( |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 418 | mStatusBarHeight, |
| 419 | insets.getDisplayCutout() != null |
| 420 | ? insets.getDisplayCutout().getSafeInsetTop() |
| 421 | : 0); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 422 | } |
| 423 | |
Joshua Tsuji | 395bcfe | 2019-07-02 19:23:23 -0400 | [diff] [blame] | 424 | /** Description of current animation controller state. */ |
| 425 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 426 | pw.println("ExpandedAnimationController state:"); |
| 427 | pw.print(" isActive: "); pw.println(isActiveController()); |
| 428 | pw.print(" animatingExpand: "); pw.println(mAnimatingExpand); |
| 429 | pw.print(" animatingCollapse: "); pw.println(mAnimatingCollapse); |
Joshua Tsuji | 395bcfe | 2019-07-02 19:23:23 -0400 | [diff] [blame] | 430 | pw.print(" springingBubble: "); pw.println(mSpringingBubbleToTouch); |
| 431 | } |
| 432 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 433 | @Override |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 434 | void onActiveControllerForLayout(PhysicsAnimationLayout layout) { |
| 435 | final Resources res = layout.getResources(); |
| 436 | mStackOffsetPx = res.getDimensionPixelSize(R.dimen.bubble_stack_offset); |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 437 | mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top); |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 438 | mBubbleSizePx = res.getDimensionPixelSize(R.dimen.individual_bubble_size); |
| 439 | mStatusBarHeight = |
| 440 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 441 | mBubblesMaxRendered = res.getInteger(R.integer.bubbles_max_rendered); |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 442 | |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 443 | // Includes overflow button. |
Lyn Han | f418e78 | 2020-03-12 21:51:30 -0700 | [diff] [blame] | 444 | float totalGapWidth = getWidthForDisplayingBubbles() - (mExpandedViewPadding * 2) |
| 445 | - (mBubblesMaxRendered + 1) * mBubbleSizePx; |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 446 | mSpaceBetweenBubbles = totalGapWidth / mBubblesMaxRendered; |
| 447 | |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 448 | // Ensure that all child views are at 1x scale, and visible, in case they were animating |
| 449 | // in. |
| 450 | mLayout.setVisibility(View.VISIBLE); |
| 451 | animationsForChildrenFromIndex(0 /* startIndex */, (index, animation) -> |
| 452 | animation.scaleX(1f).scaleY(1f).alpha(1f)).startAll(); |
| 453 | } |
| 454 | |
| 455 | @Override |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 456 | Set<DynamicAnimation.ViewProperty> getAnimatedProperties() { |
| 457 | return Sets.newHashSet( |
| 458 | DynamicAnimation.TRANSLATION_X, |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 459 | DynamicAnimation.TRANSLATION_Y, |
| 460 | DynamicAnimation.SCALE_X, |
| 461 | DynamicAnimation.SCALE_Y, |
| 462 | DynamicAnimation.ALPHA); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | @Override |
| 466 | int getNextAnimationInChain(DynamicAnimation.ViewProperty property, int index) { |
| 467 | return NONE; |
| 468 | } |
| 469 | |
| 470 | @Override |
| 471 | float getOffsetForChainedPropertyAnimation(DynamicAnimation.ViewProperty property) { |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | SpringForce getSpringForce(DynamicAnimation.ViewProperty property, View view) { |
| 477 | return new SpringForce() |
Joshua Tsuji | 010c2b1 | 2019-02-25 18:11:25 -0500 | [diff] [blame] | 478 | .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY) |
| 479 | .setStiffness(SpringForce.STIFFNESS_LOW); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @Override |
| 483 | void onChildAdded(View child, int index) { |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 484 | // If a bubble is added while the expand/collapse animations are playing, update the |
| 485 | // animation to include the new bubble. |
| 486 | if (mAnimatingExpand) { |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 487 | startOrUpdatePathAnimation(true /* expanding */); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 488 | } else if (mAnimatingCollapse) { |
Joshua Tsuji | debd831 | 2019-06-06 17:17:08 -0400 | [diff] [blame] | 489 | startOrUpdatePathAnimation(false /* expanding */); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 490 | } else { |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 491 | child.setTranslationX(getBubbleLeft(index)); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 492 | animationForChild(child) |
| 493 | .translationY( |
| 494 | getExpandedY() - mBubbleSizePx * ANIMATE_TRANSLATION_FACTOR, /* from */ |
| 495 | getExpandedY() /* to */) |
| 496 | .start(); |
| 497 | updateBubblePositions(); |
| 498 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | @Override |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 502 | void onChildRemoved(View child, int index, Runnable finishRemoval) { |
Joshua Tsuji | c110843 | 2019-02-22 16:10:12 -0500 | [diff] [blame] | 503 | final PhysicsAnimationLayout.PhysicsPropertyAnimator animator = animationForChild(child); |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 504 | |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 505 | // If we're removing the dragged-out bubble, that means it got dismissed. |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 506 | if (child.equals(getDraggedOutBubble())) { |
| 507 | mMagnetizedBubbleDraggingOut = null; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 508 | finishRemoval.run(); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 509 | } else { |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 510 | animator.alpha(0f, finishRemoval /* endAction */) |
| 511 | .withStiffness(SpringForce.STIFFNESS_HIGH) |
| 512 | .withDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY) |
| 513 | .scaleX(1.1f) |
| 514 | .scaleY(1.1f) |
| 515 | .start(); |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 516 | } |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 517 | |
| 518 | // Animate all the other bubbles to their new positions sans this bubble. |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 519 | updateBubblePositions(); |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | @Override |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 523 | void onChildReordered(View child, int oldIndex, int newIndex) { |
| 524 | updateBubblePositions(); |
Joshua Tsuji | 2862f2e | 2019-07-29 12:32:33 -0400 | [diff] [blame] | 525 | |
| 526 | // We expect reordering during collapse, since we'll put the last selected bubble on top. |
| 527 | // Update the collapse animation so they end up in the right stacked positions. |
| 528 | if (mAnimatingCollapse) { |
| 529 | startOrUpdatePathAnimation(false /* expanding */); |
| 530 | } |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 531 | } |
| 532 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 533 | private void updateBubblePositions() { |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 534 | if (mAnimatingExpand || mAnimatingCollapse) { |
| 535 | return; |
| 536 | } |
| 537 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 538 | for (int i = 0; i < mLayout.getChildCount(); i++) { |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 539 | final View bubble = mLayout.getChildAt(i); |
| 540 | |
| 541 | // Don't animate the dragging out bubble, or it'll jump around while being dragged. It |
| 542 | // will be snapped to the correct X value after the drag (if it's not dismissed). |
Joshua Tsuji | 2010354 | 2020-02-18 14:06:28 -0500 | [diff] [blame] | 543 | if (bubble.equals(getDraggedOutBubble())) { |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 544 | return; |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 545 | } |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 546 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 547 | animationForChild(bubble) |
| 548 | .translationX(getBubbleLeft(i)) |
| 549 | .start(); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 553 | /** |
| 554 | * @param index Bubble index in row. |
| 555 | * @return Bubble left x from left edge of screen. |
| 556 | */ |
| 557 | public float getBubbleLeft(int index) { |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 558 | final float bubbleFromRowLeft = index * (mBubbleSizePx + mSpaceBetweenBubbles); |
Lyn Han | 4a8efe3 | 2019-05-30 09:43:27 -0700 | [diff] [blame] | 559 | return getRowLeft() + bubbleFromRowLeft; |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 562 | /** |
| 563 | * When expanded, the bubbles are centered in the screen. In portrait, all available space is |
| 564 | * used. In landscape we have too much space so the value is restricted. This method accounts |
| 565 | * for window decorations (nav bar, cutouts). |
| 566 | * |
| 567 | * @return the desired width to display the expanded bubbles in. |
| 568 | */ |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 569 | public float getWidthForDisplayingBubbles() { |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 570 | final float availableWidth = getAvailableScreenWidth(true /* includeStableInsets */); |
| 571 | if (mScreenOrientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 572 | // display size y in landscape will be the smaller dimension of the screen |
| 573 | return Math.max(mDisplaySize.y, availableWidth * CENTER_BUBBLES_LANDSCAPE_PERCENT); |
| 574 | } else { |
| 575 | return availableWidth; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Determines the available screen width without the cutout. |
| 581 | * |
| 582 | * @param subtractStableInsets Whether or not stable insets should also be removed from the |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 583 | * returned width. |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 584 | * @return the total screen width available accounting for cutouts and insets, |
| 585 | * iff {@param includeStableInsets} is true. |
| 586 | */ |
| 587 | private float getAvailableScreenWidth(boolean subtractStableInsets) { |
| 588 | float availableSize = mDisplaySize.x; |
| 589 | WindowInsets insets = mLayout != null ? mLayout.getRootWindowInsets() : null; |
| 590 | if (insets != null) { |
| 591 | int cutoutLeft = 0; |
| 592 | int cutoutRight = 0; |
| 593 | DisplayCutout cutout = insets.getDisplayCutout(); |
| 594 | if (cutout != null) { |
| 595 | cutoutLeft = cutout.getSafeInsetLeft(); |
| 596 | cutoutRight = cutout.getSafeInsetRight(); |
| 597 | } |
| 598 | final int stableLeft = subtractStableInsets ? insets.getStableInsetLeft() : 0; |
| 599 | final int stableRight = subtractStableInsets ? insets.getStableInsetRight() : 0; |
| 600 | availableSize -= Math.max(stableLeft, cutoutLeft); |
| 601 | availableSize -= Math.max(stableRight, cutoutRight); |
| 602 | } |
| 603 | return availableSize; |
| 604 | } |
| 605 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 606 | private float getRowLeft() { |
| 607 | if (mLayout == null) { |
| 608 | return 0; |
| 609 | } |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 610 | float rowWidth = (mLayout.getChildCount() * mBubbleSizePx) |
| 611 | + ((mLayout.getChildCount() - 1) * mSpaceBetweenBubbles); |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 612 | |
Mady Mellor | e19353d | 2019-08-21 17:25:02 -0700 | [diff] [blame] | 613 | // This display size we're using includes the size of the insets, we want the true |
| 614 | // center of the display minus the notch here, which means we should include the |
| 615 | // stable insets (e.g. status bar, nav bar) in this calculation. |
| 616 | final float trueCenter = getAvailableScreenWidth(false /* subtractStableInsets */) / 2f; |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 617 | return trueCenter - (rowWidth / 2f); |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 618 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 619 | } |