You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/08/03 17:18:02 UTC

[4/9] ios commit: Update CDVSound and CDVNotification to new exec format.

Update CDVSound and CDVNotification to new exec format.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/b4c70c2e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/b4c70c2e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/b4c70c2e

Branch: refs/heads/master
Commit: b4c70c2e72bbe3d3a5056a682a79658b40f65610
Parents: 09a3a48
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Aug 3 11:07:02 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Aug 3 11:16:59 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVNotification.h |    6 +-
 CordovaLib/Classes/CDVNotification.m |   51 +++++++------
 CordovaLib/Classes/CDVSound.h        |   32 ++++----
 CordovaLib/Classes/CDVSound.m        |  114 +++++++++++++----------------
 4 files changed, 97 insertions(+), 106 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b4c70c2e/CordovaLib/Classes/CDVNotification.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVNotification.h b/CordovaLib/Classes/CDVNotification.h
index 24b2f8a..c6be279 100644
--- a/CordovaLib/Classes/CDVNotification.h
+++ b/CordovaLib/Classes/CDVNotification.h
@@ -26,9 +26,9 @@
 @interface CDVNotification : CDVPlugin <UIAlertViewDelegate>{
 }
 
-- (void)alert:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void)confirm:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void)vibrate:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)alert:(CDVInvokedUrlCommand*)command;
+- (void)confirm:(CDVInvokedUrlCommand*)command;
+- (void)vibrate:(CDVInvokedUrlCommand*)command;
 
 @end
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b4c70c2e/CordovaLib/Classes/CDVNotification.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVNotification.m b/CordovaLib/Classes/CDVNotification.m
index f0e5005..a1293f5 100644
--- a/CordovaLib/Classes/CDVNotification.m
+++ b/CordovaLib/Classes/CDVNotification.m
@@ -24,23 +24,8 @@
 
 @implementation CDVNotification
 
-
-- (void) alert:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:(NSString*)buttons callbackId:(NSString*)callbackId
 {
-    int argc = [arguments count];
-
-	NSString* callbackId = argc > 0? [arguments objectAtIndex:0] : nil;
-	NSString* message = argc > 1? [arguments objectAtIndex:1] : nil;
-	NSString* title   = argc > 2? [arguments objectAtIndex:2] : nil;
-	NSString* buttons = argc > 3? [arguments objectAtIndex:3] : nil;
-	
-	if (!title) {
-        title = NSLocalizedString(@"Alert", @"Alert");
-    }
-	if (!buttons) {
-        buttons = NSLocalizedString(@"OK", @"OK");
-    }
-	
 	CDVAlertView *alertView = [[CDVAlertView alloc]
 							  initWithTitle:title
 							  message:message 
@@ -61,14 +46,35 @@
 	[alertView show];
 }
 
-- (void) confirm:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) alert:(CDVInvokedUrlCommand*)command
+{
+	NSString* callbackId = command.callbackId;
+    NSArray* arguments = command.arguments;
+    int argc = [arguments count];
+
+	NSString* message = argc > 0 ? [arguments objectAtIndex:0] : nil;
+	NSString* title   = argc > 1 ? [arguments objectAtIndex:1] : nil;
+	NSString* buttons = argc > 2 ? [arguments objectAtIndex:2] : nil;
+
+	if (!title) {
+        title = NSLocalizedString(@"Alert", @"Alert");
+    }
+	if (!buttons) {
+        buttons = NSLocalizedString(@"OK", @"OK");
+    }
+		
+    [self showDialogWithMessage:message title:title buttons:buttons callbackId:callbackId];
+}
+
+- (void) confirm:(CDVInvokedUrlCommand*)command
 {   
+	NSString* callbackId = command.callbackId;
+    NSArray* arguments = command.arguments;
     int argc = [arguments count];
 
-	NSString* callbackId = argc > 0? [arguments objectAtIndex:0] : nil;
-	NSString* message = argc > 1? [arguments objectAtIndex:1] : nil;
-	NSString* title   = argc > 2? [arguments objectAtIndex:2] : nil;
-	NSString* buttons = argc > 3? [arguments objectAtIndex:3] : nil;
+	NSString* message = argc > 0 ? [arguments objectAtIndex:0] : nil;
+	NSString* title   = argc > 1 ? [arguments objectAtIndex:1] : nil;
+	NSString* buttons = argc > 2 ? [arguments objectAtIndex:2] : nil;
 	
 	if (!title) {
         title = NSLocalizedString(@"Confirm", @"Confirm");
@@ -77,8 +83,7 @@
         buttons = NSLocalizedString(@"OK,Cancel", @"OK,Cancel");
     }
     
-    NSMutableArray* newArguments = [NSMutableArray arrayWithObjects:callbackId, message, title, buttons, nil];
-    [self alert: newArguments withDict:options];
+    [self showDialogWithMessage:message title:title buttons:buttons callbackId:callbackId];
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b4c70c2e/CordovaLib/Classes/CDVSound.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVSound.h b/CordovaLib/Classes/CDVSound.h
index 868cdd2..78a7afa 100755
--- a/CordovaLib/Classes/CDVSound.h
+++ b/CordovaLib/Classes/CDVSound.h
@@ -92,21 +92,21 @@ typedef NSUInteger CDVMediaMsg;
 @property (nonatomic, strong) NSMutableDictionary* soundCache;
 @property (nonatomic, strong) AVAudioSession* avSession;
 //DEPRECATED
-- (void) play:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options __attribute__((deprecated));	  	
-- (void) pause:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options __attribute__((deprecated));
-- (void) stop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options __attribute__((deprecated));
+- (void) play:(CDVInvokedUrlCommand*)command __attribute__((deprecated));	  	
+- (void) pause:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
+- (void) stop:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
 // DEPRECATED
 
-- (void) startPlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) pausePlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) stopPlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) seekToAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) release:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) getCurrentPositionAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) startPlayingAudio:(CDVInvokedUrlCommand*)command;
+- (void) pausePlayingAudio:(CDVInvokedUrlCommand*)command;
+- (void) stopPlayingAudio:(CDVInvokedUrlCommand*)command;
+- (void) seekToAudio:(CDVInvokedUrlCommand*)command;
+- (void) release:(CDVInvokedUrlCommand*)command;
+- (void) getCurrentPositionAudio:(CDVInvokedUrlCommand*)command;
 
 // DEPRECATED
