1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-01-01 12:54:07 +00:00

Use checkbox preferences for Android < 5.0

SwitchCompat cannot be used because there is currently no MultiSelectListPreference
This commit is contained in:
M66B 2016-02-01 18:19:25 +01:00
parent 29d1c26166
commit 5757c66e79
3 changed files with 217 additions and 11 deletions

View file

@ -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);
}
}

View file

@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="category_defaults"
android:title="@string/setting_defaults">
<CheckBoxPreference
android:defaultValue="true"
android:key="whitelist_wifi"
android:title="@string/setting_whitelist_wifi" />
<CheckBoxPreference
android:defaultValue="true"
android:key="whitelist_other"
android:title="@string/setting_whitelist_other" />
<CheckBoxPreference
android:defaultValue="false"
android:key="screen_wifi"
android:title="@string/setting_screen_wifi" />
<CheckBoxPreference
android:defaultValue="false"
android:key="screen_other"
android:title="@string/setting_screen_other" />
<CheckBoxPreference
android:defaultValue="true"
android:key="whitelist_roaming"
android:title="@string/setting_whitelist_roaming" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_options"
android:title="@string/setting_options">
<ListPreference
android:defaultValue="teal"
android:entries="@array/themeNames"
android:entryValues="@array/themeValues"
android:key="theme" />
<CheckBoxPreference
android:defaultValue="false"
android:key="dark_theme"
android:title="@string/setting_dark" />
<EditTextPreference
android:defaultValue="0"
android:inputType="number"
android:key="auto_enable"
android:summary="@string/summary_auto" />
<EditTextPreference
android:defaultValue="0"
android:inputType="number"
android:key="screen_delay"
android:summary="@string/summary_delay" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_options"
android:title="@string/setting_network_options">
<CheckBoxPreference
android:defaultValue="false"
android:key="tethering"
android:title="@string/setting_tethering" />
<MultiSelectListPreference
android:defaultValue="@array/default_wifi_home"
android:key="wifi_homes"
android:summary="@string/summary_wifi_home" />
<CheckBoxPreference
android:defaultValue="false"
android:key="use_metered"
android:summary="@string/summary_metered"
android:title="@string/setting_metered" />
<CheckBoxPreference
android:defaultValue="false"
android:key="unmetered_2g"
android:summary="@string/summary_metered_2g"
android:title="@string/setting_metered_2g" />
<CheckBoxPreference
android:defaultValue="false"
android:key="unmetered_3g"
android:summary="@string/summary_metered_3g"
android:title="@string/setting_metered_3g" />
<CheckBoxPreference
android:defaultValue="false"
android:key="unmetered_4g"
android:summary="@string/summary_metered_4g"
android:title="@string/setting_metered_4g" />
<CheckBoxPreference
android:defaultValue="false"
android:key="national_roaming"
android:summary="@string/summary_national_roaming"
android:title="@string/setting_national_roaming" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_advanced_options"
android:title="@string/setting_advanced_options">
<CheckBoxPreference
android:defaultValue="false"
android:key="manage_system"
android:summary="@string/summary_system"
android:title="@string/setting_system" />
<CheckBoxPreference
android:defaultValue="false"
android:key="log_app"
android:summary="@string/summary_log_app"
android:title="@string/setting_log_app" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="log_app"
android:key="notify_access"
android:summary="@string/summary_access"
android:title="@string/setting_access" />
<CheckBoxPreference
android:defaultValue="false"
android:key="filter"
android:summary="@string/summary_filter"
android:title="@string/setting_filter" />
<CheckBoxPreference
android:defaultValue="true"
android:dependency="filter"
android:key="use_hosts"
android:summary="@string/summary_block_domains"
android:title="@string/setting_block_domains" />
<EditTextPreference
inputType="phone"
android:hint="10.1.10.1"
android:inputType="phone"
android:key="vpn4" />
<EditTextPreference
android:hint="fd00:1:fd00:1:fd00:1:fd00:1"
android:inputType="text"
android:key="vpn6" />
<EditTextPreference
android:dependency="filter"
android:inputType="text"
android:key="dns" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_stats"
android:title="@string/setting_stats_category">
<CheckBoxPreference
android:defaultValue="false"
android:key="show_stats"
android:summary="@string/summary_stats"
android:title="@string/setting_stats" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="show_stats"
android:key="show_top"
android:title="@string/setting_stats_top" />
<EditTextPreference
android:defaultValue="5"
android:dependency="show_stats"
android:inputType="number"
android:key="stats_base" />
<EditTextPreference
android:defaultValue="1000"
android:dependency="show_stats"
android:inputType="number"
android:key="stats_frequency" />
<EditTextPreference
android:defaultValue="90"
android:dependency="show_stats"
android:inputType="number"
android:key="stats_samples" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_backup"
android:title="@string/setting_backup">
<Preference
android:key="export"
android:title="@string/setting_export" />
<Preference
android:key="import"
android:title="@string/setting_import" />
<Preference
android:dependency="filter"
android:key="hosts"
android:summary="@string/summary_hosts"
android:title="@string/setting_hosts" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_development"
android:title="Development">
<ListPreference
android:defaultValue="4"
android:entries="@array/logLevelNames"
android:entryValues="@array/logLevelValues"
android:key="loglevel"
android:summary="Log level debug or verbose will impact performance and battery usage"
android:title="Native log level" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_technical"
android:title="@string/setting_technical">
<Preference
android:key="technical_info"
android:title="@string/setting_technical_general" />
<Preference
android:key="technical_network"
android:title="@string/setting_technical_networks" />
<Preference
android:key="technical_subscription"
android:title="@string/setting_technical_subscription" />
</PreferenceCategory>
</PreferenceScreen>