ruboto 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -49
- data/Rakefile +26 -26
- data/assets/rakelib/ruboto.rake +29 -9
- data/assets/res/drawable-hdpi/{icon.png → ic_launcher.png} +0 -0
- data/assets/res/drawable-ldpi/{icon.png → ic_launcher.png} +0 -0
- data/assets/res/drawable-mdpi/{icon.png → ic_launcher.png} +0 -0
- data/assets/samples/sample_activity.rb +19 -9
- data/assets/samples/sample_broadcast_receiver.rb +3 -1
- data/assets/samples/sample_service.rb +9 -9
- data/assets/src/InheritingActivity.java +1 -1
- data/assets/src/InheritingBroadcastReceiver.java +4 -4
- data/assets/src/InheritingClass.java +1 -1
- data/assets/src/InheritingService.java +2 -1
- data/assets/src/RubotoActivity.java +26 -17
- data/assets/src/RubotoBroadcastReceiver.java +32 -11
- data/assets/src/RubotoService.java +23 -13
- data/assets/src/org/ruboto/EntryPointActivity.java +18 -26
- data/assets/src/org/ruboto/JRubyAdapter.java +468 -0
- data/assets/src/org/ruboto/Log.java +22 -0
- data/assets/src/org/ruboto/Script.java +113 -587
- data/assets/src/org/ruboto/test/ActivityTest.java +7 -7
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +27 -12
- data/assets/src/ruboto.rb +1 -1
- data/assets/src/ruboto/activity.rb +10 -1
- data/assets/src/ruboto/base.rb +0 -12
- data/assets/src/ruboto/broadcast_receiver.rb +12 -0
- data/assets/src/ruboto/menu.rb +0 -1
- data/assets/src/ruboto/package.rb +11 -0
- data/assets/src/ruboto/service.rb +9 -0
- data/lib/ruboto/commands/base.rb +1 -1
- data/lib/ruboto/util/build.rb +1 -1
- data/lib/ruboto/util/update.rb +35 -27
- data/lib/ruboto/util/xml_element.rb +25 -12
- data/lib/ruboto/version.rb +2 -2
- data/test/activity/image_button_activity.rb +14 -11
- data/test/activity/image_button_activity_test.rb +2 -6
- data/test/activity/image_button_and_button_activity.rb +15 -17
- data/test/activity/image_button_and_button_activity_test.rb +4 -8
- data/test/activity/option_menu_activity.rb +17 -12
- data/test/activity/option_menu_activity_test.rb +1 -4
- data/test/activity/psych_activity.rb +20 -13
- data/test/activity/psych_activity_test.rb +3 -1
- data/test/activity/stack_activity.rb +17 -14
- data/test/activity/stack_activity_test.rb +13 -12
- data/test/app_test_methods.rb +25 -19
- data/test/block_def_activity/image_button_activity.rb +23 -0
- data/test/block_def_activity/image_button_activity_test.rb +21 -0
- data/test/block_def_activity/image_button_and_button_activity.rb +20 -0
- data/test/block_def_activity/image_button_and_button_activity_test.rb +27 -0
- data/test/block_def_activity/option_menu_activity.rb +26 -0
- data/test/block_def_activity/option_menu_activity_test.rb +18 -0
- data/test/block_def_activity/psych_activity.rb +35 -0
- data/test/block_def_activity/psych_activity_test.rb +16 -0
- data/test/block_def_activity/stack_activity.rb +25 -0
- data/test/block_def_activity/stack_activity_test.rb +31 -0
- data/test/broadcast_receiver_test.rb +2 -2
- data/test/handle_activity/image_button_activity.rb +21 -0
- data/test/handle_activity/image_button_activity_test.rb +21 -0
- data/test/handle_activity/image_button_and_button_activity.rb +24 -0
- data/test/handle_activity/image_button_and_button_activity_test.rb +27 -0
- data/test/handle_activity/option_menu_activity.rb +21 -0
- data/test/handle_activity/option_menu_activity_test.rb +20 -0
- data/test/handle_activity/psych_activity.rb +31 -0
- data/test/handle_activity/psych_activity_test.rb +16 -0
- data/test/handle_activity/stack_activity.rb +21 -0
- data/test/handle_activity/stack_activity_test.rb +32 -0
- data/test/minimal_app_test.rb +4 -4
- data/test/rake_test.rb +15 -1
- data/test/ruboto_gen_test.rb +7 -4
- data/test/service_test.rb +110 -21
- data/test/test_helper.rb +17 -14
- data/test/updated_example_test_methods.rb +5 -14
- metadata +30 -7
data/README.md
CHANGED
@@ -55,38 +55,9 @@ Ex:
|
|
55
55
|
<a name="callback_generator"></a>
|
56
56
|
### Callback generator
|
57
57
|
|
58
|
-
|
58
|
+
You can subclass any part of the Android API to pass control over to a script when the specified methods are called. You can also create classes that implement a single Android interface to pass control over to ruboto.
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
For classes that need subclassing (e.g., PhoneStateListener, SQLiteOpenHelper, View)
|
63
|
-
|
64
|
-
$ ruboto gen subclass AndroidPackageAndClassName --name YourClassName --method_base all-on-or-none --method_include methods --method_exclude methods
|
65
|
-
Ex:
|
66
|
-
$ ruboto gen subclass android.telephony.PhoneStateListener --name MyPhoneStateListener --method_base on
|
67
|
-
|
68
|
-
For interfaces that need implementing (e.g., OnClickListener or SensorListener)
|
69
|
-
|
70
|
-
$ ruboto gen interface AndroidPackageAndInterfaceName --name YourClassName
|
71
|
-
Ex:
|
72
|
-
$ ruboto gen interface android.hardware.SensorListener --name MySensorListener
|
73
|
-
|
74
|
-
Inside your script use:
|
75
|
-
|
76
|
-
# note that this is different than java_import
|
77
|
-
ruboto_import "your.package.MySensorListener"
|
78
|
-
|
79
|
-
Later:
|
80
|
-
|
81
|
-
# Create the callback object
|
82
|
-
@sensor_listener = MySensorListener.new
|
83
|
-
|
84
|
-
# Specify the block to call
|
85
|
-
@sensor_listener.handle_sensor_changed do |sensor, values|
|
86
|
-
# Do stuff
|
87
|
-
end
|
88
|
-
|
89
|
-
# Register the listener
|
60
|
+
Starting with Ruboto 0.6.0 there are easy ways to do this within your scripts. The new way of generating interfaces and subclasses is described in the wiki [Generating classes for callbacks](https://github.com/ruboto/ruboto/wiki/Generating-classes-for-callbacks)._
|
90
61
|
|
91
62
|
<a name="packaging_task"></a>
|
92
63
|
### Packaging task
|
@@ -174,31 +145,24 @@ The main thing Ruboto offers you is the ability to write Ruby scripts to define
|
|
174
145
|
|
175
146
|
Here's how it works:
|
176
147
|
|
177
|
-
First of all, your scripts are found in `src/` and the script name is the same as the name of your class, only under_scored instead of CamelCased. Android classes have all of these methods that get called in certain situations. `Activity.onDestroy()` gets called when the activity gets killed, for example. Save weird cases (like the "launching" methods that need to setup JRuby), to script the method onFooBar, you call the Ruby method
|
148
|
+
First of all, your scripts are found in `src/` and the script name is the same as the name of your class, only under_scored instead of CamelCased. Android classes have all of these methods that get called in certain situations. `Activity.onDestroy()` gets called when the activity gets killed, for example. Save weird cases (like the "launching" methods that need to setup JRuby), to script the method onFooBar, you call the Ruby method on_foo_bar on the Android object. That was really abstract, so here's an example.
|
178
149
|
|
179
150
|
You generate an app with the option `--activity FooActivity`, which means that ruboto will generate a FooActivity for you. So you open `src/foo_activity.rb` in your favorite text editor. If you want an activity that does nothing but Log when it gets launched and when it gets destroyed (in the onCreate and onPause methods). You want your script to look like this:
|
180
151
|
|
181
|
-
require 'ruboto
|
182
|
-
$activity.handle_create do |bundle|
|
183
|
-
Log.v 'MYAPPNAME', 'onCreate got called!'
|
184
|
-
handle_pause do
|
185
|
-
Log.v 'MYAPPNAME', 'onPause got called!'
|
186
|
-
end
|
187
|
-
end
|
152
|
+
require 'ruboto/activity' #scripts will not work without doing this
|
188
153
|
|
189
|
-
|
154
|
+
class FooActivity
|
155
|
+
include Ruboto::Activity
|
156
|
+
def on_create(bundle)
|
157
|
+
Log.v 'MYAPPNAME', 'onCreate got called!'
|
158
|
+
end
|
190
159
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
195
|
-
$activity.handle_pause do
|
196
|
-
Log.v 'MYAPPNAME', 'onPause got called!'
|
160
|
+
def on_pause
|
161
|
+
Log.v 'MYAPPNAME', 'onPause got called!'
|
162
|
+
end
|
197
163
|
end
|
198
164
|
|
199
|
-
|
200
|
-
|
201
|
-
The arguments passed to the block you give `handle_` methods are the same as the arguments that the java methods take. Consult the Android documentation.
|
165
|
+
The arguments passed to the methods are the same as the arguments that the java methods take. Consult the Android documentation.
|
202
166
|
|
203
167
|
Activities also have some special methods defined to make things easier. The easiest way to get an idea of what they are is looking over the [demo scripts](http://github.com/ruboto/ruboto-irb/tree/master/assets/demo-scripts/). You can also read the [ruboto.rb file](http://github.com/ruboto/ruboto/blob/master/assets/src/ruboto.rb) where everything is defined.
|
204
168
|
|
data/Rakefile
CHANGED
@@ -8,13 +8,12 @@ require 'net/http'
|
|
8
8
|
|
9
9
|
PLATFORM_PROJECT = File.expand_path('tmp/RubotoCore', File.dirname(__FILE__))
|
10
10
|
PLATFORM_DEBUG_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk"
|
11
|
+
PLATFORM_DEBUG_APK_BAK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk.bak"
|
11
12
|
PLATFORM_RELEASE_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-release.apk"
|
12
13
|
PLATFORM_CURRENT_RELEASE_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-release.apk.current"
|
13
14
|
MANIFEST_FILE = "AndroidManifest.xml"
|
14
15
|
GEM_FILE = "ruboto-#{Ruboto::VERSION}.gem"
|
15
|
-
GEM_FILE_OLD = "ruboto-core-#{Ruboto::VERSION}.gem"
|
16
16
|
GEM_SPEC_FILE = 'ruboto.gemspec'
|
17
|
-
GEM_SPEC_FILE_OLD = 'ruboto-core.gemspec'
|
18
17
|
EXAMPLE_FILE = File.expand_path("examples/RubotoTestApp_#{Ruboto::VERSION}_tools_r#{Ruboto::SdkVersions::ANDROID_TOOLS_REVISION}.tgz", File.dirname(__FILE__))
|
19
18
|
|
20
19
|
CLEAN.include('ruboto-*.gem', 'tmp')
|
@@ -22,18 +21,13 @@ CLEAN.include('ruboto-*.gem', 'tmp')
|
|
22
21
|
task :default => :gem
|
23
22
|
|
24
23
|
desc "Generate a gem"
|
25
|
-
task :gem =>
|
24
|
+
task :gem => GEM_FILE
|
26
25
|
|
27
26
|
file GEM_FILE => GEM_SPEC_FILE do
|
28
27
|
puts "Generating #{GEM_FILE}"
|
29
28
|
`gem build #{GEM_SPEC_FILE}`
|
30
29
|
end
|
31
30
|
|
32
|
-
file GEM_FILE_OLD => GEM_SPEC_FILE_OLD do
|
33
|
-
puts "Generating #{GEM_FILE_OLD}"
|
34
|
-
`gem build #{GEM_SPEC_FILE_OLD}`
|
35
|
-
end
|
36
|
-
|
37
31
|
task :install => :gem do
|
38
32
|
`gem query -i -n ^ruboto$ -v #{Ruboto::VERSION}`
|
39
33
|
if $? != 0
|
@@ -44,6 +38,8 @@ task :install => :gem do
|
|
44
38
|
else
|
45
39
|
sh "sudo #{cmd}"
|
46
40
|
end
|
41
|
+
else
|
42
|
+
puts "ruboto-#{Ruboto::VERSION} is already installed."
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
@@ -68,7 +64,6 @@ task :release => [:clean, :gem] do
|
|
68
64
|
sh "git tag #{Ruboto::VERSION}"
|
69
65
|
sh "git push --tags"
|
70
66
|
sh "gem push #{GEM_FILE}"
|
71
|
-
sh "gem push #{GEM_FILE_OLD}"
|
72
67
|
|
73
68
|
Rake::Task[:example].invoke
|
74
69
|
sh "git add #{EXAMPLE_FILE}"
|
@@ -102,12 +97,6 @@ namespace :platform do
|
|
102
97
|
manifest.root.attributes['android:installLocation'] = 'auto' # or 'preferExternal' ?
|
103
98
|
File.open(MANIFEST_FILE, 'w') { |f| manifest.document.write(f, 4) }
|
104
99
|
File.open('Gemfile.apk', 'w'){|f| f << "source :rubygems\n\ngem 'activerecord-jdbc-adapter'\n"}
|
105
|
-
|
106
|
-
# FIXME(uwe): Add this when either jruby-openssl is simplified or most devices are Android 4
|
107
|
-
# FIXME(uwe): Reeference: #154 and http://code.google.com/p/android/issues/detail?id=22586
|
108
|
-
# File.open('Gemfile.apk', 'w'){|f| f << "gem 'jruby-openssl'\n"}
|
109
|
-
# FIXME end
|
110
|
-
|
111
100
|
File.open('ant.properties', 'a'){|f| f << "key.store=${user.home}/ruboto_core.keystore\nkey.alias=Ruboto\n"}
|
112
101
|
end
|
113
102
|
end
|
@@ -115,11 +104,16 @@ namespace :platform do
|
|
115
104
|
desc 'Generate a Ruboto Core platform debug apk'
|
116
105
|
task :debug => PLATFORM_DEBUG_APK
|
117
106
|
|
118
|
-
|
107
|
+
task PLATFORM_DEBUG_APK do
|
108
|
+
Rake::Task[PLATFORM_PROJECT].invoke
|
119
109
|
Dir.chdir(PLATFORM_PROJECT) do
|
120
110
|
if File.exists?(PLATFORM_CURRENT_RELEASE_APK) && File.exists?(PLATFORM_DEBUG_APK) &&
|
121
111
|
File.size(PLATFORM_CURRENT_RELEASE_APK) == File.size(PLATFORM_DEBUG_APK)
|
122
|
-
|
112
|
+
if File.exists?(PLATFORM_DEBUG_APK_BAK)
|
113
|
+
FileUtils.cp PLATFORM_DEBUG_APK_BAK, PLATFORM_DEBUG_APK
|
114
|
+
else
|
115
|
+
FileUtils.rm PLATFORM_DEBUG_APK
|
116
|
+
end
|
123
117
|
end
|
124
118
|
sh 'rake debug'
|
125
119
|
end
|
@@ -135,23 +129,29 @@ namespace :platform do
|
|
135
129
|
end
|
136
130
|
|
137
131
|
desc 'Download the current RubotoCore platform release apk'
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
132
|
+
file PLATFORM_CURRENT_RELEASE_APK do
|
133
|
+
puts 'Downloading the current RubotoCore platform release apk'
|
134
|
+
url = 'http://cloud.github.com/downloads/ruboto/ruboto/RubotoCore-release.apk'
|
135
|
+
begin
|
136
|
+
File.open(PLATFORM_CURRENT_RELEASE_APK, 'w') { |f| f << Net::HTTP.get(URI.parse url) }
|
137
|
+
rescue Exception, SystemExit
|
138
|
+
FileUtils.rm(PLATFORM_CURRENT_RELEASE_APK) if File.exists?(PLATFORM_CURRENT_RELEASE_APK)
|
139
|
+
raise
|
140
|
+
end
|
141
|
+
end
|
145
142
|
|
143
|
+
desc 'Use the current RubotoCore platform release apk'
|
144
|
+
task :current => [:debug, PLATFORM_CURRENT_RELEASE_APK] do
|
145
|
+
Dir.chdir PLATFORM_PROJECT do
|
146
146
|
if File.size(PLATFORM_CURRENT_RELEASE_APK) != File.size(PLATFORM_DEBUG_APK)
|
147
|
+
FileUtils.cp PLATFORM_DEBUG_APK, PLATFORM_DEBUG_APK_BAK
|
147
148
|
FileUtils.cp PLATFORM_CURRENT_RELEASE_APK, PLATFORM_DEBUG_APK
|
148
|
-
sh 'rake uninstall'
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
desc 'Install the Ruboto Core platform debug apk'
|
154
|
-
task :install =>
|
154
|
+
task :install => PLATFORM_PROJECT do
|
155
155
|
Dir.chdir(PLATFORM_PROJECT) do
|
156
156
|
sh 'rake install'
|
157
157
|
end
|
data/assets/rakelib/ruboto.rake
CHANGED
@@ -19,6 +19,7 @@ UPDATE_MARKER_FILE = File.join(PROJECT_DIR, 'bin', 'LAST_UPDATE')
|
|
19
19
|
BUNDLE_JAR = File.expand_path 'libs/bundle.jar'
|
20
20
|
BUNDLE_PATH = File.expand_path 'bin/bundle'
|
21
21
|
MANIFEST_FILE = File.expand_path 'AndroidManifest.xml'
|
22
|
+
PROJECT_PROPS_FILE = File.expand_path 'project.properties'
|
22
23
|
RUBOTO_CONFIG_FILE = File.expand_path 'ruboto.yml'
|
23
24
|
GEM_FILE = File.expand_path('Gemfile.apk')
|
24
25
|
GEM_LOCK_FILE = File.expand_path('Gemfile.apk.lock')
|
@@ -142,7 +143,16 @@ task :uninstall do
|
|
142
143
|
uninstall_apk
|
143
144
|
end
|
144
145
|
|
145
|
-
file
|
146
|
+
file PROJECT_PROPS_FILE
|
147
|
+
file MANIFEST_FILE => PROJECT_PROPS_FILE do
|
148
|
+
sdk_level = File.read(PROJECT_PROPS_FILE).scan(/(?:target=android-)(\d+)/)[0][0].to_i
|
149
|
+
old_manifest = File.read(MANIFEST_FILE)
|
150
|
+
manifest = old_manifest.dup
|
151
|
+
manifest.sub!(/(android:minSdkVersion=').*?(')/){|m| "#$1#{sdk_level}#$2"}
|
152
|
+
manifest.sub!(/(android:targetSdkVersion=').*?(')/){|m| "#$1#{sdk_level}#$2"}
|
153
|
+
File.open(MANIFEST_FILE, 'w'){|f| f << manifest} if manifest != old_manifest
|
154
|
+
end
|
155
|
+
|
146
156
|
file RUBOTO_CONFIG_FILE
|
147
157
|
|
148
158
|
file APK_FILE => APK_DEPENDENCIES do |t|
|
@@ -330,9 +340,9 @@ end
|
|
330
340
|
def package_installed? test = false
|
331
341
|
package_name = "#{package}#{'.tests' if test}"
|
332
342
|
['', '-0', '-1', '-2'].each do |i|
|
333
|
-
|
334
|
-
o = `adb shell ls -l #{
|
335
|
-
if o =~ /^-rw-r--r-- system\s+system\s+(\d+) \d{4}-\d{2}-\d{2} \d{2}:\d{2} #{File.basename(
|
343
|
+
path = "/data/app/#{package_name}#{i}.apk"
|
344
|
+
o = `adb shell ls -l #{path}`.chomp
|
345
|
+
if o =~ /^-rw-r--r-- system\s+system\s+(\d+) \d{4}-\d{2}-\d{2} \d{2}:\d{2} #{File.basename(path)}$/
|
336
346
|
apk_file = test ? TEST_APK_FILE : APK_FILE
|
337
347
|
if !File.exists?(apk_file) || $1.to_i == File.size(apk_file)
|
338
348
|
return true
|
@@ -344,8 +354,6 @@ def package_installed? test = false
|
|
344
354
|
return nil
|
345
355
|
end
|
346
356
|
|
347
|
-
private
|
348
|
-
|
349
357
|
def replace_faulty_code(faulty_file, faulty_code)
|
350
358
|
explicit_requires = Dir["#{faulty_file.chomp('.rb')}/*.rb"].sort.map { |f| File.basename(f) }.map do |filename|
|
351
359
|
"require 'active_model/validations/#{filename}'"
|
@@ -380,14 +388,27 @@ def build_apk(t, release)
|
|
380
388
|
end
|
381
389
|
|
382
390
|
def install_apk
|
391
|
+
failure_pattern = /^Failure \[(.*)\]/
|
392
|
+
success_pattern = /^Success/
|
383
393
|
case package_installed?
|
384
394
|
when true
|
385
395
|
puts "Package #{package} already installed."
|
386
396
|
return
|
387
397
|
when false
|
388
|
-
puts "Package installed, but of
|
398
|
+
puts "Package #{package} already installed, but of different size. Replacing package."
|
399
|
+
output = `adb install -r #{APK_FILE} 2>&1`
|
400
|
+
return if $? == 0 && output !~ failure_pattern && output =~ success_pattern
|
401
|
+
case $1
|
402
|
+
when 'INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES'
|
403
|
+
puts "Found package signed with different certificate. Uninstalling it and retrying install."
|
404
|
+
else
|
405
|
+
puts "'adb install' returned an unknown error: (#$?) #{$1 ? "[#$1}]" : output}."
|
406
|
+
puts "Uninstalling #{package} and retrying install."
|
407
|
+
end
|
408
|
+
uninstall_apk
|
389
409
|
end
|
390
|
-
|
410
|
+
output = `adb install #{APK_FILE} 2>&1`
|
411
|
+
raise "Install failed (#{$?}) #{$1 ? "[#$1}]" : output}" if $? != 0 || output =~ failure_pattern || output !~ success_pattern
|
391
412
|
clear_update
|
392
413
|
end
|
393
414
|
|
@@ -405,7 +426,6 @@ def update_scripts
|
|
405
426
|
`adb shell mkdir -p #{scripts_path}` if !device_path_exists?(scripts_path)
|
406
427
|
puts "Pushing files to apk public file area."
|
407
428
|
last_update = File.exists?(UPDATE_MARKER_FILE) ? Time.parse(File.read(UPDATE_MARKER_FILE)) : Time.parse('1970-01-01T00:00:00')
|
408
|
-
# TODO(uwe): Use `adb sync src` instead?
|
409
429
|
Dir.chdir('src') do
|
410
430
|
Dir["**/*.rb"].each do |script_file|
|
411
431
|
next if File.directory? script_file
|
File without changes
|
File without changes
|
File without changes
|
@@ -4,20 +4,30 @@ require 'ruboto/util/toast'
|
|
4
4
|
|
5
5
|
ruboto_import_widgets :Button, :LinearLayout, :TextView
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
# http://xkcd.com/378/
|
8
|
+
|
9
|
+
class SampleActivity
|
10
|
+
include Ruboto::Activity
|
9
11
|
|
10
12
|
def on_create(bundle)
|
13
|
+
set_title 'Domo arigato, Mr Ruboto!'
|
14
|
+
|
11
15
|
self.content_view =
|
12
|
-
linear_layout
|
13
|
-
@text_view = text_view :text
|
14
|
-
|
15
|
-
|
16
|
+
linear_layout :orientation => :vertical do
|
17
|
+
@text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :width => :fill_parent,
|
18
|
+
:gravity => android.view.Gravity::CENTER, :text_size => 48.0
|
19
|
+
button :text => 'M-x butterfly', :width => :fill_parent, :id => 43, :on_click_listener => proc { butterfly }
|
16
20
|
end
|
21
|
+
rescue
|
22
|
+
puts "Exception creating activity: #{$!}"
|
23
|
+
puts $!.backtrace.join("\n")
|
17
24
|
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
def butterfly
|
29
|
+
@text_view.text = 'What hath Matz wrought!'
|
30
|
+
toast 'Flipped a bit via butterfly'
|
22
31
|
end
|
32
|
+
|
23
33
|
end
|
@@ -2,7 +2,9 @@ require 'ruboto/broadcast_receiver'
|
|
2
2
|
|
3
3
|
import android.util.Log
|
4
4
|
|
5
|
-
|
5
|
+
class SampleBroadcastReceiver
|
6
|
+
include Ruboto::BroadcastReceiver
|
7
|
+
|
6
8
|
# will get called whenever the BroadcastReceiver receives an intent (whenever onReceive is called)
|
7
9
|
def on_receive(context, intent)
|
8
10
|
Log.v "SampleBroadcastReceiver", 'Broadcast received!'
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'ruboto/service'
|
2
2
|
require 'ruboto/util/toast'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
# Services are complicated and don't really make sense unless you
|
5
|
+
# show the interaction between the Service and other parts of your
|
6
|
+
# app.
|
7
|
+
# For now, just take a look at the explanation and example in
|
8
|
+
# online:
|
9
|
+
# http://developer.android.com/reference/android/app/Service.html
|
10
|
+
class SampleService
|
11
|
+
include Ruboto::Service
|
11
12
|
|
12
13
|
def on_start_command(intent, flags, startId)
|
13
14
|
toast "Hello from the service"
|
14
|
-
|
15
|
+
android.app.Service::START_NOT_STICKY
|
15
16
|
end
|
16
|
-
|
17
17
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
package THE_PACKAGE;
|
2
2
|
|
3
|
-
import org.ruboto.
|
3
|
+
import org.ruboto.JRubyAdapter;
|
4
4
|
|
5
5
|
public class InheritingBroadcastReceiver extends org.ruboto.RubotoBroadcastReceiver {
|
6
6
|
private boolean scriptLoaded = false;
|
7
7
|
|
8
8
|
public InheritingBroadcastReceiver() {
|
9
|
-
super("
|
10
|
-
if (
|
9
|
+
super("sample_broadcast_receiver.rb");
|
10
|
+
if (JRubyAdapter.isInitialized()) {
|
11
11
|
scriptLoaded = true;
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|
15
15
|
public void onReceive(android.content.Context context, android.content.Intent intent) {
|
16
16
|
if (!scriptLoaded) {
|
17
|
-
if (
|
17
|
+
if (JRubyAdapter.setUpJRuby(context)) {
|
18
18
|
loadScript();
|
19
19
|
scriptLoaded = true;
|
20
20
|
} else {
|
@@ -5,19 +5,14 @@ import java.io.IOException;
|
|
5
5
|
import org.ruboto.Script;
|
6
6
|
|
7
7
|
import android.app.ProgressDialog;
|
8
|
-
import android.content.Intent;
|
9
|
-
import android.net.Uri;
|
10
8
|
import android.os.Bundle;
|
11
|
-
import android.os.Handler;
|
12
|
-
import android.util.Log;
|
13
|
-
import android.view.View;
|
14
|
-
import android.widget.TextView;
|
15
9
|
|
16
10
|
public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
|
17
11
|
private String scriptName;
|
18
12
|
private String remoteVariable = null;
|
19
13
|
private Object[] args;
|
20
14
|
private Bundle configBundle = null;
|
15
|
+
private Object rubyInstance;
|
21
16
|
|
22
17
|
THE_CONSTANTS
|
23
18
|
|
@@ -67,31 +62,45 @@ THE_CONSTANTS
|
|
67
62
|
|
68
63
|
super.onCreate(bundle);
|
69
64
|
|
70
|
-
if (
|
65
|
+
if (JRubyAdapter.isInitialized()) {
|
71
66
|
prepareJRuby();
|
72
67
|
loadScript();
|
73
68
|
}
|
74
69
|
}
|
75
70
|
|
71
|
+
// TODO(uwe): Only needed for non-class-based definitions
|
72
|
+
// Can be removed if we stop supporting non-class-based definitions
|
76
73
|
// This causes JRuby to initialize and takes a while.
|
77
74
|
protected void prepareJRuby() {
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
JRubyAdapter.put("$context", this);
|
76
|
+
JRubyAdapter.put("$activity", this);
|
77
|
+
JRubyAdapter.put("$bundle", args[0]);
|
81
78
|
}
|
79
|
+
// TODO end
|
82
80
|
|
83
81
|
protected void loadScript() {
|
84
82
|
try {
|
85
83
|
if (scriptName != null) {
|
86
|
-
|
87
|
-
|
84
|
+
String rubyClassName = Script.toCamelCase(scriptName);
|
85
|
+
System.out.println("Looking for Ruby class: " + rubyClassName);
|
86
|
+
Object rubyClass = JRubyAdapter.get(rubyClassName);
|
87
|
+
if (rubyClass == null) {
|
88
|
+
System.out.println("Loading script: " + scriptName);
|
89
|
+
JRubyAdapter.exec(new Script(scriptName).getContents());
|
90
|
+
rubyClass = JRubyAdapter.get(rubyClassName);
|
91
|
+
}
|
92
|
+
if (rubyClass != null) {
|
93
|
+
System.out.println("Instanciating Ruby class: " + rubyClassName);
|
94
|
+
rubyInstance = JRubyAdapter.callMethod(rubyClass, "new", this, Object.class);
|
95
|
+
JRubyAdapter.callMethod(rubyInstance, "on_create", args[0]);
|
96
|
+
}
|
88
97
|
} else if (configBundle != null) {
|
89
|
-
// TODO: Why doesn't this work?
|
90
|
-
// Script.callMethod(this, "initialize_ruboto");
|
91
|
-
Script.execute("$activity.initialize_ruboto");
|
92
98
|
// TODO: Why doesn't this work?
|
93
|
-
//
|
94
|
-
|
99
|
+
// JRubyAdapter.callMethod(this, "initialize_ruboto");
|
100
|
+
JRubyAdapter.execute("$activity.initialize_ruboto");
|
101
|
+
// TODO: Why doesn't this work?
|
102
|
+
// JRubyAdapter.callMethod(this, "on_create", args[0]);
|
103
|
+
JRubyAdapter.execute("$activity.on_create($bundle)");
|
95
104
|
}
|
96
105
|
} catch(IOException e){
|
97
106
|
e.printStackTrace();
|