Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a415a34b authored by Helen Cheuk's avatar Helen Cheuk Committed by Automerger Merge Worker
Browse files

Merge "Resize text in drop target button if the text displayed is truncated...

Merge "Resize text in drop target button if the text displayed is truncated vertically" into tm-qpr-dev am: f70036a1 am: 9a452ebb

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/21701323



Change-Id: Ic606f2a342d1242b47c435b51a188189378c48d2
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 751d1475 9a452ebb
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -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;