FileDocCategorySizeDatePackage
SparseRectFArray.javaAPI DocAndroid 5.1 API10965Thu Mar 12 22:22:10 GMT 2015android.view.inputmethod

SparseRectFArray

public final class SparseRectFArray extends Object implements android.os.Parcelable
An implementation of SparseArray specialized for {@link android.graphics.RectF}.

As this is a sparse array, it represents an array of {@link RectF} most of which are null. This class could be in some other packages like android.graphics or android.util but currently belong to android.view.inputmethod because this class is hidden and used only in input method framework.

hide

Fields Summary
private final int[]
mKeys
The keys, in ascending order, of those {@link RectF} that are not null. For example, {@code [null, null, null, Rect1, null, Rect2]} would be represented by {@code [3,5]}.
private final float[]
mCoordinates
Stores coordinates of the rectangles, in the order of {@code rects[mKeys[0]].left}, {@code rects[mKeys[0]].top}, {@code rects[mKeys[0]].right}, {@code rects[mKeys[0]].bottom}, {@code rects[mKeys[1]].left}, {@code rects[mKeys[1]].top}, {@code rects[mKeys[1]].right}, {@code rects[mKeys[1]].bottom}, {@code rects[mKeys[2]].left}, {@code rects[mKeys[2]].top}, ....
private final int[]
mFlagsArray
Stores visibility information.
public static final Parcelable.Creator
CREATOR
Used to make this class parcelable.
Constructors Summary
public SparseRectFArray(android.os.Parcel source)

        mKeys = source.createIntArray();
        mCoordinates = source.createFloatArray();
        mFlagsArray = source.createIntArray();
    
private SparseRectFArray(SparseRectFArrayBuilder builder)

        if (builder.mCount == 0) {
            mKeys = null;
            mCoordinates = null;
            mFlagsArray = null;
        } else {
            mKeys = new int[builder.mCount];
            mCoordinates = new float[builder.mCount * 4];
            mFlagsArray = new int[builder.mCount];
            System.arraycopy(builder.mKeys, 0, mKeys, 0, builder.mCount);
            System.arraycopy(builder.mCoordinates, 0, mCoordinates, 0, builder.mCount * 4);
            System.arraycopy(builder.mFlagsArray, 0, mFlagsArray, 0, builder.mCount);
        }
    
Methods Summary
public intdescribeContents()


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

        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof SparseRectFArray)) {
            return false;
        }
        final SparseRectFArray that = (SparseRectFArray) obj;

        return Arrays.equals(mKeys, that.mKeys) && Arrays.equals(mCoordinates, that.mCoordinates)
                && Arrays.equals(mFlagsArray, that.mFlagsArray);
    
public android.graphics.RectFget(int index)

        if (mKeys == null) {
            return null;
        }
        if (index < 0) {
            return null;
        }
        final int arrayIndex = Arrays.binarySearch(mKeys, index);
        if (arrayIndex < 0) {
            return null;
        }
        final int baseCoordIndex = arrayIndex * 4;
        return new RectF(mCoordinates[baseCoordIndex],
                mCoordinates[baseCoordIndex + 1],
                mCoordinates[baseCoordIndex + 2],
                mCoordinates[baseCoordIndex + 3]);
    
public intgetFlags(int index, int valueIfKeyNotFound)

        if (mKeys == null) {
            return valueIfKeyNotFound;
        }
        if (index < 0) {
            return valueIfKeyNotFound;
        }
        final int arrayIndex = Arrays.binarySearch(mKeys, index);
        if (arrayIndex < 0) {
            return valueIfKeyNotFound;
        }
        return mFlagsArray[arrayIndex];
    
public inthashCode()

        // TODO: Improve the hash function.
        if (mKeys == null || mKeys.length == 0) {
            return 0;
        }
        int hash = mKeys.length;
        // For performance reasons, only the first rectangle is used for the hash code now.
        for (int i = 0; i < 4; i++) {
            hash *= 31;
            hash += mCoordinates[i];
        }
        hash *= 31;
        hash += mFlagsArray[0];
        return hash;
    
public java.lang.StringtoString()

        if (mKeys == null || mCoordinates == null || mFlagsArray == null) {
            return "SparseRectFArray{}";
        }
        final StringBuilder sb = new StringBuilder();
        sb.append("SparseRectFArray{");
        for (int i = 0; i < mKeys.length; i++) {
            if (i != 0) {
                sb.append(", ");
            }
            final int baseIndex = i * 4;
            sb.append(mKeys[i]);
            sb.append(":[");
            sb.append(mCoordinates[baseIndex + 0]);
            sb.append(",");
            sb.append(mCoordinates[baseIndex + 1]);
            sb.append("],[");
            sb.append(mCoordinates[baseIndex + 2]);
            sb.append(",");
            sb.append(mCoordinates[baseIndex + 3]);
            sb.append("]:flagsArray=");
            sb.append(mFlagsArray[i]);
        }
        sb.append("}");
        return sb.toString();
    
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.writeIntArray(mKeys);
        dest.writeFloatArray(mCoordinates);
        dest.writeIntArray(mFlagsArray);