ruboto 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/README.md +13 -49
  2. data/Rakefile +26 -26
  3. data/assets/rakelib/ruboto.rake +29 -9
  4. data/assets/res/drawable-hdpi/{icon.png → ic_launcher.png} +0 -0
  5. data/assets/res/drawable-ldpi/{icon.png → ic_launcher.png} +0 -0
  6. data/assets/res/drawable-mdpi/{icon.png → ic_launcher.png} +0 -0
  7. data/assets/samples/sample_activity.rb +19 -9
  8. data/assets/samples/sample_broadcast_receiver.rb +3 -1
  9. data/assets/samples/sample_service.rb +9 -9
  10. data/assets/src/InheritingActivity.java +1 -1
  11. data/assets/src/InheritingBroadcastReceiver.java +4 -4
  12. data/assets/src/InheritingClass.java +1 -1
  13. data/assets/src/InheritingService.java +2 -1
  14. data/assets/src/RubotoActivity.java +26 -17
  15. data/assets/src/RubotoBroadcastReceiver.java +32 -11
  16. data/assets/src/RubotoService.java +23 -13
  17. data/assets/src/org/ruboto/EntryPointActivity.java +18 -26
  18. data/assets/src/org/ruboto/JRubyAdapter.java +468 -0
  19. data/assets/src/org/ruboto/Log.java +22 -0
  20. data/assets/src/org/ruboto/Script.java +113 -587
  21. data/assets/src/org/ruboto/test/ActivityTest.java +7 -7
  22. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +27 -12
  23. data/assets/src/ruboto.rb +1 -1
  24. data/assets/src/ruboto/activity.rb +10 -1
  25. data/assets/src/ruboto/base.rb +0 -12
  26. data/assets/src/ruboto/broadcast_receiver.rb +12 -0
  27. data/assets/src/ruboto/menu.rb +0 -1
  28. data/assets/src/ruboto/package.rb +11 -0
  29. data/assets/src/ruboto/service.rb +9 -0
  30. data/lib/ruboto/commands/base.rb +1 -1
  31. data/lib/ruboto/util/build.rb +1 -1
  32. data/lib/ruboto/util/update.rb +35 -27
  33. data/lib/ruboto/util/xml_element.rb +25 -12
  34. data/lib/ruboto/version.rb +2 -2
  35. data/test/activity/image_button_activity.rb +14 -11
  36. data/test/activity/image_button_activity_test.rb +2 -6
  37. data/test/activity/image_button_and_button_activity.rb +15 -17
  38. data/test/activity/image_button_and_button_activity_test.rb +4 -8
  39. data/test/activity/option_menu_activity.rb +17 -12
  40. data/test/activity/option_menu_activity_test.rb +1 -4
  41. data/test/activity/psych_activity.rb +20 -13
  42. data/test/activity/psych_activity_test.rb +3 -1
  43. data/test/activity/stack_activity.rb +17 -14
  44. data/test/activity/stack_activity_test.rb +13 -12
  45. data/test/app_test_methods.rb +25 -19
  46. data/test/block_def_activity/image_button_activity.rb +23 -0
  47. data/test/block_def_activity/image_button_activity_test.rb +21 -0
  48. data/test/block_def_activity/image_button_and_button_activity.rb +20 -0
  49. data/test/block_def_activity/image_button_and_button_activity_test.rb +27 -0
  50. data/test/block_def_activity/option_menu_activity.rb +26 -0
  51. data/test/block_def_activity/option_menu_activity_test.rb +18 -0
  52. data/test/block_def_activity/psych_activity.rb +35 -0
  53. data/test/block_def_activity/psych_activity_test.rb +16 -0
  54. data/test/block_def_activity/stack_activity.rb +25 -0
  55. data/test/block_def_activity/stack_activity_test.rb +31 -0
  56. data/test/broadcast_receiver_test.rb +2 -2
  57. data/test/handle_activity/image_button_activity.rb +21 -0
  58. data/test/handle_activity/image_button_activity_test.rb +21 -0
  59. data/test/handle_activity/image_button_and_button_activity.rb +24 -0
  60. data/test/handle_activity/image_button_and_button_activity_test.rb +27 -0
  61. data/test/handle_activity/option_menu_activity.rb +21 -0
  62. data/test/handle_activity/option_menu_activity_test.rb +20 -0
  63. data/test/handle_activity/psych_activity.rb +31 -0
  64. data/test/handle_activity/psych_activity_test.rb +16 -0
  65. data/test/handle_activity/stack_activity.rb +21 -0
  66. data/test/handle_activity/stack_activity_test.rb +32 -0
  67. data/test/minimal_app_test.rb +4 -4
  68. data/test/rake_test.rb +15 -1
  69. data/test/ruboto_gen_test.rb +7 -4
  70. data/test/service_test.rb +110 -21
  71. data/test/test_helper.rb +17 -14
  72. data/test/updated_example_test_methods.rb +5 -14
  73. metadata +30 -7
