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.healthconnect.cts.lib; 18 19 import static android.health.connect.datatypes.MindfulnessSessionRecord.MINDFULNESS_SESSION_TYPE_MEDITATION; 20 import static android.health.connect.datatypes.MindfulnessSessionRecord.MINDFULNESS_SESSION_TYPE_OTHER; 21 import static android.health.connect.datatypes.MindfulnessSessionRecord.MINDFULNESS_SESSION_TYPE_UNKNOWN; 22 import static android.healthconnect.cts.lib.BundleHelper.PREFIX; 23 24 import android.health.connect.datatypes.Metadata; 25 import android.health.connect.datatypes.MindfulnessSessionRecord; 26 import android.os.Bundle; 27 28 import java.time.Instant; 29 import java.time.ZoneOffset; 30 31 public final class MindfulnessSessionRecordFactory extends RecordFactory<MindfulnessSessionRecord> { 32 33 private static final String KEY_TYPE = PREFIX + "TYPE"; 34 private static final String KEY_TITLE = PREFIX + "TITLE"; 35 private static final String KEY_NOTES = PREFIX + "NOTES"; 36 37 @Override newFullRecord( Metadata metadata, Instant startTime, Instant endTime)38 public MindfulnessSessionRecord newFullRecord( 39 Metadata metadata, Instant startTime, Instant endTime) { 40 return new MindfulnessSessionRecord.Builder( 41 metadata, startTime, endTime, MINDFULNESS_SESSION_TYPE_OTHER) 42 .setTitle("title-foo") 43 .setNotes("notes-foo") 44 .setStartZoneOffset(ZoneOffset.ofHours(3)) 45 .setEndZoneOffset(ZoneOffset.ofHours(-2)) 46 .build(); 47 } 48 49 @Override anotherFullRecord( Metadata metadata, Instant startTime, Instant endTime)50 public MindfulnessSessionRecord anotherFullRecord( 51 Metadata metadata, Instant startTime, Instant endTime) { 52 return new MindfulnessSessionRecord.Builder( 53 metadata, startTime, endTime, MINDFULNESS_SESSION_TYPE_MEDITATION) 54 .setTitle("title-bar") 55 .setNotes("notes-bar") 56 .setStartZoneOffset(ZoneOffset.ofHours(-1)) 57 .setEndZoneOffset(ZoneOffset.ofHours(2)) 58 .build(); 59 } 60 61 @Override newEmptyRecord( Metadata metadata, Instant startTime, Instant endTime)62 public MindfulnessSessionRecord newEmptyRecord( 63 Metadata metadata, Instant startTime, Instant endTime) { 64 return new MindfulnessSessionRecord.Builder( 65 metadata, startTime, endTime, MINDFULNESS_SESSION_TYPE_UNKNOWN) 66 .build(); 67 } 68 69 @Override recordWithMetadata( MindfulnessSessionRecord record, Metadata metadata)70 protected MindfulnessSessionRecord recordWithMetadata( 71 MindfulnessSessionRecord record, Metadata metadata) { 72 return new MindfulnessSessionRecord.Builder( 73 metadata, 74 record.getStartTime(), 75 record.getEndTime(), 76 record.getMindfulnessSessionType()) 77 .setTitle(record.getTitle()) 78 .setNotes(record.getNotes()) 79 .setStartZoneOffset(record.getStartZoneOffset()) 80 .setEndZoneOffset(record.getEndZoneOffset()) 81 .build(); 82 } 83 84 @Override getValuesBundleForRecord(MindfulnessSessionRecord record)85 protected Bundle getValuesBundleForRecord(MindfulnessSessionRecord record) { 86 Bundle values = new Bundle(); 87 values.putInt(KEY_TYPE, record.getMindfulnessSessionType()); 88 values.putCharSequence(KEY_TITLE, record.getTitle()); 89 values.putCharSequence(KEY_NOTES, record.getNotes()); 90 return values; 91 } 92 93 @Override newRecordFromValuesBundle( Metadata metadata, Instant startTime, Instant endTime, ZoneOffset startZoneOffset, ZoneOffset endZoneOffset, Bundle bundle)94 public MindfulnessSessionRecord newRecordFromValuesBundle( 95 Metadata metadata, 96 Instant startTime, 97 Instant endTime, 98 ZoneOffset startZoneOffset, 99 ZoneOffset endZoneOffset, 100 Bundle bundle) { 101 int type = bundle.getInt(KEY_TYPE); 102 String title = bundle.getString(KEY_TITLE); 103 String notes = bundle.getString(KEY_NOTES); 104 return new MindfulnessSessionRecord.Builder(metadata, startTime, endTime, type) 105 .setTitle(title) 106 .setNotes(notes) 107 .setStartZoneOffset(startZoneOffset) 108 .setEndZoneOffset(endZoneOffset) 109 .build(); 110 } 111 } 112