Search in sources :

Example 21 with SpellCheckerInfo

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

the class InputMethodUtils method setNonSelectedSystemImesDisabledUntilUsed.

public static void setNonSelectedSystemImesDisabledUntilUsed(IPackageManager packageManager, List<InputMethodInfo> enabledImis, int userId, String callingPackage) {
    if (DEBUG) {
        Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
    }
    final String[] systemImesDisabledUntilUsed = Resources.getSystem().getStringArray(com.android.internal.R.array.config_disabledUntilUsedPreinstalledImes);
    if (systemImesDisabledUntilUsed == null || systemImesDisabledUntilUsed.length == 0) {
        return;
    }
    // Only the current spell checker should be treated as an enabled one.
    final SpellCheckerInfo currentSpellChecker = TextServicesManager.getInstance().getCurrentSpellChecker();
    for (final String packageName : systemImesDisabledUntilUsed) {
        if (DEBUG) {
            Slog.d(TAG, "check " + packageName);
        }
        boolean enabledIme = false;
        for (int j = 0; j < enabledImis.size(); ++j) {
            final InputMethodInfo imi = enabledImis.get(j);
            if (packageName.equals(imi.getPackageName())) {
                enabledIme = true;
                break;
            }
        }
        if (enabledIme) {
            // enabled ime. skip
            continue;
        }
        if (currentSpellChecker != null && packageName.equals(currentSpellChecker.getPackageName())) {
            // enabled spell checker. skip
            if (DEBUG) {
                Slog.d(TAG, packageName + " is the current spell checker. skip");
            }
            continue;
        }
        ApplicationInfo ai = null;
        try {
            ai = packageManager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
        } catch (RemoteException e) {
            Slog.w(TAG, "getApplicationInfo failed. packageName=" + packageName + " userId=" + userId, e);
            continue;
        }
        if (ai == null) {
            // No app found for packageName
            continue;
        }
        final boolean isSystemPackage = (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        if (!isSystemPackage) {
            continue;
        }
        setDisabledUntilUsed(packageManager, packageName, userId, callingPackage);
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 22 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndLanguageSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    mSettingsObserver.resume();
    mIm.registerInputDeviceListener(this, null);
    final Preference spellChecker = findPreference(KEY_SPELL_CHECKERS);
    if (spellChecker != null) {
        final TextServicesManager tsm = (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
        if (!tsm.isSpellCheckerEnabled()) {
            spellChecker.setSummary(R.string.switch_off_text);
        } else {
            final SpellCheckerInfo sci = tsm.getCurrentSpellChecker();
            if (sci != null) {
                spellChecker.setSummary(sci.loadLabel(getPackageManager()));
            } else {
                spellChecker.setSummary(R.string.spell_checker_not_selected);
            }
        }
    }
    if (!mShowsOnlyFullImeAndKeyboardList) {
        if (mLanguagePref != null) {
            String localeNames = getLocaleNames(getActivity());
            mLanguagePref.setSummary(localeNames);
        }
        updateUserDictionaryPreference(findPreference(KEY_USER_DICTIONARY_SETTINGS));
        if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
            mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this);
        }
    }
    updateInputDevices();
    // Refresh internal states in mInputMethodSettingValues to keep the latest
    // "InputMethodInfo"s and "InputMethodSubtype"s
    mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
    updateInputMethodPreferenceViews();
}
Also used : ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) TextServicesManager(android.view.textservice.TextServicesManager) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 23 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SpellCheckerPreference method setValue.

@Override
public void setValue(String value) {
    super.setValue(value);
    int index = value != null ? Integer.parseInt(value) : -1;
    if (index == -1) {
        mIntent = null;
        return;
    }
    SpellCheckerInfo sci = mScis[index];
    final String settingsActivity = sci.getSettingsActivity();
    if (TextUtils.isEmpty(settingsActivity)) {
        mIntent = null;
    } else {
        mIntent = new Intent(Intent.ACTION_MAIN);
        mIntent.setClassName(sci.getPackageName(), settingsActivity);
    }
}
Also used : Intent(android.content.Intent) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 24 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SpellCheckersSettings method showChooseLanguageDialog.

