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@31
|
65 self.nextButton.hidden = YES;
|
rt300@31
|
66
|
rt300@31
|
67 self.lickertOptions.hidden = NO;
|
rt300@31
|
68 self.interfacePreferenceOptions.hidden = YES;
|
rt300@16
|
69 }
|
rt300@16
|
70 //----------------------------------------------------------------
|
rt300@16
|
71 - (void)didReceiveMemoryWarning
|
rt300@16
|
72 {
|
rt300@16
|
73 [super didReceiveMemoryWarning];
|
rt300@16
|
74 // Dispose of any resources that can be recreated.
|
rt300@16
|
75 }
|
rt300@16
|
76 //----------------------------------------------------------------
|
rt300@16
|
77 - (void)dealloc {
|
rt300@16
|
78
|
rt300@16
|
79 [_questionText release];
|
rt300@16
|
80 [_titleText release];
|
rt300@16
|
81 [_finishButton release];
|
rt300@16
|
82 [_nextButton release];
|
rt300@22
|
83 [_previousButton release];
|
rt300@28
|
84 [_commentText release];
|
rt300@31
|
85 [_numberChooser release];
|
rt300@31
|
86 [_interfacePreferenceOptions release];
|
rt300@31
|
87 [_lickertOptions release];
|
rt300@31
|
88 [_pleaseAnswer release];
|
rt300@16
|
89 [super dealloc];
|
rt300@16
|
90 }
|
rt300@16
|
91 //----------------------------------------------------------------
|
rt300@16
|
92 - (void)viewDidUnload {
|
rt300@16
|
93 [self setQuestionText:nil];
|
rt300@16
|
94 [self setTitleText:nil];
|
rt300@16
|
95 [self setFinishButton:nil];
|
rt300@16
|
96 [self setNextButton:nil];
|
rt300@22
|
97 [self setPreviousButton:nil];
|
rt300@28
|
98 [self setCommentText:nil];
|
rt300@31
|
99 [self setNumberChooser:nil];
|
rt300@31
|
100 [self setInterfacePreferenceOptions:nil];
|
rt300@31
|
101 [self setLickertOptions:nil];
|
rt300@31
|
102 [self setPleaseAnswer:nil];
|
rt300@16
|
103 [super viewDidUnload];
|
rt300@16
|
104 }
|
rt300@16
|
105 //----------------------------------------------------------------
|
rt300@22
|
106 -(IBAction)hide:(id)sender{
|
rt300@22
|
107 // called when finish button hit
|
rt300@22
|
108 // c++ call with NSArray argument??
|
rt300@22
|
109 // load answers into a c++ vector;
|
rt300@22
|
110 vector<int> answersArray;
|
rt300@22
|
111
|
rt300@22
|
112 Question *q;
|
rt300@16
|
113
|
rt300@22
|
114 for(int i=0;i<[questionArray count];i++){
|
rt300@22
|
115 q = [questionArray objectAtIndex:i];
|
rt300@22
|
116 answersArray.push_back(q.answer);
|
rt300@22
|
117
|
rt300@22
|
118 }
|
rt300@28
|
119 const char *userComments = [self.commentText.text cStringUsingEncoding: NSUTF8StringEncoding];
|
rt300@28
|
120 [self.commentText resignFirstResponder];
|
rt300@28
|
121
|
rt300@16
|
122 self.view.hidden = YES;
|
rt300@29
|
123 ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray, userComments);
|
rt300@29
|
124
|
rt300@16
|
125 }
|
rt300@28
|
126
|
rt300@16
|
127 //----------------------------------------------------------------
|
rt300@16
|
128 -(IBAction)show:(id)sender{
|
rt300@16
|
129 self.view.hidden = NO;
|
rt300@16
|
130 }
|
rt300@16
|
131 //----------------------------------------------------------------
|
rt300@16
|
132
|
rt300@16
|
133 - (IBAction)nextQuestionPressed:(id)sender {
|
rt300@16
|
134 // save answer ? no button did that hopefully
|
rt300@16
|
135
|
rt300@16
|
136 // if last question show thanks
|
rt300@16
|
137 // else go to next
|
rt300@16
|
138 self.currentQuestionIndex++;
|
rt300@16
|
139 if(self.currentQuestionIndex >= [self.questionArray count]){
|
rt300@16
|
140 [self showThanks];
|
rt300@16
|
141 }else{
|
rt300@16
|
142 [self loadQuestion:self.currentQuestionIndex];
|
rt300@16
|
143
|
rt300@16
|
144 }
|
rt300@16
|
145 }
|
rt300@16
|
146 //----------------------------------------------------------------
|
rt300@16
|
147 - (IBAction)previousQuestionPressed:(id)sender {
|
rt300@16
|
148 self.currentQuestionIndex--;
|
rt300@16
|
149 if(self.currentQuestionIndex < 0){
|
rt300@16
|
150 // nothing
|
rt300@16
|
151 self.currentQuestionIndex = 0;
|
rt300@16
|
152 }else{
|
rt300@16
|
153 [self loadQuestion:self.currentQuestionIndex];
|
rt300@16
|
154 }
|
rt300@16
|
155 }
|
rt300@16
|
156
|
rt300@16
|
157 //----------------------------------------------------------------
|
rt300@16
|
158
|
rt300@16
|
159 - (void)showThanks{
|
rt300@16
|
160 // hide next question button
|
rt300@16
|
161 self.nextButton.hidden = YES;
|
rt300@16
|
162 // hide selector
|
rt300@22
|
163 self.picker.hidden = YES;
|
rt300@22
|
164 self.previousButton.hidden = YES;
|
rt300@28
|
165 self.finishButton.hidden = NO;
|
rt300@16
|
166
|
rt300@31
|
167 self.lickertOptions.hidden = YES;
|
rt300@31
|
168 self.interfacePreferenceOptions.hidden = YES;
|
rt300@31
|
169
|
rt300@16
|
170 self.titleText.text = @"Thank you!";
|
rt300@31
|
171 self.numberChooser.hidden = YES;
|
rt300@28
|
172 self.commentText.hidden = NO;
|
rt300@28
|
173
|
rt300@29
|
174 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
|
175 }
|
rt300@16
|
176
|
rt300@16
|
177 //----------------------------------------------------------------
|
rt300@16
|
178 - (void)loadQuestion:(NSInteger)questionIndex {
|
rt300@16
|
179 // populate text fields with question
|
rt300@16
|
180 NSString *qtitle;
|
rt300@23
|
181 qtitle = [@"Question " stringByAppendingFormat:@"%d / %d",questionIndex+1, [questionArray count]];
|
rt300@16
|
182 self.titleText.text = qtitle;
|
rt300@16
|
183
|
rt300@22
|
184 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@16
|
185
|
rt300@22
|
186 self.questionText.text = curQ.questionText;
|
rt300@21
|
187
|
rt300@22
|
188
|
rt300@22
|
189 // refresh picker view content
|
rt300@21
|
190 [picker reloadComponent:0];
|
rt300@21
|
191
|
rt300@31
|
192 // show correct option number labels
|
rt300@31
|
193 if(curQ.questionType == AGREE_DISAGREE){
|
rt300@31
|
194 self.lickertOptions.hidden = NO;
|
rt300@31
|
195 self.interfacePreferenceOptions.hidden = YES;
|
rt300@31
|
196 }else if(curQ.questionType == SLIDERS_ZOOMER){
|
rt300@31
|
197 self.lickertOptions.hidden = YES;
|
rt300@31
|
198 self.interfacePreferenceOptions.hidden = NO;
|
rt300@31
|
199 }
|
rt300@31
|
200
|
rt300@31
|
201 //NSLog(@"Prev answer answerInt %d", curQ.answer);
|
rt300@27
|
202 [picker selectRow:2 inComponent:0 animated:YES];
|
rt300@22
|
203
|
rt300@16
|
204 }
|
rt300@16
|
205 //----------------------------------------------------------------
|
rt300@16
|
206 - (void)populateQuestionArray{
|
rt300@22
|
207
|
rt300@22
|
208 self.questionArray = [NSArray arrayWithObjects:
|
rt300@22
|
209 [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
|
rt300@27
|
210 [[Question alloc] initWithTextAndType:@"The best interface to get a feel for the possibilities of the synth was...":SLIDERS_ZOOMER],
|
rt300@27
|
211 [[Question alloc] initWithTextAndType:@"The best interface for discovering interesting sounds quickly was...":SLIDERS_ZOOMER],
|
rt300@27
|
212 [[Question alloc] initWithTextAndType:@"The best interface for fine tuning a sound was...":SLIDERS_ZOOMER],
|
rt300@22
|
213 [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
|
rt300@22
|
214 [[Question alloc] initWithTextAndType:@"The interface that felt more familiar was:":SLIDERS_ZOOMER],
|
rt300@27
|
215 [[Question alloc] initWithTextAndType:@"Scrolling a greater distance on the grid seemed to correspond to larger difference in the sound.":AGREE_DISAGREE],
|
rt300@27
|
216 [[Question alloc] initWithTextAndType:@"The interface that I felt more in control using was...":SLIDERS_ZOOMER],
|
rt300@27
|
217 [[Question alloc] initWithTextAndType:@"The ability to see other presets laid on the grid was useful.":AGREE_DISAGREE], // ????????
|
rt300@27
|
218 [[Question alloc] initWithTextAndType:@"The interface that felt more creative was...":SLIDERS_ZOOMER],
|
rt300@27
|
219 [[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
|
220 [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was...":SLIDERS_ZOOMER],
|
rt300@27
|
221 [[Question alloc] initWithTextAndType:@"The interface better for performing live would be...":SLIDERS_ZOOMER],
|
rt300@22
|
222 [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
|
rt300@27
|
223 [[Question alloc] initWithTextAndType:@"The interface better for creating a specific sound I had in mind would be...":SLIDERS_ZOOMER], // not instructed ?????
|
rt300@27
|
224
|
rt300@22
|
225 [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
|
rt300@27
|
226 [[Question alloc] initWithTextAndType:@"Overall, the interface I preferred using was...":SLIDERS_ZOOMER], // ??????
|
rt300@16
|
227 nil];
|
rt300@22
|
228
|
rt300@16
|
229 }
|
rt300@16
|
230
|
rt300@21
|
231 //----------------------------------------------------------------
|
rt300@21
|
232 #pragma mark -
|
rt300@21
|
233 #pragma mark PickerView DataSource
|
rt300@16
|
234
|
rt300@21
|
235 - (NSInteger)numberOfComponentsInPickerView:
|
rt300@21
|
236 (UIPickerView *)pickerView
|
rt300@21
|
237 {
|
rt300@21
|
238 return 1;
|
rt300@21
|
239 }
|
rt300@22
|
240 //----------------------------------------------------------------
|
rt300@21
|
241 - (NSInteger)pickerView:(UIPickerView *)pickerView
|
rt300@21
|
242 numberOfRowsInComponent:(NSInteger)component
|
rt300@21
|
243 {
|
rt300@27
|
244
|
rt300@27
|
245 return NUM_CHOICES; // always 6
|
rt300@21
|
246 }
|
rt300@22
|
247 //----------------------------------------------------------------
|
rt300@21
|
248 - (NSString *)pickerView:(UIPickerView *)pickerView
|
rt300@21
|
249 titleForRow:(NSInteger)row
|
rt300@21
|
250 forComponent:(NSInteger)component
|
rt300@21
|
251 {
|
rt300@22
|
252 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@22
|
253
|
rt300@22
|
254 // get array of answers from Question class
|
rt300@22
|
255 NSArray * answers = [Question answersWithType:curQ.questionType];
|
rt300@22
|
256 return [answers objectAtIndex:row];
|
rt300@22
|
257
|
rt300@21
|
258 }
|
rt300@22
|
259 //----------------------------------------------------------------
|
rt300@21
|
260 #pragma mark -
|
rt300@21
|
261 #pragma mark PickerView Delegate
|
rt300@21
|
262 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
|
rt300@21
|
263 inComponent:(NSInteger)component
|
rt300@21
|
264 {
|
rt300@22
|
265 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@21
|
266 // set question answerArray
|
rt300@22
|
267 curQ.answer = row;
|
rt300@21
|
268
|
rt300@21
|
269 // chek wot we just rote
|
rt300@21
|
270
|
rt300@22
|
271 NSLog(@"Answer: %d",curQ.answer);
|
rt300@22
|
272
|
rt300@21
|
273 }
|
rt300@28
|
274 //----------------------------------------------------------------
|
rt300@28
|
275 #pragma mark UITextViewDelegate functions
|
rt300@28
|
276 /*
|
rt300@28
|
277 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
|
278 - (BOOL) textFieldShouldReturn:(UITextField *)textField { // Customer code return YES; }
|
rt300@28
|
279
|
rt300@28
|
280 You will need to send the UITextField delegate to your view controller for that to work.
|
rt300@28
|
281
|
rt300@28
|
282 */
|
rt300@28
|
283 - (BOOL) textFieldShouldReturn:(UITextField *)textField {
|
rt300@28
|
284 // Customer code
|
rt300@28
|
285 NSLog(@"RETURN DELEGATE");
|
rt300@28
|
286 [self hide:self ];
|
rt300@28
|
287 return NO;
|
rt300@28
|
288 }
|
rt300@31
|
289 - (IBAction)answerChosen:(id)sender {
|
rt300@31
|
290 self.pleaseAnswer.hidden = YES;
|
rt300@31
|
291 UISegmentedControl *seg = (UISegmentedControl *)sender;
|
rt300@31
|
292 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@31
|
293 // set question answerArray
|
rt300@31
|
294 curQ.answer = seg.selectedSegmentIndex;
|
rt300@31
|
295
|
rt300@31
|
296 // chek wot we just rote
|
rt300@31
|
297
|
rt300@31
|
298 NSLog(@"Answer: %d",curQ.answer);
|
rt300@31
|
299
|
rt300@31
|
300 // automatically go next q
|
rt300@31
|
301 self.currentQuestionIndex++;
|
rt300@31
|
302 if(self.currentQuestionIndex >= [self.questionArray count]){
|
rt300@31
|
303 [self showThanks];
|
rt300@31
|
304 }else{
|
rt300@31
|
305 [self loadQuestion:self.currentQuestionIndex];
|
rt300@31
|
306
|
rt300@31
|
307 }
|
rt300@31
|
308
|
rt300@31
|
309 }
|
rt300@21
|
310 @end // end implementation
|
rt300@21
|
311 //----------------------------------------------------------------
|
rt300@21
|
312 //----------------------------------------------------------------
|