-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forgot to add demo to github (but in 0.6 release)
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
####################################################### | |||
# | |||
# demo-camera.rb (by Scott Moyer) | |||
# | |||
# Fires up a camera. Take a picture by touching | |||
# the screen. Pictures are stored in the scripts | |||
# directory. | |||
# | |||
####################################################### | |||
|
|||
require 'ruboto/activity' | |||
require 'ruboto/util/toast' | |||
|
|||
java_import "android.view.SurfaceView" | |||
java_import "android.hardware.Camera" | |||
|
|||
ruboto_import "org.ruboto.callbacks.RubotoSurfaceHolderCallback" | |||
|
|||
class Camera | |||
def picture_id | |||
@picture_id ||= 0 | |||
@picture_id += 1 | |||
end | |||
end | |||
|
|||
$activity.start_ruboto_activity "$camera_demo", RubotoActivity, R.style::Theme_NoTitleBar_Fullscreen do | |||
def on_create(bundle) | |||
@surface_view = SurfaceView.new(self) | |||
@surface_view.set_on_click_listener(proc{|v| take_picture}) | |||
@surface_view.holder.add_callback @holder_callback | |||
# Deprecated, but still required for older API version | |||
@surface_view.holder.set_type android.view.SurfaceHolder::SURFACE_TYPE_PUSH_BUFFERS | |||
self.content_view = @surface_view | |||
end | |||
|
|||
@holder_callback = RubotoSurfaceHolderCallback.new_with_callbacks do | |||
def on_surface_created(holder) | |||
$camera = Camera.open # Add (1) for front camera | |||
$camera.preview_display = holder | |||
$camera.start_preview | |||
end | |||
|
|||
def on_surface_destroyed(holder) | |||
$camera.stop_preview | |||
$camera.release | |||
$camera = nil | |||
end | |||
end | |||
|
|||
def take_picture | |||
picture_file = "#{Dir.pwd}/picture#{$camera.picture_id}.jpg" | |||
$camera.take_picture(proc{toast "Piture taken"}, nil) do |data, camera| | |||
fos = java.io.FileOutputStream.new(picture_file) | |||
fos.write(data) | |||
fos.close | |||
end | |||
picture_file | |||
end | |||
end | |||
|