annotate QuestionnaireViewController.mm @ 29:fabb3a5cdfc9

Timed session improvements. Desperate pathetic attempts to send a simple HTTP POST.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 22 Feb 2013 17:41:38 +0000
parents e2c62db1e265
children 23ef179c3748
rev   line source
rt300@16 1 //
rt300@16 2 // QuestionnaireViewController.m
rt300@16 3 // oscSenderExample
rt300@16 4 //
rt300@16 5 // Created by Robert Tubb on 16/01/2013.
rt300@16 6 //
rt300@16 7 //
rt300@16 8
rt300@16 9 #import "QuestionnaireViewController.h"
rt300@16 10
rt300@16 11 #include "testApp.h"
rt300@21 12
rt300@21 13 #pragma mark -
rt300@21 14 #pragma mark QuestionnaireViewController
rt300@21 15
rt300@16 16 @interface QuestionnaireViewController ()
rt300@22 17 // the "model" is an array of questions
rt300@21 18 @property (strong, nonatomic) NSArray * questionArray;
rt300@21 19 @property (nonatomic) NSInteger currentQuestionIndex;
rt300@21 20 @property (nonatomic, assign) id theOFAppRef;
rt300@21 21
rt300@16 22 /*
rt300@16 23
rt300@16 24
rt300@16 25 */
rt300@16 26
rt300@16 27 @end
rt300@16 28
rt300@16 29 @implementation QuestionnaireViewController
rt300@16 30
rt300@21 31 @synthesize picker;
rt300@16 32 @synthesize nextButton = _nextButton;
rt300@22 33 @synthesize questionArray;
rt300@22 34
rt300@16 35
rt300@16 36 //----------------------------------------------------------------
rt300@16 37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
rt300@16 38 {
rt300@16 39 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
rt300@16 40 if (self) {
rt300@16 41 // Custom initialization
rt300@16 42
rt300@16 43 [self populateQuestionArray ];
rt300@16 44
rt300@16 45 }
rt300@16 46 return self;
rt300@16 47 }
rt300@16 48 - (void)setAppRef:(id)theOFApp{
rt300@16 49 self.theOFAppRef = theOFApp;
rt300@16 50
rt300@16 51 }
rt300@16 52 //----------------------------------------------------------------
rt300@16 53 - (void)viewDidLoad
rt300@16 54 {
rt300@16 55 [super viewDidLoad];
rt300@16 56 // Do any additional setup after loading the view from its nib.
rt300@16 57 self.currentQuestionIndex = 0;
rt300@21 58
rt300@22 59 // load question 1
rt300@22 60 [self loadQuestion:self.currentQuestionIndex];
rt300@21 61
rt300@22 62 self.previousButton.hidden = YES; // dont bother
rt300@28 63 self.commentText.hidden = YES;
rt300@28 64 self.finishButton.hidden = YES;
rt300@16 65 }
rt300@16 66 //----------------------------------------------------------------
rt300@16 67 - (void)didReceiveMemoryWarning
rt300@16 68 {
rt300@16 69 [super didReceiveMemoryWarning];
rt300@16 70 // Dispose of any resources that can be recreated.
rt300@16 71 }
rt300@16 72 //----------------------------------------------------------------
rt300@16 73 - (void)dealloc {
rt300@16 74
rt300@16 75 [_questionText release];
rt300@16 76 [_titleText release];
rt300@16 77 [_finishButton release];
rt300@16 78 [_nextButton release];
rt300@22 79 [_previousButton release];
rt300@28 80 [_commentText release];
rt300@16 81 [super dealloc];
rt300@16 82 }
rt300@16 83 //----------------------------------------------------------------
rt300@16 84 - (void)viewDidUnload {
rt300@16 85 [self setQuestionText:nil];
rt300@16 86 [self setTitleText:nil];
rt300@16 87 [self setFinishButton:nil];
rt300@16 88 [self setNextButton:nil];
rt300@22 89 [self setPreviousButton:nil];
rt300@28 90 [self setCommentText:nil];
rt300@16 91 [super viewDidUnload];
rt300@16 92 }
rt300@16 93 //----------------------------------------------------------------
rt300@22 94 -(IBAction)hide:(id)sender{
rt300@22 95 // called when finish button hit
rt300@22 96 // c++ call with NSArray argument??
rt300@22 97 // load answers into a c++ vector;
rt300@22 98 vector<int> answersArray;
rt300@22 99
rt300@22 100 Question *q;
rt300@16 101
rt300@22 102 for(int i=0;i<[questionArray count];i++){
rt300@22 103 q = [questionArray objectAtIndex:i];
rt300@22 104 answersArray.push_back(q.answer);
rt300@22 105
rt300@22 106 }
rt300@28 107 const char *userComments = [self.commentText.text cStringUsingEncoding: NSUTF8StringEncoding];
rt300@28 108 [self.commentText resignFirstResponder];
rt300@28 109
rt300@16 110 self.view.hidden = YES;
rt300@29 111 ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray, userComments);
rt300@29 112
rt300@16 113 }
rt300@28 114
rt300@16 115 //----------------------------------------------------------------
rt300@16 116 -(IBAction)show:(id)sender{
rt300@16 117 self.view.hidden = NO;
rt300@16 118 }
rt300@16 119 //----------------------------------------------------------------
rt300@16 120
rt300@16 121 - (IBAction)nextQuestionPressed:(id)sender {
rt300@16 122 // save answer ? no button did that hopefully
rt300@16 123
rt300@16 124 // if last question show thanks
rt300@16 125 // else go to next
rt300@16 126 self.currentQuestionIndex++;
rt300@16 127 if(self.currentQuestionIndex >= [self.questionArray count]){
rt300@16 128 [self showThanks];
rt300@16 129 }else{
rt300@16 130 [self loadQuestion:self.currentQuestionIndex];
rt300@16 131
rt300@16 132 }
rt300@16 133 }
rt300@16 134 //----------------------------------------------------------------
rt300@16 135 - (IBAction)previousQuestionPressed:(id)sender {
rt300@16 136 self.currentQuestionIndex--;
rt300@16 137 if(self.currentQuestionIndex < 0){
rt300@16 138 // nothing
rt300@16 139 self.currentQuestionIndex = 0;
rt300@16 140 }else{
rt300@16 141 [self loadQuestion:self.currentQuestionIndex];
rt300@16 142 }
rt300@16 143 }
rt300@16 144
rt300@16 145 //----------------------------------------------------------------
rt300@16 146
rt300@16 147 - (void)showThanks{
rt300@16 148 // hide next question button
rt300@16 149 self.nextButton.hidden = YES;
rt300@16 150 // hide selector
rt300@22 151 self.picker.hidden = YES;
rt300@22 152 self.previousButton.hidden = YES;
rt300@28 153 self.finishButton.hidden = NO;
rt300@16 154
rt300@16 155 self.titleText.text = @"Thank you!";
rt300@16 156
rt300@28 157 self.commentText.hidden = NO;
rt300@28 158
rt300@29 159 self.questionText.text = @"Thanks for helping science help you. Feel free to add further comments in the text box below, and then press 'finish' to go back and use the app, unhassled.";
rt300@16 160 }
rt300@16 161
rt300@16 162 //----------------------------------------------------------------
rt300@16 163 - (void)loadQuestion:(NSInteger)questionIndex {
rt300@16 164 // populate text fields with question
rt300@16 165 NSString *qtitle;
rt300@23 166 qtitle = [@"Question " stringByAppendingFormat:@"%d / %d",questionIndex+1, [questionArray count]];
rt300@16 167 self.titleText.text = qtitle;
rt300@16 168
rt300@22 169 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
rt300@16 170
rt300@22 171 self.questionText.text = curQ.questionText;
rt300@21 172
rt300@22 173
rt300@22 174 // refresh picker view content
rt300@21 175 [picker reloadComponent:0];
rt300@21 176
rt300@21 177
rt300@22 178 NSLog(@"Prev answer answerInt %d", curQ.answer);
rt300@27 179 [picker selectRow:2 inComponent:0 animated:YES];
rt300@22 180
rt300@16 181 }
rt300@16 182 //----------------------------------------------------------------
rt300@16 183 - (void)populateQuestionArray{
rt300@22 184
rt300@22 185 self.questionArray = [NSArray arrayWithObjects:
rt300@22 186 [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
rt300@27 187 [[Question alloc] initWithTextAndType:@"The best interface to get a feel for the possibilities of the synth was...":SLIDERS_ZOOMER],
rt300@27 188 [[Question alloc] initWithTextAndType:@"The best interface for discovering interesting sounds quickly was...":SLIDERS_ZOOMER],
rt300@27 189 [[Question alloc] initWithTextAndType:@"The best interface for fine tuning a sound was...":SLIDERS_ZOOMER],
rt300@22 190 [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
rt300@22 191 [[Question alloc] initWithTextAndType:@"The interface that felt more familiar was:":SLIDERS_ZOOMER],
rt300@27 192 [[Question alloc] initWithTextAndType:@"Scrolling a greater distance on the grid seemed to correspond to larger difference in the sound.":AGREE_DISAGREE],
rt300@27 193 [[Question alloc] initWithTextAndType:@"The interface that I felt more in control using was...":SLIDERS_ZOOMER],
rt300@27 194 [[Question alloc] initWithTextAndType:@"The ability to see other presets laid on the grid was useful.":AGREE_DISAGREE], // ????????
rt300@27 195 [[Question alloc] initWithTextAndType:@"The interface that felt more creative was...":SLIDERS_ZOOMER],
rt300@27 196 [[Question alloc] initWithTextAndType:@"The range of sounds was too limited/poor quality to be able to judge the eventual usefulness of the interface.":AGREE_DISAGREE],
rt300@27 197 [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was...":SLIDERS_ZOOMER],
rt300@27 198 [[Question alloc] initWithTextAndType:@"The interface better for performing live would be...":SLIDERS_ZOOMER],
rt300@22 199 [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
rt300@27 200 [[Question alloc] initWithTextAndType:@"The interface better for creating a specific sound I had in mind would be...":SLIDERS_ZOOMER], // not instructed ?????
rt300@27 201
rt300@22 202 [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
rt300@27 203 [[Question alloc] initWithTextAndType:@"Overall, the interface I preferred using was...":SLIDERS_ZOOMER], // ??????
rt300@16 204 nil];
rt300@22 205
rt300@16 206 }
rt300@16 207
rt300@21 208 //----------------------------------------------------------------
rt300@21 209 #pragma mark -
rt300@21 210 #pragma mark PickerView DataSource
rt300@16 211
rt300@21 212 - (NSInteger)numberOfComponentsInPickerView:
rt300@21 213 (UIPickerView *)pickerView
rt300@21 214 {
rt300@21 215 return 1;
rt300@21 216 }
rt300@22 217 //----------------------------------------------------------------
rt300@21 218 - (NSInteger)pickerView:(UIPickerView *)pickerView
rt300@21 219 numberOfRowsInComponent:(NSInteger)component
rt300@21 220 {
rt300@27 221
rt300@27 222 return NUM_CHOICES; // always 6
rt300@21 223 }
rt300@22 224 //----------------------------------------------------------------
rt300@21 225 - (NSString *)pickerView:(UIPickerView *)pickerView
rt300@21 226 titleForRow:(NSInteger)row
rt300@21 227 forComponent:(NSInteger)component
rt300@21 228 {
rt300@22 229 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
rt300@22 230
rt300@22 231 // get array of answers from Question class
rt300@22 232 NSArray * answers = [Question answersWithType:curQ.questionType];
rt300@22 233 return [answers objectAtIndex:row];
rt300@22 234
rt300@21 235 }
rt300@22 236 //----------------------------------------------------------------
rt300@21 237 #pragma mark -
rt300@21 238 #pragma mark PickerView Delegate
rt300@21 239 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
rt300@21 240 inComponent:(NSInteger)component
rt300@21 241 {
rt300@22 242 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
rt300@21 243 // set question answerArray
rt300@22 244 curQ.answer = row;
rt300@21 245
rt300@21 246 // chek wot we just rote
rt300@21 247
rt300@22 248 NSLog(@"Answer: %d",curQ.answer);
rt300@22 249
rt300@21 250 }
rt300@28 251 //----------------------------------------------------------------
rt300@28 252 #pragma mark UITextViewDelegate functions
rt300@28 253 /*
rt300@28 254 This answer was useful to me, but I was also looking for the callback function from the "Go" button, which I found is:
rt300@28 255 - (BOOL) textFieldShouldReturn:(UITextField *)textField { // Customer code return YES; }
rt300@28 256
rt300@28 257 You will need to send the UITextField delegate to your view controller for that to work.
rt300@28 258
rt300@28 259 */
rt300@28 260 - (BOOL) textFieldShouldReturn:(UITextField *)textField {
rt300@28 261 // Customer code
rt300@28 262 NSLog(@"RETURN DELEGATE");
rt300@28 263 [self hide:self ];
rt300@28 264 return NO;
rt300@28 265 }
rt300@21 266 @end // end implementation
rt300@21 267 //----------------------------------------------------------------
rt300@21 268 //----------------------------------------------------------------