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.Identifier; 20 import android.health.connect.datatypes.RecordTypeIdentifier; 21 import android.health.connect.datatypes.TotalCaloriesBurnedRecord; 22 import android.health.connect.datatypes.units.Energy; 23 import android.os.Parcel; 24 25 /** 26 * @see TotalCaloriesBurnedRecord 27 * @hide 28 */ 29 @Identifier(recordIdentifier = RecordTypeIdentifier.RECORD_TYPE_TOTAL_CALORIES_BURNED) 30 public final class TotalCaloriesBurnedRecordInternal 31 extends IntervalRecordInternal<TotalCaloriesBurnedRecord> { 32 private double mEnergy; 33 getEnergy()34 public double getEnergy() { 35 return mEnergy; 36 } 37 38 /** returns this object with the specified energy */ 39 @NonNull setEnergy(double energy)40 public TotalCaloriesBurnedRecordInternal setEnergy(double energy) { 41 this.mEnergy = energy; 42 return this; 43 } 44 45 @NonNull 46 @Override toExternalRecord()47 public TotalCaloriesBurnedRecord toExternalRecord() { 48 return new TotalCaloriesBurnedRecord.Builder( 49 buildMetaData(), 50 getStartTime(), 51 getEndTime(), 52 Energy.fromCalories(getEnergy())) 53 .setStartZoneOffset(getStartZoneOffset()) 54 .setEndZoneOffset(getEndZoneOffset()) 55 .buildWithoutValidation(); 56 } 57 58 @Override populateIntervalRecordFrom(@onNull Parcel parcel)59 void populateIntervalRecordFrom(@NonNull Parcel parcel) { 60 mEnergy = parcel.readDouble(); 61 } 62 63 @Override populateIntervalRecordTo(@onNull Parcel parcel)64 void populateIntervalRecordTo(@NonNull Parcel parcel) { 65 parcel.writeDouble(mEnergy); 66 } 67 } 68