forked from upstream-mirrors/OpenTracks
Adding option to reset to default settings.
This commit is contained in:
@@ -50,8 +50,7 @@ limitations under the License.
|
|||||||
<!-- Keys for non-persisted preferences - DO NOT TRANSLATE -->
|
<!-- Keys for non-persisted preferences - DO NOT TRANSLATE -->
|
||||||
<string name="backup_to_sd_key">backupToSd</string>
|
<string name="backup_to_sd_key">backupToSd</string>
|
||||||
<string name="restore_from_sd_key">restoreFromSd</string>
|
<string name="restore_from_sd_key">restoreFromSd</string>
|
||||||
|
<string name="reset_key">resetToDefaults</string>
|
||||||
<!-- Inoperative keys used for the location of preferences items -->
|
|
||||||
<string name="sensor_options_key">sensorOptions</string>
|
<string name="sensor_options_key">sensorOptions</string>
|
||||||
<string name="ant_options_key">antOptions</string>
|
<string name="ant_options_key">antOptions</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ limitations under the License.
|
|||||||
<string name="settings_sharing">Sharing</string>
|
<string name="settings_sharing">Sharing</string>
|
||||||
|
|
||||||
<string name="settings_not_available_summary">Not available in your version of Android</string>
|
<string name="settings_not_available_summary">Not available in your version of Android</string>
|
||||||
|
<string name="settings_not_while_recording">Not available while recording a track</string>
|
||||||
|
|
||||||
<string name="settings_announcement_frequency">Announcement frequency</string>
|
<string name="settings_announcement_frequency">Announcement frequency</string>
|
||||||
<string name="settings_announcement_frequency_summary">Minimum time between two voice announcements</string>
|
<string name="settings_announcement_frequency_summary">Minimum time between two voice announcements</string>
|
||||||
@@ -236,6 +237,11 @@ limitations under the License.
|
|||||||
<string name="settings_timestamp_track_name_summary_on">The default track name will be the date and time at the start of the track</string>
|
<string name="settings_timestamp_track_name_summary_on">The default track name will be the date and time at the start of the track</string>
|
||||||
<string name="settings_timestamp_track_name_summary_off">Track names will have numbers which increment for each new track.</string>
|
<string name="settings_timestamp_track_name_summary_off">Track names will have numbers which increment for each new track.</string>
|
||||||
|
|
||||||
|
<string name="settings_reset">Reset to defaults</string>
|
||||||
|
<string name="settings_reset_summary">Revert all your settings to the default values</string>
|
||||||
|
<string name="settings_reset_dialog_message">All your settings will be erased and reverted to the default values. Saved tracks will be preserved. Are you sure?</string>
|
||||||
|
<string name="settings_reset_done">All settings have been reverted to their defaults.</string>
|
||||||
|
|
||||||
<string name="pace_label">Pace</string>
|
<string name="pace_label">Pace</string>
|
||||||
|
|
||||||
<string name="eclair_required">Only supported in Android 2.0 or above</string>
|
<string name="eclair_required">Only supported in Android 2.0 or above</string>
|
||||||
@@ -257,7 +263,6 @@ limitations under the License.
|
|||||||
<string name="settings_backup_to_sd_summary">Write a full copy of all your tracks and settings to the SD card</string>
|
<string name="settings_backup_to_sd_summary">Write a full copy of all your tracks and settings to the SD card</string>
|
||||||
<string name="settings_restore_from_sd">Restore now</string>
|
<string name="settings_restore_from_sd">Restore now</string>
|
||||||
<string name="settings_restore_from_sd_summary">Restore all tracks and settings from the SD card</string>
|
<string name="settings_restore_from_sd_summary">Restore all tracks and settings from the SD card</string>
|
||||||
<string name="settings_no_backup_while_recording">Cannot manipulate backups while recording a track.</string>
|
|
||||||
|
|
||||||
<string name="restore_overwrites_warning">Restoring a backup from the SD card will OVERWRITE all your current tracks and settings. Are you sure?</string>
|
<string name="restore_overwrites_warning">Restoring a backup from the SD card will OVERWRITE all your current tracks and settings. Are you sure?</string>
|
||||||
<string name="select_backup_to_restore">Select the backup to restore</string>
|
<string name="select_backup_to_restore">Select the backup to restore</string>
|
||||||
|
|||||||
@@ -173,4 +173,10 @@ limitations under the License.
|
|||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
<!-- Reset to defaults -->
|
||||||
|
<Preference android:title="@string/settings_reset"
|
||||||
|
android:key="@string/reset_key"
|
||||||
|
android:summary="@string/settings_reset_summary"
|
||||||
|
android:persistent="false" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
@@ -15,10 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks;
|
package com.google.android.apps.mytracks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.io.backup.BackupActivityHelper;
|
import com.google.android.apps.mytracks.io.backup.BackupActivityHelper;
|
||||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||||
@@ -28,18 +25,28 @@ import com.google.android.apps.mytracks.util.ApiFeatures;
|
|||||||
import com.google.android.apps.mytracks.util.BluetoothDeviceUtils;
|
import com.google.android.apps.mytracks.util.BluetoothDeviceUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity that let's the user see and edit the settings.
|
* An activity that let's the user see and edit the settings.
|
||||||
@@ -119,6 +126,16 @@ public class MyTracksSettings extends PreferenceActivity {
|
|||||||
announcementFrequency.setSummary(
|
announcementFrequency.setSummary(
|
||||||
R.string.settings_not_available_summary);
|
R.string.settings_not_available_summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hook up action for resetting all settings
|
||||||
|
Preference resetPreference = findPreference(getString(R.string.reset_key));
|
||||||
|
resetPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference arg0) {
|
||||||
|
onResetPreferencesClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customizeSensorOptionsPreferences() {
|
private void customizeSensorOptionsPreferences() {
|
||||||
@@ -177,19 +194,24 @@ public class MyTracksSettings extends PreferenceActivity {
|
|||||||
findPreference(getString(R.string.backup_to_sd_key));
|
findPreference(getString(R.string.backup_to_sd_key));
|
||||||
Preference restoreNowPreference =
|
Preference restoreNowPreference =
|
||||||
findPreference(getString(R.string.restore_from_sd_key));
|
findPreference(getString(R.string.restore_from_sd_key));
|
||||||
|
Preference resetPreference = findPreference(getString(R.string.reset_key));
|
||||||
|
|
||||||
// If recording, disable backup/restore
|
// If recording, disable backup/restore/reset
|
||||||
// (we don't want to get to inconsistent states)
|
// (we don't want to get to inconsistent states)
|
||||||
boolean recording =
|
boolean recording =
|
||||||
preferences.getLong(getString(R.string.recording_track_key), -1) != -1;
|
preferences.getLong(getString(R.string.recording_track_key), -1) != -1;
|
||||||
backupNowPreference.setEnabled(!recording);
|
backupNowPreference.setEnabled(!recording);
|
||||||
restoreNowPreference.setEnabled(!recording);
|
restoreNowPreference.setEnabled(!recording);
|
||||||
|
resetPreference.setEnabled(!recording);
|
||||||
backupNowPreference.setSummary(
|
backupNowPreference.setSummary(
|
||||||
recording ? R.string.settings_no_backup_while_recording
|
recording ? R.string.settings_not_while_recording
|
||||||
: R.string.settings_backup_to_sd_summary);
|
: R.string.settings_backup_to_sd_summary);
|
||||||
restoreNowPreference.setSummary(
|
restoreNowPreference.setSummary(
|
||||||
recording ? R.string.settings_no_backup_while_recording
|
recording ? R.string.settings_not_while_recording
|
||||||
: R.string.settings_restore_from_sd_summary);
|
: R.string.settings_restore_from_sd_summary);
|
||||||
|
resetPreference.setSummary(
|
||||||
|
recording ? R.string.settings_not_while_recording
|
||||||
|
: R.string.settings_reset_summary);
|
||||||
|
|
||||||
// Add actions to the backup preferences
|
// Add actions to the backup preferences
|
||||||
backupNowPreference.setOnPreferenceClickListener(
|
backupNowPreference.setOnPreferenceClickListener(
|
||||||
@@ -311,4 +333,37 @@ public class MyTracksSettings extends PreferenceActivity {
|
|||||||
devicesPreference.setEntryValues(entryValuesArray);
|
devicesPreference.setEntryValues(entryValuesArray);
|
||||||
devicesPreference.setEntries(entriesArray);
|
devicesPreference.setEntries(entriesArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Callback for when user asks to reset all settings. */
|
||||||
|
private void onResetPreferencesClick() {
|
||||||
|
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setTitle(R.string.settings_reset)
|
||||||
|
.setMessage(R.string.settings_reset_dialog_message)
|
||||||
|
.setPositiveButton(android.R.string.ok,
|
||||||
|
new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int button) {
|
||||||
|
onResetPreferencesConfirmed();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.create();
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Callback for when user confirms resetting all settings. */
|
||||||
|
private void onResetPreferencesConfirmed() {
|
||||||
|
Log.i(TAG, "Resetting all settings");
|
||||||
|
|
||||||
|
// Actually wipe preferences.
|
||||||
|
preferences.edit().clear().commit();
|
||||||
|
|
||||||
|
Toast.makeText(this, R.string.settings_reset_done, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
// Restart the settings activity so all changes are loaded.
|
||||||
|
Intent intent = getIntent();
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user