Update backup and reset settings

This commit is contained in:
Jimmy Shih
2013-01-18 10:01:12 -08:00
parent ab1d6d8582
commit 3100328014
7 changed files with 149 additions and 168 deletions
+1 -1
View File
@@ -208,7 +208,7 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.AccountChooserActivity" /> <activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.AccountChooserActivity" />
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.ConfirmSharingActivity" /> <activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.ConfirmSharingActivity" />
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" /> <activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.BackupResetSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.GoogleSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.GoogleSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" />
+2 -2
View File
@@ -71,8 +71,7 @@ limitations under the License.
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. --> <!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
<string name="settings_backup_key">settingsBackup</string> <string name="settings_backup_key">settingsBackup</string>
<string name="settings_backup_now_key">settingsBackupNow</string> <string name="settings_backup_reset_key">settingsBackupReset</string>
<string name="settings_backup_restore_key">settingsBackupRestore</string>
<string name="settings_chart_key">settingsChart</string> <string name="settings_chart_key">settingsChart</string>
<string name="settings_google_key">settingsGoogle</string> <string name="settings_google_key">settingsGoogle</string>
<string name="settings_map_key">settingsMap</string> <string name="settings_map_key">settingsMap</string>
@@ -81,6 +80,7 @@ limitations under the License.
<string name="settings_map_slow_display_key">settingsMapSlowDisplay</string> <string name="settings_map_slow_display_key">settingsMapSlowDisplay</string>
<string name="settings_recording_key">settingsRecording</string> <string name="settings_recording_key">settingsRecording</string>
<string name="settings_reset_key">settingsReset</string> <string name="settings_reset_key">settingsReset</string>
<string name="settings_restore_key">settingsRestore</string>
<string name="settings_sensor_key">settingsSensor</string> <string name="settings_sensor_key">settingsSensor</string>
<string name="settings_sensor_ant_key">settingsSensorAnt</string> <string name="settings_sensor_ant_key">settingsSensorAnt</string>
<string name="settings_sensor_ant_reset_bike_cadence_sensor_key">settingsSensorAntResetBikeCadenceSensor</string> <string name="settings_sensor_ant_reset_bike_cadence_sensor_key">settingsSensorAntResetBikeCadenceSensor</string>
+41 -42
View File
@@ -1585,7 +1585,7 @@ limitations under the License.
<string name="settings_not_while_recording" <string name="settings_not_while_recording"
translation_description="In settings, the summary for an option that is not available during a translation_description="In settings, the summary for an option that is not available during a
track recording."> track recording.">
Not available while recording a track. Not available while recording a track
</string> </string>
<string name="settings_show" <string name="settings_show"
translation_description="In settings, the section label to show additional values. translation_description="In settings, the section label to show additional values.
@@ -1594,19 +1594,18 @@ limitations under the License.
Show Show
</string> </string>
<!-- Settings Backup --> <!-- Settings Backup Reset -->
<string name="settings_backup" <string name="settings_backup_reset"
translation_description="In the 'Settings' page, the option to change the data backup related translation_description="In the 'Settings' page, the option backup and reset.
settings.
Character limit: ~26 (1 line)"> Character limit: ~26 (1 line)">
Backup Backup &amp; reset
</string> </string>
<!-- Settings Backup Now --> <!-- Settings Backup Now -->
<string name="settings_backup_now" <string name="settings_backup_now"
translation_description="In the 'Backup' settings, the option to backup to the external storage translation_description="In the 'Backup and reset' settings, the option to backup to the
now. external storage now.
Character limit: ~26 (1 line)"> Character limit: ~26 (1 line)">
Backup now Backup now
@@ -1616,15 +1615,15 @@ limitations under the License.
Unable to backup. Unable to backup.
</string> </string>
<string name="settings_backup_now_progress_message" <string name="settings_backup_now_progress_message"
translation_description="In the 'Backup' settings, after pressing the 'Backup now' option, the translation_description="In the 'Backup and reset' settings, after pressing the 'Backup now'
progress message telling the user that it is writing all tracks and settings to the external option, the progress message telling the user that it is writing all tracks and settings to
storage."> the external storage.">
Writing all tracks and settings&#8230; Writing all tracks and settings&#8230;
</string> </string>
<string name="settings_backup_now_summary" <string name="settings_backup_now_summary"
translation_description="In the 'Backup' settings, the summary for the 'Backup now' option translation_description="In the 'Backup and reset' settings, the summary for the 'Backup now'
explaining that all tracks and settings will be written to the external storage."> option explaining that all tracks and settings will be written to the external storage.">
Write a full copy of all your tracks and settings to the external storage. Write a full copy of all your tracks and settings to the external storage
</string> </string>
<string name="settings_backup_now_success" <string name="settings_backup_now_success"
translation_description="When backing up to the external storage, the success message"> translation_description="When backing up to the external storage, the success message">
@@ -1633,16 +1632,16 @@ limitations under the License.
<!-- Settings Backup Restore --> <!-- Settings Backup Restore -->
<string name="settings_backup_restore" <string name="settings_backup_restore"
translation_description="In the 'Backup' settings, the option to restore from the external translation_description="In the 'Backup and reset' settings, the option to restore from the
storage. external storage.
Character limit: ~26 (1 line)"> Character limit: ~26 (1 line)">
Restore now Restore now
</string> </string>
<string name="settings_backup_restore_confirm_message" <string name="settings_backup_restore_confirm_message"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
message in the alert dialog asking the user to confirm that he wants to restore from a backup option, the message in the alert dialog asking the user to confirm that he wants to restore
and it will overwrite all the current tracks and settings."> from a backup and it will overwrite all the current tracks and settings.">
Restoring a backup from the external storage will overwrite all your current tracks and Restoring a backup from the external storage will overwrite all your current tracks and
settings. settings.
</string> </string>
@@ -1651,25 +1650,26 @@ limitations under the License.
Unable to restore from backup. Unable to restore from backup.
</string> </string>
<string name="settings_backup_restore_no_backup" <string name="settings_backup_restore_no_backup"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
message in the alert dialog informing the user that there is no backup to restore from."> option, the message in the alert dialog informing the user that there is no backup to restore
from.">
No backup found. No backup found.
</string> </string>
<string name="settings_backup_restore_progress_message" <string name="settings_backup_restore_progress_message"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
progress message informing that My Tracks is reading all tracks and settings from the backup option, the progress message informing that My Tracks is reading all tracks and settings from
on the external storage."> the backup on the external storage.">
Reading all tracks and settings&#8230; Reading all tracks and settings&#8230;
</string> </string>
<string name="settings_backup_restore_select_title" <string name="settings_backup_restore_select_title"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
title in the picker dialog asking the user to select a backup."> option, the title in the picker dialog asking the user to select a backup.">
Select a backup to restore Select a backup to restore
</string> </string>
<string name="settings_backup_restore_summary" <string name="settings_backup_restore_summary"
translation_description="In the 'Backup' settings, the summary for the 'Restore now' option translation_description="In the 'Backup and reset' settings, the summary for the 'Restore now'
explaining that it restores all tracks and settings from the external storage."> option explaining that it restores all tracks and settings from the external storage.">
Restore all tracks and settings from the external storage. Restore all tracks and settings from the external storage
</string> </string>
<string name="settings_backup_restore_success" <string name="settings_backup_restore_success"
translation_description="When restoring from backup, the success message."> translation_description="When restoring from backup, the success message.">
@@ -1943,27 +1943,27 @@ limitations under the License.
<!-- Settings Reset --> <!-- Settings Reset -->
<string name="settings_reset" <string name="settings_reset"
translation_description="In the 'Settings' page, the option to reset everything to the defaults. translation_description="In the 'Backup and reset' settings, the option to reset all settings to
the default values.
Character limit: ~26 (1 line)"> Character limit: ~26 (1 line)">
Reset Reset
</string> </string>
<string name="settings_reset_confirm_message" <string name="settings_reset_confirm_message"
translation_description="In the 'Settings' page, after pressing the 'Reset' option, the translation_description="In the 'Backup and reset' settings, after pressing the 'Reset' option,
confirmation dialog message informing the user that all settings will be reverted."> the confirmation dialog message informing the user that all settings will be reverted.">
All your settings will be erased and reverted to the default values. Saved tracks will be All settings will be erased and reverted to the default values. Saved tracks will be preserved.
preserved.
</string> </string>
<string name="settings_reset_done" <string name="settings_reset_done"
translation_description="In the 'Settings' page, after pressing the 'Reset' option, the translation_description="In the 'Backup and reset' settings, after pressing the 'Reset' option,
confirmation dialog informing the user that all settings have been reverted to their the confirmation dialog informing the user that all settings have been reverted to the default
defaults."> values.">
All settings have been reverted to their defaults. All settings have been reverted to the default values.
</string> </string>
<string name="settings_reset_summary" <string name="settings_reset_summary"
translation_description="In the 'Settings' page, the summary for the 'Reset' option explaining translation_description="In the 'Backup and reset' settings, the summary for the 'Reset' option
reverting all the settings to the default values."> explaining it will revert all settings to the default values.">
Revert all your settings to the default values. Revert all your settings to the default values
</string> </string>
<!-- Settings Sensor --> <!-- Settings Sensor -->
@@ -2047,7 +2047,6 @@ limitations under the License.
%1$s: sensor name. E.g., 'Polar Bluetooth'."> %1$s: sensor name. E.g., 'Polar Bluetooth'.">
Connected to %1$s Connected to %1$s
</string> </string>
<string name="settings_sensor_type" <string name="settings_sensor_type"
translation_description="In the 'Sensor' settings, the picker to choose a sensor type. translation_description="In the 'Sensor' settings, the picker to choose a sensor type.
@@ -15,13 +15,17 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/settings_backup" > android:title="@string/settings_backup_reset" >
<Preference <Preference
android:key="@string/settings_backup_now_key" android:key="@string/settings_backup_key"
android:persistent="false" android:persistent="false"
android:title="@string/settings_backup_now" /> android:title="@string/settings_backup_now" />
<Preference <Preference
android:key="@string/settings_backup_restore_key" android:key="@string/settings_restore_key"
android:persistent="false" android:persistent="false"
android:title="@string/settings_backup_restore" /> android:title="@string/settings_backup_restore" />
<Preference
android:key="@string/settings_reset_key"
android:persistent="false"
android:title="@string/settings_reset" />
</PreferenceScreen> </PreferenceScreen>
+2 -6
View File
@@ -45,11 +45,7 @@ limitations under the License.
android:persistent="false" android:persistent="false"
android:title="@string/settings_sensor" /> android:title="@string/settings_sensor" />
<Preference <Preference
android:key="@string/settings_backup_key" android:key="@string/settings_backup_reset_key"
android:persistent="false" android:persistent="false"
android:title="@string/settings_backup" /> android:title="@string/settings_backup_reset" />
<Preference
android:key="@string/settings_reset_key"
android:persistent="false"
android:title="@string/settings_reset" />
</PreferenceScreen> </PreferenceScreen>
@@ -33,19 +33,24 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;
import android.widget.Toast;
/** /**
* An activity for accessing the backup settings. * An activity for accessing the backup and reset settings.
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class BackupSettingsActivity extends AbstractSettingsActivity { public class BackupResetSettingsActivity extends AbstractSettingsActivity {
private static final String TAG = BackupResetSettingsActivity.class.getSimpleName();
private static final int DIALOG_CONFIRM_RESTORE_ID = 0; private static final int DIALOG_CONFIRM_RESTORE_ID = 0;
private static final int DIALOG_CONFIRM_RESET_ID = 1;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private Preference backupPreference; private Preference backupPreference;
private Preference restorePreference; private Preference restoreNowPreference;
private Preference resetPreference;
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
@@ -57,12 +62,10 @@ public class BackupSettingsActivity extends AbstractSettingsActivity {
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() { sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key == null || key.equals(PreferencesUtils.getKey( if (key != null && key.equals(PreferencesUtils.getKey(
BackupSettingsActivity.this, R.string.recording_track_id_key))) { BackupResetSettingsActivity.this, R.string.recording_track_id_key))) {
recordingTrackId = PreferencesUtils.getLong( recordingTrackId = PreferencesUtils.getLong(
BackupSettingsActivity.this, R.string.recording_track_id_key); BackupResetSettingsActivity.this, R.string.recording_track_id_key);
}
if (key != null) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -77,60 +80,81 @@ public class BackupSettingsActivity extends AbstractSettingsActivity {
@Override @Override
protected void onCreate(Bundle bundle) { protected void onCreate(Bundle bundle) {
super.onCreate(bundle); super.onCreate(bundle);
addPreferencesFromResource(R.xml.backup_reset_settings);
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
addPreferencesFromResource(R.xml.backup_settings); backupPreference = findPreference(getString(R.string.settings_backup_key));
backupPreference = findPreference(getString(R.string.settings_backup_now_key));
backupPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { backupPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(BackupSettingsActivity.this, BackupActivity.class); Intent intent = IntentUtils.newIntent(
BackupResetSettingsActivity.this, BackupActivity.class);
startActivity(intent); startActivity(intent);
return true; return true;
} }
}); });
restorePreference = findPreference(getString(R.string.settings_backup_restore_key)); restoreNowPreference = findPreference(getString(R.string.settings_restore_key));
restorePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { restoreNowPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_CONFIRM_RESTORE_ID); showDialog(DIALOG_CONFIRM_RESTORE_ID);
return true; return true;
} }
}); });
resetPreference = findPreference(getString(R.string.settings_reset_key));
resetPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
showDialog(DIALOG_CONFIRM_RESET_ID);
return true;
}
});
} }
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id != DIALOG_CONFIRM_RESTORE_ID) { Dialog dialog;
return null; switch (id) {
case DIALOG_CONFIRM_RESTORE_ID:
dialog = DialogUtils.createConfirmationDialog(this,
R.string.settings_backup_restore_confirm_message,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
Intent intent = IntentUtils.newIntent(
BackupResetSettingsActivity.this, RestoreChooserActivity.class);
startActivity(intent);
}
});
break;
case DIALOG_CONFIRM_RESET_ID:
dialog = DialogUtils.createConfirmationDialog(
this, R.string.settings_reset_confirm_message, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int button) {
onResetPreferencesConfirmed();
}
});
break;
default:
dialog = null;
} }
return DialogUtils.createConfirmationDialog(this, return dialog;
R.string.settings_backup_restore_confirm_message, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = IntentUtils.newIntent(
BackupSettingsActivity.this, RestoreChooserActivity.class);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
super.onStart();
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
updateUi(); updateUi();
} }
@Override @Override
protected void onStop() { protected void onPause() {
super.onStop(); super.onPause();
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
} }
@@ -140,10 +164,45 @@ public class BackupSettingsActivity extends AbstractSettingsActivity {
private void updateUi() { private void updateUi() {
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
backupPreference.setEnabled(!isRecording); backupPreference.setEnabled(!isRecording);
restorePreference.setEnabled(!isRecording);
backupPreference.setSummary( backupPreference.setSummary(
isRecording ? R.string.settings_not_while_recording : R.string.settings_backup_now_summary); isRecording ? R.string.settings_not_while_recording : R.string.settings_backup_now_summary);
restorePreference.setSummary(isRecording ? R.string.settings_not_while_recording
restoreNowPreference.setEnabled(!isRecording);
restoreNowPreference.setSummary(isRecording ? R.string.settings_not_while_recording
: R.string.settings_backup_restore_summary); : R.string.settings_backup_restore_summary);
resetPreference.setEnabled(!isRecording);
resetPreference.setSummary(
isRecording ? R.string.settings_not_while_recording : R.string.settings_reset_summary);
}
/**
* Callback when the user confirms resetting all settings.
*/
private void onResetPreferencesConfirmed() {
// Change preferences in a separate thread
new Thread() {
@Override
public void run() {
Log.i(TAG, "Resetting all settings");
// Actually wipe preferences and save synchronously
sharedPreferences.edit().clear().commit();
// Give UI feedback in the UI thread
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(
BackupResetSettingsActivity.this, R.string.settings_reset_done, Toast.LENGTH_SHORT)
.show();
// Restart the settings activity so all changes are loaded
Intent intent = getIntent()
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
}.start();
} }
} }
@@ -16,22 +16,13 @@
package com.google.android.apps.mytracks.settings; package com.google.android.apps.mytracks.settings;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;
import android.widget.Toast;
/** /**
* An activity for accessing settings. * An activity for accessing settings.
@@ -41,11 +32,6 @@ import android.widget.Toast;
*/ */
public class SettingsActivity extends AbstractSettingsActivity { public class SettingsActivity extends AbstractSettingsActivity {
private static final String TAG = SettingsActivity.class.getSimpleName();
private static final int DIALOG_CONFIRM_RESET_ID = 0;
private Preference resetPreference;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
protected void onCreate(Bundle bundle) { protected void onCreate(Bundle bundle) {
@@ -59,16 +45,7 @@ public class SettingsActivity extends AbstractSettingsActivity {
configPreference(R.string.settings_recording_key, RecordingSettingsActivity.class); configPreference(R.string.settings_recording_key, RecordingSettingsActivity.class);
configPreference(R.string.settings_sharing_key, SharingSettingsActivity.class); configPreference(R.string.settings_sharing_key, SharingSettingsActivity.class);
configPreference(R.string.settings_sensor_key, SensorSettingsActivity.class); configPreference(R.string.settings_sensor_key, SensorSettingsActivity.class);
configPreference(R.string.settings_backup_key, BackupSettingsActivity.class); configPreference(R.string.settings_backup_reset_key, BackupResetSettingsActivity.class);
resetPreference = findPreference(getString(R.string.settings_reset_key));
resetPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
showDialog(DIALOG_CONFIRM_RESET_ID);
return true;
}
});
} }
/** /**
@@ -88,58 +65,4 @@ public class SettingsActivity extends AbstractSettingsActivity {
} }
}); });
} }
@Override
protected void onResume() {
super.onResume();
boolean isRecording = PreferencesUtils.getLong(this, R.string.recording_track_id_key)
!= PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
resetPreference.setEnabled(!isRecording);
resetPreference.setSummary(isRecording ? R.string.settings_not_while_recording
: R.string.settings_reset_summary);
}
@Override
protected Dialog onCreateDialog(int id) {
if (id != DIALOG_CONFIRM_RESET_ID) {
return null;
}
return DialogUtils.createConfirmationDialog(
this, R.string.settings_reset_confirm_message, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int button) {
onResetPreferencesConfirmed();
}
});
}
/**
* Callback when the user confirms resetting all settings.
*/
private void onResetPreferencesConfirmed() {
// Change preferences in a separate thread
new Thread() {
@Override
public void run() {
Log.i(TAG, "Resetting all settings");
SharedPreferences sharedPreferences = getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
// Actually wipe preferences and save synchronously
sharedPreferences.edit().clear().commit();
// Give UI feedback in the UI thread
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(SettingsActivity.this, R.string.settings_reset_done, Toast.LENGTH_SHORT)
.show();
// Restart the settings activity so all changes are loaded
Intent intent = getIntent()
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
}.start();
}
} }