use of nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryJsonSummary in project Gadgetbridge by Freeyourgadget.
the class ActivitySummariesAdapter method fill_dashboard.
@Override
protected View fill_dashboard(BaseActivitySummary item, int position, View view, ViewGroup parent, Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.activity_summary_dashboard_item, parent, false);
double durationSum = 0;
double caloriesBurntSum = 0;
double distanceSum = 0;
double activeSecondsSum = 0;
double firstItemDate = 0;
double lastItemDate = 0;
int activitiesCount = getCount() - 1;
int activityIcon = 0;
boolean activitySame = true;
TextView durationSumView = view.findViewById(R.id.summary_dashboard_layout_duration_label);
TextView caloriesBurntSumView = view.findViewById(R.id.summary_dashboard_layout_calories_label);
TextView distanceSumView = view.findViewById(R.id.summary_dashboard_layout_distance_label);
TextView activeSecondsSumView = view.findViewById(R.id.summary_dashboard_layout_active_duration_label);
TextView timeStartView = view.findViewById(R.id.summary_dashboard_layout_from_label);
TextView timeEndView = view.findViewById(R.id.summary_dashboard_layout_to_label);
TextView activitiesCountView = view.findViewById(R.id.summary_dashboard_layout_count_label);
TextView activityKindView = view.findViewById(R.id.summary_dashboard_layout_activity_label);
ImageView activityIconView = view.findViewById(R.id.summary_dashboard_layout_activity_icon);
ImageView activityIconBigView = view.findViewById(R.id.summary_dashboard_layout_big_activity_icon);
for (BaseActivitySummary sportitem : getItems()) {
// first item is empty, for dashboard
if (sportitem.getStartTime() == null)
continue;
if (firstItemDate == 0)
firstItemDate = sportitem.getStartTime().getTime();
lastItemDate = sportitem.getEndTime().getTime();
durationSum += sportitem.getEndTime().getTime() - sportitem.getStartTime().getTime();
if (activityIcon == 0) {
activityIcon = sportitem.getActivityKind();
} else {
if (activityIcon != sportitem.getActivityKind()) {
activitySame = false;
}
}
ActivitySummaryJsonSummary activitySummaryJsonSummary = new ActivitySummaryJsonSummary(sportitem);
JSONObject summarySubdata = activitySummaryJsonSummary.getSummaryData();
if (summarySubdata != null) {
try {
if (summarySubdata.has("caloriesBurnt")) {
caloriesBurntSum += summarySubdata.getJSONObject("caloriesBurnt").getDouble("value");
}
if (summarySubdata.has("distanceMeters")) {
distanceSum += summarySubdata.getJSONObject("distanceMeters").getDouble("value");
}
if (summarySubdata.has("activeSeconds")) {
activeSecondsSum += summarySubdata.getJSONObject("activeSeconds").getDouble("value");
}
} catch (JSONException e) {
LOG.error("SportsActivity", e);
}
}
}
DecimalFormat df = new DecimalFormat("#.##");
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)));
distanceSumView.setText(String.format("%s %s", df.format(distanceSum / 1000), context.getString(R.string.km)));
distanceSumView.setText(FormatUtils.getFormattedDistanceLabel(distanceSum));
activeSecondsSumView.setText(String.format("%s", DateTimeUtils.formatDurationHoursMinutes((long) activeSecondsSum, TimeUnit.SECONDS)));
activitiesCountView.setText(String.valueOf(activitiesCount));
String activityName = context.getString(R.string.activity_summaries_all_activities);
if (gettActivityKindFilter() != 0) {
activityName = ActivityKind.asString(gettActivityKindFilter(), context);
activityIconView.setImageResource(ActivityKind.getIconId(gettActivityKindFilter()));
activityIconBigView.setImageResource(ActivityKind.getIconId(gettActivityKindFilter()));
} else {
if (activitySame) {
activityIconView.setImageResource(ActivityKind.getIconId(activityIcon));
activityIconBigView.setImageResource(ActivityKind.getIconId(activityIcon));
}
}
activityKindView.setText(activityName);
// start and end are inverted when filer not applied, because items are sorted the other way
timeStartView.setText((dateFromFilter != 0) ? DateTimeUtils.formatDate(new Date(dateFromFilter)) : DateTimeUtils.formatDate(new Date((long) lastItemDate)));
timeEndView.setText((dateToFilter != 0) ? DateTimeUtils.formatDate(new Date(dateToFilter)) : DateTimeUtils.formatDate(new Date((long) firstItemDate)));
return view;
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryJsonSummary in project Gadgetbridge by Freeyourgadget.
the class ActivitySummaryDetail method makeSummaryContent.
private void makeSummaryContent(BaseActivitySummary 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);
// remove old widgets
fieldLayout.removeAllViews();
ActivitySummaryJsonSummary activitySummaryJsonSummary = new ActivitySummaryJsonSummary(item);
// get list, grouped by groups
JSONObject data = activitySummaryJsonSummary.getSummaryGroupedList();
if (data == null)
return;
Iterator<String> keys = data.keys();
DecimalFormat df = new DecimalFormat("#.##");
while (keys.hasNext()) {
String key = keys.next();
try {
JSONArray innerList = (JSONArray) data.get(key);
TableRow label_row = new TableRow(ActivitySummaryDetail.this);
TextView label_field = new TextView(ActivitySummaryDetail.this);
label_field.setTextSize(16);
label_field.setPadding(0, 10, 0, 0);
label_field.setTypeface(null, Typeface.BOLD);
label_field.setText(String.format("%s", getStringResourceByName(key)));
label_row.addView(label_field);
fieldLayout.addView(label_row);
for (int i = 0; i < innerList.length(); i++) {
TextView name_field = new TextView(ActivitySummaryDetail.this);
TextView value_field = new TextView(ActivitySummaryDetail.this);
name_field.setGravity(Gravity.START);
value_field.setGravity(Gravity.END);
JSONObject innerData = innerList.getJSONObject(i);
String unit = innerData.getString("unit");
String name = innerData.getString("name");
if (!unit.equals("string")) {
double value = innerData.getDouble("value");
if (!show_raw_data) {
// special casing here + imperial units handling
switch(unit) {
case "cm":
if (units.equals(UNIT_IMPERIAL)) {
value = value * 0.0328084;
unit = "ft";
}
break;
case "meters_second":
if (units.equals(UNIT_IMPERIAL)) {
value = value * 2.236936D;
unit = "mi_h";
} else {
// metric
value = value * 3.6;
unit = "km_h";
}
break;
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;
}
}
if (unit.equals("seconds") && !show_raw_data) {
// rather then plain seconds, show formatted duration
value_field.setText(DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS));
} else {
value_field.setText(String.format("%s %s", df.format(value), getStringResourceByName(unit)));
}
} else {
// we could optimize here a bit and only do this for particular activities (swim at the moment...)
value_field.setText(getStringResourceByName(innerData.getString("value")));
}
TableRow field_row = new TableRow(ActivitySummaryDetail.this);
if (i % 2 == 0)
field_row.setBackgroundColor(alternateColor);
name_field.setText(getStringResourceByName(name));
TableRow.LayoutParams params = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1f);
value_field.setLayoutParams(params);
field_row.addView(name_field);
field_row.addView(value_field);
fieldLayout.addView(field_row);
}
} catch (JSONException e) {
LOG.error("SportsActivity", e);
}
}
}
Aggregations