-- (void) getCurrentPosition:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options __attribute__((deprecated));
-- (void) prepare:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options __attribute__((deprecated));
+- (void) getCurrentPosition:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
+- (void) prepare:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
 // DEPRECATED
 
 - (BOOL) hasAudioSession;
@@ -117,13 +117,13 @@ typedef NSUInteger CDVMediaMsg;
 - (NSString*) createMediaErrorWithCode: (CDVMediaError) code message: (NSString*) message;
 
 // DEPRECATED
-- (void) startAudioRecord:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options __attribute__((deprecated));
-- (void) stopAudioRecord:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options __attribute__((deprecated));
+- (void) startAudioRecord:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
+- (void) stopAudioRecord:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
 // DEPRECATED
 
-- (void) startRecordingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) stopRecordingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) startRecordingAudio:(CDVInvokedUrlCommand*)command;
+- (void) stopRecordingAudio:(CDVInvokedUrlCommand*)command;
 
-- (void) setVolume:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) setVolume:(CDVInvokedUrlCommand*)command;
 
 @end

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b4c70c2e/CordovaLib/Classes/CDVSound.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVSound.m b/CordovaLib/Classes/CDVSound.m
index e931757..f0cec9c 100644
--- a/CordovaLib/Classes/CDVSound.m
+++ b/CordovaLib/Classes/CDVSound.m
@@ -144,17 +144,17 @@
     
 }
 // DEPRECATED
-- (void) play:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) play:(CDVInvokedUrlCommand*)command
 {
     NSLog(@"play is DEPRECATED!  Use startPlayingAudio.");
-    [self startPlayingAudio:arguments withDict:options];
+    [self startPlayingAudio:command];
 }
 
-- (void) create:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) create:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
-	NSString* mediaId = [arguments objectAtIndex:1];
-    NSString* resourcePath = [arguments objectAtIndex:2];
+	NSString* callbackId = command.callbackId;
+	NSString* mediaId = [command.arguments objectAtIndex:0];
+    NSString* resourcePath = [command.arguments objectAtIndex:1];
     
     CDVPluginResult* result;
     CDVAudioFile* audioFile = [self audioFileForResource:resourcePath withId: mediaId];
