From 3c44a029be135cf36633c0ad4bbb3696864dca12 Mon Sep 17 00:00:00 2001 From: Ana Salazar Maldonado Date: Wed, 13 Nov 2024 10:58:45 -0800 Subject: [PATCH] Draw contrast tile around the text If the BubbletTextView should have an app contrast tile, account for some padding between the tile and the text when measuring the view, so that the text is guaranteed to be inside of the bubble. In a similar way, recalculate the bounds of the tile to only surround the app title as needed. Bug: 341217082 Flag: com.android.launcher3.enable_contrast_tiles Test: Manual, visual change Change-Id: I9e8b149ade3fa4522e62b89c2332195f648b190f --- src/com/android/launcher3/BubbleTextView.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index ef5c88aa33..817cc40abc 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -127,6 +127,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed}; + private static final int APP_PILL_TITLE_PADDING = 8; + private float mScaleForReorderBounce = 1f; private IntArray mBreakPointsIntArray; @@ -730,16 +732,21 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, Paint.FontMetrics fm = getPaint().getFontMetrics(); Rect tmpRect = new Rect(); getDrawingRect(tmpRect); + CharSequence text = getText(); - if (mIcon == null) { - appTitleBounds = new RectF(0, 0, tmpRect.right, - (int) Math.ceil(fm.bottom - fm.top)); - } else { + float titleLength = (getPaint().measureText(text, 0, text.length()) + + APP_PILL_TITLE_PADDING * 2); + titleLength = Math.min(titleLength, tmpRect.width()); + appTitleBounds = new RectF((tmpRect.width() - titleLength) / 2.f - getCompoundPaddingLeft(), + 0, (tmpRect.width() + titleLength) / 2.f + getCompoundPaddingRight(), + (int) Math.ceil(fm.bottom - fm.top)); + + + if (mIcon != null) { Rect iconBounds = new Rect(); getIconBounds(iconBounds); int textStart = iconBounds.bottom + getCompoundDrawablePadding(); - appTitleBounds = new RectF(tmpRect.left, textStart, tmpRect.right, - textStart + (int) Math.ceil(fm.bottom - fm.top)); + appTitleBounds.offset(0, textStart); } canvas.drawRoundRect(appTitleBounds, appTitleBounds.height() / 2, @@ -851,6 +858,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, setPadding(getPaddingLeft(), (height - cellHeightPx) / 2, getPaddingRight(), getPaddingBottom()); } + if (shouldDrawAppContrastTile()) { + setPadding(getPaddingLeft() + APP_PILL_TITLE_PADDING, getPaddingTop(), + getPaddingRight() + APP_PILL_TITLE_PADDING, + getPaddingBottom()); + } // Only apply two line for all_apps and device search only if necessary. if (shouldUseTwoLine() && (mLastOriginalText != null)) { int allowedVerticalSpace = height - getPaddingTop() - getPaddingBottom()