Permalink
Browse files

camera sample

  • Loading branch information...
1 parent 0cc62e8 commit 62fd80d6fa79ba369cf77d51eec343c92c5405f3 @clayallsopp clayallsopp committed Aug 16, 2012
View
@@ -0,0 +1,3 @@
+source :rubygems
+
+gem 'bubble-wrap', '~> 1.1.0'
View
@@ -0,0 +1,4 @@
+## Location Demo
+
+A bubble-wrap demo to show how to use location API.
+
View
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+$:.unshift("/Library/RubyMotion/lib")
+require 'motion/project'
+require 'bubble-wrap/core'
+require 'bubble-wrap/camera'
+
+Motion::Project::App.setup do |app|
+ app.name = 'camera'
+end
@@ -0,0 +1,8 @@
+class AppDelegate
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
+ camera_controller = CameraController.alloc.initWithNibName(nil, bundle:nil)
+ @window.rootViewController = camera_controller
+ @window.makeKeyAndVisible
+ end
+end
@@ -0,0 +1,61 @@
+class CameraController < UIViewController
+
+ def viewDidLoad
+ super
+
+ @buttons = []
+
+ @library = UIButton.buttonWithType(UIButtonTypeRoundedRect)
+ @library.setTitle("Library", forState:UIControlStateNormal)
+ @library.sizeToFit
+ @library.when UIControlEventTouchUpInside do
+ BW::Device.camera.any.picture(media_types: [:image]) do |result|
+ image_view = UIImageView.alloc.initWithImage(result[:original_image])
+ add_image_view(image_view)
+ end
+ end
+ self.view.addSubview(@library)
+ @buttons << @library
+
+ if BW::Device.camera.front?
+ @front = UIButton.buttonWithType(UIButtonTypeRoundedRect)
+ @front.setTitle("Front", forState:UIControlStateNormal)
+ @front.sizeToFit
+ last_button = @buttons.last
+ @front.frame = [[last_button.frame.origin.x, last_button.frame.origin.y + last_button.frame.size.height + 10], @front.frame.size]
+ @front.when UIControlEventTouchUpInside do
+ BW::Device.camera.front.picture(media_types: [:image]) do |result|
+ image_view = UIImageView.alloc.initWithImage(result[:original_image])
+ add_image_view(image_view)
+ end
+ end
+ self.view.addSubview(@front)
+ @buttons << @front
+ end
+
+ if BW::Device.camera.rear?
+ @rear = UIButton.buttonWithType(UIButtonTypeRoundedRect)
+ @rear.setTitle("Read", forState:UIControlStateNormal)
+ @rear.sizeToFit
+ last_button = @buttons.last
+ @rear.frame = [[last_button.frame.origin.x, last_button.frame.origin.y + last_button.frame.size.height + 10], @rear.frame.size]
+ @rear.when UIControlEventTouchUpInside do
+ BW::Device.camera.rear.picture(media_types: [:image]) do |result|
+ image_view = UIImageView.alloc.initWithImage(result[:original_image])
+ add_image_view(image_view)
+ end
+ end
+ self.view.addSubview(@rear)
+ @buttons << @rear
+ end
+ end
+
+ def add_image_view(image_view)
+ image_view.frame = [CGPointZero, self.view.frame.size]
+ image_view.center = [self.view.frame.size.width / 2, self.view.frame.size.height / 2]
+ self.view.addSubview(image_view)
+ @buttons.each do |button|
+ self.view.bringSubviewToFront(button)
+ end
+ end
+end
@@ -0,0 +1,9 @@
+describe "Application 'google_location'" do
+ before do
+ @app = UIApplication.sharedApplication
+ end
+
+ it "has one window" do
+ @app.windows.size.should == 1
+ end
+end

0 comments on commit 62fd80d

Please sign in to comment.