com.google.android.gms.fitness.request.OnDataPointListener Java Examples
The following examples show how to use
com.google.android.gms.fitness.request.OnDataPointListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleApiClientWrapper.java From android-play-games-in-motion with Apache License 2.0 | 6 votes |
/** * 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 */)); }
Example #2
Source File: GoogleApiClientWrapper.java From android-play-games-in-motion with Apache License 2.0 | 6 votes |
/** * 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); } } }
Example #3
Source File: GoogleApiClientWrapper.java From android-play-games-in-motion with Apache License 2.0 | 6 votes |
/** * 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)); }
Example #4
Source File: UserFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 4 votes |
@Override public void onResume() { super.onResume(); Log.d(TAG, "Resumed app"); // initialize the step listener stepListener = new OnDataPointListener() { @Override public void onDataPoint(DataPoint dataPoint) { for (Field field : dataPoint.getDataType().getFields()) { Log.d(TAG, "Field: " + field.getName()); Log.d(TAG, "Value: " + dataPoint.getValue(field)); if (field.getName().equals("steps")) { int currentSteps = Integer.valueOf(userSteps.getText().toString()); currentSteps = currentSteps + dataPoint.getValue(field).asInt(); userSteps.setText(Integer.toString(currentSteps)); // if nothing in sending in totalStepsConvertedToFitcoin if (totalStepsConvertedToFitcoin != null && !sendingInProgress) { if (currentSteps - totalStepsConvertedToFitcoin > FITCOINS_STEPS_CONVERSION) { sendingInProgress = true; // send steps to blockchain sendStepsToFitchain(userIdFromStorage,currentSteps); // insert send steps to mongo // insert logic for leaderboards } } } } } }; // register the step listener if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity()))) { Log.d(TAG, "Not signed in..."); } else { Fitness.getSensorsClient((AppCompatActivity) getActivity(), GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity())) .add( new SensorRequest.Builder() .setDataType(DataType.TYPE_STEP_COUNT_DELTA) .setSamplingRate(10, TimeUnit.SECONDS) .build(), stepListener ) .addOnCompleteListener( new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "Step Listener Registered."); } else { Log.e(TAG, "Step Listener not registered", task.getException()); } } } ); } }
Example #5
Source File: GoogleApiClientWrapper.java From android-play-games-in-motion with Apache License 2.0 | 4 votes |
private void unregisterFitDataListener(OnDataPointListener listener) { Fitness.SensorsApi.remove(mGoogleApiClient, listener); }