ruboto 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -6
  3. data/RELEASE_CANDICATE_DOC.md +5 -3
  4. data/RELEASE_DOC.md +32 -11
  5. data/Rakefile +86 -36
  6. data/assets/rakelib/ruboto.rake +33 -14
  7. data/assets/rakelib/ruboto.stdlib.rake +1 -1
  8. data/assets/res/layout/get_ruboto_core.xml +1 -2
  9. data/assets/src/RubotoService.java +19 -2
  10. data/assets/src/org/ruboto/JRubyAdapter.java +4 -0
  11. data/assets/src/org/ruboto/SplashActivity.java +17 -17
  12. data/assets/src/ruboto/base.rb +13 -4
  13. data/assets/src/ruboto/package.rb +12 -3
  14. data/assets/src/ruboto/service.rb +45 -8
  15. data/assets/src/ruboto/widget.rb +82 -39
  16. data/assets/test/src/test_helper.rb +4 -0
  17. data/lib/ruboto/commands/base.rb +29 -17
  18. data/lib/ruboto/sdk_versions.rb +1 -1
  19. data/lib/ruboto/util/emulator.rb +49 -33
  20. data/lib/ruboto/util/setup.rb +5 -1
  21. data/lib/ruboto/util/update.rb +68 -22
  22. data/lib/ruboto/util/xml_element.rb +5 -3
  23. data/lib/ruboto/version.rb +1 -1
  24. data/test/activity/call_super_activity.rb +2 -2
  25. data/test/activity/constants_activity.rb +51 -0
  26. data/test/activity/constants_activity_test.rb +18 -0
  27. data/test/activity/margins_activity.rb +12 -7
  28. data/test/activity/margins_activity_test.rb +10 -6
  29. data/test/activity/padding_activity.rb +15 -0
  30. data/test/activity/padding_activity_test.rb +41 -0
  31. data/test/activity/rss_activity.rb +42 -0
  32. data/test/activity/rss_activity_test.rb +35 -0
  33. data/test/activity/spinner_activity.rb +5 -5
  34. data/test/activity/spinner_activity_test.rb +6 -6
  35. data/test/activity/stack_activity.rb +7 -8
  36. data/test/activity/stack_activity_test.rb +7 -5
  37. data/test/activity/subclass_activity.rb +5 -5
  38. data/test/activity/subclass_activity_test.rb +8 -6
  39. data/test/app_test_methods.rb +8 -0
  40. data/test/arjdbc_test.rb +1 -1
  41. data/test/minimal_app_test.rb +12 -10
  42. data/test/rake_test.rb +2 -4
  43. data/test/ruboto_gen_test.rb +11 -9
  44. data/test/service_block_test.rb +112 -0
  45. data/test/{service_test.rb → service_gen_class_test.rb} +9 -4
  46. data/test/service_infile_class_test.rb +114 -0
  47. data/test/sqldroid_test.rb +1 -1
  48. data/test/test_helper.rb +39 -21
  49. metadata +11 -7
@@ -12,9 +12,11 @@ setup do |activity|
12
12
  assert @list_view
13
13
  end
14
14
 
15
- test('item click sets text') do |activity|
16
- activity.run_on_ui_thread { @list_view.performItemClick(@list_view, 1, 1) }
17
- assert_equal '[Record one]', @text_view.text
15
+ test('item click sets text', ui: false) do |activity|
16
+ activity.run_on_ui_thread do
17
+ @list_view.performItemClick(@list_view, 1, 1)
18
+ assert_equal '[Record one]', @text_view.text
19
+ end
18
20
  end
19
21
 
20
22
  class MyObject < java.lang.Object
@@ -30,12 +32,12 @@ class MyObject < java.lang.Object
30
32
  end
31
33
  end
32
34
 
33
- test('add constructor with parameter') do
35
+ test('add constructor with parameter', ui: false) do
34
36
  o = MyObject.new('It works!')
