Fix text sizes and alignment in drop target
Drop target button texts are being resized incorrectly.
When both buttons are visible, the text is considerably smaller compared
to only one visible button. This happens even for the default display and font scale 1.
Fix: 271279172
Test: manual. test all combinations of display size and font size.
Test: HomeScreenEditStateImageTest
Change-Id: Ib001dcf8b096c65b138946bdad49cf8199fb5b1d
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index fc7f614..1a86009 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.res.Resources;
+import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.InputType;
@@ -58,8 +59,6 @@
public static final int TOOLTIP_LEFT = 1;
public static final int TOOLTIP_RIGHT = 2;
- private final Rect mTempRect = new Rect();
-
protected final ActivityContext mActivityContext;
protected final DropTargetHandler mDropTargetHandler;
protected DropTargetBar mDropTargetBar;
@@ -417,15 +416,11 @@
*/
@VisibleForTesting
protected boolean isTextClippedVertically(int availableHeight) {
- availableHeight -= getPaddingTop() + getPaddingBottom();
- if (availableHeight <= 0) {
- return true;
- }
+ Paint.FontMetricsInt fontMetricsInt = getPaint().getFontMetricsInt();
+ int lineCount = (getLineCount() <= 0) ? 1 : getLineCount();
+ int textHeight = lineCount * (fontMetricsInt.bottom - fontMetricsInt.top);
- 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;
+ return textHeight + getPaddingTop() + getPaddingBottom() >= availableHeight;
}
/**
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java
index bb6d8b0..addcac9 100644
--- a/src/com/android/launcher3/DropTargetBar.java
+++ b/src/com/android/launcher3/DropTargetBar.java
@@ -152,6 +152,7 @@
firstButton.setTextVisible(true);
firstButton.setIconVisible(true);
firstButton.measure(widthSpec, heightSpec);
+ firstButton.resizeTextToFit();
} else if (visibleCount == 2) {
DeviceProfile dp = mLauncher.getDeviceProfile();
int verticalPadding = dp.dropTargetVerticalPaddingPx;