cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From becka...@apache.org
Subject ios commit: [CB-2411] Added camera popover repositioning.
Date Thu, 21 Feb 2013 18:49:25 GMT
Updated Branches:
  refs/heads/next b70634146 -> dfc6a993a


[CB-2411] Added camera popover repositioning.

Also prevented the possibility of having multiple popovers from multiple
calls to Camera.getPicture.


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

Branch: refs/heads/next
Commit: dfc6a993a99a701cc153178c6826a77727aca4df
Parents: b706341
Author: Max Woghiren <max.woghiren@gmail.com>
Authored: Fri Feb 15 12:53:37 2013 -0500
Committer: Becky Gibson <becka11y@apache.org>
Committed: Thu Feb 21 10:59:17 2013 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.h |    1 +
 CordovaLib/Classes/CDVCamera.m |   62 +++++++++++++++++++++++------------
 2 files changed, 42 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/dfc6a993/CordovaLib/Classes/CDVCamera.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.h b/CordovaLib/Classes/CDVCamera.h
index e32da7d..204d25f 100644
--- a/CordovaLib/Classes/CDVCamera.h
+++ b/CordovaLib/Classes/CDVCamera.h
@@ -80,6 +80,7 @@ typedef NSUInteger CDVMediaType;
 - (void)takePicture:(CDVInvokedUrlCommand*)command;
 - (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url;
 - (void)cleanup:(CDVInvokedUrlCommand*)command;
+- (void)repositionPopover:(CDVInvokedUrlCommand*)command;
 
 - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;
 - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image
editingInfo:(NSDictionary*)editingInfo;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/dfc6a993/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index 22aca98..aabe844 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -93,6 +93,13 @@ static NSSet* org_apache_cordova_validArrowDirections;
         targetSize = CGSizeMake([targetWidth floatValue], [targetHeight floatValue]);
     }
 
+    // If a popover is already open, close it; we only want one at a time.
+    if (([[self pickerController] popoverController] != nil) && [[[self pickerController]
popoverController] isPopoverVisible]) {
+        [[[self pickerController] popoverController] dismissPopoverAnimated:YES];
+        [[[self pickerController] popoverController] setDelegate:nil];
+        [[self pickerController] setPopoverController:nil];
+    }
+
     CDVCameraPicker* cameraPicker = [[CDVCameraPicker alloc] init];
     self.pickerController = cameraPicker;
 
@@ -128,28 +135,8 @@ static NSSet* org_apache_cordova_validArrowDirections;
         if (cameraPicker.popoverController == nil) {
             cameraPicker.popoverController = [[NSClassFromString (@"UIPopoverController")alloc]
initWithContentViewController:cameraPicker];
         }
-        int x = 0;
-        int y = 32;
-        int width = 320;
-        int height = 480;
-        UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirectionAny;
         NSDictionary* options = [command.arguments objectAtIndex:10 withDefault:nil];
-        if (options) {
-            x = [options integerValueForKey:@"x" defaultValue:0];
-            y = [options integerValueForKey:@"y" defaultValue:32];
-            width = [options integerValueForKey:@"width" defaultValue:320];
-            height = [options integerValueForKey:@"height" defaultValue:480];
-            arrowDirection = [options integerValueForKey:@"arrowDir" defaultValue:UIPopoverArrowDirectionAny];
-            if (![org_apache_cordova_validArrowDirections containsObject:[NSNumber numberWithInt:arrowDirection]])
{
-                arrowDirection = UIPopoverArrowDirectionAny;
-            }
-        }
-
-        cameraPicker.popoverController.delegate = self;
-        [cameraPicker.popoverController presentPopoverFromRect:CGRectMake(x, y, width, height)
-                                                        inView:[self.webView superview]
-                                      permittedArrowDirections:arrowDirection
-                                                      animated:YES];
+        [self displayPopover:options];
     } else {
         if ([self.viewController respondsToSelector:@selector(presentViewController:::)])
{
             [self.viewController presentViewController:cameraPicker animated:YES completion:nil];
@@ -160,6 +147,39 @@ static NSSet* org_apache_cordova_validArrowDirections;
     self.hasPendingOperation = YES;
 }
 
+- (void)repositionPopover:(CDVInvokedUrlCommand*)command
+{
+    NSDictionary* options = [command.arguments objectAtIndex:0 withDefault:nil];
+
+    [self displayPopover:options];
+}
+
+- (void)displayPopover:(NSDictionary*)options
+{
+    int x = 0;
+    int y = 32;
+    int width = 320;
+    int height = 480;
+    UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirectionAny;
+
+    if (options) {
+        x = [options integerValueForKey:@"x" defaultValue:0];
+        y = [options integerValueForKey:@"y" defaultValue:32];
+        width = [options integerValueForKey:@"width" defaultValue:320];
+        height = [options integerValueForKey:@"height" defaultValue:480];
+        arrowDirection = [options integerValueForKey:@"arrowDir" defaultValue:UIPopoverArrowDirectionAny];
+        if (![org_apache_cordova_validArrowDirections containsObject:[NSNumber numberWithInt:arrowDirection]])
{
+            arrowDirection = UIPopoverArrowDirectionAny;
+        }
+    }
+
+    [[[self pickerController] popoverController] setDelegate:self];
+    [[[self pickerController] popoverController] presentPopoverFromRect:CGRectMake(x, y,
width, height)
+                                                                 inView:[self.webView superview]
+                                               permittedArrowDirections:arrowDirection
+                                                               animated:YES];
+}
+
 - (void)cleanup:(CDVInvokedUrlCommand*)command
 {
     // empty the tmp directory


Mime
View raw message