| 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.annotation.IntDef; |
| 20 |
import android.os.Parcel; |
| 21 |
import android.os.Parcelable; |
| 22 |
|
| 23 |
import com.android.internal.util.ArrayUtils; |
| 24 |
|
| 25 |
import java.lang.annotation.Retention; |
| 26 |
import java.lang.annotation.RetentionPolicy; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public final class SuggestionsInfo implements Parcelable { |
| 32 |
private static final String[] EMPTY = ArrayUtils.emptyArray(String.class); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
@Retention(RetentionPolicy.SOURCE) |
| 41 |
@IntDef(flag = true, prefix = { "RESULT_ATTR_" }, value = { |
| 42 |
RESULT_ATTR_IN_THE_DICTIONARY, |
| 43 |
RESULT_ATTR_LOOKS_LIKE_TYPO, |
| 44 |
RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS, |
| 45 |
RESULT_ATTR_LOOKS_LIKE_GRAMMAR_ERROR, |
| 46 |
RESULT_ATTR_DONT_SHOW_UI_FOR_SUGGESTIONS, |
| 47 |
}) |
| 48 |
public @interface ResultAttrs {} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public static final int RESULT_ATTR_IN_THE_DICTIONARY = 0x0001; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public static final int RESULT_ATTR_LOOKS_LIKE_TYPO = 0x0002; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public static final int RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS = 0x0004; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public static final int RESULT_ATTR_LOOKS_LIKE_GRAMMAR_ERROR = 0x0008; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public static final int RESULT_ATTR_DONT_SHOW_UI_FOR_SUGGESTIONS = 0x0010; |
| 85 |
|
| 86 |
private final @ResultAttrs int mSuggestionsAttributes; |
| 87 |
private final String[] mSuggestions; |
| 88 |
private final boolean mSuggestionsAvailable; |
| 89 |
private int mCookie; |
| 90 |
private int mSequence; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public SuggestionsInfo(int suggestionsAttributes, String[] suggestions) { |
| 98 |
this(suggestionsAttributes, suggestions, 0, 0); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public SuggestionsInfo(@ResultAttrs int suggestionsAttributes, String[] suggestions, int cookie, |
| 109 |
int sequence) { |
| 110 |
if (suggestions == null) { |
| 111 |
mSuggestions = EMPTY; |
| 112 |
mSuggestionsAvailable = false; |
| 113 |
} else { |
| 114 |
mSuggestions = suggestions; |
| 115 |
mSuggestionsAvailable = true; |
| 116 |
} |
| 117 |
mSuggestionsAttributes = suggestionsAttributes; |
| 118 |
mCookie = cookie; |
| 119 |
mSequence = sequence; |
| 120 |
} |
| 121 |
|
| 122 |
public SuggestionsInfo(Parcel source) { |
| 123 |
mSuggestionsAttributes = source.readInt(); |
| 124 |
mSuggestions = source.readStringArray(); |
| 125 |
mCookie = source.readInt(); |
| 126 |
mSequence = source.readInt(); |
| 127 |
mSuggestionsAvailable = source.readInt() == 1; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
@Override |
| 137 |
public void writeToParcel(Parcel dest, int flags) { |
| 138 |
dest.writeInt(mSuggestionsAttributes); |
| 139 |
dest.writeStringArray(mSuggestions); |
| 140 |
dest.writeInt(mCookie); |
| 141 |
dest.writeInt(mSequence); |
| 142 |
dest.writeInt(mSuggestionsAvailable ? 1 : 0); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public void setCookieAndSequence(int cookie, int sequence) { |
| 152 |
mCookie = cookie; |
| 153 |
mSequence = sequence; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public int getCookie() { |
| 160 |
return mCookie; |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
public int getSequence() { |
| 167 |
return mSequence; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public @ResultAttrs int getSuggestionsAttributes() { |
| 176 |
return mSuggestionsAttributes; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public int getSuggestionsCount() { |
| 186 |
if (!mSuggestionsAvailable) { |
| 187 |
return -1; |
| 188 |
} |
| 189 |
return mSuggestions.length; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public String getSuggestionAt(int i) { |
| 197 |
return mSuggestions[i]; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public static final @android.annotation.NonNull Parcelable.Creator<SuggestionsInfo> CREATOR |
| 204 |
= new Parcelable.Creator<SuggestionsInfo>() { |
| 205 |
@Override |
| 206 |
public SuggestionsInfo createFromParcel(Parcel source) { |
| 207 |
return new SuggestionsInfo(source); |
| 208 |
} |
| 209 |
|
| 210 |
@Override |
| 211 |
public SuggestionsInfo[] newArray(int size) { |
| 212 |
return new SuggestionsInfo[size]; |
| 213 |
} |
| 214 |
}; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
@Override |
| 220 |
public int describeContents() { |
| 221 |
return 0; |
| 222 |
} |
| 223 |
} |