FileDocCategorySizeDatePackage
InputMethodInfo.javaAPI DocAndroid 5.1 API19156Thu Mar 12 22:22:10 GMT 2015android.view.inputmethod

InputMethodInfo

public final class InputMethodInfo extends Object implements android.os.Parcelable
This class is used to specify meta information of an input method.

It should be defined in an XML resource file with an {@code <input-method>} element. For more information, see the guide to Creating an Input Method.

see
InputMethodSubtype
attr
ref android.R.styleable#InputMethod_settingsActivity
attr
ref android.R.styleable#InputMethod_isDefault
attr
ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod

Fields Summary
static final String
TAG
final android.content.pm.ResolveInfo
mService
The Service that implements this input method component.
final String
mId
The unique string Id to identify the input method. This is generated from the input method component.
final String
mSettingsActivityName
The input method setting activity's name, used by the system settings to launch the setting activity of this input method.
final int
mIsDefaultResId
The resource in the input method's .apk that holds a boolean indicating whether it should be considered the default input method for this system. This is a resource ID instead of the final value so that it can change based on the configuration (in particular locale).
private final android.view.inputmethod.InputMethodSubtypeArray
mSubtypes
An array-like container of the subtypes.
private final boolean
mIsAuxIme
private final boolean
mForceDefault
Caveat: mForceDefault must be false for production. This flag is only for test.
private final boolean
mSupportsSwitchingToNextInputMethod
The flag whether this IME supports ways to switch to a next input method (e.g. globe key.)
public static final Parcelable.Creator
CREATOR
Used to make this class parcelable.
Constructors Summary
public InputMethodInfo(android.content.Context context, android.content.pm.ResolveInfo service)
Constructor.

param
context The Context in which we are parsing the input method.
param
service The ResolveInfo returned from the package manager about this input method's component.


                                    
        
               
        this(context, service, null);
    
public InputMethodInfo(android.content.Context context, android.content.pm.ResolveInfo service, Map additionalSubtypesMap)
Constructor.

