mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 16:15:55 +01:00
minimum working version
This commit is contained in:
parent
7a46d39193
commit
c3887ddb86
@ -25,10 +25,14 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -56,10 +60,14 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
setContentView(R.layout.activity_summary_details);
|
||||
|
||||
Intent intent = getIntent();
|
||||
ActivitySummary summary = (ActivitySummary) intent.getSerializableExtra("summary");
|
||||
|
||||
//if (true) return;
|
||||
|
||||
GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
mGBDevice = device;
|
||||
|
||||
ActivitySummary summary = (ActivitySummary) intent.getSerializableExtra("summary");
|
||||
|
||||
final String gpxTrack = summary.getGpxTrack();
|
||||
Button show_track_btn = (Button) findViewById(R.id.showTrack);
|
||||
show_track_btn.setVisibility(View.GONE);
|
||||
@ -78,8 +86,11 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LOG.debug("petr summary: " + summary + ","+ summary.getSummaryData());
|
||||
String activitykind = ActivityKind.asString(summary.getActivityKind(), getApplicationContext());
|
||||
|
||||
|
||||
String starttime = DateTimeUtils.formatDateTime(summary.getStartTime());
|
||||
String endtime = DateTimeUtils.formatDateTime(summary.getEndTime());
|
||||
Long startTs = summary.getStartTime().getTime() / 1000;
|
||||
@ -101,8 +112,46 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
end_time.setText(endtime);
|
||||
TextView activity_duration = (TextView) findViewById(R.id.duration);
|
||||
activity_duration.setText(durationhms);
|
||||
TextView activity_steps = (TextView) findViewById(R.id.steps);
|
||||
activity_steps.setText(String.valueOf(steps));
|
||||
|
||||
|
||||
JSONObject summaryData = null;
|
||||
String sumData = summary.getSummaryData();
|
||||
if (sumData != null) {
|
||||
try {
|
||||
summaryData = new JSONObject(sumData);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String summaryDatastr = "";
|
||||
|
||||
if (summaryData== null) return;
|
||||
|
||||
Iterator<String> keys = summaryData.keys();
|
||||
LOG.debug("petr summary JSON:" + summaryData + keys);
|
||||
|
||||
while(keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
LOG.debug("petr key:" + key);
|
||||
|
||||
try {
|
||||
|
||||
LOG.debug("petr" + key + ": " + summaryData.get(key) + "\n");
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
JSONObject innerData = (JSONObject) summaryData.get(key);
|
||||
Object value = innerData.get("value");
|
||||
String unit = innerData.getString("unit");
|
||||
summaryDatastr += String.format("%s: %s %s\n", key, df.format(value), unit);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
TextView details = (TextView) findViewById(R.id.details);
|
||||
|
||||
details.setText(summaryDatastr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@ -35,6 +37,7 @@ public interface ActivitySummary extends Serializable {
|
||||
long getDeviceId();
|
||||
|
||||
long getUserId();
|
||||
String getSummaryData();
|
||||
// long getSteps();
|
||||
// float getDistanceMeters();
|
||||
// float getAscentMeters();
|
||||
|
@ -57,7 +57,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FetchSportsSummaryOperation.class);
|
||||
|
||||
private ByteArrayOutputStream buffer = new ByteArrayOutputStream(140);
|
||||
|
||||
private JSONObject summaryData = new JSONObject();
|
||||
public FetchSportsSummaryOperation(HuamiSupport support) {
|
||||
super(support);
|
||||
setName("fetching sport summaries");
|
||||
@ -166,7 +166,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
|
||||
private BaseActivitySummary parseSummary(ByteArrayOutputStream stream) {
|
||||
BaseActivitySummary summary = new BaseActivitySummary();
|
||||
JSONObject summaryData = new JSONObject();
|
||||
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN);
|
||||
// summary.setVersion(BLETypeConversions.toUnsigned(buffer.getShort()));
|
||||
@ -246,6 +246,14 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
"\nlaps=" + laps +
|
||||
""
|
||||
);
|
||||
addSummaryData("averageStrokeDistance", averageStrokeDistance, "m");
|
||||
addSummaryData("averageStrokesPerSecond", averageStrokesPerSecond, "stroke/s");
|
||||
addSummaryData("averageLapPace", averageLapPace, "s");
|
||||
addSummaryData("strokes", strokes, "");
|
||||
addSummaryData("swolfIndex", swolfIndex, "");
|
||||
addSummaryData("swimStyle", swimStyle, "");
|
||||
addSummaryData("laps", laps, "");
|
||||
|
||||
} else {
|
||||
// 28 bytes
|
||||
buffer.getInt(); // unknown
|
||||
@ -265,14 +273,6 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
|
||||
short averageHR = buffer.getShort();
|
||||
|
||||
// this is just here for demonstration purboses for now
|
||||
if (averageHR > 0) {
|
||||
try {
|
||||
summaryData.put("averageHR", averageHR);
|
||||
} catch (JSONException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
short averageKMPaceSeconds = buffer.getShort();
|
||||
short averageStride = buffer.getShort();
|
||||
|
||||
@ -323,10 +323,61 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
// summary.setAveragePace(BLETypeConversions.toUnsigned(averagePace);
|
||||
// summary.setAverageStride(BLETypeConversions.toUnsigned(averageStride);
|
||||
|
||||
addSummaryData("distanceMeters", distanceMeters, "m");
|
||||
addSummaryData("ascentMeters", ascentMeters,"m");
|
||||
addSummaryData("descentMeters", descentMeters,"m");
|
||||
addSummaryData("maxAltitude", maxAltitude,"m");
|
||||
addSummaryData("minAltitude", minAltitude,"m");
|
||||
addSummaryData("steps", steps,"");
|
||||
addSummaryData("activeSeconds", activeSeconds, "s");
|
||||
addSummaryData("caloriesBurnt", caloriesBurnt, "kcal");
|
||||
addSummaryData("maxSpeed", maxSpeed, "m/s");
|
||||
addSummaryData("minPace", minPace, "");
|
||||
addSummaryData("maxPace", maxPace, "");
|
||||
addSummaryData("totalStride", totalStride, "");
|
||||
addSummaryData("averageHR", averageHR, "bpm");
|
||||
addSummaryData("averageKMPaceSeconds", averageKMPaceSeconds, "");
|
||||
addSummaryData("averageStride", averageStride, "cm");
|
||||
|
||||
summary.setSummaryData(summaryData.toString());
|
||||
return summary;
|
||||
}
|
||||
|
||||
private void addSummaryData(String key, float value, String unit) {
|
||||
if (value> 0) {
|
||||
try {
|
||||
JSONObject innerData= new JSONObject();
|
||||
innerData.put("value", value);
|
||||
innerData.put("unit", unit);
|
||||
summaryData.put(key, innerData);
|
||||
} catch (JSONException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
private void addSummaryData(String key, short value, String unit) {
|
||||
if (value> 0) {
|
||||
try {
|
||||
JSONObject innerData= new JSONObject();
|
||||
innerData.put("value", value);
|
||||
innerData.put("unit", unit);
|
||||
summaryData.put(key, innerData);
|
||||
} catch (JSONException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSummaryData(String key, int value, String unit) {
|
||||
if (value> 0) {
|
||||
try {
|
||||
JSONObject innerData= new JSONObject();
|
||||
innerData.put("value", value);
|
||||
innerData.put("unit", unit);
|
||||
summaryData.put(key, innerData);
|
||||
} catch (JSONException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLastSyncTimeKey() {
|
||||
return "lastSportsActivityTimeMillis";
|
||||
|
@ -103,26 +103,18 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/stps"
|
||||
android:id="@+id/summaryDetails"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/steps_label"
|
||||
android:id="@+id/details"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="start"
|
||||
android:text="Steps:" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/steps"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end" />
|
||||
android:gravity="start" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user