当前位置: 首页>>代码示例>>Java>>正文


Java DataType类代码示例

本文整理汇总了Java中com.google.android.gms.fitness.data.DataType的典型用法代码示例。如果您正苦于以下问题:Java DataType类的具体用法?Java DataType怎么用?Java DataType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DataType类属于com.google.android.gms.fitness.data包,在下文中一共展示了DataType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doInBackground

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params) {

    DataDeleteRequest request = new DataDeleteRequest.Builder()
            .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
            .addDataType(DataType.TYPE_WEIGHT)
            .build();

    com.google.android.gms.common.api.Status insertStatus =
            Fitness.HistoryApi.deleteData(googleFitManager.getGoogleApiClient(), request)
                    .await(1, TimeUnit.MINUTES);

    if (insertStatus.isSuccess()) {
        Log.w("myLog", "+Successfully deleted data.");
    } else {
        Log.w("myLog", "+Failed to delete data.");
    }

    return null;
}
 
开发者ID:StasDoskalenko,项目名称:react-native-google-fit,代码行数:21,代码来源:WeightsHistory.java

示例2: createDataForRequest

import com.google.android.gms.fitness.data.DataType; //导入依赖的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;
}
 
开发者ID:StasDoskalenko,项目名称:react-native-google-fit,代码行数:29,代码来源:WeightsHistory.java

示例3: findFitnessDataSources

import com.google.android.gms.fitness.data.DataType; //导入依赖的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);
    }
 
开发者ID:StasDoskalenko,项目名称:react-native-google-fit,代码行数:26,代码来源:StepCounter.java

示例4: registerFitnessDataListener

import com.google.android.gms.fitness.data.DataType; //导入依赖的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");
                        }
                    }
                });
    }
 
开发者ID:StasDoskalenko,项目名称:react-native-google-fit,代码行数:19,代码来源:StepCounter.java

示例5: onDataPoint

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
@Override
public void onDataPoint(DataPoint dataPoint) {
    DataType type = dataPoint.getDataType();
    Log.i(TAG, "Detected DataPoint type: " + type);

    for (final Field field : type.getFields()) {
        final Value value = dataPoint.getValue(field);
        Log.i(TAG, "Detected DataPoint field: " + field.getName());
        Log.i(TAG, "Detected DataPoint value: " + value);


   /*     activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(mReactContext.getApplicationContext(), "Field: " + field.getName() + " Value: " + value, Toast.LENGTH_SHORT).show();
            }
        });*/

        if(type.equals(DataType.TYPE_STEP_COUNT_CUMULATIVE)) {
            WritableMap map = Arguments.createMap();
            map.putDouble("steps", value.asInt());
            sendEvent(this.mReactContext, "StepChangedEvent", map);
        }

    }
}
 
开发者ID:StasDoskalenko,项目名称:react-native-google-fit,代码行数:27,代码来源:StepCounter.java

示例6: startBleScan

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
@NonNull
@RequiresPermission("android.permission.BLUETOOTH_ADMIN")
public Observable<BleDevice> startBleScan(List<DataType> dataTypes, int timeoutSecs) {
    return ObservableTask.create(callback -> {
        BleScanCallback bleCallBack = new BleScanCallback() {
            @Override
            public void onDeviceFound(BleDevice bleDevice) {
                callback.onNext(bleDevice);
            }

            @Override
            public void onScanStopped() {
                callback.onComplete();
            }
        };
        callback.setDisposeListener(() -> client.stopBleScan(bleCallBack));
        return client.startBleScan(dataTypes, timeoutSecs, bleCallBack);
    });
}
 
开发者ID:niqo01,项目名称:RxTask,代码行数:20,代码来源:RxBleClient.java

示例7: subscribeToSteps

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
/**
 * Subscribe to an available {@link DataType}. Subscriptions can exist across application
 * instances (so data is recorded even after the application closes down).  When creating
 * a new subscription, it may already exist from a previous invocation of this app.  If
 * the subscription already exists, the method is a no-op.  However, you can check this with
 * a special success code.
 */
private void subscribeToSteps() {
    Fitness.RecordingApi.subscribe(googleApiClient, DataType.TYPE_STEP_COUNT_DELTA)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        if (status.getStatusCode()
                                == FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
                            Log.i(TAG, "Existing subscription for activity detected.");
                        } else {
                            Log.i(TAG, "Successfully subscribed!");
                        }
                    } else {
                        Log.i(TAG, "There was a problem subscribing.");
                    }
                }
            });
}
 
开发者ID:jimmykane,项目名称:Athletica,代码行数:26,代码来源:GoogleFitStepsColumn.java

