Search in sources :

Example 1 with SpellCheckerSubtype

use of android.view.textservice.SpellCheckerSubtype in project android_frameworks_base by ParanoidAndroid.

the class TextServicesManagerService method getCurrentSpellCheckerSubtype.

// TODO: Respect allowImplicitlySelectedSubtype
// TODO: Save SpellCheckerSubtype by supported languages by looking at "locale".
@Override
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale, boolean allowImplicitlySelectedSubtype) {
    // TODO: Make this work even for non-current users?
    if (!calledFromValidUser()) {
        return null;
    }
    synchronized (mSpellCheckerMap) {
        final String subtypeHashCodeStr = mSettings.getSelectedSpellCheckerSubtype();
        if (DBG) {
            Slog.w(TAG, "getCurrentSpellCheckerSubtype: " + subtypeHashCodeStr);
        }
        final SpellCheckerInfo sci = getCurrentSpellChecker(null);
        if (sci == null || sci.getSubtypeCount() == 0) {
            if (DBG) {
                Slog.w(TAG, "Subtype not found.");
            }
            return null;
        }
        final int hashCode;
        if (!TextUtils.isEmpty(subtypeHashCodeStr)) {
            hashCode = Integer.valueOf(subtypeHashCodeStr);
        } else {
            hashCode = 0;
        }
        if (hashCode == 0 && !allowImplicitlySelectedSubtype) {
            return null;
        }
        String candidateLocale = null;
        if (hashCode == 0) {
            // Spell checker language settings == "auto"
            final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype();
                if (currentInputMethodSubtype != null) {
                    final String localeString = currentInputMethodSubtype.getLocale();
                    if (!TextUtils.isEmpty(localeString)) {
                        // 1. Use keyboard locale if available in the spell checker
                        candidateLocale = localeString;
                    }
                }
            }
            if (candidateLocale == null) {
                // 2. Use System locale if available in the spell checker
                candidateLocale = mContext.getResources().getConfiguration().locale.toString();
            }
        }
        SpellCheckerSubtype candidate = null;
        for (int i = 0; i < sci.getSubtypeCount(); ++i) {
            final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
            if (hashCode == 0) {
                final String scsLocale = scs.getLocale();
                if (candidateLocale.equals(scsLocale)) {
                    return scs;
                } else if (candidate == null) {
                    if (candidateLocale.length() >= 2 && scsLocale.length() >= 2 && candidateLocale.startsWith(scsLocale)) {
                        // Fall back to the applicable language
                        candidate = scs;
                    }
                }
            } else if (scs.hashCode() == hashCode) {
                if (DBG) {
                    Slog.w(TAG, "Return subtype " + scs.hashCode() + ", input= " + locale + ", " + scs.getLocale());
                }
                // 3. Use the user specified spell check language
                return scs;
            }
        }
        // spell check languages
        return candidate;
    }
}
Also used : SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 2 with SpellCheckerSubtype

use of android.view.textservice.SpellCheckerSubtype in project android_frameworks_base by ParanoidAndroid.

the class TextServicesManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump TextServicesManagerService from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
        return;
    }
    synchronized (mSpellCheckerMap) {
        pw.println("Current Text Services Manager state:");
        pw.println("  Spell Checker Map:");
        for (Map.Entry<String, SpellCheckerInfo> ent : mSpellCheckerMap.entrySet()) {
            pw.print("    ");
            pw.print(ent.getKey());
            pw.println(":");
            SpellCheckerInfo info = ent.getValue();
            pw.print("      ");
            pw.print("id=");
            pw.println(info.getId());
            pw.print("      ");
            pw.print("comp=");
            pw.println(info.getComponent().toShortString());
            int NS = info.getSubtypeCount();
            for (int i = 0; i < NS; i++) {
                SpellCheckerSubtype st = info.getSubtypeAt(i);
                pw.print("      ");
                pw.print("Subtype #");
                pw.print(i);
                pw.println(":");
                pw.print("        ");
                pw.print("locale=");
                pw.println(st.getLocale());
                pw.print("        ");
                pw.print("extraValue=");
                pw.println(st.getExtraValue());
            }
        }
        pw.println("");
        pw.println("  Spell Checker Bind Groups:");
        for (Map.Entry<String, SpellCheckerBindGroup> ent : mSpellCheckerBindGroups.entrySet()) {
            SpellCheckerBindGroup grp = ent.getValue();
            pw.print("    ");
            pw.print(ent.getKey());
            pw.print(" ");
            pw.print(grp);
            pw.println(":");
            pw.print("      ");
            pw.print("mInternalConnection=");
            pw.println(grp.mInternalConnection);
            pw.print("      ");
            pw.print("mSpellChecker=");
            pw.println(grp.mSpellChecker);
            pw.print("      ");
            pw.print("mBound=");
            pw.print(grp.mBound);
            pw.print(" mConnected=");
            pw.println(grp.mConnected);
            int NL = grp.mListeners.size();
            for (int i = 0; i < NL; i++) {
                InternalDeathRecipient listener = grp.mListeners.get(i);
                pw.print("      ");
                pw.print("Listener #");
                pw.print(i);
                pw.println(":");
                pw.print("        ");
                pw.print("mTsListener=");
                pw.println(listener.mTsListener);
                pw.print("        ");
                pw.print("mScListener=");
                pw.println(listener.mScListener);
                pw.print("        ");
                pw.print("mGroup=");
                pw.println(listener.mGroup);
                pw.print("        ");
                pw.print("mScLocale=");
                pw.print(listener.mScLocale);
                pw.print(" mUid=");
                pw.println(listener.mUid);
            }
        }
    }
}
Also used : SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) HashMap(java.util.HashMap) Map(java.util.Map) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 3 with SpellCheckerSubtype

