Source:
private void buildAutodownloadSelectedNetworsPreference() { final Activity activity = ui.getActivity(); if (selectedNetworks != null) { clearAutodownloadSelectedNetworsPreference(); } WifiManager wifiservice = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); if (networks != null) { selectedNetworks = new CheckBoxPreference[networks.size()]; List<String> prefValues = Arrays.asList(UserPreferences .getAutodownloadSelectedNetworks()); PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); Preference.OnPreferenceClickListener clickListener = preference -> { if (preference instanceof CheckBoxPreference) { String key = preference.getKey(); ArrayList<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) { prefValuesList.remove(index); } else if (index < 0 && newValue) { prefValuesList.add(key); } UserPreferences.setAutodownloadSelectedNetworks( prefValuesList.toArray(new String[prefValuesList.size()]) ); return true; } else { return false; } }; 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); } } else { Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); } }

Target:
private void buildAutodownloadSelectedNetworsPreference() { final Activity activity = ui.getActivity(); if (selectedNetworks != null) { clearAutodownloadSelectedNetworsPreference(); } WifiManager wifiservice = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); if (networks != null) { selectedNetworks = new CheckBoxPreference[networks.size()]; List<String> prefValues = Arrays.asList(UserPreferences .getAutodownloadSelectedNetworks()); PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); 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) { prefValuesList.remove(index); } else if (index < 0 && newValue) { prefValuesList.add(key); } UserPreferences.setAutodownloadSelectedNetworks( prefValuesList.toArray(new String[prefValuesList.size()]) ); return true; } else { return false; } }; 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); } } else { Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); } }