| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.textservice; |
| 18 |
|
| 19 |
import android.os.Parcel; |
| 20 |
import android.os.Parcelable; |
| 21 |
|
| 22 |
import java.util.Arrays; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public final class SentenceSuggestionsInfo implements Parcelable { |
| 34 |
|
| 35 |
private final SuggestionsInfo[] mSuggestionsInfos; |
| 36 |
private final int[] mOffsets; |
| 37 |
private final int[] mLengths; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public SentenceSuggestionsInfo( |
| 46 |
SuggestionsInfo[] suggestionsInfos, int[] offsets, int[] lengths) { |
| 47 |
if (suggestionsInfos == null || offsets == null || lengths == null) { |
| 48 |
throw new NullPointerException(); |
| 49 |
} |
| 50 |
if (suggestionsInfos.length != offsets.length || offsets.length != lengths.length) { |
| 51 |
throw new IllegalArgumentException(); |
| 52 |
} |
| 53 |
final int infoSize = suggestionsInfos.length; |
| 54 |
mSuggestionsInfos = Arrays.copyOf(suggestionsInfos, infoSize); |
| 55 |
mOffsets = Arrays.copyOf(offsets, infoSize); |
| 56 |
mLengths = Arrays.copyOf(lengths, infoSize); |
| 57 |
} |
| 58 |
|
| 59 |
public SentenceSuggestionsInfo(Parcel source) { |
| 60 |
final int infoSize = source.readInt(); |
| 61 |
mSuggestionsInfos = new SuggestionsInfo[infoSize]; |
| 62 |
source.readTypedArray(mSuggestionsInfos, SuggestionsInfo.CREATOR); |
| 63 |
mOffsets = new int[mSuggestionsInfos.length]; |
| 64 |
source.readIntArray(mOffsets); |
| 65 |
mLengths = new int[mSuggestionsInfos.length]; |
| 66 |
source.readIntArray(mLengths); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
@Override |
| 76 |
public void writeToParcel(Parcel dest, int flags) { |
| 77 |
final int infoSize = mSuggestionsInfos.length; |
| 78 |
dest.writeInt(infoSize); |
| 79 |
dest.writeTypedArray(mSuggestionsInfos, 0); |
| 80 |
dest.writeIntArray(mOffsets); |
| 81 |
dest.writeIntArray(mLengths); |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public int describeContents() { |
| 86 |
return 0; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public int getSuggestionsCount() { |
| 93 |
return mSuggestionsInfos.length; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public SuggestionsInfo getSuggestionsInfoAt(int i) { |
| 101 |
if (i >= 0 && i < mSuggestionsInfos.length) { |
| 102 |
return mSuggestionsInfos[i]; |
| 103 |
} |
| 104 |
return null; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public int getOffsetAt(int i) { |
| 112 |
if (i >= 0 && i < mOffsets.length) { |
| 113 |
return mOffsets[i]; |
| 114 |
} |
| 115 |
return -1; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public int getLengthAt(int i) { |
| 123 |
if (i >= 0 && i < mLengths.length) { |
| 124 |
return mLengths[i]; |
| 125 |
} |
| 126 |
return -1; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public static final @android.annotation.NonNull Parcelable.Creator<SentenceSuggestionsInfo> CREATOR |
| 133 |
= new Parcelable.Creator<SentenceSuggestionsInfo>() { |
| 134 |
@Override |
| 135 |
public SentenceSuggestionsInfo createFromParcel(Parcel source) { |
| 136 |
return new SentenceSuggestionsInfo(source); |
| 137 |
} |
| 138 |
|
| 139 |
@Override |
| 140 |
public SentenceSuggestionsInfo[] newArray(int size) { |
| 141 |
return new SentenceSuggestionsInfo[size]; |
| 142 |
} |
| 143 |
}; |
| 144 |
} |