35
37
  assert_equal 'It works!', o.my_param
36
38
  end
37
39
 
38
- test('call instance method super') do
40
+ test('call instance method super', ui: false) do
39
41
  o = MyObject.new('It works!')
40
42
  assert !o.equals(o)
41
43
  end
@@ -46,7 +48,7 @@ class MyJRubyAdapter < org.ruboto.JRubyAdapter
46
48
  end
47
49
  end
48
50
 
49
- test('call super from static subclass method') do
51
+ test('call super from static subclass method', ui: false) do
50
52
  a = org.ruboto.JRubyAdapter
51
53
  b = MyJRubyAdapter
52
54
  assert a.isDebugBuild != b.isDebugBuild
@@ -38,6 +38,14 @@ module AppTestMethods
38
38
 
39
39
  def run_activity_tests(activity_dir)
40
40
  Dir[File.expand_path("#{activity_dir}/*", File.dirname(__FILE__))].each do |file|
41
+ # FIXME(uwe): Remove when we stop testing JRuby < 1.7.14
42
+ next if file =~ /rss/ && (JRUBY_JARS_VERSION < Gem::Version.new('1.7.14.dev'))
43
+ # EMXIF
44
+
45
+ # FIXME(uwe): Remove when we release RubotoCore based on JRuby 1.7.14
46
+ next if file =~ /rss/ && (RUBOTO_PLATFORM == 'CURRENT' || RUBOTO_PLATFORM == 'FROM_GEM')
47
+ # EMXIF
48
+
41
49
  # FIXME(uwe): Remove when we stop testing api level < 16
42
50
  # FIXME(uwe): Remove when we release RubotoCore with SSL included
43
51
  next if file =~ /ssl/ && (ANDROID_OS < 16 ||
data/test/arjdbc_test.rb CHANGED
@@ -41,7 +41,7 @@ class RubotoTestAppActivity
41
41
  super
42
42
  setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "\#{s[0..0].upcase}\#{s[1..-1]}" }.join(' ')
43
43
 
44
- @adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1 , AndroidIds::text1, [])
44
+ @adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1 , android.R.id.text1, [])
45
45
 
46
46
  self.content_view =
47
47
  linear_layout :orientation => LinearLayout::VERTICAL do
@@ -12,17 +12,18 @@ if RubotoTest::RUBOTO_PLATFORM == 'STANDALONE'
12
12
  cleanup_app
13
13
  end
14
14
 
15
- # APK was 4.4MB. JRuby: 1.7.4, ANDROID_TARGET: 10
16
- # APK was 4.3MB. JRuby: 1.7.4, ANDROID_TARGET: 16
17
- # APK was 4.3MB. JRuby: 1.7.5, ANDROID_TARGET: 10
18
- # APK was 4.2MB. JRuby: 1.7.5, ANDROID_TARGET: 15
19
- # APK was 4.3MB. JRuby: 1.7.5, ANDROID_TARGET: 16
20
- # APK was 8.4MB. JRuby: 1.7.8, ANDROID_TARGET: 10
21
- # APK was 4.3MB. JRuby: 1.7.8, ANDROID_TARGET: 16
15
+ # APK was 4.4MB. JRuby: 1.7.4, ANDROID_TARGET: 10
16
+ # APK was 4.3MB. JRuby: 1.7.4, ANDROID_TARGET: 16
17
+ # APK was 4.3MB. JRuby: 1.7.5, ANDROID_TARGET: 10
18
+ # APK was 4.2MB. JRuby: 1.7.5, ANDROID_TARGET: 15
19
+ # APK was 4.3MB. JRuby: 1.7.5, ANDROID_TARGET: 16
20
+ # APK was 8.4MB. JRuby: 1.7.8, ANDROID_TARGET: 10
21
+ # APK was 4.3MB. JRuby: 1.7.8, ANDROID_TARGET: 16
22
22
  # APK was 4.4MB. JRuby: 1.7.12, ANDROID_TARGET: 19
