use of androidx.preference.CheckBoxPreference in project packages_apps_AicpExtras by AICP.
the class LogIt method updateEnabledState.
protected void updateEnabledState(CheckBoxPreference changedPref, boolean newValue) {
final CheckBoxPreference[] logSelectors = { mLogcat, mLogcatRadio, mKmsg, mDmesg };
boolean enabled = newValue;
// Enabled if any checkbox is checked
if (!enabled) {
for (CheckBoxPreference pref : logSelectors) {
if (pref == changedPref) {
// Checked status not up-to-date, we use newValue for that
continue;
}
if (pref.isChecked()) {
enabled = true;
break;
}
}
}
mAicpLogIt.setEnabled(enabled);
}
use of androidx.preference.CheckBoxPreference in project AntennaPod by AntennaPod.
the class AutoDownloadPreferencesFragment method buildAutodownloadSelectedNetworksPreference.
// getConfiguredNetworks needs location permission starting with API 29
@SuppressLint("MissingPermission")
private void buildAutodownloadSelectedNetworksPreference() {
if (Build.VERSION.SDK_INT >= 29) {
return;
}
final Activity activity = getActivity();
if (selectedNetworks != null) {
clearAutodownloadSelectedNetworsPreference();
}
// get configured networks
WifiManager wifiservice = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
if (networks == null) {
Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
return;
}
Collections.sort(networks, (x, y) -> blankIfNull(x.SSID).compareToIgnoreCase(blankIfNull(y.SSID)));
selectedNetworks = new CheckBoxPreference[networks.size()];
List<String> prefValues = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
PreferenceScreen prefScreen = getPreferenceScreen();
Preference.OnPreferenceClickListener clickListener = preference -> {
if (preference instanceof CheckBoxPreference) {
String key = preference.getKey();
List<String> prefValuesList = new ArrayList<>(Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks()));
boolean newValue = ((CheckBoxPreference) preference).isChecked();
Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
int index = prefValuesList.indexOf(key);
if (index >= 0 && !newValue) {
// remove network
prefValuesList.remove(index);
} else if (index < 0 && newValue) {
prefValuesList.add(key);
}
UserPreferences.setAutodownloadSelectedNetworks(prefValuesList.toArray(new String[0]));
return true;
} else {
return false;
}
};
// value
for (int i = 0; i < networks.size(); i++) {
WifiConfiguration config = networks.get(i);
CheckBoxPreference pref = new CheckBoxPreference(activity);
String key = Integer.toString(config.networkId);
pref.setTitle(config.SSID);
pref.setKey(key);
pref.setOnPreferenceClickListener(clickListener);
pref.setPersistent(false);
pref.setChecked(prefValues.contains(key));
selectedNetworks[i] = pref;
prefScreen.addPreference(pref);
}
}
use of androidx.preference.CheckBoxPreference in project collect by opendatakit.
the class FormManagementPreferencesFragment method updateDisabledPrefs.
private void updateDisabledPrefs() {
Settings generalSettings = settingsProvider.getUnprotectedSettings();
// Might be null if disabled in Protected settings
@Nullable Preference updateFrequency = findPreference(KEY_PERIODIC_FORM_UPDATES_CHECK);
@Nullable CheckBoxPreference automaticDownload = findPreference(KEY_AUTOMATIC_UPDATE);
if (generalSettings.getString(KEY_PROTOCOL).equals(ProjectKeys.PROTOCOL_GOOGLE_SHEETS)) {
displayDisabled(findPreference(KEY_FORM_UPDATE_MODE), getString(R.string.manual));
if (automaticDownload != null) {
displayDisabled(automaticDownload, false);
}
if (updateFrequency != null) {
updateFrequency.setEnabled(false);
}
} else {
switch(getFormUpdateMode(requireContext(), generalSettings)) {
case MANUAL:
if (automaticDownload != null) {
displayDisabled(automaticDownload, false);
}
if (updateFrequency != null) {
updateFrequency.setEnabled(false);
}
break;
case PREVIOUSLY_DOWNLOADED_ONLY:
if (automaticDownload != null) {
automaticDownload.setEnabled(true);
automaticDownload.setChecked(generalSettings.getBoolean(KEY_AUTOMATIC_UPDATE));
}
if (updateFrequency != null) {
updateFrequency.setEnabled(true);
}
break;
case MATCH_EXACTLY:
if (automaticDownload != null) {
displayDisabled(automaticDownload, true);
}
if (updateFrequency != null) {
updateFrequency.setEnabled(true);
}
break;
}
}
}
use of androidx.preference.CheckBoxPreference in project collect by opendatakit.
the class FormEntryAccessPreferencesFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
addPreferencesFromResource(R.xml.form_entry_access_preferences);
findPreference(KEY_MOVING_BACKWARDS).setOnPreferenceChangeListener((preference, newValue) -> {
if (((CheckBoxPreference) preference).isChecked()) {
new MovingBackwardsDialog().show(getActivity().getSupportFragmentManager(), MOVING_BACKWARDS_DIALOG_TAG);
} else {
SimpleDialog.newInstance(getActivity().getString(R.string.moving_backwards_enabled_title), 0, getActivity().getString(R.string.moving_backwards_enabled_message), getActivity().getString(R.string.ok), false).show(((CollectAbstractActivity) getActivity()).getSupportFragmentManager(), SimpleDialog.COLLECT_DIALOG_TAG);
onMovingBackwardsEnabled();
}
return true;
});
findPreference(KEY_JUMP_TO).setEnabled(settingsProvider.getProtectedSettings().getBoolean(ALLOW_OTHER_WAYS_OF_EDITING_FORM));
findPreference(KEY_SAVE_MID).setEnabled(settingsProvider.getProtectedSettings().getBoolean(ALLOW_OTHER_WAYS_OF_EDITING_FORM));
}
use of androidx.preference.CheckBoxPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RestrictedAppDetailsTest method refreshUi_displayPreference.
@Test
public void refreshUi_displayPreference() throws Exception {
doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfoAsUser(PACKAGE_NAME, 0, USER_ID);
doReturn(APP_NAME).when(mPackageManager).getApplicationLabel(mApplicationInfo);
doReturn(true).when(mRestrictedAppDetails.mBatteryUtils).isForceAppStandbyEnabled(UID, PACKAGE_NAME);
final SparseLongArray timestampArray = new SparseLongArray();
timestampArray.put(UID, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(5));
doReturn(timestampArray).when(mBatteryDatabaseManager).queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
mRestrictedAppDetails.refreshUi();
assertThat(mRestrictedAppDetails.mRestrictedAppListGroup.getPreferenceCount()).isEqualTo(1);
final CheckBoxPreference preference = (CheckBoxPreference) mRestrictedAppDetails.mRestrictedAppListGroup.getPreference(0);
assertThat(preference.getTitle()).isEqualTo(APP_NAME);
assertThat(preference.isChecked()).isTrue();
assertThat(preference.getSummary()).isEqualTo("Restricted 5 hours ago");
}
Aggregations