Change code style about calorie.

This commit is contained in:
youtaol
2013-10-10 11:16:58 +08:00
parent 800fabd5a0
commit 8e9be4fcf0
5 changed files with 24 additions and 17 deletions
@@ -74,7 +74,7 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
@SuppressWarnings("deprecation")
ListPreference listPreference = (ListPreference) findPreference(getString(R.string.stats_units_key));
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceChange(Preference pref, Object 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);
// 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,
ActivityType activityType) {
if (activityType == ActivityType.INVALID) {
return TripStatistics.INVALID_CALORIE;
return TripStatistics.CALORIE_UNDEFINED;
}
return ActivityType.CYCLING == activityType ? calculateCalorieCycling(start, stop, grade,
weight) : calculateCalorieFoot(start, stop, grade, weight);
@@ -282,7 +282,7 @@ public class CalorieUtils {
public static double calculateTrackCalorie(Context context, Track track, String category) {
ActivityType activityType = getActivityType(context, category);
if (activityType == ActivityType.INVALID) {
return TripStatistics.INVALID_CALORIE;
return TripStatistics.CALORIE_UNDEFINED;
}
double calorie = 0.0;
@@ -354,14 +354,18 @@ public class StatsUtils {
View view = activity.findViewById(itemId);
Button button = (Button) activity.findViewById(R.id.stats_calorie_setup);
// Current activity type is not supported.
if (calorie == TripStatistics.INVALID_CALORIE) {
// Return when it is not a valid track, which may be aggregated stats or
// marker.
if (trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
return;
}
if (calorie == TripStatistics.CALORIE_UNDEFINED) {
button.setVisibility(View.VISIBLE);
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() {
@Override
public void onClick(View v) {
@@ -78,5 +78,8 @@ public class UnitConversions {
public static final double DEG_TO_RAD = Math.PI / 180.0;
// 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
* supported.
*/
public static final double INVALID_CALORIE = -1.0;
public static final double CALORIE_UNDEFINED = -1.0;
// The calorie of current track.
private double calorie = INVALID_CALORIE;
private double calorie = CALORIE_UNDEFINED;
/**
* Default constructor.
@@ -128,7 +128,7 @@ public class TripStatistics implements Parcelable {
gradeExtremities.update(other.gradeExtremities.getMin());
gradeExtremities.update(other.gradeExtremities.getMax());
}
if (other.calorie != INVALID_CALORIE) {
if (other.calorie != CALORIE_UNDEFINED) {
calorie += other.calorie;
}
}
@@ -585,10 +585,10 @@ public class TripStatistics implements Parcelable {
* @param calorieAdded add the value to the total calorie
*/
public void addCalorie(double calorieAdded) {
if (calorieAdded != INVALID_CALORIE) {
calorie = calorie == INVALID_CALORIE ? calorieAdded : calorie + calorieAdded;
if (calorieAdded != CALORIE_UNDEFINED) {
calorie = calorie == CALORIE_UNDEFINED ? calorieAdded : calorie + calorieAdded;
} else {
calorie = INVALID_CALORIE;
calorie = CALORIE_UNDEFINED;
}
}