23
+ # APK was 4.4MB. JRuby: 1.7.14.SNAPSHOT, ANDROID_TARGET: 19
23
24
  # APK was 4.2MB. JRuby: 9000.dev, ANDROID_TARGET: 10
24
25
  # APK was 4.2MB. JRuby: 9000.dev, ANDROID_TARGET: 15
25
- # APK was 4.5MB. JRuby: 9000.dev, ANDROID_TARGET: 16
26
+ # APK was 4.6MB. JRuby: 9000.dev, ANDROID_TARGET: 16
26
27
  def test_minimal_apk_is_within_limits
27
28
  apk_size = BigDecimal(File.size("#{APP_DIR}/bin/RubotoTestApp-debug.apk").to_s) / (1024 * 1024)
28
29
  upper_limit = {
@@ -32,8 +33,9 @@ if RubotoTest::RUBOTO_PLATFORM == 'STANDALONE'
32
33
  '1.7.10' => 4.4,
33
34
  '1.7.11' => 4.4,
34
35
  '1.7.12' => 4.4,
35
- '9000.dev' => 4.5,
36
- }[JRUBY_JARS_VERSION.to_s] || 4.3
36
+ '1.7.14.dev' => 4.4,
37
+ '9000.dev' => 4.6,
38
+ }[JRUBY_JARS_VERSION.to_s] || 4.4
37
39
  lower_limit = upper_limit * 0.9
38
40
  version_message ="JRuby: #{JRUBY_JARS_VERSION}, ANDROID_TARGET: #{ANDROID_TARGET}"
39
41
  assert apk_size <= upper_limit, "APK was larger than #{'%.1f' % upper_limit}MB: #{'%.1f' % apk_size.ceil(1)}MB. #{version_message}"
data/test/rake_test.rb CHANGED
@@ -36,7 +36,6 @@ class RakeTest < Test::Unit::TestCase
36
36
  # source file instead of rebuilding the apk.
37
37
  def test_that_apk_is_built_if_only_one_ruby_source_file_has_changed
38
38
  Dir.chdir APP_DIR do
39
- system 'rake debug'
40
39
  apk_timestamp = File.mtime("bin/#{APP_NAME}-debug.apk")
41
40
  sleep 1
42
41
  FileUtils.touch 'src/ruboto_test_app_activity.rb'
@@ -49,7 +48,6 @@ class RakeTest < Test::Unit::TestCase
49
48
 
50
49
  def test_that_apk_is_built_if_only_one_non_ruby_source_file_has_changed
51
50
  Dir.chdir APP_DIR do
52
- system 'rake debug'
53
51
  apk_timestamp = File.mtime("bin/#{APP_NAME}-debug.apk")
54
52
  FileUtils.touch 'src/not_ruby_source.properties'
55
53
  system 'rake debug'
@@ -61,8 +59,8 @@ class RakeTest < Test::Unit::TestCase
61
59
  def test_that_manifest_is_updated_when_project_properties_are_changed
62
60
  Dir.chdir APP_DIR do
63
61
  manifest = File.read('AndroidManifest.xml')
64
- assert_equal "android:minSdkVersion='#{ANDROID_TARGET}'", manifest.slice(/android:minSdkVersion='\d+'/)
65
- assert_equal "android:targetSdkVersion='#{ANDROID_TARGET}'", manifest.slice(/android:targetSdkVersion='\d+'/)
62
+ assert_equal "android:minSdkVersion='#{ANDROID_TARGET}'", manifest[/android:minSdkVersion='[^']+'/]
63
+ assert_equal "android:targetSdkVersion='#{ANDROID_TARGET}'", manifest[/android:targetSdkVersion='[^']+'/]
66
64
  prop_file = File.read('project.properties')
