ruboto 0.9.0 → 0.10.0.rc.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 (71) hide show
  1. data/README.md +13 -13
  2. data/Rakefile +4 -4
  3. data/assets/rakelib/ruboto.rake +8 -4
  4. data/assets/samples/sample_broadcast_receiver.rb +0 -8
  5. data/assets/src/InheritingBroadcastReceiver.java +0 -19
  6. data/assets/src/InheritingClass.java +1 -8
  7. data/assets/src/RubotoActivity.java +1 -20
  8. data/assets/src/RubotoBroadcastReceiver.java +15 -25
  9. data/assets/src/RubotoService.java +1 -15
  10. data/assets/src/org/ruboto/EntryPointActivity.java +0 -1
  11. data/assets/src/org/ruboto/JRubyAdapter.java +9 -8
  12. data/assets/src/org/ruboto/RubotoComponent.java +0 -3
  13. data/assets/src/org/ruboto/Script.java +9 -9
  14. data/assets/src/org/ruboto/ScriptInfo.java +0 -15
  15. data/assets/src/org/ruboto/ScriptLoader.java +31 -43
  16. data/assets/src/ruboto/activity.rb +16 -41
  17. data/assets/src/ruboto/base.rb +0 -70
  18. data/assets/src/ruboto/broadcast_receiver.rb +2 -22
  19. data/assets/src/ruboto/package.rb +0 -1
  20. data/assets/src/ruboto/preference.rb +7 -3
  21. data/assets/src/ruboto/service.rb +14 -51
  22. data/assets/src/ruboto/widget.rb +2 -2
  23. data/lib/DexClient.java +10 -3
  24. data/lib/ruboto/util/build.rb +0 -5
  25. data/lib/ruboto/util/code_formatting.rb +1 -1
  26. data/lib/ruboto/util/update.rb +69 -50
  27. data/lib/ruboto/util/verify.rb +6 -5
  28. data/lib/ruboto/util/xml_element.rb +16 -29
  29. data/lib/ruboto/version.rb +2 -2
  30. data/test/activity/mytest_activity.rb +56 -0
  31. data/test/activity/mytest_activity_test.rb +52 -0
  32. data/test/activity/mytest_otherfile_activity.rb +12 -0
  33. data/test/activity/navigation_activity.rb +1 -1
  34. data/test/activity/subclass_activity.rb +10 -5
  35. data/test/activity/subclass_activity_test.rb +17 -2
  36. data/test/activity/view_constants_activity.rb +42 -0
  37. data/test/activity/view_constants_activity_test.rb +30 -0
  38. data/test/app_test_methods.rb +31 -26
  39. data/test/broadcast_receiver_test.rb +3 -1
  40. data/test/ruboto_gen_test.rb +4 -4
  41. data/test/test_helper.rb +5 -2
  42. metadata +18 -38
  43. data/assets/src/ruboto.rb +0 -25
  44. data/assets/src/ruboto/legacy.rb +0 -220
  45. data/assets/src/ruboto/menu.rb +0 -88
  46. data/lib/java_class_gen/InheritingClass.java.erb +0 -10
  47. data/test/block_def_activity/image_button_activity.rb +0 -23
  48. data/test/block_def_activity/image_button_activity_test.rb +0 -21
  49. data/test/block_def_activity/image_button_and_button_activity.rb +0 -20
  50. data/test/block_def_activity/image_button_and_button_activity_test.rb +0 -27
  51. data/test/block_def_activity/margins_activity.rb +0 -18
  52. data/test/block_def_activity/margins_activity_test.rb +0 -25
  53. data/test/block_def_activity/option_menu_activity.rb +0 -26
  54. data/test/block_def_activity/option_menu_activity_test.rb +0 -17
  55. data/test/block_def_activity/psych_activity.rb +0 -35
  56. data/test/block_def_activity/psych_activity_test.rb +0 -16
  57. data/test/block_def_activity/stack_activity.rb +0 -25
  58. data/test/block_def_activity/stack_activity_test.rb +0 -39
  59. data/test/handle_activity/image_button_activity.rb +0 -21
  60. data/test/handle_activity/image_button_activity_test.rb +0 -21
  61. data/test/handle_activity/image_button_and_button_activity.rb +0 -24
  62. data/test/handle_activity/image_button_and_button_activity_test.rb +0 -27
  63. data/test/handle_activity/margins_activity.rb +0 -15
  64. data/test/handle_activity/margins_activity_test.rb +0 -25
  65. data/test/handle_activity/option_menu_activity.rb +0 -25
  66. data/test/handle_activity/option_menu_activity_test.rb +0 -20
  67. data/test/handle_activity/psych_activity.rb +0 -31
  68. data/test/handle_activity/psych_activity_test.rb +0 -16
  69. data/test/handle_activity/stack_activity.rb +0 -24
  70. data/test/handle_activity/stack_activity_test.rb +0 -47
  71. data/test/view_constants_test.rb +0 -103