@@ -169,12 +169,12 @@
     }
 }
 
-- (void) setVolume:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) setVolume:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = [arguments objectAtIndex:0]; 
+    NSString* callbackId = command.callbackId; 
     #pragma unused(callbackId)
-	NSString* mediaId = [arguments objectAtIndex:1];
-    NSNumber* volume = [arguments objectAtIndex:2 withDefault:[NSNumber numberWithFloat:1.0]];
+	NSString* mediaId = [command.arguments objectAtIndex:0];
+    NSNumber* volume = [command.arguments objectAtIndex:1 withDefault:[NSNumber numberWithFloat:1.0]];
     
     CDVAudioFile* audioFile;
 	if ([self soundCache] == nil) {
@@ -188,12 +188,13 @@
     // don't care for any callbacks
 }
 
-- (void) startPlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) startPlayingAudio:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
+	NSString* callbackId = command.callbackId;
     #pragma unused(callbackId)
-	NSString* mediaId = [arguments objectAtIndex:1];
-    NSString* resourcePath = [arguments objectAtIndex:2];
+	NSString* mediaId = [command.arguments objectAtIndex:0];
+    NSString* resourcePath = [command.arguments objectAtIndex:1];
+    NSDictionary* options = [command.arguments objectAtIndex:2 withDefault:nil];
     
 	BOOL bError = NO;
 	NSString* jsString = nil;
@@ -317,13 +318,13 @@
 // Calls the success call back immediately as there is no mechanism to determine that the file is loaded
 // other than the return from prepareToPlay.  Thus, IMHO not really worth calling
 
-- (void) prepare:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) prepare:(CDVInvokedUrlCommand*)command
 {
     NSLog(@"prepare is DEPRECATED! Recoding will be prepared when startPlayingAudio is called");
     
-	NSString* callbackId = [arguments objectAtIndex:0]; 
+	NSString* callbackId = command.callbackId; 
     
-    NSString* mediaId = [arguments objectAtIndex:1];
+    NSString* mediaId = [command.arguments objectAtIndex:0];
     BOOL bError = NO;
     CDVMediaStates state = MEDIA_STARTING;
     NSString* jsString = nil;
@@ -331,7 +332,7 @@
 	CDVAudioFile* audioFile = [[self soundCache] objectForKey: mediaId];
     if (audioFile == nil) {
         // did not already exist, try to create
-        audioFile = [self audioFileForResource:[arguments objectAtIndex:2] withId: mediaId];
+        audioFile = [self audioFileForResource:[command.arguments objectAtIndex:1] withId: mediaId];
         if (audioFile == nil) {
             // create failed
             bError = YES;
@@ -361,17 +362,15 @@
 }
 
 // DEPRECATED
-- (void) stop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) stop:(CDVInvokedUrlCommand*)command
 {
     NSLog(@"stop is DEPRECATED!  Use stopPlayingAudio.");
-    [self stopPlayingAudio:arguments withDict:options];
+    [self stopPlayingAudio:command];
 }
 
-- (void) stopPlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) stopPlayingAudio:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
-#pragma unused(callbackId)
-	NSString* mediaId = [arguments objectAtIndex:1];
+	NSString* mediaId = [command.arguments objectAtIndex:0];
     CDVAudioFile* audioFile = [[self soundCache] objectForKey: mediaId];
 	NSString* jsString = nil;
 
@@ -386,17 +385,15 @@
     }
 }
 // DEPRECATED
-- (void) pause:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) pause:(CDVInvokedUrlCommand*)command
 {
     NSLog(@"pause is DEPRECATED!  Use pausePlayingAudio.");
-    [self pausePlayingAudio:arguments withDict:options];
+    [self pausePlayingAudio:command];
 }
 
-- (void) pausePlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) pausePlayingAudio:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
-#pragma unused(callbackId)
-	NSString* mediaId = [arguments objectAtIndex:1];
+	NSString* mediaId = [command.arguments objectAtIndex:0];
     NSString* jsString = nil;
 	CDVAudioFile* audioFile = [[self soundCache] objectForKey: mediaId];
 	
@@ -414,20 +411,17 @@
 
 
 }
