use of android.support.v7.preference.TwoStatePreference 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 : "");
}
use of android.support.v7.preference.TwoStatePreference 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);
}
use of android.support.v7.preference.TwoStatePreference 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));
}
}
}
}
use of android.support.v7.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class InputMethodAndSubtypeEnabler method updateImplicitlyEnabledSubtypesOf.
private void updateImplicitlyEnabledSubtypesOf(final InputMethodInfo imi, final boolean check) {
final String imiId = imi.getId();
final List<Preference> subtypePrefs = mInputMethodAndSubtypePrefsMap.get(imiId);
final List<InputMethodSubtype> implicitlyEnabledSubtypes = mImm.getEnabledInputMethodSubtypeList(imi, true);
if (subtypePrefs == null || implicitlyEnabledSubtypes == null) {
return;
}
for (final Preference pref : subtypePrefs) {
if (!(pref instanceof TwoStatePreference)) {
continue;
}
final TwoStatePreference subtypePref = (TwoStatePreference) pref;
subtypePref.setChecked(false);
if (check) {
for (final InputMethodSubtype subtype : implicitlyEnabledSubtypes) {
final String implicitlyEnabledSubtypePrefKey = imiId + subtype.hashCode();
if (subtypePref.getKey().equals(implicitlyEnabledSubtypePrefKey)) {
subtypePref.setChecked(true);
break;
}
}
}
}
}
use of android.support.v7.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ConfigureNotificationSettings method initPulse.
// === Pulse notification light ===
private void initPulse() {
final NotificationManager nm = mContext.getSystemService(NotificationManager.class);
final PreferenceCategory category = (PreferenceCategory) findPreference("lights");
mNotificationPulse = (TwoStatePreference) category.findPreference(KEY_NOTIFICATION_PULSE);
if (mNotificationPulse == null) {
Log.i(TAG, "Preference not found: " + KEY_NOTIFICATION_PULSE);
return;
}
if (!getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed) || !nm.doLightsSupport(NotificationManager.LIGHTS_PULSATING_LED)) {
category.removePreference(mNotificationPulse);
} else {
updatePulse();
mNotificationPulse.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean val = (Boolean) newValue;
return Settings.System.putInt(getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, val ? 1 : 0);
}
});
}
}
Aggregations