data/assets/src/ruboto.rb DELETED
@@ -1,25 +0,0 @@
1
- #######################################################
2
- #
3
- # ruboto.rb
4
- #
5
- # - Wrapper for using RubotoActivity, RubotoService, and
6
- # RubotoBroadcastReceiver.
7
- # - Provides interface for generating UI elements.
8
- # - Imports and configures callback classes.
9
- #
10
- # require this script for legacy support or require
11
- # the individual script files.
12
- #
13
- #######################################################
14
-
15
- require 'ruboto/base'
16
- require 'ruboto/package'
17
- require 'ruboto/activity'
18
- require 'ruboto/service'
19
- require 'ruboto/broadcast_receiver'
20
-
21
- require 'ruboto/widget'
22
- require 'ruboto/menu'
23
- require 'ruboto/util/stack'
24
- require 'ruboto/util/toast'
25
- require 'ruboto/legacy'
@@ -1,220 +0,0 @@
1
- require 'ruboto/activity'
2
-
3
- #######################################################
4
- #
5
- # ruboto/legacy.rb
6
- #
7
- # Required for backwards compatibility. The goal
8
- # should be to run scripts without this.
9
- #
10
- #######################################################
11
-
12
- #
13
- # Old handle methods
14
- #
15
-
16
- module Ruboto
17
- module Callbacks
18
- def method_missing(name, *args, &block)
19
- if name.to_s =~ /^handle_(.*)/ && self.class.respond_to?(:const_get) && (const = self.class.const_get("CB_#{$1.upcase}"))
20
- scriptInfo.setCallbackProc(const, block)
21
- self
22
- else
23
- super
24
- end
25
- end
26
-
27
- def respond_to?(name)
28
- return true if name.to_s =~ /^handle_(.*)/ && self.class.respond_to?(:const_get) && self.class.const_get("CB_#{$1.upcase}")
29
- super
30
- end
31
-
32
- def initialize_handlers(&block)
33
- instance_eval &block
34
- self
35
- end
36
- end
37
- end
38
-
39
- #
40
- # Old handle_create for Activities
41
- #
42
-
43
- module Ruboto
44
- module Activity
45
- def handle_finish_create &block
46
- @finish_create_block = block
47
- end
48
-
49
- def setup_content &block
50
- @view_parent = nil
51
- @content_view_block = block
52
- end
53
-
54
- def handle_create(&block)
55
- $new_context_global = "$activity"
56
- instance_exec &block
57
- initialize_ruboto
58
- on_create nil
59
- end
60
- end
61
- end
62
-
63
- RubotoActivity.class_eval do
64
- def on_create(bundle)
65
- @view_parent = nil
66
- setContentView(instance_eval &@content_view_block) if @content_view_block
67
- instance_eval { @finish_create_block.call } if @finish_create_block
68
- end
69
- end
70
-
71
- #
72
- # Allow IRB legacy
73
- #
74
-
75
- if $package_name == "org.ruboto.irb"
76
- Java::org.ruboto.irb.IRB.class_eval do
77
- def handle_create(&block)
78
- start_ruboto_activity "$activity", RubotoActivity, nil, &block
79
- end
80
- end
81
- end
82
-
83
- #
84
- # Legacy Service Subclass Setup
85
- #
86
-
87
- module Ruboto
88
- module Service
89
- def handle_create(&block)
90
- $new_context_global = "$service"
91
- instance_exec &block
92
- initialize_ruboto
93
- on_create
94
- end
95
- end
96
- end
97
-
98
- #
99
- # Legacy BroadcastReceiver Subclass Setup
100
- #
101
-
102
- module Ruboto
103
- module BroadcastReceiver
104
- def handle_receive(&block)
105
- instance_exec &block
106
- on_receive($context, nil)
107
- end
108
- end
109
- end
110
-
111
- #
112
- # Allows RubotoActivity to handle callbacks covering Class based handlers
113
- #
114
-
115
- def ruboto_register_handler(unique_name, for_class, method_name)
116
- unless RubotoActivity.method_defined? "#{unique_name}_handler"
117
- RubotoActivity.class_eval "
118
- def #{unique_name}_handler
119
- @#{unique_name}_handler
120
- end
121
-
122
- def handle_#{unique_name}(&block)
123
- @#{unique_name}_handler = block
124
- self
125
- end
126
- "
127
- end
128
-
129
- unless for_class.method_defined? "orig_#{method_name}"
130
- for_class.class_eval "
131
- alias_method :orig_#{method_name}, :#{method_name}
132
- def #{method_name}(handler)
133
- orig_#{method_name}(handler.kind_of?(RubotoActivity) ? handler.#{unique_name}_handler : handler)
134
- end
135
- "
136
- end
137
- end
138
-
139
- def setup_button
140
- Button.class_eval do
141
- def configure(context, params = {})
142
- setOnClickListener(context)
143
- super(context, params)
144
- end
145
- end
146
-
147
- ruboto_register_handler("click", Button, "setOnClickListener")
148
- end
149
-
150
- def setup_image_button
151
- ImageButton.class_eval do
152
- def configure(context, params = {})
153
- setOnClickListener(context)
154
- super(context, params)
155
- end
156
- end
157
-
158
- ruboto_register_handler("click", ImageButton, "setOnClickListener")
159
- end
160
-
161
- def setup_list_view
162
- Java::android.widget.ListView.class_eval do
163
- attr_reader :adapter, :adapter_list
164
-
165
- def configure(context, params = {})
166
- if params.has_key? :list
167
- @adapter_list = Java::java.util.ArrayList.new
168
- @adapter_list.addAll(params[:list])
169
- item_layout = params.delete(:item_layout) || R::layout::simple_list_item_1
170
- @adapter = Java::android.widget.ArrayAdapter.new(context, item_layout, @adapter_list)
171
- setAdapter @adapter
172
- params.delete :list
173
- end
174
- if params.has_key? :adapter
175
- @adapter = params[:adapter]
176
- end
177
- setOnItemClickListener(context) # legacy
178
- super(context, params)
179
- end
180
-
181
- def reload_list(list)
182
- @adapter_list.clear
183
- @adapter_list.addAll(list)
184
- @adapter.notifyDataSetChanged
185
- invalidate
186
- end
187
- end
188
-
189
- ruboto_register_handler("item_click", Java::android.widget.ListView, "setOnItemClickListener") # legacy
190
- end
191
-
192
- def setup_spinner
193
- Java::android.widget.Spinner.class_eval do
194
- attr_reader :adapter, :adapter_list
195
-
196
- def configure(context, params = {})
197
- if params.has_key? :list
198
- @adapter_list = Java::java.util.ArrayList.new
199
- @adapter_list.addAll(params[:list])
200
- item_layout = params.delete(:item_layout) || R::layout::simple_spinner_item
201
- @adapter = Java::android.widget.ArrayAdapter.new(context, item_layout, @adapter_list)
202
- @adapter.setDropDownViewResource(params.delete(:dropdown_layout) || R::layout::simple_spinner_dropdown_item)
203
- setAdapter @adapter
204
- params.delete :list
205
- end
206
- setOnItemSelectedListener(context) # legacy
207
- super(context, params)
208
- end
209
-
210
- def reload_list(list)
211
- @adapter.clear
212
- @adapter.addAll(list)
213
- @adapter.notifyDataSetChanged
214
- invalidate
215
- end
216
- end
217
-
218
- ruboto_register_handler("item_selected", Java::android.widget.Spinner, "setOnItemSelectedListener") # legacy
219
- end
220
-
@@ -1,88 +0,0 @@
1
- require 'ruboto/activity'
2
-
3
- #######################################################
4
- #
5
- # ruboto/menu.rb
6
- #
7
- # Make using menus a little easier. This is still using
8
- # handle methods and may be moved into legacy code.
9
- #
10
- #######################################################
11
-
12
- module Ruboto
13
- module Activity
14
- #
15
- # Option Menus
16
- #
17
- def add_menu title, icon=nil, &block
18
- mi = @menu.add(title)
19
- mi.setIcon(icon) if icon
20
- mi.class.class_eval { attr_accessor :on_click }
21
- mi.on_click = block
22
-
23
- # Seems to be needed or the block might get cleaned up
24
- @all_menu_items = [] unless @all_menu_items
25
- @all_menu_items << mi
26
- end
27
-
28
- def handle_create_options_menu &block
29
- p = Proc.new do |*args|
30
- @menu = args[0]
31
- instance_eval { block.call(*args) } if block
32
- end
33
- scriptInfo.setCallbackProc(self.class.const_get("CB_CREATE_OPTIONS_MENU"), p)
34
-
35
- p = Proc.new do |num, menu_item|
36
- # handles a problem where this is called for context items
37
- # TODO(uwe): Remove check for SDK version when we stop supporting api level < 11
38
- unless @just_processed_context_item == menu_item || (android.os.Build::VERSION::SDK_INT >= 11 && menu_item.item_id == AndroidIds.home)
39
- instance_eval &(menu_item.on_click)
40
- @just_processed_context_item = nil
41
- true
42
- else
43
- false
44
- end
45
- end
46
- scriptInfo.setCallbackProc(self.class.const_get("CB_MENU_ITEM_SELECTED"), p)
47
- end
48
-
49
- #
50
- # Context Menus
51
- #
52
-
53
- def add_context_menu title, &block
54
- mi = @context_menu.add(title)
55
- mi.class.class_eval { attr_accessor :on_click }
56
- mi.on_click = block
57
-
58
- # Seems to be needed or the block might get cleaned up
59
- @all_menu_items = [] unless @all_menu_items
60
- @all_menu_items << mi
61
- end
62
-
63
- def handle_create_context_menu &block
64
- p = Proc.new do |*args|
65
- @context_menu = args[0]
66
- instance_eval { block.call(*args) } if block
67
- end
68
- scriptInfo.setCallbackProc(self.class.const_get("CB_CREATE_CONTEXT_MENU"), p)
69
-
70
- p = Proc.new do |menu_item|
71
- if menu_item.on_click
72
- arg = menu_item
73
- begin
74
- arg = menu_item.getMenuInfo.position
75
- rescue
76
- end
77
- instance_eval { menu_item.on_click.call(arg) }
78
- @just_processed_context_item = menu_item
79
- true
80
- else
81
- false
82
- end
83
- end
84
- scriptInfo.setCallbackProc(self.class.const_get("CB_CONTEXT_ITEM_SELECTED"), p)
85
- end
86
- end
87
- end
88
-
@@ -1,10 +0,0 @@
1
- package THE_PACKAGE;
2
-
3
- public class Inheriting<%= @class %> extends org.ruboto.Ruboto<%= @class %> {
4
- % v = @callbacks[@full_class][@first_method]
5
- public <%= "#{v["return_type"]} #{v["interface_method"]}(#{v["args_with_types"] })" %> {
6
- setScriptName("start.rb");
7
- super.<%= @first_method %>(<%= v["args_alone"].join(',') %>);
8
- }
9
-
10
- }
@@ -1,23 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,27 +0,0 @@
1
- activity Java::org.ruboto.test_app.ImageButtonAndButtonActivity
2
-
3
- setup do |activity|
4
- start = Time.now
5
- loop do
6
- @text_view = activity.find_view_by_id 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.find_view_by_id 44
19
- button.perform_click
20
- assert_equal 'Button pressed', @text_view.text
21
- end
22
-
23
- test('image button changes text') do |activity|
24
- image_button = activity.find_view_by_id 43
25
- image_button.perform_click
26
- assert_equal 'Image button pressed', @text_view.text
27
- end
@@ -1,18 +0,0 @@
1
- require 'ruboto/activity'
2
- require 'ruboto/widget'
3
-
4
- ruboto_import_widgets :LinearLayout, :TextView
5
-
6
- $activity.start_ruboto_activity do
7
- setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
8
-
9
- def on_create(bundle)
10
- self.content_view =
11
- linear_layout :orientation => LinearLayout::VERTICAL do
12
- @text_view_margins = text_view :text => 'What hath Matz wrought?', :id => 42, :margins => [100,0,0,0]
13
- @text_view_layout = text_view :text => 'What hath Matz wrought?', :id => 43, :layout => {:set_margins => [100,0,0,0]}
14
- @text_view_fieldset = text_view :text => 'What hath Matz wrought?', :id => 44, :layout => {:left_margin= => 100}
15
- end
16
- end
17
- end
18
-