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.BloodGlucoseRecord; 20 import android.health.connect.datatypes.Identifier; 21 import android.health.connect.datatypes.MealType; 22 import android.health.connect.datatypes.RecordTypeIdentifier; 23 import android.health.connect.datatypes.units.BloodGlucose; 24 import android.os.Parcel; 25 26 /** 27 * @see BloodGlucoseRecord 28 * @hide 29 */ 30 @Identifier(recordIdentifier = RecordTypeIdentifier.RECORD_TYPE_BLOOD_GLUCOSE) 31 public final class BloodGlucoseRecordInternal extends InstantRecordInternal<BloodGlucoseRecord> { 32 private int mSpecimenSource; 33 private double mLevel; 34 private int mRelationToMeal; 35 private int mMealType; 36 37 @BloodGlucoseRecord.SpecimenSource.SpecimenSourceType getSpecimenSource()38 public int getSpecimenSource() { 39 return mSpecimenSource; 40 } 41 42 /** returns this object with the specified specimenSource */ 43 @NonNull setSpecimenSource(int specimenSource)44 public BloodGlucoseRecordInternal setSpecimenSource(int specimenSource) { 45 this.mSpecimenSource = specimenSource; 46 return this; 47 } 48 getLevel()49 public double getLevel() { 50 return mLevel; 51 } 52 53 /** returns this object with the specified level */ 54 @NonNull setLevel(double level)55 public BloodGlucoseRecordInternal setLevel(double level) { 56 this.mLevel = level; 57 return this; 58 } 59 60 @BloodGlucoseRecord.RelationToMealType.RelationToMealTypes getRelationToMeal()61 public int getRelationToMeal() { 62 return mRelationToMeal; 63 } 64 65 /** returns this object with the specified relationToMeal */ 66 @NonNull setRelationToMeal(int relationToMeal)67 public BloodGlucoseRecordInternal setRelationToMeal(int relationToMeal) { 68 this.mRelationToMeal = relationToMeal; 69 return this; 70 } 71 72 @MealType.MealTypes getMealType()73 public int getMealType() { 74 return mMealType; 75 } 76 77 /** returns this object with the specified mealType */ 78 @NonNull setMealType(int mealType)79 public BloodGlucoseRecordInternal setMealType(int mealType) { 80 this.mMealType = mealType; 81 return this; 82 } 83 84 @NonNull 85 @Override toExternalRecord()86 public BloodGlucoseRecord toExternalRecord() { 87 return new BloodGlucoseRecord.Builder( 88 buildMetaData(), 89 getTime(), 90 getSpecimenSource(), 91 BloodGlucose.fromMillimolesPerLiter(getLevel()), 92 getRelationToMeal(), 93 getMealType()) 94 .setZoneOffset(getZoneOffset()) 95 .buildWithoutValidation(); 96 } 97 98 @Override populateInstantRecordFrom(@onNull Parcel parcel)99 void populateInstantRecordFrom(@NonNull Parcel parcel) { 100 mSpecimenSource = parcel.readInt(); 101 mLevel = parcel.readDouble(); 102 mRelationToMeal = parcel.readInt(); 103 mMealType = parcel.readInt(); 104 } 105 106 @Override populateInstantRecordTo(@onNull Parcel parcel)107 void populateInstantRecordTo(@NonNull Parcel parcel) { 108 parcel.writeInt(mSpecimenSource); 109 parcel.writeDouble(mLevel); 110 parcel.writeInt(mRelationToMeal); 111 parcel.writeInt(mMealType); 112 } 113 } 114