param
context The Context in which we are parsing the input method.
param
service The ResolveInfo returned from the package manager about this input method's component.
param
additionalSubtypes additional subtypes being added to this InputMethodInfo
hide

        mService = service;
        ServiceInfo si = service.serviceInfo;
        mId = new ComponentName(si.packageName, si.name).flattenToShortString();
        boolean isAuxIme = true;
        boolean supportsSwitchingToNextInputMethod = false; // false as default
        mForceDefault = false;

        PackageManager pm = context.getPackageManager();
        String settingsActivityComponent = null;
        int isDefaultResId = 0;

        XmlResourceParser parser = null;
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
        try {
            parser = si.loadXmlMetaData(pm, InputMethod.SERVICE_META_DATA);
            if (parser == null) {
                throw new XmlPullParserException("No "
                        + InputMethod.SERVICE_META_DATA + " meta-data");
            }

            Resources res = pm.getResourcesForApplication(si.applicationInfo);

            AttributeSet attrs = Xml.asAttributeSet(parser);

            int type;
            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
                    && type != XmlPullParser.START_TAG) {
            }

            String nodeName = parser.getName();
            if (!"input-method".equals(nodeName)) {
                throw new XmlPullParserException(
                        "Meta-data does not start with input-method tag");
            }

            TypedArray sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.InputMethod);
            settingsActivityComponent = sa.getString(
                    com.android.internal.R.styleable.InputMethod_settingsActivity);
            isDefaultResId = sa.getResourceId(
                    com.android.internal.R.styleable.InputMethod_isDefault, 0);
            supportsSwitchingToNextInputMethod = sa.getBoolean(
                    com.android.internal.R.styleable.InputMethod_supportsSwitchingToNextInputMethod,
                    false);
            sa.recycle();

            final int depth = parser.getDepth();
            // Parse all subtypes
            while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
                    && type != XmlPullParser.END_DOCUMENT) {
                if (type == XmlPullParser.START_TAG) {
                    nodeName = parser.getName();
                    if (!"subtype".equals(nodeName)) {
                        throw new XmlPullParserException(
                                "Meta-data in input-method does not start with subtype tag");
                    }
                    final TypedArray a = res.obtainAttributes(
                            attrs, com.android.internal.R.styleable.InputMethod_Subtype);
                    final InputMethodSubtype subtype = new InputMethodSubtypeBuilder()
                            .setSubtypeNameResId(a.getResourceId(com.android.internal.R.styleable
                                    .InputMethod_Subtype_label, 0))
                            .setSubtypeIconResId(a.getResourceId(com.android.internal.R.styleable
                                    .InputMethod_Subtype_icon, 0))
                            .setSubtypeLocale(a.getString(com.android.internal.R.styleable
                                    .InputMethod_Subtype_imeSubtypeLocale))
                            .setSubtypeMode(a.getString(com.android.internal.R.styleable
                                    .InputMethod_Subtype_imeSubtypeMode))
                            .setSubtypeExtraValue(a.getString(com.android.internal.R.styleable
                                    .InputMethod_Subtype_imeSubtypeExtraValue))
                            .setIsAuxiliary(a.getBoolean(com.android.internal.R.styleable
                                    .InputMethod_Subtype_isAuxiliary, false))
                            .setOverridesImplicitlyEnabledSubtype(a.getBoolean(
                                    com.android.internal.R.styleable
                                    .InputMethod_Subtype_overridesImplicitlyEnabledSubtype, false))
                            .setSubtypeId(a.getInt(com.android.internal.R.styleable
                                    .InputMethod_Subtype_subtypeId, 0 /* use Arrays.hashCode */))
                            .setIsAsciiCapable(a.getBoolean(com.android.internal.R.styleable
                                    .InputMethod_Subtype_isAsciiCapable, false)).build();
                    if (!subtype.isAuxiliary()) {
                        isAuxIme = false;
                    }
                    subtypes.add(subtype);
                }
            }
        } catch (NameNotFoundException e) {
            throw new XmlPullParserException(
                    "Unable to create context for: " + si.packageName);
        } finally {
            if (parser != null) parser.close();
        }

        if (subtypes.size() == 0) {
            isAuxIme = false;
        }

        if (additionalSubtypesMap != null && additionalSubtypesMap.containsKey(mId)) {
            final List<InputMethodSubtype> additionalSubtypes = additionalSubtypesMap.get(mId);
            final int N = additionalSubtypes.size();
            for (int i = 0; i < N; ++i) {
                final InputMethodSubtype subtype = additionalSubtypes.get(i);
                if (!subtypes.contains(subtype)) {
                    subtypes.add(subtype);
                } else {
                    Slog.w(TAG, "Duplicated subtype definition found: "
                            + subtype.getLocale() + ", " + subtype.getMode());
                }
            }
        }
        mSubtypes = new InputMethodSubtypeArray(subtypes);
        mSettingsActivityName = settingsActivityComponent;
        mIsDefaultResId = isDefaultResId;
        mIsAuxIme = isAuxIme;
        mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
    
InputMethodInfo(android.os.Parcel source)

        mId = source.readString();
        mSettingsActivityName = source.readString();
        mIsDefaultResId = source.readInt();
        mIsAuxIme = source.readInt() == 1;
        mSupportsSwitchingToNextInputMethod = source.readInt() == 1;
        mService = ResolveInfo.CREATOR.createFromParcel(source);
        mSubtypes = new InputMethodSubtypeArray(source);
        mForceDefault = false;
    
public InputMethodInfo(String packageName, String className, CharSequence label, String settingsActivity)
Temporary API for creating a built-in input method for test.

        this(buildDummyResolveInfo(packageName, className, label), false, settingsActivity, null,
                0, false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */);
    
public InputMethodInfo(android.content.pm.ResolveInfo ri, boolean isAuxIme, String settingsActivity, List subtypes, int isDefaultResId, boolean forceDefault)
Temporary API for creating a built-in input method for test.

hide

        this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId,
                forceDefault, true /* supportsSwitchingToNextInputMethod */);
    
public InputMethodInfo(android.content.pm.ResolveInfo ri, boolean isAuxIme, String settingsActivity, List subtypes, int isDefaultResId, boolean forceDefault, boolean supportsSwitchingToNextInputMethod)
Temporary API for creating a built-in input method for test.

hide

        final ServiceInfo si = ri.serviceInfo;
        mService = ri;
        mId = new ComponentName(si.packageName, si.name).flattenToShortString();
        mSettingsActivityName = settingsActivity;
        mIsDefaultResId = isDefaultResId;
        mIsAuxIme = isAuxIme;
        mSubtypes = new InputMethodSubtypeArray(subtypes);
        mForceDefault = forceDefault;
        mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
    