@@ -1,3 +1,3 @@
1
1
  module Ruboto
2
- VERSION = '0.6.0'
3
- end
2
+ VERSION = '0.7.0'
3
+ end
@@ -1,21 +1,24 @@
1
- require 'ruboto'
1
+ require 'ruboto/activity'
2
2
 
3
3
  ruboto_import_widgets :ImageButton, :LinearLayout, :TextView
4
4
 
5
- $activity.handle_create do |bundle|
6
- setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
5
+ class ImageButtonActivity
6
+ include Ruboto::Activity
7
7
 
8
- setup_content do
9
- linear_layout :orientation => LinearLayout::VERTICAL do
10
- @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
11
- image_button :image_resource => $package.R::drawable::icon, :width => :wrap_content, :id => 43
12
- end
13
- end
8
+ def on_create(bundle)
9
+ set_title File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
14
10
 
15
- handle_click do |view|
16
- if view.id == 43
11
+ click_handler = proc do |view|
17
12
  @text_view.setText 'What hath Matz wrought!'
18
13
  toast 'Flipped a bit via butterfly'
19
14
  end
15
+
16
+ self.content_view =
17
+ linear_layout :orientation => LinearLayout::VERTICAL, :gravity => android.view.Gravity::CENTER_HORIZONTAL do
18
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :width => :fill_parent,
19
+ :gravity => android.view.Gravity::CENTER, :text_size => 48.0
20
+ image_button :image_resource => $package.R::drawable::get_ruboto_core, :width => :wrap_content, :id => 43,
21
+ :on_click_listener => click_handler
22
+ end
20
23
  end
21
24
  end
@@ -10,12 +10,8 @@ setup do |activity|
10
10
  assert @text_view
11
11
  end
12
12
 
13
- test('initial setup') do |activity|
14
- assert_equal "What hath Matz wrought?", @text_view.text
15
- end
16
-
17
13
  test('button changes text') do |activity|
18
- button = activity.findViewById(43)
19
- button.performClick
14
+ assert_equal "What hath Matz wrought?", @text_view.text
15
+ activity.findViewById(43).performClick
20
16
  assert_equal "What hath Matz wrought!", @text_view.text
21
17
  end
@@ -1,24 +1,22 @@
1
- require 'ruboto'
1
+ require 'ruboto/activity'
2
2
 
3
3
  ruboto_import_widgets :Button, :ImageButton, :LinearLayout, :TextView
4
4
 
5
- $activity.handle_create do |bundle|
6
- setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
5
+ class ImageButtonAndButtonActivity
6
+ include Ruboto::Activity
7
7
 
8
- setup_content do
9
- linear_layout :orientation => LinearLayout::VERTICAL do
10
- @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
11
- button :text => 'Button', :width => :wrap_content, :id => 44
12
- image_button :image_resource => $package.R::drawable::icon, :width => :wrap_content, :id => 43
13
- end
14
- end
8
+ def on_create(bundle)
9
+ setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
15
10
 
16
- handle_click do |view|
17
- if view.id == 43
18
- @text_view.text = 'Image button pressed'
19
- elsif view.id == 44
20
- @text_view.text = 'Button pressed'
21
- end
11
+ self.content_view =
12
+ linear_layout :orientation => LinearLayout::VERTICAL, :gravity => android.view.Gravity::CENTER_HORIZONTAL do
13
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :text_size => 48.0,
14
+ :width => :fill_parent, :gravity => android.view.Gravity::CENTER
15
+ button :text => 'Button', :id => 44, :text_size => 48.0,
16
+ :width => :fill_parent, :gravity => android.view.Gravity::CENTER,
17
+ :on_click_listener => proc { @text_view.text = 'Button pressed' }
18
+ image_button :image_resource => $package.R::drawable::get_ruboto_core, :id => 43, :width => :wrap_content,
19
+ :on_click_listener => proc { @text_view.text = 'Image button pressed' }
20
+ end
22
21
  end
