-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathORKOrderedTask+ORKPredefinedActiveTask.m
3048 lines (2480 loc) · 169 KB
/
ORKOrderedTask+ORKPredefinedActiveTask.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2015, Apple Inc. All rights reserved.
Copyright (c) 2016, Sage Bionetworks
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder(s) nor the names of any contributors
may be used to endorse or promote products derived from this software without
specific prior written permission. No license is granted to the trademarks of
the copyright holders even if such marks are included in this software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "ORKOrderedTask+ORKPredefinedActiveTask.h"
#import "ORKOrderedTask_Private.h"
#import "ORKAudioStepViewController.h"
#import "ORKAmslerGridStepViewController.h"
#import "ORKCountdownStepViewController.h"
#import "ORKTouchAnywhereStepViewController.h"
#import "ORKFitnessStepViewController.h"
#import "ORKToneAudiometryStepViewController.h"
#import "ORKSpatialSpanMemoryStepViewController.h"
#import "ORKSpeechRecognitionStepViewController.h"
#import "ORKStroopStepViewController.h"
#import "ORKWalkingTaskStepViewController.h"
#import "ORKAccelerometerRecorder.h"
#import "ORKActiveStep_Internal.h"
#import "ORKAmslerGridStep.h"
#import "ORKAnswerFormat_Internal.h"
#import "ORKAudioLevelNavigationRule.h"
#import "ORKAudioRecorder.h"
#import "ORKAudioStep.h"
#import "ORKCompletionStep.h"
#import "ORKCountdownStep.h"
#import "ORKEnvironmentSPLMeterStep.h"
#import "ORKHolePegTestPlaceStep.h"
#import "ORKHolePegTestRemoveStep.h"
#import "ORKTouchAnywhereStep.h"
#import "ORKFitnessStep.h"
#import "ORKFormStep.h"
#import "ORKNavigableOrderedTask.h"
#import "ORKPSATStep.h"
#import "ORKQuestionStep.h"
#import "ORKReactionTimeStep.h"
#import "ORKSpatialSpanMemoryStep.h"
#import "ORKSpeechRecognitionStep.h"
#import "ORKStep_Private.h"
#import "ORKStroopStep.h"
#import "ORKTappingIntervalStep.h"
#import "ORKTimedWalkStep.h"
#import "ORKToneAudiometryStep.h"
#import "ORKTowerOfHanoiStep.h"
#import "ORKTrailmakingStep.h"
#import "ORKVisualConsentStep.h"
#import "ORKRangeOfMotionStep.h"
#import "ORKShoulderRangeOfMotionStep.h"
#import "ORKWaitStep.h"
#import "ORKWalkingTaskStep.h"
#import "ORKResultPredicate.h"
#import "ORKSpeechInNoiseStep.h"
#import "ORKdBHLToneAudiometryStep.h"
#import "ORKdBHLToneAudiometryOnboardingStep.h"
#import "ORKSkin.h"
#import <ResearchKit/ResearchKit-Swift.h>
#import "ORKTouchAbilityTapStep.h"
#import "ORKTouchAbilityLongPressStep.h"
#import "ORKTouchAbilitySwipeStep.h"
#import "ORKTouchAbilityPinchStep.h"
#import "ORKTouchAbilityRotationStep.h"
#import "ORKTouchAbilityScrollStep.h"
#import "ORKHelpers_Internal.h"
#import "UIImage+ResearchKit.h"
#import <limits.h>
ORKTaskProgress ORKTaskProgressMake(NSUInteger current, NSUInteger total) {
return (ORKTaskProgress){.current=current, .total=total};
}
#pragma mark - Predefined
NSString *const ORKInstruction0StepIdentifier = @"instruction";
NSString *const ORKInstruction1StepIdentifier = @"instruction1";
NSString *const ORKInstruction2StepIdentifier = @"instruction2";
NSString *const ORKInstruction3StepIdentifier = @"instruction3";
NSString *const ORKInstruction4StepIdentifier = @"instruction4";
NSString *const ORKInstruction5StepIdentifier = @"instruction5";
NSString *const ORKInstruction6StepIdentifier = @"instruction6";
NSString *const ORKInstruction7StepIdentifier = @"instruction7";
NSString *const ORKCountdownStepIdentifier = @"countdown";
NSString *const ORKCountdown1StepIdentifier = @"countdown1";
NSString *const ORKCountdown2StepIdentifier = @"countdown2";
NSString *const ORKCountdown3StepIdentifier = @"countdown3";
NSString *const ORKCountdown4StepIdentifier = @"countdown4";
NSString *const ORKCountdown5StepIdentifier = @"countdown5";
NSString *const ORKEditSpeechTranscript0StepIdentifier = @"editSpeechTranscript0";
NSString *const ORKConclusionStepIdentifier = @"conclusion";
NSString *const ORKActiveTaskLeftHandIdentifier = @"left";
NSString *const ORKActiveTaskMostAffectedHandIdentifier = @"mostAffected";
NSString *const ORKActiveTaskRightHandIdentifier = @"right";
NSString *const ORKActiveTaskSkipHandStepIdentifier = @"skipHand";
NSString *const ORKTouchAnywhereStepIdentifier = @"touch.anywhere";
NSString *const ORKAudioRecorderIdentifier = @"audio";
NSString *const ORKAccelerometerRecorderIdentifier = @"accelerometer";
NSString *const ORKStreamingAudioRecorderIdentifier = @"streamingAudio";
NSString *const ORKPedometerRecorderIdentifier = @"pedometer";
NSString *const ORKDeviceMotionRecorderIdentifier = @"deviceMotion";
NSString *const ORKLocationRecorderIdentifier = @"location";
NSString *const ORKHeartRateRecorderIdentifier = @"heartRate";
void ORKStepArrayAddStep(NSMutableArray *array, ORKStep *step) {
[step validateParameters];
[array addObject:step];
}
@implementation ORKOrderedTask (ORKMakeTaskUtilities)
+ (ORKCompletionStep *)makeCompletionStep {
ORKCompletionStep *step = [[ORKCompletionStep alloc] initWithIdentifier:ORKConclusionStepIdentifier];
step.title = ORKLocalizedString(@"TASK_COMPLETE_TITLE", nil);
step.text = ORKLocalizedString(@"TASK_COMPLETE_TEXT", nil);
step.shouldTintImages = YES;
return step;
}
+ (NSDateComponentsFormatter *)textTimeFormatter {
NSDateComponentsFormatter *formatter = [NSDateComponentsFormatter new];
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleSpellOut;
// Exception list: Korean, Chinese (all), Thai, and Vietnamese.
NSArray *nonSpelledOutLanguages = @[@"ko", @"zh", @"th", @"vi", @"ja"];
NSString *currentLanguage = [[NSBundle mainBundle] preferredLocalizations].firstObject;
NSString *currentLanguageCode = [NSLocale componentsFromLocaleIdentifier:currentLanguage][NSLocaleLanguageCode];
if ((currentLanguageCode != nil) && [nonSpelledOutLanguages containsObject:currentLanguageCode]) {
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
}
formatter.allowedUnits = NSCalendarUnitMinute | NSCalendarUnitSecond;
formatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropAll;
return formatter;
}
@end
@implementation ORKOrderedTask (ORKPredefinedActiveTask)
#pragma mark - AmslerGridTask
NSString *const ORKAmslerGridStepLeftIdentifier = @"amsler.grid.left";
NSString *const ORKAmslerGridStepRightIdentifier = @"amsler.grid.right";
NSString *const ORKAmslerGridCalibrationLeftIdentifier = @"amsler.grid.calibration.left";
NSString *const ORKAmslerGridCalibrationRightIdentifier = @"amsler.grid.calibration.Right";
+ (ORKOrderedTask *)amslerGridTaskWithIdentifier:(NSString *)identifier
intendedUseDescription:(NSString *)intendedUseDescription
options:(ORKPredefinedTaskOption)options {
NSMutableArray *steps = [NSMutableArray array];
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction0StepIdentifier];
step.title = ORKLocalizedString(@"AMSLER_GRID_TITLE", nil);
step.text = intendedUseDescription;
step.detailText = ORKLocalizedString(@"AMSLER_GRID_INTRO_TEXT", nil);
step.image = [UIImage imageNamed:@"amslerGrid" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.imageContentMode = UIViewContentModeCenter;
step.shouldTintImages = YES;
ORKStepArrayAddStep(steps, step);
}
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction1StepIdentifier];
step.title = ORKLocalizedString(@"AMSLER_GRID_TITLE", nil);
step.text = ORKLocalizedString(@"AMSLER_GRID_INSTRUCTION_TEXT", nil);
NSString *leftEye = ORKLocalizedString(@"AMSLER_GRID_LEFT_EYE", nil);
NSString *detailText = [@"\n" stringByAppendingString:[NSString stringWithFormat:ORKLocalizedString(@"AMSLER_GRID_INSTRUCTION_DETAIL_TEXT", nil), leftEye]];
step.detailText = detailText;
step.image = [UIImage imageNamed:@"amslerGrid" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeCenter;
ORKStepArrayAddStep(steps, step);
}
}
{
ORKAmslerGridStep *step = [[ORKAmslerGridStep alloc] initWithIdentifier:ORKAmslerGridStepLeftIdentifier];
step.eyeSide = ORKAmslerGridEyeSideLeft;
ORKStepArrayAddStep(steps, step);
}
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction2StepIdentifier];
step.title = ORKLocalizedString(@"AMSLER_GRID_TITLE", nil);
step.text = ORKLocalizedString(@"AMSLER_GRID_INSTRUCTION_TEXT", nil);
NSString *rightEye = ORKLocalizedString(@"AMSLER_GRID_RIGHT_EYE", nil);
NSString *detailText = [@"\n" stringByAppendingString:[NSString stringWithFormat:ORKLocalizedString(@"AMSLER_GRID_INSTRUCTION_DETAIL_TEXT", nil), rightEye]];
step.detailText = detailText;
step.image = [UIImage imageNamed:@"amslerGrid" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.imageContentMode = UIViewContentModeCenter;
step.shouldTintImages = YES;
ORKStepArrayAddStep(steps, step);
}
}
{
ORKAmslerGridStep *step = [[ORKAmslerGridStep alloc] initWithIdentifier:ORKAmslerGridStepRightIdentifier];
step.eyeSide = ORKAmslerGridEyeSideRight;
ORKStepArrayAddStep(steps, step);
}
if (!(options & ORKPredefinedTaskOptionExcludeConclusion)) {
ORKCompletionStep *completionStep = [self makeCompletionStep];
ORKStepArrayAddStep(steps, completionStep);
}
ORKOrderedTask *task = [[ORKOrderedTask alloc] initWithIdentifier:identifier steps:steps];
return task;
}
#pragma mark - holePegTestTask
NSString *const ORKHolePegTestDominantPlaceStepIdentifier = @"hole.peg.test.dominant.place";
NSString *const ORKHolePegTestDominantRemoveStepIdentifier = @"hole.peg.test.dominant.remove";
NSString *const ORKHolePegTestNonDominantPlaceStepIdentifier = @"hole.peg.test.non.dominant.place";
NSString *const ORKHolePegTestNonDominantRemoveStepIdentifier = @"hole.peg.test.non.dominant.remove";
+ (ORKNavigableOrderedTask *)holePegTestTaskWithIdentifier:(NSString *)identifier
intendedUseDescription:(nullable NSString *)intendedUseDescription
dominantHand:(ORKBodySagittal)dominantHand
numberOfPegs:(int)numberOfPegs
threshold:(double)threshold
rotated:(BOOL)rotated
timeLimit:(NSTimeInterval)timeLimit
options:(ORKPredefinedTaskOption)options {
NSMutableArray *steps = [NSMutableArray array];
BOOL dominantHandLeft = (dominantHand == ORKBodySagittalLeft);
NSTimeInterval stepDuration = (timeLimit == 0) ? CGFLOAT_MAX : timeLimit;
NSString *pegs = [NSNumberFormatter localizedStringFromNumber:@(numberOfPegs) numberStyle:NSNumberFormatterNoStyle];
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction0StepIdentifier];
step.title = [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_TITLE_%@", nil), pegs];
step.text = intendedUseDescription;
step.detailText = [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_INTRO_TEXT_%@", nil), pegs];
step.image = [UIImage imageNamed:@"phoneholepeg" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.imageContentMode = UIViewContentModeCenter;
step.shouldTintImages = YES;
ORKStepArrayAddStep(steps, step);
}
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction1StepIdentifier];
step.title = [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_TITLE_%@", nil), pegs];
step.text = dominantHandLeft ? [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_INTRO_TEXT_2_LEFT_HAND_FIRST_%@%@", nil), pegs, pegs] : [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_INTRO_TEXT_2_RIGHT_HAND_FIRST_%@%@", nil), pegs, pegs];
step.detailText = ORKLocalizedString(@"HOLE_PEG_TEST_CALL_TO_ACTION", nil);
UIImage *image1 = [UIImage imageNamed:@"holepegtest1" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
UIImage *image2 = [UIImage imageNamed:@"holepegtest2" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
UIImage *image3 = [UIImage imageNamed:@"holepegtest3" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
UIImage *image4 = [UIImage imageNamed:@"holepegtest4" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
UIImage *image5 = [UIImage imageNamed:@"holepegtest5" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
UIImage *image6 = [UIImage imageNamed:@"holepegtest6" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.image = [UIImage animatedImageWithImages:@[image1, image2, image3, image4, image5, image6] duration:4];
step.imageContentMode = UIViewContentModeScaleAspectFit;
step.shouldTintImages = YES;
ORKStepArrayAddStep(steps, step);
}
}
{
{
ORKHolePegTestPlaceStep *step = [[ORKHolePegTestPlaceStep alloc] initWithIdentifier:ORKHolePegTestDominantPlaceStepIdentifier];
step.title = [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_TITLE_%@", nil), pegs];
step.text = [dominantHandLeft ? ORKLocalizedString(@"HOLE_PEG_TEST_PLACE_INSTRUCTION_LEFT_HAND", nil) : ORKLocalizedString(@"HOLE_PEG_TEST_PLACE_INSTRUCTION_RIGHT_HAND", nil) stringByAppendingString:[@"\n" stringByAppendingString:ORKLocalizedString(@"HOLE_PEG_TEST_TEXT", nil)]];
step.spokenInstruction = step.text;
step.movingDirection = dominantHand;
step.dominantHandTested = YES;
step.numberOfPegs = numberOfPegs;
step.threshold = threshold;
step.rotated = rotated;
step.shouldTintImages = YES;
step.stepDuration = stepDuration;
ORKStepArrayAddStep(steps, step);
}
{
ORKHolePegTestRemoveStep *step = [[ORKHolePegTestRemoveStep alloc] initWithIdentifier:ORKHolePegTestDominantRemoveStepIdentifier];
step.title = [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_TITLE_%@", nil), pegs];
step.text = [dominantHandLeft ? ORKLocalizedString(@"HOLE_PEG_TEST_REMOVE_INSTRUCTION_LEFT_HAND", nil) : ORKLocalizedString(@"HOLE_PEG_TEST_REMOVE_INSTRUCTION_RIGHT_HAND", nil) stringByAppendingString:[@"\n" stringByAppendingString:ORKLocalizedString(@"HOLE_PEG_TEST_TEXT", nil)]];
step.spokenInstruction = step.text;
step.movingDirection = (dominantHand == ORKBodySagittalLeft) ? ORKBodySagittalRight : ORKBodySagittalLeft;
step.dominantHandTested = YES;
step.numberOfPegs = numberOfPegs;
step.threshold = threshold;
step.shouldTintImages = YES;
step.stepDuration = stepDuration;
ORKStepArrayAddStep(steps, step);
}
{
ORKHolePegTestPlaceStep *step = [[ORKHolePegTestPlaceStep alloc] initWithIdentifier:ORKHolePegTestNonDominantPlaceStepIdentifier];
step.title = [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_TITLE_%@", nil), pegs];
step.text = [dominantHandLeft ? ORKLocalizedString(@"HOLE_PEG_TEST_PLACE_INSTRUCTION_RIGHT_HAND", nil) : ORKLocalizedString(@"HOLE_PEG_TEST_PLACE_INSTRUCTION_LEFT_HAND", nil) stringByAppendingString:[@"\n" stringByAppendingString:ORKLocalizedString(@"HOLE_PEG_TEST_TEXT", nil)]];
step.spokenInstruction = step.text;
step.movingDirection = (dominantHand == ORKBodySagittalLeft) ? ORKBodySagittalRight : ORKBodySagittalLeft;
step.dominantHandTested = NO;
step.numberOfPegs = numberOfPegs;
step.threshold = threshold;
step.rotated = rotated;
step.shouldTintImages = YES;
step.stepDuration = stepDuration;
ORKStepArrayAddStep(steps, step);
}
{
ORKHolePegTestRemoveStep *step = [[ORKHolePegTestRemoveStep alloc] initWithIdentifier:ORKHolePegTestNonDominantRemoveStepIdentifier];
step.title = [[NSString alloc] initWithFormat:ORKLocalizedString(@"HOLE_PEG_TEST_TITLE_%@", nil), pegs];
step.text = [dominantHandLeft ? ORKLocalizedString(@"HOLE_PEG_TEST_REMOVE_INSTRUCTION_RIGHT_HAND", nil) : ORKLocalizedString(@"HOLE_PEG_TEST_REMOVE_INSTRUCTION_LEFT_HAND", nil) stringByAppendingString:[@"\n" stringByAppendingString:ORKLocalizedString(@"HOLE_PEG_TEST_TEXT", nil)]];
step.spokenInstruction = step.text;
step.movingDirection = dominantHand;
step.dominantHandTested = NO;
step.numberOfPegs = numberOfPegs;
step.threshold = threshold;
step.shouldTintImages = YES;
step.stepDuration = stepDuration;
ORKStepArrayAddStep(steps, step);
}
}
if (!(options & ORKPredefinedTaskOptionExcludeConclusion)) {
ORKCompletionStep *step = [self makeCompletionStep];
ORKStepArrayAddStep(steps, step);
}
// The task is actually dynamic. The direct navigation rules are used for skipping the peg
// removal steps if the user doesn't succeed in placing all the pegs in the allotted time
// (the rules are removed from `ORKHolePegTestPlaceStepViewController` if she succeeds).
ORKNavigableOrderedTask *task = [[ORKNavigableOrderedTask alloc] initWithIdentifier:identifier steps:steps];
ORKStepNavigationRule *navigationRule = [[ORKDirectStepNavigationRule alloc] initWithDestinationStepIdentifier:ORKHolePegTestNonDominantPlaceStepIdentifier];
[task setNavigationRule:navigationRule forTriggerStepIdentifier:ORKHolePegTestDominantPlaceStepIdentifier];
navigationRule = [[ORKDirectStepNavigationRule alloc] initWithDestinationStepIdentifier:ORKConclusionStepIdentifier];
[task setNavigationRule:navigationRule forTriggerStepIdentifier:ORKHolePegTestNonDominantPlaceStepIdentifier];
return task;
}
#pragma mark - twoFingerTappingInterval
NSString *const ORKTappingStepIdentifier = @"tapping";
+ (ORKOrderedTask *)twoFingerTappingIntervalTaskWithIdentifier:(NSString *)identifier
intendedUseDescription:(NSString *)intendedUseDescription
duration:(NSTimeInterval)duration
handOptions:(ORKPredefinedTaskHandOption)handOptions
options:(ORKPredefinedTaskOption)options {
NSString *durationString = [ORKDurationStringFormatter() stringFromTimeInterval:duration];
NSMutableArray *steps = [NSMutableArray array];
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction0StepIdentifier];
step.title = ORKLocalizedString(@"TAPPING_TASK_TITLE", nil);
step.text = intendedUseDescription;
step.detailText = ORKLocalizedString(@"TAPPING_INTRO_TEXT", nil);
NSString *imageName = @"phonetapping";
if (![[NSLocale preferredLanguages].firstObject hasPrefix:@"en"]) {
imageName = [imageName stringByAppendingString:@"_notap"];
}
step.image = [UIImage imageNamed:imageName inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeScaleAspectFit;
ORKStepArrayAddStep(steps, step);
}
}
// Setup which hand to start with and how many hands to add based on the handOptions parameter
// Hand order is randomly determined.
NSUInteger handCount = ((handOptions & ORKPredefinedTaskHandOptionBoth) == ORKPredefinedTaskHandOptionBoth) ? 2 : 1;
BOOL undefinedHand = (handOptions == 0);
BOOL rightHand;
switch (handOptions) {
case ORKPredefinedTaskHandOptionLeft:
rightHand = NO; break;
case ORKPredefinedTaskHandOptionRight:
case ORKPredefinedTaskHandOptionUnspecified:
rightHand = YES; break;
default:
rightHand = (arc4random()%2 == 0); break;
}
for (NSUInteger hand = 1; hand <= handCount; hand++) {
NSString * (^appendIdentifier) (NSString *) = ^ (NSString * stepIdentifier) {
if (undefinedHand) {
return stepIdentifier;
} else {
NSString *handIdentifier = rightHand ? ORKActiveTaskRightHandIdentifier : ORKActiveTaskLeftHandIdentifier;
return [NSString stringWithFormat:@"%@.%@", stepIdentifier, handIdentifier];
}
};
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:appendIdentifier(ORKInstruction1StepIdentifier)];
// Set the title based on the hand
if (undefinedHand) {
step.title = ORKLocalizedString(@"TAPPING_TASK_TITLE", nil);
} else if (rightHand) {
step.title = ORKLocalizedString(@"TAPPING_TASK_TITLE_RIGHT", nil);
} else {
step.title = ORKLocalizedString(@"TAPPING_TASK_TITLE_LEFT", nil);
}
// Set the instructions for the tapping test screen that is displayed prior to each hand test
NSString *restText = ORKLocalizedString(@"TAPPING_INTRO_TEXT_2_REST_PHONE", nil);
NSString *tappingTextFormat = ORKLocalizedString(@"TAPPING_INTRO_TEXT_2_FORMAT", nil);
NSString *tappingText = [NSString localizedStringWithFormat:tappingTextFormat, durationString];
NSString *handText = nil;
if (hand == 1) {
if (undefinedHand) {
handText = ORKLocalizedString(@"TAPPING_INTRO_TEXT_2_MOST_AFFECTED", nil);
} else if (rightHand) {
handText = ORKLocalizedString(@"TAPPING_INTRO_TEXT_2_RIGHT_FIRST", nil);
} else {
handText = ORKLocalizedString(@"TAPPING_INTRO_TEXT_2_LEFT_FIRST", nil);
}
} else {
if (rightHand) {
handText = ORKLocalizedString(@"TAPPING_INTRO_TEXT_2_RIGHT_SECOND", nil);
} else {
handText = ORKLocalizedString(@"TAPPING_INTRO_TEXT_2_LEFT_SECOND", nil);
}
}
step.text = [NSString localizedStringWithFormat:@"%@ %@ %@", restText, handText, tappingText];
// Continue button will be different from first hand and second hand
if (hand == 1) {
step.detailText = ORKLocalizedString(@"TAPPING_CALL_TO_ACTION", nil);
} else {
step.detailText = ORKLocalizedString(@"TAPPING_CALL_TO_ACTION_NEXT", nil);
}
// Set the image
UIImage *im1 = [UIImage imageNamed:@"handtapping01" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
UIImage *im2 = [UIImage imageNamed:@"handtapping02" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
UIImage *imageAnimation = [UIImage animatedImageWithImages:@[im1, im2] duration:1];
if (rightHand || undefinedHand) {
step.image = imageAnimation;
} else {
step.image = [imageAnimation ork_flippedImage:UIImageOrientationUpMirrored];
}
step.imageContentMode = UIViewContentModeScaleAspectFit;
step.shouldTintImages = YES;
ORKStepArrayAddStep(steps, step);
}
// TAPPING STEP
{
NSMutableArray *recorderConfigurations = [NSMutableArray arrayWithCapacity:5];
if (!(ORKPredefinedTaskOptionExcludeAccelerometer & options)) {
[recorderConfigurations addObject:[[ORKAccelerometerRecorderConfiguration alloc] initWithIdentifier:ORKAccelerometerRecorderIdentifier
frequency:100]];
}
ORKTappingIntervalStep *step = [[ORKTappingIntervalStep alloc] initWithIdentifier:appendIdentifier(ORKTappingStepIdentifier)];
step.title = ORKLocalizedString(@"TAPPING_TASK_TITLE", nil);
if (undefinedHand) {
step.text = ORKLocalizedString(@"TAPPING_INSTRUCTION", nil);
} else if (rightHand) {
step.text = ORKLocalizedString(@"TAPPING_INSTRUCTION_RIGHT", nil);
} else {
step.text = ORKLocalizedString(@"TAPPING_INSTRUCTION_LEFT", nil);
}
if (UIAccessibilityIsVoiceOverRunning()) {
step.text = [NSString stringWithFormat:ORKLocalizedString(@"AX_TAPPING_INSTRUCTION_VOICEOVER", nil), step.text];
}
step.stepDuration = duration;
step.shouldContinueOnFinish = YES;
step.recorderConfigurations = recorderConfigurations;
step.optional = (handCount == 2);
ORKStepArrayAddStep(steps, step);
}
// Flip to the other hand (ignored if handCount == 1)
rightHand = !rightHand;
}
if (!(options & ORKPredefinedTaskOptionExcludeConclusion)) {
ORKInstructionStep *step = [self makeCompletionStep];
ORKStepArrayAddStep(steps, step);
}
ORKOrderedTask *task = [[ORKOrderedTask alloc] initWithIdentifier:identifier steps:[steps copy]];
return task;
}
#pragma mark - audioTask
NSString *const ORKAudioStepIdentifier = @"audio";
NSString *const ORKAudioTooLoudStepIdentifier = @"audio.tooloud";
+ (ORKNavigableOrderedTask *)audioTaskWithIdentifier:(NSString *)identifier
intendedUseDescription:(nullable NSString *)intendedUseDescription
speechInstruction:(nullable NSString *)speechInstruction
shortSpeechInstruction:(nullable NSString *)shortSpeechInstruction
duration:(NSTimeInterval)duration
recordingSettings:(nullable NSDictionary *)recordingSettings
checkAudioLevel:(BOOL)checkAudioLevel
options:(ORKPredefinedTaskOption)options {
recordingSettings = recordingSettings ? : @{ AVFormatIDKey : @(kAudioFormatAppleLossless),
AVNumberOfChannelsKey : @(2),
AVSampleRateKey: @(44100.0) };
if (options & ORKPredefinedTaskOptionExcludeAudio) {
@throw [NSException exceptionWithName:NSGenericException reason:@"Audio collection cannot be excluded from audio task" userInfo:nil];
}
NSMutableArray *steps = [NSMutableArray array];
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction0StepIdentifier];
step.title = ORKLocalizedString(@"AUDIO_TASK_TITLE", nil);
step.text = intendedUseDescription;
step.detailText = ORKLocalizedString(@"AUDIO_INTENDED_USE", nil);
step.image = [UIImage imageNamed:@"phonewaves" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeCenter;
ORKStepArrayAddStep(steps, step);
}
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction1StepIdentifier];
step.title = ORKLocalizedString(@"AUDIO_TASK_TITLE", nil);
step.text = speechInstruction ? : ORKLocalizedString(@"AUDIO_INTRO_TEXT", nil);
step.detailText = ORKLocalizedString(@"AUDIO_CALL_TO_ACTION", nil);
step.image = [UIImage imageNamed:@"phonewaves" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeCenter;
ORKStepArrayAddStep(steps, step);
}
}
{
ORKCountdownStep *step = [[ORKCountdownStep alloc] initWithIdentifier:ORKCountdownStepIdentifier];
step.stepDuration = 5.0;
step.title = ORKLocalizedString(@"AUDIO_TASK_TITLE", nil);
// Collect audio during the countdown step too, to provide a baseline.
step.recorderConfigurations = @[[[ORKAudioRecorderConfiguration alloc] initWithIdentifier:ORKAudioRecorderIdentifier
recorderSettings:recordingSettings]];
// If checking the sound level then add text indicating that's what is happening
if (checkAudioLevel) {
step.text = ORKLocalizedString(@"AUDIO_LEVEL_CHECK_LABEL", nil);
}
ORKStepArrayAddStep(steps, step);
}
if (checkAudioLevel) {
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKAudioTooLoudStepIdentifier];
step.title = ORKLocalizedString(@"AUDIO_TASK_TITLE", nil);
step.text = ORKLocalizedString(@"AUDIO_TOO_LOUD_MESSAGE", nil);
step.detailText = ORKLocalizedString(@"AUDIO_TOO_LOUD_ACTION_NEXT", nil);
ORKStepArrayAddStep(steps, step);
}
{
ORKAudioStep *step = [[ORKAudioStep alloc] initWithIdentifier:ORKAudioStepIdentifier];
step.title = ORKLocalizedString(@"AUDIO_TASK_TITLE", nil);
step.text = shortSpeechInstruction ? : ORKLocalizedString(@"AUDIO_INSTRUCTION", nil);
step.recorderConfigurations = @[[[ORKAudioRecorderConfiguration alloc] initWithIdentifier:ORKAudioRecorderIdentifier
recorderSettings:recordingSettings]];
step.stepDuration = duration;
step.shouldContinueOnFinish = YES;
ORKStepArrayAddStep(steps, step);
}
if (!(options & ORKPredefinedTaskOptionExcludeConclusion)) {
ORKInstructionStep *step = [self makeCompletionStep];
ORKStepArrayAddStep(steps, step);
}
ORKNavigableOrderedTask *task = [[ORKNavigableOrderedTask alloc] initWithIdentifier:identifier steps:steps];
if (checkAudioLevel) {
// Add rules to check for audio and fail, looping back to the countdown step if required
ORKAudioLevelNavigationRule *audioRule = [[ORKAudioLevelNavigationRule alloc] initWithAudioLevelStepIdentifier:ORKCountdownStepIdentifier destinationStepIdentifier:ORKAudioStepIdentifier recordingSettings:recordingSettings];
ORKDirectStepNavigationRule *loopRule = [[ORKDirectStepNavigationRule alloc] initWithDestinationStepIdentifier:ORKCountdownStepIdentifier];
[task setNavigationRule:audioRule forTriggerStepIdentifier:ORKCountdownStepIdentifier];
[task setNavigationRule:loopRule forTriggerStepIdentifier:ORKAudioTooLoudStepIdentifier];
}
return task;
}
#pragma mark - fitnessCheckTask
NSString *const ORKFitnessWalkStepIdentifier = @"fitness.walk";
NSString *const ORKFitnessRestStepIdentifier = @"fitness.rest";
+ (ORKOrderedTask *)fitnessCheckTaskWithIdentifier:(NSString *)identifier
intendedUseDescription:(NSString *)intendedUseDescription
walkDuration:(NSTimeInterval)walkDuration
restDuration:(NSTimeInterval)restDuration
options:(ORKPredefinedTaskOption)options {
NSDateComponentsFormatter *formatter = [self textTimeFormatter];
NSMutableArray *steps = [NSMutableArray array];
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction0StepIdentifier];
step.title = ORKLocalizedString(@"FITNESS_TASK_TITLE", nil);
step.text = intendedUseDescription ? : [NSString localizedStringWithFormat:ORKLocalizedString(@"FITNESS_INTRO_TEXT_FORMAT", nil), [formatter stringFromTimeInterval:walkDuration]];
step.image = [UIImage imageNamed:@"heartbeat" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeCenter;
ORKStepArrayAddStep(steps, step);
}
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction1StepIdentifier];
step.title = ORKLocalizedString(@"FITNESS_TASK_TITLE", nil);
step.text = [NSString localizedStringWithFormat:ORKLocalizedString(@"FITNESS_INTRO_2_TEXT_FORMAT", nil), [formatter stringFromTimeInterval:walkDuration], [formatter stringFromTimeInterval:restDuration]];
step.image = [UIImage imageNamed:@"walkingman" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeCenter;
ORKStepArrayAddStep(steps, step);
}
}
{
ORKCountdownStep *step = [[ORKCountdownStep alloc] initWithIdentifier:ORKCountdownStepIdentifier];
step.title = ORKLocalizedString(@"FITNESS_TASK_TITLE", nil);
step.stepDuration = 5.0;
ORKStepArrayAddStep(steps, step);
}
HKUnit *bpmUnit = [[HKUnit countUnit] unitDividedByUnit:[HKUnit minuteUnit]];
HKQuantityType *heartRateType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
{
if (walkDuration > 0) {
NSMutableArray *recorderConfigurations = [NSMutableArray arrayWithCapacity:5];
if (!(ORKPredefinedTaskOptionExcludePedometer & options)) {
[recorderConfigurations addObject:[[ORKPedometerRecorderConfiguration alloc] initWithIdentifier:ORKPedometerRecorderIdentifier]];
}
if (!(ORKPredefinedTaskOptionExcludeAccelerometer & options)) {
[recorderConfigurations addObject:[[ORKAccelerometerRecorderConfiguration alloc] initWithIdentifier:ORKAccelerometerRecorderIdentifier
frequency:100]];
}
if (!(ORKPredefinedTaskOptionExcludeDeviceMotion & options)) {
[recorderConfigurations addObject:[[ORKDeviceMotionRecorderConfiguration alloc] initWithIdentifier:ORKDeviceMotionRecorderIdentifier
frequency:100]];
}
if (!(ORKPredefinedTaskOptionExcludeLocation & options)) {
[recorderConfigurations addObject:[[ORKLocationRecorderConfiguration alloc] initWithIdentifier:ORKLocationRecorderIdentifier]];
}
if (!(ORKPredefinedTaskOptionExcludeHeartRate & options)) {
[recorderConfigurations addObject:[[ORKHealthQuantityTypeRecorderConfiguration alloc] initWithIdentifier:ORKHeartRateRecorderIdentifier
healthQuantityType:heartRateType unit:bpmUnit]];
}
ORKFitnessStep *fitnessStep = [[ORKFitnessStep alloc] initWithIdentifier:ORKFitnessWalkStepIdentifier];
fitnessStep.stepDuration = walkDuration;
fitnessStep.title = ORKLocalizedString(@"FITNESS_TASK_TITLE", nil);
fitnessStep.text = [NSString localizedStringWithFormat:ORKLocalizedString(@"FITNESS_WALK_INSTRUCTION_FORMAT", nil), [formatter stringFromTimeInterval:walkDuration]];
fitnessStep.spokenInstruction = fitnessStep.text;
fitnessStep.recorderConfigurations = recorderConfigurations;
fitnessStep.shouldContinueOnFinish = YES;
fitnessStep.optional = NO;
fitnessStep.shouldStartTimerAutomatically = YES;
fitnessStep.shouldTintImages = YES;
fitnessStep.image = [UIImage imageNamed:@"walkingman" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
fitnessStep.imageContentMode = UIViewContentModeCenter;
fitnessStep.shouldVibrateOnStart = YES;
fitnessStep.shouldPlaySoundOnStart = YES;
ORKStepArrayAddStep(steps, fitnessStep);
}
if (restDuration > 0) {
NSMutableArray *recorderConfigurations = [NSMutableArray arrayWithCapacity:5];
if (!(ORKPredefinedTaskOptionExcludeAccelerometer & options)) {
[recorderConfigurations addObject:[[ORKAccelerometerRecorderConfiguration alloc] initWithIdentifier:ORKAccelerometerRecorderIdentifier
frequency:100]];
}
if (!(ORKPredefinedTaskOptionExcludeDeviceMotion & options)) {
[recorderConfigurations addObject:[[ORKDeviceMotionRecorderConfiguration alloc] initWithIdentifier:ORKDeviceMotionRecorderIdentifier
frequency:100]];
}
if (!(ORKPredefinedTaskOptionExcludeHeartRate & options)) {
[recorderConfigurations addObject:[[ORKHealthQuantityTypeRecorderConfiguration alloc] initWithIdentifier:ORKHeartRateRecorderIdentifier
healthQuantityType:heartRateType unit:bpmUnit]];
}
ORKFitnessStep *stillStep = [[ORKFitnessStep alloc] initWithIdentifier:ORKFitnessRestStepIdentifier];
stillStep.stepDuration = restDuration;
stillStep.title = ORKLocalizedString(@"FITNESS_TASK_TITLE", nil);
stillStep.text = [NSString localizedStringWithFormat:ORKLocalizedString(@"FITNESS_SIT_INSTRUCTION_FORMAT", nil), [formatter stringFromTimeInterval:restDuration]];
stillStep.spokenInstruction = stillStep.text;
stillStep.recorderConfigurations = recorderConfigurations;
stillStep.shouldContinueOnFinish = YES;
stillStep.optional = NO;
stillStep.shouldStartTimerAutomatically = YES;
stillStep.shouldTintImages = YES;
stillStep.image = [UIImage imageNamed:@"sittingman" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
stillStep.imageContentMode = UIViewContentModeCenter;
stillStep.shouldVibrateOnStart = YES;
stillStep.shouldPlaySoundOnStart = YES;
stillStep.shouldPlaySoundOnFinish = YES;
stillStep.shouldVibrateOnFinish = YES;
ORKStepArrayAddStep(steps, stillStep);
}
}
if (!(options & ORKPredefinedTaskOptionExcludeConclusion)) {
ORKInstructionStep *step = [self makeCompletionStep];
ORKStepArrayAddStep(steps, step);
}
ORKOrderedTask *task = [[ORKOrderedTask alloc] initWithIdentifier:identifier steps:steps];
return task;
}
#pragma mark - shortWalkTask
NSString *const ORKShortWalkOutboundStepIdentifier = @"walking.outbound";
NSString *const ORKShortWalkReturnStepIdentifier = @"walking.return";
NSString *const ORKShortWalkRestStepIdentifier = @"walking.rest";
+ (ORKOrderedTask *)shortWalkTaskWithIdentifier:(NSString *)identifier
intendedUseDescription:(NSString *)intendedUseDescription
numberOfStepsPerLeg:(NSInteger)numberOfStepsPerLeg
restDuration:(NSTimeInterval)restDuration
options:(ORKPredefinedTaskOption)options {
NSDateComponentsFormatter *formatter = [self textTimeFormatter];
NSMutableArray *steps = [NSMutableArray array];
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
// Step 1: Video Instruction step
ORKVideoInstructionStep *videoInstructionStep = [[ORKVideoInstructionStep alloc] initWithIdentifier:ORKInstruction0StepIdentifier];
//let videoInstructionStep = ORKVideoInstructionStep(identifier: "videoInstructionStep")
videoInstructionStep.title = ORKLocalizedString(@"Step 1 - Watch Instructional Video", nil);
NSURL *URL = [NSURL URLWithString:@"https://drive.google.com/uc?export=download&id=1LjCf0_uV04k6En6eQBEwPL7wfzJIjHed"];
videoInstructionStep.videoURL = URL;
videoInstructionStep.thumbnailTime = 2; // Customizable thumbnail timestamp
ORKStepArrayAddStep(steps, videoInstructionStep);
}
{
ORKTextChoice *textChoice1 = [ORKTextChoice choiceWithText:@"Have you cleared a 10-foot-long space with no throw rugs or obstructions?" value:@1];
ORKTextChoice *textChoice2 = [ORKTextChoice choiceWithText:@"Have you set up a chair on one side (ideally with arms)?" value:@2];
ORKTextChoice *textChoice3 = [ORKTextChoice choiceWithText:@"Are you wearing regular footwear?" value:@3];
ORKTextChoice *textChoice4 = [ORKTextChoice choiceWithText:@"Do you have someone present who can assist you if needed?" value:@4];
ORKTextChoice *textChoice5 = [ORKTextChoice choiceWithText:@"Have you put on the belt with pouch to hold your phone?" value:@5];
NSArray *textChoices = @[textChoice1, textChoice2, textChoice3, textChoice4, textChoice5];
ORKTextScaleAnswerFormat *scaleAnswerFormat = [ORKAnswerFormat choiceAnswerFormatWithStyle:ORKChoiceAnswerStyleMultipleChoice textChoices:textChoices];
ORKQuestionStep *step = [ORKQuestionStep questionStepWithIdentifier:@"TextStep"
title:@"Safety Checklist "
question:@"Next, we need you to make sure the safety checklist is complete."
answer:scaleAnswerFormat];
ORKStepArrayAddStep(steps, step);
}
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction2StepIdentifier];
step.title = ORKLocalizedString(@"Step 3", nil);
step.text = [NSString localizedStringWithFormat:ORKLocalizedString(@"WALK_INTRO_2_TEXT_%ld", nil),numberOfStepsPerLeg];
step.detailText = ORKLocalizedString(@"WALK_INTRO_2_DETAIL", nil);
step.image = [UIImage imageNamed:@"pocket" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeCenter;
ORKStepArrayAddStep(steps, step);
}
}
{
ORKCountdownStep *step = [[ORKCountdownStep alloc] initWithIdentifier:ORKCountdownStepIdentifier];
step.title = ORKLocalizedString(@"WALK_TASK_TITLE", nil);
step.stepDuration = 5.0;
ORKStepArrayAddStep(steps, step);
}
{
{
NSMutableArray *recorderConfigurations = [NSMutableArray array];
if (!(ORKPredefinedTaskOptionExcludePedometer & options)) {
[recorderConfigurations addObject:[[ORKPedometerRecorderConfiguration alloc] initWithIdentifier:ORKPedometerRecorderIdentifier]];
}
if (!(ORKPredefinedTaskOptionExcludeAccelerometer & options)) {
[recorderConfigurations addObject:[[ORKAccelerometerRecorderConfiguration alloc] initWithIdentifier:ORKAccelerometerRecorderIdentifier
frequency:100]];
}
if (!(ORKPredefinedTaskOptionExcludeDeviceMotion & options)) {
[recorderConfigurations addObject:[[ORKDeviceMotionRecorderConfiguration alloc] initWithIdentifier:ORKDeviceMotionRecorderIdentifier
frequency:100]];
}
ORKWalkingTaskStep *walkingStep = [[ORKWalkingTaskStep alloc] initWithIdentifier:ORKShortWalkOutboundStepIdentifier];
walkingStep.numberOfStepsPerLeg = numberOfStepsPerLeg;
walkingStep.title = ORKLocalizedString(@"WALK_TASK_TITLE", nil);
walkingStep.text = [NSString localizedStringWithFormat:ORKLocalizedString(@"WALK_OUTBOUND_INSTRUCTION_FORMAT", nil), (long long)numberOfStepsPerLeg];
walkingStep.spokenInstruction = walkingStep.text;
walkingStep.recorderConfigurations = recorderConfigurations;
walkingStep.shouldContinueOnFinish = YES;
walkingStep.optional = NO;
walkingStep.shouldStartTimerAutomatically = YES;
walkingStep.stepDuration = numberOfStepsPerLeg * 1.5; // fallback duration in case no step count
walkingStep.shouldVibrateOnStart = YES;
walkingStep.shouldPlaySoundOnStart = YES;
ORKStepArrayAddStep(steps, walkingStep);
}
{
NSMutableArray *recorderConfigurations = [NSMutableArray array];
if (!(ORKPredefinedTaskOptionExcludePedometer & options)) {
[recorderConfigurations addObject:[[ORKPedometerRecorderConfiguration alloc] initWithIdentifier:ORKPedometerRecorderIdentifier]];
}
if (!(ORKPredefinedTaskOptionExcludeAccelerometer & options)) {
[recorderConfigurations addObject:[[ORKAccelerometerRecorderConfiguration alloc] initWithIdentifier:ORKAccelerometerRecorderIdentifier
frequency:100]];
}
if (!(ORKPredefinedTaskOptionExcludeDeviceMotion & options)) {
[recorderConfigurations addObject:[[ORKDeviceMotionRecorderConfiguration alloc] initWithIdentifier:ORKDeviceMotionRecorderIdentifier
frequency:100]];
}
ORKWalkingTaskStep *walkingStep = [[ORKWalkingTaskStep alloc] initWithIdentifier:ORKShortWalkReturnStepIdentifier];
walkingStep.numberOfStepsPerLeg = numberOfStepsPerLeg;
walkingStep.title = ORKLocalizedString(@"WALK_TASK_TITLE", nil);
walkingStep.text = [NSString localizedStringWithFormat:ORKLocalizedString(@"WALK_RETURN_INSTRUCTION_FORMAT", nil), (long long)numberOfStepsPerLeg];
walkingStep.spokenInstruction = walkingStep.text;
walkingStep.recorderConfigurations = recorderConfigurations;
walkingStep.shouldContinueOnFinish = YES;
walkingStep.shouldStartTimerAutomatically = YES;
walkingStep.optional = NO;
walkingStep.stepDuration = numberOfStepsPerLeg * 1.5; // fallback duration in case no step count
walkingStep.shouldVibrateOnStart = YES;
walkingStep.shouldPlaySoundOnStart = YES;
ORKStepArrayAddStep(steps, walkingStep);
}
if (restDuration > 0) {
NSMutableArray *recorderConfigurations = [NSMutableArray array];
if (!(ORKPredefinedTaskOptionExcludeAccelerometer & options)) {
[recorderConfigurations addObject:[[ORKAccelerometerRecorderConfiguration alloc] initWithIdentifier:ORKAccelerometerRecorderIdentifier
frequency:100]];
}
if (!(ORKPredefinedTaskOptionExcludeDeviceMotion & options)) {
[recorderConfigurations addObject:[[ORKDeviceMotionRecorderConfiguration alloc] initWithIdentifier:ORKDeviceMotionRecorderIdentifier
frequency:100]];
}
ORKFitnessStep *activeStep = [[ORKFitnessStep alloc] initWithIdentifier:ORKShortWalkRestStepIdentifier];
activeStep.recorderConfigurations = recorderConfigurations;
NSString *durationString = [formatter stringFromTimeInterval:restDuration];
activeStep.title = ORKLocalizedString(@"WALK_TASK_TITLE", nil);
activeStep.text = [NSString localizedStringWithFormat:ORKLocalizedString(@"WALK_STAND_INSTRUCTION_FORMAT", nil), durationString];
activeStep.spokenInstruction = [NSString localizedStringWithFormat:ORKLocalizedString(@"WALK_STAND_VOICE_INSTRUCTION_FORMAT", nil), durationString];
activeStep.shouldStartTimerAutomatically = YES;
activeStep.stepDuration = restDuration;
activeStep.shouldContinueOnFinish = YES;
activeStep.optional = NO;
activeStep.shouldVibrateOnStart = YES;
activeStep.shouldPlaySoundOnStart = YES;
activeStep.shouldVibrateOnFinish = YES;
activeStep.shouldPlaySoundOnFinish = YES;
ORKStepArrayAddStep(steps, activeStep);
}
}
if (!(options & ORKPredefinedTaskOptionExcludeConclusion)) {
ORKInstructionStep *step = [self makeCompletionStep];
ORKStepArrayAddStep(steps, step);
}
ORKOrderedTask *task = [[ORKOrderedTask alloc] initWithIdentifier:identifier steps:steps];
return task;
}
#pragma mark - walkBackAndForthTask
+ (ORKOrderedTask *)walkBackAndForthTaskWithIdentifier:(NSString *)identifier
intendedUseDescription:(NSString *)intendedUseDescription
walkDuration:(NSTimeInterval)walkDuration
restDuration:(NSTimeInterval)restDuration
options:(ORKPredefinedTaskOption)options {
NSDateComponentsFormatter *formatter = [self textTimeFormatter];
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
NSMutableArray *steps = [NSMutableArray array];
if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) {
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction0StepIdentifier];
step.title = ORKLocalizedString(@"WALK_TASK_TITLE", nil);
step.text = intendedUseDescription;
step.detailText = ORKLocalizedString(@"WALK_INTRO_TEXT", nil);
step.shouldTintImages = YES;
step.imageContentMode = UIViewContentModeCenter;
ORKStepArrayAddStep(steps, step);
}
{
ORKInstructionStep *step = [[ORKInstructionStep alloc] initWithIdentifier:ORKInstruction1StepIdentifier];
step.title = ORKLocalizedString(@"WALK_TASK_TITLE", nil);
step.text = ORKLocalizedString(@"WALK_INTRO_2_TEXT_BACK_AND_FORTH_INSTRUCTION", nil);
step.detailText = ORKLocalizedString(@"WALK_INTRO_2_DETAIL_BACK_AND_FORTH_INSTRUCTION", nil);
step.image = [UIImage imageNamed:@"pocket" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
step.imageContentMode = UIViewContentModeCenter;
step.shouldTintImages = YES;
ORKStepArrayAddStep(steps, step);
}
}
{
ORKCountdownStep *step = [[ORKCountdownStep alloc] initWithIdentifier:ORKCountdownStepIdentifier];
step.title = ORKLocalizedString(@"WALK_TASK_TITLE", nil);
step.stepDuration = 5.0;