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.Nullable; 20 import android.health.connect.datatypes.PlannedExerciseBlock; 21 import android.os.Parcel; 22 23 import java.util.ArrayList; 24 import java.util.List; 25 26 /** 27 * Internal {@link PlannedExerciseBlock}. Part of a {@link PlannedExerciseSessionRecordInternal}. 28 * 29 * @hide 30 */ 31 public final class PlannedExerciseBlockInternal { 32 private int mRepetitions; 33 34 @Nullable private String mDescription; 35 36 private List<PlannedExerciseStepInternal> mExerciseSteps = new ArrayList<>(); 37 38 /** Serialize to parcel. */ writeToParcel(List<PlannedExerciseBlockInternal> blocks, Parcel parcel)39 public static void writeToParcel(List<PlannedExerciseBlockInternal> blocks, Parcel parcel) { 40 parcel.writeInt(blocks.size()); 41 for (PlannedExerciseBlockInternal block : blocks) { 42 parcel.writeInt(block.getRepetitions()); 43 parcel.writeString(block.getDescription()); 44 PlannedExerciseStepInternal.writeToParcel(block.getExerciseSteps(), parcel); 45 } 46 } 47 48 /** Deserialize from parcel. */ readFromParcel(Parcel parcel)49 public static List<PlannedExerciseBlockInternal> readFromParcel(Parcel parcel) { 50 List<PlannedExerciseBlockInternal> result = new ArrayList<>(); 51 int count = parcel.readInt(); 52 for (int i = 0; i < count; i++) { 53 PlannedExerciseBlockInternal block = new PlannedExerciseBlockInternal(parcel.readInt()); 54 block.setDescription(parcel.readString()); 55 block.setExerciseSteps(PlannedExerciseStepInternal.readFromParcel(parcel)); 56 result.add(block); 57 } 58 return result; 59 } 60 PlannedExerciseBlockInternal(int repetitions)61 public PlannedExerciseBlockInternal(int repetitions) { 62 this.mRepetitions = repetitions; 63 } 64 65 @Nullable getDescription()66 public String getDescription() { 67 return mDescription; 68 } 69 getRepetitions()70 public int getRepetitions() { 71 return mRepetitions; 72 } 73 getExerciseSteps()74 public List<PlannedExerciseStepInternal> getExerciseSteps() { 75 return mExerciseSteps; 76 } 77 setDescription(String description)78 public void setDescription(String description) { 79 this.mDescription = description; 80 } 81 setRepetitions(int repetitions)82 public void setRepetitions(int repetitions) { 83 this.mRepetitions = repetitions; 84 } 85 setExerciseSteps(List<PlannedExerciseStepInternal> exerciseSteps)86 public void setExerciseSteps(List<PlannedExerciseStepInternal> exerciseSteps) { 87 this.mExerciseSteps = exerciseSteps; 88 } 89 90 /** Convert to external representation. */ toExternalObject()91 public PlannedExerciseBlock toExternalObject() { 92 PlannedExerciseBlock.Builder builder = new PlannedExerciseBlock.Builder(mRepetitions); 93 builder.setDescription(mDescription); 94 for (PlannedExerciseStepInternal step : mExerciseSteps) { 95 builder.addStep(step.toExternalObject()); 96 } 97 return builder.build(); 98 } 99 } 100