use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.
the class TypeFilterPreferenceController method updateState.
@Override
public void updateState(Preference pref) {
mNlf = mNm.getListenerFilter(mCn, mUserId);
CheckBoxPreference check = (CheckBoxPreference) pref;
check.setChecked(hasFlag(mNlf.getTypes(), getType()));
boolean disableRequestedByApp = false;
if (mSi != null) {
if (mSi.metaData != null && mSi.metaData.containsKey(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES)) {
String typeList = mSi.metaData.get(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES).toString();
if (typeList != null) {
int types = 0;
String[] typeStrings = typeList.split(FLAG_SEPARATOR);
for (int i = 0; i < typeStrings.length; i++) {
final String typeString = typeStrings[i];
if (TextUtils.isEmpty(typeString)) {
continue;
}
if (typeString.equalsIgnoreCase("ONGOING")) {
types |= FLAG_FILTER_TYPE_ONGOING;
} else if (typeString.equalsIgnoreCase("CONVERSATIONS")) {
types |= FLAG_FILTER_TYPE_CONVERSATIONS;
} else if (typeString.equalsIgnoreCase("SILENT")) {
types |= FLAG_FILTER_TYPE_SILENT;
} else if (typeString.equalsIgnoreCase("ALERTING")) {
types |= FLAG_FILTER_TYPE_ALERTING;
} else {
try {
types |= Integer.parseInt(typeString);
} catch (NumberFormatException e) {
// skip
}
}
}
if (hasFlag(types, getType())) {
disableRequestedByApp = true;
}
}
}
}
// Apps can prevent a category from being turned on, but not turned off
boolean disabledByApp = disableRequestedByApp && !check.isChecked();
pref.setEnabled(getAvailabilityStatus() == AVAILABLE && !disabledByApp);
}
use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.
the class RestrictedAppDetails method onBatteryTipHandled.
@Override
public void onBatteryTipHandled(BatteryTip batteryTip) {
final AppInfo appInfo;
final boolean isRestricted = batteryTip instanceof RestrictAppTip;
if (isRestricted) {
appInfo = ((RestrictAppTip) batteryTip).getRestrictAppList().get(0);
} else {
appInfo = ((UnrestrictAppTip) batteryTip).getUnrestrictAppInfo();
}
CheckBoxPreference preference = (CheckBoxPreference) mRestrictedAppListGroup.findPreference(getKeyFromAppInfo(appInfo));
if (preference != null) {
preference.setChecked(isRestricted);
}
}
use of androidx.preference.CheckBoxPreference in project openScale by oliexdev.
the class ReminderPreferences method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.reminder_preferences, rootKey);
setHasOptionsMenu(true);
reminderEnable = (CheckBoxPreference) findPreference(PREFERENCE_KEY_REMINDER_ENABLE);
final MultiSelectListPreference prefDays = findPreference("reminderWeekdays");
prefDays.setSummaryProvider(new Preference.SummaryProvider<MultiSelectListPreference>() {
@Override
public CharSequence provideSummary(MultiSelectListPreference preference) {
final String[] values = getResources().getStringArray(R.array.weekdays_values);
final String[] translated = getResources().getStringArray(R.array.weekdays_entries);
return IntStream.range(0, values.length).mapToObj(i -> new Pair<>(values[i], translated[i])).filter(p -> preference.getValues().contains(p.first)).map(p -> p.second).collect(Collectors.joining(", "));
}
});
updateAlarmPreferences();
}
use of androidx.preference.CheckBoxPreference in project openScale by oliexdev.
the class AboutPreferences method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.about_preferences, rootKey);
setHasOptionsMenu(true);
findPreference(KEY_APP_VERSION).setSummary(String.format("v%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
debugLog = (CheckBoxPreference) findPreference(KEY_DEBUG_LOG);
debugLog.setChecked(getEnabledFileDebugTree() != null);
debugLog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (debugLog.isChecked()) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
String fileName = String.format("openScale_%s.txt", format.format(new Date()));
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TITLE, fileName);
startActivityForResult(intent, DEBUG_LOG_REQUEST);
} else {
FileDebugTree tree = getEnabledFileDebugTree();
if (tree != null) {
Timber.d("Debug log disabled");
Timber.uproot(tree);
tree.close();
OpenScale.DEBUG_MODE = false;
}
}
return true;
}
});
}
use of androidx.preference.CheckBoxPreference in project RespawnIRC-Android by FranckRJ.
the class SettingsFragment method updatePrefDefaultValue.
/* Le but de la clef temporaire est de ne pas sauvegarder l'option par défaut si c'est celle ci
* qui est retourné par "PrefsManager.getX()". La clef temporaire n'est pas vide pour empêcher
* des possibles crash (des histoires de requireKey() etc). Elle est unique par type de pref pour
* ne pas causer de crash lors de l'assignation d'un string à ce qui était précédement un bool.
* La persistance est temporairement à false pour plus de sécurité, au cas où, dans le doute,
* mais ça reste plutôt assez moche comme solution au final. */
private static void updatePrefDefaultValue(Preference pref) {
String realPrefKey = pref.getKey();
pref.setPersistent(false);
if (pref instanceof CheckBoxPreference) {
pref.setKey("tmpKeyBool");
CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref;
checkBoxPref.setChecked(PrefsManager.getBool(realPrefKey));
} else if (pref instanceof SwitchPreferenceCompat) {
pref.setKey("tmpKeyBool");
SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) pref;
switchPref.setChecked(PrefsManager.getBool(realPrefKey));
} else if (pref instanceof EditTextPreference) {
pref.setKey("tmpKeyString");
EditTextPreference editTextPref = (EditTextPreference) pref;
editTextPref.setText(PrefsManager.getString(realPrefKey));
} else if (pref instanceof ListPreference) {
pref.setKey("tmpKeyString");
ListPreference listPref = (ListPreference) pref;
listPref.setValue(PrefsManager.getString(realPrefKey));
}
pref.setPersistent(true);
pref.setKey(realPrefKey);
}
Aggregations