From 5757c66e7969a1bcfa58078169ab0dbbc28c6901 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 1 Feb 2016 18:19:25 +0100 Subject: [PATCH] Use checkbox preferences for Android < 5.0 SwitchCompat cannot be used because there is currently no MultiSelectListPreference --- .../faircode/netguard/ActivitySettings.java | 22 +- app/src/main/res/xml-v14/preferences.xml | 206 ++++++++++++++++++ .../main/res/{xml => xml-v21}/preferences.xml | 0 3 files changed, 217 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/xml-v14/preferences.xml rename app/src/main/res/{xml => xml-v21}/preferences.xml (100%) diff --git a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java index a3601777..5864cfdf 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java @@ -45,7 +45,7 @@ import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; -import android.preference.SwitchPreference; +import android.preference.TwoStatePreference; import android.support.annotation.NonNull; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.AppCompatActivity; @@ -292,16 +292,16 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere prefs.edit().putBoolean("unmetered_3g", false).apply(); prefs.edit().putBoolean("unmetered_4g", false).apply(); - ((SwitchPreference) screen.findPreference("unmetered_2g")).setChecked(false); - ((SwitchPreference) screen.findPreference("unmetered_3g")).setChecked(false); - ((SwitchPreference) screen.findPreference("unmetered_4g")).setChecked(false); + ((TwoStatePreference) screen.findPreference("unmetered_2g")).setChecked(false); + ((TwoStatePreference) screen.findPreference("unmetered_3g")).setChecked(false); + ((TwoStatePreference) screen.findPreference("unmetered_4g")).setChecked(false); } // Check if permission was revoked if (prefs.getBoolean("national_roaming", false)) if (!Util.hasPhoneStatePermission(this)) { prefs.edit().putBoolean("national_roaming", false).apply(); - ((SwitchPreference) screen.findPreference("national_roaming")).setChecked(false); + ((TwoStatePreference) screen.findPreference("national_roaming")).setChecked(false); } // Listen for preference changes @@ -356,7 +356,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere } else if ("show_stats".equals(name)) { if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) { prefs.edit().putBoolean(name, false).apply(); - ((SwitchPreference) getPreferenceScreen().findPreference(name)).setChecked(false); + ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false); startActivity(new Intent(this, ActivityPro.class)); return; } @@ -525,9 +525,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere prefs.edit().putBoolean("unmetered_2g", false).apply(); prefs.edit().putBoolean("unmetered_3g", false).apply(); prefs.edit().putBoolean("unmetered_4g", false).apply(); - ((SwitchPreference) screen.findPreference("unmetered_2g")).setChecked(false); - ((SwitchPreference) screen.findPreference("unmetered_3g")).setChecked(false); - ((SwitchPreference) screen.findPreference("unmetered_4g")).setChecked(false); + ((TwoStatePreference) screen.findPreference("unmetered_2g")).setChecked(false); + ((TwoStatePreference) screen.findPreference("unmetered_3g")).setChecked(false); + ((TwoStatePreference) screen.findPreference("unmetered_4g")).setChecked(false); } else if (requestCode == REQUEST_ROAMING_NATIONAL) @@ -536,7 +536,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere else { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.edit().putBoolean("national_roaming", false).apply(); - ((SwitchPreference) screen.findPreference("national_roaming")).setChecked(false); + ((TwoStatePreference) screen.findPreference("national_roaming")).setChecked(false); } else if (requestCode == REQUEST_ROAMING_INTERNATIONAL) @@ -545,7 +545,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere else { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.edit().putBoolean("whitelist_roaming", false).apply(); - ((SwitchPreference) screen.findPreference("whitelist_roaming")).setChecked(false); + ((TwoStatePreference) screen.findPreference("whitelist_roaming")).setChecked(false); } } diff --git a/app/src/main/res/xml-v14/preferences.xml b/app/src/main/res/xml-v14/preferences.xml new file mode 100644 index 00000000..eec8cd97 --- /dev/null +++ b/app/src/main/res/xml-v14/preferences.xml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml-v21/preferences.xml similarity index 100% rename from app/src/main/res/xml/preferences.xml rename to app/src/main/res/xml-v21/preferences.xml