本文整理汇总了Java中com.google.android.gms.fitness.data.DataSource类的典型用法代码示例。如果您正苦于以下问题:Java DataSource类的具体用法?Java DataSource怎么用?Java DataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataSource类属于com.google.android.gms.fitness.data包,在下文中一共展示了DataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDataForRequest
import com.google.android.gms.fitness.data.DataSource; //导入依赖的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: findFitnessDataSources
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
public void findFitnessDataSources() {
DataSourcesRequest dataSourceRequest = new DataSourcesRequest.Builder()
.setDataTypes(DataType.TYPE_STEP_COUNT_DELTA, DataType.TYPE_STEP_COUNT_CUMULATIVE)
.setDataSourceTypes( DataSource.TYPE_DERIVED)
.build();
ResultCallback<DataSourcesResult> dataSourcesResultCallback = new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
DataType type = dataSource.getDataType();
if (DataType.TYPE_STEP_COUNT_DELTA.equals(type)
|| DataType.TYPE_STEP_COUNT_CUMULATIVE.equals(type)) {
Log.i(TAG, "Register Fitness Listener: " + type);
registerFitnessDataListener(dataSource, type);//DataType.TYPE_STEP_COUNT_DELTA);
}
}
}
};
Fitness.SensorsApi.findDataSources(googleFitManager.getGoogleApiClient(), dataSourceRequest)
.setResultCallback(dataSourcesResultCallback);
}
示例3: registerFitnessDataListener
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
SensorRequest request = new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(3, TimeUnit.SECONDS)
.build();
Fitness.SensorsApi.add(googleFitManager.getGoogleApiClient(), request, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "SensorApi successfully added");
}
}
});
}
示例4: listDataSources
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
public void listDataSources(DataType mDataType)
{
Fitness.SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
.setDataTypes(mDataType)
.setDataSourceTypes(DataSource.TYPE_DERIVED)
.setDataSourceTypes(DataSource.TYPE_RAW)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
mListAdapter.notifyDataSetChanged();
if (dataSourcesResult.getDataSources().size() > 0) {
mDataSourceList.addAll(dataSourcesResult.getDataSources());
mLiveDataText.setText("Please select from following data source to get the live data");
} else {
mLiveDataText.setText("No data source found for selected data type");
}
}
});
}
示例5: addDataListener
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
public void addDataListener(DataSource mDataSource)
{
Fitness.SensorsApi.add(mClient,
new SensorRequest.Builder()
.setDataSource(mDataSource)
.setDataType(mDataSource.getDataType())
.setSamplingRate(1, TimeUnit.SECONDS)
.build(), mOnDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
mLiveDataText.setText("Listener registered successfully, waiting for live data");
isDataListenerAdded = true;
} else {
mLiveDataText.setText("Listener registration failed");
}
}
});
}
示例6: queryStepEstimate
import com.google.android.gms.fitness.data.DataSource; //导入依赖的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();
}
示例7: createStepDeltaDataSet
import com.google.android.gms.fitness.data.DataSource; //导入依赖的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;
}
示例8: createActivityDataSet
import com.google.android.gms.fitness.data.DataSource; //导入依赖的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;
}
示例9: saveWeight
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
public boolean saveWeight(ReadableMap weightSample) {
this.WeightsDataset = createDataForRequest(
DataType.TYPE_WEIGHT, // for height, it would be DataType.TYPE_HEIGHT
DataSource.TYPE_RAW,
weightSample.getDouble("value"), // weight in kgs
(long)weightSample.getDouble("date"), // start time
(long)weightSample.getDouble("date"), // end time
TimeUnit.MILLISECONDS // Time Unit, for example, TimeUnit.MILLISECONDS
);
new InsertAndVerifyDataTask(this.WeightsDataset).execute();
return true;
}
示例10: insertFitnessData
import com.google.android.gms.fitness.data.DataSource; //导入依赖的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;
}
示例11: updateFitnessData
import com.google.android.gms.fitness.data.DataSource; //导入依赖的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;
}
示例12: findFitnessDataSources
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
/**
* Find available data sources and attempt to register on a specific {@link DataType}.
* If the application cares about a data type but doesn't care about the source of the data,
* this can be skipped entirely, instead calling
* {@link com.google.android.gms.fitness.SensorsApi
* #register(GoogleApiClient, SensorRequest, DataSourceListener)},
* where the {@link SensorRequest} contains the desired data type.
*/
private void findFitnessDataSources() {
// [START find_data_sources]
Fitness.SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
// At least one datatype must be specified.
.setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
// Can specify whether data type is raw or derived.
.setDataSourceTypes(DataSource.TYPE_RAW)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
Log.i(TAG, "Result: " + dataSourcesResult.getStatus().toString());
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
Log.i(TAG, "Data source found: " + dataSource.toString());
Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());
//Let's register a listener to receive Activity data!
if (dataSource.getDataType().equals(DataType.TYPE_LOCATION_SAMPLE)
&& mListener == null) {
Log.i(TAG, "Data source for LOCATION_SAMPLE found! Registering.");
registerFitnessDataListener(dataSource,
DataType.TYPE_LOCATION_SAMPLE);
}
}
}
});
// [END find_data_sources]
}
示例13: registerFitnessDataListener
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
/**
* Register a listener with the Sensors API for the provided {@link DataSource} and
* {@link DataType} combo.
*/
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
// [START register_data_listener]
mListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()) {
Value val = dataPoint.getValue(field);
Log.i(TAG, "Detected DataPoint field: " + field.getName());
Log.i(TAG, "Detected DataPoint value: " + val);
}
}
};
Fitness.SensorsApi.add(
mClient,
new SensorRequest.Builder()
.setDataSource(dataSource) // Optional but recommended for custom data sets.
.setDataType(dataType) // Can't be omitted.
.setSamplingRate(10, TimeUnit.SECONDS)
.build(),
mListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Listener registered!");
} else {
Log.i(TAG, "Listener not registered.");
}
}
});
// [END register_data_listener]
}
示例14: findFitnessDataSources
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
/** Finds available data sources and attempts to register on a specific {@link DataType}. */
private void findFitnessDataSources() {
// [START find_data_sources]
// Note: Fitness.SensorsApi.findDataSources() requires the ACCESS_FINE_LOCATION permission.
Fitness.getSensorsClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.findDataSources(
new DataSourcesRequest.Builder()
//.setDataTypes(DataType.TYPE_STEP_COUNT_DELTA)
.setDataTypes(DataType.TYPE_STEP_COUNT_CUMULATIVE)
.setDataSourceTypes(DataSource.TYPE_RAW)
.build())
.addOnSuccessListener(
new OnSuccessListener<List<DataSource>>() {
@Override
public void onSuccess(List<DataSource> dataSources) {
for (DataSource dataSource : dataSources) {
Log.wtf(TAG, "Data source found: " + dataSource.toString());
Log.wtf(TAG, "Data Source type: " + dataSource.getDataType().getName());
// Let's register a listener to receive Activity data!
if (dataSource.getDataType().equals(DataType.TYPE_STEP_COUNT_CUMULATIVE)
&& mlistener == null) {
Log.i(TAG, "Data source for Step Count (cumulative) found! Registering.");
setupSensors(dataSource, DataType.TYPE_STEP_COUNT_CUMULATIVE);
}
}
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "failed", e);
}
});
// [END find_data_sources]
}
示例15: setupSensors
import com.google.android.gms.fitness.data.DataSource; //导入依赖的package包/类
public void setupSensors(DataSource dataSource, DataType dataType) {
logthis("Setup Sensors start");
mlistener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
//we are not on the UI thread!
for (Field field : dataPoint.getDataType().getFields()) {
Value val = dataPoint.getValue(field);
Log.i(TAG, "Detected DataPoint field: " + field.getName());
sendmessage("Detected DataPoint field: " + field.getName());
Log.i(TAG, "Detected DataPoint value: " + val);
sendmessage("Detected DataPoint value: " + val);
}
}
};
Fitness.getSensorsClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.add(
new SensorRequest.Builder()
.setDataSource(dataSource) // Optional but recommended for custom data sets.
.setDataType(dataType) // Can't be omitted.
.setSamplingRate(10, TimeUnit.SECONDS)
.build(),
mlistener)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.i(TAG, "Listener registered!");
} else {
Log.e(TAG, "Listener not registered.", task.getException());
}
}
});
}