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 | |
| 19 | import static org.junit.Assert.assertEquals; |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 20 | import static org.junit.Assert.assertNotEquals; |
| 21 | import static org.mockito.Mockito.verify; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 22 | |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 24 | import android.content.res.Resources; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 25 | import android.graphics.Point; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 26 | import android.graphics.PointF; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 27 | import android.testing.AndroidTestingRunner; |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.widget.FrameLayout; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 30 | |
| 31 | import androidx.dynamicanimation.animation.DynamicAnimation; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 32 | import androidx.test.filters.SmallTest; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 33 | |
| 34 | import com.android.systemui.R; |
| 35 | |
| 36 | import org.junit.Before; |
Joshua Tsuji | 15e7262 | 2019-05-09 21:31:29 -0400 | [diff] [blame] | 37 | import org.junit.Ignore; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
| 40 | import org.mockito.Mockito; |
| 41 | import org.mockito.Spy; |
| 42 | |
| 43 | @SmallTest |
| 44 | @RunWith(AndroidTestingRunner.class) |
| 45 | public class ExpandedAnimationControllerTest extends PhysicsAnimationLayoutTestCase { |
| 46 | |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 47 | private int mDisplayWidth = 500; |
| 48 | private int mDisplayHeight = 1000; |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 49 | private int mExpandedViewPadding = 10; |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 50 | private int mOrientation = Configuration.ORIENTATION_PORTRAIT; |
Lyn Han | 1b4f25e | 2019-06-11 13:56:34 -0700 | [diff] [blame] | 51 | private float mLauncherGridDiff = 30f; |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 52 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 53 | @Spy |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 54 | private ExpandedAnimationController mExpandedController = |
Lyn Han | 6f6b3ae | 2019-05-16 14:17:30 -0700 | [diff] [blame] | 55 | new ExpandedAnimationController( |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 56 | new Point(mDisplayWidth, mDisplayHeight) /* displaySize */, |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 57 | mExpandedViewPadding, mOrientation); |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 58 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 59 | private int mStackOffset; |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 60 | private float mBubblePaddingTop; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 61 | private float mBubbleSize; |
| 62 | |
| 63 | private PointF mExpansionPoint; |
| 64 | |
| 65 | @Before |
| 66 | public void setUp() throws Exception { |
| 67 | super.setUp(); |
Joshua Tsuji | cb97a11 | 2019-05-29 16:20:41 -0400 | [diff] [blame] | 68 | addOneMoreThanBubbleLimitBubbles(); |
Joshua Tsuji | c36ee6f | 2019-05-28 17:00:16 -0400 | [diff] [blame] | 69 | mLayout.setActiveController(mExpandedController); |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 70 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 71 | Resources res = mLayout.getResources(); |
| 72 | mStackOffset = res.getDimensionPixelSize(R.dimen.bubble_stack_offset); |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 73 | mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 74 | mBubbleSize = res.getDimensionPixelSize(R.dimen.individual_bubble_size); |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 75 | mExpansionPoint = new PointF(100, 100); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Test |
Joshua Tsuji | c5fab41 | 2019-09-12 15:16:40 -0400 | [diff] [blame] | 79 | @Ignore |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 80 | public void testExpansionAndCollapse() throws InterruptedException { |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 81 | Runnable afterExpand = Mockito.mock(Runnable.class); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 82 | mExpandedController.expandFromStack(afterExpand); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 83 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 84 | |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 85 | testBubblesInCorrectExpandedPositions(); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 86 | verify(afterExpand).run(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 87 | |
| 88 | Runnable afterCollapse = Mockito.mock(Runnable.class); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 89 | mExpandedController.collapseBackToStack(mExpansionPoint, afterCollapse); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 90 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 91 | |
| 92 | testStackedAtPosition(mExpansionPoint.x, mExpansionPoint.y, -1); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 93 | verify(afterExpand).run(); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 96 | @Test |
Joshua Tsuji | c5fab41 | 2019-09-12 15:16:40 -0400 | [diff] [blame] | 97 | @Ignore |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 98 | public void testOnChildAdded() throws InterruptedException { |
| 99 | expand(); |
| 100 | |
| 101 | // Add another new view and wait for its animation. |
| 102 | final View newView = new FrameLayout(getContext()); |
| 103 | mLayout.addView(newView, 0); |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 104 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 105 | |
| 106 | testBubblesInCorrectExpandedPositions(); |
| 107 | } |
| 108 | |
| 109 | @Test |
Joshua Tsuji | c5fab41 | 2019-09-12 15:16:40 -0400 | [diff] [blame] | 110 | @Ignore |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 111 | public void testOnChildRemoved() throws InterruptedException { |
| 112 | expand(); |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 113 | |
| 114 | // Remove some views and see if the remaining child views still pass the expansion test. |
| 115 | mLayout.removeView(mViews.get(0)); |
| 116 | mLayout.removeView(mViews.get(3)); |
| 117 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 118 | testBubblesInCorrectExpandedPositions(); |
| 119 | } |
| 120 | |
| 121 | @Test |
Joshua Tsuji | c5fab41 | 2019-09-12 15:16:40 -0400 | [diff] [blame] | 122 | @Ignore |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 123 | public void testBubbleDraggedNotDismissedSnapsBack() throws InterruptedException { |
| 124 | expand(); |
| 125 | |
| 126 | final View draggedBubble = mViews.get(0); |
| 127 | mExpandedController.prepareForBubbleDrag(draggedBubble); |
| 128 | mExpandedController.dragBubbleOut(draggedBubble, 500f, 500f); |
| 129 | |
| 130 | assertEquals(500f, draggedBubble.getTranslationX(), 1f); |
| 131 | assertEquals(500f, draggedBubble.getTranslationY(), 1f); |
| 132 | |
| 133 | // Snap it back and make sure it made it back correctly. |
| 134 | mExpandedController.snapBubbleBack(draggedBubble, 0f, 0f); |
| 135 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 136 | testBubblesInCorrectExpandedPositions(); |
| 137 | } |
| 138 | |
| 139 | @Test |
Joshua Tsuji | c5fab41 | 2019-09-12 15:16:40 -0400 | [diff] [blame] | 140 | @Ignore |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 141 | public void testBubbleDismissed() throws InterruptedException { |
| 142 | expand(); |
| 143 | |
| 144 | final View draggedBubble = mViews.get(0); |
| 145 | mExpandedController.prepareForBubbleDrag(draggedBubble); |
| 146 | mExpandedController.dragBubbleOut(draggedBubble, 500f, 500f); |
| 147 | |
| 148 | assertEquals(500f, draggedBubble.getTranslationX(), 1f); |
| 149 | assertEquals(500f, draggedBubble.getTranslationY(), 1f); |
| 150 | |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 151 | mLayout.removeView(draggedBubble); |
| 152 | waitForLayoutMessageQueue(); |
| 153 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 154 | |
| 155 | assertEquals(-1, mLayout.indexOfChild(draggedBubble)); |
| 156 | testBubblesInCorrectExpandedPositions(); |
| 157 | } |
| 158 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 159 | @Test |
Joshua Tsuji | 16a4abf | 2019-05-22 13:03:58 -0400 | [diff] [blame] | 160 | @Ignore("Flaky") |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 161 | public void testMagnetToDismiss_dismiss() throws InterruptedException { |
| 162 | expand(); |
| 163 | |
| 164 | final View draggedOutView = mViews.get(0); |
| 165 | final Runnable after = Mockito.mock(Runnable.class); |
| 166 | |
| 167 | mExpandedController.prepareForBubbleDrag(draggedOutView); |
| 168 | mExpandedController.dragBubbleOut(draggedOutView, 25, 25); |
| 169 | |
| 170 | // Magnet to dismiss, verify the bubble is at the dismiss target and the callback was |
| 171 | // called. |
| 172 | mExpandedController.magnetBubbleToDismiss( |
| 173 | mViews.get(0), 100 /* velX */, 100 /* velY */, 1000 /* destY */, after); |
| 174 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 175 | verify(after).run(); |
| 176 | assertEquals(1000, mViews.get(0).getTranslationY(), .1f); |
| 177 | |
| 178 | // Dismiss the now-magneted bubble, verify that the callback was called. |
| 179 | final Runnable afterDismiss = Mockito.mock(Runnable.class); |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 180 | mExpandedController.dismissDraggedOutBubble(draggedOutView, afterDismiss); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 181 | waitForPropertyAnimations(DynamicAnimation.ALPHA); |
| 182 | verify(after).run(); |
| 183 | |
| 184 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 185 | |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 186 | assertEquals(mBubblePaddingTop, mViews.get(1).getTranslationX(), 1f); |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Test |
Joshua Tsuji | 15e7262 | 2019-05-09 21:31:29 -0400 | [diff] [blame] | 190 | @Ignore("Flaky") |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 191 | public void testMagnetToDismiss_demagnetizeThenDrag() throws InterruptedException { |
| 192 | expand(); |
| 193 | |
| 194 | final View draggedOutView = mViews.get(0); |
| 195 | final Runnable after = Mockito.mock(Runnable.class); |
| 196 | |
| 197 | mExpandedController.prepareForBubbleDrag(draggedOutView); |
| 198 | mExpandedController.dragBubbleOut(draggedOutView, 25, 25); |
| 199 | |
| 200 | // Magnet to dismiss, verify the bubble is at the dismiss target and the callback was |
| 201 | // called. |
| 202 | mExpandedController.magnetBubbleToDismiss( |
| 203 | draggedOutView, 100 /* velX */, 100 /* velY */, 1000 /* destY */, after); |
| 204 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 205 | verify(after).run(); |
| 206 | assertEquals(1000, mViews.get(0).getTranslationY(), .1f); |
| 207 | |
| 208 | // Demagnetize the bubble towards (25, 25). |
| 209 | mExpandedController.demagnetizeBubbleTo(25 /* x */, 25 /* y */, 100, 100); |
| 210 | |
| 211 | // Start dragging towards (20, 20). |
| 212 | mExpandedController.dragBubbleOut(draggedOutView, 20, 20); |
| 213 | |
| 214 | // Since we just demagnetized, the bubble shouldn't be at (20, 20), it should be animating |
| 215 | // towards it. |
| 216 | assertNotEquals(20, draggedOutView.getTranslationX()); |
| 217 | assertNotEquals(20, draggedOutView.getTranslationY()); |
| 218 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
| 219 | |
| 220 | // Waiting for the animations should result in the bubble ending at (20, 20) since the |
| 221 | // animation end value was updated. |
| 222 | assertEquals(20, draggedOutView.getTranslationX(), 1f); |
| 223 | assertEquals(20, draggedOutView.getTranslationY(), 1f); |
| 224 | |
| 225 | // Drag to (30, 30). |
| 226 | mExpandedController.dragBubbleOut(draggedOutView, 30, 30); |
| 227 | |
| 228 | // It should go there instantly since the animations finished. |
| 229 | assertEquals(30, draggedOutView.getTranslationX(), 1f); |
| 230 | assertEquals(30, draggedOutView.getTranslationY(), 1f); |
| 231 | } |
| 232 | |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 233 | /** Expand the stack and wait for animations to finish. */ |
| 234 | private void expand() throws InterruptedException { |
Joshua Tsuji | f49ee14 | 2019-05-29 16:32:01 -0400 | [diff] [blame] | 235 | mExpandedController.expandFromStack(Mockito.mock(Runnable.class)); |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 236 | waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y); |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 239 | /** Check that children are in the correct positions for being stacked. */ |
| 240 | private void testStackedAtPosition(float x, float y, int offsetMultiplier) { |
| 241 | // Make sure the rest of the stack moved again, including the first bubble not moving, and |
| 242 | // is stacked to the right now that we're on the right side of the screen. |
| 243 | for (int i = 0; i < mLayout.getChildCount(); i++) { |
| 244 | assertEquals(x + i * offsetMultiplier * mStackOffset, |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 245 | mLayout.getChildAt(i).getTranslationX(), 2f); |
| 246 | assertEquals(y, mLayout.getChildAt(i).getTranslationY(), 2f); |
Joshua Tsuji | cb97a11 | 2019-05-29 16:20:41 -0400 | [diff] [blame] | 247 | assertEquals(1f, mLayout.getChildAt(i).getAlpha(), .01f); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | /** Check that children are in the correct positions for being expanded. */ |
Joshua Tsuji | 442b627 | 2019-02-08 13:23:43 -0500 | [diff] [blame] | 252 | private void testBubblesInCorrectExpandedPositions() { |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 253 | // Check all the visible bubbles to see if they're in the right place. |
Joshua Tsuji | cb97a11 | 2019-05-29 16:20:41 -0400 | [diff] [blame] | 254 | for (int i = 0; i < mLayout.getChildCount(); i++) { |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 255 | assertEquals(getBubbleLeft(i), |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 256 | mLayout.getChildAt(i).getTranslationX(), |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 257 | 2f); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 258 | assertEquals(mExpandedController.getExpandedY(), |
Joshua Tsuji | 1575e6b | 2019-01-30 13:43:28 -0500 | [diff] [blame] | 259 | mLayout.getChildAt(i).getTranslationY(), 2f); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 260 | } |
| 261 | } |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * @param index Bubble index in row. |
| 265 | * @return Bubble left x from left edge of screen. |
| 266 | */ |
| 267 | public float getBubbleLeft(int index) { |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 268 | final float bubbleLeft = index * (mBubbleSize + getSpaceBetweenBubbles()); |
| 269 | return getRowLeft() + bubbleLeft; |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | private float getRowLeft() { |
| 273 | if (mLayout == null) { |
| 274 | return 0; |
| 275 | } |
| 276 | int bubbleCount = mLayout.getChildCount(); |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 277 | final float totalBubbleWidth = bubbleCount * mBubbleSize; |
| 278 | final float totalGapWidth = (bubbleCount - 1) * getSpaceBetweenBubbles(); |
| 279 | final float rowWidth = totalGapWidth + totalBubbleWidth; |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 280 | |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 281 | final float centerScreen = mDisplayWidth / 2f; |
| 282 | final float halfRow = rowWidth / 2f; |
| 283 | final float rowLeft = centerScreen - halfRow; |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 284 | |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 285 | return rowLeft; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * @return Space between bubbles in row above expanded view. |
| 290 | */ |
| 291 | private float getSpaceBetweenBubbles() { |
Lyn Han | 1b4f25e | 2019-06-11 13:56:34 -0700 | [diff] [blame] | 292 | final float rowMargins = (mExpandedViewPadding + mLauncherGridDiff) * 2; |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 293 | final float maxRowWidth = mDisplayWidth - rowMargins; |
| 294 | |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 295 | final float totalBubbleWidth = mMaxBubbles * mBubbleSize; |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 296 | final float totalGapWidth = maxRowWidth - totalBubbleWidth; |
| 297 | |
Joshua Tsuji | 61b38f5 | 2019-05-31 16:20:22 -0400 | [diff] [blame] | 298 | final int gapCount = mMaxBubbles - 1; |
Lyn Han | 5390ce3 | 2019-05-31 07:25:50 -0700 | [diff] [blame] | 299 | final float gapWidth = totalGapWidth / gapCount; |
| 300 | return gapWidth; |
Lyn Han | 522e9ff | 2019-05-17 13:26:13 -0700 | [diff] [blame] | 301 | } |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 302 | } |