67
65
  File.open('project.properties', 'w') { |f| f << prop_file.sub(/target=android-#{ANDROID_TARGET}/, 'target=android-6') }
68
66
  system 'rake debug'
@@ -49,7 +49,7 @@ class RubotoGenTest < Test::Unit::TestCase
49
49
  end
50
50
  end
51
51
 
52
- # APK was 59.6KB. PLATFORM: CURRENT, ANDROID_TARGET: 10
52
+ # APK was 66.3KB. PLATFORM: CURRENT, ANDROID_TARGET: 10
53
53
  # APK was 66.6KB. PLATFORM: CURRENT, ANDROID_TARGET: 15
54
54
  # APK was 74.9KB. PLATFORM: CURRENT, ANDROID_TARGET: 16
55
55
  # APK was 80.4KB. PLATFORM: CURRENT, ANDROID_TARGET: 19
@@ -69,10 +69,11 @@ class RubotoGenTest < Test::Unit::TestCase
69
69
  # APK was 8793.4KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 1.7.11
70
70
  # APK was 9743.3KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 1.7.12
71
71
  # APK was 9123.8KB. PLATFORM: STANDALONE, ANDROID_TARGET: 19, JRuby: 1.7.12
72
+ # APK was 9745.0KB. PLATFORM: STANDALONE, ANDROID_TARGET: 19, JRuby: 1.7.14.dev
72
73
  # APK was 6689.5KB. PLATFORM: STANDALONE, ANDROID_TARGET: 10, JRuby: 9000.dev
73
74
  # APK was 7012.2KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 9000.dev
74
75
  # APK was 8015.9KB. PLATFORM: STANDALONE, ANDROID_TARGET: 17, JRuby: 9000.dev
75
- # APK was 7386.1KB. PLATFORM: STANDALONE, ANDROID_TARGET: 19, JRuby: 9000.dev
76
+ # APK was 8232.4KB. PLATFORM: STANDALONE, ANDROID_TARGET: 19, JRuby: 9000.dev
76
77
  def test_new_apk_size_is_within_limits
77
78
  apk_size = BigDecimal(File.size("#{APP_DIR}/bin/RubotoTestApp-debug.apk").to_s) / 1024
78
79
  version = " PLATFORM: #{RUBOTO_PLATFORM}"
@@ -87,19 +88,20 @@ class RubotoGenTest < Test::Unit::TestCase
87
88
  '1.7.10' => 8800.0,
88
89
  '1.7.11' => 8800.0,
89
90
  '1.7.12' => 9800.0,
90
- '9000.dev' => 8100.0,
91
- }[JRUBY_JARS_VERSION.to_s] || 0.0
91
+ '1.7.14.dev' => 9800.0,
92
+ '9000.dev' => 8300.0,
93
+ }[JRUBY_JARS_VERSION.to_s] || 9800.0
92
94
  version << ", JRuby: #{JRUBY_JARS_VERSION.to_s}"
93
95
  else
94
96
  upper_limit = {
95
- 10 => 66.0,
97
+ 10 => 67.0,
96
98
  15 => 67.0,
97
99
  16 => 82.0,
98
100
  17 => 81.0,
99
101
  19 => 81.0,
100
102
  }[ANDROID_TARGET] || 75.0
101
103
  end
102
- lower_limit = upper_limit * 0.7
104
+ lower_limit = upper_limit * 0.8
103
105
  assert apk_size <= upper_limit, "APK was larger than #{'%.1f' % upper_limit}KB: #{'%.1f' % apk_size.ceil(1)}KB.#{version}"
104
106
  assert apk_size >= lower_limit, "APK was smaller than #{'%.1f' % lower_limit}KB: #{'%.1f' % apk_size.floor(1)}KB. You should lower the limit.#{version}"
105
107
  end
@@ -144,7 +146,7 @@ class RubotoTestAppActivity
144
146
  set_title 'ListView Example'
145
147
 
146
148
  records = [{:text1 => 'First row'}, {:image => resources.get_drawable($package.R::drawable::get_ruboto_core), :text1 => 'Second row'}, 'Third row']
