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.Vo2MaxRecord;
22 import android.health.connect.datatypes.Vo2MaxRecord.Vo2MaxMeasurementMethod;
23 import android.os.Parcel;
24 
25 /**
26  * @see Vo2MaxRecord
27  * @hide
28  */
29 @Identifier(recordIdentifier = RecordTypeIdentifier.RECORD_TYPE_VO2_MAX)
30 public final class Vo2MaxRecordInternal extends InstantRecordInternal<Vo2MaxRecord> {
31     private int mMeasurementMethod;
32     private double mVo2MillilitersPerMinuteKilogram;
33 
34     @Vo2MaxMeasurementMethod.Vo2MaxMeasurementMethodTypes
getMeasurementMethod()35     public int getMeasurementMethod() {
36         return mMeasurementMethod;
37     }
38 
39     /** returns this object with the specified measurementMethod */
40     @NonNull
setMeasurementMethod(int measurementMethod)41     public Vo2MaxRecordInternal setMeasurementMethod(int measurementMethod) {
42         this.mMeasurementMethod = measurementMethod;
43         return this;
44     }
45 
getVo2MillilitersPerMinuteKilogram()46     public double getVo2MillilitersPerMinuteKilogram() {
47         return mVo2MillilitersPerMinuteKilogram;
48     }
49 
50     /** returns this object with the specified vo2MillilitersPerMinuteKilogram */
51     @NonNull
setVo2MillilitersPerMinuteKilogram( double vo2MillilitersPerMinuteKilogram)52     public Vo2MaxRecordInternal setVo2MillilitersPerMinuteKilogram(
53             double vo2MillilitersPerMinuteKilogram) {
54         this.mVo2MillilitersPerMinuteKilogram = vo2MillilitersPerMinuteKilogram;
55         return this;
56     }
57 
58     @NonNull
59     @Override
toExternalRecord()60     public Vo2MaxRecord toExternalRecord() {
61         return new Vo2MaxRecord.Builder(
62                         buildMetaData(),
63                         getTime(),
64                         getMeasurementMethod(),
65                         getVo2MillilitersPerMinuteKilogram())
66                 .setZoneOffset(getZoneOffset())
67                 .buildWithoutValidation();
68     }
69 
70     @Override
populateInstantRecordFrom(@onNull Parcel parcel)71     void populateInstantRecordFrom(@NonNull Parcel parcel) {
72         mMeasurementMethod = parcel.readInt();
73         mVo2MillilitersPerMinuteKilogram = parcel.readDouble();
74     }
75 
76     @Override
populateInstantRecordTo(@onNull Parcel parcel)77     void populateInstantRecordTo(@NonNull Parcel parcel) {
78         parcel.writeInt(mMeasurementMethod);
79         parcel.writeDouble(mVo2MillilitersPerMinuteKilogram);
80     }
81 }
82