Merge "Changes CervicalMucus StringDefs to IntDefs." into androidx-main
diff --git a/health/connect/connect-client/api/current.txt b/health/connect/connect-client/api/current.txt
index b526a23..1943714 100644
--- a/health/connect/connect-client/api/current.txt
+++ b/health/connect/connect-client/api/current.txt
@@ -293,33 +293,32 @@
}
public final class CervicalMucusRecord implements androidx.health.connect.client.records.Record {
- ctor public CervicalMucusRecord(java.time.Instant time, java.time.ZoneOffset? zoneOffset, optional String? appearance, optional String? sensation, optional androidx.health.connect.client.records.metadata.Metadata metadata);
- method public String? getAppearance();
+ ctor public CervicalMucusRecord(java.time.Instant time, java.time.ZoneOffset? zoneOffset, optional int appearance, optional int sensation, optional androidx.health.connect.client.records.metadata.Metadata metadata);
+ method public int getAppearance();
method public androidx.health.connect.client.records.metadata.Metadata getMetadata();
- method public String? getSensation();
+ method public int getSensation();
method public java.time.Instant getTime();
method public java.time.ZoneOffset? getZoneOffset();
- property public final String? appearance;
+ property public final int appearance;
property public androidx.health.connect.client.records.metadata.Metadata metadata;
- property public final String? sensation;
+ property public final int sensation;
property public java.time.Instant time;
property public java.time.ZoneOffset? zoneOffset;
+ field public static final int APPEARANCE_CREAMY = 3; // 0x3
+ field public static final int APPEARANCE_DRY = 1; // 0x1
+ field public static final int APPEARANCE_EGG_WHITE = 5; // 0x5
+ field public static final int APPEARANCE_STICKY = 2; // 0x2
+ field public static final int APPEARANCE_UNKNOWN = 0; // 0x0
+ field public static final int APPEARANCE_UNUSUAL = 6; // 0x6
+ field public static final int APPEARANCE_WATERY = 4; // 0x4
+ field public static final androidx.health.connect.client.records.CervicalMucusRecord.Companion Companion;
+ field public static final int SENSATION_HEAVY = 3; // 0x3
+ field public static final int SENSATION_LIGHT = 1; // 0x1
+ field public static final int SENSATION_MEDIUM = 2; // 0x2
+ field public static final int SENSATION_UNKNOWN = 0; // 0x0
}
- public static final class CervicalMucusRecord.Appearance {
- field public static final String CLEAR = "clear";
- field public static final String CREAMY = "creamy";
- field public static final String DRY = "dry";
- field public static final androidx.health.connect.client.records.CervicalMucusRecord.Appearance INSTANCE;
- field public static final String STICKY = "sticky";
- field public static final String WATERY = "watery";
- }
-
- public static final class CervicalMucusRecord.Sensation {
- field public static final String HEAVY = "heavy";
- field public static final androidx.health.connect.client.records.CervicalMucusRecord.Sensation INSTANCE;
- field public static final String LIGHT = "light";
- field public static final String MEDIUM = "medium";
+ public static final class CervicalMucusRecord.Companion {
}
public final class CyclingPedalingCadenceRecord implements androidx.health.connect.client.records.Record {
diff --git a/health/connect/connect-client/api/public_plus_experimental_current.txt b/health/connect/connect-client/api/public_plus_experimental_current.txt
index b526a23..1943714 100644
--- a/health/connect/connect-client/api/public_plus_experimental_current.txt
+++ b/health/connect/connect-client/api/public_plus_experimental_current.txt
@@ -293,33 +293,32 @@
}
public final class CervicalMucusRecord implements androidx.health.connect.client.records.Record {
- ctor public CervicalMucusRecord(java.time.Instant time, java.time.ZoneOffset? zoneOffset, optional String? appearance, optional String? sensation, optional androidx.health.connect.client.records.metadata.Metadata metadata);
- method public String? getAppearance();
+ ctor public CervicalMucusRecord(java.time.Instant time, java.time.ZoneOffset? zoneOffset, optional int appearance, optional int sensation, optional androidx.health.connect.client.records.metadata.Metadata metadata);
+ method public int getAppearance();
method public androidx.health.connect.client.records.metadata.Metadata getMetadata();
- method public String? getSensation();
+ method public int getSensation();
method public java.time.Instant getTime();
method public java.time.ZoneOffset? getZoneOffset();
- property public final String? appearance;
+ property public final int appearance;
property public androidx.health.connect.client.records.metadata.Metadata metadata;
- property public final String? sensation;
+ property public final int sensation;
property public java.time.Instant time;
property public java.time.ZoneOffset? zoneOffset;
+ field public static final int APPEARANCE_CREAMY = 3; // 0x3
+ field public static final int APPEARANCE_DRY = 1; // 0x1
+ field public static final int APPEARANCE_EGG_WHITE = 5; // 0x5
+ field public static final int APPEARANCE_STICKY = 2; // 0x2
+ field public static final int APPEARANCE_UNKNOWN = 0; // 0x0
+ field public static final int APPEARANCE_UNUSUAL = 6; // 0x6
+ field public static final int APPEARANCE_WATERY = 4; // 0x4
+ field public static final androidx.health.connect.client.records.CervicalMucusRecord.Companion Companion;
+ field public static final int SENSATION_HEAVY = 3; // 0x3
+ field public static final int SENSATION_LIGHT = 1; // 0x1
+ field public static final int SENSATION_MEDIUM = 2; // 0x2
+ field public static final int SENSATION_UNKNOWN = 0; // 0x0
}
- public static final class CervicalMucusRecord.Appearance {
- field public static final String CLEAR = "clear";
- field public static final String CREAMY = "creamy";
- field public static final String DRY = "dry";
- field public static final androidx.health.connect.client.records.CervicalMucusRecord.Appearance INSTANCE;
- field public static final String STICKY = "sticky";
- field public static final String WATERY = "watery";
- }
-
- public static final class CervicalMucusRecord.Sensation {
- field public static final String HEAVY = "heavy";
- field public static final androidx.health.connect.client.records.CervicalMucusRecord.Sensation INSTANCE;
- field public static final String LIGHT = "light";
- field public static final String MEDIUM = "medium";
+ public static final class CervicalMucusRecord.Companion {
}
public final class CyclingPedalingCadenceRecord implements androidx.health.connect.client.records.Record {
diff --git a/health/connect/connect-client/api/restricted_current.txt b/health/connect/connect-client/api/restricted_current.txt
index 4910c88..86bb039 100644
--- a/health/connect/connect-client/api/restricted_current.txt
+++ b/health/connect/connect-client/api/restricted_current.txt
@@ -293,33 +293,32 @@
}
public final class CervicalMucusRecord implements androidx.health.connect.client.records.InstantaneousRecord {
- ctor public CervicalMucusRecord(java.time.Instant time, java.time.ZoneOffset? zoneOffset, optional String? appearance, optional String? sensation, optional androidx.health.connect.client.records.metadata.Metadata metadata);
- method public String? getAppearance();
+ ctor public CervicalMucusRecord(java.time.Instant time, java.time.ZoneOffset? zoneOffset, optional int appearance, optional int sensation, optional androidx.health.connect.client.records.metadata.Metadata metadata);
+ method public int getAppearance();
method public androidx.health.connect.client.records.metadata.Metadata getMetadata();
- method public String? getSensation();
+ method public int getSensation();
method public java.time.Instant getTime();
method public java.time.ZoneOffset? getZoneOffset();
- property public final String? appearance;
+ property public final int appearance;
property public androidx.health.connect.client.records.metadata.Metadata metadata;
- property public final String? sensation;
+ property public final int sensation;
property public java.time.Instant time;
property public java.time.ZoneOffset? zoneOffset;
+ field public static final int APPEARANCE_CREAMY = 3; // 0x3
+ field public static final int APPEARANCE_DRY = 1; // 0x1
+ field public static final int APPEARANCE_EGG_WHITE = 5; // 0x5
+ field public static final int APPEARANCE_STICKY = 2; // 0x2
+ field public static final int APPEARANCE_UNKNOWN = 0; // 0x0
+ field public static final int APPEARANCE_UNUSUAL = 6; // 0x6
+ field public static final int APPEARANCE_WATERY = 4; // 0x4
+ field public static final androidx.health.connect.client.records.CervicalMucusRecord.Companion Companion;
+ field public static final int SENSATION_HEAVY = 3; // 0x3
+ field public static final int SENSATION_LIGHT = 1; // 0x1
+ field public static final int SENSATION_MEDIUM = 2; // 0x2
+ field public static final int SENSATION_UNKNOWN = 0; // 0x0
}
- public static final class CervicalMucusRecord.Appearance {
- field public static final String CLEAR = "clear";
- field public static final String CREAMY = "creamy";
- field public static final String DRY = "dry";
- field public static final androidx.health.connect.client.records.CervicalMucusRecord.Appearance INSTANCE;
- field public static final String STICKY = "sticky";
- field public static final String WATERY = "watery";
- }
-
- public static final class CervicalMucusRecord.Sensation {
- field public static final String HEAVY = "heavy";
- field public static final androidx.health.connect.client.records.CervicalMucusRecord.Sensation INSTANCE;
- field public static final String LIGHT = "light";
- field public static final String MEDIUM = "medium";
+ public static final class CervicalMucusRecord.Companion {
}
public final class CyclingPedalingCadenceRecord implements androidx.health.connect.client.records.SeriesRecord<androidx.health.connect.client.records.CyclingPedalingCadenceRecord.Sample> {
diff --git a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordConverters.kt b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordConverters.kt
index 5101275..4e62508 100644
--- a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordConverters.kt
+++ b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordConverters.kt
@@ -28,6 +28,8 @@
import androidx.health.connect.client.records.BodyWaterMassRecord
import androidx.health.connect.client.records.BoneMassRecord
import androidx.health.connect.client.records.CervicalMucusRecord
+import androidx.health.connect.client.records.CervicalMucusRecord.Companion.APPEARANCE_STRING_TO_INT_MAP
+import androidx.health.connect.client.records.CervicalMucusRecord.Companion.SENSATION_STRING_TO_INT_MAP
import androidx.health.connect.client.records.CyclingPedalingCadenceRecord
import androidx.health.connect.client.records.DistanceRecord
import androidx.health.connect.client.records.ElevationGainedRecord
@@ -155,8 +157,18 @@
)
"CervicalMucus" ->
CervicalMucusRecord(
- appearance = getEnum("texture"),
- sensation = getEnum("amount"),
+ appearance =
+ mapEnum(
+ "texture",
+ APPEARANCE_STRING_TO_INT_MAP,
+ CervicalMucusRecord.APPEARANCE_UNKNOWN
+ ),
+ sensation =
+ mapEnum(
+ "amount",
+ SENSATION_STRING_TO_INT_MAP,
+ CervicalMucusRecord.SENSATION_UNKNOWN
+ ),
time = time,
zoneOffset = zoneOffset,
metadata = metadata
diff --git a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordUtils.kt b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordUtils.kt
index 25f805d..9894ddb 100644
--- a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordUtils.kt
+++ b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ProtoToRecordUtils.kt
@@ -65,6 +65,16 @@
return valuesMap[key]?.enumVal
}
+/** Maps a string enum field to public API integers. */
+internal fun DataPointOrBuilder.mapEnum(
+ key: String,
+ stringToIntMap: Map<String, Int>,
+ default: Int
+): Int {
+ val value = getEnum(key) ?: return default
+ return stringToIntMap.getOrDefault(value, default)
+}
+
internal fun SeriesValueOrBuilder.getLong(key: String, defaultVal: Long = 0): Long =
valuesMap[key]?.longVal ?: defaultVal
diff --git a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/RecordToProtoConverters.kt b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/RecordToProtoConverters.kt
index e00d9d2..5f85f66 100644
--- a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/RecordToProtoConverters.kt
+++ b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/RecordToProtoConverters.kt
@@ -28,6 +28,8 @@
import androidx.health.connect.client.records.BodyWaterMassRecord
import androidx.health.connect.client.records.BoneMassRecord
import androidx.health.connect.client.records.CervicalMucusRecord
+import androidx.health.connect.client.records.CervicalMucusRecord.Companion.APPEARANCE_INT_TO_STRING_MAP
+import androidx.health.connect.client.records.CervicalMucusRecord.Companion.SENSATION_INT_TO_STRING_MAP
import androidx.health.connect.client.records.CyclingPedalingCadenceRecord
import androidx.health.connect.client.records.DistanceRecord
import androidx.health.connect.client.records.ElevationGainedRecord
@@ -136,8 +138,12 @@
instantaneousProto()
.setDataType(protoDataType("CervicalMucus"))
.apply {
- appearance?.let { putValues("texture", enumVal(it)) }
- sensation?.let { putValues("amount", enumVal(it)) }
+ enumValFromInt(appearance, APPEARANCE_INT_TO_STRING_MAP)?.let {
+ putValues("texture", it)
+ }
+ enumValFromInt(sensation, SENSATION_INT_TO_STRING_MAP)?.let {
+ putValues("amount", it)
+ }
}
.build()
is CyclingPedalingCadenceRecord ->
diff --git a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ValueExt.kt b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ValueExt.kt
index d32fdfb..b2b38cad 100644
--- a/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ValueExt.kt
+++ b/health/connect/connect-client/src/main/java/androidx/health/connect/client/impl/converters/records/ValueExt.kt
@@ -36,3 +36,7 @@
internal fun enumVal(value: String): DataProto.Value =
DataProto.Value.newBuilder().setEnumVal(value).build()
+
+internal fun enumValFromInt(value: Int, intToStringMap: Map<Int, String>): DataProto.Value? {
+ return intToStringMap[value]?.let(::enumVal)
+}
diff --git a/health/connect/connect-client/src/main/java/androidx/health/connect/client/records/CervicalMucusRecord.kt b/health/connect/connect-client/src/main/java/androidx/health/connect/client/records/CervicalMucusRecord.kt
index ccd7386..c1cc1d0 100644
--- a/health/connect/connect-client/src/main/java/androidx/health/connect/client/records/CervicalMucusRecord.kt
+++ b/health/connect/connect-client/src/main/java/androidx/health/connect/client/records/CervicalMucusRecord.kt
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+@file:RestrictTo(RestrictTo.Scope.LIBRARY)
+
package androidx.health.connect.client.records
+import androidx.annotation.IntDef
import androidx.annotation.RestrictTo
-import androidx.annotation.StringDef
import androidx.health.connect.client.records.CervicalMucusRecord.Appearances
import androidx.health.connect.client.records.CervicalMucusRecord.Sensations
import androidx.health.connect.client.records.metadata.Metadata
@@ -31,46 +33,64 @@
public class CervicalMucusRecord(
override val time: Instant,
override val zoneOffset: ZoneOffset?,
- /**
- * The consistency of the user's cervical mucus. Optional field. Allowed values: [Appearance].
- *
- * @see Appearance
- */
- @property:Appearances public val appearance: String? = null,
- /**
- * The feel of the user's cervical mucus. Optional field. Allowed values: [Sensation].
- *
- * @see Sensation
- */
- @property:Sensations public val sensation: String? = null,
+ /** The consistency of the user's cervical mucus. */
+ @property:Appearances public val appearance: Int = APPEARANCE_UNKNOWN,
+ /** The feel of the user's cervical mucus. */
+ @property:Sensations public val sensation: Int = SENSATION_UNKNOWN,
override val metadata: Metadata = Metadata.EMPTY,
) : InstantaneousRecord {
- override fun equals(other: Any?): Boolean {
- if (this === other) return true
- if (other !is CervicalMucusRecord) return false
+ companion object {
+ const val APPEARANCE_UNKNOWN = 0
+ const val APPEARANCE_DRY = 1
+ const val APPEARANCE_STICKY = 2
+ const val APPEARANCE_CREAMY = 3
+ const val APPEARANCE_WATERY = 4
+ /** A constant describing clear or egg white like looking cervical mucus. */
+ const val APPEARANCE_EGG_WHITE = 5
+ /** A constant describing an unusual (worth attention) kind of cervical mucus. */
+ const val APPEARANCE_UNUSUAL = 6
- if (appearance != other.appearance) return false
- if (sensation != other.sensation) return false
- if (time != other.time) return false
- if (zoneOffset != other.zoneOffset) return false
- if (metadata != other.metadata) return false
+ const val SENSATION_UNKNOWN = 0
+ const val SENSATION_LIGHT = 1
+ const val SENSATION_MEDIUM = 2
+ const val SENSATION_HEAVY = 3
- return true
- }
+ /** Internal mappings useful for interoperability between integers and strings. */
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ @JvmField
+ val APPEARANCE_STRING_TO_INT_MAP: Map<String, Int> =
+ mapOf(
+ Appearance.CLEAR to APPEARANCE_EGG_WHITE,
+ Appearance.CREAMY to APPEARANCE_CREAMY,
+ Appearance.DRY to APPEARANCE_DRY,
+ Appearance.STICKY to APPEARANCE_STICKY,
+ Appearance.WATERY to APPEARANCE_WATERY,
+ Appearance.UNUSUAL to APPEARANCE_UNUSUAL
+ )
- override fun hashCode(): Int {
- var result = 0
- result = 31 * result + appearance.hashCode()
- result = 31 * result + sensation.hashCode()
- result = 31 * result + time.hashCode()
- result = 31 * result + (zoneOffset?.hashCode() ?: 0)
- result = 31 * result + metadata.hashCode()
- return result
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ @JvmField
+ val APPEARANCE_INT_TO_STRING_MAP =
+ APPEARANCE_STRING_TO_INT_MAP.entries.associate { it.value to it.key }
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ @JvmField
+ val SENSATION_STRING_TO_INT_MAP: Map<String, Int> =
+ mapOf(
+ Sensation.LIGHT to SENSATION_LIGHT,
+ Sensation.MEDIUM to SENSATION_MEDIUM,
+ Sensation.HEAVY to SENSATION_HEAVY
+ )
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ @JvmField
+ val SENSATION_INT_TO_STRING_MAP =
+ SENSATION_STRING_TO_INT_MAP.entries.associate { it.value to it.key }
}
/** List of supported Cervical Mucus Sensation types on Health Platform. */
- public object Sensation {
+ internal object Sensation {
const val LIGHT = "light"
const val MEDIUM = "medium"
const val HEAVY = "heavy"
@@ -81,24 +101,18 @@
* @suppress
*/
@Retention(AnnotationRetention.SOURCE)
- @StringDef(
- value =
- [
- Sensation.LIGHT,
- Sensation.MEDIUM,
- Sensation.HEAVY,
- ]
- )
+ @IntDef(value = [SENSATION_UNKNOWN, SENSATION_LIGHT, SENSATION_MEDIUM, SENSATION_HEAVY])
@RestrictTo(RestrictTo.Scope.LIBRARY)
annotation class Sensations
/** The consistency or appearance of the user's cervical mucus. */
- public object Appearance {
+ internal object Appearance {
const val DRY = "dry"
const val STICKY = "sticky"
const val CREAMY = "creamy"
const val WATERY = "watery"
const val CLEAR = "clear"
+ const val UNUSUAL = "unusual"
}
/**
@@ -106,16 +120,42 @@
* @suppress
*/
@Retention(AnnotationRetention.SOURCE)
- @StringDef(
+ @IntDef(
value =
[
- Appearance.DRY,
- Appearance.STICKY,
- Appearance.CREAMY,
- Appearance.WATERY,
- Appearance.CLEAR,
+ APPEARANCE_UNKNOWN,
+ APPEARANCE_DRY,
+ APPEARANCE_STICKY,
+ APPEARANCE_CREAMY,
+ APPEARANCE_WATERY,
+ APPEARANCE_EGG_WHITE,
+ APPEARANCE_UNUSUAL
]
)
@RestrictTo(RestrictTo.Scope.LIBRARY)
annotation class Appearances
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (javaClass != other?.javaClass) return false
+
+ other as CervicalMucusRecord
+
+ if (time != other.time) return false
+ if (zoneOffset != other.zoneOffset) return false
+ if (appearance != other.appearance) return false
+ if (sensation != other.sensation) return false
+ if (metadata != other.metadata) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = time.hashCode()
+ result = 31 * result + (zoneOffset?.hashCode() ?: 0)
+ result = 31 * result + appearance
+ result = 31 * result + sensation
+ result = 31 * result + metadata.hashCode()
+ return result
+ }
}
diff --git a/health/connect/connect-client/src/test/java/androidx/health/connect/client/impl/converters/records/AllRecordsConverterTest.kt b/health/connect/connect-client/src/test/java/androidx/health/connect/client/impl/converters/records/AllRecordsConverterTest.kt
index be9cdbe..cdde08f 100644
--- a/health/connect/connect-client/src/test/java/androidx/health/connect/client/impl/converters/records/AllRecordsConverterTest.kt
+++ b/health/connect/connect-client/src/test/java/androidx/health/connect/client/impl/converters/records/AllRecordsConverterTest.kt
@@ -27,8 +27,6 @@
import androidx.health.connect.client.records.BodyWaterMassRecord
import androidx.health.connect.client.records.BoneMassRecord
import androidx.health.connect.client.records.CervicalMucusRecord
-import androidx.health.connect.client.records.CervicalMucusRecord.Appearance
-import androidx.health.connect.client.records.CervicalMucusRecord.Sensation
import androidx.health.connect.client.records.CyclingPedalingCadenceRecord
import androidx.health.connect.client.records.DistanceRecord
import androidx.health.connect.client.records.ElevationGainedRecord
@@ -254,8 +252,8 @@
fun testCervicalMucus() {
val data =
CervicalMucusRecord(
- appearance = Appearance.CLEAR,
- sensation = Sensation.HEAVY,
+ appearance = CervicalMucusRecord.APPEARANCE_EGG_WHITE,
+ sensation = CervicalMucusRecord.SENSATION_HEAVY,
time = START_TIME,
zoneOffset = END_ZONE_OFFSET,
metadata = TEST_METADATA