DataPoint

public final class DataPoint extends Object
implements Parcelable Parcelable

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.

Nested Class Summary

class DataPoint.Builder Builder for DataPoint instances. 

Inherited Constant Summary

Public Method Summary

static DataPoint.Builder
builder(DataSource dataSource)
Creates a new builder for a DataPoint with the given dataSource.
static DataPoint
create(DataSource dataSource)
This method is deprecated. Use DataPoint.Builder to create DataPoint instances.
boolean
equals(Object other)
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
DataPoint
setFloatValues(float... values)
This method is deprecated. Use DataPoint.Builder to create DataPoint instances.
DataPoint
setIntValues(int... values)
This method is deprecated. Use DataPoint.Builder to create DataPoint instances.
DataPoint
setTimeInterval(long startTime, long endTime, TimeUnit timeUnit)
This method is deprecated. Use DataPoint.Builder to create DataPoint instances.
DataPoint
setTimestamp(long timestamp, TimeUnit timeUnit)
This method is deprecated. Use DataPoint.Builder to create DataPoint instances.
String
void
writeToParcel(Parcel parcel, int flags)

Inherited Method Summary

Public Methods

public static DataPoint.Builder builder (DataSource dataSource)

Creates a new builder for a DataPoint with the given dataSource.

Throws
NullPointerException If specified data source is null.

public static DataPoint create (DataSource dataSource)

This method is deprecated.
Use DataPoint.Builder to create DataPoint instances.

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 boolean equals (Object other)

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.

WARNING: do not rely on this field for anything other than debugging. The value of this field, if it is set at all, is an implementation detail and is not guaranteed to remain consistent.

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)

This method is deprecated.
Use DataPoint.Builder to create DataPoint instances.

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)

This method is deprecated.
Use DataPoint.Builder to create DataPoint instances.

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)

This method is deprecated.
Use DataPoint.Builder to create DataPoint instances.

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)

This method is deprecated.
Use DataPoint.Builder to create DataPoint instances.

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.
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)