forked from upstream-mirrors/OpenTracks
Change code style about calorie.
This commit is contained in:
@@ -74,7 +74,7 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
|||||||
@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() {
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||||
configRateListPreference(PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue));
|
configRateListPreference(PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue));
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class CalorieUtils {
|
|||||||
double power = earthGravity * weight * speed * (K1 + grade) + K2 * (speed * speed * speed);
|
double power = earthGravity * weight * speed * (K1 + grade) + K2 * (speed * speed * speed);
|
||||||
|
|
||||||
// Get the calories in kcal
|
// Get the calories in kcal
|
||||||
return power * timeUsed / UnitConversions.KCAL_TO_J / 1000 ;
|
return power * timeUsed / UnitConversions.KCAL_TO_J;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -220,7 +220,7 @@ public class CalorieUtils {
|
|||||||
public static double getCalorie(Location start, Location stop, double grade, int weight,
|
public static double getCalorie(Location start, Location stop, double grade, int weight,
|
||||||
ActivityType activityType) {
|
ActivityType activityType) {
|
||||||
if (activityType == ActivityType.INVALID) {
|
if (activityType == ActivityType.INVALID) {
|
||||||
return TripStatistics.INVALID_CALORIE;
|
return TripStatistics.CALORIE_UNDEFINED;
|
||||||
}
|
}
|
||||||
return ActivityType.CYCLING == activityType ? calculateCalorieCycling(start, stop, grade,
|
return ActivityType.CYCLING == activityType ? calculateCalorieCycling(start, stop, grade,
|
||||||
weight) : calculateCalorieFoot(start, stop, grade, weight);
|
weight) : calculateCalorieFoot(start, stop, grade, weight);
|
||||||
@@ -282,7 +282,7 @@ public class CalorieUtils {
|
|||||||
public static double calculateTrackCalorie(Context context, Track track, String category) {
|
public static double calculateTrackCalorie(Context context, Track track, String category) {
|
||||||
ActivityType activityType = getActivityType(context, category);
|
ActivityType activityType = getActivityType(context, category);
|
||||||
if (activityType == ActivityType.INVALID) {
|
if (activityType == ActivityType.INVALID) {
|
||||||
return TripStatistics.INVALID_CALORIE;
|
return TripStatistics.CALORIE_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
double calorie = 0.0;
|
double calorie = 0.0;
|
||||||
|
|||||||
@@ -354,14 +354,18 @@ public class StatsUtils {
|
|||||||
View view = activity.findViewById(itemId);
|
View view = activity.findViewById(itemId);
|
||||||
Button button = (Button) activity.findViewById(R.id.stats_calorie_setup);
|
Button button = (Button) activity.findViewById(R.id.stats_calorie_setup);
|
||||||
// Current activity type is not supported.
|
// Current activity type is not supported.
|
||||||
if (calorie == TripStatistics.INVALID_CALORIE) {
|
if (calorie == TripStatistics.CALORIE_UNDEFINED) {
|
||||||
// Return when it is not a valid track, which may be aggregated stats or
|
|
||||||
// marker.
|
|
||||||
if (trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
button.setVisibility(View.VISIBLE);
|
button.setVisibility(View.VISIBLE);
|
||||||
view.setVisibility(View.GONE);
|
view.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return when it is not a valid track, which may be aggregated stats or
|
||||||
|
* marker.
|
||||||
|
*/
|
||||||
|
if (trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
|
||||||
|
button.setVisibility(View.GONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
button.setOnClickListener(new OnClickListener() {
|
button.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|||||||
@@ -78,5 +78,8 @@ public class UnitConversions {
|
|||||||
public static final double DEG_TO_RAD = Math.PI / 180.0;
|
public static final double DEG_TO_RAD = Math.PI / 180.0;
|
||||||
|
|
||||||
// multiplication factor to convert Kcal to joules.
|
// multiplication factor to convert Kcal to joules.
|
||||||
public static final double KCAL_TO_J = 4.184;
|
public static final double KCAL_TO_J = 4184;
|
||||||
|
|
||||||
|
// multiplication factor to convert joules to Kcal.
|
||||||
|
public static final double J_TO_KCAL = 1 / KCAL_TO_J;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ public class TripStatistics implements Parcelable {
|
|||||||
* This value means the calorie value is invalid due to activity type is not
|
* This value means the calorie value is invalid due to activity type is not
|
||||||
* supported.
|
* supported.
|
||||||
*/
|
*/
|
||||||
public static final double INVALID_CALORIE = -1.0;
|
public static final double CALORIE_UNDEFINED = -1.0;
|
||||||
|
|
||||||
// The calorie of current track.
|
// The calorie of current track.
|
||||||
private double calorie = INVALID_CALORIE;
|
private double calorie = CALORIE_UNDEFINED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
@@ -128,7 +128,7 @@ public class TripStatistics implements Parcelable {
|
|||||||
gradeExtremities.update(other.gradeExtremities.getMin());
|
gradeExtremities.update(other.gradeExtremities.getMin());
|
||||||
gradeExtremities.update(other.gradeExtremities.getMax());
|
gradeExtremities.update(other.gradeExtremities.getMax());
|
||||||
}
|
}
|
||||||
if (other.calorie != INVALID_CALORIE) {
|
if (other.calorie != CALORIE_UNDEFINED) {
|
||||||
calorie += other.calorie;
|
calorie += other.calorie;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -585,10 +585,10 @@ public class TripStatistics implements Parcelable {
|
|||||||
* @param calorieAdded add the value to the total calorie
|
* @param calorieAdded add the value to the total calorie
|
||||||
*/
|
*/
|
||||||
public void addCalorie(double calorieAdded) {
|
public void addCalorie(double calorieAdded) {
|
||||||
if (calorieAdded != INVALID_CALORIE) {
|
if (calorieAdded != CALORIE_UNDEFINED) {
|
||||||
calorie = calorie == INVALID_CALORIE ? calorieAdded : calorie + calorieAdded;
|
calorie = calorie == CALORIE_UNDEFINED ? calorieAdded : calorie + calorieAdded;
|
||||||
} else {
|
} else {
|
||||||
calorie = INVALID_CALORIE;
|
calorie = CALORIE_UNDEFINED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user