annotate TimedSessionController.mm @ 49:178642d134a7 tip

xtra files
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 01 May 2013 17:34:33 +0100
parents 92dba082d957
children
rev   line source
rt300@29 1 //
rt300@29 2 // TimedSessionController.m
rt300@29 3 // sonicZoom
rt300@29 4 //
rt300@29 5 // Created by Robert Tubb on 18/02/2013.
rt300@29 6 //
rt300@29 7 //
rt300@29 8 #import "testApp.h"
rt300@29 9 #import "TimedSessionController.h"
rt300@29 10 @interface TimedSessionController()
rt300@29 11 // private stuff
rt300@29 12 @end
rt300@29 13
rt300@29 14 @implementation TimedSessionController
rt300@29 15
rt300@29 16 int orders[6][3] = {{0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0}};
rt300@29 17 int theOrder;
rt300@29 18 int scount;
rt300@29 19
rt300@29 20 NSArray *alertMessages = [NSArray arrayWithObjects:
rt300@33 21 @"Now try the sliders only.",
rt300@33 22 @"Now try the sliders and the Zoomer together.",
rt300@33 23 @"Now try the zoomer only.",
rt300@33 24 @"Now please take the questionnaire.",nil];
rt300@29 25
rt300@29 26 // nicer if it was initWithAppRef ?
rt300@29 27 - (void)setAppRef:(id)theOFApp{
rt300@29 28 self.theOFAppRef = theOFApp;
rt300@29 29 theOrder = arc4random() % 6;
rt300@29 30 scount = 0;
rt300@29 31 }
rt300@29 32 -(void)startTimer{
rt300@29 33 // SHOW FIRST PROMPT
rt300@29 34 NSString *themessage;
rt300@29 35 themessage = [alertMessages objectAtIndex:orders[theOrder][0]];
rt300@29 36 UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Thanks!"
rt300@33 37 message:[themessage stringByAppendingString:@" Press play to start sound."]
rt300@29 38 delegate:self
rt300@29 39 cancelButtonTitle:@"Continue"
rt300@29 40 otherButtonTitles:nil];
rt300@29 41 alert.alertViewStyle = UIAlertViewStyleDefault;
rt300@29 42 [alert show];
rt300@29 43 [alert release];
rt300@29 44
rt300@29 45 }
rt300@29 46 -(void)resetTime:(int)newTime{
rt300@29 47
rt300@29 48 }
rt300@29 49
rt300@29 50 // ALERT
rt300@29 51
rt300@29 52
rt300@29 53 -(void)showNextPrompt{
rt300@29 54 NSString *themessage;
rt300@29 55 scount++;
rt300@30 56 ((testApp *)self.theOFAppRef)->moveVel = TwoVector(); // stops movement
rt300@29 57 if(scount < 3){
rt300@29 58 themessage = [alertMessages objectAtIndex:orders[theOrder][scount] ];
rt300@29 59 }else{
rt300@29 60 themessage = [alertMessages objectAtIndex:3 ];
rt300@29 61 }
rt300@31 62 NSString * topmsg;
rt300@31 63 if(scount == 0){
rt300@31 64 topmsg = @"OK";
rt300@31 65 }else{
rt300@31 66 topmsg = @"Thanks!";
rt300@31 67 }
rt300@31 68 UIAlertView * alert = [[UIAlertView alloc] initWithTitle:topmsg
rt300@29 69 message:themessage
rt300@29 70 delegate:self
rt300@29 71 cancelButtonTitle:@"Continue"
rt300@29 72 otherButtonTitles:nil];
rt300@29 73 alert.alertViewStyle = UIAlertViewStyleDefault;
rt300@29 74 [alert show];
rt300@29 75 [alert release];
rt300@31 76
rt300@29 77
rt300@29 78 }
rt300@29 79
rt300@29 80 -(void)cancelTimers{
rt300@29 81 scount = 0;
rt300@29 82 if(self.theCurrentTimer){
rt300@29 83 [self.theCurrentTimer invalidate];
rt300@29 84 self.theCurrentTimer = nil;
rt300@29 85 }
rt300@29 86 }
rt300@29 87 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
rt300@29 88
rt300@29 89 NSLog(@"OK TO NEXT VIEW");
rt300@29 90
rt300@29 91 if(scount < 3){
rt300@29 92 NSInteger next = orders[theOrder][scount];
rt300@30 93
rt300@29 94 ((testApp *)self.theOFAppRef)->interfaceSelected(next);
rt300@29 95
rt300@29 96 self.theCurrentTimer = [NSTimer scheduledTimerWithTimeInterval:SECONDS_PER_INTERFACE target:self selector:@selector(showNextPrompt) userInfo:nil repeats:NO];
rt300@29 97
rt300@29 98 }else{
rt300@29 99 ((testApp *)self.theOFAppRef)->showQuestionnaire();
rt300@29 100 scount = 0; // incase we try again
rt300@29 101 self.theCurrentTimer = nil;
rt300@29 102 }
rt300@29 103
rt300@29 104 }
rt300@29 105
rt300@29 106
rt300@29 107 @end