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

Commit 08b9eefa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add Layout#getLineBottom with includeLineSpacing parameter"

parents 7282ed1f 5bfd33e8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -45194,6 +45194,7 @@ package android.text {
    method public final int getLineAscent(int);
    method public final int getLineBaseline(int);
    method public final int getLineBottom(int);
    method public int getLineBottom(int, boolean);
    method public int getLineBounds(int, android.graphics.Rect);
    method public abstract boolean getLineContainsTab(int);
    method public abstract int getLineCount();
+15 −11
Original line number Diff line number Diff line
@@ -1841,7 +1841,7 @@ public abstract class Layout {
        // Find the first line whose vertical center is below the top of the area.
        int startLine = getLineForVertical((int) area.top);
        int startLineTop = getLineTop(startLine);
        int startLineBottom = getLineBottomWithoutSpacing(startLine);
        int startLineBottom = getLineBottom(startLine, /* includeLineSpacing= */ false);
        if (area.top > (startLineTop + startLineBottom) / 2f) {
            startLine++;
            if (startLine >= getLineCount()) {
@@ -1854,7 +1854,7 @@ public abstract class Layout {
        // Find the last line whose vertical center is above the bottom of the area.
        int endLine = getLineForVertical((int) area.bottom);
        int endLineTop = getLineTop(endLine);
        int endLineBottom = getLineBottomWithoutSpacing(endLine);
        int endLineBottom = getLineBottom(endLine, /* includeLineSpacing= */ false);
        if (area.bottom < (endLineTop + endLineBottom) / 2f) {
            endLine--;
        }
@@ -2229,18 +2229,22 @@ public abstract class Layout {
     * Return the vertical position of the bottom of the specified line.
     */
    public final int getLineBottom(int line) {
        return getLineTop(line + 1);
        return getLineBottom(line, /* includeLineSpacing= */ true);
    }

    /**
     * Return the vertical position of the bottom of the specified line without the line spacing
     * added.
     * Return the vertical position of the bottom of the specified line.
     *
     * @hide
     * @param line index of the line
     * @param includeLineSpacing whether to include the line spacing
     */
    public final int getLineBottomWithoutSpacing(int line) {
    public int getLineBottom(int line, boolean includeLineSpacing) {
        if (includeLineSpacing) {
            return getLineTop(line + 1);
        } else {
            return getLineTop(line + 1) - getLineExtra(line);
        }
    }

    /**
     * Return the vertical position of the baseline of the specified line.
@@ -2394,7 +2398,7 @@ public abstract class Layout {

        int line = getLineForOffset(point);
        int top = getLineTop(line);
        int bottom = getLineBottomWithoutSpacing(line);
        int bottom = getLineBottom(line, /* includeLineSpacing= */ false);

        boolean clamped = shouldClampCursor(line);
        float h1 = getPrimaryHorizontal(point, clamped) - 0.5f;
@@ -2530,7 +2534,7 @@ public abstract class Layout {
        final int endline = getLineForOffset(end);

        int top = getLineTop(startline);
        int bottom = getLineBottomWithoutSpacing(endline);
        int bottom = getLineBottom(endline, /* includeLineSpacing= */ false);

        if (startline == endline) {
            addSelection(startline, start, end, top, bottom, consumer);
@@ -2559,7 +2563,7 @@ public abstract class Layout {
            }

            top = getLineTop(endline);
            bottom = getLineBottomWithoutSpacing(endline);
            bottom = getLineBottom(endline, /* includeLineSpacing= */ false);

            addSelection(endline, getLineStart(endline), end, top, bottom, consumer);

+18 −14
Original line number Diff line number Diff line
@@ -572,8 +572,8 @@ public class Editor {

        final Layout layout = mTextView.getLayout();
        final int line = layout.getLineForOffset(mTextView.getSelectionStart());
        final int sourceHeight =
            layout.getLineBottomWithoutSpacing(line) - layout.getLineTop(line);
        final int sourceHeight = layout.getLineBottom(line, /* includeLineSpacing= */ false)
                - layout.getLineTop(line);
        final int height = (int)(sourceHeight * zoom);
        final int width = (int)(aspectRatio * Math.max(sourceHeight, mMinLineHeightForMagnifier));

@@ -2340,7 +2340,7 @@ public class Editor {
        final int offset = mTextView.getSelectionStart();
        final int line = layout.getLineForOffset(offset);
        final int top = layout.getLineTop(line);
        final int bottom = layout.getLineBottomWithoutSpacing(line);
        final int bottom = layout.getLineBottom(line, /* includeLineSpacing= */ false);

        final boolean clamped = layout.shouldClampCursor(line);
        updateCursorPosition(top, bottom, layout.getPrimaryHorizontal(offset, clamped));
@@ -3443,7 +3443,7 @@ public class Editor {
        @Override
        protected int getVerticalLocalPosition(int line) {
            final Layout layout = mTextView.getLayout();
            return layout.getLineBottomWithoutSpacing(line);
            return layout.getLineBottom(line, /* includeLineSpacing= */ false);
        }

        @Override
@@ -4109,7 +4109,8 @@ public class Editor {
        @Override
        protected int getVerticalLocalPosition(int line) {
            final Layout layout = mTextView.getLayout();
            return layout.getLineBottomWithoutSpacing(line) - mContainerMarginTop;
            return layout.getLineBottom(line, /* includeLineSpacing= */ false)
                    - mContainerMarginTop;
        }

        @Override
@@ -4706,7 +4707,8 @@ public class Editor {
                                + viewportToContentVerticalOffset;
                        final float insertionMarkerBaseline = layout.getLineBaseline(line)
                                + viewportToContentVerticalOffset;
                        final float insertionMarkerBottom = layout.getLineBottomWithoutSpacing(line)
                        final float insertionMarkerBottom =
                                layout.getLineBottom(line, /* includeLineSpacing= */ false)
                                        + viewportToContentVerticalOffset;
                        final boolean isTopVisible = mTextView
                                .isPositionVisible(insertionMarkerX, insertionMarkerTop);
@@ -5137,7 +5139,7 @@ public class Editor {

                mPositionX = getCursorHorizontalPosition(layout, offset) - mHotspotX
                        - getHorizontalOffset() + getCursorOffset();
                mPositionY = layout.getLineBottomWithoutSpacing(line);
                mPositionY = layout.getLineBottom(line, /* includeLineSpacing= */ false);

                // Take TextView's padding and scroll into account.
                mPositionX += mTextView.viewportToContentHorizontalOffset();
@@ -5233,8 +5235,8 @@ public class Editor {
            if (mNewMagnifierEnabled) {
                Layout layout = mTextView.getLayout();
                final int line = layout.getLineForOffset(getCurrentCursorOffset());
                return layout.getLineBottomWithoutSpacing(line) - layout.getLineTop(line)
                        >= mMaxLineHeightForMagnifier;
                return layout.getLineBottom(line, /* includeLineSpacing= */ false)
                        - layout.getLineTop(line) >= mMaxLineHeightForMagnifier;
            }
            final float magnifierContentHeight = Math.round(
                    mMagnifierAnimator.mMagnifier.getHeight()
@@ -5389,7 +5391,8 @@ public class Editor {

            // Vertically snap to middle of current line.
            showPosInView.y = ((mTextView.getLayout().getLineTop(lineNumber)
                    + mTextView.getLayout().getLineBottomWithoutSpacing(lineNumber)) / 2.0f
                    + mTextView.getLayout()
                            .getLineBottom(lineNumber, /* includeLineSpacing= */ false)) / 2.0f
                    + mTextView.getTotalPaddingTop() - mTextView.getScrollY()) * mTextViewScaleY;
            return true;
        }
@@ -5473,7 +5476,8 @@ public class Editor {
                        updateCursorPosition();
                    }
                    final int lineHeight =
                            layout.getLineBottomWithoutSpacing(line) - layout.getLineTop(line);
                            layout.getLineBottom(line, /* includeLineSpacing= */ false)
                                    - layout.getLineTop(line);
                    float zoom = mInitialZoom;
                    if (lineHeight < mMinLineHeightForMagnifier) {
                        zoom = zoom * mMinLineHeightForMagnifier / lineHeight;
@@ -5823,8 +5827,8 @@ public class Editor {
        private MotionEvent transformEventForTouchThrough(MotionEvent ev) {
            final Layout layout = mTextView.getLayout();
            final int line = layout.getLineForOffset(getCurrentCursorOffset());
            final int textHeight =
                    layout.getLineBottomWithoutSpacing(line) - layout.getLineTop(line);
            final int textHeight = layout.getLineBottom(line, /* includeLineSpacing= */ false)
                    - layout.getLineTop(line);
            // Transforms the touch events to screen coordinates.
            // And also shift up to make the hit point is on the text.
            // Note:
+3 −3
Original line number Diff line number Diff line
@@ -9390,7 +9390,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        PointF point = convertFromScreenToContentCoordinates(gesture.getInsertionPoint());
        int line = mLayout.getLineForVertical((int) point.y);
        if (point.y < mLayout.getLineTop(line)
                || point.y > mLayout.getLineBottomWithoutSpacing(line)) {
                || point.y > mLayout.getLineBottom(line, /* includeLineSpacing= */ false)) {
            return handleGestureFailure(gesture);
        }
        if (point.x < mLayout.getLineLeft(line) || point.x > mLayout.getLineRight(line)) {
@@ -9418,7 +9418,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            // Both points are above the top of the first line.
            return handleGestureFailure(gesture);
        }
        if (yMin > mLayout.getLineBottomWithoutSpacing(line)) {
        if (yMin > mLayout.getLineBottom(line, /* includeLineSpacing= */ false)) {
            if (line == mLayout.getLineCount() - 1 || yMax < mLayout.getLineTop(line + 1)) {
                // The points are below the last line, or they are between two lines.
                return handleGestureFailure(gesture);
@@ -9472,7 +9472,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        int line = mLayout.getLineForVertical((int) point.y);
        if (point.y < mLayout.getLineTop(line)
                || point.y > mLayout.getLineBottomWithoutSpacing(line)) {
                || point.y > mLayout.getLineBottom(line, /* includeLineSpacing= */ false)) {
            return handleGestureFailure(gesture);
        }
        if (point.x < mLayout.getLineLeft(line) || point.x > mLayout.getLineRight(line)) {
+2 −1
Original line number Diff line number Diff line
@@ -90,7 +90,8 @@ public class LayoutGetRangeForRectTest {

        mLineCenters = new float[mLayout.getLineCount()];
        for (int i = 0; i < mLayout.getLineCount(); ++i) {
            mLineCenters[i] = (mLayout.getLineTop(i) + mLayout.getLineBottomWithoutSpacing(i)) / 2f;
            mLineCenters[i] = (mLayout.getLineTop(i)
                    + mLayout.getLineBottom(i, /* includeLineSpacing= */ false)) / 2f;
        }

        mGraphemeClusterSegmentIterator =