-- (void) seekToAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) seekToAudio:(CDVInvokedUrlCommand*)command
 {
 	//args:
-	// 0 = callbackId
-    // 1 = Media id
-    // 2 = path to resource
-    // 3 = seek to location in milliseconds
+    // 0 = Media id
+    // 1 = path to resource
+    // 2 = seek to location in milliseconds
 	
-	NSString* callbackId = [arguments objectAtIndex:0];
-#pragma unused(callbackId)
-	NSString* mediaId = [arguments objectAtIndex:1];
+	NSString* mediaId = [command.arguments objectAtIndex:0];
 
 	CDVAudioFile* audioFile = [[self soundCache] objectForKey: mediaId];
-    double position = [[arguments objectAtIndex:2 ] doubleValue];
+    double position = [[command.arguments objectAtIndex:1] doubleValue];
 	
     if (audioFile != nil && audioFile.player != nil && position){
         double posInSeconds = position/1000;
@@ -442,11 +436,9 @@
     
 }
 
-- (void) release:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) release:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
-#pragma unused(callbackId)
-    NSString* mediaId = [arguments objectAtIndex:1];
+    NSString* mediaId = [command.arguments objectAtIndex:0];
 
 	if (mediaId != nil){
 		CDVAudioFile* audioFile = [[self soundCache] objectForKey: mediaId];
@@ -467,20 +459,16 @@
 	}
 }
 // DEPRECATED
-- (void) getCurrentPosition:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) getCurrentPosition:(CDVInvokedUrlCommand*)command
 {
     NSLog(@"getCurrentPosition is DEPRECATED!  Use getCurrentPositionAudio.");
-    [self getCurrentPositionAudio:arguments withDict:options];
+    [self getCurrentPositionAudio:command];
 }
 
-- (void) getCurrentPositionAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) getCurrentPositionAudio:(CDVInvokedUrlCommand*)command
 {
-	//args:
-	// 0 = callbackId
-    // 1 = Media id
-	
-	NSString* callbackId = [arguments objectAtIndex:0];
-	NSString* mediaId = [arguments objectAtIndex:1];
+	NSString* callbackId = command.callbackId;
+	NSString* mediaId = [command.arguments objectAtIndex:0];
 #pragma unused(mediaId)
 	CDVAudioFile* audioFile = [[self soundCache] objectForKey: mediaId];
     double position = -1;
@@ -496,19 +484,19 @@
 		
 }
 // DEPRECATED
-- (void) startAudioRecord:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) startAudioRecord:(CDVInvokedUrlCommand*)command
 {
     NSLog(@"startAudioRecord is DEPRECATED!  Use startRecordingAudio.");
-    [self startRecordingAudio:arguments withDict:options];
+    [self startRecordingAudio:command];
 }
 
-- (void) startRecordingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) startRecordingAudio:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
+	NSString* callbackId = command.callbackId;
 #pragma unused(callbackId)
 	
-	NSString* mediaId = [arguments objectAtIndex:1];
-	CDVAudioFile* audioFile = [self audioFileForResource:[arguments objectAtIndex:2] withId: mediaId];
+	NSString* mediaId = [command.arguments objectAtIndex:0];
+	CDVAudioFile* audioFile = [self audioFileForResource:[command.arguments objectAtIndex:1] withId: mediaId];
     NSString* jsString = nil;
     NSString* errorMsg = @"";
     
@@ -563,17 +551,15 @@
 	return;
 }
 // DEPRECATED
-- (void) stopAudioRecord:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) stopAudioRecord:(CDVInvokedUrlCommand*)command
 {
     NSLog(@"stopAudioRecord is DEPRECATED!  Use stopRecordingAudio.");
-    [self stopRecordingAudio:arguments withDict:options];
+    [self stopRecordingAudio:command];
 }
 
-- (void) stopRecordingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void) stopRecordingAudio:(CDVInvokedUrlCommand*)command
 {
-	NSString* callbackId = [arguments objectAtIndex:0];
-#pragma unused(callbackId)
-	NSString* mediaId = [arguments objectAtIndex:1];
+	NSString* mediaId = [command.arguments objectAtIndex:0];
 
 	CDVAudioFile* audioFile = [[self soundCache] objectForKey: mediaId];
     NSString* jsString = nil;