23
-
24
22
  end
@@ -10,18 +10,14 @@ setup do |activity|
10
10
  assert @text_view
11
11
  end
12
12
 
13
- test('initial setup') do |activity|
14
- assert_equal "What hath Matz wrought?", @text_view.text
15
- end
16
-
17
13
  test('button changes text') do |activity|
18
- button = activity.find_view_by_id 44
19
- button.perform_click
14
+ assert_equal "What hath Matz wrought?", @text_view.text
15
+ activity.find_view_by_id(44).perform_click
20
16
  assert_equal 'Button pressed', @text_view.text
21
17
  end
22
18
 
23
19
  test('image button changes text') do |activity|
24
- image_button = activity.find_view_by_id 43
25
- image_button.perform_click
20
+ assert_equal "What hath Matz wrought?", @text_view.text
21
+ activity.find_view_by_id(43).perform_click
26
22
  assert_equal 'Image button pressed', @text_view.text
27
23
  end
@@ -1,23 +1,28 @@
1
1
  require 'ruboto/activity'
2
2
  require 'ruboto/widget'
3
- require 'ruboto/legacy'
4
- require 'ruboto/menu'
5
3
  require 'ruboto/util/toast'
6
4
 
7
- ruboto_import_widgets :ImageButton, :LinearLayout, :TextView
5
+ ruboto_import_widgets :LinearLayout, :TextView
8
6
 
9
- $activity.handle_create do |bundle|
10
- setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
7
+ class OptionMenuActivity
8
+ include Ruboto::Activity
11
9
 
12
- setup_content do
13
- linear_layout :orientation => LinearLayout::VERTICAL do
14
- @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
15
- end
10
+ def on_create(bundle)
11
+ set_title File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
12
+
13
+ self.content_view =
14
+ linear_layout :orientation => LinearLayout::VERTICAL do
15
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :text_size => 48.0,
16
+ :width => :fill_parent, :gravity => android.view.Gravity::CENTER
17
+ end
16
18
  end
17
19
 
18
- handle_create_options_menu do |menu|
19
- add_menu('Test') do
20
- @text_view.setText 'What hath Matz wrought!'
20
+ def on_create_options_menu(menu)
21
+ mi = menu.add('Test')
22
+ # mi.icon = $package.R::drawable::get_ruboto_core
23
+ mi.setIcon($package.R::drawable::get_ruboto_core)
24
+ mi.set_on_menu_item_click_listener do |menu_item|
25
+ @text_view.text = 'What hath Matz wrought!'
21
26
  toast 'Flipped a bit via butterfly'
22
27
  end
23
28
  true
@@ -10,11 +10,8 @@ setup do |activity|
10
10
  assert @text_view
11
11
  end
12
12
 
13
- test('initial setup') do |activity|
14
- assert_equal "What hath Matz wrought?", @text_view.text
15
- end
16
-
17
13
  test('option_menu changes text') do |activity|
14
+ assert_equal "What hath Matz wrought?", @text_view.text
18
15
  activity.window.performPanelIdentifierAction(android.view.Window::FEATURE_OPTIONS_PANEL, 0, 0)
19
16
  assert_equal "What hath Matz wrought!", @text_view.text
20
17
  end
@@ -1,5 +1,5 @@
1
- # TODO(uwe): Remove when we stop supporting Ruby 1.8 mode
2
- if RUBY_VERSION < "1.9"
1
+ # TODO(uwe): Remove when we stop supporting psych with Ruby 1.8 mode
2
+ if RUBY_VERSION < '1.9'
3
3
  require 'jruby'
4
4
  require 'rbconfig'
5
5
  org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
@@ -8,23 +8,30 @@ if RUBY_VERSION < "1.9"
8
8
  end
9
9
  # TODO end
10
10
 
11
- with_large_stack{require 'psych.rb'}
11
+ require 'ruboto/activity'
12
+ require 'ruboto/util/stack'
13
+ with_large_stack { require 'psych.rb' }
12
14
 
13
15
  Psych::Parser
14
16
  Psych::Handler
15
17
 
16
- require 'ruboto'
17
-
18
18
  ruboto_import_widgets :Button, :LinearLayout, :TextView
19
19
 
20
- $activity.handle_create do |bundle|
21
- setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
20
+ class PsychActivity
21
+ include Ruboto::Activity
22
22
 
