本文整理汇总了Java中com.google.android.gms.fitness.request.DataReadRequest类的典型用法代码示例。如果您正苦于以下问题:Java DataReadRequest类的具体用法?Java DataReadRequest怎么用?Java DataReadRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataReadRequest类属于com.google.android.gms.fitness.request包,在下文中一共展示了DataReadRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryFitnessData
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
/**
* Query to get the num of steps since 00:00 until now
*/
private DataReadRequest queryFitnessData() {
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long startTime = cal.getTimeInMillis();
return new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
}
示例2: accessFitnessHistory
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
private void accessFitnessHistory() {
Log.d(TAG, "accessFitnessHistory()...");
Calendar startTimeCalendar = Calendar.getInstance();
startTimeCalendar.set(2014, 4, 4);
DataReadRequest readDataRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_STEP_COUNT_CUMULATIVE)
.setLimit(18)
.setTimeRange(startTimeCalendar.getTimeInMillis(), System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.build();
PendingResult<DataReadResult> pendingResultDataReadResult = Fitness.HistoryApi.readData(googleApiClient, readDataRequest);
pendingResultDataReadResult.setResultCallback(new ResultCallback<DataReadResult>() {
public void onResult(DataReadResult dataReadResult) {
String historyInfo = Arrays.deepToString(dataReadResult.getDataSets().toArray());
Log.d(TAG, "accessFitnessHistory() dataReadResult=" + historyInfo);
addContentToView("DataReadResult = " + historyInfo);
}
}
);
}
示例3: queryDataWithBuckets
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
/**
* Return a {@link DataReadRequest} for all step count changes in the past week.
*/
private DataReadRequest queryDataWithBuckets(long startTime, long endTime, List<DataType> types, List<DataType> aggregations, int duration, TimeUnit time, int bucketType) {
DataReadRequest.Builder builder = new DataReadRequest.Builder();
for (int i=0; i< types.size(); i++) {
builder.aggregate(types.get(i), aggregations.get(i));
}
switch (bucketType) {
case 2:
builder.bucketByActivitySegment(duration, time);
break;
case 1:
builder.bucketByActivityType(duration, time);
break;
case 0:
default:
builder.bucketByTime(duration, time);
break;
}
return builder.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).build();
}
示例4: queryStepEstimate
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
/**
* GET total estimated STEP_COUNT
*
* Retrieves an estimated step count.
*
*/
public static DataReadRequest queryStepEstimate(long startTime, long endTime) {
DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.setAppPackageName("com.google.android.gms")
.build();
return new DataReadRequest.Builder()
.aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.enableServerQueries() // Used to retrieve data from cloud
.build();
}
示例5: getSteps
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
@Override
public void getSteps(long startTime,
long endTime,
TimeUnit rangeUnit,
int duration,
TimeUnit durationUnit,
int requestId) {
if(mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
DataReadRequest request = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.bucketByTime(duration, durationUnit)
.setTimeRange(startTime, endTime, rangeUnit)
.build();
//int requestId = mRequestId++;
mRequestMap.put(requestId, RequestType.Step);
new ReadFitnessThread(mGoogleApiClient, requestId, request, this).start();
return;
}
notifyStepsReceived(FitnessLibrary.IFitnessLibraryListener.ExecutionStatus.Error, requestId, new ArrayList<StepBucket>());
}
示例6: getActivities
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
@Override
public void getActivities(long startTime,
long endTime,
TimeUnit rangeUnit,
int duration,
TimeUnit durationUnit,
int requestId) {
if(mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
DataReadRequest request = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(duration, durationUnit)
.setTimeRange(startTime, endTime, rangeUnit)
.build();
//int requestId = mRequestId++;
mRequestMap.put(requestId, RequestType.Activity);
new ReadFitnessThread(mGoogleApiClient, requestId, request, this).start();
return;
}
notifyActivitiesReceived(FitnessLibrary.IFitnessLibraryListener.ExecutionStatus.Error, requestId, new ArrayList<ActivityBucket>());
}
示例7: getBasalAVG
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
private float getBasalAVG(long _et) throws Exception {
float basalAVG = 0;
Calendar cal = java.util.Calendar.getInstance();
cal.setTime(new Date(_et));
//set start time to a week before end time
cal.add(Calendar.WEEK_OF_YEAR, -1);
long nst = cal.getTimeInMillis();
DataReadRequest.Builder builder = new DataReadRequest.Builder();
builder.aggregate(DataType.TYPE_BASAL_METABOLIC_RATE, DataType.AGGREGATE_BASAL_METABOLIC_RATE_SUMMARY);
builder.bucketByTime(1, TimeUnit.DAYS);
builder.setTimeRange(nst, _et, TimeUnit.MILLISECONDS);
DataReadRequest readRequest = builder.build();
DataReadResult dataReadResult = Fitness.HistoryApi.readData(googleFitManager.getGoogleApiClient(), readRequest).await();
if (dataReadResult.getStatus().isSuccess()) {
JSONObject obj = new JSONObject();
int avgsN = 0;
for (Bucket bucket : dataReadResult.getBuckets()) {
// in the com.google.bmr.summary data type, each data point represents
// the average, maximum and minimum basal metabolic rate, in kcal per day, over the time interval of the data point.
DataSet ds = bucket.getDataSet(DataType.AGGREGATE_BASAL_METABOLIC_RATE_SUMMARY);
for (DataPoint dp : ds.getDataPoints()) {
float avg = dp.getValue(Field.FIELD_AVERAGE).asFloat();
basalAVG += avg;
avgsN++;
}
}
// do the average of the averages
if (avgsN != 0) basalAVG /= avgsN; // this a daily average
return basalAVG;
} else throw new Exception(dataReadResult.getStatus().getStatusMessage());
}
示例8: doInBackground
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
protected Void doInBackground(Void... params) {
// Create a new dataset and insertion request.
// DataSet dataSet = insertFitnessData();
// [START insert_dataset]
// Then, invoke the History API to insert the data and await the result, which is
// possible here because of the {@link AsyncTask}. Always include a timeout when calling
// await() to prevent hanging that can occur from the service being shutdown because
// of low memory or other conditions.
// Log.i(TAG, "Inserting the dataset in the History API.");
// com.google.android.gms.common.api.Status insertStatus =
// Fitness.HistoryApi.insertData(mClient, dataSet)
// .await(1, TimeUnit.MINUTES);
//
// // Before querying the data, check to see if the insertion succeeded.
// if (!insertStatus.isSuccess()) {
// Log.i(TAG, "There was a problem inserting the dataset.");
// return null;
// }
//
// // At this point, the data has been inserted and can be read.
// Log.i(TAG, "Data insert was successful!");
// // [END insert_dataset]
// Begin by creating the query.
DataReadRequest readRequest = queryFitnessData();
// [START read_dataset]
// Invoke the History API to fetch the data with the query and await the result of
// the read request.
DataReadResult dataReadResult =
Fitness.HistoryApi.readData(mClient, readRequest).await(1, TimeUnit.MINUTES);
// [END read_dataset]
// For the sake of the sample, we'll print the data so we can see what we just added.
// In general, logging fitness information should be avoided for privacy reasons.
printData(dataReadResult);
return null;
}
示例9: queryFitnessData
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
/**
* Return a {@link DataReadRequest} for all step count changes in the past week.
*/
public static DataReadRequest queryFitnessData() {
// [START build_read_data_request]
// Setting a start and end date using a range of 1 week before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.MINUTE, -10);
long startTime = cal.getTimeInMillis();
java.text.DateFormat dateFormat = getDateInstance();
Log.i(TAG, "Range Start: " + dateFormat.format(startTime));
Log.i(TAG, "Range End: " + dateFormat.format(endTime));
DataReadRequest readRequest = new DataReadRequest.Builder()
// The data request can specify multiple data types to return, effectively
// combining multiple data queries into one call.
// In this example, it's very unlikely that the request is for several hundred
// datapoints each consisting of a few steps and a timestamp. The more likely
// scenario is wanting to see how many steps were walked per day, for 7 days.
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
// Analogous to a "Group By" in SQL, defines how data should be aggregated.
// bucketByTime allows for a time span, whereas bucketBySession would allow
// bucketing by "sessions", which would need to be defined in code.
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
// [END build_read_data_request]
return readRequest;
}
示例10: fetchStepsCount
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
public void fetchStepsCount() {
ex.execute(new Runnable() {
@Override
public void run() {
// Find steps from Fitness API
DataReadRequest r = queryFitnessData();
DataReadResult dataReadResult = Fitness.HistoryApi.readData(client, r).await(1, TimeUnit.MINUTES);
boolean stepsFetched = false;
if (dataReadResult.getBuckets().size() > 0) {
Bucket bucket = dataReadResult.getBuckets().get(0);
DataSet ds = bucket.getDataSet(DataType.TYPE_STEP_COUNT_DELTA);
if (ds != null) {
for (DataPoint dp : ds.getDataPoints()) {
for (Field field : dp.getDataType().getFields()) {
if (field.getName().equals("steps")) {
stepsFetched = true;
listener.onStepsCountFetched(dp.getValue(field).asInt());
}
}
}
}
}
if (!stepsFetched) {
// No steps today yet or no fitness data available
listener.onStepsCountFetched(0);
}
}
});
}
示例11: checkStreak
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
private void checkStreak(final long timeEnd, final int consecutiveDaysNumber) {
if(consecutiveDaysNumber == 0) {
stepsDuringConsecutiveDays = 0;
}
final long timeStart = (timeEnd - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS));
final DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_STEP_COUNT_DELTA)
.enableServerQueries()
.setTimeRange(timeStart, timeEnd, TimeUnit.MILLISECONDS)
.build();
Fitness.HistoryApi.readData(mClient, readRequest).setResultCallback(new ResultCallback<DataReadResult>() {
@Override
public void onResult(DataReadResult dataReadResult) {
DataSet stepData = dataReadResult.getDataSet(DataType.TYPE_STEP_COUNT_DELTA);
int totalSteps = 0;
for (DataPoint dp : stepData.getDataPoints()) {
for(Field field : dp.getDataType().getFields()) {
int steps = dp.getValue(field).asInt();
totalSteps += steps;
}
}
if(totalSteps > 0) {
stepsDuringConsecutiveDays += totalSteps;
checkStreak((timeEnd - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS)), consecutiveDaysNumber + 1);
} else {
//set dayNumber as consecutiveDays
if(consecutiveDaysNumber > 0) {
Log.d(TAG, "onResult consecutive days: " + consecutiveDaysNumber);
consecutiveDays = new ConsecutiveDays(stepsDuringConsecutiveDays, consecutiveDaysNumber);
coordinator.completeAction(ACTION_CONSECUTIVE_DAYS);
}
}
}
});
}
示例12: getActivityDistancesRequest
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
private DataReadRequest getActivityDistancesRequest() {
Date pastDate = new Date(1);
Date presentDate = new Date();
return new DataReadRequest.Builder()
.aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
.bucketByActivityType(1, TimeUnit.SECONDS)
.setTimeRange(pastDate.getTime(), presentDate.getTime(), TimeUnit.MILLISECONDS)
.build();
}
示例13: queryActivitySegment
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
/**
* GET data by ACTIVITY
*
* The Google Fit API suggests that we don't want granular data, HOWEVER, we need granular
* data to do anything remotely interesting with the data. This takes a while so we'll store
* the results in a local db.
*
* After retrieving all activity segments, we go back and ask for step counts for each
* segment. This allows us to summarize steps and duration per activity.
*
*/
public static DataReadRequest queryActivitySegment(long startTime, long endTime, boolean isNetworkConnected) {
if(isNetworkConnected) {
return new DataReadRequest.Builder()
.read(DataType.TYPE_ACTIVITY_SEGMENT)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.enableServerQueries() // Used to retrieve data from cloud.
.build();
}else {
return new DataReadRequest.Builder()
.read(DataType.TYPE_ACTIVITY_SEGMENT)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
}
}
示例14: queryActivitySegmentBucket
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
public static DataReadRequest queryActivitySegmentBucket(long startTime, long endTime) {
return new DataReadRequest.Builder()
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.enableServerQueries() // Used to retrieve data from cloud
.build();
}
示例15: queryStepCount
import com.google.android.gms.fitness.request.DataReadRequest; //导入依赖的package包/类
/**
* GET step count for a specific ACTIVITY.
*
* Retrieves a raw step count.
*
*/
public static DataReadRequest queryStepCount(long startTime, long endTime) {
return new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.enableServerQueries() // Used to retrieve data from cloud
.build();
}