private void showChooseLanguageDialog() {
    if (mDialog != null && mDialog.isShowing()) {
        mDialog.dismiss();
    }
    final SpellCheckerInfo currentSci = mTsm.getCurrentSpellChecker();
    if (currentSci == null) {
        // spell checker belongs to was uninstalled or being in background.
        return;
    }
    final SpellCheckerSubtype currentScs = mTsm.getCurrentSpellCheckerSubtype(false);
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.phone_language);
    final int subtypeCount = currentSci.getSubtypeCount();
    final CharSequence[] items = new CharSequence[subtypeCount + 1];
    items[ITEM_ID_USE_SYSTEM_LANGUAGE] = getSpellCheckerSubtypeLabel(currentSci, null);
    int checkedItemId = ITEM_ID_USE_SYSTEM_LANGUAGE;
    for (int index = 0; index < subtypeCount; ++index) {
        final SpellCheckerSubtype subtype = currentSci.getSubtypeAt(index);
        final int itemId = convertSubtypeIndexToDialogItemId(index);
        items[itemId] = getSpellCheckerSubtypeLabel(currentSci, subtype);
        if (subtype.equals(currentScs)) {
            checkedItemId = itemId;
        }
    }
    builder.setSingleChoiceItems(items, checkedItemId, new AlertDialog.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int item) {
            if (item == ITEM_ID_USE_SYSTEM_LANGUAGE) {
                mTsm.setSpellCheckerSubtype(null);
            } else {
                final int index = convertDialogItemIdToSubtypeIndex(item);
                mTsm.setSpellCheckerSubtype(currentSci.getSubtypeAt(index));
            }
            if (DBG) {
                final SpellCheckerSubtype subtype = mTsm.getCurrentSpellCheckerSubtype(true);
                Log.d(TAG, "Current spell check locale is " + subtype == null ? "null" : subtype.getLocale());
            }
            dialog.dismiss();
            updatePreferenceScreen();
        }
    });
    mDialog = builder.create();
    mDialog.show();
}
Also used : SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 25 with SpellCheckerInfo

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

the class InputMethodUtils method setNonSelectedSystemImesDisabledUntilUsed.

public static void setNonSelectedSystemImesDisabledUntilUsed(IPackageManager packageManager, List<InputMethodInfo> enabledImis, int userId, String callingPackage) {
    if (DEBUG) {
        Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
    }
    final String[] systemImesDisabledUntilUsed = Resources.getSystem().getStringArray(com.android.internal.R.array.config_disabledUntilUsedPreinstalledImes);
    if (systemImesDisabledUntilUsed == null || systemImesDisabledUntilUsed.length == 0) {
        return;
    }
    // Only the current spell checker should be treated as an enabled one.
    final SpellCheckerInfo currentSpellChecker = TextServicesManager.getInstance().getCurrentSpellChecker();
    for (final String packageName : systemImesDisabledUntilUsed) {
        if (DEBUG) {
            Slog.d(TAG, "check " + packageName);
        }
        boolean enabledIme = false;
        for (int j = 0; j < enabledImis.size(); ++j) {
            final InputMethodInfo imi = enabledImis.get(j);
            if (packageName.equals(imi.getPackageName())) {
                enabledIme = true;
                break;
            }
        }
        if (enabledIme) {
            // enabled ime. skip
            continue;
        }
        if (currentSpellChecker != null && packageName.equals(currentSpellChecker.getPackageName())) {
            // enabled spell checker. skip
            if (DEBUG) {
                Slog.d(TAG, packageName + " is the current spell checker. skip");
            }
            continue;
        }
        ApplicationInfo ai = null;
        try {
            ai = packageManager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
        } catch (RemoteException e) {
            Slog.w(TAG, "getApplicationInfo failed. packageName=" + packageName + " userId=" + userId, e);
            continue;
        }
        if (ai == null) {
            // No app found for packageName
            continue;
        }
        final boolean isSystemPackage = (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        if (!isSystemPackage) {
            continue;
        }
        setDisabledUntilUsed(packageManager, packageName, userId, callingPackage);
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Aggregations

SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)62 RemoteException (android.os.RemoteException)16 SpellCheckerSubtype (android.view.textservice.SpellCheckerSubtype)13 ServiceInfo (android.content.pm.ServiceInfo)11 Locale (java.util.Locale)10 Intent (android.content.Intent)7 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 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1