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 
17 package android.health.connect.internal.datatypes;
18 
19 import android.annotation.NonNull;
20 import android.health.connect.datatypes.BasalMetabolicRateRecord;
21 import android.health.connect.datatypes.Identifier;
22 import android.health.connect.datatypes.RecordTypeIdentifier;
23 import android.health.connect.datatypes.units.Power;
24 import android.os.Parcel;
25 
26 /**
27  * @see BasalMetabolicRateRecord
28  * @hide
29  */
30 @Identifier(recordIdentifier = RecordTypeIdentifier.RECORD_TYPE_BASAL_METABOLIC_RATE)
31 public final class BasalMetabolicRateRecordInternal
32         extends InstantRecordInternal<BasalMetabolicRateRecord> {
33     private double mBasalMetabolicRate;
34 
getBasalMetabolicRate()35     public double getBasalMetabolicRate() {
36         return mBasalMetabolicRate;
37     }
38 
39     /** returns this object with the specified basalMetabolicRate */
40     @NonNull
setBasalMetabolicRate(double basalMetabolicRate)41     public BasalMetabolicRateRecordInternal setBasalMetabolicRate(double basalMetabolicRate) {
42         this.mBasalMetabolicRate = basalMetabolicRate;
43         return this;
44     }
45 
46     @NonNull
47     @Override
toExternalRecord()48     public BasalMetabolicRateRecord toExternalRecord() {
49         return new BasalMetabolicRateRecord.Builder(
50                         buildMetaData(), getTime(), Power.fromWatts(getBasalMetabolicRate()))
51                 .setZoneOffset(getZoneOffset())
52                 .buildWithoutValidation();
53     }
54 
55     @Override
populateInstantRecordFrom(@onNull Parcel parcel)56     void populateInstantRecordFrom(@NonNull Parcel parcel) {
57         mBasalMetabolicRate = parcel.readDouble();
58     }
59 
60     @Override
populateInstantRecordTo(@onNull Parcel parcel)61     void populateInstantRecordTo(@NonNull Parcel parcel) {
62         parcel.writeDouble(mBasalMetabolicRate);
63     }
64 }
65