From 1a55cde8c3145f922a82245ce66b081532158e90 Mon Sep 17 00:00:00 2001 From: Helen Cheuk Date: Thu, 2 Mar 2023 16:45:41 +0000 Subject: [PATCH] Resize text in drop target button if the text displayed is truncated vertically MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “Don’t suggest app” text is cut off at the bottom in tablet when it is set to have largest font and display size before this fix. This change is to check if the text is displayed completely with available height. If not, decrease the text size until it does Fix: 264732627 Test: manual Change-Id: I8331a40f2cd767a7b2807c15d9772566baf9f355 --- .../android/launcher3/ButtonDropTarget.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index ee3e278b8d..376cab76d9 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -57,6 +57,8 @@ public abstract class ButtonDropTarget extends TextView public static final int TOOLTIP_LEFT = 1; public static final int TOOLTIP_RIGHT = 2; + private final Rect mTempRect = new Rect(); + protected final Launcher mLauncher; protected DropTargetBar mDropTargetBar; @@ -402,6 +404,21 @@ public abstract class ButtonDropTarget extends TextView secondLine)); } + /** + * Returns if the text will be clipped vertically within the provided availableHeight. + */ + private boolean isTextClippedVertically(int availableHeight) { + availableHeight -= getPaddingTop() + getPaddingBottom(); + if (availableHeight <= 0) { + return true; + } + + getPaint().getTextBounds(mText.toString(), 0, mText.length(), mTempRect); + // Add bounds bottom to height, as text bounds height measures from the text baseline and + // above, which characters can descend below + return mTempRect.bottom + mTempRect.height() <= availableHeight; + } + /** * Reduce the size of the text until it fits the measured width or reaches a minimum. * @@ -423,7 +440,9 @@ public abstract class ButtonDropTarget extends TextView float textSize = Utilities.pxToSp(getTextSize()); int availableWidth = getMeasuredWidth(); - while (isTextTruncated(availableWidth)) { + int availableHeight = getMeasuredHeight(); + + while (isTextTruncated(availableWidth) || isTextClippedVertically(availableHeight)) { textSize -= step; if (textSize < minSize) { textSize = minSize;