remove weight from stats settings

This commit is contained in:
Jimmy Shih
2013-11-14 15:55:44 -08:00
parent 982828d0af
commit 857b53c4ca
13 changed files with 24 additions and 116 deletions
@@ -210,9 +210,9 @@ public class TrackEditActivity extends AbstractMyTracksActivity
}
@Override
public void onChooseActivityTypeDone(String value, boolean newWeight) {
if (!this.newWeight) {
this.newWeight = newWeight;
public void onChooseActivityTypeDone(String value, boolean hasNewWeight) {
if (!newWeight) {
newWeight = hasNewWeight;
}
setActivityTypeIcon(value);
activityType.setText(getString(TrackIconUtils.getIconActivityType(value)));
@@ -453,7 +453,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
if (tripStatisticsUpdater != null) {
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
if (chartByDistance) {
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
@@ -59,6 +59,7 @@ public class PreferenceBackupHelper {
doNotBackup.add(context.getString(R.string.google_account_key));
doNotBackup.add(context.getString(R.string.recording_track_id_key));
doNotBackup.add(context.getString(R.string.recording_track_paused_key));
doNotBackup.add(context.getString(R.string.weight_key));
}
/**
@@ -244,9 +244,9 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
return;
}
trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
}
if (waypoint.getLocation().getTime() > trackPoint.getTime()) {
trackPoint = null;
@@ -551,7 +551,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
location.getTime() != -1L ? location.getTime() : trackData.importTime);
}
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
trackData.bufferedLocations[trackData.numBufferedLocations] = location;
trackData.numBufferedLocations++;
@@ -279,7 +279,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
}
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
if (i % elevationSamplingFrequency == 0) {
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
@@ -668,10 +668,10 @@ public class TrackRecordingService extends Service {
do {
Location location = myTracksProviderUtils.createTrackPoint(cursor);
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
if (location.getTime() > markerStartTime) {
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
}
} while (cursor.moveToPrevious());
}
@@ -1013,9 +1013,9 @@ public class TrackRecordingService extends Service {
long trackPointId = Long.parseLong(uri.getLastPathSegment());
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, true,
CalorieUtils.getActivityType(context, track.getCategory()), PreferencesUtils.getFloat(context,
R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT));
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
} catch (SQLiteException e) {
/*
@@ -17,19 +17,12 @@
package com.google.android.apps.mytracks.settings;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
import android.app.Dialog;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
/**
* An activity for accessing stats settings.
@@ -38,19 +31,12 @@ import android.widget.TextView;
*/
public class StatsSettingsActivity extends AbstractSettingsActivity {
private EditTextPreference weightPreference;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.stats_settings);
weightPreference = (EditTextPreference) findPreference(
getString(R.string.settings_stats_weight_display_key));
configWeightPreference();
updateWeightSummary(PreferencesUtils.isMetricUnits(this));
/*
* Note configureUnitsListPreference will trigger
* configureRateListPreference
@@ -58,41 +44,6 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
configUnitsListPreference();
}
/**
* Configures the weight preference.
*/
private void configWeightPreference() {
weightPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PreferencesUtils.storeWeightValue(StatsSettingsActivity.this, (String) newValue);
updateWeightSummary(PreferencesUtils.isMetricUnits(StatsSettingsActivity.this));
return true;
}
});
weightPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference pref) {
double value = PreferencesUtils.getWeightDisplayValue(StatsSettingsActivity.this);
((EditTextPreference) pref).getEditText().setText(StringUtils.formatWeight(value));
return true;
}
});
weightPreference.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Dialog dialog = weightPreference.getDialog();
weightPreference.onClick(dialog, Dialog.BUTTON_POSITIVE);
dialog.dismiss();
return true;
}
return false;
}
});
}
/**
* Configures the preferred units list preference.
*/
@@ -106,7 +57,6 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
public boolean onPreferenceChange(Preference pref, Object newValue) {
boolean metricUnits = PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue);
configRateListPreference(metricUnits);
updateWeightSummary(metricUnits);
return true;
}
};
@@ -133,13 +83,4 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
configureListPreference(listPreference, options, options, values, value, null);
}
/**
* Updates the weight summary.
*/
private void updateWeightSummary(boolean metricUnits) {
weightPreference.setSummary(getString(
metricUnits ? R.string.value_kilogram : R.string.value_pound, StringUtils.formatWeight(
PreferencesUtils.getWeightDisplayValue(StatsSettingsActivity.this, metricUnits))));
}
}
@@ -104,7 +104,7 @@ public class CalorieUtils {
R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
double weight = PreferencesUtils.getFloat(
context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT);
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
while (iterator.hasNext()) {
tripStatisticsUpdater.addLocation(
@@ -107,7 +107,6 @@ public class PreferencesUtils {
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
public static final String STATS_UNITS_DEFAULT = "METRIC";
public static final float STATS_WEIGHT_DEFAULT = 65.0f; // in kilogram
// Track color
public static final String TRACK_COLOR_MODE_DEFAULT = "SINGLE";
@@ -124,6 +123,8 @@ public class PreferencesUtils {
public static final int TRACK_WIDGET_ITEM4_DEFAULT = 2; // average speed
public static final int VOICE_FREQUENCY_DEFAULT = 0;
public static final float WEIGHT_DEFAULT = 65.0f; // in kilogram
private static final String TAG = PreferencesUtils.class.getSimpleName();
private PreferencesUtils() {}
@@ -350,9 +351,9 @@ public class PreferencesUtils {
}
} catch (NumberFormatException e) {
Log.e(TAG, "invalid value " + displayValue);
value = PreferencesUtils.STATS_WEIGHT_DEFAULT;
value = PreferencesUtils.WEIGHT_DEFAULT;
}
PreferencesUtils.setFloat(context, R.string.stats_weight_key, (float) value);
PreferencesUtils.setFloat(context, R.string.weight_key, (float) value);
}
/**
@@ -361,19 +362,9 @@ public class PreferencesUtils {
* @param context the context
*/
public static double getWeightDisplayValue(Context context) {
return getWeightDisplayValue(context, PreferencesUtils.isMetricUnits(context));
}
/**
* Gets the weight display value.
*
* @param context the context
* @param metricUnits true to get display value in metric units
*/
public static double getWeightDisplayValue(Context context, boolean metricUnits) {
double value = PreferencesUtils.getFloat(
context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT);
if (!metricUnits) {
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
if (!PreferencesUtils.isMetricUnits(context)) {
value = value * UnitConversions.KG_TO_LB;
}
return value;