Search in sources :

Example 1 with UserDictionarySettings

use of com.android.settings.UserDictionarySettings in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndLanguageSettings method updateUserDictionaryPreference.

private void updateUserDictionaryPreference(Preference userDictionaryPreference) {
    if (userDictionaryPreference == null) {
        return;
    }
    final Activity activity = getActivity();
    final TreeSet<String> localeSet = UserDictionaryList.getUserDictionaryLocalesSet(activity);
    if (null == localeSet) {
        // The locale list is null if and only if the user dictionary service is
        // not present or disabled. In this case we need to remove the preference.
        getPreferenceScreen().removePreference(userDictionaryPreference);
    } else {
        userDictionaryPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                // Redirect to UserDictionarySettings if the user needs only one
                // language.
                final Bundle extras = new Bundle();
                final Class<? extends Fragment> targetFragment;
                if (localeSet.size() <= 1) {
                    if (!localeSet.isEmpty()) {
                        // If the size of localeList is 0, we don't set the locale
                        // parameter in the extras. This will be interpreted by the
                        // UserDictionarySettings class as meaning
                        // "the current locale". Note that with the current code for
                        // UserDictionaryList#getUserDictionaryLocalesSet()
                        // the locale list always has at least one element, since it
                        // always includes the current locale explicitly.
                        // @see UserDictionaryList.getUserDictionaryLocalesSet().
                        extras.putString("locale", localeSet.first());
                    }
                    targetFragment = UserDictionarySettings.class;
                } else {
                    targetFragment = UserDictionaryList.class;
                }
                startFragment(InputMethodAndLanguageSettings.this, targetFragment.getCanonicalName(), -1, -1, extras);
                return true;
            }
        });
    }
}
Also used : OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) UserDictionarySettings(com.android.settings.UserDictionarySettings) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) Bundle(android.os.Bundle) SettingsActivity(com.android.settings.SettingsActivity) KeyboardLayoutPickerActivity(com.android.settings.Settings.KeyboardLayoutPickerActivity) Activity(android.app.Activity) SettingsPreferenceFragment(com.android.settings.SettingsPreferenceFragment) Fragment(android.app.Fragment)

Aggregations

Activity (android.app.Activity)1 Fragment (android.app.Fragment)1 Bundle (android.os.Bundle)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)1 KeyboardLayoutPickerActivity (com.android.settings.Settings.KeyboardLayoutPickerActivity)1 SettingsActivity (com.android.settings.SettingsActivity)1 SettingsPreferenceFragment (com.android.settings.SettingsPreferenceFragment)1 UserDictionarySettings (com.android.settings.UserDictionarySettings)1