use of android.preference.ListPreference in project NetGuard by M66B.
the class ActivitySettings method onSharedPreferenceChanged.
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
// Pro features
if ("theme".equals(name)) {
if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) {
prefs.edit().putString(name, "teal").apply();
((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal");
startActivity(new Intent(this, ActivityPro.class));
return;
}
} else if ("install".equals(name)) {
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_NOTIFY, this)) {
prefs.edit().putBoolean(name, false).apply();
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false);
startActivity(new Intent(this, ActivityPro.class));
return;
}
} else if ("show_stats".equals(name)) {
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) {
prefs.edit().putBoolean(name, false).apply();
startActivity(new Intent(this, ActivityPro.class));
return;
}
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(prefs.getBoolean(name, false));
}
Object value = prefs.getAll().get(name);
if (value instanceof String && "".equals(value))
prefs.edit().remove(name).apply();
// Dependencies
if ("screen_on".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("whitelist_other".equals(name) || "screen_other".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("whitelist_roaming".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("auto_enable".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_auto, prefs.getString(name, "0")));
else if ("screen_delay".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_delay, prefs.getString(name, "0")));
else if ("theme".equals(name) || "dark_theme".equals(name))
recreate();
else if ("subnet".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("tethering".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("lan".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("ip6".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("wifi_homes".equals(name)) {
MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen().findPreference(name);
Set<String> ssid = prefs.getStringSet(name, new HashSet<String>());
if (ssid.size() > 0)
pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid)));
else
pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-"));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("use_metered".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("national_roaming".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("eu_roaming".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("disable_on_call".equals(name)) {
if (prefs.getBoolean(name, false)) {
if (checkPermissions(name))
ServiceSinkhole.reload("changed " + name, this, false);
} else
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("lockdown_wifi".equals(name) || "lockdown_other".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("manage_system".equals(name)) {
boolean manage = prefs.getBoolean(name, false);
if (!manage)
prefs.edit().putBoolean("show_user", true).apply();
prefs.edit().putBoolean("show_system", manage).apply();
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("log_app".equals(name)) {
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset);
} else if ("filter".equals(name)) {
// Show dialog
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && prefs.getBoolean(name, false)) {
LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this);
View view = inflater.inflate(R.layout.filter, null, false);
dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
dialogFilter = null;
}
}).create();
dialogFilter.show();
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !prefs.getBoolean(name, false)) {
prefs.edit().putBoolean(name, true).apply();
Toast.makeText(ActivitySettings.this, R.string.msg_filter4, Toast.LENGTH_SHORT).show();
}
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(prefs.getBoolean(name, false));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("use_hosts".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("vpn4".equals(name)) {
String vpn4 = prefs.getString(name, null);
try {
checkAddress(vpn4);
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(vpn4))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_vpn4, prefs.getString(name, "10.1.10.1")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("vpn6".equals(name)) {
String vpn6 = prefs.getString(name, null);
try {
checkAddress(vpn6);
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(vpn6))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_vpn6, prefs.getString(name, "fd00:1:fd00:1:fd00:1:fd00:1")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("dns".equals(name) || "dns2".equals(name)) {
String dns = prefs.getString(name, null);
try {
checkAddress(dns);
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(dns))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_dns, prefs.getString(name, Util.getDefaultDNS(this).get("dns".equals(name) ? 0 : 1))));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("ttl".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_ttl, prefs.getString(name, "259200")));
else if ("rcode".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_rcode, prefs.getString(name, "3")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_enabled".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("socks5_addr".equals(name)) {
String socks5_addr = prefs.getString(name, null);
try {
if (!TextUtils.isEmpty(socks5_addr) && !Util.isNumericAddress(socks5_addr))
throw new IllegalArgumentException("Bad address");
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(socks5_addr))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_addr, prefs.getString(name, "-")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_port".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_port, prefs.getString(name, "-")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_username".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_username, prefs.getString(name, "-")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_password".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_password, TextUtils.isEmpty(prefs.getString(name, "")) ? "-" : "*****"));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) {
if ("pcap_record_size".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64")));
else
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2")));
ServiceSinkhole.setPcap(false, this);
File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");
if (pcap_file.exists() && !pcap_file.delete())
Log.w(TAG, "Delete PCAP failed");
if (prefs.getBoolean("pcap", false))
ServiceSinkhole.setPcap(true, this);
} else if ("watchdog".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_watchdog, prefs.getString(name, "0")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("show_stats".equals(name))
ServiceSinkhole.reloadStats("changed " + name, this);
else if ("stats_frequency".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000")));
else if ("stats_samples".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90")));
else if ("hosts_url".equals(name))
getPreferenceScreen().findPreference(name).setSummary(prefs.getString(name, "http://www.netguard.me/hosts"));
else if ("loglevel".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
}
use of android.preference.ListPreference in project Bilal by cdjalel.
the class SettingsActivity method setListPrefSummary.
private static int setListPrefSummary(Preference pref, String value) {
ListPreference listPref = (ListPreference) pref;
int index = listPref.findIndexOfValue(value);
listPref.setSummary(index >= 0 ? listPref.getEntries()[index] : null);
return index;
}
use of android.preference.ListPreference in project afwall by ukanth.
the class SecPreferenceFragment method checkFingerprintDeviceSupport.
@TargetApi(Build.VERSION_CODES.M)
private void checkFingerprintDeviceSupport() {
// Initializing both Android Keyguard Manager and Fingerprint Manager
KeyguardManager keyguardManager = (KeyguardManager) globalContext.getSystemService(KEYGUARD_SERVICE);
FingerprintManager fingerprintManager = (FingerprintManager) globalContext.getSystemService(FINGERPRINT_SERVICE);
ListPreference itemList = (ListPreference) findPreference("passSetting");
// Check whether the device has a Fingerprint sensor.
if (!fingerprintManager.isHardwareDetected()) {
Api.toast(globalContext, getString(R.string.device_with_no_fingerprint_sensor));
itemList.setValueIndex(0);
} else {
// Checks whether fingerprint permission is set on manifest
if (ActivityCompat.checkSelfPermission(globalContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
Api.toast(globalContext, getString(R.string.fingerprint_permission_manifest_missing));
itemList.setValueIndex(0);
} else {
// Check whether at least one fingerprint is registered
if (!fingerprintManager.hasEnrolledFingerprints()) {
Api.toast(globalContext, getString(R.string.register_at_least_one_fingerprint));
itemList.setValueIndex(0);
} else {
// Checks whether lock screen security is enabled or not
if (!keyguardManager.isKeyguardSecure()) {
Api.toast(globalContext, getString(R.string.lock_screen_not_enabled));
itemList.setValueIndex(0);
} else {
// Anything is ok
if (!G.isFingerprintEnabled()) {
G.isFingerprintEnabled(true);
// make sure we set the index
itemList.setValueIndex(3);
Api.toast(globalContext, getString(R.string.fingerprint_enabled_successfully));
}
return;
}
}
}
}
}
use of android.preference.ListPreference in project afwall by ukanth.
the class ExpPreferenceFragment method setupInitDir.
private void setupInitDir(Preference initd) {
ListPreference listPreference = (ListPreference) initd;
final Context ctx = getActivity().getApplicationContext();
listPreference.setOnPreferenceChangeListener((preference, newValue) -> {
String selected = newValue.toString();
// fix leak enabled - but user trying to change the path
if (!selected.equals(G.initPath()) && G.fixLeak()) {
deleteFiles(ctx, false);
G.initPath(selected);
updateFixLeakScript(true);
return true;
}
return true;
});
List<String> listSupportedDir = new ArrayList<>();
// going through the list of known initDirectories
for (String dir : initDirs) {
File file = new File(dir);
// path exists
if (file.exists() && file.isDirectory()) {
listSupportedDir.add(dir);
}
}
// some path exists
if (listSupportedDir.size() > 0) {
String[] entries = listSupportedDir.toArray(new String[listSupportedDir.size()]);
listPreference.setEntries(entries);
listPreference.setEntryValues(entries);
}
if (G.initPath() != null && !G.initPath().isEmpty()) {
listPreference.setValue(G.initPath());
} else {
CheckBoxPreference fixLeakPref = (CheckBoxPreference) findPreference("fixLeak");
fixLeakPref.setEnabled(false);
}
setupFixLeak(findPreference("fixLeak"), this.getActivity().getApplicationContext());
}
use of android.preference.ListPreference in project openScale by oliexdev.
the class BackupPreferences method updatePrefSummary.
private void updatePrefSummary(Preference p) {
if (p instanceof ListPreference) {
ListPreference listPref = (ListPreference) p;
p.setSummary(listPref.getEntry());
}
if (p instanceof EditTextPreference) {
EditTextPreference editTextPref = (EditTextPreference) p;
if (p.getTitle().toString().contains("assword")) {
p.setSummary("******");
} else {
p.setSummary(editTextPref.getText());
}
}
if (p instanceof MultiSelectListPreference) {
MultiSelectListPreference editMultiListPref = (MultiSelectListPreference) p;
CharSequence[] entries = editMultiListPref.getEntries();
CharSequence[] entryValues = editMultiListPref.getEntryValues();
List<String> currentEntries = new ArrayList<>();
Set<String> currentEntryValues = editMultiListPref.getValues();
for (int i = 0; i < entries.length; i++) {
if (currentEntryValues.contains(entryValues[i].toString()))
currentEntries.add(entries[i].toString());
}
p.setSummary(currentEntries.toString());
}
}
Aggregations