Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated for ruboto 0.10.X

  • Loading branch information...
commit 9be768a3a375f09e29aae9c451730835ca742020 1 parent 769ba00
@rscottm rscottm authored
View
2  assets/demo-scripts/call.rb
@@ -4,4 +4,4 @@
intent = Intent.new(Intent::ACTION_VIEW)
intent.setData(Uri.parse("tel:123"))
-$activity.startActivity(intent)
+$irb.startActivity(intent)
View
154 assets/demo-scripts/craps.rb 100755 → 100644
@@ -1,4 +1,3 @@
-#!/usr/bin/env ruby
######################################################
#
# craps.rb (by Daniel Jackoway)
@@ -149,7 +148,7 @@ def bet(klass, amount)
# all of the bets on the table
$bets = []
# all of the types of bets one can place
-AVAILABLE_BETS = subclasses_of Bet
+$AVAILABLE_BETS = subclasses_of Bet
###############################################################################
@@ -160,102 +159,107 @@ def bet(klass, amount)
#
###############################################################################
-require 'ruboto'
-confirm_ruboto_version(3, false)
+require 'ruboto/activity'
+require 'ruboto/widget'
+require 'ruboto/util/toast'
ruboto_import_widgets :TextView, :LinearLayout, :Button, :ListView, :EditText
-
-$activity.start_ruboto_activity "$craps" do
- setTitle "Craps"
- setup_content do
- linear_layout :orientation => LinearLayout::VERTICAL do
- linear_layout :orientation => LinearLayout::HORIZONTAL do
+class CrapsActivity
+ def on_create(b)
+ super
+ setTitle "Craps"
+ set_content_view(linear_layout(:orientation => :vertical) do
+ linear_layout(:orientation => :horizontal) do
text_view :text => "You have $"
@money_view = text_view :text => "#{$money}"
end
@point_view = text_view :text => "Come-out"
- linear_layout :orientation => LinearLayout::HORIZONTAL do
- button :text => "Roll", :width => :wrap_content
+ linear_layout(:orientation => :horizontal) do
+ button :text => "Roll", :width => :wrap_content, :on_click_listener => (proc{roll})
@roll_view = text_view :text => ""
end
- button :text => "Place a Bet", :width => :wrap_content
- end
+ button :text => "Place a Bet", :width => :wrap_content, :on_click_listener => (proc{launch_bets})
+ end)
end
- handle_click do |view|
- case view.getText
- when "Roll" then roll
- when "Place a Bet" then launch_bets
- else toast "foo"
- end
+ def launch_bets
+ start_ruboto_activity :class_name => "BetList"
end
-end
-def launch_bets
- self.start_ruboto_activity("$bet_list") do
- setTitle "Place a Bet"
- setup_content {list_view :list => AVAILABLE_BETS}
- handle_item_click do |adapter_view, view, pos, item_id|
- klass = AVAILABLE_BETS[pos]
- $activity.start_ruboto_activity "$money_dialog" do
- setTitle klass.to_s
- setup_content do
- linear_layout :orientation => LinearLayout::VERTICAL do
- @bet_amount = edit_text
- button :text => "Place Bet"
- end
- end
-
- handle_click do |view|
- if view.getText == "Place Bet"
- amount = @bet_amount.getText.to_s.to_i
- if amount > 0
- $bets << bet(klass, amount)
- else
- toast "enter a valid integer greater than 0"
- end
- else
- toast "something bad happened"
- end
- end
+ def roll
+ $bets.compact!
+
+ roll = Roll.new
+ @roll_view.setText roll.dice.inspect
+
+ delete = []
+ $bets.each do |bet|
+ result = bet.play(roll, $point)
+ if !result
+ toast "your #{bet.name} bet is still on"
+ elsif result < 0
+ toast "you lost your #{bet.name} bet"
+ delete << bet
+ else
+ # they get their money back (1 * money) + the payout (result * money)
+ toast "you won your #{bet.name} bet!"
+ $money += bet.money * (1 + result)
+ delete << bet
end
end
+ delete.each {|bet| $bets.delete bet }
+
+ if $point
+ $point = nil if $point == roll.sum || roll.sum == 7
+ else
+ $point = roll.sum if [4,5,6,8,9,10].include? roll.sum
+ end
+
+ @money_view.setText $money.to_s
+ @point_view.setText $point ? "The point is #{$point}" : "Come-out"
end
end
+class BetList
+ def on_create(b)
+ super
+ setTitle "Place a Bet"
+ self.content_view = list_view(:list => $AVAILABLE_BETS,
+ :on_item_click_listener => (proc{|av, v, p, i| item_clicked(p)}))
+ end
+ def item_clicked(pos)
+ MoneyDialog.klass = $AVAILABLE_BETS[pos]
+ start_ruboto_activity :class_name => "MoneyDialog"
+ finish
+ end
+end
-def roll
- $bets.compact!
+class MoneyDialog
+ def self.klass=(k)
+ @@klass = k
+ end
- roll = Roll.new
- @roll_view.setText roll.dice.inspect
+ def on_create(b)
+ super
+ setTitle @@klass.to_s
+ set_content_view(
+ linear_layout(:orientation => :vertical) do
+ @bet_amount = edit_text
+ button :text => "Place Bet", :on_click_listener => (proc{place_bet})
+ end)
+ end
- delete = []
- $bets.each do |bet|
- result = bet.play(roll, $point)
- if !result
- toast "your #{bet.name} bet is still on"
- elsif result < 0
- toast "you lost your #{bet.name} bet"
- delete << bet
+ def place_bet
+ amount = @bet_amount.getText.to_s.to_i
+ if amount > 0
+ $bets << bet(@@klass, amount)
+ finish
else
- # they get their money back (1 * money) + the payout (result * money)
- toast "you won your #{bet.name} bet!"
- $money += bet.money * (1 + result)
- delete << bet
+ toast "enter a valid integer greater than 0"
end
end
- delete.each {|bet| $bets.delete bet }
-
-
- if $point
- $point = nil if $point == roll.sum || roll.sum == 7
- else
- $point = roll.sum if [4,5,6,8,9,10].include? roll.sum
- end
-
- @money_view.setText $money.to_s
- @point_view.setText $point ? "The point is #{$point}" : "Come-out"
end
+
+$irb.start_ruboto_activity :class_name => "CrapsActivity"
View
1,040 assets/demo-scripts/demo-android-api.rb
@@ -9,7 +9,6 @@
require 'ruboto/activity'
require 'ruboto/widget'
-require 'ruboto/generate'
require 'ruboto/util/toast'
class RubotoActivity
@@ -53,19 +52,19 @@ def self.resolve_click(context, title)
RubotoActivity.launch_list context, "$sl_#{title.downcase.gsub(' ', '_')}", "Api Demos", title
else
case title
- when "Custom Dialog" then custom_dialog(context)
- when "Custom Title" then custom_title(context)
- when "Forwarding" then forwarding(context)
- when "Hello World" then hello_world(context)
- when "Persistent State" then persistent_state(context)
- when "Save & Restore State" then save_and_restore_state(context)
- when "Arcs" then arcs(context)
- when "Morse Code" then morse_code(context)
- when "Sensors" then sensors(context)
- when "Buttons" then buttons(context)
- when "Chronometer" then chronometer_demo(context)
- when "1. Dialog" then date_dialog(context)
- when "2. Inline" then date_inline(context)
+ when "Custom Dialog" then context.start_ruboto_dialog(:class_name => "CustomDialog")
+ when "Custom Title" then context.start_ruboto_activity(:class_name => "CustomTitle")
+ when "Forwarding" then context.start_ruboto_activity(:class_name => "Forwarding")
+ when "Hello World" then context.start_ruboto_activity(:class_name => "HelloWorld")
+ when "Persistent State" then context.start_ruboto_activity(:class_name => "PersistentState")
+ when "Save & Restore State" then context.start_ruboto_activity(:class_name => "SaveAndRestoreState")
+ when "Arcs" then context.start_ruboto_activity(:class_name => "Arcs")
+ when "Morse Code" then context.start_ruboto_activity(:class_name => "MorseCode")
+ when "Sensors" then context.start_ruboto_activity(:class_name => "Sensors")
+ when "Buttons" then context.start_ruboto_activity(:class_name => "Buttons")
+ when "Chronometer" then context.start_ruboto_activity(:class_name => "ChronometerDemo")
+ when "1. Dialog" then context.start_ruboto_activity(:class_name => "DateDialog")
+ when "2. Inline" then context.start_ruboto_activity(:class_name => "DateInline")
else
context.toast "Not Implemented Yet"
end
@@ -75,637 +74,600 @@ def self.resolve_click(context, title)
def self.launch_list(context, var, title, list_id, extra_text=nil)
ruboto_import_widgets :LinearLayout, :TextView, :ListView
- context.start_ruboto_activity var do
- setTitle title
-
- @list_id = list_id
- @extra_text = extra_text
+ context.start_ruboto_activity(var) do
+ @@list_id = list_id
+ @@extra_text = extra_text
def on_create(bundle)
+ super
+ setTitle title
setContentView(
- linear_layout :orientation => :vertical do
- text_view(:text => @extra_text) if @extra_text
- list_view :list => @@lists[@list_id], :on_item_click_listener => @handle_item_click
+ linear_layout(:orientation => :vertical) do
+ text_view(:text => @@extra_text) if @@extra_text
+ list_view(:list => @@lists[@@list_id],
+ :on_item_click_listener => (proc{|av, v, p, i| RubotoActivity.resolve_click self, v.getText}))
end)
end
-
- @handle_item_click = Proc.new do |adapter_view, view, pos, item_id|
- RubotoActivity.resolve_click self, view.getText
- end
end
end
+end
- #######################################################
- #
- # App -> Activity
- #
-
- #
- # Custom Dialog
- #
+#######################################################
+#
+# App -> Activity
+#
- def self.custom_dialog(context)
- java_import "android.graphics.drawable.GradientDrawable"
- java_import "android.view.Gravity"
- java_import "android.graphics.Color"
+#
+# Custom Dialog
+#
+class CustomDialog
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :TextView
- context.start_ruboto_dialog "$custom_dialog" do
- setTitle "App/Activity/Custom Dialog"
+ super
- def on_create(bundle)
- getWindow.setLayout(ViewGroup::LayoutParams::FILL_PARENT,
- ViewGroup::LayoutParams::WRAP_CONTENT)
- cd = GradientDrawable.new
- cd.setColor(Color.argb(240,96,0,0))
- cd.setStroke(3, Color.argb(255,255,128,128))
- cd.setCornerRadius(3)
- getWindow.setBackgroundDrawable(cd)
+ set_title "App/Activity/Custom Dialog"
+ getWindow.setLayout(ViewGroup::LayoutParams::FILL_PARENT,
+ ViewGroup::LayoutParams::WRAP_CONTENT)
- setContentView(
- linear_layout(:orientation => :vertical, :padding => [10,0,10,10]) do
- text_view :text => "Example of how you can use a custom Theme.Dialog theme to make an activity that looks like a customized dialog, here with an ugly frame.",
- :text_size => 14,
- :gravity => Gravity::CENTER_HORIZONTAL
- end)
- end
- end
- end
+ cd = android.graphics.drawable.GradientDrawable.new
+ cd.color = android.graphics.Color.argb(240,96,0,0)
+ cd.set_stroke(3, android.graphics.Color.argb(255,255,128,128))
+ cd.corner_radius = 3
+ window.background_drawable = cd
- #
- # Custom Title
- #
+ set_content_view(
+ linear_layout(:orientation => :vertical, :padding => [10,0,10,10]) do
+ text_view :text => "Example of how you can use a custom Theme.Dialog theme to make an activity that looks like a customized dialog, here with an ugly frame.",
+ :text_size => 14,
+ :gravity => android.view.Gravity::CENTER_HORIZONTAL
+ end)
+ end
+end
- def self.custom_title(context)
- java_import "android.graphics.Typeface"
- java_import "android.view.Window"
- java_import "android.graphics.Color"
+#
+# Custom Title
+#
+class CustomTitle
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :TextView, :Button, :EditText, :RelativeLayout
+ requestWindowFeature android.view.Window::FEATURE_CUSTOM_TITLE unless @ruboto_java_instance.respond_to?(:action_bar)
- context.start_ruboto_activity "$custom_title" do
- requestWindowFeature Window::FEATURE_CUSTOM_TITLE
-
- def on_create(bundle)
- setContentView(
- linear_layout :orientation => :vertical do
- linear_layout do
- @etl = edit_text(:text => "Left is best", :min_ems => 10, :max_ems => 10)
- button :text => "Change left", :on_click_listener => (proc{@tvl.text = @etl.text})
- end
- linear_layout do
- @etr = edit_text(:text => "Right is always right", :min_ems => 10, :max_ems => 10)
- button :text => "Change right", :on_click_listener => (proc{@tvr.text = @etr.text})
- end
- end)
-
- getWindow.setFeatureInt(Window::FEATURE_CUSTOM_TITLE,
- Ruboto::R::layout::empty_relative_layout)
+ super
- @rl = findViewById(Ruboto::Id::empty_relative_layout)
- @tvl = text_view :text => "Left is best", :text_color => Color::WHITE,
- :typeface => [Typeface::DEFAULT, Typeface::BOLD],
- :parent => @rl, :layout => {:add_rule => :align_parent_left}
+ setContentView(
+ linear_layout(:orientation => :vertical) do
+ linear_layout do
+ @etl = edit_text(:text => "Left is best", :min_ems => 10, :max_ems => 10)
+ button :text => "Change left", :on_click_listener => (proc{@tvl.text = @etl.text})
+ end
+ linear_layout do
+ @etr = edit_text(:text => "Right is always right", :min_ems => 10, :max_ems => 10)
+ button :text => "Change right", :on_click_listener => (proc{@tvr.text = @etr.text})
+ end
+ end)
- @tvr = text_view :text => "Right is always right", :text_color => Color::WHITE,
- :typeface => [Typeface::DEFAULT, Typeface::BOLD],
- :parent => @rl, :layout => {:add_rule => :align_parent_right}
- end
+ if @ruboto_java_instance.respond_to?(:action_bar)
+ action_bar.set_display_options(android.app.ActionBar::DISPLAY_SHOW_CUSTOM,
+ android.app.ActionBar::DISPLAY_SHOW_CUSTOM | android.app.ActionBar::DISPLAY_USE_LOGO)
+ action_bar.set_custom_view Ruboto::R::layout::empty_relative_layout
+ @rl = action_bar.custom_view
+ else
+ getWindow.setFeatureInt(android.view.Window::FEATURE_CUSTOM_TITLE, Ruboto::R::layout::empty_relative_layout)
+ @rl = findViewById(Ruboto::Id::empty_relative_layout)
end
- end
- #
- # Forwarding
- #
+ @tvl = text_view :text => "Left is best",
+ :text_color => android.graphics.Color::WHITE,
+ :typeface => [android.graphics.Typeface::DEFAULT, android.graphics.Typeface::BOLD],
+ :parent => @rl,
+ :layout => {:add_rule => :align_parent_left}
+
+ @tvr = text_view :text => "Right is always right",
+ :text_color => android.graphics.Color::WHITE,
+ :typeface => [android.graphics.Typeface::DEFAULT, android.graphics.Typeface::BOLD],
+ :parent => @rl,
+ :layout => {:add_rule => :align_parent_right}
+ end
+end
- def self.forwarding(context)
- java_import "android.view.Gravity"
+#
+# Forwarding
+#
+class Forwarding
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :Button, :TextView
+ super
+ setTitle "App/Activity/Forwarding"
- context.start_ruboto_activity "$forwarding" do
- setTitle "App/Activity/Forwarding"
-
- def on_create(bundle)
- setContentView(
- linear_layout :orientation => :vertical do
- text_view :text => "Press the button to go forward to the next activity. This activity will stop, so you will no longer see it when going back."
- linear_layout(:gravity => Gravity::CENTER_HORIZONTAL) do
- button :text => "Go", :width => :wrap_content, :on_click_listener => @handle_click
- end
- end)
+ setContentView(
+ linear_layout(:orientation => :vertical) do
+ text_view :text => "Press the button to go forward to the next activity. This activity will stop, so you will no longer see it when going back."
+ linear_layout(:gravity => android.view.Gravity::CENTER_HORIZONTAL) do
+ button :text => "Go", :width => :wrap_content, :on_click_listener => (proc{|v| my_click(v)})
end
+ end)
+ end
- @handle_click = proc do |view|
- context.start_ruboto_activity "$forwarding2" do
- setTitle "App/Activity/Forwarding"
- def on_create (bundle)
- setContentView(
- text_view :text => "Press back button and notice we don't see the previous activity.")
- end
- end
- finish
+ def my_click(view)
+ self.start_ruboto_activity "$forwarding2" do
+ def on_create (bundle)
+ super
+ setTitle "App/Activity/Forwarding"
+ setContentView(
+ text_view :text => "Press back button and notice we don't see the previous activity.")
end
end
+ finish
end
+end
- #
- # Hello, World
- #
-
- def self.hello_world(context)
- java_import "android.view.Gravity"
+#
+# Hello, World
+#
+class HelloWorld
+ def on_create(bundle)
ruboto_import_widgets :TextView
-
- context.start_ruboto_activity "$hello_world" do
- setTitle "App/Activity/Hello World"
-
- def on_create(bundle)
- setContentView(text_view :text => "Hello, World!",
- :gravity => (Gravity::CENTER_HORIZONTAL | Gravity::CENTER_VERTICAL))
- end
- end
+ super
+ setTitle "App/Activity/Hello World"
+ setContentView(text_view :text => "Hello, World!",
+ :gravity => (android.view.Gravity::CENTER_HORIZONTAL |
+ android.view.Gravity::CENTER_VERTICAL))
end
+end
- #
- # Persistent State
- #
-
- def self.persistent_state(context)
- java_import "android.view.WindowManager"
+#
+# Persistent State
+#
+class PersistentState
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :TextView, :EditText
+ super
+ setTitle "App/Activity/Persistent State"
+ getWindow.setSoftInputMode(
+ android.view.WindowManager::LayoutParams::SOFT_INPUT_STATE_VISIBLE |
+ android.view.WindowManager::LayoutParams::SOFT_INPUT_ADJUST_RESIZE)
+ setContentView(
+ linear_layout(:orientation => :vertical, :padding => [4,4,4,4]) do
+ text_view :text => "Demonstration of persistent activity state with getPreferences(0).edit() and getPreferences(0).", :padding => [0,0,0,4]
+ text_view :text => "This text field saves its state:", :padding => [0,0,0,4]
+ @save = edit_text(:text => "Initial text.", :backgroundColor => 0x7700ff00,
+ :padding => [0,4,0,4], :layout => {:weight= => 1.0})
+
+ text_view :text => "This text field does not save its state:", :padding => [0,8,0,4]
+ edit_text :text => "Initial text.", :backgroundColor => 0x77ff0000,
+ :padding => [0,4,0,4], :layout => {:weight= => 1.0}
+ end)
+ end
- context.start_ruboto_activity "$persistent_state" do
- setTitle "App/Activity/Persistent State"
- getWindow.setSoftInputMode(
- WindowManager::LayoutParams::SOFT_INPUT_STATE_VISIBLE |
- WindowManager::LayoutParams::SOFT_INPUT_ADJUST_RESIZE)
-
- def on_create(bundle)
- setContentView(
- linear_layout :orientation => :vertical, :padding => [4,4,4,4] do
- text_view :text => "Demonstration of persistent activity state with getPreferences(0).edit() and getPreferences(0).", :padding => [0,0,0,4]
- text_view :text => "This text field saves its state:", :padding => [0,0,0,4]
- @save = edit_text(:text => "Initial text.", :backgroundColor => 0x7700ff00,
- :padding => [0,4,0,4], :layout => {:weight= => 1.0})
-
- text_view :text => "This text field does not save its state:", :padding => [0,8,0,4]
- edit_text :text => "Initial text.", :backgroundColor => 0x77ff0000,
- :padding => [0,4,0,4], :layout => {:weight= => 1.0}
- end)
- end
+ def on_pause
+ super
+ editor = getPreferences(0).edit
+ editor.putString("text", @save.getText.toString)
+ editor.putInt("selection-start", @save.getSelectionStart)
+ editor.putInt("selection-end", @save.getSelectionEnd)
+ editor.commit
+ end
- def on_pause
- editor = getPreferences(0).edit
- editor.putString("text", @save.getText.toString)
- editor.putInt("selection-start", @save.getSelectionStart)
- editor.putInt("selection-end", @save.getSelectionEnd)
- editor.commit
- end
+ def on_resume
+ super
+ prefs = getPreferences(0)
+ restoredText = prefs.getString("text", nil)
+ if (restoredText != nil)
+ @save.setText(restoredText, TextView::BufferType::EDITABLE)
- def on_resume
- prefs = getPreferences(0)
- restoredText = prefs.getString("text", nil)
- if (restoredText != nil)
- @save.setText(restoredText, TextView::BufferType::EDITABLE)
-
- selectionStart = prefs.getInt("selection-start", -1)
- selectionEnd = prefs.getInt("selection-end", -1)
- if (selectionStart != -1 && selectionEnd != -1)
- @save.setSelection(selectionStart, selectionEnd)
- end
- end
+ selectionStart = prefs.getInt("selection-start", -1)
+ selectionEnd = prefs.getInt("selection-end", -1)
+ if (selectionStart != -1 && selectionEnd != -1)
+ @save.setSelection(selectionStart, selectionEnd)
end
end
end
+end
- #
- # Save and Restore State
- #
-
- def self.save_and_restore_state(context)
- java_import "android.view.WindowManager"
+#
+# Save and Restore State
+#
+class SaveAndRestoreState
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :TextView, :EditText
-
- context.start_ruboto_activity "$save_and_restore_state" do
- setTitle "App/Activity/Save & Restore State"
- getWindow.setSoftInputMode(
- WindowManager::LayoutParams::SOFT_INPUT_STATE_VISIBLE |
- WindowManager::LayoutParams::SOFT_INPUT_ADJUST_RESIZE)
-
- def on_create(bundle)
- setContentView(
- linear_layout :orientation => :vertical, :padding => [4,4,4,4] do
- text_view :text => "Demonstration of saving and restoring activity state in onSaveInstanceState() and onCreate().", :padding => [0,0,0,4]
- text_view :text => "This text field saves its state:", :padding => [0,0,0,4]
- @save = edit_text(:text => "Initial text.", :backgroundColor => 0x7700ff00, :padding => [0,4,0,4],
- :freezes_text => true, :id => 55555, :layout => {:weight= => 1.0})
-
- text_view :text => "This text field does not save its state:", :padding => [0,8,0,4]
- edit_text :text => "Initial text.", :backgroundColor => 0x77ff0000,
+ super
+ setTitle "App/Activity/Save & Restore State"
+ getWindow.setSoftInputMode(
+ android.view.WindowManager::LayoutParams::SOFT_INPUT_STATE_VISIBLE |
+ android.view.WindowManager::LayoutParams::SOFT_INPUT_ADJUST_RESIZE)
+ setContentView(
+ linear_layout(:orientation => :vertical, :padding => [4,4,4,4]) do
+ text_view :text => "Demonstration of saving and restoring activity state in onSaveInstanceState() and onCreate().", :padding => [0,0,0,4]
+ text_view :text => "This text field saves its state:", :padding => [0,0,0,4]
+ @save = edit_text(:text => "Initial text.", :backgroundColor => 0x7700ff00, :padding => [0,4,0,4],
+ :freezes_text => true, :id => 55555, :layout => {:weight= => 1.0})
+
+ text_view :text => "This text field does not save its state:", :padding => [0,8,0,4]
+ edit_text :text => "Initial text.", :backgroundColor => 0x77ff0000,
:padding => [0,4,0,4], :layout => {:weight= => 1.0}
- end)
- end
- end
+ end)
end
+end
- #######################################################
- #
- # Graphics
- #
-
- #
- # Arcs
- #
-
- def self.arcs(context)
- java_import "android.graphics.Color"
- java_import "android.graphics.Paint"
- java_import "android.graphics.RectF"
-
- ruboto_generate(android.view.View => "org.ruboto.RubotoView")
+#######################################################
+#
+# Graphics
+#
- context.start_ruboto_activity "$arcs" do
- setTitle "Graphics/Arcs"
+#
+# Arcs
+#
- def on_create(bundle)
- @sweep_inc = 2
- @start_inc = 15
- @mStart = 0.0
- @mSweep = 0.0
- @mBigIndex = 0
-
- @mPaints = []
- @mUseCenters = []
- @mOvals = []
+class ArcsView < android.view.View
+ java_import "android.graphics.Color"
+ java_import "android.graphics.Paint"
+ java_import "android.graphics.RectF"
+
+ def initialize(c)
+ @sweep_inc = 2
+ @start_inc = 15
+ @mStart = 0.0
+ @mSweep = 0.0
+ @mBigIndex = 0
+
+ @mPaints = []
+ @mUseCenters = []
+ @mOvals = []
- @mPaints[0] = Paint.new
- @mPaints[0].setAntiAlias(true)
- @mPaints[0].setStyle(Paint::Style::FILL)
- @mPaints[0].setColor(Color::RED)
- @mUseCenters[0] = false
+ @mPaints[0] = Paint.new
+ @mPaints[0].setAntiAlias(true)
+ @mPaints[0].setStyle(Paint::Style::FILL)
+ @mPaints[0].setColor(Color::RED)
+ @mUseCenters[0] = false
- @mPaints[1] = Paint.new(@mPaints[0])
- @mPaints[1].setColor(Color::GREEN)
- @mUseCenters[1] = true
+ @mPaints[1] = Paint.new(@mPaints[0])
+ @mPaints[1].setColor(Color::GREEN)
+ @mUseCenters[1] = true
- @mPaints[2] = Paint.new(@mPaints[0])
- @mPaints[2].setStyle(Paint::Style::STROKE)
- @mPaints[2].setStrokeWidth(4)
- @mPaints[2].setColor(Color::BLUE)
- @mUseCenters[2] = false
-
- @mPaints[3] = Paint.new(@mPaints[2])
- @mPaints[3].setColor(Color::GRAY)
- @mUseCenters[3] = true
+ @mPaints[2] = Paint.new(@mPaints[0])
+ @mPaints[2].setStyle(Paint::Style::STROKE)
+ @mPaints[2].setStrokeWidth(4)
+ @mPaints[2].setColor(Color::BLUE)
+ @mUseCenters[2] = false
+
+ @mPaints[3] = Paint.new(@mPaints[2])
+ @mPaints[3].setColor(Color::GRAY)
+ @mUseCenters[3] = true
- @mBigOval = RectF.new( 40, 10, 280, 250)
- @mOvals[0] = RectF.new( 10, 270, 70, 330)
- @mOvals[1] = RectF.new( 90, 270, 150, 330)
- @mOvals[2] = RectF.new(170, 270, 230, 330)
- @mOvals[3] = RectF.new(250, 270, 310, 330)
+ @mBigOval = RectF.new( 40, 10, 280, 250)
+ @mOvals[0] = RectF.new( 10, 270, 70, 330)
+ @mOvals[1] = RectF.new( 90, 270, 150, 330)
+ @mOvals[2] = RectF.new(170, 270, 230, 330)
+ @mOvals[3] = RectF.new(250, 270, 310, 330)
- @mFramePaint = Paint.new
- @mFramePaint.setAntiAlias(true)
- @mFramePaint.setStyle(Paint::Style::STROKE)
- @mFramePaint.setStrokeWidth(0)
-
- setContentView(@ruboto_view)
- end
+ @mFramePaint = Paint.new
+ @mFramePaint.setAntiAlias(true)
+ @mFramePaint.setStyle(Paint::Style::STROKE)
+ @mFramePaint.setStrokeWidth(0)
- def draw(canvas, oval, useCenters, paints, drawBig)
- if drawBig
- canvas.drawRect(@mBigOval, @mFramePaint)
- canvas.drawArc(@mBigOval, @mStart, @mSweep, useCenters, paints)
- end
+ super
+ end
- canvas.drawRect(oval, @mFramePaint)
- canvas.drawArc(oval, @mStart, @mSweep, useCenters, paints)
- end
-
- def view_on_draw(canvas)
- canvas.drawColor(Color::WHITE)
+ def onDraw(canvas)
+ canvas.drawColor(Color::WHITE)
- 0.upto(3) {|i| draw(canvas, @mOvals[i], @mUseCenters[i], @mPaints[i], @mBigIndex == i)}
+ 0.upto(3) {|i| draw_object(canvas, @mOvals[i], @mUseCenters[i], @mPaints[i], @mBigIndex == i)}
- @mSweep += @sweep_inc
- if (@mSweep > 360)
- @mSweep -= 360
- @mStart += @start_inc
- @mStart -= 360 if @mStart >= 360
- @mBigIndex = (@mBigIndex + 1) % @mOvals.length
- end
+ @mSweep += @sweep_inc
+ if (@mSweep > 360)
+ @mSweep -= 360
+ @mStart += @start_inc
+ @mStart -= 360 if @mStart >= 360
+ @mBigIndex = (@mBigIndex + 1) % @mOvals.length
+ end
- @ruboto_view.invalidate
- end
+ invalidate
+ end
- @ruboto_view = RubotoView.new(self)
- @ruboto_view.initialize_ruboto_callbacks do
- def on_draw(canvas)
- $arcs.view_on_draw(canvas)
- end
- end
+ def draw_object(canvas, oval, useCenters, paints, drawBig)
+ if drawBig
+ canvas.drawRect(@mBigOval, @mFramePaint)
+ canvas.drawArc(@mBigOval, @mStart, @mSweep, useCenters, paints)
end
+
+ canvas.drawRect(oval, @mFramePaint)
+ canvas.drawArc(oval, @mStart, @mSweep, useCenters, paints)
end
+end
- #######################################################
- #
- # OS
- #
+class Arcs
+ def on_create(bundle)
+ super
+ setTitle "Graphics/Arcs"
+ setContentView(ArcsView.new(@ruboto_java_instance))
+ end
+end
- #
- # Morse Code
- #
+#######################################################
+#
+# OS
+#
- def self.morse_code(context)
- java_import "android.content.Context"
+#
+# Morse Code
+#
+class MorseCode
+ java_import "android.content.Context"
+
+ @@base = 100
+ @@durations = {"." => [@@base, @@base], "-" => [@@base* 3, @@base],
+ "|" => [0, @@base * 2], " " => [0, @@base * 6]}
+ @@codes = {"A" => ".-", "B" => "-...", "C" => "-.-.", "D" => "-..",
+ "E" => ".", "F" => "..-.", "G" => "--.", "H" => "....",
+ "I" => "..", "J" => ".---", "K" => "-.-", "L" => ".-..",
+ "M" => "--", "N" => "-.", "O" => "---", "P" => ".--.",
+ "Q" => "--.-", "R" => ".-.", "S" => "...", "T" => "-",
+ "U" => "..-", "V" => "..-", "W" => ".--", "X" => "-..-",
+ "Y" => "-.--", "Z" => "--..", "0" => "-----","1" => ".----",
+ "2" => "..---","3" => "...--","4" => "....-","5" => ".....",
+ "6" => "-....","7" => "--...","8" => "---..","9" => "----."}
+
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :EditText, :Button
-
- context.start_ruboto_activity "$morse_code" do
- @base = 100
- @durations = {"." => [@base, @base], "-" => [@base* 3, @base],
- "|" => [0, @base * 2], " " => [0, @base * 6]}
- @codes = {"A" => ".-", "B" => "-...", "C" => "-.-.", "D" => "-..",
- "E" => ".", "F" => "..-.", "G" => "--.", "H" => "....",
- "I" => "..", "J" => ".---", "K" => "-.-", "L" => ".-..",
- "M" => "--", "N" => "-.", "O" => "---", "P" => ".--.",
- "Q" => "--.-", "R" => ".-.", "S" => "...", "T" => "-",
- "U" => "..-", "V" => "..-", "W" => ".--", "X" => "-..-",
- "Y" => "-.--", "Z" => "--..", "0" => "-----","1" => ".----",
- "2" => "..---","3" => "...--","4" => "....-","5" => ".....",
- "6" => "-....","7" => "--...","8" => "---..","9" => "----."}
- setTitle "OS/Morse Code"
- def on_create(bundle)
- setContentView(
- linear_layout :orientation => :vertical do
- @et = edit_text
- button :text => "Vibrate", :width => :wrap_content, :on_click_listener => @handle_click
- end)
- end
- @handle_click = proc do |view|
- getSystemService(Context::VIBRATOR_SERVICE).vibrate(
- @et.getText.to_s.upcase.split('').
- map {|i| @codes[i] || " "}.join('|').split('').
- map {|i| @durations[i]}.flatten.unshift(0).to_java(:long), -1)
- end
- end
+ super
+ setTitle "OS/Morse Code"
+ setContentView(
+ linear_layout(:orientation => :vertical) do
+ @et = edit_text
+ button :text => "Vibrate", :width => :wrap_content,
+ :on_click_listener => (proc{|v| handle_click(v)})
+ end)
end
- #
- # Sensors
- #
-
- def self.sensors(context)
- java_import "android.graphics.Path"
- java_import "android.hardware.SensorManager"
- java_import "android.hardware.Sensor"
- java_import "android.graphics.Color"
- java_import "android.graphics.Paint"
- java_import "android.graphics.RectF"
- java_import "android.graphics.Bitmap"
- java_import "android.graphics.Canvas"
- java_import "android.content.Context"
-
- ruboto_generate(android.view.View => "org.ruboto.RubotoView")
+ def handle_click(view)
+ getSystemService(Context::VIBRATOR_SERVICE).vibrate(
+ @et.getText.to_s.upcase.split('').
+ map {|i| @@codes[i] || " "}.join('|').split('').
+ map {|i| @@durations[i]}.flatten.unshift(0).to_java(:long), -1)
+ end
+end
- context.start_ruboto_activity "$sensors" do
- setTitle "OS/Sensors"
+#
+# Sensors
+#
- def on_create(bundle)
- @manager = getSystemService(Context::SENSOR_SERVICE)
- @sensors = [Sensor::TYPE_ACCELEROMETER,
- Sensor::TYPE_MAGNETIC_FIELD,
- Sensor::TYPE_ORIENTATION].map {|s| @manager.getDefaultSensor(s)}
+class SensorsView < android.view.View
+ include android.hardware.SensorEventListener
+
+ java_import "android.graphics.Path"
+ java_import "android.graphics.Color"
+ java_import "android.graphics.Paint"
+ java_import "android.graphics.RectF"
+ java_import "android.graphics.Bitmap"
+ java_import "android.graphics.Canvas"
+ java_import "android.hardware.Sensor"
+ java_import "android.hardware.SensorManager"
+
+ def initialize(c)
+ @canvas = Canvas.new
+ @last_values = []
+ @orientation_values = [0.0, 0.0, 0.0]
+ @speed = 1.0
+
+ @line_colors = [Color.argb(192, 255, 64, 64),
+ Color.argb(192, 64, 128, 64),
+ Color.argb(192, 64, 64, 255),
+ Color.argb(192, 64, 255, 255),
+ Color.argb(192, 128, 64, 128),
+ Color.argb(192, 255, 255, 64)]
+
+ @paint = Paint.new
+ @paint.setFlags(Paint::ANTI_ALIAS_FLAG);
+
+ @rect = RectF.new(-0.5, -0.5, 0.5, 0.5)
+
+ @path = Path.new
+ @path.arcTo(@rect, 0, 180)
+
+ super
+ end
- self.content_view = @rv
+ def onDraw(canvas)
+ if @bitmap
+ if (@last_x >= @max_x)
+ @last_x = 0
+ oneG = SensorManager::STANDARD_GRAVITY * @scale[0]
+ @paint.setColor(Color.argb(0xFF, 0xAA, 0xAA, 0xAA))
+ @canvas.drawColor(Color::WHITE)
+ @canvas.drawLine(0, @y_offset, @max_x, @y_offset, @paint)
+ @canvas.drawLine(0, @y_offset + oneG, @max_x, @y_offset + oneG, @paint)
+ @canvas.drawLine(0, @y_offset - oneG, @max_x, @y_offset - oneG, @paint)
+ end
+
+ canvas.drawBitmap(@bitmap, 0, 0, nil)
+
+ 0.upto(2) do |i|
+ canvas.save(Canvas::MATRIX_SAVE_FLAG)
+ canvas.translate(@circle_centers[i][0], @circle_centers[i][1])
+ canvas.save(Canvas::MATRIX_SAVE_FLAG)
+ @paint.setColor(Color.argb(0xFF, 0xC0, 0xC0, 0xC0))
+ canvas.scale(@circle_size, @circle_size)
+ canvas.drawOval(@rect, @paint)
+ canvas.restore
+ canvas.scale(@circle_size - 5, @circle_size - 5)
+ @paint.setColor(Color.argb(0xFF, 0xFF, 0x70, 0x10))
+ canvas.rotate(0.0 - @orientation_values[i])
+ canvas.drawPath(@path, @paint)
+ canvas.restore
end
+ end
+ end
- def on_resume
- @sensors.each{|s| @manager.registerListener(@sensor_event_listener, s, SensorManager::SENSOR_DELAY_FASTEST)}
+ def onSizeChanged(w, h, oldw, oldh)
+ @bitmap = Bitmap.createBitmap(w, h, Bitmap::Config::RGB_565)
+ @y_offset = h * 0.5
+ @scale = [(h * -0.5 * (1.0 / (SensorManager::STANDARD_GRAVITY * 2))),
+ (h * -0.5 * (1.0 / (SensorManager::MAGNETIC_FIELD_EARTH_MAX)))]
+ @width = w
+ @height = h
+ @max_x = w + ((@width < @height) ? 0 : 50)
+ @last_x = @max_x
+
+ @canvas.setBitmap(@bitmap)
+ @canvas.drawColor(Color::WHITE)
+
+ @circle_space = ((@width < @height) ? @width : @height) * 0.333333
+ @circle_size = @circle_space - 32
+ @circle_centers = []
+ x = @circle_space * 0.5
+ y = @circle_space * 0.5
+ 0.upto(2) do |i|
+ if (@width < @height)
+ @circle_centers << [x, y + 4.0]
+ x += @circle_space
+ else
+ @circle_centers << [@width - (x + 4.0), y]
+ y += @circle_space
end
+ end
+ end
- def on_stop
- @sensors.each{|s| @manager.unregisterListener(@sensor_event_listener, s)}
+ def onSensorChanged(event)
+ if @bitmap
+ if (event.sensor.getType == Sensor::TYPE_ORIENTATION)
+ @orientation_values = [event.values[0], event.values[1], event.values[2]]
+ else
+ j = (event.sensor.getType == Sensor::TYPE_MAGNETIC_FIELD) ? 1 : 0
+ 0.upto(2) do |i|
+ k = i + j * 3
+ v = @y_offset + event.values[i] * @scale[j]
+ @paint.setColor(@line_colors[k])
+ @canvas.drawLine(@last_x, @last_values[k], @last_x + @speed, v, @paint)
+ @last_values[k] = v
+ end
+ @last_x += @speed if (event.sensor.getType == Sensor::TYPE_MAGNETIC_FIELD)
end
+ invalidate
+ end
+ end
- def view
- @rv
- end
+ def onAccuracyChanged(sensor, accuracy)
+ end
+end
- @rv = RubotoView.new(self).initialize_ruboto_callbacks do
- @canvas = Canvas.new
- @last_values = []
- @orientation_values = [0.0, 0.0, 0.0]
- @speed = 1.0
-
- @line_colors = [Color.argb(192, 255, 64, 64),
- Color.argb(192, 64, 128, 64),
- Color.argb(192, 64, 64, 255),
- Color.argb(192, 64, 255, 255),
- Color.argb(192, 128, 64, 128),
- Color.argb(192, 255, 255, 64)]
-
- @paint = Paint.new
- @paint.setFlags(Paint::ANTI_ALIAS_FLAG);
-
- @rect = RectF.new(-0.5, -0.5, 0.5, 0.5)
-
- @path = Path.new
- @path.arcTo(@rect, 0, 180)
-
- def on_draw(canvas)
- if @bitmap
- if (@last_x >= @max_x)
- @last_x = 0
- oneG = SensorManager::STANDARD_GRAVITY * @scale[0]
- @paint.setColor(Color.argb(0xFF, 0xAA, 0xAA, 0xAA))
- @canvas.drawColor(Color::WHITE)
- @canvas.drawLine(0, @y_offset, @max_x, @y_offset, @paint)
- @canvas.drawLine(0, @y_offset + oneG, @max_x, @y_offset + oneG, @paint)
- @canvas.drawLine(0, @y_offset - oneG, @max_x, @y_offset - oneG, @paint)
- end
-
- canvas.drawBitmap(@bitmap, 0, 0, nil)
-
- 0.upto(2) do |i|
- canvas.save(Canvas::MATRIX_SAVE_FLAG)
- canvas.translate(@circle_centers[i][0], @circle_centers[i][1])
- canvas.save(Canvas::MATRIX_SAVE_FLAG)
- @paint.setColor(Color.argb(0xFF, 0xC0, 0xC0, 0xC0))
- canvas.scale(@circle_size, @circle_size)
- canvas.drawOval(@rect, @paint)
- canvas.restore
- canvas.scale(@circle_size - 5, @circle_size - 5)
- @paint.setColor(Color.argb(0xFF, 0xFF, 0x70, 0x10))
- canvas.rotate(0.0 - @orientation_values[i])
- canvas.drawPath(@path, @paint)
- canvas.restore
- end
- end
- end
+class Sensors
+ java_import "android.hardware.SensorManager"
+ java_import "android.hardware.Sensor"
+ java_import "android.content.Context"
- def on_size_changed(w, h, oldw, oldh)
- @bitmap = Bitmap.createBitmap(w, h, Bitmap::Config::RGB_565)
- @y_offset = h * 0.5
- @scale = [(h * -0.5 * (1.0 / (SensorManager::STANDARD_GRAVITY * 2))),
- (h * -0.5 * (1.0 / (SensorManager::MAGNETIC_FIELD_EARTH_MAX)))]
- @width = w
- @height = h
- @max_x = w + ((@width < @height) ? 0 : 50)
- @last_x = @max_x
-
- @canvas.setBitmap(@bitmap)
- @canvas.drawColor(Color::WHITE)
-
- @circle_space = ((@width < @height) ? @width : @height) * 0.333333
- @circle_size = @circle_space - 32
- @circle_centers = []
- x = @circle_space * 0.5
- y = @circle_space * 0.5
- 0.upto(2) do |i|
- if (@width < @height)
- @circle_centers << [x, y + 4.0]
- x += @circle_space
- else
- @circle_centers << [@width - (x + 4.0), y]
- y += @circle_space
- end
- end
- end
+ def on_create(bundle)
+ super
+ setTitle "OS/Sensors"
- def sensor_changed(event)
- if @bitmap
- if (event.sensor.getType == Sensor::TYPE_ORIENTATION)
- @orientation_values = [event.values[0], event.values[1], event.values[2]]
- else
- j = (event.sensor.getType == Sensor::TYPE_MAGNETIC_FIELD) ? 1 : 0
- 0.upto(2) do |i|
- k = i + j * 3
- v = @y_offset + event.values[i] * @scale[j]
- @paint.setColor(@line_colors[k])
- @canvas.drawLine(@last_x, @last_values[k], @last_x + @speed, v, @paint)
- @last_values[k] = v
- end
- @last_x += @speed if (event.sensor.getType == Sensor::TYPE_MAGNETIC_FIELD)
- end
- self.invalidate
- end
- end
- end
+ @manager = getSystemService(Context::SENSOR_SERVICE)
+ @sensors = [Sensor::TYPE_ACCELEROMETER,
+ Sensor::TYPE_MAGNETIC_FIELD,
+ Sensor::TYPE_ORIENTATION].map {|s| @manager.getDefaultSensor(s)}
- @sensor_event_listener = Object.new
- class << @sensor_event_listener
- def onSensorChanged(event)
- $sensors.view.sensor_changed(event)
- end
+ @sensors_view = SensorsView.new(@ruboto_java_instance)
+ self.content_view = @sensors_view
+ end
- def onAccuracyChanged(sensor, accuracy)
- end
- end
- end
+ def on_resume
+ super
+ @sensors.each{|s| @manager.registerListener(@sensors_view, s, SensorManager::SENSOR_DELAY_FASTEST)}
end
- #######################################################
- #
- # Views
- #
+ def on_stop
+ super
+ @sensors.each{|s| @manager.unregisterListener(@sensors_view, s)}
+ end
+end
- def self.chronometer_demo(context)
- java_import "android.os.SystemClock"
- java_import "android.view.Gravity"
+#######################################################
+#
+# Views
+#
- ruboto_import_widgets :LinearLayout, :Button, :Chronometer
+class ChronometerDemo
+ java_import "android.os.SystemClock"
+ java_import "android.view.Gravity"
- context.start_ruboto_activity "$chronometer_demo" do
- setTitle "Views/Chronometer"
- def on_create(bundle)
- setContentView(
- linear_layout(:orientation => :vertical, :gravity => Gravity::CENTER_HORIZONTAL) do
- @c = chronometer :format => "Initial format: %s", :width => :wrap_content, :padding => [0,30,0,30]
- button :text => "Start", :width => :wrap_content, :on_click_listener => proc{@c.start}
- button :text => "Stop", :width => :wrap_content, :on_click_listener => proc{@c.stop}
- button :text => "Reset", :width => :wrap_content, :on_click_listener => proc{@c.setBase SystemClock.elapsedRealtime}
- button :text => "Set format string", :width => :wrap_content, :on_click_listener => proc{@c.setFormat("Formatted time (%s)")}
- button :text => "Clear format string", :width => :wrap_content, :on_click_listener => proc{@c.setFormat(nil)}
- end)
- end
- end
+ def on_create(bundle)
+ ruboto_import_widgets :LinearLayout, :Button, :Chronometer
+ super
+ setTitle "Views/Chronometer"
+ setContentView(
+ linear_layout(:orientation => :vertical, :gravity => Gravity::CENTER_HORIZONTAL) do
+ @c = chronometer :format => "Initial format: %s", :width => :wrap_content, :padding => [0,30,0,30]
+ button :text => "Start", :width => :wrap_content, :on_click_listener => proc{@c.start}
+ button :text => "Stop", :width => :wrap_content, :on_click_listener => proc{@c.stop}
+ button :text => "Reset", :width => :wrap_content, :on_click_listener => proc{@c.setBase SystemClock.elapsedRealtime}
+ button :text => "Set format string", :width => :wrap_content, :on_click_listener => proc{@c.setFormat("Formatted time (%s)")}
+ button :text => "Clear format string", :width => :wrap_content, :on_click_listener => proc{@c.setFormat(nil)}
+ end)
end
+end
- def self.buttons(context)
+class Buttons
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :Button, :ToggleButton
-
- context.start_ruboto_activity "$buttons" do
- setTitle "Views/Buttons"
- def on_create(bundle)
- setContentView(
- linear_layout :orientation => :vertical do
- button :text => "Normal", :width => :wrap_content
- button :text => "Small", :width => :wrap_content,
- :default_style => JavaUtilities.get_proxy_class("android.R$attr")::buttonStyleSmall
- toggle_button :width => :wrap_content
- end)
- end
- end
+ super
+ setTitle "Views/Buttons"
+ setContentView(
+ linear_layout(:orientation => :vertical) do
+ button :text => "Normal", :width => :wrap_content
+ button :text => "Small", :width => :wrap_content,
+ :default_style => JavaUtilities.get_proxy_class("android.R$attr")::buttonStyleSmall
+ toggle_button :width => :wrap_content
+ end)
end
+end
- def self.date_dialog(context)
- java_import "android.app.TimePickerDialog"
- java_import "android.app.DatePickerDialog"
+class DateDialog
+ java_import "android.app.TimePickerDialog"
+ java_import "android.app.DatePickerDialog"
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :TextView, :Button
+ super
+ setTitle "Views/Date Widgets/1. Dialog"
- context.start_ruboto_activity "$date_dialog" do
- setTitle "Views/Date Widgets/1. Dialog"
-
- def on_create(bundle)
- @time = Time.now
+ @time = Time.now
- setContentView(
- linear_layout :orientation => :vertical do
- @tv = text_view :text => @time.strftime("%m-%d-%Y %R")
- button :text => "change the date", :width => :wrap_content, :on_click_listener => proc{date_picker.show}
- button :text => "change the time", :width => :wrap_content, :on_click_listener => proc{time_picker.show}
- end)
- end
-
- def date_picker
- @date_picker ||= DatePickerDialog.new(self, @date_set_listener, @time.year, @time.month-1, @time.day)
- end
-
- def time_picker
- @time_picker ||= TimePickerDialog.new(self, @time_set_listener, @time.hour, @time.min, false)
- end
+ setContentView(
+ linear_layout(:orientation => :vertical) do
+ @tv = text_view :text => @time.strftime("%m-%d-%Y %R")
+ button :text => "change the date", :width => :wrap_content, :on_click_listener => proc{date_picker.show}
+ button :text => "change the time", :width => :wrap_content, :on_click_listener => proc{time_picker.show}
+ end)
+ end
- @date_set_listener = proc do |view, year, month, day|
- @tv.text = ("%d-%d-%d #{@tv.text.split(' ')[1]}" % [month+1, day, year])
- end
+ def date_picker
+ @date_set_listener ||= proc{|v, y, m, d| @tv.text = ("%d-%d-%d #{@tv.text.split(' ')[1]}" % [m+1, d, y])}
+ @date_picker ||= DatePickerDialog.new(@ruboto_java_instance, @date_set_listener, @time.year, @time.month-1, @time.day)
+ end
- @time_set_listener = proc do |view, hour, minute|
- @tv.text = ("#{@tv.text.split(' ')[0]} %02d:%02d" % [hour, minute])
- end
- end
+ def time_picker
+ @time_set_listener ||= proc{|v, h, m| @tv.text = ("#{@tv.text.split(' ')[0]} %02d:%02d" % [h, m])}
+ @time_picker ||= TimePickerDialog.new(@ruboto_java_instance, @time_set_listener, @time.hour, @time.min, false)
end
+end
- def self.date_inline(context)
+class DateInline
+ def on_create(bundle)
ruboto_import_widgets :LinearLayout, :TextView, :TimePicker
-
- context.start_ruboto_activity "$date_inline" do
- setTitle "Views/Date Widgets/#{title}"
- def on_create(bundle)
- setContentView(
- linear_layout do
- time_picker :on_time_changed_listener => proc{|v, h, m| @tv.setText("%02d:%02d" % [h, m]) if @tv},
- :current_hour => 12, :current_minute=> 15
- @tv = text_view :text => "12:15"
- end)
- end
- end
+ super
+ setTitle "Views/Date Widgets/#{title}"
+ setContentView(
+ linear_layout do
+ time_picker :on_time_changed_listener => proc{|v, h, m| @tv.setText("%02d:%02d" % [h, m]) if @tv},
+ :current_hour => 12, :current_minute=> 15
+ @tv = text_view :text => "12:15"
+ end)
end
end
View
31 assets/demo-scripts/demo-camera.rb
@@ -21,35 +21,42 @@ def picture_id
end
class RubotoSurfaceHolderCallback
+ attr_reader :camera
+
def surfaceCreated(holder)
- $camera = Camera.open # Add (1) for front camera
- $camera.preview_display = holder
- $camera.start_preview
+ @camera = Camera.open # Add (1) for front camera
+ @camera.preview_display = holder
+ @camera.start_preview
end
def surfaceChanged(holder, format, width, height)
end
def surfaceDestroyed(holder)
- $camera.stop_preview
- $camera.release
- $camera = nil
+ @camera.stop_preview
+ @camera.release
+ @camera = nil
end
end
-$activity.start_ruboto_activity "$camera_demo", RubotoActivity, R.style::Theme_NoTitleBar_Fullscreen do
+class CameraDemo
def on_create(bundle)
- @surface_view = android.view.SurfaceView.new(self)
+ super
+ @surface_view = android.view.SurfaceView.new(@ruboto_java_instance)
@surface_view.set_on_click_listener{|v| take_picture}
- @surface_view.holder.add_callback RubotoSurfaceHolderCallback.new
+ @holder_callback = RubotoSurfaceHolderCallback.new
+ @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
def take_picture
- picture_file = "#{Dir.pwd}/picture#{$camera.picture_id}.jpg"
- $camera.take_picture(proc{toast "Picture taken"}, nil) do |data, camera|
+ camera = @holder_callback.camera
+ return unless camera
+
+ picture_file = "#{Dir.pwd}/picture#{camera.picture_id}.jpg"
+ camera.take_picture(proc{toast "Picture taken"}, nil) do |data, camera|
fos = java.io.FileOutputStream.new(picture_file)
fos.write(data)
fos.close
@@ -58,3 +65,5 @@ def take_picture
end
end
+$irb.start_ruboto_activity "$camera_demo", RubotoActivity, R.style::Theme_NoTitleBar_Fullscreen,
+ :class_name => "CameraDemo"
View
73 assets/demo-scripts/demo-opengl.rb
@@ -8,9 +8,7 @@
#######################################################
require 'ruboto/activity'
-require 'ruboto/generate'
-
-java_import "android.opengl.GLSurfaceView"
+require 'ruboto/widget'
java_import "javax.microedition.khronos.egl.EGL10"
java_import "javax.microedition.khronos.egl.EGLConfig"
@@ -19,7 +17,8 @@
java_import "java.nio.ByteBuffer"
java_import "java.nio.ByteOrder"
java_import "java.nio.IntBuffer"
-java_import "android.view.MotionEvent"
+
+ruboto_import_widget :GLSurfaceView, "android.opengl"
#######################################################
#
@@ -146,41 +145,10 @@ def onSurfaceCreated(gl, config)
gl.glEnable(GL10::GL_DEPTH_TEST)
end
- def changeAngle
+ def change_angle
@offset = -@offset
end
end
-
-#######################################################
-#
-# TouchGLSurfaceView
-#
-# A surface view that reacts to touch events
-#
-
-ruboto_generate(android.opengl.GLSurfaceView => "TouchSurfaceView")
-
-class TouchSurfaceView
-
- def initialize(context)
- super context
-
- self.initialize_ruboto_callbacks do
- def on_touch_event(event)
- if event.getAction == MotionEvent::ACTION_DOWN
- @renderer.changeAngle
- request_render
- end
- return true
- end
- end
- end
-
- def renderer= renderer
- @renderer = renderer
- super renderer
- end
-end
#######################################################
#
@@ -188,20 +156,43 @@ def renderer= renderer
#
# Start a new activity or connect to $activity
#
-$activity.start_ruboto_activity "$glsurface" do
- setTitle "GLSurfaceView"
+class OpenGLDemo
def on_create(bundle)
- @surface_view = TouchSurfaceView.new(self)
- @surface_view.renderer = RubotoGLSurfaceViewRenderer.new
- self.content_view = @surface_view
+ super
+
+ begin
+ action_bar.hide
+ rescue
+ set_title("GLSurfaceView Demo")
+ end
+
+ @renderer = RubotoGLSurfaceViewRenderer.new
+ @surface_view = g_l_surface_view :renderer => @renderer,
+ :on_click_listener => (proc{@renderer.change_angle})
+
+ self.content_view = @surface_view
end
def on_resume
+ super
@surface_view.on_resume
end
def on_pause
+ super
@surface_view.on_pause
end
end
+
+#######################################################
+#
+# Needed because this is called from inside of Ruboto IRB
+#
+
+$irb.start_ruboto_activity :class_name => "OpenGLDemo"
+
+# The other option is the remove the line above and to replace
+# the "class OpenGLDemo" line with this:
+# $irb.start_ruboto_activity "$glsurface" do
+
View
87 assets/demo-scripts/demo-ruboto.rb
@@ -9,71 +9,86 @@
require 'ruboto/activity'
require 'ruboto/widget'
-require 'ruboto/menu'
require 'ruboto/util/toast'
-confirm_ruboto_version(10, false)
+
+java_import "android.view.MenuItem"
#
# ruboto_import_widgets imports the UI widgets needed
-# by the activities in this script. ListView and Button
-# come in automatically because those classes get extended.
+# by the activities in this script.
#
ruboto_import_widgets :LinearLayout, :EditText, :TextView, :ListView, :Button
+$options = ["Hello", "World", "Mr", "Ruboto"]
+
#
# $activity is the Activity that launched the
# script engine. The start_ruboto_activity
# method creates a new RubotoActivity to work with.
-# After launch, the new activity can be accessed
-# through the $ruboto_demo (in this case) global.
-# You man not need the global, because the block
-# to start_ruboto_activity is executed in the
-# context of the new activity as it initializes.
#
-$activity.start_ruboto_activity "$ruboto_demo" do
+$irb.start_ruboto_activity do
#
# on_create uses methods created through
- # ruboto_import_widgets to build a UI. All
- # code is executed in the context of the
- # activity.
+ # ruboto_import_widgets to build a UI.
+ # All code will be executed in the context
+ # of the activity.
#
def on_create(bundle)
+ super
+
+ self.title = "Simple Ruboto Demo"
+
+ # Easy way to allow the list activity to call back into this activity
+ $main_activity = self
+
setContentView(
linear_layout(:orientation => LinearLayout::VERTICAL) do
@et = edit_text
linear_layout do
- button :text => "Hello, World", :on_click_listener => proc{|v| my_click(v.getText)}
- button :text => "Hello, Ruboto", :on_click_listener => proc{|v| my_click(v.getText)}
- button :text => "List", :on_click_listener => proc{|v| launch_list}
+ $options.each do |i|
+ button :text => i, :on_click_listener => proc{|v| my_click(v.text)}
+ end
+
+ button :text => "List", :on_click_listener => proc{|v| launch_list}
end
@tv = text_view :text => "Click buttons or menu items:"
end)
end
#
- # All "handle" methods register for the
- # corresponding callback (in this case
- # OnCreateOptionsMenu. Creates menus that
- # execute the corresponding block (still
- # in the context of the activity)
+ # Creates menus items
#
- handle_create_options_menu do |menu|
- add_menu("Hello, World") {my_click "Hello, World"}
- add_menu("Hello, Ruboto") {my_click "Hello, Ruboto"}
- add_menu("Exit") {finish}
+
+ def on_create_options_menu(m)
+ $options.each do |i|
+ mi = m.add(i)
+ mi.show_as_action = MenuItem::SHOW_AS_ACTION_IF_ROOM if MenuItem.const_defined?("SHOW_AS_ACTION_IF_ROOM")
+ end
+
+ m.add("Exit")
+
+ true
+ end
+
+ def on_options_item_selected(mi)
+ case mi.title.to_s
+ when "Exit"
+ finish
+ else
+ my_click(mi.title.to_s)
+ end
+
true
end
#
- # Extra singleton methods for this activity
- # need to be declared with self. This one
- # handles some of the button and menu clicks.
+ # Handles text update for clicks.
#
def my_click(text)
- toast text
- @tv.append "\n#{text}"
- @et.setText text
+ toast "Hello, #{text}"
+ @tv.append "\nHello, #{text}"
+ @et.text = "Hello, #{text}"
end
#
@@ -81,12 +96,12 @@ def my_click(text)
# a ListView.
#
def launch_list
- self.start_ruboto_activity("$my_list") do
- setTitle "Pick Something"
- @list = ["Hello, World", "Hello, Ruboto"]
+ self.start_ruboto_activity do
def on_create(bundle)
- setContentView(list_view :list => @list,
- :on_item_click_listener => proc{|av, v, pos, item_id| toast(@list[pos]); finish})
+ super
+ self.title = "Pick One"
+ setContentView(list_view :list => $options,
+ :on_item_click_listener => proc{|av, v, pos, i| puts $main_activity.my_click(v.text.to_s); finish})
end
end
end
View
123 assets/demo-scripts/demo-webview-editor.rb
@@ -1,77 +1,84 @@
require 'ruboto/activity'
require 'ruboto/widget'
require 'ruboto/util/toast'
-require 'ruboto/generate'
require 'webrick/htmlutils'
require 'webrick/httputils'
ruboto_import_widget :WebView, "android.webkit"
-ruboto_generate(android.webkit.WebViewClient => "org.ruboto.callbacks.RubotoWebViewClient")
ruboto_import_widgets :ListView
-$activity.start_ruboto_activity("$script_list") do
- setTitle "Ruboto Scripts"
+class RubotoWebViewClient < android.webkit.WebViewClient
+ attr_writer :context
- def on_create(bundle)
- setContentView(list_view :list => Dir.glob("*.rb").sort, :on_item_click_listener => @handle_item_click)
+ def shouldOverrideUrlLoading(wv, uri)
+ query = uri.split('?')[1].split('&')
+ name = WEBrick::HTTPUtils.unescape(query[0][5..-1].gsub('+', ' '))
+ script = WEBrick::HTTPUtils.unescape(query[1][5..-1].gsub('+', ' '))
+ File.open(name,"w") {|f| f.write script}
+ @context.save(name)
+ true
end
+end
- @handle_item_click = Proc.new do |adapter_view, view, pos, item_id|
- edit view.getText
+class ScriptList
+ def on_create(bundle)
+ super
+ setTitle "Ruboto Scripts"
+ setContentView(list_view :list => Dir.glob("*.rb").sort,
+ :on_item_click_listener => (proc{|av, v, p, i| ScriptEditor.edit(self, v.text)}))
end
end
-def edit(script)
- $script_list.start_ruboto_activity "$webview_editor" do
- @script = script
-
- def page(name)
- script = File.exists?(name) ? WEBrick::HTMLUtils.escape(IO.read(name)) : ""
- pwd = Dir.pwd
- %Q[
- <html>
- <head>
- <link rel="stylesheet" href="file:#{pwd}/codemirror/lib/codemirror.css">
- <script src="file:#{pwd}/codemirror/lib/codemirror.js"></script>
- <script src="file:#{pwd}/codemirror/mode/ruby/ruby.js"></script>
- <style>
- .CodeMirror-scroll {height: auto; overflow-y: hidden; overflow-x: auto; width: 100%;}
- </style>
- </head>
- <body leftmargin='0px' topmargin='0px' marginwidth='0px' marginheight='0px'>
- <form action='save'>
- Name: <input name='name' value='#{name}' />
- <input type='submit' value='Save' /><br/>
- <textarea id='code' name='code' rows='25' cols='100'>#{script}</textarea>
- </form>
- <script>
- CodeMirror.fromTextArea(document.getElementById("code"),
- {mode: "text/x-ruby", tabMode: "indent", matchBrackets: true, lineNumbers: true, indentUnit: 2});
- </script>
- </body>
- </html>
- ]
- end
+class ScriptEditor
+ def self.edit(context, script)
+ @@script = script
+ context.start_ruboto_activity :class_name => "ScriptEditor"
+ end
+
+ def page(name)
+ script = File.exists?(name) ? WEBrick::HTMLUtils.escape(IO.read(name)) : ""
+ pwd = Dir.pwd
+ %Q[
+ <html>
+ <head>
+ <link rel="stylesheet" href="file:#{pwd}/codemirror/lib/codemirror.css">
+ <script src="file:#{pwd}/codemirror/lib/codemirror.js"></script>
+ <script src="file:#{pwd}/codemirror/mode/ruby/ruby.js"></script>
+ <style>
+ .CodeMirror-scroll {height: auto; overflow-y: hidden; overflow-x: auto; width: 100%;}
+ </style>
+ </head>
+ <body leftmargin='0px' topmargin='0px' marginwidth='0px' marginheight='0px'>
+ <form action='save'>
+ Name: <input name='name' value='#{name}' />
+ <input type='submit' value='Save' /><br/>
+ <textarea id='code' name='code' rows='25' cols='100'>#{script}</textarea>
+ </form>
+ <script>
+ CodeMirror.fromTextArea(document.getElementById("code"),
+ {mode: "text/x-ruby", tabMode: "indent", matchBrackets: true, lineNumbers: true, indentUnit: 2});
+ </script>
+ </body>
+ </html>
+ ]
+ end
- def on_create(bundle)
- @wv = web_view(:initial_scale => 100, :web_view_client => @wvc)
- @wv.settings.use_wide_view_port = true
- @wv.settings.java_script_enabled = true
- @wv.settings.built_in_zoom_controls = true
- @wv.loadDataWithBaseURL("file:#{Dir.pwd}", page(@script), "text/html", nil, nil);
- self.content_view = @wv
- end
-
- @wvc = RubotoWebViewClient.new_with_callbacks do
- def on_should_override_url_loading(wv, uri)
- query = uri.split('?')[1].split('&')
- name = WEBrick::HTTPUtils.unescape(query[0][5..-1].gsub('+', ' '))
- script = WEBrick::HTTPUtils.unescape(query[1][5..-1].gsub('+', ' '))
- File.open(name,"w") {|f| f.write script}
- $webview_editor.runOnUiThread(proc{$webview_editor.toast "Saved #{name}"; $webview_editor.finish})
- true
- end
- end
+ def on_create(bundle)
+ super
+ @wvc = RubotoWebViewClient.new
+ @wvc.context = self
+
+ @wv = web_view(:initial_scale => 100, :web_view_client => @wvc)
+ @wv.settings.use_wide_view_port = true
+ @wv.settings.java_script_enabled = true
+ @wv.settings.built_in_zoom_controls = true
+ @wv.loadDataWithBaseURL("file:#{Dir.pwd}", page(@@script), "text/html", nil, nil);
+ self.content_view = @wv
end
+
+ def save(name)
+ runOnUiThread(proc{toast "Saved #{name}"; finish})
+ end
end
+$irb.start_ruboto_activity :class_name => "ScriptList"
View
111 assets/demo-scripts/dex_manager.rb
@@ -1,113 +1,8 @@
#######################################################
#
-# dex_manager.rb (by Scott Moyer)
+# dex_manager.rb
#
-# This script manages the dex cache (jars created
-# through ruboto_generate). It can clear individual
-# jars (also clearing the constant) or the entire cache.
+# This script has been removed. It was created for the
+# old ruboto/generate code which has also been replaced.
#
#######################################################
-
-class DexManager
- @dex_root = "#{$activity.files_dir.absolute_path}/dx"
-
- def self.root
- @dex_root
- end
-
- def self.clear_optimized_dex
- dex_files.each{|i| File.delete i}
- end
-
- def self.clear_files
- clear_optimized_dex
- jar_files.each{|i| File.delete i}
- end
-
- def self.files_of_type(type)
- return [] unless File.exists?(@dex_root)
- current_dir = Dir.pwd
- Dir.chdir(@dex_root)
- rv = Dir.glob("**/*.#{type}")
- Dir.chdir(current_dir)
- rv.map{|i| "#{@dex_root}/#{i}"}
- end
-
- def self.dex_files
- files_of_type("dex")
- end
-
- def self.jar_files
- files_of_type("jar")
- end
-
- def self.file_size
- dex_size + jar_size
- end
-
- def self.dex_size
- dex_files.inject(0){|size, i| size += File.size i}
- end
-
- def self.jar_size
- jar_files.inject(0){|size, i| size += File.size i}
- end
-
- def self.size_of(file)
- size = 0
- size += File.size(file) if File.exists?(file)
- file = file[-3..-1] == "jar" ? file.gsub(/jar$/, "dex") : file.gsub(/dex$/, "jar")
- size += File.size(file) if File.exists?(file)
- size
- end
-end
-
-#######################################################
-
-require 'ruboto/activity'
-require 'ruboto/widget'
-require 'ruboto/util/toast'
-
-ruboto_import_widgets :ListView
-
-$activity.start_ruboto_activity "$dex_list" do
- setTitle "Manage Generated Classes"
-
- def on_create(bundle)
- build_jars_list
- setContentView(
- @list_view = list_view(:list => @list, :on_item_click_listener => @handle_item_click)
- )
- end
-
- def build_jars_list
- @jar_list = DexManager.jar_files
- @list = ["Delete All (#{DexManager.file_size} bytes)",
- "Delete Optimized Dex Files (#{DexManager.dex_size} bytes)"] +
- @jar_list.map{|i| "Delete #{i.split('/')[-1][0..-5]} (#{DexManager.size_of i} bytes)"}
- end
-
- @handle_item_click = Proc.new do |adapter_view, view, pos, item_id|
- case view.text.to_s[7..9]
- when "All"
- @jar_list.each do |i|
- const = i.split('/')[-1][0..-5]
- Object.class_eval{remove_const(const)} if Object.const_defined?(const)
- end
- DexManager.clear_files
- when "Opt"
- DexManager.clear_optimized_dex
- else
- const = @jar_list[pos-2].split('/')[-1][0..-5]
- Object.class_eval{remove_const(const)} if Object.const_defined?(const)
- File.delete @jar_list[pos-2]
- dex = @jar_list[pos-2].gsub(/jar$/, "dex")
- File.delete(dex) if File.exists?(dex)
- end
-
- build_jars_list
- @list_view.reload_list(@list)
- toast view.text.to_s
- end
-end
-
View
214 assets/demo-scripts/script_market.rb
@@ -7,8 +7,10 @@
#
#######################################################
-require 'ruboto'
-confirm_ruboto_version(10, false)
+require 'ruboto/activity'
+require 'ruboto/widget'
+require 'ruboto/util/toast'
+require 'ruboto/util/stack'
ruboto_import_widgets :TableLayout, :TableRow, :TextView, :EditText, :ScrollView, :ListView
@@ -25,7 +27,7 @@
if Environment.getExternalStorageState == Environment::MEDIA_MOUNTED
$SCRIPT_DIR = "/sdcard/jruby"
else
- $SCRIPT_DIR = $activity.getFilesDir.getAbsolutePath + "/scripts"
+ $SCRIPT_DIR = $irb.getFilesDir.getAbsolutePath + "/scripts"
end
class Activity
@@ -39,27 +41,57 @@ def save_script name, contents
end
end
-
-$activity.start_ruboto_activity("$source_picker") do
- setTitle "Script Market - Select a source"
-
- setup_content do
+$irb.start_ruboto_activity("$source_picker") do
+ def on_create(b)
+ super
+ setTitle "Script Market - Select a source"
@default_list = ["Application asset demo scripts", "Ruboto github scripts"]
load_preferences
@list = @default_list + @options
- @list_view = list_view :list => @list
+ @list_view = list_view :list => @list, :on_item_click_listener => (proc{|av, v, p, i| item_clicked(p)})
registerForContextMenu(@list_view)
- @list_view
+ set_content_view(@list_view)
end
- handle_create_options_menu do |menu|
- add_menu("About") {about self}
- add_menu("Add Github Source") {edit_github_source self}
- add_menu("Add Web Source") {edit_web_source self}
+ def on_create_options_menu(m)
+ m.add("Add Github Source")
+ m.add("Add Web Source")
+ m.add("About")
+ true
+ end
+
+ def on_options_item_selected(mi)
+ case mi.title.to_s
+ when "About" then start_ruboto_activity(:class_name => "AboutActivity")
+ when "Add Github Source" then edit_github_source
+ when "Add Web Source" then edit_web_source
+ end
+
+ true
+ end
+
+ def on_create_context_menu(m, v, mi)
+ m.add("Edit")
+ m.add("Delete")
true
end
- handle_item_click do |adapter_view, view, pos, item_id|
+ def on_context_item_selected(mi)
+ pos = mi.menu_info.position
+
+ case mi.title.to_s
+ when "Edit"
+ pos < 2 ? toast("Can't edit default entries") : edit(@list[pos])
+ true
+ when "Delete"
+ pos < 2 ? toast("Can't delete default entries") : delete_source(@list[pos])
+ true
+ else
+ false
+ end
+ end
+
+ def item_clicked(pos)
case (@list[pos])
when @list[0]
pick_asset
@@ -81,19 +113,7 @@ def save_script name, contents
end
end
- handle_create_context_menu do |menu, view, menu_info|
- add_context_menu("Edit") do |pos|
- pos < 2 ? toast("Can't edit default entries") : edit(@list[pos])
- end
-
- add_context_menu("Delete") do |pos|
- pos < 2 ? toast("Can't delete default entries") : delete_source(@list[pos])
- end
-
- true
- end
-
- def self.pick_asset
+ def pick_asset
launch_script_list(getAssets.list('demo-scripts').map(&:to_s)) do |s|
buf = getAssets.open("demo-scripts/#{s}", AssetManager::ACCESS_BUFFER)
contents = []
@@ -103,20 +123,27 @@ def self.pick_asset
end
end
- def self.launch_script_list(list, &block)
+ def launch_script_list(list, &block)
start_ruboto_activity("$script_list") do
- setTitle "Pick a Script"
-
- setup_content {list_view :list => list}
+ @@block = block
+ @@list = list
+
+ def on_create(b)
+ super
+ setTitle "Pick a Script"
+ set_content_view(
+ list_view(:list => @@list, :on_item_click_listener => (proc{|av, v, p, i| item_clicked(p)}))
+ )
+ end
- handle_item_click do |adapter_view, view, pos, item_id|
- block.call(list[pos])
+ def item_clicked(pos)
+ @@block.call(@@list[pos])
finish
end
end
end
- def self.pick_remote_script(site, list_path, get_path)
+ def pick_remote_script(site, list_path, get_path)
launch_script_list(get_remote_page("http://#{site}/#{list_path}").scan(/>([^<]*.rb)<\//).flatten) do |s|
self.toast_result(
save_script(s, get_remote_page("http://#{site}/#{get_path}" % s)),
@@ -124,7 +151,7 @@ def self.pick_remote_script(site, list_path, get_path)
end
end
- def self.load_preferences
+ def load_preferences
e = getPreferences(Context::MODE_PRIVATE)
@options = e.getString("ScriptSourceOptions", "").split("|")
@option_data = {}
@@ -132,21 +159,21 @@ def self.load_preferences
@list = @default_list + @options
end
- def self.reload_list
+ def reload_list
load_preferences
@list_view.reload_list(@list)
end
- def self.edit(name)
+ def edit(name)
item_data = @option_data[name]
if item_data[0] == "github"
- edit_github_source self, *(item_data[1..-1])
+ edit_github_source *(item_data[1..-1])
else
- edit_web_source self, *(item_data[1..-1])
+ edit_web_source *(item_data[1..-1])
end
end
- def self.save_source(*args)
+ def save_source(*args)
e = getPreferences(Context::MODE_PRIVATE).edit
unless @list.include? args[1]
@options << args[1]
@@ -154,103 +181,128 @@ def self.save_source(*args)
end
e.putString("ScriptSourceOption-#{args[1]}", args.join("|"))
e.commit
- self.reload_list
+ reload_list
end
- def self.delete_source name
+ def delete_source name
@options = @options - [name]
e = getPreferences(Context::MODE_PRIVATE).edit
e.putString("ScriptSourceOptions", @options.join("|"))
e.remove("ScriptSourceOption-#{name}")
e.commit
- self.reload_list
+ reload_list
end
- def self.edit_github_source(context, name="", user="", project="", branch="", dir="")
- context.start_ruboto_activity("$edit_github_source") do
- setTitle "Github Source"
+ def edit_github_source(name="", user="", project="", branch="", dir="")
+ caller = self
+ start_ruboto_activity("$edit_github_source") do
+ @@name = name
+ @@user = user
+ @@project = project
+ @@branch = branch
+ @@dir = dir