motion/core/device/ios/camera.rb in bubble-wrap-1.4.0 vs motion/core/device/ios/camera.rb in bubble-wrap-1.5.0.rc1

- old
+ new

@@ -32,14 +32,26 @@ def self.rear return nil if not UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDeviceRear) @rear ||= Camera.new(:rear) end + def self.available? + UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera) + end + # For uploading photos from the library. - def self.any - @any ||= Camera.new + class << self + def any + @any ||= Camera.new + end + alias_method "photo_library", "any" end + + def popover_from(view) + @popover_in_view = view + self + end def initialize(location = :none) self.location = location end @@ -76,10 +88,11 @@ # BW::Camera.picture(source_type: :photo_library, media_types: [:image]) do |result| # image_view = UIImageView.alloc.initWithImage(result[:original_image]) # end def picture(options = {}, presenting_controller = nil, &block) @callback = block + @callback.weak! if @callback && BubbleWrap.use_weak_callbacks? @options = options @options[:allows_editing] = false if not @options.has_key? :allows_editing @options[:animated] = true if not @options.has_key? :animated @options[:media_types] = [:image] if not @options.has_key? :media_types @@ -122,12 +135,24 @@ self.picker.cameraDevice = camera_device end presenting_controller ||= App.window.rootViewController.presentedViewController # May be nil, but handles use case of container views presenting_controller ||= App.window.rootViewController - presenting_controller.presentViewController(self.picker, animated:@options[:animated], completion: lambda {}) + + # use popover for iPad (ignore on iPhone) + if Device.ipad? and source_type==UIImagePickerControllerSourceTypePhotoLibrary and @popover_in_view + @popover = UIPopoverController.alloc.initWithContentViewController(picker) + @popover.presentPopoverFromRect(@popover_in_view.bounds, inView:@popover_in_view, permittedArrowDirections:UIPopoverArrowDirectionAny, animated:@options[:animated]) + else + presenting_controller.presentViewController(self.picker, animated:@options[:animated], completion: lambda {}) + end end + + # iPad popover is dismissed + def popoverControllerDidDismissPopover(popoverController) + @popover = nil + end ########## # UIImagePickerControllerDelegate Methods def imagePickerControllerDidCancel(picker) error(Error::CANCELED) @@ -152,9 +177,14 @@ callback_info[:media_type] = media_type_to_symbol(media_type) end @callback.call(callback_info) dismiss + # iPad popover? close it + if @popover + @popover.dismissPopoverAnimated(@options[:animated]) + @popover = nil + end end ########## # Short Helper Methods def picker