Skip to content

Instantly share code, notes, and snippets.

@rscottm
Created February 23, 2011 08:13
Show Gist options
  • Select an option

  • Save rscottm/840160 to your computer and use it in GitHub Desktop.

Select an option

Save rscottm/840160 to your computer and use it in GitHub Desktop.
require 'ruboto.rb'
ruboto_import_widgets :TextView, :LinearLayout, :Button
java_import 'android.content.Intent'
java_import "android.util.Log"
java_import 'android.provider.MediaStore'
java_import 'android.net.Uri'
java_import 'java.io.File'
java_import 'java.io.FileNotFoundException'
java_import 'android.graphics.BitmapFactory'
java_import 'android.graphics.Bitmap'
java_import 'android.graphics.Canvas'
ruboto_import "org.myname.example.GraphicsView"
$activity.handle_create do |bundle|
setTitle 'Image Capture'
setup_content do
linear_layout :orientation => LinearLayout::VERTICAL do
@text_view = text_view :text => "Welcome"
button :text => "Capture", :width => :wrap_content
button :text => "Edit", :width => :wrap_content
end
end
handle_click do |view|
case view.getText
when "Capture"
capture_intent = Intent.new(MediaStore::ACTION_IMAGE_CAPTURE)
capture_intent.putExtra(MediaStore::EXTRA_OUTPUT, Uri.fromFile(File.new("/sdcard/123.jpg")))
startActivityForResult(capture_intent, 1)
when "Edit"
show_editor(self)
end
end
handle_activity_result do |one, two, three|
Log.i("EXAMPLE", "back from activity camera!")
show_editor(self)
end
end
def show_editor(context)
context.start_ruboto_activity "$editor" do
setTitle 'Edit'
setup_content do
Log.i("EXAMPLE", "EDIT ACTIVITY STARTING")
@surface_view = GraphicsView.new(self)
@surface_view.handle_draw do |canvas|
viewWidth = @surface_view.getWidth.to_f
viewHeight = @surface_view.getHeight.to_f
tmpPaint = Paint.new(Paint::ANTI_ALIAS_FLAG)
tmpPaint.setStyle(Paint::Style::STROKE)
tmpPaint.setTextAlign(Paint::Align::CENTER)
mBitmap = BitmapFactory.decodeFile("/sdcard/123.jpg")
canvas.drawBitmap(mBitmap, nil, Rect.new(0,0, viewWidth, viewHeight), tmpPaint)
end
@surface_view
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment