Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Camera Sample #27

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Camera/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Camera.app

This sample demonstrates the following concepts: UIImagePickerController.
9 changes: 9 additions & 0 deletions Camera/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# coding: utf-8
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'

Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'Camera'
app.info_plist['UIStatusBarHidden'] = true
end
9 changes: 9 additions & 0 deletions Camera/app/app_delegate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
@window.rootViewController = CameraViewController.alloc.init
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
true
end
end
58 changes: 58 additions & 0 deletions Camera/app/camera_view_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class CameraViewController < UIViewController
INVALID_LABEL_WIDTH = 260
INVALID_LABEL_HEIGHT = 40
INVALID_LABEL_POS_X = (UIScreen.mainScreen.bounds.size.width - INVALID_LABEL_WIDTH) / 2
INVALID_LABEL_POS_Y = (UIScreen.mainScreen.bounds.size.height - INVALID_LABEL_HEIGHT) / 2

FIRE_BUTTON_MARGIN = 5
FIRE_BUTTON_WIDTH = 320
FIRE_BUTTON_HEIGHT = 44
FIRE_BUTTON_POS_X = 0
FIRE_BUTTON_POS_Y = UIScreen.mainScreen.bounds.size.height - FIRE_BUTTON_HEIGHT - FIRE_BUTTON_MARGIN

def viewDidLoad
self.view.backgroundColor = UIColor.blackColor
end

def viewDidAppear(animated)
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
@ipc = UIImagePickerController.alloc.init
@ipc.delegate = self
@ipc.sourceType = UIImagePickerControllerSourceTypeCamera
@ipc.allowsEditing = false
@ipc.showsCameraControls = false
@ipc.view.addSubview(fire_button)
self.presentModalViewController(@ipc, animated: true)
else
make_invalid_screen
end
end

def make_invalid_screen
invalid_label = UILabel.new.tap do |label|
label.text = 'The device can not use camera'
label.textColor = UIColor.whiteColor
label.backgroundColor = UIColor.blackColor
label.frame = [[INVALID_LABEL_POS_X, INVALID_LABEL_POS_Y],
[INVALID_LABEL_WIDTH, INVALID_LABEL_HEIGHT]]
end
self.view.addSubview(invalid_label)
end

def fire_button
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
button.setTitle("Take picture", forState: UIControlStateNormal)
button.frame = [[FIRE_BUTTON_POS_X, FIRE_BUTTON_POS_Y],
[FIRE_BUTTON_WIDTH, FIRE_BUTTON_HEIGHT]]
button.addTarget(self, action:'take_picture', forControlEvents:UIControlEventTouchUpInside)
end

def take_picture
@ipc.takePicture
end

def imagePickerController(picker, didFinishPickingMediaWithInfo:info)
imageToSave = info.objectForKey UIImagePickerControllerOriginalImage
UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil)
end
end
Binary file added Camera/resources/Default-568h@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.