Search in sources :

Example 16 with CheckBoxPreference

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);
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference)

Example 17 with CheckBoxPreference

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);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) Arrays(java.util.Arrays) Bundle(android.os.Bundle) R(de.danoeh.antennapod.R) Preference(androidx.preference.Preference) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) ArrayList(java.util.ArrayList) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) WifiManager(android.net.wifi.WifiManager) SuppressLint(android.annotation.SuppressLint) CheckBoxPreference(androidx.preference.CheckBoxPreference) List(java.util.List) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) ListPreference(androidx.preference.ListPreference) Build(android.os.Build) Activity(android.app.Activity) Collections(java.util.Collections) Log(android.util.Log) Resources(android.content.res.Resources) WifiConfiguration(android.net.wifi.WifiConfiguration) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) PreferenceScreen(androidx.preference.PreferenceScreen) CheckBoxPreference(androidx.preference.CheckBoxPreference) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Activity(android.app.Activity) SuppressLint(android.annotation.SuppressLint) Preference(androidx.preference.Preference) CheckBoxPreference(androidx.preference.CheckBoxPreference) ListPreference(androidx.preference.ListPreference) ArrayList(java.util.ArrayList) List(java.util.List) SuppressLint(android.annotation.SuppressLint)

Example 18 with CheckBoxPreference

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;
        }
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) CheckBoxPreference(androidx.preference.CheckBoxPreference) Settings(org.odk.collect.shared.settings.Settings) Nullable(androidx.annotation.Nullable)

Example 19 with CheckBoxPreference

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));
}
Also used : MovingBackwardsDialog(org.odk.collect.android.fragments.dialogs.MovingBackwardsDialog) CheckBoxPreference(androidx.preference.CheckBoxPreference)

Example 20 with CheckBoxPreference

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");
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SparseLongArray(android.util.SparseLongArray) Test(org.junit.Test)

Aggregations

CheckBoxPreference (androidx.preference.CheckBoxPreference)36 Test (org.junit.Test)16 NotificationListenerFilter (android.service.notification.NotificationListenerFilter)14 Preference (androidx.preference.Preference)8 ListPreference (androidx.preference.ListPreference)7 Bundle (android.os.Bundle)6 VersionedPackage (android.content.pm.VersionedPackage)4 SparseLongArray (android.util.SparseLongArray)4 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)4 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)4 Context (android.content.Context)3 SharedPreferences (android.content.SharedPreferences)3 PackageManager (android.content.pm.PackageManager)3 ArraySet (android.util.ArraySet)3 EditTextPreference (androidx.preference.EditTextPreference)3 PreferenceCategory (androidx.preference.PreferenceCategory)3 SeekBarPreference (androidx.preference.SeekBarPreference)3 ArrayList (java.util.ArrayList)3 ApplicationInfo (android.content.pm.ApplicationInfo)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2