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. For example, "take 10k steps".Goal.DurationObjective
uses duration time of activities to determine whether the goal is met. For example, "run 30 minutes".Goal.FrequencyObjective
uses the number of activity segments to determine whether the goal is met. For example, "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 timeis the time when a goal was first created.
- start timeis 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 timeis 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.
Goal | Recurrence | Activity | Objective type | Objective |
---|---|---|---|---|
Run 3 times a week. | 1 week | FitnessActivities.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 | FitnessActivities.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
Goal.getMetricObjective() ,
Goal.getDurationObjective() ,
Goal.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 finalCreator<Goal> | CREATOR |
Public Method Summary
boolean | |
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(Calendarcurrent,
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(Calendarcurrent,
TimeUnit
timeUnit)
Returns the start time of the time range that should be used to calculate goal
progress for current time.
|
int |
hashCode()
|
String |
toString()
|
void |
writeToParcel(Parceldest, 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. For example, "run 30 minutes".
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. For example, "do yoga 2x".
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. For example, "take 10k steps".
Fields
Public Methods
public booleanequals(Objectother)
publicStringgetActivityName()
Returns the name of the goal's specific activity, if any. For example, 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. For example, the goal "30km a week" takes into account all activities such as walking, running, and biking.
public longgetCreateTime(TimeUnit timeUnit)
Returns the creation time of the goal since epoch, in the specified time unit.
publicGoal.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 longgetEndTime(Calendarcurrent,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. |
publicGoal.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 . |
---|
publicGoal.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 intgetObjectiveType()
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.
publicGoal.Recurrence getRecurrence()
Returns the recurrence period of a goal if the goal is a recurring one. For example, returns 1 week for a goal to "run 30km a week".
Returns
null
if the goal is not recurring.
public longgetStartTime(Calendarcurrent,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. |