From b291c10c710e6c796cf411a4680550c77a01d026 Mon Sep 17 00:00:00 2001 From: huangyz0918 Date: Wed, 14 Aug 2019 16:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20added=20reset=20settings=20?= =?UTF-8?q?option,=20closes=20#299=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/ui/settings/PreferenceKeys.java | 1 + .../views/ui/settings/SettingsActivity.java | 23 +++++++++++++++++++ .../res/drawable/ic_refresh_black_24dp.xml | 9 ++++++++ .../src/main/res/values/strings.xml | 4 ++++ .../src/main/res/xml/preferences_menu.xml | 6 +++++ 5 files changed, 43 insertions(+) create mode 100644 skunkworks_crow/src/main/res/drawable/ic_refresh_black_24dp.xml diff --git a/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/PreferenceKeys.java b/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/PreferenceKeys.java index 8d026d51..9d70f36c 100644 --- a/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/PreferenceKeys.java +++ b/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/PreferenceKeys.java @@ -13,6 +13,7 @@ public class PreferenceKeys { public static final String KEY_DEFAULT_TRANSFER_METHOD = "default_transfer_method"; public static final String KEY_BLUETOOTH_NAME = "bluetooth_name"; public static final String KEY_BLUETOOTH_SECURE_MODE = "bluetooth_secure_mode"; + public static final String KEY_RESET_SETTINGS = "reset_settings"; private PreferenceKeys() { diff --git a/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/SettingsActivity.java b/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/SettingsActivity.java index 45cd3b46..3ad1b597 100644 --- a/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/SettingsActivity.java +++ b/skunkworks_crow/src/main/java/org/odk/share/views/ui/settings/SettingsActivity.java @@ -1,6 +1,7 @@ package org.odk.share.views.ui.settings; import android.bluetooth.BluetoothAdapter; +import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; @@ -35,6 +36,7 @@ public class SettingsActivity extends PreferenceActivity { EditTextPreference hotspotNamePreference; EditTextPreference bluetoothNamePreference; Preference hotspotPasswordPreference; + Preference resetPreference; CheckBoxPreference passwordRequirePreference; CheckBoxPreference btSecureModePreference; EditTextPreference odkDestinationDirPreference; @@ -62,6 +64,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void addPreferences() { + resetPreference = findPreference(PreferenceKeys.KEY_RESET_SETTINGS); defaultMethodPreference = (ListPreference) findPreference(PreferenceKeys.KEY_DEFAULT_TRANSFER_METHOD); hotspotNamePreference = (EditTextPreference) findPreference(PreferenceKeys.KEY_HOTSPOT_NAME); bluetoothNamePreference = (EditTextPreference) findPreference(PreferenceKeys.KEY_BLUETOOTH_NAME); @@ -94,6 +97,7 @@ private void addPreferences() { odkDestinationDirPreference.setOnPreferenceChangeListener(preferenceChangeListener()); defaultMethodPreference.setOnPreferenceChangeListener(preferenceChangeListener()); + resetPreference.setOnPreferenceClickListener(preferenceClickListener()); hotspotPasswordPreference.setOnPreferenceClickListener(preferenceClickListener()); } @@ -103,6 +107,9 @@ private Preference.OnPreferenceClickListener preferenceClickListener() { case PreferenceKeys.KEY_HOTSPOT_PASSWORD: showPasswordDialog(); break; + case PreferenceKeys.KEY_RESET_SETTINGS: + resetSettings(); + break; } return false; }; @@ -196,4 +203,20 @@ private void showPasswordDialog() { alertDialog.setCancelable(true); alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } + + private void resetSettings() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.title_reset_settings)) + .setMessage(getString(R.string.message_reset_settings)) + .setPositiveButton(getString(R.string.ok), (DialogInterface dialog, int which) -> { + SharedPreferences.Editor editor = prefs.edit(); + editor.clear(); + editor.apply(); + Toast.makeText(this, getString(R.string.success_reset_settings), Toast.LENGTH_LONG).show(); + finish(); + }) + .setNegativeButton(getString(R.string.cancel), (DialogInterface dialog, int which) -> { + dialog.dismiss(); + }).create().show(); + } } diff --git a/skunkworks_crow/src/main/res/drawable/ic_refresh_black_24dp.xml b/skunkworks_crow/src/main/res/drawable/ic_refresh_black_24dp.xml new file mode 100644 index 00000000..8229a9a6 --- /dev/null +++ b/skunkworks_crow/src/main/res/drawable/ic_refresh_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/skunkworks_crow/src/main/res/values/strings.xml b/skunkworks_crow/src/main/res/values/strings.xml index f0a81b9a..13098105 100644 --- a/skunkworks_crow/src/main/res/values/strings.xml +++ b/skunkworks_crow/src/main/res/values/strings.xml @@ -136,6 +136,10 @@ The destination should not be empty Location Permission Needed Enable location from the settings. + Click to reset all preferences + Reset Settings + Are you sure to reset all the settings? + Reset success, open settings to see changes Switch Refresh diff --git a/skunkworks_crow/src/main/res/xml/preferences_menu.xml b/skunkworks_crow/src/main/res/xml/preferences_menu.xml index a1cd473b..4f0e6d21 100644 --- a/skunkworks_crow/src/main/res/xml/preferences_menu.xml +++ b/skunkworks_crow/src/main/res/xml/preferences_menu.xml @@ -18,6 +18,12 @@ android:summary="@string/preference_default_method_summary" android:title="@string/preference_default_method" /> + +