diff UsernameAlertViewController.mm @ 0:a223551fdc1f

First commit - copy from tweakathlon.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 10 Oct 2014 11:46:42 +0100
parents
children 851833072cf1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UsernameAlertViewController.mm	Fri Oct 10 11:46:42 2014 +0100
@@ -0,0 +1,87 @@
+//
+//  iViewController.m
+//  oscSenderExample
+//
+//  Created by Robert Tubb on 07/01/2013.
+//
+//
+#include "testApp.h"
+#include "eventLogger.h"
+
+#import "usernameAlertViewController.h"
+
+
+extern EventLogger eventLogger;
+
+@implementation UsernameAlertViewController
+
+-(void)showUserNamePrompt{
+
+    
+    self.alert = [[UIAlertView alloc] initWithTitle:@"Hello!"
+                                                     message:@"Please enter your name:"
+                                                    delegate:self
+                                                    cancelButtonTitle:@"Continue"
+                                                    otherButtonTitles:nil];
+    self.alert.alertViewStyle = UIAlertViewStylePlainTextInput;
+    UITextField * alertTextField = [self.alert textFieldAtIndex:0];
+    [alertTextField setDelegate:self];
+    alertTextField.keyboardType = UIKeyboardTypeDefault;
+    alertTextField.placeholder = @"Username";
+    [self.alert show];
+    //[self.alert release];
+
+    
+}
+-(void)setAppRef:(id)theAppRef{
+    self.theOFAppRef = theAppRef;
+}
+
+- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
+    
+    NSLog(@"Entered: %@",[[alertView textFieldAtIndex:0] text]);
+    NSString *userName = [[alertView textFieldAtIndex:0] text];
+    if ([userName isEqualToString:@""]){
+        [self showUserNamePrompt];
+        return;
+    }
+    eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]);
+    
+    // call some start func
+    ((testApp *)self.theOFAppRef)->startTheTests();
+    // rememebr to change return func too!
+
+}
+
+-(BOOL)textFieldShouldReturn:(UITextField *)textField{
+
+    NSLog(@"Entered: %@",[[self.alert textFieldAtIndex:0] text]);
+    NSString *userName = [[self.alert textFieldAtIndex:0] text];
+    if ([userName isEqualToString:@""]){
+        [self showUserNamePrompt];
+        
+    }else{
+        eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]);
+        ((testApp *)self.theOFAppRef)->startTheTests();
+        
+    }
+    [self.alert dismissWithClickedButtonIndex:self.alert.firstOtherButtonIndex animated:YES];
+    return YES;
+}
+
+- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
+{
+    UITextField *textField = [alertView textFieldAtIndex:0];
+    if ([textField.text length] == 0)
+    {
+        return NO;
+    }
+    return YES;
+}
+
+
+@end
+
+
+// global. again.
+