use of android.view.textservice.SpellCheckerSubtype in project platform_frameworks_base by android.

the class TextServicesManagerService method findAvailSpellCheckerLocked.

private SpellCheckerInfo findAvailSpellCheckerLocked(String prefPackage) {
    final int spellCheckersCount = mSpellCheckerList.size();
    if (spellCheckersCount == 0) {
        Slog.w(TAG, "no available spell checker services found");
        return null;
    }
    if (prefPackage != null) {
        for (int i = 0; i < spellCheckersCount; ++i) {
            final SpellCheckerInfo sci = mSpellCheckerList.get(i);
            if (prefPackage.equals(sci.getPackageName())) {
                if (DBG) {
                    Slog.d(TAG, "findAvailSpellCheckerLocked: " + sci.getPackageName());
                }
                return sci;
            }
        }
    }
    // Look up a spell checker based on the system locale.
    // TODO: Still there is a room to improve in the following logic: e.g., check if the package
    // is pre-installed or not.
    final Locale systemLocal = mContext.getResources().getConfiguration().locale;
    final ArrayList<Locale> suitableLocales = InputMethodUtils.getSuitableLocalesForSpellChecker(systemLocal);
    if (DBG) {
        Slog.w(TAG, "findAvailSpellCheckerLocked suitableLocales=" + Arrays.toString(suitableLocales.toArray(new Locale[suitableLocales.size()])));
    }
    final int localeCount = suitableLocales.size();
    for (int localeIndex = 0; localeIndex < localeCount; ++localeIndex) {
        final Locale locale = suitableLocales.get(localeIndex);
        for (int spellCheckersIndex = 0; spellCheckersIndex < spellCheckersCount; ++spellCheckersIndex) {
            final SpellCheckerInfo info = mSpellCheckerList.get(spellCheckersIndex);
            final int subtypeCount = info.getSubtypeCount();
            for (int subtypeIndex = 0; subtypeIndex < subtypeCount; ++subtypeIndex) {
                final SpellCheckerSubtype subtype = info.getSubtypeAt(subtypeIndex);
                final Locale subtypeLocale = InputMethodUtils.constructLocaleFromString(subtype.getLocale());
                if (locale.equals(subtypeLocale)) {
                    // returning the first found one.
                    return info;
                }
            }
        }
    }
    if (spellCheckersCount > 1) {
        Slog.w(TAG, "more than one spell checker service found, picking first");
    }
    return mSpellCheckerList.get(0);
}
Also used : Locale(java.util.Locale) SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 4 with SpellCheckerSubtype

use of android.view.textservice.SpellCheckerSubtype in project android_frameworks_base by AOSPA.

the class TextView method updateTextServicesLocaleLocked.

private void updateTextServicesLocaleLocked() {
    final TextServicesManager textServicesManager = (TextServicesManager) mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
    final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true);
    final Locale locale;
    if (subtype != null) {
        locale = subtype.getLocaleObject();
    } else {
        locale = null;
    }
    mCurrentSpellCheckerLocaleCache = locale;
}
Also used : SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) Locale(java.util.Locale) TextServicesManager(android.view.textservice.TextServicesManager)

Example 5 with SpellCheckerSubtype

use of android.view.textservice.SpellCheckerSubtype in project android_frameworks_base by ResurrectionRemix.

the class TextView method updateTextServicesLocaleLocked.

private void updateTextServicesLocaleLocked() {
    final TextServicesManager textServicesManager = (TextServicesManager) mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
    final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true);
    final Locale locale;
    if (subtype != null) {
        locale = subtype.getLocaleObject();
    } else {
        locale = null;
    }
    mCurrentSpellCheckerLocaleCache = locale;
}
Also used : SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) Locale(java.util.Locale) TextServicesManager(android.view.textservice.TextServicesManager)

Aggregations

SpellCheckerSubtype (android.view.textservice.SpellCheckerSubtype)20 Locale (java.util.Locale)16 SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)13 InputMethodManager (android.view.inputmethod.InputMethodManager)6 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)6 TextServicesManager (android.view.textservice.TextServicesManager)6 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Preference (android.support.v7.preference.Preference)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1