Skip to content

Commit

Permalink
✨ feat: added reset settings option, closes getodk#299 .
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyz0918 committed Aug 14, 2019
1 parent a0a3445 commit b291c10
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,6 +36,7 @@ public class SettingsActivity extends PreferenceActivity {
EditTextPreference hotspotNamePreference;
EditTextPreference bluetoothNamePreference;
Preference hotspotPasswordPreference;
Preference resetPreference;
CheckBoxPreference passwordRequirePreference;
CheckBoxPreference btSecureModePreference;
EditTextPreference odkDestinationDirPreference;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -94,6 +97,7 @@ private void addPreferences() {
odkDestinationDirPreference.setOnPreferenceChangeListener(preferenceChangeListener());
defaultMethodPreference.setOnPreferenceChangeListener(preferenceChangeListener());

resetPreference.setOnPreferenceClickListener(preferenceClickListener());
hotspotPasswordPreference.setOnPreferenceClickListener(preferenceClickListener());
}

Expand All @@ -103,6 +107,9 @@ private Preference.OnPreferenceClickListener preferenceClickListener() {
case PreferenceKeys.KEY_HOTSPOT_PASSWORD:
showPasswordDialog();
break;
case PreferenceKeys.KEY_RESET_SETTINGS:
resetSettings();
break;
}
return false;
};
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
4 changes: 4 additions & 0 deletions skunkworks_crow/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
<string name="odk_destination_dir_error">The destination should not be empty</string>
<string name="location_permission_needed">Location Permission Needed</string>
<string name="location_settings_dialog">Enable location from the settings.</string>
<string name="reset_settings">Click to reset all preferences</string>
<string name="title_reset_settings">Reset Settings</string>
<string name="message_reset_settings">Are you sure to reset all the settings?</string>
<string name="success_reset_settings">Reset success, open settings to see changes</string>

<string name="switch_method">Switch</string>
<string name="btn_refresh">Refresh</string>
Expand Down
6 changes: 6 additions & 0 deletions skunkworks_crow/src/main/res/xml/preferences_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
android:summary="@string/preference_default_method_summary"
android:title="@string/preference_default_method" />

<Preference
android:icon="@drawable/ic_refresh_black_24dp"
android:key="reset_settings"
android:summary="@string/reset_settings"
android:title="@string/title_reset_settings" />

</PreferenceCategory>

<PreferenceCategory android:title="Hotspot Settings">
Expand Down

0 comments on commit b291c10

Please sign in to comment.