FileDocCategorySizeDatePackage
SpellCheckerInfo.javaAPI DocAndroid 5.1 API9160Thu Mar 12 22:22:10 GMT 2015android.view.textservice

SpellCheckerInfo

public final class SpellCheckerInfo extends Object implements android.os.Parcelable
This class is used to specify meta information of a spell checker.

Fields Summary
private static final String
TAG
private final android.content.pm.ResolveInfo
mService
private final String
mId
private final int
mLabel
private final String
mSettingsActivityName
The spell checker setting activity's name, used by the system settings to launch the setting activity.
private final ArrayList
mSubtypes
The array of subtypes.
public static final Parcelable.Creator
CREATOR
Used to make this class parcelable.
Constructors Summary
public SpellCheckerInfo(android.content.Context context, android.content.pm.ResolveInfo service)
Constructor.

hide


           
        
               
        mService = service;
        ServiceInfo si = service.serviceInfo;
        mId = new ComponentName(si.packageName, si.name).flattenToShortString();

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

        XmlResourceParser parser = null;
        try {
            parser = si.loadXmlMetaData(pm, SpellCheckerSession.SERVICE_META_DATA);
            if (parser == null) {
                throw new XmlPullParserException("No "
                        + SpellCheckerSession.SERVICE_META_DATA + " meta-data");
            }

            final Resources res = pm.getResourcesForApplication(si.applicationInfo);
            final AttributeSet attrs = Xml.asAttributeSet(parser);
            int type;
            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
                    && type != XmlPullParser.START_TAG) {
            }

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

            TypedArray sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.SpellChecker);
            label = sa.getResourceId(com.android.internal.R.styleable.SpellChecker_label, 0);
            settingsActivityComponent = sa.getString(
                    com.android.internal.R.styleable.SpellChecker_settingsActivity);
            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) {
                    final String subtypeNodeName = parser.getName();
                    if (!"subtype".equals(subtypeNodeName)) {
                        throw new XmlPullParserException(
                                "Meta-data in spell-checker does not start with subtype tag");
                    }
                    final TypedArray a = res.obtainAttributes(
                            attrs, com.android.internal.R.styleable.SpellChecker_Subtype);
                    SpellCheckerSubtype subtype = new SpellCheckerSubtype(
                            a.getResourceId(com.android.internal.R.styleable
                                    .SpellChecker_Subtype_label, 0),
                            a.getString(com.android.internal.R.styleable
                                    .SpellChecker_Subtype_subtypeLocale),
                            a.getString(com.android.internal.R.styleable
                                    .SpellChecker_Subtype_subtypeExtraValue));
                    mSubtypes.add(subtype);
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Caught exception: " + e);
            throw new XmlPullParserException(
                    "Unable to create context for: " + si.packageName);
        } finally {
            if (parser != null) parser.close();
        }
        mLabel = label;
        mSettingsActivityName = settingsActivityComponent;
    
public SpellCheckerInfo(android.os.Parcel source)
Constructor.

hide

        mLabel = source.readInt();
        mId = source.readString();
        mSettingsActivityName = source.readString();
        mService = ResolveInfo.CREATOR.createFromParcel(source);
        source.readTypedList(mSubtypes, SpellCheckerSubtype.CREATOR);
    
Methods Summary
public intdescribeContents()
Used to make this class parcelable.

        return 0;
    
public android.content.ComponentNamegetComponent()
Return the component of the service that implements.

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

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

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

        return mService.serviceInfo;
    
public java.lang.StringgetSettingsActivity()
Return the class name of an activity that provides a settings UI. 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.

        return mSettingsActivityName;
    
public SpellCheckerSubtypegetSubtypeAt(int index)
Return the 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.

        return mSubtypes.size();
    
public android.graphics.drawable.DrawableloadIcon(android.content.pm.PackageManager pm)
Load the user-displayed icon for this spell checker.

param
pm Supply a PackageManager used to load the spell checker's resources.

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

param
pm Supply a PackageManager used to load the spell checker's resources.


                             
        
        if (mLabel == 0 || pm == null) return "";
        return pm.getText(getPackageName(), mLabel, mService.serviceInfo.applicationInfo);
    
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.writeInt(mLabel);
        dest.writeString(mId);
        dest.writeString(mSettingsActivityName);
        mService.writeToParcel(dest, flags);
        dest.writeTypedList(mSubtypes);