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

Commit 16cd6145 authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Unhide getTextRunCursor APIs"

parents e854a65a fa95b83d
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -14022,6 +14022,8 @@ package android.graphics {
    method public void getTextPath(char[], int, int, float, float, android.graphics.Path);
    method public void getTextPath(char[], int, int, float, float, android.graphics.Path);
    method public void getTextPath(java.lang.String, int, int, float, float, android.graphics.Path);
    method public void getTextPath(java.lang.String, int, int, float, float, android.graphics.Path);
    method public float getTextRunAdvances(char[], int, int, int, int, boolean, float[], int);
    method public float getTextRunAdvances(char[], int, int, int, int, boolean, float[], int);
    method public int getTextRunCursor(char[], int, int, boolean, int, int);
    method public int getTextRunCursor(java.lang.CharSequence, int, int, boolean, int, int);
    method public float getTextScaleX();
    method public float getTextScaleX();
    method public float getTextSize();
    method public float getTextSize();
    method public float getTextSkewX();
    method public float getTextSkewX();
@@ -14088,6 +14090,11 @@ package android.graphics {
    method public void setWordSpacing(float);
    method public void setWordSpacing(float);
    method public android.graphics.Xfermode setXfermode(android.graphics.Xfermode);
    method public android.graphics.Xfermode setXfermode(android.graphics.Xfermode);
    field public static final int ANTI_ALIAS_FLAG = 1; // 0x1
    field public static final int ANTI_ALIAS_FLAG = 1; // 0x1
    field public static final int CURSOR_AFTER = 0; // 0x0
    field public static final int CURSOR_AT = 4; // 0x4
    field public static final int CURSOR_AT_OR_AFTER = 1; // 0x1
    field public static final int CURSOR_AT_OR_BEFORE = 3; // 0x3
    field public static final int CURSOR_BEFORE = 2; // 0x2
    field public static final int DEV_KERN_TEXT_FLAG = 256; // 0x100
    field public static final int DEV_KERN_TEXT_FLAG = 256; // 0x100
    field public static final int DITHER_FLAG = 4; // 0x4
    field public static final int DITHER_FLAG = 4; // 0x4
    field public static final int EMBEDDED_BITMAP_TEXT_FLAG = 1024; // 0x400
    field public static final int EMBEDDED_BITMAP_TEXT_FLAG = 1024; // 0x400
+1 −1
Original line number Original line Diff line number Diff line
@@ -58,6 +58,6 @@ public interface GraphicsOperations extends CharSequence {
    /**
    /**
     * Just like {@link Paint#getTextRunCursor}.
     * Just like {@link Paint#getTextRunCursor}.
     */
     */
    int getTextRunCursor(int contextStart, int contextEnd, int dir, int offset,
    int getTextRunCursor(int contextStart, int contextEnd, boolean isRtl, int offset,
            int cursorOpt, Paint p);
            int cursorOpt, Paint p);
}
}
+11 −4
Original line number Original line Diff line number Diff line
@@ -1551,7 +1551,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
     *
     *
     * @param contextStart the start index of the context
     * @param contextStart the start index of the context
     * @param contextEnd the (non-inclusive) end index of the context
     * @param contextEnd the (non-inclusive) end index of the context
     * @param dir either DIRECTION_RTL or DIRECTION_LTR
     * @param dir 1 if the run is RTL, otherwise 0
     * @param offset the cursor position to move from
     * @param offset the cursor position to move from
     * @param cursorOpt how to move the cursor, one of CURSOR_AFTER,
     * @param cursorOpt how to move the cursor, one of CURSOR_AFTER,
     * CURSOR_AT_OR_AFTER, CURSOR_BEFORE,
     * CURSOR_AT_OR_AFTER, CURSOR_BEFORE,
@@ -1563,21 +1563,28 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
    @Deprecated
    @Deprecated
    public int getTextRunCursor(int contextStart, int contextEnd, int dir, int offset,
    public int getTextRunCursor(int contextStart, int contextEnd, int dir, int offset,
            int cursorOpt, Paint p) {
            int cursorOpt, Paint p) {
        return getTextRunCursor(contextStart, contextEnd, dir == 1, offset, cursorOpt, p);
    }

    /** @hide */
    @Override
    public int getTextRunCursor(int contextStart, int contextEnd, boolean isRtl, int offset,
            int cursorOpt, Paint p) {


        int ret;
        int ret;


        int contextLen = contextEnd - contextStart;
        int contextLen = contextEnd - contextStart;
        if (contextEnd <= mGapStart) {
        if (contextEnd <= mGapStart) {
            ret = p.getTextRunCursor(mText, contextStart, contextLen,
            ret = p.getTextRunCursor(mText, contextStart, contextLen,
                    dir, offset, cursorOpt);
                    isRtl, offset, cursorOpt);
        } else if (contextStart >= mGapStart) {
        } else if (contextStart >= mGapStart) {
            ret = p.getTextRunCursor(mText, contextStart + mGapLength, contextLen,
            ret = p.getTextRunCursor(mText, contextStart + mGapLength, contextLen,
                    dir, offset + mGapLength, cursorOpt) - mGapLength;
                    isRtl, offset + mGapLength, cursorOpt) - mGapLength;
        } else {
        } else {
            char[] buf = TextUtils.obtain(contextLen);
            char[] buf = TextUtils.obtain(contextLen);
            getChars(contextStart, contextEnd, buf, 0);
            getChars(contextStart, contextEnd, buf, 0);
            ret = p.getTextRunCursor(buf, 0, contextLen,
            ret = p.getTextRunCursor(buf, 0, contextLen,
                    dir, offset - contextStart, cursorOpt) + contextStart;
                    isRtl, offset - contextStart, cursorOpt) + contextStart;
            TextUtils.recycle(buf);
            TextUtils.recycle(buf);
        }
        }


+2 −3
Original line number Original line Diff line number Diff line
@@ -802,14 +802,13 @@ public class TextLine {
            }
            }
        }
        }


        int dir = runIsRtl ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR;
        int cursorOpt = after ? Paint.CURSOR_AFTER : Paint.CURSOR_BEFORE;
        int cursorOpt = after ? Paint.CURSOR_AFTER : Paint.CURSOR_BEFORE;
        if (mCharsValid) {
        if (mCharsValid) {
            return wp.getTextRunCursor(mChars, spanStart, spanLimit - spanStart,
            return wp.getTextRunCursor(mChars, spanStart, spanLimit - spanStart,
                    dir, offset, cursorOpt);
                    runIsRtl, offset, cursorOpt);
        } else {
        } else {
            return wp.getTextRunCursor(mText, mStart + spanStart,
            return wp.getTextRunCursor(mText, mStart + spanStart,
                    mStart + spanLimit, dir, mStart + offset, cursorOpt) - mStart;
                    mStart + spanLimit, runIsRtl, mStart + offset, cursorOpt) - mStart;
        }
        }
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -310,7 +310,7 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
            return len;
            return len;
        }
        }


        offset = paint.getTextRunCursor(text, offset, len, Paint.DIRECTION_LTR /* not used */,
        offset = paint.getTextRunCursor(text, offset, len, false /* LTR, not used */,
                offset, Paint.CURSOR_AFTER);
                offset, Paint.CURSOR_AFTER);


        return adjustReplacementSpan(text, offset, false /* move to the end */);
        return adjustReplacementSpan(text, offset, false /* move to the end */);
Loading