本文整理汇总了Java中com.google.android.gms.fitness.request.OnDataPointListener类的典型用法代码示例。如果您正苦于以下问题:Java OnDataPointListener类的具体用法?Java OnDataPointListener怎么用?Java OnDataPointListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OnDataPointListener类属于com.google.android.gms.fitness.request包,在下文中一共展示了OnDataPointListener类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: unsubscribe
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
public void unsubscribe() {
for (OnDataPointListener listener : listeners) {
Fitness.SensorsApi.remove(
client,
listener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
display.show("Listener was removed!");
} else {
display.show("Listener was not removed.");
}
}
});
}
listeners.clear();
}
开发者ID:parthsatra,项目名称:WalkPotato,代码行数:19,代码来源:Sensors.java
示例2: startFitDataSession
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
/**
* Starts a new session for Fit data. This will take care of registering all the sensors,
* recording the sensor data, and registering the data set as a session to Google Fit.
* @param dataTypeSettings Types of data to listen to, in an array.
* @param sessionDescription The description of the session.
* @param listener The OnDataPointListener to receive sensor events.
*/
public void startFitDataSession(FitDataTypeSetting[] dataTypeSettings,
String sessionDescription, OnDataPointListener listener) {
for (FitDataTypeSetting dataTypeSetting : dataTypeSettings) {
registerFitDataListener(dataTypeSetting, listener);
startRecordingFitData(dataTypeSetting);
}
Session session = new Session.Builder()
.setName(SESSION_NAME)
.setDescription(sessionDescription)
.setActivity(FitnessActivities.RUNNING_JOGGING)
.setStartTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.build();
PendingResult<Status> pendingResult =
Fitness.SessionsApi.startSession(mGoogleApiClient, session);
pendingResult.setResultCallback(new FitResultCallback<Status>(
this, FitResultCallback.RegisterType.SESSION, null /* dataType */,
true /* subscribe */));
}
开发者ID:googlesamples,项目名称:android-play-games-in-motion,代码行数:28,代码来源:GoogleApiClientWrapper.java
示例3: endFitDataSession
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
/**
* Ends the session for Fit data. This will take care of un-registering all the sensors,
* stop recording the sensor data, and stop recording the data set as a session to Google Fit.
* @param dataTypeSettings Types of data to listen to, in an array.
* @param listener The OnDataPointListener to receive sensor events.
*/
public void endFitDataSession(
FitDataTypeSetting[] dataTypeSettings, OnDataPointListener listener) {
if (mGoogleApiClient.isConnected()) {
PendingResult<SessionStopResult> pendingResult =
Fitness.SessionsApi.stopSession(mGoogleApiClient, null);
pendingResult.setResultCallback(new FitResultCallback<SessionStopResult>(
this, FitResultCallback.RegisterType.SESSION, null /* dataType */,
false /* subscribe */));
for (FitDataTypeSetting dataTypeSetting : dataTypeSettings) {
stopRecordingFitData(dataTypeSetting);
unregisterFitDataListener(listener);
}
}
}
开发者ID:googlesamples,项目名称:android-play-games-in-motion,代码行数:22,代码来源:GoogleApiClientWrapper.java
示例4: registerFitDataListener
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
/**
* Add SensorsApi listener for real-time display of sensor data. Can be called repeatedly on
* multiple data types.
* @param dataTypeSetting Type of data to listen to.
* @param listener Listener for callbacks from SensorsApi.
*/
private void registerFitDataListener(
FitDataTypeSetting dataTypeSetting, OnDataPointListener listener) {
sensorsAwaitingRegistration.add(dataTypeSetting);
Fitness.SensorsApi.add(
mGoogleApiClient,
new SensorRequest.Builder()
.setDataType(dataTypeSetting.getDataType())
.setSamplingRate(dataTypeSetting.getSamplingRateSeconds(), TimeUnit.SECONDS)
.setAccuracyMode(dataTypeSetting.getAccuracyMode())
.build(),
listener)
.setResultCallback(new FitResultCallback<Status>(
this, FitResultCallback.RegisterType.SENSORS, dataTypeSetting.getDataType(),
true));
}
开发者ID:googlesamples,项目名称:android-play-games-in-motion,代码行数:22,代码来源:GoogleApiClientWrapper.java
示例5: readData
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
@NonNull
public Observable<DataPoint> readData(SensorRequest request) {
return ObservableTask.create(callback -> {
OnDataPointListener listener = dataPoint -> callback.onNext(dataPoint);
callback.setDisposeListener(() -> client.remove(listener));
return client.add(request, listener);
});
}
开发者ID:niqo01,项目名称:RxTask,代码行数:9,代码来源:RxSensorsClient.java
示例6: registerFitnessDataListener
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的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]
}
开发者ID:maseh87,项目名称:androidFitApp,代码行数:38,代码来源:MainActivity.java
示例7: setupSensors
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的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());
}
}
});
}
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:38,代码来源:SensorFragment.java
示例8: registerDataSourceListener
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
private void registerDataSourceListener(DataType dataType) {
onDataPointListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()) {
Value aValue = dataPoint.getValue(field);
Log.d(TAG, "registerDataSourceListener onDataPoint L-value= " + field.getName());
Log.d(TAG, "registerDataSourceListener onDataPoint R-value=" + aValue);
addContentToView( "dataPoint=" + field.getName() + "= " + aValue + "\n") ;
}
}
};
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
// .setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(12, TimeUnit.SECONDS)
.setAccuracyMode(SensorRequest.ACCURACY_MODE_DEFAULT)
.build(),
onDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onDataPointListener registered good");
} else {
Log.d(TAG, "onDataPointListener failed to register bad");
}
}
});
}
开发者ID:smitzey,项目名称:wearbooksource,代码行数:38,代码来源:GHelloFitActivity.java
示例9: registerDataSourceListener
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
private void registerDataSourceListener(DataType dataType) {
onDataPointListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()) {
Value aValue = dataPoint.getValue(field);
Log.d(TAG, "Detected DataPoint field: " + field.getName());
Log.d(TAG, "Detected DataPoint value: " + aValue);
addContentToView( "dataPoint=" + field.getName() + " " + aValue + "\n") ;
}
}
};
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
// .setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(12, TimeUnit.SECONDS)
.setAccuracyMode(SensorRequest.ACCURACY_MODE_DEFAULT)
.build(),
onDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onDataPointListener registered good");
} else {
Log.d(TAG, "onDataPointListener failed to register bad");
}
}
});
}
开发者ID:smitzey,项目名称:wearbooksource,代码行数:35,代码来源:HelloFitActivity.java
示例10: run
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
@Override
protected Task<Void> run(ObservableTaskCallback<DataPoint> callback) {
OnDataPointListener listener = dataPoint -> callback.onNext(dataPoint);
callback.setDisposeListener(() -> this.client.remove(listener));
return client.add(this.request, listener);
}
开发者ID:niqo01,项目名称:RxTask,代码行数:7,代码来源:SensorObservable.java
示例11: listDatasourcesAndSubscribe
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
public void listDatasourcesAndSubscribe() {
Fitness.SensorsApi.findDataSources(client, new DataSourcesRequest.Builder()
.setDataTypes(
DataType.TYPE_STEP_COUNT_DELTA,
DataType.TYPE_DISTANCE_DELTA)
.setDataSourceTypes(DataSource.TYPE_DERIVED)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
datasources.clear();
listeners.clear();
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
Device device = dataSource.getDevice();
String fields = dataSource.getDataType().getFields().toString();
datasources.add(device.getManufacturer() + " " + device.getModel() + " [" + dataSource.getDataType().getName() + " " + fields + "]");
final DataType dataType = dataSource.getDataType();
if (
dataType.equals(DataType.TYPE_STEP_COUNT_DELTA) ||
dataType.equals(DataType.TYPE_DISTANCE_DELTA)) {
final OnDataPointListener listener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
String msg = "onDataPoint: ";
for (Field field : dataPoint.getDataType().getFields()) {
Value value = dataPoint.getValue(field);
msg += field + "=" + value + ", ";
}
display.show(msg);
}
};
Fitness.SensorsApi.add(client,
new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(10, TimeUnit.SECONDS)
.build(),
listener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
listeners.add(listener);
display.show("Listener for " + dataType.getName() + " registered");
} else {
display.show("Failed to register listener for " + dataType.getName());
}
}
});
}
}
datasourcesListener.onDatasourcesListed();
}
});
}
开发者ID:parthsatra,项目名称:WalkPotato,代码行数:61,代码来源:Sensors.java
示例12: subscribeToHeartRate
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
public void subscribeToHeartRate() {
Fitness.SensorsApi.findDataSources(client, new DataSourcesRequest.Builder()
.setDataTypes( DataType.TYPE_HEART_RATE_BPM )
.setDataSourceTypes(DataSource.TYPE_RAW, DataSource.TYPE_DERIVED)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
datasources.clear();
listeners.clear();
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
Device device = dataSource.getDevice();
String fields = dataSource.getDataType().getFields().toString();
datasources.add(device.getManufacturer() + " " + device.getModel() + " [" + dataSource.getDataType().getName() + " " + fields + "]");
final DataType dataType = dataSource.getDataType();
if (dataType.equals(DataType.TYPE_HEART_RATE_BPM)) {
final OnDataPointListener listener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
String msg = "onDataPoint: ";
for (Field field : dataPoint.getDataType().getFields()) {
Value value = dataPoint.getValue(field);
msg += field + "=" + value + ", ";
}
display.show(msg);
}
};
Fitness.SensorsApi.add(client,
new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(30, TimeUnit.SECONDS)
.build(),
listener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
listeners.add(listener);
display.show("Listener for " + dataType.getName() + " registered");
} else {
display.show("Failed to register listener for " + dataType.getName());
}
}
});
}
}
datasourcesListener.onDatasourcesListed();
}
});
}
开发者ID:parthsatra,项目名称:WalkPotato,代码行数:56,代码来源:Sensors.java
示例13: registerDataSourceListener
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
private void registerDataSourceListener(DataType dataType) {
onDataPointListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
if (dataPoint == null) {
Log.d(TAG, "registerDataSourceListener onDataPoint = " + dataPoint);
return;
}
if ( dataPoint.getDataType().equals( DataType.TYPE_STEP_COUNT_CUMULATIVE) ) {
Log.d ( TAG, " onDataPoint of type DataType.TYPE_STEP_COUNT_CUMULATIVE " ) ;
for (Field field : dataPoint.getDataType().getFields()) {
Value aValue = dataPoint.getValue(field);
Log.d(TAG, "registerDataSourceListener onDataPoint L-value= " + field.getName());
Log.d(TAG, "registerDataSourceListener onDataPoint R-value=" + aValue);
addContentToView( "dataPoint=" + field.getName() + "= " + aValue + "\n") ;
// lets write cumulative steps
if ( field.getName().equals ("steps") ) {
// ideally one should use the same datapoint and add it to the set.
// rather than :-
DataSet originatedDataSet = originateDataSetCumulativeSteps( aValue.asInt() ) ;
writeQueue.add( originatedDataSet) ;
writeFitnessHistory();
}
}
}
}
};
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
// .setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(12, TimeUnit.SECONDS)
.setAccuracyMode(SensorRequest.ACCURACY_MODE_DEFAULT)
.build(),
onDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onDataPointListener registered good");
} else {
Log.d(TAG, "onDataPointListener failed to register bad");
}
}
});
}
开发者ID:smitzey,项目名称:wearbooksource,代码行数:58,代码来源:FitWriteHistoryActivity.java
示例14: unregisterFitDataListener
import com.google.android.gms.fitness.request.OnDataPointListener; //导入依赖的package包/类
private void unregisterFitDataListener(OnDataPointListener listener) {
Fitness.SensorsApi.remove(mGoogleApiClient, listener);
}
开发者ID:googlesamples,项目名称:android-play-games-in-motion,代码行数:4,代码来源:GoogleApiClientWrapper.java
注:本文中的com.google.android.gms.fitness.request.OnDataPointListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论