use of com.google.android.gms.fitness.request.DataReadRequest in project capacitor-google-fit by perfood.
the class GoogleFitPlugin method getHistoryActivity.
@PluginMethod
public Task<DataReadResponse> getHistoryActivity(final PluginCall call) throws ParseException {
final GoogleSignInAccount account = getAccount();
if (account == null) {
call.reject("No access");
return null;
}
long startTime = dateToTimestamp(call.getString("startTime"));
long endTime = dateToTimestamp(call.getString("endTime"));
if (startTime == -1 || endTime == -1) {
call.reject("Must provide a start time and end time");
return null;
}
DataReadRequest readRequest = new DataReadRequest.Builder().aggregate(DataType.TYPE_STEP_COUNT_DELTA).aggregate(DataType.AGGREGATE_STEP_COUNT_DELTA).aggregate(DataType.TYPE_DISTANCE_DELTA).aggregate(DataType.AGGREGATE_DISTANCE_DELTA).aggregate(DataType.TYPE_SPEED).aggregate(DataType.TYPE_CALORIES_EXPENDED).aggregate(DataType.AGGREGATE_CALORIES_EXPENDED).aggregate(DataType.TYPE_WEIGHT).setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).bucketByActivitySegment(1, TimeUnit.MINUTES).enableServerQueries().build();
return Fitness.getHistoryClient(getActivity(), account).readData(readRequest).addOnSuccessListener(new OnSuccessListener<DataReadResponse>() {
@Override
public void onSuccess(DataReadResponse dataReadResponse) {
List<Bucket> buckets = dataReadResponse.getBuckets();
JSONArray activities = new JSONArray();
for (Bucket bucket : buckets) {
JSONObject summary = new JSONObject();
try {
summary.put("start", timestampToDate(bucket.getStartTime(TimeUnit.MILLISECONDS)));
summary.put("end", timestampToDate(bucket.getEndTime(TimeUnit.MILLISECONDS)));
List<DataSet> dataSets = bucket.getDataSets();
for (DataSet dataSet : dataSets) {
if (dataSet.getDataPoints().size() > 0) {
switch(dataSet.getDataType().getName()) {
case "com.google.distance.delta":
summary.put("distance", dataSet.getDataPoints().get(0).getValue(Field.FIELD_DISTANCE));
break;
case "com.google.speed.summary":
summary.put("speed", dataSet.getDataPoints().get(0).getValue(Field.FIELD_AVERAGE));
break;
case "com.google.calories.expended":
summary.put("calories", dataSet.getDataPoints().get(0).getValue(Field.FIELD_CALORIES));
break;
case "com.google.weight.summary":
summary.put("weight", dataSet.getDataPoints().get(0).getValue(Field.FIELD_AVERAGE));
break;
case "com.google.step_count.delta":
summary.put("steps", dataSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS));
break;
default:
Log.i(TAG, "need to handle " + dataSet.getDataType().getName());
}
}
}
summary.put("activity", bucket.getActivity());
} catch (JSONException e) {
call.reject(e.getMessage());
return;
}
activities.put(summary);
}
JSObject result = new JSObject();
result.put("activities", activities);
call.resolve(result);
}
});
}
use of com.google.android.gms.fitness.request.DataReadRequest in project Zweet-Fit-App by rachit0904.
the class StatData_TestActivity method getDataRequestForWeeks.
// create request to retrieve step history for specific weeks
public static DataReadRequest getDataRequestForWeeks(int weeks) {
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.WEEK_OF_YEAR, -1 * weeks);
long startTime = cal.getTimeInMillis();
java.text.DateFormat dateFormat = DateFormat.getDateInstance();
Log.e(TAG, "Range Start: " + dateFormat.format(startTime));
Log.e(TAG, "Range End: " + dateFormat.format(endTime));
final DataSource ds = new DataSource.Builder().setAppPackageName("com.google.android.gms").setDataType(DataType.TYPE_STEP_COUNT_DELTA).setType(DataSource.TYPE_DERIVED).setStreamName("estimated_steps").build();
DataReadRequest readRequest = new DataReadRequest.Builder().aggregate(ds, DataType.TYPE_STEP_COUNT_DELTA).bucketByTime(1, TimeUnit.DAYS).setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).build();
return readRequest;
}
use of com.google.android.gms.fitness.request.DataReadRequest in project Zweet-Fit-App by rachit0904.
the class home_fragment method getDataRequestForWeeks.
// create request to retrieve step history for specific weeks
public static DataReadRequest getDataRequestForWeeks(String startDate, String endDate) {
long start = LocalDateTime.of(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1]), Integer.parseInt(startDate.split("-")[2]), 0, 0).toEpochSecond(ZoneOffset.UTC);
long end = LocalDateTime.of(Integer.parseInt(endDate.split("-")[0]), Integer.parseInt(endDate.split("-")[1]), Integer.parseInt(endDate.split("-")[2]), 0, 0).toEpochSecond(ZoneOffset.UTC);
java.text.DateFormat dateFormat = DateFormat.getDateInstance();
Log.e(TAG, "Range Start: " + (startDate));
Log.e(TAG, "Range End: " + (endDate));
final DataSource ds = new DataSource.Builder().setAppPackageName("com.google.android.gms").setDataType(DataType.TYPE_STEP_COUNT_DELTA).setType(DataSource.TYPE_DERIVED).setStreamName("estimated_steps").build();
DataReadRequest readRequest = new DataReadRequest.Builder().aggregate(ds, DataType.TYPE_STEP_COUNT_DELTA).bucketByTime(1, TimeUnit.DAYS).setTimeRange(start, end, TimeUnit.SECONDS).build();
return readRequest;
}
use of com.google.android.gms.fitness.request.DataReadRequest in project Zweet-Fit-App by rachit0904.
the class DailyStatView method getDataRequestForWeeks.
// create request to retrieve step history for specific weeks
public static DataReadRequest getDataRequestForWeeks(String startDate, String endDate) {
long start = LocalDateTime.of(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1]), Integer.parseInt(startDate.split("-")[2]), 0, 0).toEpochSecond(ZoneOffset.UTC);
long end = LocalDateTime.of(Integer.parseInt(endDate.split("-")[0]), Integer.parseInt(endDate.split("-")[1]), Integer.parseInt(endDate.split("-")[2]), 0, 0).toEpochSecond(ZoneOffset.UTC);
java.text.DateFormat dateFormat = DateFormat.getDateInstance();
Log.e(TAG, "Range Start: " + (startDate));
Log.e(TAG, "Range End: " + (endDate));
final DataSource ds = new DataSource.Builder().setAppPackageName("com.google.android.gms").setDataType(DataType.TYPE_STEP_COUNT_DELTA).setType(DataSource.TYPE_DERIVED).setStreamName("estimated_steps").build();
DataReadRequest readRequest = new DataReadRequest.Builder().aggregate(ds, DataType.TYPE_STEP_COUNT_DELTA).bucketByTime(1, TimeUnit.DAYS).setTimeRange(start, end, TimeUnit.SECONDS).build();
return readRequest;
}
use of com.google.android.gms.fitness.request.DataReadRequest in project Zweet-Fit-App by rachit0904.
the class WeeklyStatView method getDataRequestForDuration.
// create request to retrieve step history for specific weeks
public static DataReadRequest getDataRequestForDuration(String startDate, String endDate) {
long start = LocalDateTime.of(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1]), Integer.parseInt(startDate.split("-")[2]), 0, 0).toEpochSecond(ZoneOffset.UTC);
long end = LocalDateTime.of(Integer.parseInt(endDate.split("-")[0]), Integer.parseInt(endDate.split("-")[1]), Integer.parseInt(endDate.split("-")[2]), 0, 0).toEpochSecond(ZoneOffset.UTC);
java.text.DateFormat dateFormat = DateFormat.getDateInstance();
Log.e(TAG, "Range Start: " + dateFormat.format(start));
Log.e(TAG, "Range End: " + dateFormat.format(end));
final DataSource ds = new DataSource.Builder().setAppPackageName("com.google.android.gms").setDataType(DataType.TYPE_STEP_COUNT_DELTA).setType(DataSource.TYPE_DERIVED).setStreamName("estimated_steps").build();
DataReadRequest readRequest = new DataReadRequest.Builder().aggregate(ds, DataType.TYPE_STEP_COUNT_DELTA).bucketByTime(1, TimeUnit.DAYS).setTimeRange(start, end, TimeUnit.SECONDS).build();
return readRequest;
}
Aggregations