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

Commit bf8b0837 authored by Tyler Freeman's avatar Tyler Freeman Committed by Automerger Merge Worker
Browse files

Merge "fix(non linear font scaling): add a setLineHeight() that accepts...

Merge "fix(non linear font scaling): add a setLineHeight() that accepts explicit units." into udc-dev am: 1c42936d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22211042



Change-Id: Iae40ab3b505f3794e9925adb254ccb8317941df2
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 983a6814 1c42936d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -60415,6 +60415,7 @@ package android.widget {
    method public void setLineBreakStyle(int);
    method public void setLineBreakWordStyle(int);
    method public void setLineHeight(@IntRange(from=0) @Px int);
    method public void setLineHeight(int, @FloatRange(from=0) float);
    method public void setLineSpacing(float, float);
    method public void setLines(int);
    method public final void setLinkTextColor(@ColorInt int);
+33 −3
Original line number Diff line number Diff line
@@ -4604,7 +4604,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }
    private void setTextSizeInternal(int unit, float size, boolean shouldRequestLayout) {
    @NonNull
    private DisplayMetrics getDisplayMetricsOrSystem() {
        Context c = getContext();
        Resources r;
@@ -4614,8 +4615,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            r = c.getResources();
        }
        return r.getDisplayMetrics();
    }
    private void setTextSizeInternal(int unit, float size, boolean shouldRequestLayout) {
        mTextSizeUnit = unit;
        setRawTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()),
        setRawTextSize(TypedValue.applyDimension(unit, size, getDisplayMetricsOrSystem()),
                shouldRequestLayout);
    }
@@ -6197,16 +6202,41 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
    @android.view.RemotableViewMethod
    public void setLineHeight(@Px @IntRange(from = 0) int lineHeight) {
        Preconditions.checkArgumentNonnegative(lineHeight);
        setLineHeightPx(lineHeight);
    }
    private void setLineHeightPx(@Px @FloatRange(from = 0) float lineHeight) {
        Preconditions.checkArgumentNonnegative((int) lineHeight);
        final int fontHeight = getPaint().getFontMetricsInt(null);
        // Make sure we don't setLineSpacing if it's not needed to avoid unnecessary redraw.
        // TODO(b/274974975): should this also check if lineSpacing needs to change?
        if (lineHeight != fontHeight) {
            // Set lineSpacingExtra by the difference of lineSpacing with lineHeight
            setLineSpacing(lineHeight - fontHeight, 1f);
        }
    }
    /**
     * Sets an explicit line height to a given unit and value for this TextView. This is equivalent
     * to the vertical distance between subsequent baselines in the TextView. See {@link
     * TypedValue} for the possible dimension units.
     *
     * @param unit The desired dimension unit. SP units are strongly recommended so that line height
     *             stays proportional to the text size when fonts are scaled up for accessibility.
     * @param lineHeight The desired line height in the given units.
     *
     * @see #setLineSpacing(float, float)
     * @see #getLineSpacingExtra()
     *
     * @attr ref android.R.styleable#TextView_lineHeight
     */
    @android.view.RemotableViewMethod
    public void setLineHeight(int unit, @FloatRange(from = 0) float lineHeight) {
        setLineHeightPx(
                TypedValue.applyDimension(unit, lineHeight, getDisplayMetricsOrSystem()));
    }
    /**
     * Set Highlights
     *