Search in sources :

Example 51 with SpellCheckerInfo

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

the class TextServicesManagerService method setCurrentSpellCheckerLocked.

private void setCurrentSpellCheckerLocked(String sciId) {
    if (DBG) {
        Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
    }
    if (TextUtils.isEmpty(sciId) || !mSpellCheckerMap.containsKey(sciId))
        return;
    final SpellCheckerInfo currentSci = getCurrentSpellChecker(null);
    if (currentSci != null && currentSci.getId().equals(sciId)) {
        // Do nothing if the current spell checker is same as new spell checker.
        return;
    }
    final long ident = Binder.clearCallingIdentity();
    try {
        mSettings.putSelectedSpellChecker(sciId);
        setCurrentSpellCheckerSubtypeLocked(0);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 52 with SpellCheckerInfo

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

the class TextServicesManagerService method resetInternalState.

private void resetInternalState(@UserIdInt int userId) {
    final boolean useCopyOnWriteSettings = !mSystemReady || !mUserManager.isUserUnlockingOrUnlocked(userId);
    mSettings.switchCurrentUser(userId, useCopyOnWriteSettings);
    updateCurrentProfileIds();
    unbindServiceLocked();
    buildSpellCheckerMapLocked(mContext, mSpellCheckerList, mSpellCheckerMap, mSettings);
    SpellCheckerInfo sci = getCurrentSpellChecker(null);
    if (sci == null) {
        sci = findAvailSpellCheckerLocked(null);
        if (sci != null) {
            // Set the current spell checker if there is one or more spell checkers
            // available. In this case, "sci" is the first one in the available spell
            // checkers.
            setCurrentSpellCheckerLocked(sci.getId());
        }
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 53 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by DirtyUnicorns.

the class TextServicesManagerService method setCurrentSpellCheckerLocked.

private void setCurrentSpellCheckerLocked(String sciId) {
    if (DBG) {
        Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
    }
    if (TextUtils.isEmpty(sciId) || !mSpellCheckerMap.containsKey(sciId))
        return;
    final SpellCheckerInfo currentSci = getCurrentSpellChecker(null);
    if (currentSci != null && currentSci.getId().equals(sciId)) {
        // Do nothing if the current spell checker is same as new spell checker.
        return;
    }
    final long ident = Binder.clearCallingIdentity();
    try {
        mSettings.putSelectedSpellChecker(sciId);
        setCurrentSpellCheckerSubtypeLocked(0);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 54 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by DirtyUnicorns.

the class TextServicesManagerService method setCurrentSpellCheckerSubtypeLocked.

private void setCurrentSpellCheckerSubtypeLocked(int hashCode) {
    if (DBG) {
        Slog.w(TAG, "setCurrentSpellCheckerSubtype: " + hashCode);
    }
    final SpellCheckerInfo sci = getCurrentSpellChecker(null);
    int tempHashCode = 0;
    for (int i = 0; sci != null && i < sci.getSubtypeCount(); ++i) {
        if (sci.getSubtypeAt(i).hashCode() == hashCode) {
            tempHashCode = hashCode;
            break;
        }
    }
    final long ident = Binder.clearCallingIdentity();
    try {
        mSettings.putSelectedSpellCheckerSubtype(tempHashCode);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 55 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by DirtyUnicorns.

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)

Aggregations

SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)87 SpellCheckerSubtype (android.view.textservice.SpellCheckerSubtype)19 RemoteException (android.os.RemoteException)16 Intent (android.content.Intent)13 ServiceInfo (android.content.pm.ServiceInfo)11 Locale (java.util.Locale)10 DialogInterface (android.content.DialogInterface)7 Test (org.junit.Test)7 AlertDialog (android.app.AlertDialog)6 ComponentName (android.content.ComponentName)6 ApplicationInfo (android.content.pm.ApplicationInfo)6 PackageManager (android.content.pm.PackageManager)6 ResolveInfo (android.content.pm.ResolveInfo)6 InputMethodInfo (android.view.inputmethod.InputMethodInfo)6 InputMethodManager (android.view.inputmethod.InputMethodManager)6 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)6 ISpellCheckerSession (com.android.internal.textservice.ISpellCheckerSession)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6