23
- setup_content do
24
- linear_layout :orientation => LinearLayout::VERTICAL do
25
- @decoded_view = text_view :id => 42, :text => Psych.load('--- foo')
26
- # @encoded_view = text_view :id => 43, :text => Psych.dump("foo")
27
- end
28
- end
23
+ def on_create(bundle)
24
+ set_title File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
25
+ self.content_view =
26
+ linear_layout :orientation => LinearLayout::VERTICAL, :gravity => android.view.Gravity::CENTER do
27
+ @decoded_view = text_view :id => 42, :text => with_large_stack { Psych.load('--- foo') },
28
+ :text_size => 48.0, :gravity => android.view.Gravity::CENTER
29
29
 
30
+ # TODO(uwe): Simplify when we stop supporting Psych in Ruby 1.8 mode
31
+ if RUBY_VERSION >= '1.9'
32
+ @encoded_view = text_view :id => 43, :text => with_large_stack { Psych.dump('foo') },
33
+ :text_size => 48.0, :gravity => android.view.Gravity::CENTER
34
+ end
35
+ end
36
+ end
30
37
  end
@@ -12,5 +12,7 @@ end
12
12
 
13
13
  test('psych_encode_decode') do |activity|
14
14
  assert_equal 'foo', activity.find_view_by_id(42).text.to_s
15
- #assert_equal "--- foo\n...\n", activity.find_view_by_id(43).text.to_s
15
+ if RUBY_VERSION >= '1.9'
16
+ assert_equal "--- foo\n", activity.find_view_by_id(43).text.to_s
17
+ end
16
18
  end
@@ -1,21 +1,24 @@
1
1
  STACK_DEPTH_SCRIPT = java.lang.Thread.current_thread.stack_trace.length.to_s
2
- require 'ruboto'
2
+
3
+ require 'ruboto/activity'
3
4
 
4
5
  ruboto_import_widgets :Button, :LinearLayout, :TextView
5
6
 
6
- $activity.handle_create do |bundle|
7
- STACK_DEPTH_HANDLE_CREATE = java.lang.Thread.current_thread.stack_trace.length.to_s
8
- setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
7
+ class StackActivity
8
+ STACK_DEPTH_CLASS = java.lang.Thread.current_thread.stack_trace.length.to_s
9
+ include Ruboto::Activity
9
10
 
10
- setup_content do
11
- STACK_DEPTH_SETUP_CONTENT = java.lang.Thread.current_thread.stack_trace.length.to_s
12
- linear_layout :orientation => LinearLayout::VERTICAL do
13
- STACK_DEPTH_LINEAR_LAYOUT = java.lang.Thread.current_thread.stack_trace.length.to_s
14
- @script_view = text_view :id => 42, :text => STACK_DEPTH_SCRIPT
15
- @handle_create_view = text_view :id => 43, :text => STACK_DEPTH_HANDLE_CREATE
16
- @setup_content_view = text_view :id => 44, :text => STACK_DEPTH_SETUP_CONTENT
17
- @linear_layout_view = text_view :id => 45, :text => STACK_DEPTH_LINEAR_LAYOUT
18
- end
19
- end
11
+ def on_create(bundle)
12
+ stack_depth_on_create = java.lang.Thread.current_thread.stack_trace.length.to_s
13
+ setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
20
14
 
15
+ self.content_view =
16
+ linear_layout :orientation => :vertical, :gravity => android.view.Gravity::CENTER do
17
+ stack_depth_linear_layout = java.lang.Thread.current_thread.stack_trace.length.to_s
18
+ text_view :id => 42, :text => STACK_DEPTH_SCRIPT, :text_size => 48.0, :gravity => android.view.Gravity::CENTER
19
+ text_view :id => 43, :text => STACK_DEPTH_CLASS, :text_size => 48.0, :gravity => android.view.Gravity::CENTER
20
+ text_view :id => 44, :text => stack_depth_on_create, :text_size => 48.0, :gravity => android.view.Gravity::CENTER
21
+ text_view :id => 45, :text => stack_depth_linear_layout, :text_size => 48.0, :gravity => android.view.Gravity::CENTER
22
+ end
23
+ end
21
24
  end
@@ -11,21 +11,22 @@ setup do |activity|
11
11
  end
12
12
 
13
13
  test('stack depth') do |activity|
