| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.bubbles; |
| 18 |
|
| 19 |
import static android.view.View.LAYOUT_DIRECTION_RTL; |
| 20 |
|
| 21 |
import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 22 |
|
| 23 |
import android.annotation.IntDef; |
| 24 |
import android.content.Context; |
| 25 |
import android.content.res.Configuration; |
| 26 |
import android.content.res.Resources; |
| 27 |
import android.graphics.Insets; |
| 28 |
import android.graphics.PointF; |
| 29 |
import android.graphics.Rect; |
| 30 |
import android.graphics.RectF; |
| 31 |
import android.util.Log; |
| 32 |
import android.view.Surface; |
| 33 |
import android.view.WindowInsets; |
| 34 |
import android.view.WindowManager; |
| 35 |
import android.view.WindowMetrics; |
| 36 |
|
| 37 |
import androidx.annotation.VisibleForTesting; |
| 38 |
|
| 39 |
import com.android.launcher3.icons.IconNormalizer; |
| 40 |
import com.android.wm.shell.R; |
| 41 |
|
| 42 |
import java.lang.annotation.Retention; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public class BubblePositioner { |
| 49 |
private static final String TAG = BubbleDebugConfig.TAG_WITH_CLASS_NAME |
| 50 |
? "BubblePositioner" |
| 51 |
: BubbleDebugConfig.TAG_BUBBLES; |
| 52 |
|
| 53 |
@Retention(SOURCE) |
| 54 |
@IntDef({TASKBAR_POSITION_NONE, TASKBAR_POSITION_RIGHT, TASKBAR_POSITION_LEFT, |
| 55 |
TASKBAR_POSITION_BOTTOM}) |
| 56 |
@interface TaskbarPosition {} |
| 57 |
public static final int TASKBAR_POSITION_NONE = -1; |
| 58 |
public static final int TASKBAR_POSITION_RIGHT = 0; |
| 59 |
public static final int TASKBAR_POSITION_LEFT = 1; |
| 60 |
public static final int TASKBAR_POSITION_BOTTOM = 2; |
| 61 |
|
| 62 |
|
| 63 |
public static final int NUM_VISIBLE_WHEN_RESTING = 2; |
| 64 |
|
| 65 |
public static final int MAX_HEIGHT = -1; |
| 66 |
|
| 67 |
public static final float FLYOUT_MAX_WIDTH_PERCENT_LARGE_SCREEN = 0.3f; |
| 68 |
|
| 69 |
public static final float FLYOUT_MAX_WIDTH_PERCENT = 0.6f; |
| 70 |
|
| 71 |
private static final float EXPANDED_VIEW_LARGE_SCREEN_LANDSCAPE_WIDTH_PERCENT = 0.48f; |
| 72 |
|
| 73 |
private static final float EXPANDED_VIEW_LARGE_SCREEN_PORTRAIT_WIDTH_PERCENT = 0.70f; |
| 74 |
|
| 75 |
private static final float EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT = 0.72f; |
| 76 |
|
| 77 |
private Context mContext; |
| 78 |
private WindowManager mWindowManager; |
| 79 |
private Rect mScreenRect; |
| 80 |
private @Surface.Rotation int mRotation = Surface.ROTATION_0; |
| 81 |
private Insets mInsets; |
| 82 |
private boolean mImeVisible; |
| 83 |
private int mImeHeight; |
| 84 |
private boolean mIsLargeScreen; |
| 85 |
private boolean mIsSmallTablet; |
| 86 |
|
| 87 |
private Rect mPositionRect; |
| 88 |
private int mDefaultMaxBubbles; |
| 89 |
private int mMaxBubbles; |
| 90 |
private int mBubbleSize; |
| 91 |
private int mSpacingBetweenBubbles; |
| 92 |
private int mBubblePaddingTop; |
| 93 |
private int mBubbleOffscreenAmount; |
| 94 |
private int mStackOffset; |
| 95 |
|
| 96 |
private int mExpandedViewMinHeight; |
| 97 |
private int mExpandedViewLargeScreenWidth; |
| 98 |
private int mExpandedViewLargeScreenInsetClosestEdge; |
| 99 |
private int mExpandedViewLargeScreenInsetFurthestEdge; |
| 100 |
|
| 101 |
private int mOverflowWidth; |
| 102 |
private int mExpandedViewPadding; |
| 103 |
private int mPointerMargin; |
| 104 |
private int mPointerWidth; |
| 105 |
private int mPointerHeight; |
| 106 |
private int mPointerOverlap; |
| 107 |
private int mManageButtonHeight; |
| 108 |
private int mOverflowHeight; |
| 109 |
private int mMinimumFlyoutWidthLargeScreen; |
| 110 |
|
| 111 |
private PointF mPinLocation; |
| 112 |
private PointF mRestingStackPosition; |
| 113 |
private int[] mPaddings = new int[4]; |
| 114 |
|
| 115 |
private boolean mShowingInTaskbar; |
| 116 |
private @TaskbarPosition int mTaskbarPosition = TASKBAR_POSITION_NONE; |
| 117 |
private int mTaskbarIconSize; |
| 118 |
private int mTaskbarSize; |
| 119 |
|
| 120 |
public BubblePositioner(Context context, WindowManager windowManager) { |
| 121 |
mContext = context; |
| 122 |
mWindowManager = windowManager; |
| 123 |
update(); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public void update() { |
| 131 |
WindowMetrics windowMetrics = mWindowManager.getCurrentWindowMetrics(); |
| 132 |
if (windowMetrics == null) { |
| 133 |
return; |
| 134 |
} |
| 135 |
WindowInsets metricInsets = windowMetrics.getWindowInsets(); |
| 136 |
Insets insets = metricInsets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars() |
| 137 |
| WindowInsets.Type.statusBars() |
| 138 |
| WindowInsets.Type.displayCutout()); |
| 139 |
|
| 140 |
final Rect bounds = windowMetrics.getBounds(); |
| 141 |
Configuration config = mContext.getResources().getConfiguration(); |
| 142 |
mIsLargeScreen = config.smallestScreenWidthDp >= 600; |
| 143 |
if (mIsLargeScreen) { |
| 144 |
float largestEdgeDp = Math.max(config.screenWidthDp, config.screenHeightDp); |
| 145 |
mIsSmallTablet = largestEdgeDp < 960; |
| 146 |
} else { |
| 147 |
mIsSmallTablet = false; |
| 148 |
} |
| 149 |
|
| 150 |
if (BubbleDebugConfig.DEBUG_POSITIONER) { |
| 151 |
Log.w(TAG, "update positioner:" |
| 152 |
+ " rotation: " + mRotation |
| 153 |
+ " insets: " + insets |
| 154 |
+ " isLargeScreen: " + mIsLargeScreen |
| 155 |
+ " isSmallTablet: " + mIsSmallTablet |
| 156 |
+ " bounds: " + bounds |
| 157 |
+ " showingInTaskbar: " + mShowingInTaskbar); |
| 158 |
} |
| 159 |
updateInternal(mRotation, insets, bounds); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
public void updateForTaskbar(int iconSize, |
| 169 |
@TaskbarPosition int taskbarPosition, boolean showingInTaskbar, int taskbarSize) { |
| 170 |
mShowingInTaskbar = showingInTaskbar; |
| 171 |
mTaskbarIconSize = iconSize; |
| 172 |
mTaskbarPosition = taskbarPosition; |
| 173 |
mTaskbarSize = taskbarSize; |
| 174 |
update(); |
| 175 |
} |
| 176 |
|
| 177 |
@VisibleForTesting |
| 178 |
public void updateInternal(int rotation, Insets insets, Rect bounds) { |
| 179 |
mRotation = rotation; |
| 180 |
mInsets = insets; |
| 181 |
|
| 182 |
mScreenRect = new Rect(bounds); |
| 183 |
mPositionRect = new Rect(bounds); |
| 184 |
mPositionRect.left += mInsets.left; |
| 185 |
mPositionRect.top += mInsets.top; |
| 186 |
mPositionRect.right -= mInsets.right; |
| 187 |
mPositionRect.bottom -= mInsets.bottom; |
| 188 |
|
| 189 |
Resources res = mContext.getResources(); |
| 190 |
mBubbleSize = res.getDimensionPixelSize(R.dimen.bubble_size); |
| 191 |
mSpacingBetweenBubbles = res.getDimensionPixelSize(R.dimen.bubble_spacing); |
| 192 |
mDefaultMaxBubbles = res.getInteger(R.integer.bubbles_max_rendered); |
| 193 |
mExpandedViewPadding = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding); |
| 194 |
mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top); |
| 195 |
mBubbleOffscreenAmount = res.getDimensionPixelSize(R.dimen.bubble_stack_offscreen); |
| 196 |
mStackOffset = res.getDimensionPixelSize(R.dimen.bubble_stack_offset); |
| 197 |
|
| 198 |
if (mIsSmallTablet) { |
| 199 |
mExpandedViewLargeScreenWidth = (int) (bounds.width() |
| 200 |
* EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT); |
| 201 |
} else { |
| 202 |
mExpandedViewLargeScreenWidth = isLandscape() |
| 203 |
? (int) (bounds.width() * EXPANDED_VIEW_LARGE_SCREEN_LANDSCAPE_WIDTH_PERCENT) |
| 204 |
: (int) (bounds.width() * EXPANDED_VIEW_LARGE_SCREEN_PORTRAIT_WIDTH_PERCENT); |
| 205 |
} |
| 206 |
if (mIsLargeScreen) { |
| 207 |
if (isLandscape() && !mIsSmallTablet) { |
| 208 |
mExpandedViewLargeScreenInsetClosestEdge = res.getDimensionPixelSize( |
| 209 |
R.dimen.bubble_expanded_view_largescreen_landscape_padding); |
| 210 |
mExpandedViewLargeScreenInsetFurthestEdge = bounds.width() |
| 211 |
- mExpandedViewLargeScreenInsetClosestEdge |
| 212 |
- mExpandedViewLargeScreenWidth; |
| 213 |
} else { |
| 214 |
final int centeredInset = (bounds.width() - mExpandedViewLargeScreenWidth) / 2; |
| 215 |
mExpandedViewLargeScreenInsetClosestEdge = centeredInset; |
| 216 |
mExpandedViewLargeScreenInsetFurthestEdge = centeredInset; |
| 217 |
} |
| 218 |
} else { |
| 219 |
mExpandedViewLargeScreenInsetClosestEdge = mExpandedViewPadding; |
| 220 |
mExpandedViewLargeScreenInsetFurthestEdge = mExpandedViewPadding; |
| 221 |
} |
| 222 |
|
| 223 |
mOverflowWidth = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_overflow_width); |
| 224 |
mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 225 |
mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
| 226 |
mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin); |
| 227 |
mPointerOverlap = res.getDimensionPixelSize(R.dimen.bubble_pointer_overlap); |
| 228 |
mManageButtonHeight = res.getDimensionPixelSize(R.dimen.bubble_manage_button_total_height); |
| 229 |
mExpandedViewMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height); |
| 230 |
mOverflowHeight = res.getDimensionPixelSize(R.dimen.bubble_overflow_height); |
| 231 |
mMinimumFlyoutWidthLargeScreen = res.getDimensionPixelSize( |
| 232 |
R.dimen.bubbles_flyout_min_width_large_screen); |
| 233 |
|
| 234 |
mMaxBubbles = calculateMaxBubbles(); |
| 235 |
|
| 236 |
if (mShowingInTaskbar) { |
| 237 |
adjustForTaskbar(); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
private int calculateMaxBubbles() { |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
int padding = showBubblesVertically() ? 0 : (mExpandedViewPadding * 2); |
| 251 |
int availableSpace = Math.min(mPositionRect.width(), mPositionRect.height()) |
| 252 |
- padding |
| 253 |
- mBubbleSize; |
| 254 |
|
| 255 |
int howManyFit = availableSpace / (mBubbleSize + mSpacingBetweenBubbles); |
| 256 |
if (howManyFit < mDefaultMaxBubbles) { |
| 257 |
|
| 258 |
return howManyFit; |
| 259 |
} |
| 260 |
return mDefaultMaxBubbles; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
private void adjustForTaskbar() { |
| 270 |
|
| 271 |
if (mShowingInTaskbar && mTaskbarPosition != TASKBAR_POSITION_BOTTOM) { |
| 272 |
WindowInsets metricInsets = mWindowManager.getCurrentWindowMetrics().getWindowInsets(); |
| 273 |
Insets navBarInsets = metricInsets.getInsetsIgnoringVisibility( |
| 274 |
WindowInsets.Type.navigationBars()); |
| 275 |
int newInsetLeft = mInsets.left; |
| 276 |
int newInsetRight = mInsets.right; |
| 277 |
if (mTaskbarPosition == TASKBAR_POSITION_LEFT) { |
| 278 |
mPositionRect.left -= navBarInsets.left; |
| 279 |
newInsetLeft -= navBarInsets.left; |
| 280 |
} else if (mTaskbarPosition == TASKBAR_POSITION_RIGHT) { |
| 281 |
mPositionRect.right += navBarInsets.right; |
| 282 |
newInsetRight -= navBarInsets.right; |
| 283 |
} |
| 284 |
mInsets = Insets.of(newInsetLeft, mInsets.top, newInsetRight, mInsets.bottom); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public Rect getAvailableRect() { |
| 293 |
return mPositionRect; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
public Rect getScreenRect() { |
| 300 |
return mScreenRect; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
public Insets getInsets() { |
| 308 |
return mInsets; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
public boolean isLandscape() { |
| 313 |
return mContext.getResources().getConfiguration().orientation |
| 314 |
== Configuration.ORIENTATION_LANDSCAPE; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
public boolean isLargeScreen() { |
| 319 |
return mIsLargeScreen; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public boolean showBubblesVertically() { |
| 330 |
return isLandscape() || mShowingInTaskbar || mIsLargeScreen; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
public int getBubbleSize() { |
| 335 |
return (mShowingInTaskbar && mTaskbarIconSize > 0) |
| 336 |
? mTaskbarIconSize |
| 337 |
: mBubbleSize; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
public int getBubblePaddingTop() { |
| 342 |
return mBubblePaddingTop; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
public int getStackOffScreenAmount() { |
| 347 |
return mBubbleOffscreenAmount; |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
public int getStackOffset() { |
| 352 |
return mStackOffset; |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
public int getPointerSize() { |
| 357 |
return mPointerHeight - mPointerOverlap; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
public int getMaxBubbles() { |
| 362 |
return mMaxBubbles; |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
public int getImeHeight() { |
| 367 |
return mImeVisible ? mImeHeight : 0; |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
public int getImeTop() { |
| 372 |
if (mImeVisible) { |
| 373 |
return getScreenRect().bottom - getImeHeight() - getInsets().bottom; |
| 374 |
} |
| 375 |
return 0; |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
public void setImeVisible(boolean visible, int height) { |
| 380 |
mImeVisible = visible; |
| 381 |
mImeHeight = height; |
| 382 |
} |
| 383 |
|
| 384 |
private int getExpandedViewLargeScreenInsetFurthestEdge(boolean isOverflow) { |
| 385 |
if (isOverflow && mIsLargeScreen) { |
| 386 |
return mScreenRect.width() |
| 387 |
- mExpandedViewLargeScreenInsetClosestEdge |
| 388 |
- mOverflowWidth; |
| 389 |
} |
| 390 |
return mExpandedViewLargeScreenInsetFurthestEdge; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public int[] getExpandedViewContainerPadding(boolean onLeft, boolean isOverflow) { |
| 406 |
final int pointerTotalHeight = getPointerSize(); |
| 407 |
final int expandedViewLargeScreenInsetFurthestEdge = |
| 408 |
getExpandedViewLargeScreenInsetFurthestEdge(isOverflow); |
| 409 |
if (mIsLargeScreen) { |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
mPaddings[0] = onLeft |
| 415 |
? mExpandedViewLargeScreenInsetClosestEdge - pointerTotalHeight |
| 416 |
: expandedViewLargeScreenInsetFurthestEdge; |
| 417 |
mPaddings[1] = 0; |
| 418 |
mPaddings[2] = onLeft |
| 419 |
? expandedViewLargeScreenInsetFurthestEdge |
| 420 |
: mExpandedViewLargeScreenInsetClosestEdge - pointerTotalHeight; |
| 421 |
|
| 422 |
mPaddings[3] = isOverflow ? mExpandedViewPadding : 0; |
| 423 |
return mPaddings; |
| 424 |
} else { |
| 425 |
int leftPadding = mInsets.left + mExpandedViewPadding; |
| 426 |
int rightPadding = mInsets.right + mExpandedViewPadding; |
| 427 |
final float expandedViewWidth = isOverflow |
| 428 |
? mOverflowWidth |
| 429 |
: mExpandedViewLargeScreenWidth; |
| 430 |
if (showBubblesVertically()) { |
| 431 |
if (!onLeft) { |
| 432 |
rightPadding += mBubbleSize - pointerTotalHeight; |
| 433 |
leftPadding += isOverflow |
| 434 |
? (mPositionRect.width() - rightPadding - expandedViewWidth) |
| 435 |
: 0; |
| 436 |
} else { |
| 437 |
leftPadding += mBubbleSize - pointerTotalHeight; |
| 438 |
rightPadding += isOverflow |
| 439 |
? (mPositionRect.width() - leftPadding - expandedViewWidth) |
| 440 |
: 0; |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
mPaddings[0] = leftPadding; |
| 445 |
mPaddings[1] = showBubblesVertically() ? 0 : mPointerMargin; |
| 446 |
mPaddings[2] = rightPadding; |
| 447 |
mPaddings[3] = 0; |
| 448 |
return mPaddings; |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
public float getExpandedViewYTopAligned() { |
| 454 |
final int top = getAvailableRect().top; |
| 455 |
if (showBubblesVertically()) { |
| 456 |
return top - mPointerWidth + mExpandedViewPadding; |
| 457 |
} else { |
| 458 |
return top + mBubbleSize + mPointerMargin; |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
public int getMaxExpandedViewHeight(boolean isOverflow) { |
| 467 |
|
| 468 |
int expandedContainerY = (int) getExpandedViewYTopAligned() - getInsets().top; |
| 469 |
int paddingTop = showBubblesVertically() |
| 470 |
? 0 |
| 471 |
: mPointerHeight; |
| 472 |
|
| 473 |
int pointerSize = showBubblesVertically() |
| 474 |
? mPointerWidth |
| 475 |
: (mPointerHeight + mPointerMargin); |
| 476 |
int bottomPadding = isOverflow ? mExpandedViewPadding : mManageButtonHeight; |
| 477 |
return getAvailableRect().height() |
| 478 |
- expandedContainerY |
| 479 |
- paddingTop |
| 480 |
- pointerSize |
| 481 |
- bottomPadding; |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
public float getExpandedViewHeight(BubbleViewProvider bubble) { |
| 489 |
boolean isOverflow = bubble == null || BubbleOverflow.KEY.equals(bubble.getKey()); |
| 490 |
if (isOverflow && showBubblesVertically() && !mIsLargeScreen) { |
| 491 |
|
| 492 |
return MAX_HEIGHT; |
| 493 |
} |
| 494 |
float desiredHeight = isOverflow |
| 495 |
? mOverflowHeight |
| 496 |
: ((Bubble) bubble).getDesiredHeight(mContext); |
| 497 |
desiredHeight = Math.max(desiredHeight, mExpandedViewMinHeight); |
| 498 |
if (desiredHeight > getMaxExpandedViewHeight(isOverflow)) { |
| 499 |
return MAX_HEIGHT; |
| 500 |
} |
| 501 |
return desiredHeight; |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
public float getExpandedViewY(BubbleViewProvider bubble, float bubblePosition) { |
| 514 |
boolean isOverflow = bubble == null || BubbleOverflow.KEY.equals(bubble.getKey()); |
| 515 |
float expandedViewHeight = getExpandedViewHeight(bubble); |
| 516 |
float topAlignment = getExpandedViewYTopAligned(); |
| 517 |
if (!showBubblesVertically() || expandedViewHeight == MAX_HEIGHT) { |
| 518 |
|
| 519 |
return topAlignment; |
| 520 |
} |
| 521 |
|
| 522 |
int manageButtonHeight = isOverflow ? mExpandedViewPadding : mManageButtonHeight; |
| 523 |
float pointerPosition = getPointerPosition(bubblePosition); |
| 524 |
float bottomIfCentered = pointerPosition + (expandedViewHeight / 2) + manageButtonHeight; |
| 525 |
float topIfCentered = pointerPosition - (expandedViewHeight / 2); |
| 526 |
if (topIfCentered > mPositionRect.top && mPositionRect.bottom > bottomIfCentered) { |
| 527 |
|
| 528 |
return pointerPosition - mPointerWidth - (expandedViewHeight / 2f); |
| 529 |
} else if (topIfCentered <= mPositionRect.top) { |
| 530 |
|
| 531 |
return topAlignment; |
| 532 |
} else { |
| 533 |
|
| 534 |
return mPositionRect.bottom - manageButtonHeight - expandedViewHeight - mPointerWidth; |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
public float getPointerPosition(float bubblePosition) { |
| 547 |
|
| 548 |
|
| 549 |
final float normalizedSize = IconNormalizer.getNormalizedCircleSize( |
| 550 |
getBubbleSize()); |
| 551 |
return showBubblesVertically() |
| 552 |
? bubblePosition + (getBubbleSize() / 2f) |
| 553 |
: bubblePosition + (normalizedSize / 2f) - mPointerWidth; |
| 554 |
} |
| 555 |
|
| 556 |
private int getExpandedStackSize(int numberOfBubbles) { |
| 557 |
return (numberOfBubbles * mBubbleSize) |
| 558 |
+ ((numberOfBubbles - 1) * mSpacingBetweenBubbles); |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
public PointF getExpandedBubbleXY(int index, BubbleStackView.StackViewState state) { |
| 569 |
boolean showBubblesVertically = showBubblesVertically(); |
| 570 |
boolean isRtl = mContext.getResources().getConfiguration().getLayoutDirection() |
| 571 |
== LAYOUT_DIRECTION_RTL; |
| 572 |
|
| 573 |
int onScreenIndex; |
| 574 |
if (showBubblesVertically || !isRtl) { |
| 575 |
onScreenIndex = index; |
| 576 |
} else { |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
onScreenIndex = state.numberOfBubbles - 1 - index; |
| 581 |
} |
| 582 |
|
| 583 |
final float positionInRow = onScreenIndex * (mBubbleSize + mSpacingBetweenBubbles); |
| 584 |
final float expandedStackSize = getExpandedStackSize(state.numberOfBubbles); |
| 585 |
final float centerPosition = showBubblesVertically |
| 586 |
? mPositionRect.centerY() |
| 587 |
: mPositionRect.centerX(); |
| 588 |
|
| 589 |
final float rowStart = centerPosition - (expandedStackSize / 2f); |
| 590 |
float x; |
| 591 |
float y; |
| 592 |
if (showBubblesVertically) { |
| 593 |
int inset = mExpandedViewLargeScreenInsetClosestEdge; |
| 594 |
y = rowStart + positionInRow; |
| 595 |
int left = mIsLargeScreen |
| 596 |
? inset - mExpandedViewPadding - mBubbleSize |
| 597 |
: mPositionRect.left; |
| 598 |
int right = mIsLargeScreen |
| 599 |
? mPositionRect.right - inset + mExpandedViewPadding |
| 600 |
: mPositionRect.right - mBubbleSize; |
| 601 |
x = state.onLeft |
| 602 |
? left |
| 603 |
: right; |
| 604 |
} else { |
| 605 |
y = mPositionRect.top + mExpandedViewPadding; |
| 606 |
x = rowStart + positionInRow; |
| 607 |
} |
| 608 |
|
| 609 |
if (showBubblesVertically && mImeVisible) { |
| 610 |
return new PointF(x, getExpandedBubbleYForIme(onScreenIndex, state)); |
| 611 |
} |
| 612 |
return new PointF(x, y); |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
private float getExpandedBubbleYForIme(int index, BubbleStackView.StackViewState state) { |
| 624 |
final float top = getAvailableRect().top + mExpandedViewPadding; |
| 625 |
if (!showBubblesVertically()) { |
| 626 |
|
| 627 |
return top; |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
final float bottomHeight = getImeHeight() + mInsets.bottom + (mSpacingBetweenBubbles * 2); |
| 633 |
final float bottomInset = mScreenRect.bottom - bottomHeight; |
| 634 |
final float expandedStackSize = getExpandedStackSize(state.numberOfBubbles); |
| 635 |
final float centerPosition = mPositionRect.centerY(); |
| 636 |
final float rowBottom = centerPosition + (expandedStackSize / 2f); |
| 637 |
final float rowTop = centerPosition - (expandedStackSize / 2f); |
| 638 |
float rowTopForIme = rowTop; |
| 639 |
if (rowBottom > bottomInset) { |
| 640 |
|
| 641 |
float translationY = rowBottom - bottomInset; |
| 642 |
rowTopForIme = Math.max(rowTop - translationY, top); |
| 643 |
if (rowTop - translationY < top) { |
| 644 |
|
| 645 |
|
| 646 |
final float expandedStackSizeNoO = getExpandedStackSize(state.numberOfBubbles - 1); |
| 647 |
final float centerPositionNoO = showBubblesVertically() |
| 648 |
? mPositionRect.centerY() |
| 649 |
: mPositionRect.centerX(); |
| 650 |
final float rowBottomNoO = centerPositionNoO + (expandedStackSizeNoO / 2f); |
| 651 |
final float rowTopNoO = centerPositionNoO - (expandedStackSizeNoO / 2f); |
| 652 |
translationY = rowBottomNoO - bottomInset; |
| 653 |
rowTopForIme = rowTopNoO - translationY; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
final float selectedPosition = rowTopForIme |
| 658 |
+ (state.selectedIndex * (mBubbleSize + mSpacingBetweenBubbles)); |
| 659 |
if (selectedPosition < top) { |
| 660 |
|
| 661 |
rowTopForIme = top; |
| 662 |
} |
| 663 |
return rowTopForIme + (index * (mBubbleSize + mSpacingBetweenBubbles)); |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
public float getMaxFlyoutSize() { |
| 670 |
if (isLargeScreen()) { |
| 671 |
return Math.max(mScreenRect.width() * FLYOUT_MAX_WIDTH_PERCENT_LARGE_SCREEN, |
| 672 |
mMinimumFlyoutWidthLargeScreen); |
| 673 |
} |
| 674 |
return mScreenRect.width() * FLYOUT_MAX_WIDTH_PERCENT; |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
public boolean isStackOnLeft(PointF currentStackPosition) { |
| 681 |
if (currentStackPosition == null) { |
| 682 |
currentStackPosition = getRestingPosition(); |
| 683 |
} |
| 684 |
final int stackCenter = (int) currentStackPosition.x + mBubbleSize / 2; |
| 685 |
return stackCenter < mScreenRect.width() / 2; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
public void setRestingPosition(PointF position) { |
| 693 |
if (mRestingStackPosition == null) { |
| 694 |
mRestingStackPosition = new PointF(position); |
| 695 |
} else { |
| 696 |
mRestingStackPosition.set(position); |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
public PointF getRestingPosition() { |
| 702 |
if (mPinLocation != null) { |
| 703 |
return mPinLocation; |
| 704 |
} |
| 705 |
if (mRestingStackPosition == null) { |
| 706 |
return getDefaultStartPosition(); |
| 707 |
} |
| 708 |
return mRestingStackPosition; |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
public PointF getDefaultStartPosition() { |
| 716 |
if (mPinLocation != null) { |
| 717 |
return mPinLocation; |
| 718 |
} |
| 719 |
|
| 720 |
final boolean startOnLeft = |
| 721 |
mContext.getResources().getConfiguration().getLayoutDirection() |
| 722 |
!= LAYOUT_DIRECTION_RTL; |
| 723 |
final float startingVerticalOffset = mContext.getResources().getDimensionPixelOffset( |
| 724 |
R.dimen.bubble_stack_starting_offset_y); |
| 725 |
|
| 726 |
return new BubbleStackView.RelativeStackPosition( |
| 727 |
startOnLeft, |
| 728 |
startingVerticalOffset / mPositionRect.height()) |
| 729 |
.getAbsolutePositionInRegion(getAllowableStackPositionRegion( |
| 730 |
1 )); |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
public RectF getAllowableStackPositionRegion(int bubbleCount) { |
| 741 |
final RectF allowableRegion = new RectF(getAvailableRect()); |
| 742 |
final int imeHeight = getImeHeight(); |
| 743 |
final float bottomPadding = bubbleCount > 1 |
| 744 |
? mBubblePaddingTop + mStackOffset |
| 745 |
: mBubblePaddingTop; |
| 746 |
allowableRegion.left -= mBubbleOffscreenAmount; |
| 747 |
allowableRegion.top += mBubblePaddingTop; |
| 748 |
allowableRegion.right += mBubbleOffscreenAmount - mBubbleSize; |
| 749 |
allowableRegion.bottom -= imeHeight + bottomPadding + mBubbleSize; |
| 750 |
return allowableRegion; |
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
public boolean showingInTaskbar() { |
| 757 |
return mShowingInTaskbar; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
public int getTaskbarPosition() { |
| 764 |
return mTaskbarPosition; |
| 765 |
} |
| 766 |
|
| 767 |
public int getTaskbarSize() { |
| 768 |
return mTaskbarSize; |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
public void setUsePinnedLocation(boolean usePinnedLocation) { |
| 776 |
if (usePinnedLocation) { |
| 777 |
mShowingInTaskbar = true; |
| 778 |
mPinLocation = new PointF(mPositionRect.right - mBubbleSize, |
| 779 |
mPositionRect.bottom - mBubbleSize); |
| 780 |
} else { |
| 781 |
mPinLocation = null; |
| 782 |
mShowingInTaskbar = false; |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
public Rect getNavBarGestureZone() { |
| 792 |
|
| 793 |
int gestureZoneHeight = mContext.getResources().getDimensionPixelSize( |
| 794 |
com.android.internal.R.dimen.navigation_bar_gesture_height); |
| 795 |
Rect screen = getScreenRect(); |
| 796 |
return new Rect( |
| 797 |
screen.left, |
| 798 |
screen.bottom - gestureZoneHeight, |
| 799 |
screen.right, |
| 800 |
screen.bottom); |
| 801 |
} |
| 802 |
} |