com.google.android.gms.fitness.data.Value Java Examples
The following examples show how to use
com.google.android.gms.fitness.data.Value.
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: Mission.java From android-play-games-in-motion with Apache License 2.0 | 7 votes |
@Override public void onDataPoint(DataPoint dataPoint) { // If we get data before the mission has started, discard them. if (!mIsStarted) { return; } DataType dataType = dataPoint.getDataType(); for (Field field : dataType.getFields()) { Value val = dataPoint.getValue(field); if (dataType.equals(DataType.TYPE_STEP_COUNT_DELTA)) { onStepTaken(val.asInt()); } else if (dataType.equals(DataType.TYPE_SPEED)) { // Data comes in as meters per second, have to convert to minutes per mile. float speedMetersPerSeconds = val.asFloat(); updateChallengePace(Utils.metersPerSecondToMinutesPerMile(speedMetersPerSeconds)); } } }
Example #2
Source File: NutritionHistory.java From react-native-google-fit with MIT License | 6 votes |
private void processDataSet(DataSet dataSet, WritableArray map) { Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName()); DateFormat dateFormat = DateFormat.getDateInstance(); DateFormat timeFormat = DateFormat.getTimeInstance(); for (DataPoint dp : dataSet.getDataPoints()) { Log.i(TAG, "Data point:"); Log.i(TAG, "\tType: " + dp.getDataType().getName()); Log.i(TAG, "\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); Log.i(TAG, "\tEnd: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); WritableMap nutritionMap = Arguments.createMap(); Value nutrients = dp.getValue((Field.FIELD_NUTRIENTS)); nutritionMap.putDouble("date", dp.getStartTime(TimeUnit.MILLISECONDS)); nutritionMap.putMap("nutrients", getNutrientsAsMap(nutrients)); map.pushMap(nutritionMap); } }
Example #3
Source File: StepCounter.java From react-native-google-fit with MIT License | 6 votes |
@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_DELTA)) { WritableMap map = Arguments.createMap(); map.putDouble("steps", value.asInt()); sendEvent(this.mReactContext, "StepChangedEvent", map); } } }
Example #4
Source File: HydrationHistory.java From react-native-google-fit with MIT License | 5 votes |
private void processDataSet(DataSet dataSet, WritableArray map) { for (DataPoint dp : dataSet.getDataPoints()) { WritableMap hydrationMap = Arguments.createMap(); Value hydration = dp.getValue((Field.FIELD_VOLUME)); hydrationMap.putDouble("date", dp.getEndTime(TimeUnit.MILLISECONDS)); hydrationMap.putDouble("waterConsumed", hydration.asFloat()); hydrationMap.putString("addedBy", dp.getOriginalDataSource().getAppPackageName()); map.pushMap(hydrationMap); } }
Example #5
Source File: NutritionHistory.java From react-native-google-fit with MIT License | 5 votes |
private WritableMap getNutrientsAsMap(Value nutrients) { WritableMap nutrientsMap = Arguments.createMap(); for (String nutrientKey : NUTRIENTS_SET) { try { Float nutrientVal = nutrients.getKeyValue(nutrientKey); nutrientsMap.putDouble(nutrientKey, nutrientVal); } catch (Exception e) { } } return nutrientsMap; }
Example #6
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
@Override public void onDataPoint(DataPoint dataPoint) { for( final Field field : dataPoint.getDataType().getFields() ) { final Value value = dataPoint.getValue( field ); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "Field: " + field.getName() + " Value: " + value, Toast.LENGTH_SHORT).show(); } }); } }