• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.annotation.Nullable;
21 import android.health.connect.datatypes.Identifier;
22 import android.health.connect.datatypes.MindfulnessSessionRecord;
23 import android.health.connect.datatypes.RecordTypeIdentifier;
24 import android.os.Parcel;
25 
26 /**
27  * @see MindfulnessSessionRecord
28  * @hide
29  */
30 @Identifier(recordIdentifier = RecordTypeIdentifier.RECORD_TYPE_MINDFULNESS_SESSION)
31 public final class MindfulnessSessionRecordInternal
32         extends IntervalRecordInternal<MindfulnessSessionRecord> {
33 
34     private int mMindfulnessSessionType;
35     @Nullable private String mTitle;
36     @Nullable private String mNotes;
37 
38     @Override
populateIntervalRecordFrom(@onNull Parcel parcel)39     void populateIntervalRecordFrom(@NonNull Parcel parcel) {
40         mMindfulnessSessionType = parcel.readInt();
41         mTitle = parcel.readString();
42         mNotes = parcel.readString();
43     }
44 
45     @Override
populateIntervalRecordTo(@onNull Parcel parcel)46     void populateIntervalRecordTo(@NonNull Parcel parcel) {
47         parcel.writeInt(mMindfulnessSessionType);
48         parcel.writeString(mTitle);
49         parcel.writeString(mNotes);
50     }
51 
52     @Override
toExternalRecord()53     public MindfulnessSessionRecord toExternalRecord() {
54         MindfulnessSessionRecord.Builder builder =
55                 new MindfulnessSessionRecord.Builder(
56                         buildMetaData(), getStartTime(), getEndTime(), mMindfulnessSessionType);
57 
58         if (getStartZoneOffset() != null) {
59             builder.setStartZoneOffset(getStartZoneOffset());
60         }
61 
62         if (getEndZoneOffset() != null) {
63             builder.setEndZoneOffset(getEndZoneOffset());
64         }
65 
66         if (getTitle() != null) {
67             builder.setTitle(getTitle());
68         }
69 
70         if (getNotes() != null) {
71             builder.setNotes(getNotes());
72         }
73 
74         return builder.buildWithoutValidation();
75     }
76 
77     @MindfulnessSessionRecord.MindfulnessSessionType
getMindfulnessSessionType()78     public int getMindfulnessSessionType() {
79         return mMindfulnessSessionType;
80     }
81 
82     /**
83      * @return this object with the measurement location.
84      */
85     @NonNull
setMindfulnessSessionType(int mindfulnessSessionType)86     public MindfulnessSessionRecordInternal setMindfulnessSessionType(int mindfulnessSessionType) {
87         mMindfulnessSessionType = mindfulnessSessionType;
88         return this;
89     }
90 
91     @Nullable
getTitle()92     public String getTitle() {
93         return mTitle;
94     }
95 
96     /** Returns this object with the specified title */
97     @NonNull
setTitle(String title)98     public MindfulnessSessionRecordInternal setTitle(String title) {
99         this.mTitle = title;
100         return this;
101     }
102 
103     @Nullable
getNotes()104     public String getNotes() {
105         return mNotes;
106     }
107 
108     /** Returns this object with the specified notes. */
109     @NonNull
setNotes(String notes)110     public MindfulnessSessionRecordInternal setNotes(String notes) {
111         this.mNotes = notes;
112         return this;
113     }
114 }
115