14
- os_offset = {13 => 1, 15 => 1}[android.os.Build::VERSION::SDK_INT].to_i
15
- if org.ruboto.Script.uses_platform_apk?
14
+ os_offset = {13 => 1, 15 => 1, 16 => 1}[android.os.Build::VERSION::SDK_INT].to_i
15
+ if org.ruboto.JRubyAdapter.uses_platform_apk?
16
16
  jruby_offset = {
17
17
  '0.4.7' => [0, 0, 0, 0],
18
- '0.4.8.dev' => [0, -1, -1, -1],
19
- }[org.ruboto.Script.platform_version_name] || [0, 0, 0, 0]
20
- else
18
+ '0.4.8.dev' => [0, 0, 0, 0],
19
+ }[org.ruboto.JRubyAdapter.platform_version_name] || [0, 0, 0, 0]
20
+ else # STANDALONE
21
21
  jruby_offset = {
22
- '1.5.6' => [-2, -5, -6, -8],
23
- '1.7.0.dev' => [0, -1, -1, -1],
22
+ '1.7.0.dev' => [1, 1, 1, 1],
23
+ '1.7.0.preview1' => [0, -1, -1, -1],
24
+ '1.7.0.preview2.dev' => [0, 0, 0, 0],
24
25
  }[org.jruby.runtime.Constants::VERSION] || [0, 0, 0, 0]
25
26
  end
26
- version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, PLATFORM: #{org.ruboto.Script.uses_platform_apk ? org.ruboto.Script.platform_version_name : 'STANDALONE'}, JRuby: #{org.jruby.runtime.Constants::VERSION}"
27
- assert_equal 44 + os_offset + jruby_offset[0], activity.find_view_by_id(42).text.to_i, version_message
28
- assert_equal 68 + os_offset + jruby_offset[1], activity.find_view_by_id(43).text.to_i, version_message
29
- assert_equal 77 + os_offset + jruby_offset[2], activity.find_view_by_id(44).text.to_i, version_message
30
- assert_equal 93 + os_offset + jruby_offset[3], activity.find_view_by_id(45).text.to_i, version_message
27
+ version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, PLATFORM: #{org.ruboto.JRubyAdapter.uses_platform_apk ? org.ruboto.JRubyAdapter.platform_version_name : 'STANDALONE'}, JRuby: #{org.jruby.runtime.Constants::VERSION}"
28
+ assert_equal 43 + os_offset + jruby_offset[0], activity.find_view_by_id(42).text.to_i, version_message
29
+ assert_equal 48 + os_offset + jruby_offset[1], activity.find_view_by_id(43).text.to_i, version_message
30
+ assert_equal 46 + os_offset + jruby_offset[2], activity.find_view_by_id(44).text.to_i, version_message
31
+ assert_equal 79 + os_offset + jruby_offset[3], activity.find_view_by_id(45).text.to_i, version_message
31
32
  end
@@ -4,37 +4,30 @@ module AppTestMethods
4
4
  include RubotoTest
5
5
 
6
6
  def test_activity_tests
7
- # TODO(uwe): Remove check when we stop supporting jruby-jars 1.5.6
8
- if Test::Unit::TestCase::ON_JRUBY_JARS_1_5_6
9
- puts "Skipping YAML tests on jruby-jars-1.5.6"
10
- else
11
- assert_code 'YamlLoads', "with_large_stack{require 'yaml'}"
12
- end
13
-
7
+ assert_code 'YamlLoads', "with_large_stack{require 'yaml'}"
14
8
  assert_code 'ReadSourceFile', 'File.read(__FILE__)'
15
9
  assert_code 'DirListsFilesInApk', 'Dir["#{File.dirname(__FILE__)}/*"].each{|f| raise "File #{f.inspect} not found" unless File.exists?(f)}'
16
10
  assert_code 'RepeatRubotoImport', 'ruboto_import :TextView ; ruboto_import :TextView'
11
+ run_activity_tests('activity')
12
+ end
17
13
 
18
- Dir[File.expand_path('activity/*_test.rb', File.dirname(__FILE__))].each do |test_src|
19
- # TODO(uwe): Remove check when we stop supporting jruby-jars 1.5.6
20
- next if Test::Unit::TestCase::ON_JRUBY_JARS_1_5_6 && test_src =~ /psych_activity_test.rb$/
14
+ def test_block_def_activity_tests
15
+ run_activity_tests('block_def_activity')
16
+ end
21
17
 
