public final class

DataPoint

extends Object
implements Parcelable
java.lang.Object
   ↳ com.google.android.gms.fitness.data.DataPoint

Class Overview

Represents a single data point in a data type's stream from a particular data source. A data point holds a value for each field, a timestamp and an optional start time. The exact semantics of each of these attributes is specified in the documentation for the particular data type, which can be found in the appropriate constant in DataType.

A data point can represent an instantaneous measurement, reading or inputted observation, as well as averages or aggregates over a time interval. Check the data type documentation to determine which is the case for a particular data type.

DataPoints always contain one value for each the data type field. Initially, all of the values are unset. After creating the data point, the appropriate values and timestamps should be set.

Summary

[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<DataPoint> CREATOR
Public Methods
static DataPoint create(DataSource dataSource)
Creates a new data point for the given dataSource.
int describeContents()
boolean equals(Object o)
static DataPoint extract(Intent intent)
Extracts a data point from a callback intent received after registering to a data source with a PendingIntent.
DataSource getDataSource()
Returns the data source for the data point.
DataType getDataType()
Returns the data type defining the format of the values in this data point.
long getEndTime(TimeUnit timeUnit)
Returns the end time of the interval represented by this data point, in the given unit since epoch.
DataSource getOriginalDataSource()
Returns the original data source for this data point.
long getStartTime(TimeUnit timeUnit)
Returns the start time of the interval represented by this data point, in the given unit since epoch.
long getTimestamp(TimeUnit timeUnit)
Returns the timestamp of the data point, in the given unit since epoch.
Value getValue(Field field)
Returns the value holder for the field with the given name.
int hashCode()
DataPoint setFloatValues(float... values)
Sets the values of this data point, where the format for all of its values is float.
DataPoint setIntValues(int... values)
Sets the values of this data point, where the format for all of its values is int.
DataPoint setTimeInterval(long startTime, long endTime, TimeUnit timeUnit)
Sets the time interval of a data point that represents an interval of time.
DataPoint setTimestamp(long timestamp, TimeUnit timeUnit)
Sets the timestamp of a data point that represent an instantaneous reading, measurement, or input.
String toString()
void writeToParcel(Parcel parcel, int flags)
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Fields

public static final Creator<DataPoint> CREATOR

Public Methods

public static DataPoint create (DataSource dataSource)

Creates a new data point for the given dataSource. An unset Value is created for each field of the data source's data type.

Returns
  • an empty data point instance

public int describeContents ()

public boolean equals (Object o)

public static DataPoint extract (Intent intent)

Extracts a data point from a callback intent received after registering to a data source with a PendingIntent.

Returns
  • the extracted DataPoint, or null if the given intent does not contain a DataPoint

public DataSource getDataSource ()

Returns the data source for the data point. If the data point is part of a DataSet, this will correspond to the data set's data source.

public DataType getDataType ()

Returns the data type defining the format of the values in this data point.

public long getEndTime (TimeUnit timeUnit)

Returns the end time of the interval represented by this data point, in the given unit since epoch. This method is equivalent to getTimestamp(TimeUnit)

public DataSource getOriginalDataSource ()

Returns the original data source for this data point. The original data source helps identify the source of the data point as it gets merged and transformed into different streams.

Note that, if this data point is part of a DataSet, the data source returned here may be different from the data set's data source. In case of transformed or merged data sets, each data point's original data source will retain the original attribution as much as possible, while the data set's data source will represent the merged or transformed stream.

public long getStartTime (TimeUnit timeUnit)

Returns the start time of the interval represented by this data point, in the given unit since epoch.

public long getTimestamp (TimeUnit timeUnit)

Returns the timestamp of the data point, in the given unit since epoch. For data points that represent intervals, this method will return the end time.

public Value getValue (Field field)

Returns the value holder for the field with the given name. This method can be used both to query the value and to set it.

Parameters
field one of the fields of this data type
Returns
  • the Value associated with the given field
Throws
IllegalArgumentException if the given field doesn't match any of the fields for this DataPoint's data type.

public int hashCode ()

public DataPoint setFloatValues (float... values)

Sets the values of this data point, where the format for all of its values is float.

Parameters
values the value for each field of the data point, in order

public DataPoint setIntValues (int... values)

Sets the values of this data point, where the format for all of its values is int.

Parameters
values the value for each field of the data point, in order

public DataPoint setTimeInterval (long startTime, long endTime, TimeUnit timeUnit)

Sets the time interval of a data point that represents an interval of time. For data points that represent instantaneous readings, setTimestamp(long, TimeUnit) should be used.

Examples of data types that represent intervals include:

Google Fit accepts timestamps with up to nanosecond granularity.

Parameters
startTime the start time in the given unit, representing elapsed time since epoch
endTime the end time in the given unit, representing elapsed time since epoch
timeUnit the time unit of both start and end timestamps

public DataPoint setTimestamp (long timestamp, TimeUnit timeUnit)

Sets the timestamp of a data point that represent an instantaneous reading, measurement, or input. For data points that represent intervals, setTimeInterval(long, long, TimeUnit) should be used.

Examples of data types with instantaneous timestamp include:

Google Fit accepts timestamps with up to nanosecond granularity for all DataTypes with the exception of location, which supports only timestamps with millisecond precision. If the timestamp has more than millisecond granularity for a location, the extra precision will be lost.

Parameters
timestamp the timestamp in the given unit, representing elapsed time since epoch
timeUnit the unit of the given timestamp

public String toString ()

public void writeToParcel (Parcel parcel, int flags)