Search in sources :

Example 31 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by ResurrectionRemix.

the class Ime method runList.

/**
     * Execute the list sub-command.
     */
private void runList() {
    String opt;
    boolean all = false;
    boolean brief = false;
    while ((opt = nextOption()) != null) {
        if (opt.equals("-a")) {
            all = true;
        } else if (opt.equals("-s")) {
            brief = true;
        } else {
            System.err.println("Error: Unknown option: " + opt);
            showUsage();
            return;
        }
    }
    List<InputMethodInfo> methods;
    if (!all) {
        try {
            methods = mImm.getEnabledInputMethodList();
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(IMM_NOT_RUNNING_ERR);
            return;
        }
    } else {
        try {
            methods = mImm.getInputMethodList();
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(IMM_NOT_RUNNING_ERR);
            return;
        }
    }
    if (methods != null) {
        Printer pr = new PrintStreamPrinter(System.out);
        for (int i = 0; i < methods.size(); i++) {
            InputMethodInfo imi = methods.get(i);
            if (brief) {
                System.out.println(imi.getId());
            } else {
                System.out.println(imi.getId() + ":");
                imi.dump(pr, "  ");
            }
        }
    }
}
Also used : PrintStreamPrinter(android.util.PrintStreamPrinter) RemoteException(android.os.RemoteException) PrintStreamPrinter(android.util.PrintStreamPrinter) Printer(android.util.Printer) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 32 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndSubtypeEnabler method onCreate.

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    final Configuration config = getResources().getConfiguration();
    mHaveHardKeyboard = (config.keyboard == Configuration.KEYBOARD_QWERTY);
    // Input method id should be available from an Intent when this preference is launched as a
    // single Activity (see InputMethodAndSubtypeEnablerActivity). It should be available
    // from a preference argument when the preference is launched as a part of the other
    // Activity (like a right pane of 2-pane Settings app)
    final String targetImi = getStringExtraFromIntentOrArguments(android.provider.Settings.EXTRA_INPUT_METHOD_ID);
    mInputMethodInfoList = mImm.getInputMethodList();
    mCollator = Collator.getInstance();
    final PreferenceScreen root = getPreferenceManager().createPreferenceScreen(getActivity());
    final int imiCount = mInputMethodInfoList.size();
    for (int index = 0; index < imiCount; ++index) {
        final InputMethodInfo imi = mInputMethodInfoList.get(index);
        // Add subtype preferences of this IME when it is specified or no IME is specified.
        if (imi.getId().equals(targetImi) || TextUtils.isEmpty(targetImi)) {
            addInputMethodSubtypePreferences(imi, root);
        }
    }
    setPreferenceScreen(root);
}
Also used : Configuration(android.content.res.Configuration) PreferenceScreen(android.support.v7.preference.PreferenceScreen) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 33 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndSubtypeUtil method saveInputMethodSubtypeList.

