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.ConfirmSharingActivity" />
<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.GoogleSettingsActivity" />
<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. -->
<string name="settings_backup_key">settingsBackup</string>
<string name="settings_backup_now_key">settingsBackupNow</string>
<string name="settings_backup_restore_key">settingsBackupRestore</string>
<string name="settings_backup_reset_key">settingsBackupReset</string>
<string name="settings_chart_key">settingsChart</string>
<string name="settings_google_key">settingsGoogle</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_recording_key">settingsRecording</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_ant_key">settingsSensorAnt</string>
<string name="settings_sensor_ant_reset_bike_cadence_sensor_key">settingsSensorAntResetBikeCadenceSensor</string>
+42 -43
View File
@@ -1585,7 +1585,7 @@ limitations under the License.
<string name="settings_not_while_recording"
translation_description="In settings, the summary for an option that is not available during a
track recording.">
Not available while recording a track.
Not available while recording a track
</string>
<string name="settings_show"
translation_description="In settings, the section label to show additional values.
@@ -1594,19 +1594,18 @@ limitations under the License.
Show
</string>
<!-- Settings Backup -->
<string name="settings_backup"
translation_description="In the 'Settings' page, the option to change the data backup related
settings.
<!-- Settings Backup Reset -->
<string name="settings_backup_reset"
translation_description="In the 'Settings' page, the option backup and reset.
Character limit: ~26 (1 line)">
Backup
Backup &amp; reset
</string>
<!-- Settings Backup Now -->
<string name="settings_backup_now"
translation_description="In the 'Backup' settings, the option to backup to the external storage
now.
translation_description="In the 'Backup and reset' settings, the option to backup to the
external storage now.
Character limit: ~26 (1 line)">
Backup now
@@ -1616,15 +1615,15 @@ limitations under the License.
Unable to backup.
</string>
<string name="settings_backup_now_progress_message"
translation_description="In the 'Backup' settings, after pressing the 'Backup now' option, the
progress message telling the user that it is writing all tracks and settings to the external
storage.">
translation_description="In the 'Backup and reset' settings, after pressing the 'Backup now'
option, the progress message telling the user that it is writing all tracks and settings to
the external storage.">
Writing all tracks and settings&#8230;
</string>
<string name="settings_backup_now_summary"
translation_description="In the 'Backup' settings, the summary for the 'Backup now' 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.
translation_description="In the 'Backup and reset' settings, the summary for the 'Backup now'
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
</string>
<string name="settings_backup_now_success"
translation_description="When backing up to the external storage, the success message">
@@ -1633,16 +1632,16 @@ limitations under the License.
<!-- Settings Backup Restore -->
<string name="settings_backup_restore"
translation_description="In the 'Backup' settings, the option to restore from the external
storage.
translation_description="In the 'Backup and reset' settings, the option to restore from the
external storage.
Character limit: ~26 (1 line)">
Restore now
</string>
<string name="settings_backup_restore_confirm_message"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the
message in the alert dialog asking the user to confirm that he wants to restore from a backup
and it will overwrite all the current tracks and settings.">
translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
option, the message in the alert dialog asking the user to confirm that he wants to restore
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
settings.
</string>
@@ -1651,25 +1650,26 @@ limitations under the License.
Unable to restore from backup.
</string>
<string name="settings_backup_restore_no_backup"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the
message in the alert dialog informing the user that there is no backup to restore from.">
translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
option, the message in the alert dialog informing the user that there is no backup to restore
from.">
No backup found.
</string>
<string name="settings_backup_restore_progress_message"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the
progress message informing that My Tracks is reading all tracks and settings from the backup
on the external storage.">
translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
option, the progress message informing that My Tracks is reading all tracks and settings from
the backup on the external storage.">
Reading all tracks and settings&#8230;
</string>
<string name="settings_backup_restore_select_title"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the
title in the picker dialog asking the user to select a backup.">
translation_description="In the 'Backup and reset' settings, after pressing the 'Restore now'
option, the title in the picker dialog asking the user to select a backup.">
Select a backup to restore
</string>
<string name="settings_backup_restore_summary"
translation_description="In the 'Backup' settings, the summary for the 'Restore now' option
explaining that it restores all tracks and settings from the external storage.">
Restore all tracks and settings from the external storage.
translation_description="In the 'Backup and reset' settings, the summary for the 'Restore now'
option explaining that it restores all tracks and settings from the external storage.">
Restore all tracks and settings from the external storage
</string>
<string name="settings_backup_restore_success"
translation_description="When restoring from backup, the success message.">
@@ -1943,27 +1943,27 @@ limitations under the License.
<!-- 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)">
Reset
</string>
<string name="settings_reset_confirm_message"
translation_description="In the 'Settings' page, after pressing the 'Reset' option, 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
preserved.
translation_description="In the 'Backup and reset' settings, after pressing the 'Reset' option,
the confirmation dialog message informing the user that all settings will be reverted.">
All settings will be erased and reverted to the default values. Saved tracks will be preserved.
</string>
<string name="settings_reset_done"
translation_description="In the 'Settings' page, after pressing the 'Reset' option, the
confirmation dialog informing the user that all settings have been reverted to their
defaults.">
All settings have been reverted to their defaults.
translation_description="In the 'Backup and reset' settings, after pressing the 'Reset' option,
the confirmation dialog informing the user that all settings have been reverted to the default
values.">
All settings have been reverted to the default values.
</string>
<string name="settings_reset_summary"
translation_description="In the 'Settings' page, the summary for the 'Reset' option explaining
reverting all the settings to the default values.">
Revert all your settings to the default values.
translation_description="In the 'Backup and reset' settings, the summary for the 'Reset' option
explaining it will revert all settings to the default values.">
Revert all your settings to the default values
</string>
<!-- Settings Sensor -->
@@ -2047,7 +2047,6 @@ limitations under the License.
%1$s: sensor name. E.g., 'Polar Bluetooth'.">
Connected to %1$s
</string>
<string name="settings_sensor_type"
translation_description="In the 'Sensor' settings, the picker to choose a sensor type.
@@ -2055,7 +2054,7 @@ limitations under the License.
Sensor type
</string>
<string name="settings_sensor_type_ant"
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
choose an ANT+ sensor. Note that ANT+ is a radio standard.
Character limit: ~20 (1 line)">
@@ -15,13 +15,17 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/settings_backup" >
android:title="@string/settings_backup_reset" >
<Preference
android:key="@string/settings_backup_now_key"
android:key="@string/settings_backup_key"
android:persistent="false"
android:title="@string/settings_backup_now" />
<Preference
android:key="@string/settings_backup_restore_key"
android:key="@string/settings_restore_key"
android:persistent="false"
android:title="@string/settings_backup_restore" />
<Preference
android:key="@string/settings_reset_key"
android:persistent="false"
android:title="@string/settings_reset" />
</PreferenceScreen>
+2 -6
View File
@@ -45,11 +45,7 @@ limitations under the License.
android:persistent="false"
android:title="@string/settings_sensor" />
<Preference
android:key="@string/settings_backup_key"
android:key="@string/settings_backup_reset_key"
android:persistent="false"
android:title="@string/settings_backup" />
<Preference
android:key="@string/settings_reset_key"
android:persistent="false"
android:title="@string/settings_reset" />
android:title="@string/settings_backup_reset" />
</PreferenceScreen>
@@ -33,19 +33,24 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
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
*/
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_RESET_ID = 1;
private SharedPreferences sharedPreferences;
private Preference backupPreference;
private Preference restorePreference;
private Preference restoreNowPreference;
private Preference resetPreference;
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
@@ -57,12 +62,10 @@ public class BackupSettingsActivity extends AbstractSettingsActivity {
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key == null || key.equals(PreferencesUtils.getKey(
BackupSettingsActivity.this, R.string.recording_track_id_key))) {
if (key != null && key.equals(PreferencesUtils.getKey(
BackupResetSettingsActivity.this, R.string.recording_track_id_key))) {
recordingTrackId = PreferencesUtils.getLong(
BackupSettingsActivity.this, R.string.recording_track_id_key);
}
if (key != null) {
BackupResetSettingsActivity.this, R.string.recording_track_id_key);
runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -77,60 +80,81 @@ public class BackupSettingsActivity extends AbstractSettingsActivity {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.backup_reset_settings);
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
addPreferencesFromResource(R.xml.backup_settings);
backupPreference = findPreference(getString(R.string.settings_backup_now_key));
backupPreference = findPreference(getString(R.string.settings_backup_key));
backupPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(BackupSettingsActivity.this, BackupActivity.class);
Intent intent = IntentUtils.newIntent(
BackupResetSettingsActivity.this, BackupActivity.class);
startActivity(intent);
return true;
}
});
restorePreference = findPreference(getString(R.string.settings_backup_restore_key));
restorePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
restoreNowPreference = findPreference(getString(R.string.settings_restore_key));
restoreNowPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_CONFIRM_RESTORE_ID);
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
protected Dialog onCreateDialog(int id) {
if (id != DIALOG_CONFIRM_RESTORE_ID) {
return null;
Dialog dialog;
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,
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);
return dialog;
}
@Override
protected void onResume() {
super.onResume();
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
updateUi();
}
@Override
protected void onStop() {
super.onStop();
protected void onPause() {
super.onPause();
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
@@ -140,10 +164,45 @@ public class BackupSettingsActivity extends AbstractSettingsActivity {
private void updateUi() {
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
backupPreference.setEnabled(!isRecording);
restorePreference.setEnabled(!isRecording);
backupPreference.setSummary(
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);
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;
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.PreferencesUtils;
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.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;
import android.widget.Toast;
/**
* An activity for accessing settings.
@@ -41,11 +32,6 @@ import android.widget.Toast;
*/
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")
@Override
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_sharing_key, SharingSettingsActivity.class);
configPreference(R.string.settings_sensor_key, SensorSettingsActivity.class);
configPreference(R.string.settings_backup_key, BackupSettingsActivity.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;
}
});
configPreference(R.string.settings_backup_reset_key, BackupResetSettingsActivity.class);
}
/**
@@ -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();
}
}