1 package com.android.healthconnect.testapps.toolbox.fieldviews 2 3 import android.annotation.SuppressLint 4 import android.content.Context 5 import android.health.connect.datatypes.ExerciseCompletionGoal 6 import android.health.connect.datatypes.ExercisePerformanceGoal 7 import android.health.connect.datatypes.ExerciseSegmentType 8 import android.health.connect.datatypes.PlannedExerciseBlock 9 import android.health.connect.datatypes.PlannedExerciseStep 10 import android.health.connect.datatypes.units.Length 11 import android.health.connect.datatypes.units.Velocity 12 import android.widget.CheckBox 13 import android.widget.LinearLayout 14 import com.android.healthconnect.testapps.toolbox.R 15 16 @SuppressLint("ViewConstructor") 17 class ExerciseBlockInputField( 18 context: Context, 19 repetitionsField: EditableTextView, 20 descriptionField: EditableTextView, 21 generateTestExerciseSteps: CheckBox 22 ) : InputFieldView(context) { 23 var repetitionsField: EditableTextView 24 var descriptionField: EditableTextView 25 var generateTestExerciseSteps: CheckBox 26 27 init { 28 inflate(context, R.layout.fragment_exercise_block_input_field, this) 29 val containerView = findViewById<LinearLayout>(R.id.exercise_block_input_field) 30 this.repetitionsField = repetitionsField 31 this.descriptionField = descriptionField 32 this.generateTestExerciseSteps = generateTestExerciseSteps 33 generateTestExerciseSteps.text = 34 context.getString(R.string.training_plan_exercise_block_notice_text) 35 containerView.addView(repetitionsField) 36 containerView.addView(descriptionField) 37 containerView.addView(generateTestExerciseSteps) 38 } 39 getFieldValuenull40 override fun getFieldValue(): Any { 41 if (generateTestExerciseSteps.isChecked) { 42 return PlannedExerciseBlock.Builder( 43 Integer.parseInt(repetitionsField.getFieldValue().toString())) 44 .setDescription(descriptionField.getFieldValue().toString()) 45 .setSteps( 46 listOf( 47 PlannedExerciseStep.Builder( 48 ExerciseSegmentType.EXERCISE_SEGMENT_TYPE_RUNNING, 49 PlannedExerciseStep.EXERCISE_CATEGORY_ACTIVE, 50 ExerciseCompletionGoal.DistanceGoal(Length.fromMeters(4000.0))) 51 .setDescription("This is a test exercise step") 52 .setPerformanceGoals( 53 listOf( 54 ExercisePerformanceGoal.HeartRateGoal(150, 180), 55 ExercisePerformanceGoal.SpeedGoal( 56 Velocity.fromMetersPerSecond(50.0), 57 Velocity.fromMetersPerSecond(25.0)))) 58 .build())) 59 .build() 60 } else { 61 return PlannedExerciseBlock.Builder( 62 Integer.parseInt(repetitionsField.getFieldValue().toString())) 63 .setDescription(descriptionField.getFieldValue().toString()) 64 .setSteps(listOf()) 65 .build() 66 } 67 } 68 isEmptynull69 override fun isEmpty(): Boolean { 70 return repetitionsField.isEmpty() || descriptionField.isEmpty() 71 } 72 } 73