static void saveInputMethodSubtypeList(SettingsPreferenceFragment context, ContentResolver resolver, List<InputMethodInfo> inputMethodInfos, boolean hasHardKeyboard) {
    String currentInputMethodId = Settings.Secure.getString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD);
    final int selectedInputMethodSubtype = getInputMethodSubtypeSelected(resolver);
    final HashMap<String, HashSet<String>> enabledIMEsAndSubtypesMap = getEnabledInputMethodsAndSubtypeList(resolver);
    final HashSet<String> disabledSystemIMEs = getDisabledSystemIMEs(resolver);
    boolean needsToResetSelectedSubtype = false;
    for (final InputMethodInfo imi : inputMethodInfos) {
        final String imiId = imi.getId();
        final Preference pref = context.findPreference(imiId);
        if (pref == null) {
            continue;
        }
        // In the choose input method screen or in the subtype enabler screen,
        // <code>pref</code> is an instance of TwoStatePreference.
        final boolean isImeChecked = (pref instanceof TwoStatePreference) ? ((TwoStatePreference) pref).isChecked() : enabledIMEsAndSubtypesMap.containsKey(imiId);
        final boolean isCurrentInputMethod = imiId.equals(currentInputMethodId);
        final boolean systemIme = InputMethodUtils.isSystemIme(imi);
        if ((!hasHardKeyboard && InputMethodSettingValuesWrapper.getInstance(context.getActivity()).isAlwaysCheckedIme(imi, context.getActivity())) || isImeChecked) {
            if (!enabledIMEsAndSubtypesMap.containsKey(imiId)) {
                // imiId has just been enabled
                enabledIMEsAndSubtypesMap.put(imiId, new HashSet<String>());
            }
            final HashSet<String> subtypesSet = enabledIMEsAndSubtypesMap.get(imiId);
            boolean subtypePrefFound = false;
            final int subtypeCount = imi.getSubtypeCount();
            for (int i = 0; i < subtypeCount; ++i) {
                final InputMethodSubtype subtype = imi.getSubtypeAt(i);
                final String subtypeHashCodeStr = String.valueOf(subtype.hashCode());
                final TwoStatePreference subtypePref = (TwoStatePreference) context.findPreference(imiId + subtypeHashCodeStr);
                // In the Configure input method screen which does not have subtype preferences.
                if (subtypePref == null) {
                    continue;
                }
                if (!subtypePrefFound) {
                    // Once subtype preference is found, subtypeSet needs to be cleared.
                    // Because of system change, hashCode value could have been changed.
                    subtypesSet.clear();
                    // If selected subtype preference is disabled, needs to reset.
                    needsToResetSelectedSubtype = true;
                    subtypePrefFound = true;
                }
                // subtypes can be saved here.
                if (subtypePref.isEnabled() && subtypePref.isChecked()) {
                    subtypesSet.add(subtypeHashCodeStr);
                    if (isCurrentInputMethod) {
                        if (selectedInputMethodSubtype == subtype.hashCode()) {
                            // Selected subtype is still enabled, there is no need to reset
                            // selected subtype.
                            needsToResetSelectedSubtype = false;
                        }
                    }
                } else {
                    subtypesSet.remove(subtypeHashCodeStr);
                }
            }
        } else {
            enabledIMEsAndSubtypesMap.remove(imiId);
            if (isCurrentInputMethod) {
                // find the applicable IME from the history and the system locale.
                if (DEBUG) {
                    Log.d(TAG, "Current IME was uninstalled or disabled.");
                }
                currentInputMethodId = null;
            }
        }
        // doesn't get enabled automatically on any changes to the package list
        if (systemIme && hasHardKeyboard) {
            if (disabledSystemIMEs.contains(imiId)) {
                if (isImeChecked) {
                    disabledSystemIMEs.remove(imiId);
                }
            } else {
                if (!isImeChecked) {
                    disabledSystemIMEs.add(imiId);
                }
            }
        }
    }
    final String enabledIMEsAndSubtypesString = buildInputMethodsAndSubtypesString(enabledIMEsAndSubtypesMap);
    final String disabledSystemIMEsString = buildInputMethodsString(disabledSystemIMEs);
    if (DEBUG) {
        Log.d(TAG, "--- Save enabled inputmethod settings. :" + enabledIMEsAndSubtypesString);
        Log.d(TAG, "--- Save disabled system inputmethod settings. :" + disabledSystemIMEsString);
        Log.d(TAG, "--- Save default inputmethod settings. :" + currentInputMethodId);
        Log.d(TAG, "--- Needs to reset the selected subtype :" + needsToResetSelectedSubtype);
        Log.d(TAG, "--- Subtype is selected :" + isInputMethodSubtypeSelected(resolver));
    }
    // We should reset the selected input method's subtype.
    if (needsToResetSelectedSubtype || !isInputMethodSubtypeSelected(resolver)) {
        if (DEBUG) {
            Log.d(TAG, "--- Reset inputmethod subtype because it's not defined.");
        }
        putSelectedInputMethodSubtype(resolver, NOT_A_SUBTYPE_ID);
    }
    Settings.Secure.putString(resolver, Settings.Secure.ENABLED_INPUT_METHODS, enabledIMEsAndSubtypesString);
    if (disabledSystemIMEsString.length() > 0) {
        Settings.Secure.putString(resolver, Settings.Secure.DISABLED_SYSTEM_INPUT_METHODS, disabledSystemIMEsString);
    }
    // If the current input method is unset, InputMethodManagerService will find the applicable
    // IME from the history and the system locale.
    Settings.Secure.putString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD, currentInputMethodId != null ? currentInputMethodId : "");
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) TwoStatePreference(android.support.v7.preference.TwoStatePreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) InputMethodInfo(android.view.inputmethod.InputMethodInfo) HashSet(java.util.HashSet)