147
- adapter = $package.RubotoArrayAdapter.new(self, $package.R::layout::list_item, AndroidIds::text1, records)
149
+ adapter = $package.RubotoArrayAdapter.new(self, $package.R::layout::list_item, android.R.id.text1, records)
148
150
  puts "adapter: \#{adapter.inspect}"
149
151
  self.content_view =
150
152
  linear_layout :orientation => :vertical do
@@ -196,7 +198,7 @@ class RubotoArrayAdapter
196
198
  if convert_view
197
199
  row = convert_view
198
200
  row.findViewById(Ruboto::Id.image).image_drawable = nil
199
- row.findViewById(AndroidIds.text1).text = nil
201
+ row.findViewById(android.R.id.text1).text = nil
200
202
  else
201
203
  row = @inflater.inflate(mResource, nil)
202
204
  end
@@ -207,7 +209,7 @@ class RubotoArrayAdapter
207
209
  model.each do |field, value|
208
210
  begin
209
211
  field_id = Ruboto::Id.respond_to?(field) && Ruboto::Id.send(field) ||
210
- AndroidIds.respond_to?(field) && AndroidIds.send(field)
212
+ android.R.id.respond_to?(field) && android.R.id.send(field)
211
213
  field_view = row.findViewById(field_id)
212
214
  case value
213
215
  when String
@@ -0,0 +1,112 @@
1
+ require File.expand_path("test_helper", File.dirname(__FILE__))
2
+ require 'fileutils'
3
+
4
+ class ServiceBlockTest < Test::Unit::TestCase
5
+ SRC_DIR = "#{APP_DIR}/src"
6
+
7
+ def setup
8
+ generate_app
9
+ end
10
+
11
+ def teardown
12
+ cleanup_app
13
+ end
14
+
15
+ def test_service_startup
16
+ # FIXME(uwe): Remove when Android L is released or service start is fixed
17
+ return if ANDROID_OS == 21
18
+ # EMXIF
19
+
20
+ Dir.chdir APP_DIR do
21
+ activity_filename = "#{SRC_DIR}/ruboto_test_app_activity.rb"
22
+ assert File.exists? activity_filename
23
+ File.open(activity_filename, 'w') { |f| f << <<EOF }
24
+ require 'ruboto/activity'
25
+ require 'ruboto/widget'
26
+ require 'ruboto/service'
27
+
28
+ ruboto_import_widgets :Button, :LinearLayout, :TextView
29
+
30
+ class RubotoTestAppActivity
31
+ def onCreate(bundle)
32
+ super
33
+ $ruboto_test_app_activity = self
34
+ set_title 'Domo arigato, Mr Ruboto!'
35
+
36
+ self.content_view =
37
+ linear_layout :orientation => :vertical do
38
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42,
39
+ :layout => {:width => :fill_parent},
40
+ :gravity => android.view.Gravity::CENTER, :text_size => 48.0
41
+ button :text => 'M-x butterfly', :layout => {:width => :fill_parent},
42
+ :id => 43, :on_click_listener => proc { butterfly }
43
+ end
44
+ rescue
45
+ puts "Exception creating activity: \#{$!}"
46
+ puts $!.backtrace.join("\\n")
47
+ end
48
+
49
+ def set_text(text)
50
+ @text_view.text = text
51
+ end
52
+
53
+ private
54
+
55
+ def butterfly
56
+ puts 'butterfly'
57
+ Thread.start do
58
+ begin
59
+ start_ruboto_service do
60
+ def onStartCommand(intent, flags, start_id)
61
+ puts "service on_start_command(\#{intent}, \#{flags}, \#{start_id})"
62
+ $ruboto_test_app_activity.set_title 'on_start_command'
63
+ $ruboto_test_app_activity.set_text 'What hath Matz wrought!'
64
+
65
+ android.app.Service::START_STICKY
66
+ end
67
+ end
68
+ rescue Exception
69
+ puts "Exception starting the service: \#{$!}"
70
+ puts $!.backtrace.join("\\n")
71
+ end
72
+ end
73
+ puts 'butterfly OK'
74
+ end
75
+
76
+ end
77
+ EOF
78
+
79
+ service_test_filename = "#{APP_DIR}/test/src/ruboto_test_app_activity_test.rb"
80
+ assert File.exists? service_test_filename
81
+ File.open(service_test_filename, 'w') { |f| f << <<EOF }
82
+ activity Java::org.ruboto.test_app.RubotoTestAppActivity
83
+
84
+ setup do |activity|
85
+ start = Time.now
86
+ loop do
87
+ @text_view = activity.findViewById(42)
88
+ break if @text_view || (Time.now - start > 60)
89
+ sleep 1
90
+ end
91
+ assert @text_view
92
+ end
93
+
94
+ test 'button changes text', :ui => false do |activity|
95
+ button = activity.findViewById(43)
96
+ puts 'Clicking...'
97
+ activity.run_on_ui_thread{button.performClick}
98
+ puts 'Clicked!'
99
+ start = Time.now
100
+ loop do
101
+ break if @text_view.text == 'What hath Matz wrought!' || (Time.now - start > 60)
102
+ sleep 1
103
+ end
104
+ assert_equal 'What hath Matz wrought!', @text_view.text
105
+ end
106
+ EOF
107
+
108
+ end
109
+ run_app_tests
110
+ end
111
+
112
+ end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path("test_helper", File.dirname(__FILE__))
2
2
  require 'fileutils'
