1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.health.connect.internal.datatypes; 17 18 import android.annotation.NonNull; 19 import android.health.connect.datatypes.BasalBodyTemperatureRecord; 20 import android.health.connect.datatypes.BodyTemperatureMeasurementLocation; 21 import android.health.connect.datatypes.Identifier; 22 import android.health.connect.datatypes.RecordTypeIdentifier; 23 import android.health.connect.datatypes.units.Temperature; 24 import android.os.Parcel; 25 26 /** 27 * @see BasalBodyTemperatureRecord 28 * @hide 29 */ 30 @Identifier(recordIdentifier = RecordTypeIdentifier.RECORD_TYPE_BASAL_BODY_TEMPERATURE) 31 public final class BasalBodyTemperatureRecordInternal 32 extends InstantRecordInternal<BasalBodyTemperatureRecord> { 33 private int mMeasurementLocation; 34 private double mTemperature; 35 36 @BodyTemperatureMeasurementLocation.BodyTemperatureMeasurementLocations getMeasurementLocation()37 public int getMeasurementLocation() { 38 return mMeasurementLocation; 39 } 40 41 /** returns this object with the specified measurementLocation */ 42 @NonNull setMeasurementLocation(int measurementLocation)43 public BasalBodyTemperatureRecordInternal setMeasurementLocation(int measurementLocation) { 44 this.mMeasurementLocation = measurementLocation; 45 return this; 46 } 47 getTemperature()48 public double getTemperature() { 49 return mTemperature; 50 } 51 52 /** returns this object with the specified temperature */ 53 @NonNull setTemperature(double temperature)54 public BasalBodyTemperatureRecordInternal setTemperature(double temperature) { 55 this.mTemperature = temperature; 56 return this; 57 } 58 59 @NonNull 60 @Override toExternalRecord()61 public BasalBodyTemperatureRecord toExternalRecord() { 62 return new BasalBodyTemperatureRecord.Builder( 63 buildMetaData(), 64 getTime(), 65 getMeasurementLocation(), 66 Temperature.fromCelsius(getTemperature())) 67 .setZoneOffset(getZoneOffset()) 68 .buildWithoutValidation(); 69 } 70 71 @Override populateInstantRecordFrom(@onNull Parcel parcel)72 void populateInstantRecordFrom(@NonNull Parcel parcel) { 73 mMeasurementLocation = parcel.readInt(); 74 mTemperature = parcel.readDouble(); 75 } 76 77 @Override populateInstantRecordTo(@onNull Parcel parcel)78 void populateInstantRecordTo(@NonNull Parcel parcel) { 79 parcel.writeInt(mMeasurementLocation); 80 parcel.writeDouble(mTemperature); 81 } 82 } 83