Example 34 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndSubtypeUtil method loadInputMethodSubtypeList.

static void loadInputMethodSubtypeList(final SettingsPreferenceFragment context, final ContentResolver resolver, final List<InputMethodInfo> inputMethodInfos, final Map<String, List<Preference>> inputMethodPrefsMap) {
    final HashMap<String, HashSet<String>> enabledSubtypes = getEnabledInputMethodsAndSubtypeList(resolver);
    for (final InputMethodInfo imi : inputMethodInfos) {
        final String imiId = imi.getId();
        final Preference pref = context.findPreference(imiId);
        if (pref instanceof TwoStatePreference) {
            final TwoStatePreference subtypePref = (TwoStatePreference) pref;
            final boolean isEnabled = enabledSubtypes.containsKey(imiId);
            subtypePref.setChecked(isEnabled);
            if (inputMethodPrefsMap != null) {
                for (final Preference childPref : inputMethodPrefsMap.get(imiId)) {
                    childPref.setEnabled(isEnabled);
                }
            }
            setSubtypesPreferenceEnabled(context, inputMethodInfos, imiId, isEnabled);
        }
    }
    updateSubtypesPreferenceChecked(context, inputMethodInfos, enabledSubtypes);
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) InputMethodInfo(android.view.inputmethod.InputMethodInfo) HashSet(java.util.HashSet)

Example 35 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndSubtypeUtil method updateSubtypesPreferenceChecked.

private static void updateSubtypesPreferenceChecked(final SettingsPreferenceFragment context, final List<InputMethodInfo> inputMethodProperties, final HashMap<String, HashSet<String>> enabledSubtypes) {
    final PreferenceScreen preferenceScreen = context.getPreferenceScreen();
    for (final InputMethodInfo imi : inputMethodProperties) {
        final String id = imi.getId();
        if (!enabledSubtypes.containsKey(id)) {
            // There is no need to enable/disable subtypes of disabled IMEs.
            continue;
        }
        final HashSet<String> enabledSubtypesSet = enabledSubtypes.get(id);
        final int subtypeCount = imi.getSubtypeCount();
        for (int i = 0; i < subtypeCount; ++i) {
            final InputMethodSubtype subtype = imi.getSubtypeAt(i);
            final String hashCode = String.valueOf(subtype.hashCode());
            if (DEBUG) {
                Log.d(TAG, "--- Set checked state: " + "id" + ", " + hashCode + ", " + enabledSubtypesSet.contains(hashCode));
            }
            final TwoStatePreference pref = (TwoStatePreference) preferenceScreen.findPreference(id + hashCode);
            if (pref != null) {
                pref.setChecked(enabledSubtypesSet.contains(hashCode));
            }
        }
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) TwoStatePreference(android.support.v7.preference.TwoStatePreference) PreferenceScreen(android.support.v7.preference.PreferenceScreen) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Aggregations

InputMethodInfo (android.view.inputmethod.InputMethodInfo)309 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)113 ArrayList (java.util.ArrayList)80 RemoteException (android.os.RemoteException)53 ServiceInfo (android.content.pm.ServiceInfo)34 ComponentName (android.content.ComponentName)33 Intent (android.content.Intent)33 Context (android.content.Context)32 InputMethodManager (android.view.inputmethod.InputMethodManager)29 ApplicationInfo (android.content.pm.ApplicationInfo)27 PendingIntent (android.app.PendingIntent)24 Test (org.junit.Test)24 ResolveInfo (android.content.pm.ResolveInfo)19 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 InputMethodPreference (com.android.settingslib.inputmethod.InputMethodPreference)14 List (java.util.List)14 PackageManager (android.content.pm.PackageManager)13 Drawable (android.graphics.drawable.Drawable)13 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 Printer (android.util.Printer)12