forked from upstream-mirrors/OpenTracks
Cleanup calorie settings
This commit is contained in:
@@ -42,7 +42,6 @@ limitations under the License.
|
|||||||
<string name="stats_rate_key">statsRate</string>
|
<string name="stats_rate_key">statsRate</string>
|
||||||
<string name="stats_show_coordinate_key">statsShowCoordinate</string>
|
<string name="stats_show_coordinate_key">statsShowCoordinate</string>
|
||||||
<string name="stats_show_grade_elevation_key">statsShowGradeElevation</string>
|
<string name="stats_show_grade_elevation_key">statsShowGradeElevation</string>
|
||||||
<string name="stats_show_calorie_key">statsShowCalorie</string>
|
|
||||||
<string name="stats_weight_key">statsWeight</string>
|
<string name="stats_weight_key">statsWeight</string>
|
||||||
<string name="stats_units_key">statsUnits</string>
|
<string name="stats_units_key">statsUnits</string>
|
||||||
<string name="track_color_mode_medium_key">trackColorModeMedium</string>
|
<string name="track_color_mode_medium_key">trackColorModeMedium</string>
|
||||||
@@ -93,4 +92,5 @@ limitations under the License.
|
|||||||
<string name="settings_sensor_bluetooth_pairing_key">settingsSensorBluetoothPairing</string>
|
<string name="settings_sensor_bluetooth_pairing_key">settingsSensorBluetoothPairing</string>
|
||||||
<string name="settings_sensor_root_key">settingsSensorRoot</string>
|
<string name="settings_sensor_root_key">settingsSensorRoot</string>
|
||||||
<string name="settings_stats_key">settingsStats</string>
|
<string name="settings_stats_key">settingsStats</string>
|
||||||
|
<string name="settings_stats_weight_display_key">settingsStatsWeightDisplay</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -2025,16 +2025,12 @@ limitations under the License.
|
|||||||
Character limit: ~23 (1 line)">
|
Character limit: ~23 (1 line)">
|
||||||
Grade/Elevation
|
Grade/Elevation
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_stats_calorie_weight"
|
<string name="settings_stats_weight"
|
||||||
translation_description="In the 'Stats settings, the option to configure user's weight.
|
translation_description="In the 'Stats settings, the option to configure user's weight.
|
||||||
|
|
||||||
Character limit: ~23 (1 line)">
|
Character limit: ~23 (1 line)">
|
||||||
Weight
|
Weight
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_stats_calorie_weight_description"
|
|
||||||
translation_description="In the 'Stats settings, the description message about weight setting item.">
|
|
||||||
Weight for calculating calories.
|
|
||||||
</string>
|
|
||||||
<string name="settings_stats_rate_title"
|
<string name="settings_stats_rate_title"
|
||||||
translation_description="In the 'Stats' settings, the option to change the preferred rate,
|
translation_description="In the 'Stats' settings, the option to change the preferred rate,
|
||||||
either speed (mi/hr) or pace (min/mi).
|
either speed (mi/hr) or pace (min/mi).
|
||||||
@@ -2487,6 +2483,12 @@ limitations under the License.
|
|||||||
%1$.1f a float number. E.g., '2.2'.">
|
%1$.1f a float number. E.g., '2.2'.">
|
||||||
%1$.1f mi (poor GPS)
|
%1$.1f mi (poor GPS)
|
||||||
</string>
|
</string>
|
||||||
|
<string name="value_kilogram"
|
||||||
|
translation_description="Display a value in kilogram (kg).
|
||||||
|
|
||||||
|
%1$s a value. E.g., '150.2'.">
|
||||||
|
%1$s kg
|
||||||
|
</string>
|
||||||
<string name="value_integer_feet"
|
<string name="value_integer_feet"
|
||||||
translation_description="In a setting picker, the string format to display an integer value in
|
translation_description="In a setting picker, the string format to display an integer value in
|
||||||
feet (ft).
|
feet (ft).
|
||||||
@@ -2514,12 +2516,6 @@ limitations under the License.
|
|||||||
%1$d an integer value. E.g., '2'.">
|
%1$d an integer value. E.g., '2'.">
|
||||||
%1$d kB
|
%1$d kB
|
||||||
</string>
|
</string>
|
||||||
<string name="value_integer_kilogram"
|
|
||||||
translation_description="Display an integer value in kilogram (kg).
|
|
||||||
|
|
||||||
%1$d an integer value. E.g., '2'.">
|
|
||||||
%1$d kg
|
|
||||||
</string>
|
|
||||||
<string name="value_integer_kilometer"
|
<string name="value_integer_kilometer"
|
||||||
translation_description="In a setting picker, the string format to display an integer value in
|
translation_description="In a setting picker, the string format to display an integer value in
|
||||||
kilometers (km).
|
kilometers (km).
|
||||||
@@ -2594,12 +2590,6 @@ limitations under the License.
|
|||||||
%1$d an integer value. E.g., '2'.">
|
%1$d an integer value. E.g., '2'.">
|
||||||
%1$d %%
|
%1$d %%
|
||||||
</string>
|
</string>
|
||||||
<string name="value_integer_pound"
|
|
||||||
translation_description="Display an integer value in pound (lb).
|
|
||||||
|
|
||||||
%1$d an integer value. E.g., '2'.">
|
|
||||||
%1$d lb
|
|
||||||
</string>
|
|
||||||
<string name="value_integer_second"
|
<string name="value_integer_second"
|
||||||
translation_description="In a setting picker, the string format to display an integer value in
|
translation_description="In a setting picker, the string format to display an integer value in
|
||||||
seconds (s).
|
seconds (s).
|
||||||
@@ -2619,6 +2609,12 @@ limitations under the License.
|
|||||||
translation_description="In a setting picker, the value to turn off the feature.">
|
translation_description="In a setting picker, the value to turn off the feature.">
|
||||||
Off
|
Off
|
||||||
</string>
|
</string>
|
||||||
|
<string name="value_pound"
|
||||||
|
translation_description="Display a value in pound (lb).
|
||||||
|
|
||||||
|
%1$s a value. E.g., '155.2'.">
|
||||||
|
%1$s lb
|
||||||
|
</string>
|
||||||
<string name="value_smallest"
|
<string name="value_smallest"
|
||||||
translation_description="In a setting picker, the value to use the smallest value.">
|
translation_description="In a setting picker, the value to use the smallest value.">
|
||||||
Smallest
|
Smallest
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ limitations under the License.
|
|||||||
android:defaultValue="@string/stats_rate_speed"
|
android:defaultValue="@string/stats_rate_speed"
|
||||||
android:key="@string/stats_rate_key"
|
android:key="@string/stats_rate_key"
|
||||||
android:title="@string/settings_stats_rate_title" />
|
android:title="@string/settings_stats_rate_title" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:imeOptions="actionDone"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:key="@string/settings_stats_weight_display_key"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/settings_stats_weight" />
|
||||||
<PreferenceCategory android:title="@string/settings_show" >
|
<PreferenceCategory android:title="@string/settings_show" >
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
@@ -33,16 +39,5 @@ limitations under the License.
|
|||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="@string/stats_show_coordinate_key"
|
android:key="@string/stats_show_coordinate_key"
|
||||||
android:title="@string/settings_stats_coordinate" />
|
android:title="@string/settings_stats_coordinate" />
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="@string/stats_show_calorie_key"
|
|
||||||
android:title="@string/stats_calorie" />
|
|
||||||
<EditTextPreference
|
|
||||||
android:dependency="@string/stats_show_calorie_key"
|
|
||||||
android:imeOptions="actionDone"
|
|
||||||
android:inputType="number"
|
|
||||||
android:key="@string/stats_weight_key"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/settings_stats_calorie_weight" />
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
@@ -1006,7 +1006,7 @@ public class TrackRecordingService extends Service {
|
|||||||
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
|
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
|
||||||
long trackPointId = Long.parseLong(uri.getLastPathSegment());
|
long trackPointId = Long.parseLong(uri.getLastPathSegment());
|
||||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, true,
|
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, true,
|
||||||
CalorieUtils.getActivityType(context, track.getCategory()), PreferencesUtils.getInt(context,
|
CalorieUtils.getActivityType(context, track.getCategory()), PreferencesUtils.getFloat(context,
|
||||||
R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
||||||
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
||||||
|
|||||||
+67
-125
@@ -17,22 +17,21 @@
|
|||||||
package com.google.android.apps.mytracks.settings;
|
package com.google.android.apps.mytracks.settings;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.StringUtils;
|
||||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.text.InputType;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.EditText;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity for accessing stats settings.
|
* An activity for accessing stats settings.
|
||||||
@@ -43,23 +42,19 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
|||||||
|
|
||||||
private static final String TAG = MapSettingsActivity.class.getSimpleName();
|
private static final String TAG = MapSettingsActivity.class.getSimpleName();
|
||||||
|
|
||||||
private CheckBoxPreference caloriePreference;
|
|
||||||
private EditTextPreference weightPreference;
|
private EditTextPreference weightPreference;
|
||||||
|
|
||||||
private static final int WEIGHT_INPUT_DIALOG = 1;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle bundle) {
|
protected void onCreate(Bundle bundle) {
|
||||||
super.onCreate(bundle);
|
super.onCreate(bundle);
|
||||||
addPreferencesFromResource(R.xml.stats_settings);
|
addPreferencesFromResource(R.xml.stats_settings);
|
||||||
|
|
||||||
caloriePreference = (CheckBoxPreference) findPreference(getString(R.string.stats_show_calorie_key));
|
weightPreference = (EditTextPreference) findPreference(
|
||||||
weightPreference = (EditTextPreference) findPreference(getString(R.string.stats_weight_key));
|
getString(R.string.settings_stats_weight_display_key));
|
||||||
|
|
||||||
configCaloriePreference();
|
|
||||||
configWeightPreference();
|
configWeightPreference();
|
||||||
updateWeightSummary();
|
updateWeightSummary(PreferencesUtils.isMetricUnits(this));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note configureUnitsListPreference will trigger
|
* Note configureUnitsListPreference will trigger
|
||||||
* configureRateListPreference
|
* configureRateListPreference
|
||||||
@@ -67,32 +62,62 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
|||||||
configUnitsListPreference();
|
configUnitsListPreference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the weight preference.
|
||||||
|
*/
|
||||||
|
private void configWeightPreference() {
|
||||||
|
weightPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
storeWeightValue((String) newValue);
|
||||||
|
updateWeightSummary(PreferencesUtils.isMetricUnits(StatsSettingsActivity.this));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
weightPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference pref) {
|
||||||
|
double value = getWeightDisplayValue(
|
||||||
|
PreferencesUtils.isMetricUnits(getApplicationContext()));
|
||||||
|
((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.
|
* Configures the preferred units list preference.
|
||||||
*/
|
*/
|
||||||
private void configUnitsListPreference() {
|
private void configUnitsListPreference() {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
ListPreference listPreference = (ListPreference) findPreference(getString(R.string.stats_units_key));
|
ListPreference listPreference = (ListPreference) findPreference(
|
||||||
|
getString(R.string.stats_units_key));
|
||||||
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
|
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||||
configRateListPreference(PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue));
|
boolean metricUnits = PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue);
|
||||||
|
configRateListPreference(metricUnits);
|
||||||
/*
|
updateWeightSummary(metricUnits);
|
||||||
* It is necessary to change the weight summary as they are in the same
|
|
||||||
* activity.
|
|
||||||
*/
|
|
||||||
updateWeightSummary(PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue));
|
|
||||||
// Recreate weight value dialog.
|
|
||||||
removeDialog(WEIGHT_INPUT_DIALOG);
|
|
||||||
onCreateDialog(WEIGHT_INPUT_DIALOG);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
String value = PreferencesUtils.getString(this, R.string.stats_units_key,
|
String value = PreferencesUtils.getString(
|
||||||
PreferencesUtils.STATS_UNITS_DEFAULT);
|
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||||
String[] values = getResources().getStringArray(R.array.stats_units_values);
|
String[] values = getResources().getStringArray(R.array.stats_units_values);
|
||||||
String[] options = getResources().getStringArray(R.array.stats_units_options);
|
String[] options = getResources().getStringArray(R.array.stats_units_options);
|
||||||
configureListPreference(listPreference, options, options, values, value, listener);
|
configureListPreference(listPreference, options, options, values, value, listener);
|
||||||
@@ -105,101 +130,23 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
|||||||
*/
|
*/
|
||||||
private void configRateListPreference(boolean metricUnits) {
|
private void configRateListPreference(boolean metricUnits) {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
ListPreference listPreference = (ListPreference) findPreference(getString(R.string.stats_rate_key));
|
ListPreference listPreference = (ListPreference) findPreference(
|
||||||
String value = PreferencesUtils.getString(this, R.string.stats_rate_key,
|
getString(R.string.stats_rate_key));
|
||||||
PreferencesUtils.STATS_RATE_DEFAULT);
|
String value = PreferencesUtils.getString(
|
||||||
|
this, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT);
|
||||||
String[] values = getResources().getStringArray(R.array.stats_rate_values);
|
String[] values = getResources().getStringArray(R.array.stats_rate_values);
|
||||||
String[] options = getResources().getStringArray(
|
String[] options = getResources().getStringArray(
|
||||||
metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
|
metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
|
||||||
configureListPreference(listPreference, options, options, values, value, null);
|
configureListPreference(listPreference, options, options, values, value, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the calorie preference.
|
|
||||||
*/
|
|
||||||
private void configCaloriePreference() {
|
|
||||||
caloriePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
boolean value = (Boolean) newValue;
|
|
||||||
if (value) {
|
|
||||||
showDialog(WEIGHT_INPUT_DIALOG);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
protected Dialog onCreateDialog(int id) {
|
|
||||||
Dialog dialog = null;
|
|
||||||
switch (id) {
|
|
||||||
case WEIGHT_INPUT_DIALOG:
|
|
||||||
final EditText weightInput = new EditText(this);
|
|
||||||
weightInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
|
||||||
weightInput.setText(Integer.toString(getWeightDisplayValue(PreferencesUtils
|
|
||||||
.isMetricUnits(getApplicationContext()))));
|
|
||||||
weightInput.setSelectAllOnFocus(true);
|
|
||||||
dialog = (new AlertDialog.Builder(this))
|
|
||||||
.setMessage(R.string.settings_stats_calorie_weight_description)
|
|
||||||
.setNegativeButton(R.string.generic_cancel, null)
|
|
||||||
.setPositiveButton(R.string.generic_ok,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialogInterface, int number) {
|
|
||||||
storeWeightValue(weightInput.getText().toString());
|
|
||||||
updateWeightSummary();
|
|
||||||
dialogInterface.cancel();
|
|
||||||
}
|
|
||||||
}).setTitle(R.string.settings_stats_calorie_weight).setView(weightInput).create();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the weight preference.
|
|
||||||
*/
|
|
||||||
private void configWeightPreference() {
|
|
||||||
weightPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
storeWeightValue((String) newValue);
|
|
||||||
updateWeightSummary();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
weightPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceClick(Preference pref) {
|
|
||||||
int value = getWeightDisplayValue(PreferencesUtils.isMetricUnits(getApplicationContext()));
|
|
||||||
((EditTextPreference) pref).getEditText().setText(String.valueOf(value));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the weight summary.
|
* Updates the weight summary.
|
||||||
*/
|
*/
|
||||||
private void updateWeightSummary() {
|
|
||||||
boolean metricUnits = PreferencesUtils.isMetricUnits(this);
|
|
||||||
updateWeightSummary(metricUnits);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the weight summary.
|
|
||||||
*
|
|
||||||
* @param metricUnits true if metric units
|
|
||||||
*/
|
|
||||||
private void updateWeightSummary(boolean metricUnits) {
|
private void updateWeightSummary(boolean metricUnits) {
|
||||||
int displayValue = getWeightDisplayValue(metricUnits);
|
weightPreference.setSummary(getString(
|
||||||
weightPreference.setSummary(getString(metricUnits ? R.string.value_integer_kilogram
|
metricUnits ? R.string.value_kilogram : R.string.value_pound,
|
||||||
: R.string.value_integer_pound, displayValue));
|
StringUtils.formatWeight(getWeightDisplayValue(metricUnits))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,11 +155,11 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
|||||||
*
|
*
|
||||||
* @param metricUnits true if metric units
|
* @param metricUnits true if metric units
|
||||||
*/
|
*/
|
||||||
private int getWeightDisplayValue(boolean metricUnits) {
|
private double getWeightDisplayValue(boolean metricUnits) {
|
||||||
int value = PreferencesUtils.getInt(this, R.string.stats_weight_key,
|
double value = PreferencesUtils.getFloat(
|
||||||
PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
this, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
||||||
if (!metricUnits) {
|
if (!metricUnits) {
|
||||||
value = (int) Math.round(value * UnitConversions.KG_TO_LB);
|
value = value * UnitConversions.KG_TO_LB;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -223,21 +170,16 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
|||||||
* @param displayValue the display value
|
* @param displayValue the display value
|
||||||
*/
|
*/
|
||||||
private void storeWeightValue(String displayValue) {
|
private void storeWeightValue(String displayValue) {
|
||||||
/*
|
double value;
|
||||||
* TODO add a method to an abstract class or an utility class to avoid
|
|
||||||
* duplicating store preference logic in MapSettingsActivity.java.
|
|
||||||
*/
|
|
||||||
int value;
|
|
||||||
try {
|
try {
|
||||||
value = Integer.parseInt(displayValue);
|
value = Double.parseDouble(displayValue);
|
||||||
if (!PreferencesUtils.isMetricUnits(this)) {
|
if (!PreferencesUtils.isMetricUnits(this)) {
|
||||||
value = (int) (value * UnitConversions.LB_TO_KG);
|
value = value * UnitConversions.LB_TO_KG;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "invalid value " + displayValue);
|
Log.e(TAG, "invalid value " + displayValue);
|
||||||
value = PreferencesUtils.STATS_WEIGHT_DEFAULT;
|
value = PreferencesUtils.STATS_WEIGHT_DEFAULT;
|
||||||
}
|
}
|
||||||
|
PreferencesUtils.setFloat(this, R.string.stats_weight_key, (float) value);
|
||||||
PreferencesUtils.setInt(this, R.string.stats_weight_key, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class TripStatisticsUpdater {
|
|||||||
* calorie
|
* calorie
|
||||||
*/
|
*/
|
||||||
public void addLocation(Location location, int minRecordingDistance,
|
public void addLocation(Location location, int minRecordingDistance,
|
||||||
boolean calculateCalorie, ActivityType activityType, int weight) {
|
boolean calculateCalorie, ActivityType activityType, double weight) {
|
||||||
// Always update time
|
// Always update time
|
||||||
updateTime(location.getTime());
|
updateTime(location.getTime());
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(location)) {
|
||||||
|
|||||||
@@ -120,11 +120,11 @@ public class CalorieUtils {
|
|||||||
int recordingDistanceInterval = PreferencesUtils.getInt(context,
|
int recordingDistanceInterval = PreferencesUtils.getInt(context,
|
||||||
R.string.recording_distance_interval_key,
|
R.string.recording_distance_interval_key,
|
||||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||||
int statsWeight = PreferencesUtils.getInt(
|
double weight = PreferencesUtils.getFloat(
|
||||||
context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
tripStatisticsUpdater.addLocation(
|
tripStatisticsUpdater.addLocation(
|
||||||
iterator.next(), recordingDistanceInterval, true, activityType, statsWeight);
|
iterator.next(), recordingDistanceInterval, true, activityType, weight);
|
||||||
}
|
}
|
||||||
return tripStatisticsUpdater.getTripStatistics().getCalorie();
|
return tripStatisticsUpdater.getTripStatistics().getCalorie();
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ public class CalorieUtils {
|
|||||||
* @param activityType the activity type
|
* @param activityType the activity type
|
||||||
*/
|
*/
|
||||||
public static double getCalorie(
|
public static double getCalorie(
|
||||||
Location start, Location stop, double grade, int weight, ActivityType activityType) {
|
Location start, Location stop, double grade, double weight, ActivityType activityType) {
|
||||||
if (activityType == ActivityType.INVALID) {
|
if (activityType == ActivityType.INVALID) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ public class CalorieUtils {
|
|||||||
* @param weight the weight in kilogram of the rider plus bike
|
* @param weight the weight in kilogram of the rider plus bike
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double getCyclingCalorie(Location start, Location stop, double grade, int weight) {
|
static double getCyclingCalorie(Location start, Location stop, double grade, double weight) {
|
||||||
// Gets duration in seconds
|
// Gets duration in seconds
|
||||||
double duration = (double) (stop.getTime() - start.getTime()) * UnitConversions.MS_TO_S;
|
double duration = (double) (stop.getTime() - start.getTime()) * UnitConversions.MS_TO_S;
|
||||||
// Get speed in meters per second
|
// Get speed in meters per second
|
||||||
@@ -191,7 +191,7 @@ public class CalorieUtils {
|
|||||||
* @param duration the duration in seconds
|
* @param duration the duration in seconds
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double getCyclingCalorie(double speed, double grade, int weight, double duration) {
|
static double getCyclingCalorie(double speed, double grade, double weight, double duration) {
|
||||||
// Get the power in watt (Joule/second)
|
// Get the power in watt (Joule/second)
|
||||||
double power = EARTH_GRAVITY * weight * speed * (K1 + grade) + K2 * (speed * speed * speed);
|
double power = EARTH_GRAVITY * weight * speed * (K1 + grade) + K2 * (speed * speed * speed);
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ public class CalorieUtils {
|
|||||||
* @param weight the weight of the user in kilogram
|
* @param weight the weight of the user in kilogram
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double getFootCalorie(Location start, Location stop, double grade, int weight) {
|
static double getFootCalorie(Location start, Location stop, double grade, double weight) {
|
||||||
// Get speed in meters per second
|
// Get speed in meters per second
|
||||||
double averageSpeed = (start.getSpeed() + stop.getSpeed()) / 2.0;
|
double averageSpeed = (start.getSpeed() + stop.getSpeed()) / 2.0;
|
||||||
// Get VO2 in mL/kg/min
|
// Get VO2 in mL/kg/min
|
||||||
|
|||||||
@@ -106,8 +106,7 @@ public class PreferencesUtils {
|
|||||||
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
|
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
|
||||||
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
|
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
|
||||||
public static final String STATS_UNITS_DEFAULT = "METRIC";
|
public static final String STATS_UNITS_DEFAULT = "METRIC";
|
||||||
public static final boolean STATS_SHOW_CALORIE_DEFAULT = false;
|
public static final float STATS_WEIGHT_DEFAULT = 65.0f; // in kilogram
|
||||||
public static final int STATS_WEIGHT_DEFAULT = 65; // in kilogram
|
|
||||||
|
|
||||||
// Track color
|
// Track color
|
||||||
public static final String TRACK_COLOR_MODE_DEFAULT = "SINGLE";
|
public static final String TRACK_COLOR_MODE_DEFAULT = "SINGLE";
|
||||||
@@ -194,6 +193,35 @@ public class PreferencesUtils {
|
|||||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a float preference value.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param keyId the key id
|
||||||
|
* @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);
|
||||||
|
return sharedPreferences.getFloat(getKey(context, keyId), defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a float preference value.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param keyId the key id
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
|
@SuppressLint("CommitPrefEdits")
|
||||||
|
public static void setFloat(Context context, int keyId, float value) {
|
||||||
|
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||||
|
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
|
Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putFloat(getKey(context, keyId), value);
|
||||||
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a long preference value.
|
* Gets a long preference value.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -149,9 +149,17 @@ public class StringUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String formatWeight(double value) {
|
||||||
|
return formatDecimal(value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
public static String formatDecimal(double value) {
|
public static String formatDecimal(double value) {
|
||||||
String result = String.format(Locale.getDefault(), "%1$,.2f", value);
|
return formatDecimal(value, 2);
|
||||||
return result.endsWith(".00") ? result.substring(0, result.lastIndexOf('.')) : result;
|
}
|
||||||
|
|
||||||
|
private static String formatDecimal(double value, int precision) {
|
||||||
|
String result = String.format(Locale.getDefault(), "%1$,." + precision + "f", value);
|
||||||
|
return value % 1 == 0 ? result.substring(0, result.lastIndexOf('.')) : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user