Goal

public class Goal extends AbstractSafeParcelable

A fitness goal, which users create in Google Fit.

A goal should hold its objective, time period and activity (if any).

There are different objective types:

  • Goal.MetricObjective uses a metric value to determine whether the goal is met. Metrics include step, distance and calories. e.g. Take 10k steps.
  • Goal.DurationObjective uses duration time of activities to determine whether the goal is met. e.g. Run 30 minutes.
  • Goal.FrequencyObjective uses the number of activity segments to determine whether the goal is met. e.g. Do yoga 2x.

A goal also has a recurrence period, since users often want to "take 10k steps a day" or "do yoga 2x per week".

A goal holds different times:

  • create time is the time when a goal was first created.
  • start time is the start of the time range that should be used to calculate a goal's progress for current recurrence period. For a weekly goal, this will be the start of the current week.
  • end time is the end of the time range that should be used to calculate a goal's progress for current recurrence period. For a daily goal, this will be the end of the current day.
The following are some common goals:
Goal Recurrence Activity Objective type Objective
Run 3 times a week. 1 week RUNNING OBJECTIVE_TYPE_FREQUENCY Frequency: 3
Active 60 minutes a day. 1 day N/A OBJECTIVE_TYPE_DURATION Duration: 60 minutes
Take 1,000 steps a day. 1 day N/A OBJECTIVE_TYPE_METRIC
Run 2 km a week. 1 week RUNNING OBJECTIVE_TYPE_METRIC
Burn 30k calories a month. 1 month N/A OBJECTIVE_TYPE_METRIC

Nested Class Summary

class Goal.DurationObjective A duration objective, which uses duration time of activities to determine whether the goal is met. 
class Goal.FrequencyObjective A frequency objective, which uses the number of activity segments to determine whether the goal is met. 
class Goal.MetricObjective A metric objective, which uses a metric value to determine whether the goal is met. 
class Goal.MismatchedGoalException Exception thrown by getMetricObjective(), getDurationObjective(), getFrequencyObjective() if the goal doesn't match the requested objective type. 
@interface Goal.ObjectiveType Type of a goal's objective. 
class Goal.Recurrence A recurrence period of a recurring goal. 

Constant Summary

int OBJECTIVE_TYPE_DURATION Objective type constant representing a duration objective, which uses duration time of activities to determine whether the goal is met.
int OBJECTIVE_TYPE_FREQUENCY Objective type constant representing a frequency objective, which uses the number of activity segments to determine whether the goal is met.
int OBJECTIVE_TYPE_METRIC Objective type constant representing a metric objective, which uses a metric value to determine whether the goal is met.

Inherited Constant Summary

Field Summary

public static final Creator<Goal> CREATOR

Public Method Summary

boolean
equals(Object other)
String
getActivityName()
Returns the name of the goal's specific activity, if any.
long
getCreateTime(TimeUnit timeUnit)
Returns the creation time of the goal since epoch, in the specified time unit.
Goal.DurationObjective
getDurationObjective()
Returns the duration objective of the goal if the objective type is OBJECTIVE_TYPE_DURATION.
long
getEndTime(Calendar current, TimeUnit timeUnit)
Returns the end time of the time range that should be used to calculate goal progress for current time.
Goal.FrequencyObjective
getFrequencyObjective()
Returns the frequency objective of the goal if the objective type is OBJECTIVE_TYPE_FREQUENCY.
Goal.MetricObjective
getMetricObjective()
Returns the metric objective of the goal if the objective type is OBJECTIVE_TYPE_METRIC.
int
getObjectiveType()
Returns the type of the goal's objective.
Goal.Recurrence
getRecurrence()
Returns the recurrence period of a goal if the goal is a recurring one.
long
getStartTime(Calendar current, TimeUnit timeUnit)
Returns the start time of the time range that should be used to calculate goal progress for current time.
int
String
void
writeToParcel(Parcel dest, int flags)

Inherited Method Summary

Constants

public static final int OBJECTIVE_TYPE_DURATION

Objective type constant representing a duration objective, which uses duration time of activities to determine whether the goal is met. e.g. Run 30 minutes.

Constant Value: 2

public static final int OBJECTIVE_TYPE_FREQUENCY

Objective type constant representing a frequency objective, which uses the number of activity segments to determine whether the goal is met. e.g. Do yoga 2x.

Constant Value: 3

public static final int OBJECTIVE_TYPE_METRIC

Objective type constant representing a metric objective, which uses a metric value to determine whether the goal is met. e.g. Take 10k steps.

Constant Value: 1

Fields

public static final Creator<Goal> CREATOR

Public Methods

public boolean equals (Object other)

public String getActivityName ()

Returns the name of the goal's specific activity, if any. e.g. Returns "running" for a goal "run 30km a week".

Returns
  • null if there is no specific activity for the goal. If there is no specific activity for a goal, then the goal should apply to all activities. e.g. The goal "30km a week" takes into account all activities including walking, running, biking, etc.

public long getCreateTime (TimeUnit timeUnit)

Returns the creation time of the goal since epoch, in the specified time unit.

public Goal.DurationObjective getDurationObjective ()

Returns the duration objective of the goal if the objective type is OBJECTIVE_TYPE_DURATION.

Throws
Goal.MismatchedGoalException if the objective type of the goal is not OBJECTIVE_TYPE_DURATION

public long getEndTime (Calendar current, TimeUnit timeUnit)

Returns the end time of the time range that should be used to calculate goal progress for current time. For recurring goals, end time represents the end time of the current recurrence of the goal. For non-recurring goals, the end time is the time at which user activities stop counting towards the objective.

Parameters
current current time
timeUnit the desired time unit for the returned end time

public Goal.FrequencyObjective getFrequencyObjective ()

Returns the frequency objective of the goal if the objective type is OBJECTIVE_TYPE_FREQUENCY.

Throws
Goal.MismatchedGoalException if the objective type of the goal is not OBJECTIVE_TYPE_FREQUENCY

public Goal.MetricObjective getMetricObjective ()

Returns the metric objective of the goal if the objective type is OBJECTIVE_TYPE_METRIC.

Throws
Goal.MismatchedGoalException if the objective type of the goal is not OBJECTIVE_TYPE_METRIC

public int getObjectiveType ()

Returns the type of the goal's objective. The objective type should be one of the OBJECTIVE_TYPE_METRIC, OBJECTIVE_TYPE_DURATION, OBJECTIVE_TYPE_FREQUENCY constants.

public Goal.Recurrence getRecurrence ()

Returns the recurrence period of a goal if the goal is a recurring one. e.g. Returns 1 week for a goal to "run 30km a week".

Returns
  • null if the goal is not recurring.

public long getStartTime (Calendar current, TimeUnit timeUnit)

Returns the start time of the time range that should be used to calculate goal progress for current time. This is the time from which user activities start counting towards the objective. For recurring goals, start time represents the start time of the current recurrence of the goal. For non-recurring goals, start time is the same as create time.

Parameters
current current time
timeUnit the desired time unit for the returned start time

public int hashCode ()

public String toString ()

public void writeToParcel (Parcel dest, int flags)