示例8: unsubscribeFromSteps

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
/**
 * Cancel the ACTIVITY_SAMPLE subscription by calling unsubscribe on that {@link DataType}.
 */
private void unsubscribeFromSteps() {
    final String dataTypeStr = DataType.TYPE_STEP_COUNT_DELTA.toString();
    Log.i(TAG, "Unsubscribing from data type: " + dataTypeStr);

    // Invoke the Recording API to unsubscribe from the data type and specify a callback that
    // will check the result.
    Fitness.RecordingApi.unsubscribe(googleApiClient, DataType.TYPE_ACTIVITY_SAMPLE)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Successfully unsubscribed for data type: " + dataTypeStr);
                    } else {
                        // Subscription not removed
                        Log.i(TAG, "Failed to unsubscribe for data type: " + dataTypeStr);
                    }
                }
            });
}
 
开发者ID:jimmykane,项目名称:Athletica,代码行数:23,代码来源:GoogleFitStepsColumn.java

示例9: removeSubscription

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
public void removeSubscription(DataType mDataType) {

        Fitness.RecordingApi.unsubscribe(mClient, mDataType)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    mDataTypeList.remove(lastRemovedPosition);
                                    mListAdapter.notifyDataSetChanged();
                                }
                            });
                        } else {
                            Log.i(TAG, "Failed to unsubscribe ");
                        }
                    }
                });
    }
 
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:21,代码来源:SubscriptionActivity.java

示例10: listDataSources

import com.google.android.gms.fitness.data.DataType; //导入依赖的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");
                    }
                }
            });
}
 
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:21,代码来源:SensorActivity.java

示例11: queryFitnessData

import com.google.android.gms.fitness.data.DataType; //导入依赖的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();
}
 
开发者ID:Drippler,项目名称:drip-steps,代码行数:21,代码来源:StepsHelper.java

示例12: subscribe

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
public void subscribe() {
    //connect to the step count.
    Fitness.getRecordingClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
        .subscribe(DataType.TYPE_STEP_COUNT_DELTA)
        .addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                logthis("Subscribed to the Recording API");
            }
        })
        .addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                logthis("failed to subscribe to the Recording API");
            }
        });
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:18,代码来源:RecordFragment.java

示例13: displayTodayData

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
private Task<DataSet> displayTodayData() {
    Log.i(TAG, "Reading History API results for today of Steps");
    return Fitness.getHistoryClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
        .readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA)
        .addOnSuccessListener(new OnSuccessListener<DataSet>() {
            @Override
            public void onSuccess(DataSet dataSet) {
                Log.i(TAG, "Reading History API results for today");
                showDataSet(dataSet);
            }
        })
        .addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.i(TAG, "Failed to read DailyTotal for Steps.");
            }
        });

}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:20,代码来源:HistoryFragment.java

示例14: loadSessionData

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
public Observable<SessionData> loadSessionData(final GoogleApiClient googleApiClient, final String sessionId) {
	// create read request (only read distance, not location for overview)
	final SessionReadRequest readRequest = createReadRequest()
			.setSessionId(sessionId)
			.build();
	return Observable.defer(new Func0<Observable<SessionData>>() {
		@Override
		public Observable<SessionData> call() {
			SessionReadResult readResult = Fitness.SessionsApi.readSession(googleApiClient, readRequest).await();

			if (readResult.getSessions().isEmpty()) throw new IllegalStateException("error finding session " + sessionId);

			// parse result
			Session session = readResult.getSessions().get(0);
			List<Location> locations = locationsFromDataSet(readResult.getDataSet(session, DataType.TYPE_LOCATION_SAMPLE).get(0));
			Timber.d("found " + locations.size() + " locations");
			return Observable.just(new SessionData(session, locations));
		}
	});
}
 
开发者ID:FauDroids,项目名称:KeepOn,代码行数:21,代码来源:SessionManager.java

示例15: subscribe

import com.google.android.gms.fitness.data.DataType; //导入依赖的package包/类
public void subscribe(DataType dataType) {
    Fitness.RecordingApi.subscribe(client, dataType)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    if (status.isSuccess()) {
                        if (status.getStatusCode() == FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
                            display.show("Existing subscription for activity detected.");
                        } else {
                            display.show("Successfully subscribed!");
                        }
                    } else {
                        display.show("There was a problem subscribing.");
                    }
                }
            });
}
 
开发者ID:parthsatra,项目名称:WalkPotato,代码行数:18,代码来源:Recording.java


注:本文中的com.google.android.gms.fitness.data.DataType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。