Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

[MRG] Add reset settings option. #300

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PreferenceKeys {
public static final String KEY_HOTSPOT_PASSWORD = "hotspot_password";
public static final String KEY_HOTSPOT_PWD_REQUIRE = "hotspot_pwd_require";
public static final String KEY_ODK_DESTINATION_DIR = "odk_destination_dir";
public static final String KEY_RESET_SETTINGS = "reset_settings";

private PreferenceKeys() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.odk.share.views.ui.settings;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -15,13 +16,13 @@
import android.view.WindowManager;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;

import com.google.android.material.textfield.TextInputLayout;

import org.odk.share.R;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;


/**
* Created by laksh on 5/27/2018.
Expand All @@ -31,6 +32,7 @@ public class SettingsActivity extends PreferenceActivity {

EditTextPreference hotspotNamePreference;
Preference hotspotPasswordPreference;
Preference resetPreference;
CheckBoxPreference passwordRequirePreference;
EditTextPreference odkDestinationDirPreference;
private SharedPreferences prefs;
Expand All @@ -56,6 +58,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void addPreferences() {
resetPreference = findPreference(PreferenceKeys.KEY_RESET_SETTINGS);
hotspotNamePreference = (EditTextPreference) findPreference(PreferenceKeys.KEY_HOTSPOT_NAME);
hotspotPasswordPreference = findPreference(PreferenceKeys.KEY_HOTSPOT_PASSWORD);
passwordRequirePreference = (CheckBoxPreference) findPreference(PreferenceKeys.KEY_HOTSPOT_PWD_REQUIRE);
Expand All @@ -77,6 +80,7 @@ private void addPreferences() {
passwordRequirePreference.setOnPreferenceChangeListener(preferenceChangeListener());
odkDestinationDirPreference.setOnPreferenceChangeListener(preferenceChangeListener());

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

Expand All @@ -86,6 +90,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 @@ -162,4 +169,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();
huangyz0918 marked this conversation as resolved.
Show resolved Hide resolved
editor.apply();
Toast.makeText(this, getString(R.string.success_reset_settings), Toast.LENGTH_LONG).show();
huangyz0918 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -131,6 +131,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>
huangyz0918 marked this conversation as resolved.
Show resolved Hide resolved
<string name="title_reset_settings">Reset Settings</string>
huangyz0918 marked this conversation as resolved.
Show resolved Hide resolved
<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>
huangyz0918 marked this conversation as resolved.
Show resolved Hide resolved

<string name="btn_refresh">Refresh</string>
<string name="method_bluetooth">Bluetooth</string>
Expand Down
44 changes: 26 additions & 18 deletions skunkworks_crow/src/main/res/xml/preferences_menu.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="General Settings">
<EditTextPreference
android:defaultValue="@string/default_odk_destination_dir"
android:icon="@drawable/ic_sd_storage_black_24dp"
android:key="odk_destination_dir"
android:summary="@string/default_odk_destination_dir"
android:title="@string/title_odk_destination_dir" />

<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">

<EditTextPreference
android:defaultValue="@string/default_hotspot_ssid"
android:summary="@string/default_hotspot_ssid"
android:title="@string/title_hotspot_ssid"
android:icon="@drawable/ic_wifi_tethering_black_24dp"
android:key="hotspot_name"
android:icon="@drawable/ic_wifi_tethering_black_24dp"/>
android:summary="@string/default_hotspot_ssid"
android:title="@string/title_hotspot_ssid" />

<Preference
android:defaultValue="@string/default_hotspot_password"
android:summary="********"
android:title="@string/title_hotspot_password"
android:key="hotspot_password"
android:enabled="false"
android:icon="@drawable/ic_vpn_key_black_24dp"/>
android:icon="@drawable/ic_vpn_key_black_24dp"
android:key="hotspot_password"
android:summary="********"
android:title="@string/title_hotspot_password" />

<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_lock_black_24dp"
android:key="hotspot_pwd_require"
android:summary="@string/password_hotspot"
android:title="@string/set_password"
android:icon="@drawable/ic_lock_black_24dp"/>

<EditTextPreference
android:defaultValue="@string/default_odk_destination_dir"
android:summary="@string/default_odk_destination_dir"
android:title="@string/title_odk_destination_dir"
android:key="odk_destination_dir"
android:icon="@drawable/ic_sd_storage_black_24dp"/>
android:title="@string/set_password" />

</PreferenceCategory>
</PreferenceScreen>