wearos-whs: Hierarchize ExerciseTypeConfig and add GolfExerciseTypeConfig subclass
To resolve API review feedback, in this cl we
1. Hierarchize ExerciseTypeConfig
- Make ExerciseTypeConfig an abstract baseclass with abstract method toProto()
- Create new subclass GolfExerciseTypeConfig, extending
ExerciseTypeConfig and have public constructor, taking an object param
- Move constants of GolfShotTrackingPlaceInfo into
GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo
- Make GolfShotTrackingPlaceInfo an object instead of an annotation
class, and remove the @IntDef
- Delete GolfShotTrackingPlaceInfo.kt
2. Remove @JvmOverloads from ExerciseConfig constructor
- Add another constructor, so that ExerciseConfig has constructors both with/without
ExerciseTypeConfig definition
Relnote: Add another constructor for backward compatibility
Test: ./gradlew :health:health-services-client:assemble --info
Test: ./gradlew :health:health-services-client:test
Bug: 259363329, (overridePolicyWithApproval=)260745756
Change-Id: Iddeda8a23e653cf104d8dfacabc5ef8c5e8f83a8
diff --git a/health/health-services-client/api/1.0.0-beta02.txt b/health/health-services-client/api/1.0.0-beta02.txt
index 30f5a77..29de2a1 100644
--- a/health/health-services-client/api/1.0.0-beta02.txt
+++ b/health/health-services-client/api/1.0.0-beta02.txt
@@ -316,9 +316,6 @@
public final class ExerciseConfig {
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters, optional androidx.health.services.client.data.ExerciseTypeConfig? exerciseTypeConfig);
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled);
method public static androidx.health.services.client.data.ExerciseConfig.Builder builder(androidx.health.services.client.data.ExerciseType exerciseType);
method public java.util.Set<androidx.health.services.client.data.DataType<?,?>> getDataTypes();
method public java.util.List<androidx.health.services.client.data.ExerciseGoal<?>> getExerciseGoals();
@@ -569,15 +566,11 @@
property public final boolean supportsAutoPauseAndResume;
}
- public final class ExerciseTypeConfig {
- method public static androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
- method public int getGolfShotTrackingPlaceInfo();
- property public final int golfShotTrackingPlaceInfo;
+ public abstract class ExerciseTypeConfig {
field public static final androidx.health.services.client.data.ExerciseTypeConfig.Companion Companion;
}
public static final class ExerciseTypeConfig.Companion {
- method public androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
}
public final class ExerciseUpdate {
@@ -612,6 +605,25 @@
public static final class ExerciseUpdate.Companion {
}
+ public final class GolfExerciseTypeConfig extends androidx.health.services.client.data.ExerciseTypeConfig {
+ ctor public GolfExerciseTypeConfig(optional androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo);
+ method public androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo getGolfShotTrackingPlaceInfo();
+ property public final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo {
+ method public int getPlaceInfoId();
+ property public final int placeInfoId;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion Companion;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion {
+ }
+
public final class HealthEvent {
ctor public HealthEvent(androidx.health.services.client.data.HealthEvent.Type type, java.time.Instant eventTime, androidx.health.services.client.data.DataPointContainer metrics);
method public java.time.Instant getEventTime();
diff --git a/health/health-services-client/api/current.txt b/health/health-services-client/api/current.txt
index 30f5a77..29de2a1 100644
--- a/health/health-services-client/api/current.txt
+++ b/health/health-services-client/api/current.txt
@@ -316,9 +316,6 @@
public final class ExerciseConfig {
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters, optional androidx.health.services.client.data.ExerciseTypeConfig? exerciseTypeConfig);
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled);
method public static androidx.health.services.client.data.ExerciseConfig.Builder builder(androidx.health.services.client.data.ExerciseType exerciseType);
method public java.util.Set<androidx.health.services.client.data.DataType<?,?>> getDataTypes();
method public java.util.List<androidx.health.services.client.data.ExerciseGoal<?>> getExerciseGoals();
@@ -569,15 +566,11 @@
property public final boolean supportsAutoPauseAndResume;
}
- public final class ExerciseTypeConfig {
- method public static androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
- method public int getGolfShotTrackingPlaceInfo();
- property public final int golfShotTrackingPlaceInfo;
+ public abstract class ExerciseTypeConfig {
field public static final androidx.health.services.client.data.ExerciseTypeConfig.Companion Companion;
}
public static final class ExerciseTypeConfig.Companion {
- method public androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
}
public final class ExerciseUpdate {
@@ -612,6 +605,25 @@
public static final class ExerciseUpdate.Companion {
}
+ public final class GolfExerciseTypeConfig extends androidx.health.services.client.data.ExerciseTypeConfig {
+ ctor public GolfExerciseTypeConfig(optional androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo);
+ method public androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo getGolfShotTrackingPlaceInfo();
+ property public final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo {
+ method public int getPlaceInfoId();
+ property public final int placeInfoId;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion Companion;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion {
+ }
+
public final class HealthEvent {
ctor public HealthEvent(androidx.health.services.client.data.HealthEvent.Type type, java.time.Instant eventTime, androidx.health.services.client.data.DataPointContainer metrics);
method public java.time.Instant getEventTime();
diff --git a/health/health-services-client/api/public_plus_experimental_1.0.0-beta02.txt b/health/health-services-client/api/public_plus_experimental_1.0.0-beta02.txt
index 30f5a77..29de2a1 100644
--- a/health/health-services-client/api/public_plus_experimental_1.0.0-beta02.txt
+++ b/health/health-services-client/api/public_plus_experimental_1.0.0-beta02.txt
@@ -316,9 +316,6 @@
public final class ExerciseConfig {
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters, optional androidx.health.services.client.data.ExerciseTypeConfig? exerciseTypeConfig);
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled);
method public static androidx.health.services.client.data.ExerciseConfig.Builder builder(androidx.health.services.client.data.ExerciseType exerciseType);
method public java.util.Set<androidx.health.services.client.data.DataType<?,?>> getDataTypes();
method public java.util.List<androidx.health.services.client.data.ExerciseGoal<?>> getExerciseGoals();
@@ -569,15 +566,11 @@
property public final boolean supportsAutoPauseAndResume;
}
- public final class ExerciseTypeConfig {
- method public static androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
- method public int getGolfShotTrackingPlaceInfo();
- property public final int golfShotTrackingPlaceInfo;
+ public abstract class ExerciseTypeConfig {
field public static final androidx.health.services.client.data.ExerciseTypeConfig.Companion Companion;
}
public static final class ExerciseTypeConfig.Companion {
- method public androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
}
public final class ExerciseUpdate {
@@ -612,6 +605,25 @@
public static final class ExerciseUpdate.Companion {
}
+ public final class GolfExerciseTypeConfig extends androidx.health.services.client.data.ExerciseTypeConfig {
+ ctor public GolfExerciseTypeConfig(optional androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo);
+ method public androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo getGolfShotTrackingPlaceInfo();
+ property public final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo {
+ method public int getPlaceInfoId();
+ property public final int placeInfoId;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion Companion;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion {
+ }
+
public final class HealthEvent {
ctor public HealthEvent(androidx.health.services.client.data.HealthEvent.Type type, java.time.Instant eventTime, androidx.health.services.client.data.DataPointContainer metrics);
method public java.time.Instant getEventTime();
diff --git a/health/health-services-client/api/public_plus_experimental_current.txt b/health/health-services-client/api/public_plus_experimental_current.txt
index 30f5a77..29de2a1 100644
--- a/health/health-services-client/api/public_plus_experimental_current.txt
+++ b/health/health-services-client/api/public_plus_experimental_current.txt
@@ -316,9 +316,6 @@
public final class ExerciseConfig {
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters, optional androidx.health.services.client.data.ExerciseTypeConfig? exerciseTypeConfig);
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled);
method public static androidx.health.services.client.data.ExerciseConfig.Builder builder(androidx.health.services.client.data.ExerciseType exerciseType);
method public java.util.Set<androidx.health.services.client.data.DataType<?,?>> getDataTypes();
method public java.util.List<androidx.health.services.client.data.ExerciseGoal<?>> getExerciseGoals();
@@ -569,15 +566,11 @@
property public final boolean supportsAutoPauseAndResume;
}
- public final class ExerciseTypeConfig {
- method public static androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
- method public int getGolfShotTrackingPlaceInfo();
- property public final int golfShotTrackingPlaceInfo;
+ public abstract class ExerciseTypeConfig {
field public static final androidx.health.services.client.data.ExerciseTypeConfig.Companion Companion;
}
public static final class ExerciseTypeConfig.Companion {
- method public androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
}
public final class ExerciseUpdate {
@@ -612,6 +605,25 @@
public static final class ExerciseUpdate.Companion {
}
+ public final class GolfExerciseTypeConfig extends androidx.health.services.client.data.ExerciseTypeConfig {
+ ctor public GolfExerciseTypeConfig(optional androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo);
+ method public androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo getGolfShotTrackingPlaceInfo();
+ property public final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo {
+ method public int getPlaceInfoId();
+ property public final int placeInfoId;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion Companion;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion {
+ }
+
public final class HealthEvent {
ctor public HealthEvent(androidx.health.services.client.data.HealthEvent.Type type, java.time.Instant eventTime, androidx.health.services.client.data.DataPointContainer metrics);
method public java.time.Instant getEventTime();
diff --git a/health/health-services-client/api/restricted_1.0.0-beta02.txt b/health/health-services-client/api/restricted_1.0.0-beta02.txt
index 30f5a77..29de2a1 100644
--- a/health/health-services-client/api/restricted_1.0.0-beta02.txt
+++ b/health/health-services-client/api/restricted_1.0.0-beta02.txt
@@ -316,9 +316,6 @@
public final class ExerciseConfig {
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters, optional androidx.health.services.client.data.ExerciseTypeConfig? exerciseTypeConfig);
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled);
method public static androidx.health.services.client.data.ExerciseConfig.Builder builder(androidx.health.services.client.data.ExerciseType exerciseType);
method public java.util.Set<androidx.health.services.client.data.DataType<?,?>> getDataTypes();
method public java.util.List<androidx.health.services.client.data.ExerciseGoal<?>> getExerciseGoals();
@@ -569,15 +566,11 @@
property public final boolean supportsAutoPauseAndResume;
}
- public final class ExerciseTypeConfig {
- method public static androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
- method public int getGolfShotTrackingPlaceInfo();
- property public final int golfShotTrackingPlaceInfo;
+ public abstract class ExerciseTypeConfig {
field public static final androidx.health.services.client.data.ExerciseTypeConfig.Companion Companion;
}
public static final class ExerciseTypeConfig.Companion {
- method public androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
}
public final class ExerciseUpdate {
@@ -612,6 +605,25 @@
public static final class ExerciseUpdate.Companion {
}
+ public final class GolfExerciseTypeConfig extends androidx.health.services.client.data.ExerciseTypeConfig {
+ ctor public GolfExerciseTypeConfig(optional androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo);
+ method public androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo getGolfShotTrackingPlaceInfo();
+ property public final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo {
+ method public int getPlaceInfoId();
+ property public final int placeInfoId;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion Companion;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion {
+ }
+
public final class HealthEvent {
ctor public HealthEvent(androidx.health.services.client.data.HealthEvent.Type type, java.time.Instant eventTime, androidx.health.services.client.data.DataPointContainer metrics);
method public java.time.Instant getEventTime();
diff --git a/health/health-services-client/api/restricted_current.txt b/health/health-services-client/api/restricted_current.txt
index 30f5a77..29de2a1 100644
--- a/health/health-services-client/api/restricted_current.txt
+++ b/health/health-services-client/api/restricted_current.txt
@@ -316,9 +316,6 @@
public final class ExerciseConfig {
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters, optional androidx.health.services.client.data.ExerciseTypeConfig? exerciseTypeConfig);
ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams, optional @FloatRange(from=0.0) float swimmingPoolLengthMeters);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals, optional android.os.Bundle exerciseParams);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled, optional java.util.List<? extends androidx.health.services.client.data.ExerciseGoal<?>> exerciseGoals);
- ctor public ExerciseConfig(androidx.health.services.client.data.ExerciseType exerciseType, java.util.Set<? extends androidx.health.services.client.data.DataType<?,?>> dataTypes, boolean isAutoPauseAndResumeEnabled, boolean isGpsEnabled);
method public static androidx.health.services.client.data.ExerciseConfig.Builder builder(androidx.health.services.client.data.ExerciseType exerciseType);
method public java.util.Set<androidx.health.services.client.data.DataType<?,?>> getDataTypes();
method public java.util.List<androidx.health.services.client.data.ExerciseGoal<?>> getExerciseGoals();
@@ -569,15 +566,11 @@
property public final boolean supportsAutoPauseAndResume;
}
- public final class ExerciseTypeConfig {
- method public static androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
- method public int getGolfShotTrackingPlaceInfo();
- property public final int golfShotTrackingPlaceInfo;
+ public abstract class ExerciseTypeConfig {
field public static final androidx.health.services.client.data.ExerciseTypeConfig.Companion Companion;
}
public static final class ExerciseTypeConfig.Companion {
- method public androidx.health.services.client.data.ExerciseTypeConfig createGolfExerciseTypeConfig(int golfShotTrackingPlaceInfo);
}
public final class ExerciseUpdate {
@@ -612,6 +605,25 @@
public static final class ExerciseUpdate.Companion {
}
+ public final class GolfExerciseTypeConfig extends androidx.health.services.client.data.ExerciseTypeConfig {
+ ctor public GolfExerciseTypeConfig(optional androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo);
+ method public androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo getGolfShotTrackingPlaceInfo();
+ property public final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo {
+ method public int getPlaceInfoId();
+ property public final int placeInfoId;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion Companion;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX;
+ field public static final androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED;
+ }
+
+ public static final class GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion {
+ }
+
public final class HealthEvent {
ctor public HealthEvent(androidx.health.services.client.data.HealthEvent.Type type, java.time.Instant eventTime, androidx.health.services.client.data.DataPointContainer metrics);
method public java.time.Instant getEventTime();
diff --git a/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseConfig.kt b/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseConfig.kt
index a125add..ae694c1 100644
--- a/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseConfig.kt
+++ b/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseConfig.kt
@@ -43,7 +43,7 @@
* modified after the exercise has started
*/
@Suppress("ParcelCreator")
-class ExerciseConfig @JvmOverloads constructor(
+class ExerciseConfig(
val exerciseType: ExerciseType,
val dataTypes: Set<DataType<*, *>>,
val isAutoPauseAndResumeEnabled: Boolean,
@@ -53,6 +53,24 @@
@FloatRange(from = 0.0) val swimmingPoolLengthMeters: Float = SWIMMING_POOL_LENGTH_UNSPECIFIED,
val exerciseTypeConfig: ExerciseTypeConfig? = null
) {
+ constructor(
+ exerciseType: ExerciseType,
+ dataTypes: Set<DataType<*, *>>,
+ isAutoPauseAndResumeEnabled: Boolean,
+ isGpsEnabled: Boolean,
+ exerciseGoals: List<ExerciseGoal<*>> = listOf(),
+ exerciseParams: Bundle = Bundle(),
+ @FloatRange(from = 0.0) swimmingPoolLengthMeters: Float = SWIMMING_POOL_LENGTH_UNSPECIFIED,
+ ) : this(
+ exerciseType,
+ dataTypes,
+ isAutoPauseAndResumeEnabled,
+ isGpsEnabled,
+ exerciseGoals,
+ exerciseParams,
+ swimmingPoolLengthMeters,
+ null
+ )
internal constructor(
proto: DataProto.ExerciseConfig
@@ -65,12 +83,12 @@
proto.exerciseGoalsList.map { ExerciseGoal.fromProto(it) },
BundlesUtil.fromProto(proto.exerciseParams),
if (proto.hasSwimmingPoolLength()) {
- proto.swimmingPoolLength
+ proto.swimmingPoolLength
} else {
- SWIMMING_POOL_LENGTH_UNSPECIFIED
+ SWIMMING_POOL_LENGTH_UNSPECIFIED
},
if (proto.hasExerciseTypeConfig()) {
- ExerciseTypeConfig(proto.exerciseTypeConfig)
+ ExerciseTypeConfig.fromProto(proto.exerciseTypeConfig)
} else null
)
@@ -81,9 +99,10 @@
}
if (exerciseType == ExerciseType.SWIMMING_POOL) {
- require(swimmingPoolLengthMeters != 0.0f) {
- "If exercise type is SWIMMING_POOL, then swimming pool length must also be specified"
- }
+ require(swimmingPoolLengthMeters != 0.0f) {
+ "If exercise type is SWIMMING_POOL, " +
+ "then swimming pool length must also be specified"
+ }
}
}
@@ -179,8 +198,8 @@
/** Sets the swimming pool length (in m). */
@Suppress("MissingGetterMatchingBuilder")
fun setSwimmingPoolLengthMeters(swimmingPoolLength: Float): Builder {
- this.swimmingPoolLength = swimmingPoolLength
- return this
+ this.swimmingPoolLength = swimmingPoolLength
+ return this
}
/**
@@ -219,28 +238,28 @@
"swimmingPoolLengthMeters=$swimmingPoolLengthMeters, " +
"exerciseTypeConfig=$exerciseTypeConfig)"
- internal fun toProto(): DataProto.ExerciseConfig {
- val builder = DataProto.ExerciseConfig.newBuilder()
- .setExerciseType(exerciseType.toProto())
- .addAllDataTypes(dataTypes.filter { !it.isAggregate }.map { it.proto })
- .addAllAggregateDataTypes(dataTypes.filter { it.isAggregate }.map { it.proto })
- .setIsAutoPauseAndResumeEnabled(isAutoPauseAndResumeEnabled)
- .setIsGpsUsageEnabled(isGpsEnabled)
- .addAllExerciseGoals(exerciseGoals.map { it.proto })
- .setExerciseParams(BundlesUtil.toProto(exerciseParams))
- .setSwimmingPoolLength(swimmingPoolLengthMeters)
- if (exerciseTypeConfig != null) {
- builder.exerciseTypeConfig = exerciseTypeConfig.toProto()
- }
- return builder.build()
- }
+ internal fun toProto(): DataProto.ExerciseConfig {
+ val builder = DataProto.ExerciseConfig.newBuilder()
+ .setExerciseType(exerciseType.toProto())
+ .addAllDataTypes(dataTypes.filter { !it.isAggregate }.map { it.proto })
+ .addAllAggregateDataTypes(dataTypes.filter { it.isAggregate }.map { it.proto })
+ .setIsAutoPauseAndResumeEnabled(isAutoPauseAndResumeEnabled)
+ .setIsGpsUsageEnabled(isGpsEnabled)
+ .addAllExerciseGoals(exerciseGoals.map { it.proto })
+ .setExerciseParams(BundlesUtil.toProto(exerciseParams))
+ .setSwimmingPoolLength(swimmingPoolLengthMeters)
+ if (exerciseTypeConfig != null) {
+ builder.exerciseTypeConfig = exerciseTypeConfig.toProto()
+ }
+ return builder.build()
+ }
companion object {
/**
* Returns a fresh new [Builder].
*
* @param exerciseType the [ExerciseType] representing this exercise
- */
+ */
@JvmStatic
fun builder(exerciseType: ExerciseType): Builder = Builder(exerciseType)
diff --git a/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseTypeConfig.kt b/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseTypeConfig.kt
index 3d643b7..55cd47f 100644
--- a/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseTypeConfig.kt
+++ b/health/health-services-client/src/main/java/androidx/health/services/client/data/ExerciseTypeConfig.kt
@@ -16,50 +16,29 @@
package androidx.health.services.client.data
-import androidx.health.services.client.data.GolfShotTrackingPlaceInfo.Companion.toProto
import androidx.health.services.client.proto.DataProto
/**
* Configuration attributes for a specific exercise type that may be modified after the exercise has
- * started.
- *
- * @property golfShotTrackingPlaceInfo location where user takes [DataType.GOLF_SHOT_COUNT] during
- * [ExerciseType.GOLF] activity
+ * started. This should not be instantiated outside the health.services.client.data library.
*/
-class ExerciseTypeConfig private constructor(
- @GolfShotTrackingPlaceInfo
- val golfShotTrackingPlaceInfo: Int = GolfShotTrackingPlaceInfo.UNSPECIFIED
-) {
-
- internal constructor(
- proto: DataProto.ExerciseTypeConfig
- ) : this (
- GolfShotTrackingPlaceInfo.fromProto(proto.golfShotTrackingPlaceInfo)
- )
-
- internal fun toProto(): DataProto.ExerciseTypeConfig {
- return DataProto.ExerciseTypeConfig.newBuilder()
- .setGolfShotTrackingPlaceInfo(golfShotTrackingPlaceInfo.toProto())
- .build()
- }
-
- override fun toString(): String =
- "ExerciseTypeConfig(golfShotTrackingPlaceInfo=$golfShotTrackingPlaceInfo)"
-
+abstract class ExerciseTypeConfig internal constructor() {
+ internal abstract fun toProto(): DataProto.ExerciseTypeConfig
companion object {
- /**
- * Creates golf-specific exercise type configuration.
- *
- * @param golfShotTrackingPlaceInfo location where user takes [DataType.GOLF_SHOT_COUNT] during
- * [ExerciseType.GOLF] activity
- *
- * @return an instance of [ExerciseTypeConfig] with specific [GolfShotTrackingPlaceInfo]
- */
- @JvmStatic
- fun createGolfExerciseTypeConfig(
- @GolfShotTrackingPlaceInfo golfShotTrackingPlaceInfo: Int
- ): ExerciseTypeConfig {
- return ExerciseTypeConfig(golfShotTrackingPlaceInfo)
+ internal fun fromProto(proto: DataProto.ExerciseTypeConfig): ExerciseTypeConfig {
+ if (proto.hasGolfShotTrackingPlaceInfo()) {
+ return GolfExerciseTypeConfig(
+ GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo
+ .fromProto(proto.golfShotTrackingPlaceInfo)
+ )
+ } else {
+ val emptyExerciseTypeConfig = object : ExerciseTypeConfig() {
+ override fun toProto(): DataProto.ExerciseTypeConfig {
+ return DataProto.ExerciseTypeConfig.getDefaultInstance()
+ }
+ }
+ return emptyExerciseTypeConfig
+ }
}
}
}
diff --git a/health/health-services-client/src/main/java/androidx/health/services/client/data/GolfExerciseTypeConfig.kt b/health/health-services-client/src/main/java/androidx/health/services/client/data/GolfExerciseTypeConfig.kt
new file mode 100644
index 0000000..067c87a
--- /dev/null
+++ b/health/health-services-client/src/main/java/androidx/health/services/client/data/GolfExerciseTypeConfig.kt
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.health.services.client.data
+
+import androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion.GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED
+import androidx.health.services.client.data.GolfExerciseTypeConfig.GolfShotTrackingPlaceInfo.Companion.toProto
+import androidx.health.services.client.proto.DataProto
+import java.util.Objects
+
+/**
+ * An [ExerciseTypeConfig] that is specifically for an [ExerciseType.GOLF] activity to configure the
+ * detection of [DataType.GOLF_SHOT_COUNT], enabling higher accuracy of the detection. Developers
+ * are not expected to receive or consume it from health-services.
+ *
+ * @property golfShotTrackingPlaceInfo location where user takes [DataType.GOLF_SHOT_COUNT] during
+ * [ExerciseType.GOLF] activity
+ */
+class GolfExerciseTypeConfig(
+ val golfShotTrackingPlaceInfo: GolfShotTrackingPlaceInfo =
+ GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED
+) : ExerciseTypeConfig() {
+
+ internal constructor(
+ proto: DataProto.ExerciseTypeConfig
+ ) : this (
+ GolfShotTrackingPlaceInfo.fromProto(proto.golfShotTrackingPlaceInfo)
+ )
+
+ override fun toString(): String =
+ "GolfExerciseTypeConfig(golfShotTrackingPlaceInfo=$golfShotTrackingPlaceInfo)"
+
+ /**
+ * The tracking information for a golf shot used in [GolfExerciseTypeConfig]. It is the semantic
+ * location of a user while golfing to assist golf swing activity recognition algorithms.
+ *
+ */
+ class GolfShotTrackingPlaceInfo private constructor(val placeInfoId: Int) {
+ override fun equals(other: Any?): Boolean {
+ return other is GolfShotTrackingPlaceInfo && other.placeInfoId == this.placeInfoId
+ }
+
+ override fun hashCode(): Int {
+ return Objects.hash(placeInfoId)
+ }
+
+ override fun toString(): String {
+ val name = when (placeInfoId) {
+ 1 -> "GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY"
+ 2 -> "GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN"
+ 3 -> "GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX"
+ else -> "GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED"
+ }
+ return "GolfShotTrackingPlaceInfo(placeInfoId=$placeInfoId):$name"
+ }
+
+ companion object {
+ internal fun GolfShotTrackingPlaceInfo.toProto():
+ DataProto.GolfShotTrackingPlaceInfoType =
+ when (this) {
+ GolfShotTrackingPlaceInfo(1) ->
+ DataProto
+ .GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
+ GolfShotTrackingPlaceInfo(2) ->
+ DataProto
+ .GolfShotTrackingPlaceInfoType
+ .GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN
+ GolfShotTrackingPlaceInfo(3) ->
+ DataProto
+ .GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX
+ else ->
+ DataProto
+ .GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED
+ }
+ internal fun fromProto(
+ proto: DataProto.GolfShotTrackingPlaceInfoType
+ ): GolfShotTrackingPlaceInfo =
+ when (proto) {
+ DataProto
+ .GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
+ -> GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
+ DataProto
+ .GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN
+ -> GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN
+ DataProto
+ .GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX
+ -> GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX
+ else -> GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED
+ }
+
+ /** The golf shot is being taken from an unspecified place. */
+ @JvmField
+ val GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED = GolfShotTrackingPlaceInfo(0)
+
+ /** The golf shot is being taken from the fairway. */
+ @JvmField
+ val GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY = GolfShotTrackingPlaceInfo(1)
+
+ /** The golf shot is being taken from the putting green. */
+ @JvmField
+ val GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN = GolfShotTrackingPlaceInfo(2)
+
+ /** The golf shot is being taken from the tee box area. */
+ @JvmField
+ val GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX = GolfShotTrackingPlaceInfo(3)
+ }
+ }
+
+ override fun toProto(): DataProto.ExerciseTypeConfig {
+ return DataProto
+ .ExerciseTypeConfig
+ .newBuilder()
+ .setGolfShotTrackingPlaceInfo(golfShotTrackingPlaceInfo.toProto())
+ .build()
+ }
+}
\ No newline at end of file
diff --git a/health/health-services-client/src/main/java/androidx/health/services/client/data/GolfShotTrackingPlaceInfo.kt b/health/health-services-client/src/main/java/androidx/health/services/client/data/GolfShotTrackingPlaceInfo.kt
deleted file mode 100644
index 5cf89cb..0000000
--- a/health/health-services-client/src/main/java/androidx/health/services/client/data/GolfShotTrackingPlaceInfo.kt
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.health.services.client.data
-
-import androidx.annotation.IntDef
-import androidx.health.services.client.proto.DataProto
-import kotlin.annotation.AnnotationRetention.SOURCE
-
-/**
- * The tracking information for a golf shot used in [ExerciseTypeConfig]. It is the semantic
- * location of a user while golfing to assist golf swing activity recognition algorithms.
- *
- * @hide
- */
-@Retention(AnnotationRetention.SOURCE)
-@IntDef(
- GolfShotTrackingPlaceInfo.UNSPECIFIED,
- GolfShotTrackingPlaceInfo.FAIRWAY,
- GolfShotTrackingPlaceInfo.PUTTING_GREEN,
- GolfShotTrackingPlaceInfo.TEE_BOX
-)
-annotation class GolfShotTrackingPlaceInfo {
- companion object {
- /** The golf shot is being taken from an unknown place. */
- const val UNSPECIFIED: Int = 0
- /** The golf shot is being taken from the fairway. */
- const val FAIRWAY: Int = 1
- /** The golf shot is being taken from the putting green. */
- const val PUTTING_GREEN: Int = 2
- /** The golf shot is being taken from the tee box area. */
- const val TEE_BOX: Int = 3
-
- internal fun @receiver:GolfShotTrackingPlaceInfo Int.toProto():
- DataProto.GolfShotTrackingPlaceInfoType =
- when (this) {
- FAIRWAY -> DataProto.GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
- PUTTING_GREEN ->
- DataProto.GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN
- TEE_BOX -> DataProto.GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX
- else -> DataProto.GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_UNSPECIFIED
- }
-
- @GolfShotTrackingPlaceInfo
- internal fun fromProto(proto: DataProto.GolfShotTrackingPlaceInfoType): Int =
- when (proto) {
- DataProto.GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_PUTTING_GREEN ->
- PUTTING_GREEN
- DataProto.GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX -> TEE_BOX
- DataProto.GolfShotTrackingPlaceInfoType.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY -> FAIRWAY
- else -> UNSPECIFIED
- }
- }
-}
diff --git a/health/health-services-client/src/main/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequest.kt b/health/health-services-client/src/main/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequest.kt
index a3820b5..8416212 100644
--- a/health/health-services-client/src/main/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequest.kt
+++ b/health/health-services-client/src/main/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequest.kt
@@ -42,7 +42,10 @@
@JvmField
val CREATOR: Parcelable.Creator<UpdateExerciseTypeConfigRequest> = newCreator { bytes ->
val proto = RequestsProto.UpdateExerciseTypeConfigRequest.parseFrom(bytes)
- UpdateExerciseTypeConfigRequest(proto.packageName, ExerciseTypeConfig(proto.config))
+ UpdateExerciseTypeConfigRequest(
+ proto.packageName,
+ ExerciseTypeConfig.fromProto(proto.config)
+ )
}
}
}
\ No newline at end of file
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/ExerciseClientTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/ExerciseClientTest.kt
index 0290c4a..20aef2e 100644
--- a/health/health-services-client/src/test/java/androidx/health/services/client/ExerciseClientTest.kt
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/ExerciseClientTest.kt
@@ -34,9 +34,8 @@
import androidx.health.services.client.data.ExerciseTrackedStatus
import androidx.health.services.client.data.ExerciseType
import androidx.health.services.client.data.ExerciseTypeCapabilities
-import androidx.health.services.client.data.ExerciseTypeConfig
import androidx.health.services.client.data.ExerciseUpdate
-import androidx.health.services.client.data.GolfShotTrackingPlaceInfo
+import androidx.health.services.client.data.GolfExerciseTypeConfig
import androidx.health.services.client.data.WarmUpConfig
import androidx.health.services.client.impl.IExerciseApiService
import androidx.health.services.client.impl.IExerciseUpdateListener
@@ -743,7 +742,8 @@
fun updateExerciseTypeConfigForActiveExercise() = runTest {
service.exerciseConfig = ExerciseConfig.builder(ExerciseType.GOLF).build()
val exerciseTypeConfig =
- ExerciseTypeConfig.createGolfExerciseTypeConfig(GolfShotTrackingPlaceInfo.FAIRWAY)
+ GolfExerciseTypeConfig(GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY)
val request =
UpdateExerciseTypeConfigRequest(
CLIENT_CONFIGURATION.servicePackageName, exerciseTypeConfig
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseConfigTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseConfigTest.kt
index c23763f..1dba2cf 100644
--- a/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseConfigTest.kt
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseConfigTest.kt
@@ -43,8 +43,10 @@
DataTypeCondition(DISTANCE_TOTAL, 150.0, GREATER_THAN)
),
),
- exerciseTypeConfig = ExerciseTypeConfig.createGolfExerciseTypeConfig(
- GolfShotTrackingPlaceInfo.FAIRWAY)
+ exerciseTypeConfig = GolfExerciseTypeConfig(
+ GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
+ )
).toProto()
val config = ExerciseConfig(proto)
@@ -59,8 +61,12 @@
assertThat(config.exerciseGoals[1].dataTypeCondition.dataType).isEqualTo(DISTANCE_TOTAL)
assertThat(config.exerciseGoals[1].dataTypeCondition.threshold).isEqualTo(150.0)
assertThat(config.exerciseGoals[1].dataTypeCondition.comparisonType).isEqualTo(GREATER_THAN)
- assertThat((config.exerciseTypeConfig)?.golfShotTrackingPlaceInfo).isEqualTo(
- GolfShotTrackingPlaceInfo.FAIRWAY)
+ assertThat(config.exerciseTypeConfig!!).isInstanceOf(GolfExerciseTypeConfig::class.java)
+ assertThat(
+ (config.exerciseTypeConfig!! as GolfExerciseTypeConfig)
+ .golfShotTrackingPlaceInfo
+ ).isEqualTo(GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY)
}
@Test
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseTypeConfigTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseTypeConfigTest.kt
index 10cf21d..15b619f 100644
--- a/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseTypeConfigTest.kt
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseTypeConfigTest.kt
@@ -16,6 +16,7 @@
package androidx.health.services.client.data
+import androidx.health.services.client.proto.DataProto
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@@ -25,19 +26,20 @@
class ExerciseTypeConfigTest {
@Test
fun protoRoundTrip() {
- val proto = ExerciseTypeConfig.createGolfExerciseTypeConfig(
- GolfShotTrackingPlaceInfo.FAIRWAY).toProto()
- val config = ExerciseTypeConfig(proto)
+ val proto =
+ GolfExerciseTypeConfig(GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
+ ).toProto()
+ val config = ExerciseTypeConfig.fromProto(proto)
- assertThat(config.golfShotTrackingPlaceInfo).isEqualTo(GolfShotTrackingPlaceInfo.FAIRWAY)
+ assertThat(config.toProto()).isEqualTo(proto)
}
@Test
- fun createGolfExerciseTypeConfigFromFactoryMethod() {
- val golfExerciseStyleConfig = ExerciseTypeConfig.createGolfExerciseTypeConfig(
- GolfShotTrackingPlaceInfo.FAIRWAY)
+ fun protoNotContainsWantedField_producesEmptyInstance_protoRoundTrip() {
+ val proto = DataProto.ExerciseTypeConfig.getDefaultInstance()
+ val config = ExerciseTypeConfig.fromProto(proto)
- assertThat(golfExerciseStyleConfig.golfShotTrackingPlaceInfo).isEqualTo(
- GolfShotTrackingPlaceInfo.FAIRWAY)
+ assertThat(config.toProto()).isEqualTo(proto)
}
}
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseUpdateTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseUpdateTest.kt
index b4b0537..eebb8fe 100644
--- a/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseUpdateTest.kt
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/data/ExerciseUpdateTest.kt
@@ -19,6 +19,7 @@
import androidx.health.services.client.data.ComparisonType.Companion.GREATER_THAN_OR_EQUAL
import androidx.health.services.client.data.DataType.Companion.CALORIES_TOTAL
import androidx.health.services.client.data.ExerciseGoal.Companion.createOneTimeGoal
+import androidx.health.services.client.data.ExerciseType.Companion.GOLF
import androidx.health.services.client.data.ExerciseType.Companion.WALKING
import androidx.health.services.client.data.ExerciseUpdate.ActiveDurationCheckpoint
import com.google.common.truth.Truth.assertThat
@@ -57,13 +58,14 @@
),
exerciseStateInfo = ExerciseStateInfo(ExerciseState.ACTIVE, ExerciseEndReason.UNKNOWN),
exerciseConfig = ExerciseConfig(
- WALKING,
+ GOLF,
setOf(CALORIES_TOTAL),
isAutoPauseAndResumeEnabled = false,
isGpsEnabled = false,
exerciseGoals = listOf(goal),
- exerciseTypeConfig = ExerciseTypeConfig.createGolfExerciseTypeConfig(
- GolfShotTrackingPlaceInfo.FAIRWAY
+ exerciseTypeConfig = GolfExerciseTypeConfig(
+ GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
)
),
activeDurationCheckpoint = ActiveDurationCheckpoint(42.instant(), 30.duration()),
@@ -83,10 +85,15 @@
assertThat(update.latestAchievedGoals.first().dataTypeCondition.dataType)
.isEqualTo(CALORIES_TOTAL)
assertThat(markerSummary.achievedGoal.dataTypeCondition.dataType).isEqualTo(CALORIES_TOTAL)
- assertThat(update.exerciseConfig!!.exerciseType).isEqualTo(WALKING)
+ assertThat(update.exerciseConfig!!.exerciseType).isEqualTo(GOLF)
assertThat(
- update.exerciseConfig!!.exerciseTypeConfig!!.golfShotTrackingPlaceInfo).isEqualTo(
- GolfShotTrackingPlaceInfo.FAIRWAY)
+ update.exerciseConfig!!.exerciseTypeConfig!!
+ ).isInstanceOf(GolfExerciseTypeConfig::class.java)
+ assertThat(
+ (update.exerciseConfig!!.exerciseTypeConfig!! as GolfExerciseTypeConfig)
+ .golfShotTrackingPlaceInfo
+ ).isEqualTo(GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY)
assertThat(update.activeDurationCheckpoint!!.activeDuration).isEqualTo(30.duration())
assertThat(update.exerciseStateInfo.state).isEqualTo(ExerciseState.ACTIVE)
}
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedExerciseClientTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedExerciseClientTest.kt
index b519939..0743bbb 100644
--- a/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedExerciseClientTest.kt
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/impl/ServiceBackedExerciseClientTest.kt
@@ -31,8 +31,7 @@
import androidx.health.services.client.data.ExerciseType
import androidx.health.services.client.data.ExerciseUpdate
import androidx.health.services.client.data.WarmUpConfig
-import androidx.health.services.client.data.ExerciseTypeConfig
-import androidx.health.services.client.data.GolfShotTrackingPlaceInfo
+import androidx.health.services.client.data.GolfExerciseTypeConfig
import androidx.health.services.client.impl.event.ExerciseUpdateListenerEvent
import androidx.health.services.client.impl.internal.IExerciseInfoCallback
import androidx.health.services.client.impl.internal.IStatusCallback
@@ -180,9 +179,10 @@
setOf(HEART_RATE_BPM, HEART_RATE_BPM_STATS),
isAutoPauseAndResumeEnabled = false,
isGpsEnabled = false,
- exerciseTypeConfig = ExerciseTypeConfig.createGolfExerciseTypeConfig(
- GolfShotTrackingPlaceInfo.FAIRWAY
- )
+ exerciseTypeConfig = GolfExerciseTypeConfig(
+ GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_FAIRWAY
+ )
)
val availabilityEvent = ExerciseUpdateListenerEvent.createAvailabilityUpdateEvent(
// Currently the proto form of HEART_RATE_BPM and HEART_RATE_BPM_STATS is identical. The
diff --git a/health/health-services-client/src/test/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequestTest.kt b/health/health-services-client/src/test/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequestTest.kt
index 1e2a23c..4fece94 100644
--- a/health/health-services-client/src/test/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequestTest.kt
+++ b/health/health-services-client/src/test/java/androidx/health/services/client/impl/request/UpdateExerciseTypeConfigRequestTest.kt
@@ -17,8 +17,7 @@
package androidx.health.services.client.impl.request
import android.os.Parcel
-import androidx.health.services.client.data.ExerciseTypeConfig
-import androidx.health.services.client.data.GolfShotTrackingPlaceInfo
+import androidx.health.services.client.data.GolfExerciseTypeConfig
import com.google.common.truth.Truth
import org.junit.Test
import org.junit.runner.RunWith
@@ -31,7 +30,10 @@
val request =
UpdateExerciseTypeConfigRequest(
"package",
- ExerciseTypeConfig.createGolfExerciseTypeConfig(GolfShotTrackingPlaceInfo.TEE_BOX)
+ GolfExerciseTypeConfig(
+ GolfExerciseTypeConfig
+ .GolfShotTrackingPlaceInfo.GOLF_SHOT_TRACKING_PLACE_INFO_TEE_BOX
+ )
)
val parcel = Parcel.obtain()