Search in sources :

Example 41 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndSubtypeEnabler method setAutoSelectionSubtypesEnabled.

private void setAutoSelectionSubtypesEnabled(final String imiId, final boolean autoSelectionEnabled) {
    final TwoStatePreference autoSelectionPref = mAutoSelectionPrefsMap.get(imiId);
    if (autoSelectionPref == null) {
        return;
    }
    autoSelectionPref.setChecked(autoSelectionEnabled);
    final List<Preference> subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId);
    for (final Preference pref : subtypePrefs) {
        if (pref instanceof TwoStatePreference) {
            // When autoSelectionEnabled is true, all subtype prefs need to be disabled with
            // implicitly checked subtypes. In case of false, all subtype prefs need to be
            // enabled.
            pref.setEnabled(!autoSelectionEnabled);
            if (autoSelectionEnabled) {
                ((TwoStatePreference) pref).setChecked(false);
            }
        }
    }
    if (autoSelectionEnabled) {
        InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, getContentResolver(), mInputMethodInfoList, mHaveHardKeyboard);
        updateImplicitlyEnabledSubtypes(imiId, true);
    }
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference)

Example 42 with Preference

use of android.support.v7.preference.Preference 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 43 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndSubtypeEnabler method onPreferenceChange.

@Override
public boolean onPreferenceChange(final Preference pref, final Object newValue) {
    if (!(newValue instanceof Boolean)) {
        // Invoke default behavior.
        return true;
    }
    final boolean isChecking = (Boolean) newValue;
    for (final String imiId : mAutoSelectionPrefsMap.keySet()) {
        // An auto select subtype preference is changing.
        if (mAutoSelectionPrefsMap.get(imiId) == pref) {
            final TwoStatePreference autoSelectionPref = (TwoStatePreference) pref;
            autoSelectionPref.setChecked(isChecking);
            // Enable or disable subtypes depending on the auto selection preference.
            setAutoSelectionSubtypesEnabled(imiId, autoSelectionPref.isChecked());
            return false;
        }
    }
    // A subtype preference is changing.
    if (pref instanceof InputMethodSubtypePreference) {
        final InputMethodSubtypePreference subtypePref = (InputMethodSubtypePreference) pref;
        subtypePref.setChecked(isChecking);
        if (!subtypePref.isChecked()) {
            // It takes care of the case where no subtypes are explicitly enabled then the auto
            // selection preference is going to be checked.
            updateAutoSelectionPreferences();
        }
        return false;
    }
    // Invoke default behavior.
    return true;
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference)

Example 44 with Preference

use of android.support.v7.preference.Preference 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 45 with Preference

use of android.support.v7.preference.Preference 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)

Aggregations

Preference (android.support.v7.preference.Preference)122 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 SwitchPreference (android.support.v14.preference.SwitchPreference)33 Intent (android.content.Intent)27 ListPreference (android.support.v7.preference.ListPreference)27 Context (android.content.Context)17 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)15 ArrayList (java.util.ArrayList)14 PackageManager (android.content.pm.PackageManager)11 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)11 PreferenceGroup (android.support.v7.preference.PreferenceGroup)11 TwoStatePreference (android.support.v7.preference.TwoStatePreference)11 Activity (android.app.Activity)10 View (android.view.View)10 Bundle (android.os.Bundle)9 TextView (android.widget.TextView)8 AlertDialog (android.support.v7.app.AlertDialog)7 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)7 DimmableIconPreference (com.android.settings.DimmableIconPreference)7