3
3
 
4
- class ServiceTest < Test::Unit::TestCase
4
+ class ServiceGenClassTest < Test::Unit::TestCase
5
5
  SRC_DIR = "#{APP_DIR}/src"
6
6
 
7
7
  def setup
@@ -13,6 +13,10 @@ class ServiceTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  def test_service_startup
16
+ # FIXME(uwe): Remove when Android L is released or service start is fixed
17
+ return if ANDROID_OS == 21
18
+ # EMXIF
19
+
16
20
  Dir.chdir APP_DIR do
17
21
  system "#{RUBOTO_CMD} gen class Service --name RubotoTestService"
18
22
 
@@ -21,6 +25,7 @@ class ServiceTest < Test::Unit::TestCase
21
25
  File.open(activity_filename, 'w') { |f| f << <<EOF }
22
26
  require 'ruboto/activity'
23
27
  require 'ruboto/widget'
28
+ require 'ruboto/service'
24
29
 
25
30
  ruboto_import_widgets :Button, :LinearLayout, :TextView
26
31
 
@@ -53,7 +58,9 @@ class RubotoTestAppActivity
53
58
  puts 'butterfly'
54
59
  Thread.start do
55
60
  begin
56
- startService(android.content.Intent.new(application_context, $package.RubotoTestService.java_class))
61
+ puts 'activity start service...'
62
+ start_ruboto_service("RubotoTestService")
63
+ puts 'activity start service...OK'
57
64
  rescue Exception
58
65
  puts "Exception starting the service: \#{$!}"
59
66
  puts $!.backtrace.join("\\n")
@@ -68,8 +75,6 @@ EOF
68
75
  service_filename = "#{SRC_DIR}/ruboto_test_service.rb"
69
76
  assert File.exists? service_filename
70
77
  File.open(service_filename, 'w') { |f| f << <<EOF }
71
- require 'ruboto/service'
72
-
73
78
  class RubotoTestService
74
79
  TARGET_TEXT = 'What hath Matz wrought!'
75
80
 
