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