Cleanup and default track name is location+date.

This commit is contained in:
Dennis Guse
2019-07-20 21:09:19 +02:00
parent 86aac36153
commit 02bb5bb48e
8 changed files with 31 additions and 123 deletions
@@ -45,10 +45,8 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity {
private static final String TAG = AdvancedSettingsActivity.class.getSimpleName();
private static final int DIALOG_CONFIRM_ALLOW_ACCESS_ID = 0;
private static final int DIALOG_CONFIRM_RESET_ID = 1;
private CheckBoxPreference allowAccessCheckBoxPreference;
private Preference resetPreference;
private SharedPreferences sharedPreferences;
@@ -90,20 +88,6 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity {
setPhotoSizeSummaryAndOptions(summary, options, values);
configureListPreference(preference, summary, options, values, String.valueOf(value), null);
allowAccessCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.allow_access_key));
allowAccessCheckBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
if ((Boolean) newValue) {
showDialog(DIALOG_CONFIRM_ALLOW_ACCESS_ID);
return false;
} else {
return true;
}
}
});
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
resetPreference = findPreference(getString(R.string.settings_reset_key));
@@ -133,16 +117,6 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity {
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CONFIRM_ALLOW_ACCESS_ID:
return DialogUtils.createConfirmationDialog(this,
R.string.settings_sharing_allow_access_confirm_title,
getString(R.string.settings_sharing_allow_access_confirm_message),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int button) {
allowAccessCheckBoxPreference.setChecked(true);
}
});
case DIALOG_CONFIRM_RESET_ID:
return DialogUtils.createConfirmationDialog(this, R.string.settings_reset_confirm_title,
getString(R.string.settings_reset_confirm_message),
@@ -204,8 +178,7 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity {
AdvancedSettingsActivity.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);
Intent intent = getIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
@@ -45,8 +45,7 @@ public class DialogUtils {
* @param message the message
* @param okListener the listener when OK is clicked
*/
public static Dialog createConfirmationDialog(
final Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
public static Dialog createConfirmationDialog(final Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
final AlertDialog alertDialog = new AlertDialog.Builder(context)
.setCancelable(true)
.setIcon(android.R.drawable.ic_dialog_alert)
@@ -71,8 +70,7 @@ public class DialogUtils {
* @param messageId the progress message id
* @param onCancelListener the cancel listener
*/
public static ProgressDialog createSpinnerProgressDialog(
Context context, int messageId, DialogInterface.OnCancelListener onCancelListener) {
public static ProgressDialog createSpinnerProgressDialog(Context context, int messageId, DialogInterface.OnCancelListener onCancelListener) {
return createProgressDialog(true, context, messageId, onCancelListener);
}
@@ -84,8 +82,7 @@ public class DialogUtils {
* @param onCancelListener the cancel listener
* @param formatArgs the format arguments for the messageId
*/
public static ProgressDialog createHorizontalProgressDialog(Context context, int messageId,
DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
public static ProgressDialog createHorizontalProgressDialog(Context context, int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
return createProgressDialog(false, context, messageId, onCancelListener, formatArgs);
}
@@ -98,8 +95,7 @@ public class DialogUtils {
* @param onCancelListener the cancel listener
* @param formatArgs the format arguments for the message id
*/
private static ProgressDialog createProgressDialog(boolean spinner, final Context context,
int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
private static ProgressDialog createProgressDialog(boolean spinner, final Context context, int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
final ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
@@ -107,8 +103,7 @@ public class DialogUtils {
progressDialog.setIndeterminate(true);
progressDialog.setMessage(context.getString(messageId, formatArgs));
progressDialog.setOnCancelListener(onCancelListener);
progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER
: ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER : ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@@ -84,7 +84,7 @@ public class PreferencesUtils {
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
public static final String STATS_UNITS_DEFAULT = "METRIC";
public static final String TRACK_NAME_DEFAULT = "LOCATION";
public static final String TRACK_NAME_DEFAULT = "DATE_ISO_8601_LOCATION";
// Track widget
public static final int TRACK_WIDGET_ITEM1_DEFAULT = 3; // moving time
@@ -92,9 +92,7 @@ public class PreferencesUtils {
public static final int TRACK_WIDGET_ITEM3_DEFAULT = 1; // total time
public static final int TRACK_WIDGET_ITEM4_DEFAULT = 2; // average speed
public static final int VOICE_FREQUENCY_DEFAULT = 0;
private static final String TAG = PreferencesUtils.class.getSimpleName();
private PreferencesUtils() {}
/**
@@ -115,8 +113,7 @@ public class PreferencesUtils {
* @param defaultValue the default value
*/
public static boolean getBoolean(Context context, int keyId, boolean defaultValue) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getBoolean(getKey(context, keyId), defaultValue);
}
@@ -128,8 +125,7 @@ public class PreferencesUtils {
* @param value the value
*/
public static void setBoolean(Context context, int keyId, boolean value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();
editor.putBoolean(getKey(context, keyId), value);
editor.apply();
@@ -143,8 +139,7 @@ public class PreferencesUtils {
* @param defaultValue the default value
*/
public static int getInt(Context context, int keyId, int defaultValue) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getInt(getKey(context, keyId), defaultValue);
}
@@ -156,8 +151,7 @@ public class PreferencesUtils {
* @param value the value
*/
public static void setInt(Context context, int keyId, int value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();
editor.putInt(getKey(context, keyId), value);
editor.apply();
@@ -171,8 +165,7 @@ public class PreferencesUtils {
* @param defaultValue the default value
*/
public static float getFloat(Context context, int keyId, float defaultValue) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getFloat(getKey(context, keyId), defaultValue);
}
@@ -184,8 +177,7 @@ public class PreferencesUtils {
* @param value the value
*/
public static void setFloat(Context context, int keyId, float value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();
editor.putFloat(getKey(context, keyId), value);
editor.apply();
@@ -198,8 +190,7 @@ public class PreferencesUtils {
* @param keyId the key id
*/
public static long getLong(Context context, int keyId) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getLong(getKey(context, keyId), -1L);
}
@@ -211,8 +202,7 @@ public class PreferencesUtils {
* @param value the value
*/
public static void setLong(Context context, int keyId, long value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();
editor.putLong(getKey(context, keyId), value);
editor.apply();
@@ -226,8 +216,7 @@ public class PreferencesUtils {
* @param defaultValue default value
*/
public static String getString(Context context, int keyId, String defaultValue) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(getKey(context, keyId), defaultValue);
}
@@ -239,8 +228,7 @@ public class PreferencesUtils {
* @param value the value
*/
public static void setString(Context context, int keyId, String value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();
editor.putString(getKey(context, keyId), value);
editor.apply();
@@ -252,8 +240,7 @@ public class PreferencesUtils {
* @param context the context
*/
public static boolean isMetricUnits(Context context) {
return STATS_UNITS_DEFAULT.equals(
getString(context, R.string.stats_units_key, STATS_UNITS_DEFAULT));
return STATS_UNITS_DEFAULT.equals(getString(context, R.string.stats_units_key, STATS_UNITS_DEFAULT));
}
/**
@@ -263,8 +250,7 @@ public class PreferencesUtils {
* @param context the context
*/
public static boolean isReportSpeed(Context context) {
return STATS_RATE_DEFAULT.equals(
getString(context, R.string.stats_rate_key, STATS_RATE_DEFAULT));
return STATS_RATE_DEFAULT.equals(getString(context, R.string.stats_rate_key, STATS_RATE_DEFAULT));
}
/**
@@ -273,30 +259,6 @@ public class PreferencesUtils {
* @param context the context
*/
public static boolean isChartByDistance(Context context) {
return CHART_X_AXIS_DEFAULT.equals(
getString(context, R.string.chart_x_axis_key, CHART_X_AXIS_DEFAULT));
}
/**
* Adds a value to a list.
*
* @param context the context
* @param keyId the key id
* @param defaultValue the default value
* @param value the value
*/
public static void addToList(Context context, int keyId, String defaultValue, String value) {
String list = getString(context, keyId, defaultValue);
if (defaultValue.equals(list)) {
setString(context, keyId, value);
return;
}
String[] items = TextUtils.split(list, ";");
for (String item : items) {
if (value.equals(item)) {
return;
}
}
setString(context, keyId, list + ";" + value);
return CHART_X_AXIS_DEFAULT.equals(getString(context, R.string.chart_x_axis_key, CHART_X_AXIS_DEFAULT));
}
}
@@ -50,26 +50,18 @@ public class TrackNameUtils {
* @param startTime the track start time
* @param location the track location, can be null
*/
public static String getTrackName(
Context context, long trackId, long startTime, Location location) {
String trackName = PreferencesUtils.getString(
context, R.string.track_name_key, PreferencesUtils.TRACK_NAME_DEFAULT);
public static String getTrackName(Context context, long trackId, long startTime, Location location) {
String trackName = PreferencesUtils.getString(context, R.string.track_name_key, PreferencesUtils.TRACK_NAME_DEFAULT);
if (trackName.equals(
context.getString(R.string.settings_recording_track_name_location_value))) {
if (trackName.equals(context.getString(R.string.settings_recording_track_name_location_value))) {
// Use the startTime if location is null
return location != null ? getReverseGeoCoding(context, location)
: StringUtils.formatDateTime(context, startTime);
} else if (trackName.equals(
context.getString(R.string.settings_recording_track_name_date_local_value))) {
return location != null ? getReverseGeoCoding(context, location) : StringUtils.formatDateTime(context, startTime);
} else if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_local_value))) {
return StringUtils.formatDateTime(context, startTime);
} else if (trackName.equals(
context.getString(R.string.settings_recording_track_name_date_iso_8601_value))) {
} else if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_iso_8601_value))) {
return new SimpleDateFormat(ISO_8601_FORMAT, Locale.US).format(startTime);
} else if (trackName.equals(
context.getString(R.string.settings_recording_track_name_date_iso_8601_location_value))) {
StringBuilder builder = new StringBuilder(
new SimpleDateFormat(ISO_8601_FORMAT, Locale.US).format(startTime));
} else if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_iso_8601_location_value))) {
StringBuilder builder = new StringBuilder(new SimpleDateFormat(ISO_8601_FORMAT, Locale.US).format(startTime));
if (location != null) {
String address = getReverseGeoCoding(context, location);
@@ -197,11 +197,6 @@ limitations under the License.
<item>@string/settings_map_track_color_mode_fixed_summary</item>
<item>@string/settings_map_track_color_mode_dynamic_summary</item>
</string-array>
<string-array name="track_color_mode_values">
<item>@string/settings_map_track_color_mode_single_value</item>
<item>@string/settings_map_track_color_mode_fixed_value</item>
<item>@string/settings_map_track_color_mode_dynamic_value</item>
</string-array>
<string-array name="track_name_options">
<item>@string/settings_recording_track_name_location_option</item>
<item>@string/settings_recording_track_name_date_local_option</item>
+1 -4
View File
@@ -21,14 +21,11 @@ limitations under the License.
<string name="marker_statistics_icon_url">http://maps.google.com/mapfiles/ms/micons/ylw-pushpin.png</string>
<string name="marker_waypoint_icon_url">http://maps.google.com/mapfiles/ms/micons/blue-pushpin.png</string>
<string name="my_tracks_recording_service_name">My Tracks Recording Service</string>
<string name="my_tracks_web_url">www.google.com/mobile/mytracks</string>
<string name="my_tracks_web_url">TODO</string>
<string name="permission_notification_value">com.google.android.apps.mytracks.MYTRACKS_NOTIFICATIONS</string>
<string name="sensor_type_value_none">NONE</string>
<string name="sensor_unit_rounds_per_minute">RPM</string>
<string name="sensor_unit_beats_per_minute">BPM</string>
<string name="settings_map_track_color_mode_dynamic_value">DYNAMIC</string>
<string name="settings_map_track_color_mode_fixed_value">FIXED</string>
<string name="settings_map_track_color_mode_single_value">SINGLE</string>
<string name="settings_recording_track_name_date_iso_8601_value">DATE_ISO_8601</string>
<string name="settings_recording_track_name_date_iso_8601_location_value">DATE_ISO_8601_LOCATION</string>
<string name="settings_recording_track_name_date_local_value">DATE_LOCAL</string>
-6
View File
@@ -20,12 +20,6 @@ limitations under the License.
android:defaultValue="1024"
android:key="@string/photo_size_key"
android:title="@string/settings_advanced_photo_size_title" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/allow_access_key"
android:summaryOff="@string/settings_sharing_allow_access_summary"
android:summaryOn="@string/settings_sharing_allow_access_summary"
android:title="@string/settings_sharing_allow_access" />
<Preference
android:key="@string/settings_reset_key"
android:persistent="false"
+1 -1
View File
@@ -25,7 +25,7 @@ limitations under the License.
android:key="@string/split_frequency_key"
android:title="@string/menu_split_frequency" />
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue="@string/settings_recording_track_name_location_value"
android:defaultValue="@string/settings_recording_track_name_date_iso_8601_location_value"
android:key="@string/track_name_key"
android:title="@string/settings_recording_track_name_title" />
<com.google.android.apps.mytracks.settings.ActivityTypePreference