diff iViewController.mm @ 9:346807b47860

added extra files: JSON stuff and ofxPD altered example code.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 16 Jan 2013 13:44:07 +0000
parents
children 6a9191f5b269
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iViewController.mm	Wed Jan 16 13:44:07 2013 +0000
@@ -0,0 +1,104 @@
+//
+//  iViewController.m
+//  oscSenderExample
+//
+//  Created by Robert Tubb on 07/01/2013.
+//
+//
+
+#import "iViewController.h"
+
+extern EventLogger eventLogger;
+extern PresetManager presetManager;
+@implementation IViewController
+
+-(void)showUserNamePrompt{
+
+    
+    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!"
+                                                     message:@"Please enter your name:"
+                                                    delegate:self
+                                                    cancelButtonTitle:@"Continue"
+                                                    otherButtonTitles:nil];
+    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
+    UITextField * alertTextField = [alert textFieldAtIndex:0];
+    alertTextField.keyboardType = UIKeyboardTypeDefault;
+    alertTextField.placeholder = @"Username";
+    [alert show];
+    [alert release];
+
+    
+}
+
+
+- (void)showPresetNamePrompt{
+    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Save"
+                                                     message:@"Enter preset name:"
+                                                    delegate:self
+                                           cancelButtonTitle:@"Cancel"
+                                           otherButtonTitles:@"Enter",nil];
+    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
+    UITextField * alertTextField = [alert textFieldAtIndex:0];
+    alertTextField.keyboardType = UIKeyboardTypeDefault;
+    alertTextField.placeholder = @"Preset Name";
+    [alert show];
+    [alert release];
+}
+
+- (void)showQuestionPrompt:(NSString *)question{
+    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Save"
+                                                     message:@"Are you mad?"
+                                                    delegate:self
+                                           cancelButtonTitle:@"Next"
+                                           otherButtonTitles:@"Hell No",nil];
+    alert.alertViewStyle = UIAlertViewStyleDefault;
+    [alert show];
+    [alert release];
+}
+
+// shheet - only one delegate fnc
+// we're actually overriding alertViews function here?
+
+- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
+    NSLog(@"Button: %d",buttonIndex);
+    
+    NSLog(@"Dialog title: %@",[alertView title]); // check right title!
+    if([[alertView title] isEqualToString:@"Hello!"]){
+        NSLog(@"Entered: %@",[[alertView textFieldAtIndex:0] text]);
+        NSString *userName = [[alertView textFieldAtIndex:0] text];
+        if ([userName isEqualToString:@""]){
+            [self showUserNamePrompt:43];
+            return;
+        }
+        eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]);
+    } else if ([[alertView title] isEqualToString:@"Save"]) {
+        NSLog(@"Preset save ");
+        if(buttonIndex == 0){
+            // cancel
+            NSLog(@"preset save was cancelled");
+        }else{
+            // save it
+            presetManager.addPreset([[[alertView textFieldAtIndex:0] text] cStringUsingEncoding:NSASCIIStringEncoding]);
+        }
+    } else {
+        NSLog(@"Dialog title didn't match anything");
+    }
+
+}
+
+- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
+{
+    UITextField *textField = [alertView textFieldAtIndex:0];
+    if ([textField.text length] == 0)
+    {
+        return NO;
+    }
+    return YES;
+}
+
+
+@end
+
+
+// global. again.
+IViewController *iViewController = [[IViewController alloc] init];