blob: b0ccbea7d91a2f92fdbdac6347eddbd28ea2ed65 [file] [log] [blame]
satok988323c2011-06-22 16:38:13 +09001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package android.view.textservice;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * This class contains a metadata of suggestions from the text service
24 */
25public final class SuggestionsInfo implements Parcelable {
26 /**
27 * Flag of the attributes of the suggestions that can be obtained by
satok3de3d6a2011-07-22 15:35:31 +090028 * {@link #getSuggestionsAttributes}: this tells that the requested word was found
satok988323c2011-06-22 16:38:13 +090029 * in the dictionary in the text service.
30 */
31 public static final int RESULT_ATTR_IN_THE_DICTIONARY = 0x0001;
32 /** Flag of the attributes of the suggestions that can be obtained by
satok3de3d6a2011-07-22 15:35:31 +090033 * {@link #getSuggestionsAttributes}: this tells that there are one or more suggestions
34 * available for the requested word. This doesn't necessarily mean that the suggestions
35 * are actually in this SuggestionsInfo. For instance, the caller could have been asked to
36 * limit the maximum number of suggestions returned.
satok988323c2011-06-22 16:38:13 +090037 */
38 public static final int RESULT_ATTR_SUGGESTIONS_AVAILABLE = 0x0002;
39 /**
40 * Flag of the attributes of the suggestions that can be obtained by
satok3de3d6a2011-07-22 15:35:31 +090041 * {@link #getSuggestionsAttributes}: this tells that the text service thinks the requested
42 * word looks a typo.
satok988323c2011-06-22 16:38:13 +090043 */
44 public static final int RESULT_ATTR_LOOKS_TYPO = 0x0004;
45 private final int mSuggestionsAttributes;
46 private final String[] mSuggestions;
47 private int mCookie;
48 private int mSequence;
49
50 /**
51 * Constructor.
52 * @param suggestionsAttributes from the text service
53 * @param suggestions from the text service
54 */
55 public SuggestionsInfo(int suggestionsAttributes, String[] suggestions) {
56 if (suggestions == null) {
57 throw new NullPointerException();
58 }
59 mSuggestionsAttributes = suggestionsAttributes;
60 mSuggestions = suggestions;
61 mCookie = 0;
62 mSequence = 0;
63 }
64
65 /**
66 * Constructor.
67 * @param suggestionsAttributes from the text service
68 * @param suggestions from the text service
69 * @param cookie the cookie of the input TextInfo
70 * @param sequence the cookie of the input TextInfo
71 */
72 public SuggestionsInfo(
73 int suggestionsAttributes, String[] suggestions, int cookie, int sequence) {
74 if (suggestions == null) {
75 throw new NullPointerException();
76 }
77 mSuggestionsAttributes = suggestionsAttributes;
78 mSuggestions = suggestions;
79 mCookie = cookie;
80 mSequence = sequence;
81 }
82
83 public SuggestionsInfo(Parcel source) {
84 mSuggestionsAttributes = source.readInt();
85 mSuggestions = source.readStringArray();
86 mCookie = source.readInt();
87 mSequence = source.readInt();
88 }
89
90 /**
91 * Used to package this object into a {@link Parcel}.
92 *
93 * @param dest The {@link Parcel} to be written.
94 * @param flags The flags used for parceling.
95 */
96 @Override
97 public void writeToParcel(Parcel dest, int flags) {
98 dest.writeInt(mSuggestionsAttributes);
99 dest.writeStringArray(mSuggestions);
100 dest.writeInt(mCookie);
101 dest.writeInt(mSequence);
102 }
103
104 /**
105 * Set the cookie and the sequence of SuggestionsInfo which are set to TextInfo from a client
106 * application
107 * @param cookie the cookie of an input TextInfo
108 * @param sequence the cookie of an input TextInfo
109 */
110 public void setCookieAndSequence(int cookie, int sequence) {
111 mCookie = cookie;
112 mSequence = sequence;
113 }
114
115 /**
116 * @return the cookie which may be set by a client application
117 */
118 public int getCookie() {
119 return mCookie;
120 }
121
122 /**
123 * @return the sequence which may be set by a client application
124 */
125 public int getSequence() {
126 return mSequence;
127 }
128
129 /**
130 * @return the attributes of suggestions. This includes whether the spell checker has the word
131 * in its dictionary or not and whether the spell checker has confident suggestions for the
132 * word or not.
133 */
134 public int getSuggestionsAttributes() {
135 return mSuggestionsAttributes;
136 }
137
138 /**
139 * @return the count of suggestions
140 */
141 public int getSuggestionsCount() {
142 return mSuggestions.length;
143 }
144
145 /**
146 * @param i the id of suggestions
147 * @return the suggestion at the specified id
148 */
149 public String getSuggestionAt(int i) {
150 return mSuggestions[i];
151 }
152
153 /**
154 * Used to make this class parcelable.
155 */
156 public static final Parcelable.Creator<SuggestionsInfo> CREATOR
157 = new Parcelable.Creator<SuggestionsInfo>() {
158 @Override
159 public SuggestionsInfo createFromParcel(Parcel source) {
160 return new SuggestionsInfo(source);
161 }
162
163 @Override
164 public SuggestionsInfo[] newArray(int size) {
165 return new SuggestionsInfo[size];
166 }
167 };
168
169 /**
170 * Used to make this class parcelable.
171 */
172 @Override
173 public int describeContents() {
174 return 0;
175 }
176}