@@ -0,0 +1,114 @@
1
+ require File.expand_path("test_helper", File.dirname(__FILE__))
2
+ require 'fileutils'
3
+
4
+ class ServiceInfileClassTest < Test::Unit::TestCase
5
+ SRC_DIR = "#{APP_DIR}/src"
6
+
7
+ def setup
8
+ generate_app
9
+ end
10
+
11
+ def teardown
12
+ cleanup_app
13
+ end
14
+
15
+ def test_service_startup
16
+ # FIXME(uwe): Remove when Android L is released or service start is fixed
17
+ return if ANDROID_OS == 21
18
+ # EMXIF
19
+
20
+ Dir.chdir APP_DIR do
21
+ activity_filename = "#{SRC_DIR}/ruboto_test_app_activity.rb"
22
+ assert File.exists? activity_filename
23
+ File.open(activity_filename, 'w') { |f| f << <<EOF }
24
+ require 'ruboto/activity'
25
+ require 'ruboto/widget'
26
+ require 'ruboto/service'
27
+
28
+ ruboto_import_widgets :Button, :LinearLayout, :TextView
29
+
30
+ class RubotoServiceClass
31
+ def onStartCommand(intent, flags, start_id)
32
+ puts "service on_start_command(\#{intent}, \#{flags}, \#{start_id})"
33
+ $ruboto_test_app_activity.set_title 'on_start_command'
34
+ $ruboto_test_app_activity.set_text 'What hath Matz wrought!'
35
+
36
+ android.app.Service::START_STICKY
37
+ end
38
+ end
39
+
40
+ class RubotoTestAppActivity
41
+ def onCreate(bundle)
42
+ super
43
+ $ruboto_test_app_activity = self
44
+ set_title 'Domo arigato, Mr Ruboto!'
45
+
46
+ self.content_view =
47
+ linear_layout :orientation => :vertical do
48
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42,
49
+ :layout => {:width => :fill_parent},
50
+ :gravity => android.view.Gravity::CENTER, :text_size => 48.0
51
+ button :text => 'M-x butterfly', :layout => {:width => :fill_parent},
52
+ :id => 43, :on_click_listener => proc { butterfly }
53
+ end
54
+ rescue
55
+ puts "Exception creating activity: \#{$!}"
56
+ puts $!.backtrace.join("\\n")
57
+ end
58
+
59
+ def set_text(text)
60
+ @text_view.text = text
61
+ end
62
+
63
+ private
64
+
65
+ def butterfly
66
+ puts 'butterfly'
67
+ Thread.start do
68
+ begin
69
+ start_ruboto_service "RubotoServiceClass"
70
+ rescue Exception
71
+ puts "Exception starting the service: \#{$!}"
72
+ puts $!.backtrace.join("\\n")
73
+ end
74
+ end
75
+ puts 'butterfly OK'
76
+ end
77
+
78
+ end
79
+ EOF
80
+
81
+ service_test_filename = "#{APP_DIR}/test/src/ruboto_test_app_activity_test.rb"
82
+ assert File.exists? service_test_filename
83
+ File.open(service_test_filename, 'w') { |f| f << <<EOF }
84
+ activity Java::org.ruboto.test_app.RubotoTestAppActivity
85
+
86
+ setup do |activity|
87
+ start = Time.now
88
+ loop do
89
+ @text_view = activity.findViewById(42)
90
+ break if @text_view || (Time.now - start > 60)
91
+ sleep 1
92
+ end
93
+ assert @text_view
94
+ end
95
+
96
+ test 'button changes text', :ui => false do |activity|
97
+ button = activity.findViewById(43)
98
+ puts 'Clicking...'
99
+ activity.run_on_ui_thread{button.performClick}
100
+ puts 'Clicked!'
101
+ start = Time.now
102
+ loop do
103
+ break if @text_view.text == 'What hath Matz wrought!' || (Time.now - start > 60)
104
+ sleep 1
105
+ end
106
+ assert_equal 'What hath Matz wrought!', @text_view.text
107
+ end
108
+ EOF
109
+
110
+ end
111
+ run_app_tests
112
+ end
113
+
114
+ end