blob: 0a8e4b9c21815f0769d72b1349c7f23a57a4a274 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007-2008 The Android Open Source Project
Yohei Yukawa66996da2014-02-24 19:50:40 +09003 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004 * 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
Yohei Yukawa66996da2014-02-24 19:50:40 +09007 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008 * http://www.apache.org/licenses/LICENSE-2.0
Yohei Yukawa66996da2014-02-24 19:50:40 +09009 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010 * 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.inputmethod;
18
19import org.xmlpull.v1.XmlPullParser;
20import org.xmlpull.v1.XmlPullParserException;
21
22import android.content.ComponentName;
23import android.content.Context;
24import android.content.pm.ApplicationInfo;
25import android.content.pm.PackageManager;
satoke7c6998e2011-06-03 17:57:59 +090026import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.pm.ResolveInfo;
28import android.content.pm.ServiceInfo;
Dianne Hackborn20cb56e2010-03-04 00:58:29 -080029import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.res.TypedArray;
31import android.content.res.XmlResourceParser;
32import android.graphics.drawable.Drawable;
33import android.os.Parcel;
34import android.os.Parcelable;
35import android.util.AttributeSet;
36import android.util.Printer;
Satoshi Kataokae62e6d82012-07-02 18:45:43 +090037import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.util.Xml;
Satoshi Kataokadc8abf62013-03-12 14:40:04 +090039import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
Yohei Yukawaf0656952014-03-03 15:38:18 +090040import android.view.inputmethod.InputMethodSubtypeArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
42import java.io.IOException;
satok7eb84252010-08-04 18:26:42 +090043import java.util.ArrayList;
satoke7c6998e2011-06-03 17:57:59 +090044import java.util.List;
45import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046
47/**
48 * This class is used to specify meta information of an input method.
Scott Main5df06312013-10-18 16:07:47 -070049 *
50 * <p>It should be defined in an XML resource file with an {@code &lt;input-method>} element.
51 * For more information, see the guide to
52 * <a href="{@docRoot}guide/topics/text/creating-input-method.html">
53 * Creating an Input Method</a>.</p>
54 *
55 * @see InputMethodSubtype
56 *
57 * @attr ref android.R.styleable#InputMethod_settingsActivity
58 * @attr ref android.R.styleable#InputMethod_isDefault
59 * @attr ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 */
61public final class InputMethodInfo implements Parcelable {
Dianne Hackborneb034652009-09-07 00:49:58 -070062 static final String TAG = "InputMethodInfo";
satokab751aa2010-09-14 19:17:36 +090063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 /**
65 * The Service that implements this input method component.
66 */
67 final ResolveInfo mService;
Yohei Yukawa66996da2014-02-24 19:50:40 +090068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 /**
70 * The unique string Id to identify the input method. This is generated
71 * from the input method component.
72 */
73 final String mId;
74
75 /**
76 * The input method setting activity's name, used by the system settings to
77 * launch the setting activity of this input method.
78 */
79 final String mSettingsActivityName;
80
81 /**
82 * The resource in the input method's .apk that holds a boolean indicating
83 * whether it should be considered the default input method for this
84 * system. This is a resource ID instead of the final value so that it
85 * can change based on the configuration (in particular locale).
86 */
87 final int mIsDefaultResId;
satok7eb84252010-08-04 18:26:42 +090088
89 /**
Yohei Yukawaf0656952014-03-03 15:38:18 +090090 * An array-like container of the subtypes.
satok7eb84252010-08-04 18:26:42 +090091 */
Yohei Yukawaf0656952014-03-03 15:38:18 +090092 private final InputMethodSubtypeArray mSubtypes;
satok7eb84252010-08-04 18:26:42 +090093
Satoshi Kataoka660e6c92013-08-01 16:50:48 +090094 private final boolean mIsAuxIme;
satokdbfba852011-09-05 19:19:12 +090095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 /**
Satoshi Kataoka69da2692013-08-15 15:36:44 +090097 * Caveat: mForceDefault must be false for production. This flag is only for test.
Satoshi Kataokaf1367b72013-01-25 17:20:12 +090098 */
99 private final boolean mForceDefault;
100
101 /**
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900102 * The flag whether this IME supports ways to switch to a next input method (e.g. globe key.)
103 */
104 private final boolean mSupportsSwitchingToNextInputMethod;
105
106 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 * Constructor.
satoke7c6998e2011-06-03 17:57:59 +0900108 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 * @param context The Context in which we are parsing the input method.
110 * @param service The ResolveInfo returned from the package manager about
111 * this input method's component.
112 */
113 public InputMethodInfo(Context context, ResolveInfo service)
114 throws XmlPullParserException, IOException {
satoke7c6998e2011-06-03 17:57:59 +0900115 this(context, service, null);
116 }
117
118 /**
119 * Constructor.
120 *
121 * @param context The Context in which we are parsing the input method.
122 * @param service The ResolveInfo returned from the package manager about
123 * this input method's component.
124 * @param additionalSubtypes additional subtypes being added to this InputMethodInfo
125 * @hide
126 */
127 public InputMethodInfo(Context context, ResolveInfo service,
128 Map<String, List<InputMethodSubtype>> additionalSubtypesMap)
129 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 mService = service;
131 ServiceInfo si = service.serviceInfo;
132 mId = new ComponentName(si.packageName, si.name).flattenToShortString();
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900133 boolean isAuxIme = true;
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900134 boolean supportsSwitchingToNextInputMethod = false; // false as default
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900135 mForceDefault = false;
satok7eb84252010-08-04 18:26:42 +0900136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 PackageManager pm = context.getPackageManager();
138 String settingsActivityComponent = null;
139 int isDefaultResId = 0;
satok7eb84252010-08-04 18:26:42 +0900140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 XmlResourceParser parser = null;
Yohei Yukawaf0656952014-03-03 15:38:18 +0900142 final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 try {
144 parser = si.loadXmlMetaData(pm, InputMethod.SERVICE_META_DATA);
145 if (parser == null) {
146 throw new XmlPullParserException("No "
147 + InputMethod.SERVICE_META_DATA + " meta-data");
148 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900149
Dianne Hackborn20cb56e2010-03-04 00:58:29 -0800150 Resources res = pm.getResourcesForApplication(si.applicationInfo);
Yohei Yukawa66996da2014-02-24 19:50:40 +0900151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 AttributeSet attrs = Xml.asAttributeSet(parser);
Yohei Yukawa66996da2014-02-24 19:50:40 +0900153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 int type;
155 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
156 && type != XmlPullParser.START_TAG) {
157 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 String nodeName = parser.getName();
160 if (!"input-method".equals(nodeName)) {
161 throw new XmlPullParserException(
162 "Meta-data does not start with input-method tag");
163 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900164
Dianne Hackborn20cb56e2010-03-04 00:58:29 -0800165 TypedArray sa = res.obtainAttributes(attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 com.android.internal.R.styleable.InputMethod);
167 settingsActivityComponent = sa.getString(
168 com.android.internal.R.styleable.InputMethod_settingsActivity);
169 isDefaultResId = sa.getResourceId(
170 com.android.internal.R.styleable.InputMethod_isDefault, 0);
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900171 supportsSwitchingToNextInputMethod = sa.getBoolean(
172 com.android.internal.R.styleable.InputMethod_supportsSwitchingToNextInputMethod,
173 false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 sa.recycle();
satok7eb84252010-08-04 18:26:42 +0900175
176 final int depth = parser.getDepth();
177 // Parse all subtypes
178 while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
179 && type != XmlPullParser.END_DOCUMENT) {
satokab751aa2010-09-14 19:17:36 +0900180 if (type == XmlPullParser.START_TAG) {
181 nodeName = parser.getName();
182 if (!"subtype".equals(nodeName)) {
183 throw new XmlPullParserException(
184 "Meta-data in input-method does not start with subtype tag");
185 }
186 final TypedArray a = res.obtainAttributes(
187 attrs, com.android.internal.R.styleable.InputMethod_Subtype);
Satoshi Kataokadc8abf62013-03-12 14:40:04 +0900188 final InputMethodSubtype subtype = new InputMethodSubtypeBuilder()
189 .setSubtypeNameResId(a.getResourceId(com.android.internal.R.styleable
190 .InputMethod_Subtype_label, 0))
191 .setSubtypeIconResId(a.getResourceId(com.android.internal.R.styleable
192 .InputMethod_Subtype_icon, 0))
193 .setSubtypeLocale(a.getString(com.android.internal.R.styleable
194 .InputMethod_Subtype_imeSubtypeLocale))
195 .setSubtypeMode(a.getString(com.android.internal.R.styleable
196 .InputMethod_Subtype_imeSubtypeMode))
197 .setSubtypeExtraValue(a.getString(com.android.internal.R.styleable
198 .InputMethod_Subtype_imeSubtypeExtraValue))
199 .setIsAuxiliary(a.getBoolean(com.android.internal.R.styleable
200 .InputMethod_Subtype_isAuxiliary, false))
201 .setOverridesImplicitlyEnabledSubtype(a.getBoolean(
202 com.android.internal.R.styleable
203 .InputMethod_Subtype_overridesImplicitlyEnabledSubtype, false))
204 .setSubtypeId(a.getInt(com.android.internal.R.styleable
205 .InputMethod_Subtype_subtypeId, 0 /* use Arrays.hashCode */))
206 .setIsAsciiCapable(a.getBoolean(com.android.internal.R.styleable
207 .InputMethod_Subtype_isAsciiCapable, false)).build();
satokdbfba852011-09-05 19:19:12 +0900208 if (!subtype.isAuxiliary()) {
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900209 isAuxIme = false;
satokdbfba852011-09-05 19:19:12 +0900210 }
Yohei Yukawaf0656952014-03-03 15:38:18 +0900211 subtypes.add(subtype);
satok7eb84252010-08-04 18:26:42 +0900212 }
satok7eb84252010-08-04 18:26:42 +0900213 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -0800214 } catch (NameNotFoundException e) {
215 throw new XmlPullParserException(
216 "Unable to create context for: " + si.packageName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 } finally {
218 if (parser != null) parser.close();
219 }
satoke7c6998e2011-06-03 17:57:59 +0900220
Yohei Yukawaf0656952014-03-03 15:38:18 +0900221 if (subtypes.size() == 0) {
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900222 isAuxIme = false;
satokdbfba852011-09-05 19:19:12 +0900223 }
224
satoke7c6998e2011-06-03 17:57:59 +0900225 if (additionalSubtypesMap != null && additionalSubtypesMap.containsKey(mId)) {
226 final List<InputMethodSubtype> additionalSubtypes = additionalSubtypesMap.get(mId);
227 final int N = additionalSubtypes.size();
228 for (int i = 0; i < N; ++i) {
229 final InputMethodSubtype subtype = additionalSubtypes.get(i);
Yohei Yukawaf0656952014-03-03 15:38:18 +0900230 if (!subtypes.contains(subtype)) {
231 subtypes.add(subtype);
Satoshi Kataokae62e6d82012-07-02 18:45:43 +0900232 } else {
233 Slog.w(TAG, "Duplicated subtype definition found: "
234 + subtype.getLocale() + ", " + subtype.getMode());
satoke7c6998e2011-06-03 17:57:59 +0900235 }
236 }
237 }
Yohei Yukawaf0656952014-03-03 15:38:18 +0900238 mSubtypes = new InputMethodSubtypeArray(subtypes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 mSettingsActivityName = settingsActivityComponent;
240 mIsDefaultResId = isDefaultResId;
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900241 mIsAuxIme = isAuxIme;
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900242 mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 }
244
245 InputMethodInfo(Parcel source) {
246 mId = source.readString();
247 mSettingsActivityName = source.readString();
248 mIsDefaultResId = source.readInt();
satokdbfba852011-09-05 19:19:12 +0900249 mIsAuxIme = source.readInt() == 1;
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900250 mSupportsSwitchingToNextInputMethod = source.readInt() == 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 mService = ResolveInfo.CREATOR.createFromParcel(source);
Yohei Yukawaf0656952014-03-03 15:38:18 +0900252 mSubtypes = new InputMethodSubtypeArray(source);
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900253 mForceDefault = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
satok7eb84252010-08-04 18:26:42 +0900255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 /**
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900257 * Temporary API for creating a built-in input method for test.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 */
259 public InputMethodInfo(String packageName, String className,
260 CharSequence label, String settingsActivity) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900261 this(buildDummyResolveInfo(packageName, className, label), false, settingsActivity, null,
Yohei Yukawad1da1152014-05-01 17:20:05 +0900262 0, false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */);
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900263 }
264
265 /**
266 * Temporary API for creating a built-in input method for test.
267 * @hide
268 */
269 public InputMethodInfo(ResolveInfo ri, boolean isAuxIme,
270 String settingsActivity, List<InputMethodSubtype> subtypes, int isDefaultResId,
271 boolean forceDefault) {
Yohei Yukawad1da1152014-05-01 17:20:05 +0900272 this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId,
273 forceDefault, true /* supportsSwitchingToNextInputMethod */);
274 }
275
276 /**
277 * Temporary API for creating a built-in input method for test.
278 * @hide
279 */
280 public InputMethodInfo(ResolveInfo ri, boolean isAuxIme,
281 String settingsActivity, List<InputMethodSubtype> subtypes, int isDefaultResId,
282 boolean forceDefault, boolean supportsSwitchingToNextInputMethod) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900283 final ServiceInfo si = ri.serviceInfo;
284 mService = ri;
285 mId = new ComponentName(si.packageName, si.name).flattenToShortString();
286 mSettingsActivityName = settingsActivity;
287 mIsDefaultResId = isDefaultResId;
288 mIsAuxIme = isAuxIme;
Yohei Yukawaf0656952014-03-03 15:38:18 +0900289 mSubtypes = new InputMethodSubtypeArray(subtypes);
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900290 mForceDefault = forceDefault;
Yohei Yukawad1da1152014-05-01 17:20:05 +0900291 mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900292 }
293
294 private static ResolveInfo buildDummyResolveInfo(String packageName, String className,
295 CharSequence label) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 ResolveInfo ri = new ResolveInfo();
297 ServiceInfo si = new ServiceInfo();
298 ApplicationInfo ai = new ApplicationInfo();
299 ai.packageName = packageName;
300 ai.enabled = true;
301 si.applicationInfo = ai;
302 si.enabled = true;
303 si.packageName = packageName;
304 si.name = className;
305 si.exported = true;
306 si.nonLocalizedLabel = label;
307 ri.serviceInfo = si;
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900308 return ri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 }
satok7eb84252010-08-04 18:26:42 +0900310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 /**
312 * Return a unique ID for this input method. The ID is generated from
313 * the package and class name implementing the method.
314 */
315 public String getId() {
316 return mId;
317 }
satok7eb84252010-08-04 18:26:42 +0900318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 /**
320 * Return the .apk package that implements this input method.
321 */
322 public String getPackageName() {
323 return mService.serviceInfo.packageName;
324 }
satok7eb84252010-08-04 18:26:42 +0900325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 /**
327 * Return the class name of the service component that implements
328 * this input method.
329 */
330 public String getServiceName() {
331 return mService.serviceInfo.name;
332 }
333
334 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700335 * Return the raw information about the Service implementing this
336 * input method. Do not modify the returned object.
337 */
338 public ServiceInfo getServiceInfo() {
339 return mService.serviceInfo;
340 }
341
342 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 * Return the component of the service that implements this input
344 * method.
345 */
346 public ComponentName getComponent() {
347 return new ComponentName(mService.serviceInfo.packageName,
348 mService.serviceInfo.name);
349 }
satok7eb84252010-08-04 18:26:42 +0900350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 /**
352 * Load the user-displayed label for this input method.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900353 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 * @param pm Supply a PackageManager used to load the input method's
355 * resources.
356 */
357 public CharSequence loadLabel(PackageManager pm) {
358 return mService.loadLabel(pm);
359 }
satok7eb84252010-08-04 18:26:42 +0900360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 /**
362 * Load the user-displayed icon for this input method.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900363 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 * @param pm Supply a PackageManager used to load the input method's
365 * resources.
366 */
367 public Drawable loadIcon(PackageManager pm) {
368 return mService.loadIcon(pm);
369 }
satok7eb84252010-08-04 18:26:42 +0900370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 /**
372 * Return the class name of an activity that provides a settings UI for
373 * the input method. You can launch this activity be starting it with
374 * an {@link android.content.Intent} whose action is MAIN and with an
375 * explicit {@link android.content.ComponentName}
376 * composed of {@link #getPackageName} and the class name returned here.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900377 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 * <p>A null will be returned if there is no settings activity associated
Yohei Yukawaf0656952014-03-03 15:38:18 +0900379 * with the input method.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 */
381 public String getSettingsActivity() {
382 return mSettingsActivityName;
383 }
satok7eb84252010-08-04 18:26:42 +0900384
385 /**
Ken Wakasa586f0512011-01-20 22:31:01 +0900386 * Return the count of the subtypes of Input Method.
satok7eb84252010-08-04 18:26:42 +0900387 */
Ken Wakasa586f0512011-01-20 22:31:01 +0900388 public int getSubtypeCount() {
Yohei Yukawaf0656952014-03-03 15:38:18 +0900389 return mSubtypes.getCount();
Ken Wakasa586f0512011-01-20 22:31:01 +0900390 }
391
392 /**
393 * Return the Input Method's subtype at the specified index.
394 *
395 * @param index the index of the subtype to return.
396 */
397 public InputMethodSubtype getSubtypeAt(int index) {
398 return mSubtypes.get(index);
satok7eb84252010-08-04 18:26:42 +0900399 }
400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 /**
402 * Return the resource identifier of a resource inside of this input
403 * method's .apk that determines whether it should be considered a
404 * default input method for the system.
405 */
406 public int getIsDefaultResourceId() {
407 return mIsDefaultResId;
408 }
satok7eb84252010-08-04 18:26:42 +0900409
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900410 /**
411 * Return whether or not this ime is a default ime or not.
412 * @hide
413 */
414 public boolean isDefault(Context context) {
415 if (mForceDefault) {
416 return true;
417 }
418 try {
Yohei Yukawadc489242014-09-14 12:01:59 +0900419 if (getIsDefaultResourceId() == 0) {
420 return false;
421 }
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900422 final Resources res = context.createPackageContext(getPackageName(), 0).getResources();
423 return res.getBoolean(getIsDefaultResourceId());
424 } catch (NameNotFoundException e) {
425 return false;
426 }
427 }
428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 public void dump(Printer pw, String prefix) {
430 pw.println(prefix + "mId=" + mId
431 + " mSettingsActivityName=" + mSettingsActivityName);
432 pw.println(prefix + "mIsDefaultResId=0x"
433 + Integer.toHexString(mIsDefaultResId));
434 pw.println(prefix + "Service:");
435 mService.dump(pw, prefix + " ");
436 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 @Override
439 public String toString() {
Dianne Hackborneb034652009-09-07 00:49:58 -0700440 return "InputMethodInfo{" + mId
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 + ", settings: "
442 + mSettingsActivityName + "}";
443 }
444
445 /**
446 * Used to test whether the given parameter object is an
447 * {@link InputMethodInfo} and its Id is the same to this one.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900448 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 * @return true if the given parameter object is an
450 * {@link InputMethodInfo} and its Id is the same to this one.
451 */
452 @Override
453 public boolean equals(Object o) {
454 if (o == this) return true;
455 if (o == null) return false;
456
457 if (!(o instanceof InputMethodInfo)) return false;
458
459 InputMethodInfo obj = (InputMethodInfo) o;
460 return mId.equals(obj.mId);
461 }
satokc50232d2011-03-25 13:52:48 +0900462
463 @Override
464 public int hashCode() {
465 return mId.hashCode();
466 }
467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 /**
satokdbfba852011-09-05 19:19:12 +0900469 * @hide
470 */
471 public boolean isAuxiliaryIme() {
472 return mIsAuxIme;
473 }
474
475 /**
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900476 * @return true if this input method supports ways to switch to a next input method.
477 * @hide
478 */
479 public boolean supportsSwitchingToNextInputMethod() {
480 return mSupportsSwitchingToNextInputMethod;
481 }
482
483 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 * Used to package this object into a {@link Parcel}.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900485 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 * @param dest The {@link Parcel} to be written.
487 * @param flags The flags used for parceling.
488 */
satokdbfba852011-09-05 19:19:12 +0900489 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 public void writeToParcel(Parcel dest, int flags) {
491 dest.writeString(mId);
492 dest.writeString(mSettingsActivityName);
493 dest.writeInt(mIsDefaultResId);
satokdbfba852011-09-05 19:19:12 +0900494 dest.writeInt(mIsAuxIme ? 1 : 0);
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900495 dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 mService.writeToParcel(dest, flags);
Yohei Yukawaf0656952014-03-03 15:38:18 +0900497 mSubtypes.writeToParcel(dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
499
500 /**
501 * Used to make this class parcelable.
502 */
satok7eb84252010-08-04 18:26:42 +0900503 public static final Parcelable.Creator<InputMethodInfo> CREATOR
504 = new Parcelable.Creator<InputMethodInfo>() {
satokdbfba852011-09-05 19:19:12 +0900505 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 public InputMethodInfo createFromParcel(Parcel source) {
507 return new InputMethodInfo(source);
508 }
509
satokdbfba852011-09-05 19:19:12 +0900510 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 public InputMethodInfo[] newArray(int size) {
512 return new InputMethodInfo[size];
513 }
514 };
515
satokdbfba852011-09-05 19:19:12 +0900516 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 public int describeContents() {
518 return 0;
519 }
520}