FileDocCategorySizeDatePackage
SpellCheckerSubtype.javaAPI DocAndroid 5.1 API9352Thu Mar 12 22:22:10 GMT 2015android.view.textservice

SpellCheckerSubtype

public final class SpellCheckerSubtype extends Object implements android.os.Parcelable
This class is used to specify meta information of a subtype contained in a spell checker. Subtype can describe locale (e.g. en_US, fr_FR...) used for settings.

Fields Summary
private static final String
TAG
private static final String
EXTRA_VALUE_PAIR_SEPARATOR
private static final String
EXTRA_VALUE_KEY_VALUE_SEPARATOR
private final int
mSubtypeHashCode
private final int
mSubtypeNameResId
private final String
mSubtypeLocale
private final String
mSubtypeExtraValue
private HashMap
mExtraValueHashMapCache
public static final Parcelable.Creator
CREATOR
Constructors Summary
public SpellCheckerSubtype(int nameId, String locale, String extraValue)
Constructor

param
nameId The name of the subtype
param
locale The locale supported by the subtype
param
extraValue The extra value of the subtype


                                 
           
        mSubtypeNameResId = nameId;
        mSubtypeLocale = locale != null ? locale : "";
        mSubtypeExtraValue = extraValue != null ? extraValue : "";
        mSubtypeHashCode = hashCodeInternal(mSubtypeLocale, mSubtypeExtraValue);
    
SpellCheckerSubtype(android.os.Parcel source)

        String s;
        mSubtypeNameResId = source.readInt();
        s = source.readString();
        mSubtypeLocale = s != null ? s : "";
        s = source.readString();
        mSubtypeExtraValue = s != null ? s : "";
        mSubtypeHashCode = hashCodeInternal(mSubtypeLocale, mSubtypeExtraValue);
    
Methods Summary
public static java.util.LocaleconstructLocaleFromString(java.lang.String localeStr)

hide

        if (TextUtils.isEmpty(localeStr))
            return null;
        String[] localeParams = localeStr.split("_", 3);
        // The length of localeStr is guaranteed to always return a 1 <= value <= 3
        // because localeStr is not empty.
        if (localeParams.length == 1) {
            return new Locale(localeParams[0]);
        } else if (localeParams.length == 2) {
            return new Locale(localeParams[0], localeParams[1]);
        } else if (localeParams.length == 3) {
            return new Locale(localeParams[0], localeParams[1], localeParams[2]);
        }
        return null;
    
public booleancontainsExtraValueKey(java.lang.String key)
The string of ExtraValue in subtype should be defined as follows: example: key0,key1=value1,key2,key3,key4=value4

param
key the key of extra value
return
the subtype contains specified the extra value

        return getExtraValueHashMap().containsKey(key);
    
public intdescribeContents()

        return 0;
    
public booleanequals(java.lang.Object o)

        if (o instanceof SpellCheckerSubtype) {
            SpellCheckerSubtype subtype = (SpellCheckerSubtype) o;
            return (subtype.hashCode() == hashCode())
                && (subtype.getNameResId() == getNameResId())
                && (subtype.getLocale().equals(getLocale()))
                && (subtype.getExtraValue().equals(getExtraValue()));
        }
        return false;
    
public java.lang.CharSequencegetDisplayName(android.content.Context context, java.lang.String packageName, android.content.pm.ApplicationInfo appInfo)

param
context Context will be used for getting Locale and PackageManager.
param
packageName The package name of the spell checker
param
appInfo The application info of the spell checker
return
a display name for this subtype. The string resource of the label (mSubtypeNameResId) can have only one %s in it. If there is, the %s part will be replaced with the locale's display name by the formatter. If there is not, this method simply returns the string specified by mSubtypeNameResId. If mSubtypeNameResId is not specified (== 0), it's up to the framework to generate an appropriate display name.

        final Locale locale = constructLocaleFromString(mSubtypeLocale);
        final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale;
        if (mSubtypeNameResId == 0) {
            return localeStr;
        }
        final CharSequence subtypeName = context.getPackageManager().getText(
                packageName, mSubtypeNameResId, appInfo);
        if (!TextUtils.isEmpty(subtypeName)) {
            return String.format(subtypeName.toString(), localeStr);
        } else {
            return localeStr;
        }
    
public java.lang.StringgetExtraValue()

return
the extra value of the subtype

        return mSubtypeExtraValue;
    
private java.util.HashMapgetExtraValueHashMap()

        if (mExtraValueHashMapCache == null) {
            mExtraValueHashMapCache = new HashMap<String, String>();
            final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR);
            final int N = pairs.length;
            for (int i = 0; i < N; ++i) {
                final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR);
                if (pair.length == 1) {
                    mExtraValueHashMapCache.put(pair[0], null);
                } else if (pair.length > 1) {
                    if (pair.length > 2) {
                        Slog.w(TAG, "ExtraValue has two or more '='s");
                    }
                    mExtraValueHashMapCache.put(pair[0], pair[1]);
                }
            }
        }
        return mExtraValueHashMapCache;
    
public java.lang.StringgetExtraValueOf(java.lang.String key)
The string of ExtraValue in subtype should be defined as follows: example: key0,key1=value1,key2,key3,key4=value4

param
key the key of extra value
return
the value of the specified key

        return getExtraValueHashMap().get(key);
    
public java.lang.StringgetLocale()

return
the locale of the subtype

        return mSubtypeLocale;
    
public intgetNameResId()

return
the name of the subtype

        return mSubtypeNameResId;
    
public inthashCode()

        return mSubtypeHashCode;
    
private static inthashCodeInternal(java.lang.String locale, java.lang.String extraValue)


           
        return Arrays.hashCode(new Object[] {locale, extraValue});
    
public static java.util.Listsort(android.content.Context context, int flags, SpellCheckerInfo sci, java.util.List subtypeList)
Sort the list of subtypes

param
context Context will be used for getting localized strings
param
flags Flags for the sort order
param
sci SpellCheckerInfo of which subtypes are subject to be sorted
param
subtypeList List which will be sorted
return
Sorted list of subtypes
hide

        if (sci == null) return subtypeList;
        final HashSet<SpellCheckerSubtype> subtypesSet = new HashSet<SpellCheckerSubtype>(
                subtypeList);
        final ArrayList<SpellCheckerSubtype> sortedList = new ArrayList<SpellCheckerSubtype>();
        int N = sci.getSubtypeCount();
        for (int i = 0; i < N; ++i) {
            SpellCheckerSubtype subtype = sci.getSubtypeAt(i);
            if (subtypesSet.contains(subtype)) {
                sortedList.add(subtype);
                subtypesSet.remove(subtype);
            }
        }
        // If subtypes in subtypesSet remain, that means these subtypes are not
        // contained in sci, so the remaining subtypes will be appended.
        for (SpellCheckerSubtype subtype: subtypesSet) {
            sortedList.add(subtype);
        }
        return sortedList;
    
public voidwriteToParcel(android.os.Parcel dest, int parcelableFlags)

        dest.writeInt(mSubtypeNameResId);
        dest.writeString(mSubtypeLocale);
        dest.writeString(mSubtypeExtraValue);