ruboto 0.5.2 → 0.5.3
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.
- data/Gemfile.lock +5 -5
- data/README.md +2 -2
- data/Rakefile +5 -6
- data/assets/Rakefile +32 -11
- data/assets/res/drawable/get_ruboto_core.png +0 -0
- data/assets/res/layout/get_ruboto_core.xml +1 -1
- data/assets/samples/sample_activity.rb +13 -11
- data/assets/samples/sample_broadcast_receiver.rb +6 -3
- data/assets/samples/sample_service.rb +10 -7
- data/assets/src/InheritingActivity.java +1 -186
- data/assets/src/RubotoActivity.java +9 -11
- data/assets/src/RubotoBroadcastReceiver.java +34 -27
- data/assets/src/RubotoService.java +9 -2
- data/assets/src/org/ruboto/EntryPointActivity.java +194 -0
- data/assets/src/org/ruboto/Script.java +29 -15
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +17 -16
- data/assets/src/ruboto.rb +11 -608
- data/assets/src/ruboto/activity.rb +84 -0
- data/assets/src/ruboto/base.rb +88 -0
- data/assets/src/ruboto/broadcast_receiver.rb +31 -0
- data/assets/src/ruboto/legacy.rb +223 -0
- data/assets/src/ruboto/menu.rb +89 -0
- data/assets/src/ruboto/preference.rb +78 -0
- data/assets/src/ruboto/service.rb +74 -0
- data/assets/src/ruboto/util/stack.rb +34 -0
- data/assets/src/ruboto/util/toast.rb +18 -0
- data/assets/src/ruboto/widget.rb +188 -0
- data/assets/test/{assets/scripts → src}/test_helper.rb +4 -0
- data/bin/ruboto +7 -0
- data/lib/ruboto/commands/base.rb +4 -18
- data/lib/ruboto/util/build.rb +1 -2
- data/lib/ruboto/util/update.rb +77 -70
- data/lib/ruboto/version.rb +1 -1
- data/test/activity/psych_activity.rb +25 -0
- data/test/activity/psych_activity_test.rb +16 -0
- data/test/activity/stack_activity_test.rb +1 -1
- data/test/app_test_methods.rb +8 -4
- data/test/minimal_app_test.rb +6 -3
- data/test/rake_test.rb +1 -1
- data/test/ruboto_gen_test.rb +10 -1
- data/test/test_helper.rb +3 -5
- data/test/update_test_methods.rb +2 -2
- metadata +20 -8
- data/test/ruboto_gen_with_psych_test.rb +0 -16
- data/test/ruboto_update_with_psych_test.rb +0 -18
@@ -0,0 +1,78 @@
|
|
1
|
+
#######################################################
|
2
|
+
#
|
3
|
+
# ruboto/preference.rb
|
4
|
+
#
|
5
|
+
# Basic set up for preferences (activity and widgets).
|
6
|
+
#
|
7
|
+
#######################################################
|
8
|
+
|
9
|
+
require 'ruboto/activity'
|
10
|
+
|
11
|
+
java_import "android.preference.PreferenceScreen"
|
12
|
+
java_import "android.preference.Preference"
|
13
|
+
ruboto_import "org.ruboto.RubotoPreferenceActivity"
|
14
|
+
ruboto_configure_activity(RubotoPreferenceActivity)
|
15
|
+
|
16
|
+
RubotoPreferenceActivity.class_eval do
|
17
|
+
def preference_screen(params={})
|
18
|
+
rv = self.getPreferenceManager.createPreferenceScreen(self)
|
19
|
+
rv.configure self, params
|
20
|
+
@parent.addPreference(rv) if @parent
|
21
|
+
if block_given?
|
22
|
+
old_parent, @parent = @parent, rv
|
23
|
+
yield
|
24
|
+
@parent = old_parent
|
25
|
+
end
|
26
|
+
rv
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_preference_screen &block
|
30
|
+
@preference_screen_block = block
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_create(bundle)
|
34
|
+
@parent = nil
|
35
|
+
setPreferenceScreen(instance_eval &@preference_screen_block) if @preference_screen_block
|
36
|
+
instance_eval { @finish_create_block.call } if @finish_create_block
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Preference.class_eval do
|
41
|
+
def configure(context, params = {})
|
42
|
+
params.each do |k, v|
|
43
|
+
if v.is_a?(Array)
|
44
|
+
self.send("set#{k.to_s.gsub(/(^|_)([a-z])/) { $2.upcase }}", *v)
|
45
|
+
else
|
46
|
+
self.send("set#{k.to_s.gsub(/(^|_)([a-z])/) { $2.upcase }}", v)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# RubotoPreferenceActivity Preference Generation
|
54
|
+
#
|
55
|
+
|
56
|
+
def ruboto_import_preferences(*preferences)
|
57
|
+
preferences.each { |i| ruboto_import_preference i }
|
58
|
+
end
|
59
|
+
|
60
|
+
def ruboto_import_preference(class_name, package_name="android.preference")
|
61
|
+
klass = java_import("#{package_name}.#{class_name}") || eval("Java::#{package_name}.#{class_name}")
|
62
|
+
return unless klass
|
63
|
+
|
64
|
+
RubotoPreferenceActivity.class_eval "
|
65
|
+
def #{(class_name.to_s.gsub(/([A-Z])/) { '_' + $1.downcase })[1..-1]}(params={})
|
66
|
+
rv = #{class_name}.new self
|
67
|
+
rv.configure self, params
|
68
|
+
@parent.addPreference(rv) if @parent
|
69
|
+
if block_given?
|
70
|
+
old_parent, @parent = @parent, rv
|
71
|
+
yield
|
72
|
+
@parent = old_parent
|
73
|
+
end
|
74
|
+
rv
|
75
|
+
end
|
76
|
+
"
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'ruboto/base'
|
2
|
+
|
3
|
+
#######################################################
|
4
|
+
#
|
5
|
+
# ruboto/service.rb
|
6
|
+
#
|
7
|
+
# Basic service set up and callback configuration.
|
8
|
+
#
|
9
|
+
#######################################################
|
10
|
+
|
11
|
+
#
|
12
|
+
# Context
|
13
|
+
#
|
14
|
+
|
15
|
+
module Ruboto
|
16
|
+
module Context
|
17
|
+
def initialize_ruboto()
|
18
|
+
eval("#{$new_context_global} = self")
|
19
|
+
$new_context_global = nil
|
20
|
+
|
21
|
+
instance_eval &$context_init_block if $context_init_block
|
22
|
+
$context_init_block = nil
|
23
|
+
setup_ruboto_callbacks
|
24
|
+
|
25
|
+
@initialized = true
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_ruboto_service(global_variable_name = '$service', klass=RubotoService, &block)
|
30
|
+
$context_init_block = block
|
31
|
+
$new_context_global = global_variable_name
|
32
|
+
|
33
|
+
if @initialized or (self == $service) or ($service == nil) # FIx mix between activity and service
|
34
|
+
self.startService Java::android.content.Intent.new(self, klass.java_class)
|
35
|
+
else
|
36
|
+
initialize_ruboto
|
37
|
+
on_create
|
38
|
+
end
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
java_import "android.content.Context"
|
46
|
+
Context.class_eval do
|
47
|
+
include Ruboto::Context
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Leave for legacy Service Subclass Setup
|
52
|
+
#
|
53
|
+
|
54
|
+
module Ruboto
|
55
|
+
module Service
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Basic Service Setup
|
61
|
+
#
|
62
|
+
|
63
|
+
def ruboto_configure_service(klass)
|
64
|
+
klass.class_eval do
|
65
|
+
include Ruboto::Service
|
66
|
+
|
67
|
+
def on_create
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
ruboto_import "org.ruboto.RubotoService"
|
73
|
+
ruboto_configure_service(RubotoService)
|
74
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#######################################################
|
2
|
+
#
|
3
|
+
# ruboto/util/stack.rb
|
4
|
+
#
|
5
|
+
# Utility methods for running code in a separate
|
6
|
+
# thread with a larger stack.
|
7
|
+
#
|
8
|
+
#######################################################
|
9
|
+
|
10
|
+
class Object
|
11
|
+
def with_large_stack(opts = {}, &block)
|
12
|
+
opts = {:size => opts} if opts.is_a? Integer
|
13
|
+
opts = {:name => 'Block with large stack'}.update(opts)
|
14
|
+
exception = nil
|
15
|
+
result = nil
|
16
|
+
t = Thread.with_large_stack(opts, &proc{result = block.call rescue exception = $!})
|
17
|
+
t.join
|
18
|
+
raise exception if exception
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Thread
|
24
|
+
def self.with_large_stack(opts = {}, &block)
|
25
|
+
opts = {:size => opts} if opts.is_a? Integer
|
26
|
+
stack_size_kb = opts.delete(:size) || 64
|
27
|
+
name = opts.delete(:name) || "Thread with large stack"
|
28
|
+
raise "Unknown option(s): #{opts.inspect}" unless opts.empty?
|
29
|
+
t = java.lang.Thread.new(nil, block, name, stack_size_kb * 1024)
|
30
|
+
t.start
|
31
|
+
t
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#######################################################
|
2
|
+
#
|
3
|
+
# ruboto/util/toast.rb
|
4
|
+
#
|
5
|
+
# Utility methods for doing a toast.
|
6
|
+
#
|
7
|
+
#######################################################
|
8
|
+
|
9
|
+
Java::android.content.Context.class_eval do
|
10
|
+
def toast(text, duration=5000)
|
11
|
+
Java::android.widget.Toast.makeText(self, text, duration).show
|
12
|
+
end
|
13
|
+
|
14
|
+
def toast_result(result, success, failure, duration=5000)
|
15
|
+
toast(result ? success : failure, duration)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'ruboto/activity'
|
2
|
+
|
3
|
+
#######################################################
|
4
|
+
#
|
5
|
+
# ruboto/widget.rb
|
6
|
+
#
|
7
|
+
# Import widgets and set up methods on activity to
|
8
|
+
# create and initialize. You do not need this if
|
9
|
+
# you want to call the Android methods directly.
|
10
|
+
#
|
11
|
+
#######################################################
|
12
|
+
|
13
|
+
#
|
14
|
+
# Prepare View
|
15
|
+
#
|
16
|
+
|
17
|
+
java_import "android.view.View"
|
18
|
+
|
19
|
+
View.class_eval do
|
20
|
+
@@convert_constants ||= {}
|
21
|
+
|
22
|
+
def self.add_constant_conversion(from, to)
|
23
|
+
@@convert_constants[from] = to
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.convert_constant(from)
|
27
|
+
@@convert_constants[from] or from
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.setup_constant_conversion
|
31
|
+
(self.constants - self.superclass.constants).each do |i|
|
32
|
+
View.add_constant_conversion i.downcase.to_sym, self.const_get(i)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def configure(context, params = {})
|
37
|
+
if width = params.delete(:width)
|
38
|
+
getLayoutParams.width = View.convert_constant(width)
|
39
|
+
end
|
40
|
+
|
41
|
+
if height = params.delete(:height)
|
42
|
+
getLayoutParams.height = View.convert_constant(height)
|
43
|
+
end
|
44
|
+
|
45
|
+
if layout = params.delete(:layout)
|
46
|
+
lp = getLayoutParams
|
47
|
+
layout.each do |k, v|
|
48
|
+
values = (v.is_a?(Array) ? v : [v]).map { |i| @@convert_constants[i] or i }
|
49
|
+
lp.send("#{k.to_s.gsub(/_([a-z])/) { $1.upcase }}", *values)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
params.each do |k, v|
|
54
|
+
values = (v.is_a?(Array) ? v : [v]).map { |i| @@convert_constants[i] or i }
|
55
|
+
self.send("set#{k.to_s.gsub(/(^|_)([a-z])/) { $2.upcase }}", *values)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Load ViewGroup constants
|
62
|
+
#
|
63
|
+
|
64
|
+
java_import "android.view.ViewGroup"
|
65
|
+
View.add_constant_conversion :wrap_content, ViewGroup::LayoutParams::WRAP_CONTENT
|
66
|
+
View.add_constant_conversion :fill_parent, ViewGroup::LayoutParams::FILL_PARENT
|
67
|
+
|
68
|
+
#
|
69
|
+
# RubotoActivity View Generation
|
70
|
+
#
|
71
|
+
|
72
|
+
def ruboto_import_widgets(*widgets)
|
73
|
+
widgets.each { |i| ruboto_import_widget i }
|
74
|
+
end
|
75
|
+
|
76
|
+
def ruboto_import_widget(class_name, package_name="android.widget")
|
77
|
+
klass = java_import("#{package_name}.#{class_name}") || eval("Java::#{package_name}.#{class_name}")
|
78
|
+
|
79
|
+
return unless klass
|
80
|
+
|
81
|
+
RubotoActivity.class_eval "
|
82
|
+
def #{(class_name.to_s.gsub(/([A-Z])/) { '_' + $1.downcase })[1..-1]}(params={})
|
83
|
+
if force_style = params.delete(:default_style)
|
84
|
+
rv = #{class_name}.new(self, nil, force_style)
|
85
|
+
elsif api_key = params.delete(:apiKey)
|
86
|
+
rv = #{class_name}.new(self, api_key)
|
87
|
+
else
|
88
|
+
rv = #{class_name}.new(self)
|
89
|
+
end
|
90
|
+
|
91
|
+
if parent = (params.delete(:parent) || @view_parent)
|
92
|
+
parent.addView(rv, (params.delete(:parent_index) || parent.child_count))
|
93
|
+
end
|
94
|
+
|
95
|
+
rv.configure self, params
|
96
|
+
|
97
|
+
return rv unless block_given?
|
98
|
+
|
99
|
+
old_view_parent, @view_parent = @view_parent, rv
|
100
|
+
yield
|
101
|
+
@view_parent = old_view_parent
|
102
|
+
|
103
|
+
rv
|
104
|
+
end
|
105
|
+
"
|
106
|
+
|
107
|
+
setup_list_view if class_name == :ListView
|
108
|
+
setup_spinner if class_name == :Spinner
|
109
|
+
setup_button if class_name == :Button
|
110
|
+
setup_image_button if class_name == :ImageButton
|
111
|
+
setup_linear_layout if class_name == :LinearLayout
|
112
|
+
setup_relative_layout if class_name == :RelativeLayout
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
# Special widget setup
|
117
|
+
#
|
118
|
+
|
119
|
+
def setup_linear_layout
|
120
|
+
Java::android.widget.LinearLayout.setup_constant_conversion
|
121
|
+
end
|
122
|
+
|
123
|
+
def setup_relative_layout
|
124
|
+
Java::android.widget.RelativeLayout.setup_constant_conversion
|
125
|
+
end
|
126
|
+
|
127
|
+
def setup_button
|
128
|
+
# legacy
|
129
|
+
end
|
130
|
+
|
131
|
+
def setup_image_button
|
132
|
+
# legacy
|
133
|
+
end
|
134
|
+
|
135
|
+
def setup_list_view
|
136
|
+
Java::android.widget.ListView.class_eval do
|
137
|
+
attr_reader :adapter, :adapter_list
|
138
|
+
|
139
|
+
def configure(context, params = {})
|
140
|
+
if params.has_key? :list
|
141
|
+
@adapter_list = Java::java.util.ArrayList.new
|
142
|
+
@adapter_list.addAll(params[:list])
|
143
|
+
item_layout = params.delete(:item_layout) || R::layout::simple_list_item_1
|
144
|
+
@adapter = Java::android.widget.ArrayAdapter.new(context, item_layout, @adapter_list)
|
145
|
+
setAdapter @adapter
|
146
|
+
params.delete :list
|
147
|
+
end
|
148
|
+
if params.has_key? :adapter
|
149
|
+
@adapter = params[:adapter]
|
150
|
+
end
|
151
|
+
super(context, params)
|
152
|
+
end
|
153
|
+
|
154
|
+
def reload_list(list)
|
155
|
+
@adapter_list.clear
|
156
|
+
@adapter_list.addAll(list)
|
157
|
+
@adapter.notifyDataSetChanged
|
158
|
+
invalidate
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def setup_spinner
|
164
|
+
Java::android.widget.Spinner.class_eval do
|
165
|
+
attr_reader :adapter, :adapter_list
|
166
|
+
|
167
|
+
def configure(context, params = {})
|
168
|
+
if params.has_key? :list
|
169
|
+
@adapter_list = Java::java.util.ArrayList.new
|
170
|
+
@adapter_list.addAll(params[:list])
|
171
|
+
item_layout = params.delete(:item_layout) || R::layout::simple_spinner_item
|
172
|
+
@adapter = Java::android.widget.ArrayAdapter.new(context, item_layout, @adapter_list)
|
173
|
+
@adapter.setDropDownViewResource(params.delete(:dropdown_layout) || R::layout::simple_spinner_dropdown_item)
|
174
|
+
setAdapter @adapter
|
175
|
+
params.delete :list
|
176
|
+
end
|
177
|
+
super(context, params)
|
178
|
+
end
|
179
|
+
|
180
|
+
def reload_list(list)
|
181
|
+
@adapter.clear
|
182
|
+
@adapter.addAll(list)
|
183
|
+
@adapter.notifyDataSetChanged
|
184
|
+
invalidate
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
@@ -11,3 +11,7 @@ end
|
|
11
11
|
def assert_less_than_or_equal(limit, actual, message = nil)
|
12
12
|
raise "#{"#{message}\n" if message}Expected '#{actual}' to be less than or equal to '#{limit}'" unless actual <= limit
|
13
13
|
end
|
14
|
+
|
15
|
+
def assert_matches(pattern, actual, message = nil)
|
16
|
+
raise "#{"#{message}\n" if message}'#{pattern}' expected, but got '#{actual}'" unless pattern =~ actual
|
17
|
+
end
|
data/bin/ruboto
CHANGED
data/lib/ruboto/commands/base.rb
CHANGED
@@ -55,10 +55,6 @@ module Ruboto
|
|
55
55
|
description "Generate the JRuby jars jar"
|
56
56
|
cast :boolean
|
57
57
|
}
|
58
|
-
option("with-psych") {
|
59
|
-
description "Generate the Psych YAML parser jar"
|
60
|
-
cast :boolean
|
61
|
-
}
|
62
58
|
|
63
59
|
def run
|
64
60
|
package = params['package'].value
|
@@ -94,7 +90,7 @@ module Ruboto
|
|
94
90
|
update_ruboto true
|
95
91
|
update_icons true
|
96
92
|
update_classes true
|
97
|
-
update_jruby true
|
93
|
+
update_jruby true if params['with-jruby'].value
|
98
94
|
# update_build_xml
|
99
95
|
update_manifest min_sdk[/\d+/], target[/\d+/], true
|
100
96
|
update_core_classes "exclude"
|
@@ -114,14 +110,9 @@ module Ruboto
|
|
114
110
|
include Ruboto::Util::Update
|
115
111
|
include Ruboto::Util::Verify
|
116
112
|
|
117
|
-
option("with-psych") {
|
118
|
-
description "Generate the Psych YAML parser jar"
|
119
|
-
cast :boolean
|
120
|
-
}
|
121
|
-
|
122
113
|
def run
|
123
114
|
Dir.chdir root do
|
124
|
-
update_jruby true
|
115
|
+
update_jruby true
|
125
116
|
end
|
126
117
|
end
|
127
118
|
end
|
@@ -332,11 +323,6 @@ module Ruboto
|
|
332
323
|
description "force and update even if the version hasn't changed"
|
333
324
|
}
|
334
325
|
|
335
|
-
option("with-psych") {
|
336
|
-
description "Generate the Psych YAML parser jar"
|
337
|
-
cast :boolean
|
338
|
-
}
|
339
|
-
|
340
326
|
def run
|
341
327
|
case params['what'].value
|
342
328
|
when "app" then
|
@@ -347,12 +333,12 @@ module Ruboto
|
|
347
333
|
update_ruboto force
|
348
334
|
update_icons force
|
349
335
|
update_classes force
|
350
|
-
update_jruby force
|
336
|
+
update_jruby force
|
351
337
|
update_manifest nil, nil, force
|
352
338
|
update_core_classes "exclude"
|
353
339
|
update_bundle
|
354
340
|
when "jruby" then
|
355
|
-
update_jruby(params['force'].value
|
341
|
+
update_jruby(params['force'].value) || abort
|
356
342
|
when "ruboto" then
|
357
343
|
update_ruboto(params['force'].value) || abort
|
358
344
|
end
|