本文整理汇总了Java中com.google.android.gms.fitness.data.DataSet.add方法的典型用法代码示例。如果您正苦于以下问题:Java DataSet.add方法的具体用法?Java DataSet.add怎么用?Java DataSet.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.fitness.data.DataSet
的用法示例。
在下文中一共展示了DataSet.add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDataForRequest
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
/**
* This method creates a dataset object to be able to insert data in google fit
* @param dataType DataType Fitness Data Type object
* @param dataSourceType int Data Source Id. For example, DataSource.TYPE_RAW
* @param value Object Values for the fitness data. They must be int or float
* @param startTime long Time when the fitness activity started
* @param endTime long Time when the fitness activity finished
* @param timeUnit TimeUnit Time unit in which period is expressed
* @return
*/
private DataSet createDataForRequest(DataType dataType, int dataSourceType, Double value,
long startTime, long endTime, TimeUnit timeUnit) {
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(GoogleFitPackage.PACKAGE_NAME)
.setDataType(dataType)
.setType(dataSourceType)
.build();
DataSet dataSet = DataSet.create(dataSource);
DataPoint dataPoint = dataSet.createDataPoint().setTimeInterval(startTime, endTime, timeUnit);
float f1 = Float.valueOf(value.toString());
dataPoint = dataPoint.setFloatValues(f1);
dataSet.add(dataPoint);
return dataSet;
}
示例2: createStepDeltaDataSet
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
/**
* DataSets can only include one data type.
*
* @param startTime Start time for the activity in milliseconds
* @param endTime End time for the activity in milliseconds
* @param stepCountDelta Number of steps during the activity
* @param packageName Package name for the app
* @return Resulting DataSet
*/
public static DataSet createStepDeltaDataSet(long startTime, long endTime, int stepCountDelta, String packageName, Device device) {
// Create a data source
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(packageName)
.setDevice(device)
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setName(TAG + " - step count")
.setType(DataSource.TYPE_RAW)
.build();
// Create a data set
DataSet dataSet = DataSet.create(dataSource);
// For each data point, specify a start time, end time, and the data value -- in this case,
// the number of new steps.
DataPoint dataPoint = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta); // Can't do this on an Activity Segment
dataSet.add(dataPoint);
return dataSet;
}
示例3: createActivityDataSet
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
public static DataSet createActivityDataSet(long startTime, long endTime, String activityName, String packageName, Device device) {
// Create a data source
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(packageName)
.setDevice(device)
.setDataType(DataType.TYPE_ACTIVITY_SEGMENT)
.setName(TAG + " - activity")
.setType(DataSource.TYPE_RAW)
.build();
// Create a data set
DataSet dataSet = DataSet.create(dataSource);
// For each data point, specify a start time, end time, and the data value -- in this case,
// the number of new steps.
DataPoint activityDataPoint = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
//dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta); // Can't do this on an Activity Segment
activityDataPoint.getValue(Field.FIELD_ACTIVITY).setActivity(activityName);
dataSet.add(activityDataPoint);
return dataSet;
}
示例4: insertFitnessData
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
/**
* Create and return a {@link DataSet} of step count data for insertion using the History API.
*/
private DataSet insertFitnessData() {
Log.i(TAG, "Creating a new data insert request.");
// [START build_insert_data_request]
// Set a start and end time for our data, using a start time of 1 hour before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.HOUR_OF_DAY, -1);
long startTime = cal.getTimeInMillis();
// Create a data source
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(this)
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setStreamName(TAG + " - step count")
.setType(DataSource.TYPE_RAW)
.build();
// Create a data set
int stepCountDelta = 950;
DataSet dataSet = DataSet.create(dataSource);
// For each data point, specify a start time, end time, and the data value -- in this case,
// the number of new steps.
DataPoint dataPoint = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
dataSet.add(dataPoint);
// [END build_insert_data_request]
return dataSet;
}
示例5: updateFitnessData
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
/**
* Create and return a {@link DataSet} of step count data to update.
*/
private DataSet updateFitnessData() {
Log.i(TAG, "Creating a new data update request.");
// [START build_update_data_request]
// Set a start and end time for the data that fits within the time range
// of the original insertion.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
cal.add(Calendar.MINUTE, 0);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.MINUTE, -50);
long startTime = cal.getTimeInMillis();
// Create a data source
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(this)
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setStreamName(TAG + " - step count")
.setType(DataSource.TYPE_RAW)
.build();
// Create a data set
int stepCountDelta = 1000;
DataSet dataSet = DataSet.create(dataSource);
// For each data point, specify a start time, end time, and the data value -- in this case,
// the number of new steps.
DataPoint dataPoint = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
dataSet.add(dataPoint);
// [END build_update_data_request]
return dataSet;
}
示例6: recordedLocationsToDataSet
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
private DataSet recordedLocationsToDataSet() {
final DataSet dataSet = DataSet.create(locationDataSource);
for (Location location : recordedLocations) {
DataPoint newPoint = dataSet.createDataPoint();
newPoint.setTimestamp(location.getTime(), TimeUnit.MILLISECONDS);
newPoint.getValue(Field.FIELD_LATITUDE).setFloat((float) location.getLatitude());
newPoint.getValue(Field.FIELD_LONGITUDE).setFloat((float) location.getLongitude());
newPoint.getValue(Field.FIELD_ALTITUDE).setFloat((float) location.getAltitude());
newPoint.getValue(Field.FIELD_ACCURACY).setFloat(location.getAccuracy());
dataSet.add(newPoint);
}
return dataSet;
}
示例7: insertHeartRate
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
private boolean insertHeartRate () {
boolean success = true;
if(heartRateList != null) {
Log.d(LOG_TAG, "write heartRate");
DataSource bpmDataSource = new DataSource.Builder()
.setAppPackageName("com.solderbyte.openfit")
.setDataType(DataType.TYPE_HEART_RATE_BPM)
.setName("Open Fit - heartrate data")
.setType(DataSource.TYPE_RAW)
.build();
for(int i = 0; i < heartRateList.size(); i++) {
long timeStamp = heartRateList.get(i).getTimeStamp();
float bpm = (float) heartRateList.get(i).getHeartRate();
Calendar cal = Calendar.getInstance();
Date startDate = new Date(timeStamp);
cal.setTime(startDate);
cal.add(Calendar.SECOND, 1);
Date endDate = new Date(cal.getTimeInMillis());
DataSet dBPM = DataSet.create(bpmDataSource);
DataPoint pBPM = dBPM.createDataPoint().setTimeInterval(startDate.getTime(), endDate.getTime(), TimeUnit.MILLISECONDS);
pBPM = pBPM.setFloatValues(bpm);
dBPM.add(pBPM);
com.google.android.gms.common.api.Status insertStatusBPM = Fitness.HistoryApi.insertData(mClient, dBPM).await(1, TimeUnit.MINUTES);
if(!insertStatusBPM.isSuccess()) {
success &= false;
Log.d(LOG_TAG, "Profile data: There was a problem inserting the session");
}
else {
success &= true;
Log.d(LOG_TAG, "Profile data inserted: " + insertStatusBPM);
}
}
}
return success;
}
示例8: insertSteps
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
/**
* Creates and executes a insert Data request for 10,000 steps for today.
*/
private Task<Void> insertSteps() {
//First, create a new session and an insertion request.
//Adds steps spread out evenly from start time to end time
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.HOUR_OF_DAY, -1);
long startTime = cal.getTimeInMillis();
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(getActivity())
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setName("Step Count")
.setType(DataSource.TYPE_RAW)
.build();
int stepCountDelta = 10000; //we will add 10,000 steps for yesterday.
DataSet dataSet = DataSet.create(dataSource);
DataPoint point = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
point.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
dataSet.add(point);
// Now insert the new dataset view the client.
Log.i(TAG, "Inserting the session in the History API");
return Fitness.getHistoryClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.insertData(dataSet)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// At this point, the session has been inserted and can be read.
sendmessage("dataSet of 10000 steps inserted successfully!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
sendmessage("There was a problem inserting the dataset: " +
e.getLocalizedMessage());
}
});
}
示例9: insertUpdateSteps
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
/**
* Creates and executes a This will update the existing data and add the step count.
*/
private Task<Void> insertUpdateSteps() {
//If two entries overlap, the new data is dropped when trying to insert. Instead, you need to use update
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.HOUR_OF_DAY, -1);
long startTime = cal.getTimeInMillis();
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(getActivity())
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setName("Step Count")
.setType(DataSource.TYPE_RAW)
.build();
int stepCountDelta = 20000; //add another 20K steps to the data already there.
DataSet dataSet = DataSet.create(dataSource);
DataPoint point = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
point.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
dataSet.add(point);
DataUpdateRequest updateRequest = new DataUpdateRequest.Builder().setDataSet(dataSet).setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS).build();
// Now insert the new dataset view the client.
Log.i(TAG, "Inserting the session in the History API");
return Fitness.getHistoryClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.updateData(updateRequest)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// At this point, the session has been inserted and can be read.
sendmessage("dataSet of 20000 steps updated for yesterday successfully!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
sendmessage("There was a problem updating yesterdays dataset: " +
e.getLocalizedMessage());
}
});
}
示例10: insertProfileData
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
private boolean insertProfileData () {
boolean success = false;
if(profileData != null) {
Log.d(LOG_TAG, "write userData");
DataSource heightDataSource = new DataSource.Builder()
.setAppPackageName("com.solderbyte.openfit")
.setDataType(DataType.TYPE_HEIGHT)
.setName("Open Fit - profile data")
.setType(DataSource.TYPE_RAW)
.build();
DataSource weightDataSource = new DataSource.Builder()
.setAppPackageName("com.solderbyte.openfit")
.setDataType(DataType.TYPE_WEIGHT)
.setName("Open Fit - profile data")
.setType(DataSource.TYPE_RAW)
.build();
Calendar cal = Calendar.getInstance();
Date startDate = new Date(profileData.getTimeStamp());
cal.setTime(startDate);
cal.add(Calendar.SECOND, 1);
Date endDate = new Date(cal.getTimeInMillis());
DataSet dHeight = DataSet.create(heightDataSource);
DataPoint pHeight = dHeight.createDataPoint().setTimeInterval(startDate.getTime(), endDate.getTime(), TimeUnit.MILLISECONDS);
pHeight = pHeight.setFloatValues(profileData.getHeight() / 100);
dHeight.add(pHeight);
DataSet dWeight = DataSet.create(weightDataSource);
DataPoint pWeight = dWeight.createDataPoint().setTimeInterval(startDate.getTime(), endDate.getTime(), TimeUnit.MILLISECONDS);
pWeight = pWeight.setFloatValues(profileData.getWeight());
dWeight.add(pWeight);
com.google.android.gms.common.api.Status insertStatusH = Fitness.HistoryApi.insertData(mClient, dHeight).await(1, TimeUnit.MINUTES);
com.google.android.gms.common.api.Status insertStatusW = Fitness.HistoryApi.insertData(mClient, dWeight).await(1, TimeUnit.MINUTES);
if(!insertStatusH.isSuccess() || !insertStatusW.isSuccess()) {
success = false;
Log.d(LOG_TAG, "Profile data: There was a problem inserting the session");
}
else {
success = true;
Log.d(LOG_TAG, "Profile data inserted: " + insertStatusW);
}
}
return success;
}
示例11: originateDataSetCumulativeSteps
import com.google.android.gms.fitness.data.DataSet; //导入方法依赖的package包/类
private DataSet originateDataSetCumulativeSteps ( int valueStepCountDelta) {
DataSet retVal = null ;
Calendar calendar = Calendar.getInstance();
Date now = new Date();
calendar.setTime(now);
long endTime = calendar.getTimeInMillis();
calendar.add(Calendar.DAY_OF_YEAR, -366 );
long startTime = calendar.getTimeInMillis();
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(this)
.setDataType(DataType.TYPE_STEP_COUNT_CUMULATIVE)
.setType(DataSource.TYPE_RAW)
.build();
// int valueStepCountDelta = 54321 ;
retVal = DataSet.create(dataSource);
DataPoint dataPoint = retVal.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_STEPS).setInt(valueStepCountDelta);
retVal.add(dataPoint);
return retVal;
}