22
- snake_name = test_src.chomp('_test.rb')
23
- activity_name = File.basename(snake_name).split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join
24
- Dir.chdir APP_DIR do
25
- system "#{RUBOTO_CMD} gen class Activity --name #{activity_name}"
26
- FileUtils.cp "#{snake_name}.rb", "src/"
27
- FileUtils.cp test_src, "test/src/"
28
- end
18
+ def test_handle_activity_tests
19
+ Dir.chdir APP_DIR do
20
+ FileUtils.rm "src/ruboto_test_app_activity.rb"
21
+ FileUtils.rm "test/src/ruboto_test_app_activity_test.rb"
29
22
  end
30
- run_app_tests
23
+ run_activity_tests('handle_activity')
31
24
  end
32
25
 
33
26
  private
34
27
 
35
28
  def assert_code(activity_name, code)
36
29
  snake_name = activity_name.scan(/[A-Z]+[a-z]+/).map { |s| s.downcase }.join('_')
37
- filename = "src/#{snake_name}_activity.rb"
30
+ filename = "src/#{snake_name}_activity.rb"
38
31
  Dir.chdir APP_DIR do
39
32
  system "#{RUBOTO_CMD} gen class Activity --name #{activity_name}Activity"
40
33
  s = File.read(filename)
@@ -43,4 +36,17 @@ module AppTestMethods
43
36
  end
44
37
  end
45
38
 
39
+ def run_activity_tests(activity_dir)
40
+ Dir[File.expand_path("#{activity_dir}/*_test.rb", File.dirname(__FILE__))].each do |test_src|
41
+ snake_name = test_src.chomp('_test.rb')
42
+ activity_name = File.basename(snake_name).split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join
43
+ Dir.chdir APP_DIR do
44
+ system "#{RUBOTO_CMD} gen class Activity --name #{activity_name}"
45
+ FileUtils.cp "#{snake_name}.rb", "src/"
46
+ FileUtils.cp test_src, "test/src/"
47
+ end
48
+ end
49
+ run_app_tests
50
+ end
51
+
46
52
  end
@@ -0,0 +1,23 @@
1
+ require 'ruboto/activity'
2
+ require 'ruboto/widget'
3
+ require 'ruboto/util/toast'
4
+
5
+ ruboto_import_widgets :ImageButton, :LinearLayout, :TextView
6
+
7
+ $activity.start_ruboto_activity do
8
+ setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
9
+
10
+ def on_create(bundle)
11
+ click_handler = proc do |view|
12
+ @text_view.setText 'What hath Matz wrought!'
13
+ toast 'Flipped a bit via butterfly'
14
+ end
15
+
16
+ self.content_view =
17
+ linear_layout :orientation => LinearLayout::VERTICAL do
18
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
19
+ image_button :image_resource => $package.R::drawable::get_ruboto_core, :width => :wrap_content, :id => 43,
20
+ :on_click_listener => click_handler
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ activity Java::org.ruboto.test_app.ImageButtonActivity
2
+
3
+ setup do |activity|
4
+ start = Time.now
5
+ loop do
6
+ @text_view = activity.findViewById(42)
7
+ break if @text_view || (Time.now - start > 60)
8
+ sleep 1
9
+ end
10
+ assert @text_view
11
+ end
12
+
13
+ test('initial setup') do |activity|
14
+ assert_equal "What hath Matz wrought?", @text_view.text
15
+ end
16
+
17
+ test('button changes text') do |activity|
18
+ button = activity.findViewById(43)
19
+ button.performClick
20
+ assert_equal "What hath Matz wrought!", @text_view.text
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'ruboto/activity'
2
+ require 'ruboto/widget'
3
+ require 'ruboto/util/toast'
4
+
5
+ ruboto_import_widgets :Button, :ImageButton, :LinearLayout, :TextView
6
+
7
+ $activity.start_ruboto_activity do
8
+ setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
9
+
10
+ def on_create(bundle)
11
+ self.content_view =
12
+ linear_layout :orientation => LinearLayout::VERTICAL do
13
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
14
+ button :text => 'Button', :width => :wrap_content, :id => 44,
15
+ :on_click_listener => proc { @text_view.text = 'Button pressed' }
16
+ image_button :image_resource => $package.R::drawable::get_ruboto_core, :width => :wrap_content, :id => 43,
17
+ :on_click_listener => proc { @text_view.text = 'Image button pressed' }
18
+ end
19
+ end
20
+ end