FileDocCategorySizeDatePackage
CursorAnchorInfo.javaAPI DocAndroid 5.1 API23257Thu Mar 12 22:22:10 GMT 2015android.view.inputmethod

CursorAnchorInfo

public final class CursorAnchorInfo extends Object implements android.os.Parcelable
Positional information about the text insertion point and characters in the composition string.

This class encapsulates locations of the text insertion point and the composition string in the screen coordinates so that IMEs can render their UI components near where the text is actually inserted.

Fields Summary
private final int
mSelectionStart
The index of the first character of the selected text (inclusive). {@code -1} when there is no text selection.
private final int
mSelectionEnd
The index of the first character of the selected text (exclusive). {@code -1} when there is no text selection.
private final int
mComposingTextStart
The index of the first character of the composing text (inclusive). {@code -1} when there is no composing text.
private final CharSequence
mComposingText
The text, tracked as a composing region.
private final int
mInsertionMarkerFlags
Flags of the insertion marker. See {@link #FLAG_HAS_VISIBLE_REGION} for example.
private final float
mInsertionMarkerHorizontal
Horizontal position of the insertion marker, in the local coordinates that will be transformed with the transformation matrix when rendered on the screen. This should be calculated or compatible with {@link Layout#getPrimaryHorizontal(int)}. This can be {@code java.lang.Float.NaN} when no value is specified.
private final float
mInsertionMarkerTop
Vertical position of the insertion marker, in the local coordinates that will be transformed with the transformation matrix when rendered on the screen. This should be calculated or compatible with {@link Layout#getLineTop(int)}. This can be {@code java.lang.Float.NaN} when no value is specified.
private final float
mInsertionMarkerBaseline
Vertical position of the insertion marker, in the local coordinates that will be transformed with the transformation matrix when rendered on the screen. This should be calculated or compatible with {@link Layout#getLineBaseline(int)}. This can be {@code java.lang.Float.NaN} when no value is specified.
private final float
mInsertionMarkerBottom
Vertical position of the insertion marker, in the local coordinates that will be transformed with the transformation matrix when rendered on the screen. This should be calculated or compatible with {@link Layout#getLineBottom(int)}. This can be {@code java.lang.Float.NaN} when no value is specified.
private final SparseRectFArray
mCharacterBoundsArray
Container of rectangular position of characters, keyed with character index in a unit of Java chars, in the local coordinates that will be transformed with the transformation matrix when rendered on the screen.
private final android.graphics.Matrix
mMatrix
Transformation matrix that is applied to any positional information of this class to transform local coordinates into screen coordinates.
public static final int
FLAG_HAS_VISIBLE_REGION
Flag for {@link #getInsertionMarkerFlags()} and {@link #getCharacterBoundsFlags(int)}: the insertion marker or character bounds have at least one visible region.
public static final int
FLAG_HAS_INVISIBLE_REGION
Flag for {@link #getInsertionMarkerFlags()} and {@link #getCharacterBoundsFlags(int)}: the insertion marker or character bounds have at least one invisible (clipped) region.
public static final int
FLAG_IS_RTL
Flag for {@link #getInsertionMarkerFlags()} and {@link #getCharacterBoundsFlags(int)}: the insertion marker or character bounds is placed at right-to-left (RTL) character.
public static final Parcelable.Creator
CREATOR
Used to make this class parcelable.
Constructors Summary
public CursorAnchorInfo(android.os.Parcel source)


        
        mSelectionStart = source.readInt();
        mSelectionEnd = source.readInt();
        mComposingTextStart = source.readInt();
        mComposingText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
        mInsertionMarkerFlags = source.readInt();
        mInsertionMarkerHorizontal = source.readFloat();
        mInsertionMarkerTop = source.readFloat();
        mInsertionMarkerBaseline = source.readFloat();
        mInsertionMarkerBottom = source.readFloat();
        mCharacterBoundsArray = source.readParcelable(SparseRectFArray.class.getClassLoader());
        mMatrix = new Matrix();
        mMatrix.setValues(source.createFloatArray());
    
private CursorAnchorInfo(Builder builder)

        mSelectionStart = builder.mSelectionStart;
        mSelectionEnd = builder.mSelectionEnd;
        mComposingTextStart = builder.mComposingTextStart;
        mComposingText = builder.mComposingText;
        mInsertionMarkerFlags = builder.mInsertionMarkerFlags;
        mInsertionMarkerHorizontal = builder.mInsertionMarkerHorizontal;
        mInsertionMarkerTop = builder.mInsertionMarkerTop;
        mInsertionMarkerBaseline = builder.mInsertionMarkerBaseline;
        mInsertionMarkerBottom = builder.mInsertionMarkerBottom;
        mCharacterBoundsArray = builder.mCharacterBoundsArrayBuilder != null ?
                builder.mCharacterBoundsArrayBuilder.build() : null;
        mMatrix = new Matrix(builder.mMatrix);
    
Methods Summary
private static booleanareSameFloatImpl(float a, float b)
Compares two float values. Returns {@code true} if {@code a} and {@code b} are {@link Float#NaN} at the same time.

        if (Float.isNaN(a) && Float.isNaN(b)) {
            return true;
        }
        return a == b;
    
public intdescribeContents()


    
       
        return 0;
    
public booleanequals(java.lang.Object obj)

        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof CursorAnchorInfo)) {
            return false;
        }
        final CursorAnchorInfo that = (CursorAnchorInfo) obj;
        if (hashCode() != that.hashCode()) {
            return false;
        }
        if (mSelectionStart != that.mSelectionStart || mSelectionEnd != that.mSelectionEnd) {
            return false;
        }
        if (mComposingTextStart != that.mComposingTextStart
                || !Objects.equals(mComposingText, that.mComposingText)) {
            return false;
        }
        if (mInsertionMarkerFlags != that.mInsertionMarkerFlags
                || !areSameFloatImpl(mInsertionMarkerHorizontal, that.mInsertionMarkerHorizontal)
                || !areSameFloatImpl(mInsertionMarkerTop, that.mInsertionMarkerTop)
                || !areSameFloatImpl(mInsertionMarkerBaseline, that.mInsertionMarkerBaseline)
                || !areSameFloatImpl(mInsertionMarkerBottom, that.mInsertionMarkerBottom)) {
            return false;
        }
        if (!Objects.equals(mCharacterBoundsArray, that.mCharacterBoundsArray)) {
            return false;
        }
        if (!Objects.equals(mMatrix, that.mMatrix)) {
            return false;
        }
        return true;
    
public android.graphics.RectFgetCharacterBounds(int index)
Returns a new instance of {@link RectF} that indicates the location of the character specified with the index.

param
index index of the character in a Java chars.
return
the character bounds in local coordinates as a new instance of {@link RectF}.

        if (mCharacterBoundsArray == null) {
            return null;
        }
        return mCharacterBoundsArray.get(index);
    
public intgetCharacterBoundsFlags(int index)
Returns the flags associated with the character bounds specified with the index.

param
index index of the character in a Java chars.
return
{@code 0} if no flag is specified.

        if (mCharacterBoundsArray == null) {
            return 0;
        }
        return mCharacterBoundsArray.getFlags(index, 0);
    
public java.lang.CharSequencegetComposingText()
Returns the entire composing text.

return
{@code null} if there is no composition.

        return mComposingText;
    
public intgetComposingTextStart()
Returns the index where the composing text starts.

return
{@code -1} if there is no composing text.

        return mComposingTextStart;
    
public floatgetInsertionMarkerBaseline()
Returns the vertical baseline position of the insertion marker, in the local coordinates that will be transformed with {@link #getMatrix()} when rendered on the screen.

return
y coordinate that is compatible with {@link Layout#getLineBaseline(int)}. {@code java.lang.Float.NaN} if not specified.

        return mInsertionMarkerBaseline;
    
public floatgetInsertionMarkerBottom()
Returns the vertical bottom position of the insertion marker, in the local coordinates that will be transformed with {@link #getMatrix()} when rendered on the screen.

return
y coordinate that is compatible with {@link Layout#getLineBottom(int)}. {@code java.lang.Float.NaN} if not specified.

        return mInsertionMarkerBottom;
    
public intgetInsertionMarkerFlags()
Returns the flag of the insertion marker.

return
the flag of the insertion marker. {@code 0} if no flag is specified.

        return mInsertionMarkerFlags;
    
public floatgetInsertionMarkerHorizontal()
Returns the horizontal start of the insertion marker, in the local coordinates that will be transformed with {@link #getMatrix()} when rendered on the screen.

return
x coordinate that is compatible with {@link Layout#getPrimaryHorizontal(int)}. Pay special care to RTL/LTR handling. {@code java.lang.Float.NaN} if not specified.
see
Layout#getPrimaryHorizontal(int)

        return mInsertionMarkerHorizontal;
    
public floatgetInsertionMarkerTop()
Returns the vertical top position of the insertion marker, in the local coordinates that will be transformed with {@link #getMatrix()} when rendered on the screen.

return
y coordinate that is compatible with {@link Layout#getLineTop(int)}. {@code java.lang.Float.NaN} if not specified.

        return mInsertionMarkerTop;
    
public android.graphics.MatrixgetMatrix()
Returns a new instance of {@link android.graphics.Matrix} that indicates the transformation matrix that is to be applied other positional data in this class.

return
a new instance (copy) of the transformation matrix.

        return new Matrix(mMatrix);
    
public intgetSelectionEnd()
Returns the index where the selection ends.

return
{@code -1} if there is no selection.

        return mSelectionEnd;
    
public intgetSelectionStart()
Returns the index where the selection starts.

return
{@code -1} if there is no selection.

        return mSelectionStart;
    
public inthashCode()

        final float floatHash = mInsertionMarkerHorizontal + mInsertionMarkerTop
                + mInsertionMarkerBaseline + mInsertionMarkerBottom;
        int hash = floatHash > 0 ? (int) floatHash : (int)(-floatHash);
        hash *= 31;
        hash += mInsertionMarkerFlags;
        hash *= 31;
        hash += mSelectionStart + mSelectionEnd + mComposingTextStart;
        hash *= 31;
        hash += Objects.hashCode(mComposingText);
        hash *= 31;
        hash += Objects.hashCode(mCharacterBoundsArray);
        hash *= 31;
        hash += Objects.hashCode(mMatrix);
        return hash;
    
public java.lang.StringtoString()

        return "SelectionInfo{mSelection=" + mSelectionStart + "," + mSelectionEnd
                + " mComposingTextStart=" + mComposingTextStart
                + " mComposingText=" + Objects.toString(mComposingText)
                + " mInsertionMarkerFlags=" + mInsertionMarkerFlags
                + " mInsertionMarkerHorizontal=" + mInsertionMarkerHorizontal
                + " mInsertionMarkerTop=" + mInsertionMarkerTop
                + " mInsertionMarkerBaseline=" + mInsertionMarkerBaseline
                + " mInsertionMarkerBottom=" + mInsertionMarkerBottom
                + " mCharacterBoundsArray=" + Objects.toString(mCharacterBoundsArray)
                + " mMatrix=" + Objects.toString(mMatrix)
                + "}";
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Used to package this object into a {@link Parcel}.

param
dest The {@link Parcel} to be written.
param
flags The flags used for parceling.

        dest.writeInt(mSelectionStart);
        dest.writeInt(mSelectionEnd);
        dest.writeInt(mComposingTextStart);
        TextUtils.writeToParcel(mComposingText, dest, flags);
        dest.writeInt(mInsertionMarkerFlags);
        dest.writeFloat(mInsertionMarkerHorizontal);
        dest.writeFloat(mInsertionMarkerTop);
        dest.writeFloat(mInsertionMarkerBaseline);
        dest.writeFloat(mInsertionMarkerBottom);
        dest.writeParcelable(mCharacterBoundsArray, flags);
        final float[] matrixArray = new float[9];
        mMatrix.getValues(matrixArray);
        dest.writeFloatArray(matrixArray);