mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-26 11:56:48 +01:00
honor Imperial units settings in Widget, Activity list and Workouts, fixes #2041
This commit is contained in:
parent
fb2c9158e4
commit
57fe621ba8
@ -59,6 +59,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2;
|
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.WidgetAlarmsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.WidgetAlarmsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
@ -155,20 +156,31 @@ public class Widget extends AppWidgetProvider {
|
|||||||
long[] dailyTotals = getSteps();
|
long[] dailyTotals = getSteps();
|
||||||
int steps = (int) dailyTotals[0];
|
int steps = (int) dailyTotals[0];
|
||||||
int sleep = (int) dailyTotals[1];
|
int sleep = (int) dailyTotals[1];
|
||||||
|
|
||||||
ActivityUser activityUser = new ActivityUser();
|
ActivityUser activityUser = new ActivityUser();
|
||||||
int stepGoal = activityUser.getStepsGoal();
|
int stepGoal = activityUser.getStepsGoal();
|
||||||
int sleepGoal = activityUser.getSleepDuration();
|
int sleepGoal = activityUser.getSleepDuration();
|
||||||
int sleepGoalMinutes = sleepGoal * 60;
|
int sleepGoalMinutes = sleepGoal * 60;
|
||||||
int distanceGoal = activityUser.getDistanceMeters() * 100;
|
int distanceGoal = activityUser.getDistanceMeters() * 100;
|
||||||
int stepLength = activityUser.getStepLengthCm();
|
int stepLength = activityUser.getStepLengthCm();
|
||||||
int distanceFormatted = (int) (dailyTotals[0] * stepLength / 100);
|
double distanceMeters = dailyTotals[0] * stepLength / 100;
|
||||||
|
double distanceFeet = distanceMeters * 3.28084f;
|
||||||
|
double distanceFormatted = 0;
|
||||||
|
|
||||||
String unit = "###m";
|
String unit = "###m";
|
||||||
if (distanceFormatted > 2000) {
|
distanceFormatted = distanceMeters;
|
||||||
distanceFormatted = distanceFormatted / 1000;
|
if (distanceMeters > 2000) {
|
||||||
|
distanceFormatted = distanceMeters / 1000;
|
||||||
unit = "###.#km";
|
unit = "###.#km";
|
||||||
}
|
}
|
||||||
|
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
|
||||||
|
if (units.equals(GBApplication.getContext().getString(R.string.p_unit_imperial))) {
|
||||||
|
unit = "###ft";
|
||||||
|
distanceFormatted = distanceFeet;
|
||||||
|
if (distanceFeet > 6000) {
|
||||||
|
distanceFormatted = distanceFeet * 0.0001893939f;
|
||||||
|
unit = "###.#mi";
|
||||||
|
}
|
||||||
|
}
|
||||||
DecimalFormat df = new DecimalFormat(unit);
|
DecimalFormat df = new DecimalFormat(unit);
|
||||||
|
|
||||||
views.setTextViewText(R.id.todaywidget_steps, String.format("%1s", steps));
|
views.setTextViewText(R.id.todaywidget_steps, String.format("%1s", steps));
|
||||||
|
@ -312,6 +312,8 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
|
|
||||||
private void makeSummaryContent(BaseActivitySummary item) {
|
private void makeSummaryContent(BaseActivitySummary item) {
|
||||||
//make view of data from summaryData of item
|
//make view of data from summaryData of item
|
||||||
|
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
|
||||||
|
String UNIT_IMPERIAL = GBApplication.getContext().getString(R.string.p_unit_imperial);
|
||||||
|
|
||||||
TableLayout fieldLayout = findViewById(R.id.summaryDetails);
|
TableLayout fieldLayout = findViewById(R.id.summaryDetails);
|
||||||
fieldLayout.removeAllViews(); //remove old widgets
|
fieldLayout.removeAllViews(); //remove old widgets
|
||||||
@ -349,27 +351,56 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
double value = innerData.getDouble("value");
|
double value = innerData.getDouble("value");
|
||||||
|
|
||||||
if (!show_raw_data) {
|
if (!show_raw_data) {
|
||||||
//special casing here:
|
//special casing here + imperial units handling
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case "meters_second":
|
case "cm":
|
||||||
value = value * 3.6;
|
if (units.equals(UNIT_IMPERIAL)) {
|
||||||
unit = "km_h";
|
value = value * 0.0328084;
|
||||||
break;
|
unit = "ft";
|
||||||
case "seconds_m":
|
}
|
||||||
value = value * (1000 / 60D);
|
break;
|
||||||
unit = "minutes_km";
|
case "meters_second":
|
||||||
break;
|
if (units.equals(UNIT_IMPERIAL)) {
|
||||||
case "seconds_km":
|
value = value * 2.236936D;
|
||||||
value = value / 60;
|
unit = "mi_h";
|
||||||
unit = "minutes_km";
|
} else { //metric
|
||||||
break;
|
value = value * 3.6;
|
||||||
case "meters":
|
unit = "km_h";
|
||||||
if (value > 2000) {
|
}
|
||||||
value = value / 1000;
|
break;
|
||||||
unit = "km";
|
case "seconds_m":
|
||||||
|
if (units.equals(UNIT_IMPERIAL)) {
|
||||||
|
value = value * (1609.344 / 60D);
|
||||||
|
unit = "minutes_mi";
|
||||||
|
} else { //metric
|
||||||
|
value = value * (1000 / 60D);
|
||||||
|
unit = "minutes_km";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "seconds_km":
|
||||||
|
if (units.equals(UNIT_IMPERIAL)) {
|
||||||
|
value = value / 60D * 1.609344;
|
||||||
|
unit = "minutes_mi";
|
||||||
|
} else { //metric
|
||||||
|
value = value / 60D;
|
||||||
|
unit = "minutes_km";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "meters":
|
||||||
|
if (units.equals(UNIT_IMPERIAL)) {
|
||||||
|
value = value * 3.28084D;
|
||||||
|
unit = "ft";
|
||||||
|
if (value > 6000) {
|
||||||
|
value = value * 0.0001893939D;
|
||||||
|
unit = "mi";
|
||||||
|
}
|
||||||
|
} else { //metric
|
||||||
|
if (value > 2000) {
|
||||||
|
value = value / 1000;
|
||||||
|
unit = "km";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.adapter.AbstractActivityListingAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.adapter.AbstractActivityListingAdapter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySession;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySession;
|
||||||
@ -244,14 +246,28 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter<Activ
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDistanceLabel(ActivitySession item) {
|
protected String getDistanceLabel(ActivitySession item) {
|
||||||
float distance = item.getDistance();
|
double distanceMeters = item.getDistance();
|
||||||
|
double distanceFeet = distanceMeters * 3.28084f;
|
||||||
|
double distanceFormatted = 0;
|
||||||
|
|
||||||
String unit = "###m";
|
String unit = "###m";
|
||||||
if (distance > 2000) {
|
distanceFormatted = distanceMeters;
|
||||||
distance = distance / 1000;
|
if (distanceMeters > 2000) {
|
||||||
|
distanceFormatted = distanceMeters / 1000;
|
||||||
unit = "###.#km";
|
unit = "###.#km";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
|
||||||
|
if (units.equals(GBApplication.getContext().getString(R.string.p_unit_imperial))) {
|
||||||
|
unit = "###ft";
|
||||||
|
distanceFormatted = distanceFeet;
|
||||||
|
if (distanceFeet > 6000) {
|
||||||
|
distanceFormatted = distanceFeet * 0.0001893939f;
|
||||||
|
unit = "###.#mi";
|
||||||
|
}
|
||||||
|
}
|
||||||
DecimalFormat df = new DecimalFormat(unit);
|
DecimalFormat df = new DecimalFormat(unit);
|
||||||
return df.format(distance);
|
return df.format(distanceFormatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import de.greenrobot.dao.query.QueryBuilder;
|
import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
||||||
@ -221,6 +222,9 @@ public class ActivitySummariesAdapter extends AbstractActivityListingAdapter<Bas
|
|||||||
durationSumView.setText(String.format("%s", DateTimeUtils.formatDurationHoursMinutes((long) durationSum, TimeUnit.MILLISECONDS)));
|
durationSumView.setText(String.format("%s", DateTimeUtils.formatDurationHoursMinutes((long) durationSum, TimeUnit.MILLISECONDS)));
|
||||||
caloriesBurntSumView.setText(String.format("%s %s", (long) caloriesBurntSum, context.getString(R.string.calories_unit)));
|
caloriesBurntSumView.setText(String.format("%s %s", (long) caloriesBurntSum, context.getString(R.string.calories_unit)));
|
||||||
distanceSumView.setText(String.format("%s %s", df.format(distanceSum / 1000), context.getString(R.string.km)));
|
distanceSumView.setText(String.format("%s %s", df.format(distanceSum / 1000), context.getString(R.string.km)));
|
||||||
|
distanceSumView.setText(getLabel(distanceSum));
|
||||||
|
|
||||||
|
|
||||||
activeSecondsSumView.setText(String.format("%s", DateTimeUtils.formatDurationHoursMinutes((long) activeSecondsSum, TimeUnit.SECONDS)));
|
activeSecondsSumView.setText(String.format("%s", DateTimeUtils.formatDurationHoursMinutes((long) activeSecondsSum, TimeUnit.SECONDS)));
|
||||||
activitiesCountView.setText(String.valueOf(activitiesCount));
|
activitiesCountView.setText(String.valueOf(activitiesCount));
|
||||||
String activityName = context.getString(R.string.activity_summaries_all_activities);
|
String activityName = context.getString(R.string.activity_summaries_all_activities);
|
||||||
@ -312,6 +316,31 @@ public class ActivitySummariesAdapter extends AbstractActivityListingAdapter<Bas
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getLabel(double distance) {
|
||||||
|
double distanceMetric = distance;
|
||||||
|
double distanceImperial = distanceMetric * 3.28084f;
|
||||||
|
double distanceFormatted = 0;
|
||||||
|
|
||||||
|
String unit = "###m";
|
||||||
|
distanceFormatted = distanceMetric;
|
||||||
|
if (distanceMetric > 2000) {
|
||||||
|
distanceFormatted = distanceMetric / 1000;
|
||||||
|
unit = "###.#km";
|
||||||
|
}
|
||||||
|
|
||||||
|
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
|
||||||
|
if (units.equals(GBApplication.getContext().getString(R.string.p_unit_imperial))) {
|
||||||
|
unit = "###ft";
|
||||||
|
distanceFormatted = distanceImperial;
|
||||||
|
if (distanceImperial > 6000) {
|
||||||
|
distanceFormatted = distanceImperial * 0.0001893939f;
|
||||||
|
unit = "###.#mi";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DecimalFormat df = new DecimalFormat(unit);
|
||||||
|
return df.format(distanceFormatted);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getHrLabel(BaseActivitySummary item) {
|
protected String getHrLabel(BaseActivitySummary item) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -1035,9 +1035,12 @@
|
|||||||
<!-- activity summary units-->
|
<!-- activity summary units-->
|
||||||
<string name="meters">m</string>
|
<string name="meters">m</string>
|
||||||
<string name="cm">cm</string>
|
<string name="cm">cm</string>
|
||||||
|
<string name="ft">ft</string>
|
||||||
<string name="steps_unit">steps</string>
|
<string name="steps_unit">steps</string>
|
||||||
<string name="meters_second">m/s</string>
|
<string name="meters_second">m/s</string>
|
||||||
<string name="km_h">km/h</string>
|
<string name="km_h">km/h</string>
|
||||||
|
<string name="mi_h">mi/h</string>
|
||||||
|
<string name="minutes_mi">min/mi</string>
|
||||||
<string name="strokes_second">str/s</string>
|
<string name="strokes_second">str/s</string>
|
||||||
<string name="strokes_unit">str</string>
|
<string name="strokes_unit">str</string>
|
||||||
<string name="seconds">sec</string>
|
<string name="seconds">sec</string>
|
||||||
@ -1050,6 +1053,7 @@
|
|||||||
<string name="minutes_km">min/km</string>
|
<string name="minutes_km">min/km</string>
|
||||||
<string name="bpm">bpm</string>
|
<string name="bpm">bpm</string>
|
||||||
<string name="km">km</string>
|
<string name="km">km</string>
|
||||||
|
<string name="mi">mi</string>
|
||||||
<!-- activity summary groups-->
|
<!-- activity summary groups-->
|
||||||
<string name="Strokes">Strokes</string>
|
<string name="Strokes">Strokes</string>
|
||||||
<string name="Swimming">Swimming</string>
|
<string name="Swimming">Swimming</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user