Methods Summary
private static android.content.pm.ResolveInfobuildDummyResolveInfo(java.lang.String packageName, java.lang.String className, java.lang.CharSequence label)

        ResolveInfo ri = new ResolveInfo();
        ServiceInfo si = new ServiceInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.packageName = packageName;
        ai.enabled = true;
        si.applicationInfo = ai;
        si.enabled = true;
        si.packageName = packageName;
        si.name = className;
        si.exported = true;
        si.nonLocalizedLabel = label;
        ri.serviceInfo = si;
        return ri;
    
public intdescribeContents()


    
       
        return 0;
    
public voiddump(android.util.Printer pw, java.lang.String prefix)

        pw.println(prefix + "mId=" + mId
                + " mSettingsActivityName=" + mSettingsActivityName);
        pw.println(prefix + "mIsDefaultResId=0x"
                + Integer.toHexString(mIsDefaultResId));
        pw.println(prefix + "Service:");
        mService.dump(pw, prefix + "  ");
    
public booleanequals(java.lang.Object o)
Used to test whether the given parameter object is an {@link InputMethodInfo} and its Id is the same to this one.

return
true if the given parameter object is an {@link InputMethodInfo} and its Id is the same to this one.

        if (o == this) return true;
        if (o == null) return false;

        if (!(o instanceof InputMethodInfo)) return false;

        InputMethodInfo obj = (InputMethodInfo) o;
        return mId.equals(obj.mId);
    
public android.content.ComponentNamegetComponent()
Return the component of the service that implements this input method.

        return new ComponentName(mService.serviceInfo.packageName,
                mService.serviceInfo.name);
    
public java.lang.StringgetId()
Return a unique ID for this input method. The ID is generated from the package and class name implementing the method.

        return mId;
    
public intgetIsDefaultResourceId()
Return the resource identifier of a resource inside of this input method's .apk that determines whether it should be considered a default input method for the system.

        return mIsDefaultResId;
    
public java.lang.StringgetPackageName()
Return the .apk package that implements this input method.

        return mService.serviceInfo.packageName;
    
public android.content.pm.ServiceInfogetServiceInfo()
Return the raw information about the Service implementing this input method. Do not modify the returned object.

        return mService.serviceInfo;
    
public java.lang.StringgetServiceName()
Return the class name of the service component that implements this input method.

        return mService.serviceInfo.name;
    
public java.lang.StringgetSettingsActivity()
Return the class name of an activity that provides a settings UI for the input method. You can launch this activity be starting it with an {@link android.content.Intent} whose action is MAIN and with an explicit {@link android.content.ComponentName} composed of {@link #getPackageName} and the class name returned here.

A null will be returned if there is no settings activity associated with the input method.

        return mSettingsActivityName;
    
public InputMethodSubtypegetSubtypeAt(int index)
Return the Input Method's subtype at the specified index.

param
index the index of the subtype to return.

        return mSubtypes.get(index);
    
public intgetSubtypeCount()
Return the count of the subtypes of Input Method.

        return mSubtypes.getCount();
    
public inthashCode()

        return mId.hashCode();
    
public booleanisAuxiliaryIme()

hide

        return mIsAuxIme;
    
public booleanisDefault(android.content.Context context)
Return whether or not this ime is a default ime or not.

hide

        if (mForceDefault) {
            return true;
        }
        try {
            if (getIsDefaultResourceId() == 0) {
                return false;
            }
            final Resources res = context.createPackageContext(getPackageName(), 0).getResources();
            return res.getBoolean(getIsDefaultResourceId());
        } catch (NameNotFoundException | NotFoundException e) {
            return false;
        }
    
public android.graphics.drawable.DrawableloadIcon(android.content.pm.PackageManager pm)
Load the user-displayed icon for this input method.

param
pm Supply a PackageManager used to load the input method's resources.

        return mService.loadIcon(pm);
    
public java.lang.CharSequenceloadLabel(android.content.pm.PackageManager pm)
Load the user-displayed label for this input method.

param
pm Supply a PackageManager used to load the input method's resources.

        return mService.loadLabel(pm);
    
public booleansupportsSwitchingToNextInputMethod()

return
true if this input method supports ways to switch to a next input method.
hide

        return mSupportsSwitchingToNextInputMethod;
    
public java.lang.StringtoString()

        return "InputMethodInfo{" + mId
                + ", settings: "
                + mSettingsActivityName + "}";
    
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.writeString(mId);
        dest.writeString(mSettingsActivityName);
        dest.writeInt(mIsDefaultResId);
        dest.writeInt(mIsAuxIme ? 1 : 0);
        dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0);
        mService.writeToParcel(dest, flags);
        mSubtypes.writeToParcel(dest);