ruboto 0.10.2 → 0.11.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 (47) hide show
  1. data/Gemfile +2 -4
  2. data/Gemfile.lock +12 -6
  3. data/README.md +2 -2
  4. data/assets/rakelib/ruboto.rake +165 -7
  5. data/assets/samples/sample_activity.rb +1 -1
  6. data/assets/samples/sample_activity_test.rb +2 -2
  7. data/assets/samples/sample_broadcast_receiver.rb +3 -3
  8. data/assets/samples/sample_broadcast_receiver_test.rb +1 -1
  9. data/assets/samples/sample_service.rb +2 -2
  10. data/assets/src/RubotoBroadcastReceiver.java +9 -0
  11. data/assets/src/org/ruboto/EntryPointActivity.java +3 -0
  12. data/assets/src/org/ruboto/JRubyAdapter.java +57 -23
  13. data/assets/src/org/ruboto/ScriptLoader.java +5 -2
  14. data/assets/src/ruboto/activity.rb +12 -13
  15. data/assets/src/ruboto/base.rb +2 -2
  16. data/assets/src/ruboto/broadcast_receiver.rb +1 -1
  17. data/assets/src/ruboto/package.rb +2 -2
  18. data/assets/src/ruboto/preference.rb +4 -4
  19. data/assets/src/ruboto/service.rb +9 -10
  20. data/assets/src/ruboto/util/stack.rb +10 -2
  21. data/assets/src/ruboto/widget.rb +5 -3
  22. data/lib/ruboto/sdk_versions.rb +1 -1
  23. data/lib/ruboto/util/update.rb +97 -52
  24. data/lib/ruboto/version.rb +1 -1
  25. data/lib/ruboto.rb +1 -1
  26. data/test/activity/image_button_activity.rb +1 -1
  27. data/test/activity/image_button_and_button_activity.rb +1 -1
  28. data/test/activity/json_activity.rb +1 -1
  29. data/test/activity/margins_activity.rb +1 -1
  30. data/test/activity/navigation_activity.rb +4 -4
  31. data/test/activity/navigation_target_activity.rb +1 -1
  32. data/test/activity/option_menu_activity.rb +2 -2
  33. data/test/activity/psych_activity.rb +1 -1
  34. data/test/activity/ruby_file_activity.rb +1 -1
  35. data/test/activity/stack_activity.rb +1 -1
  36. data/test/activity/startup_exception_activity.rb +31 -0
  37. data/test/activity/startup_exception_activity_test.rb +15 -0
  38. data/test/activity/subclass_activity.rb +2 -2
  39. data/test/activity/view_constants_activity.rb +1 -1
  40. data/test/app_test_methods.rb +1 -5
  41. data/test/broadcast_receiver_test.rb +4 -4
  42. data/test/minimal_app_test.rb +36 -8
  43. data/test/ruboto_gen_test.rb +5 -9
  44. data/test/service_test.rb +5 -5
  45. data/test/sqldroid_test.rb +1 -1
  46. data/test/test_helper.rb +13 -4
  47. metadata +67 -50
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rake'
4
- gem 'main'
1
+ source 'https://rubygems.org/'
2
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,21 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruboto (0.11.0.rc.0)
5
+ main (>= 4.7.2)
6
+
1
7
  GEM
2
8
  remote: https://rubygems.org/
3
9
  specs:
4
- arrayfields (4.7.4)
5
- chronic (0.6.7)
10
+ arrayfields (4.9.0)
11
+ chronic (0.9.1)
6
12
  fattr (2.2.1)
7
- main (5.0.1)
13
+ main (5.2.0)
8
14
  arrayfields (>= 4.7.4)
9
15
  chronic (>= 0.6.2)
10
16
  fattr (>= 2.2.0)
11
17
  map (>= 5.1.0)
12
- map (5.5.0)
13
- rake (0.9.2.2)
18
+ map (6.3.0)
19
+ rake (10.0.4)
14
20
 
15
21
  PLATFORMS
16
22
  java
17
23
  ruby
18
24
 
19
25
  DEPENDENCIES
20
- main
21
26
  rake
27
+ ruboto!
data/README.md CHANGED
@@ -154,11 +154,11 @@ You generate an app with the option `--activity FooActivity`, which means that r
154
154
 
155
155
  class FooActivity
156
156
  include Ruboto::Activity
157
- def on_create(bundle)
157
+ def onCreate(bundle)
158
158
  Log.v 'MYAPPNAME', 'onCreate got called!'
159
159
  end
160
160
 
161
- def on_pause
161
+ def onPause
162
162
  Log.v 'MYAPPNAME', 'onPause got called!'
163
163
  end
164
164
  end
@@ -163,7 +163,7 @@ end
163
163
 
164
164
  desc 'Start the emulator with larger disk'
165
165
  task :emulator do
166
- sh "emulator -partition-size 1024 -avd Android_#{sdk_level_name}"
166
+ start_emulator
167
167
  end
168
168
 
169
169
  desc 'Start the application on the device/emulator.'
@@ -257,24 +257,40 @@ task :bundle => BUNDLE_JAR
257
257
  file BUNDLE_JAR => [GEM_FILE, GEM_LOCK_FILE] do
258
258
  next unless File.exists? GEM_FILE
259
259
  puts "Generating #{BUNDLE_JAR}"
260
+ require 'bundler'
261
+ require 'bundler/vendored_thor'
260
262
 
261
- # Override RUBY_ENGINE (we can bundle from MRI for JRuby)
263
+ # Store original RubyGems/Bundler environment
262
264
  platforms = Gem.platforms
263
265
  ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE
266
+ gem_paths = {'GEM_HOME' => Gem.path, 'GEM_PATH' => Gem.dir}
267
+
268
+ # Override RUBY_ENGINE (we can bundle from MRI for JRuby)
264
269
  Gem.platforms = [Gem::Platform::RUBY, Gem::Platform.new('universal-java')]
265
- Object.const_set('RUBY_ENGINE', 'jruby')
270
+ Gem.paths = {'GEM_HOME' => BUNDLE_PATH, 'GEM_PATH' => BUNDLE_PATH}
271
+ old_verbose, $VERBOSE = $VERBOSE, nil
272
+ begin
273
+ Object.const_set('RUBY_ENGINE', 'jruby')
274
+ ensure
275
+ $VERBOSE = old_verbose
276
+ end
266
277
 
267
278
  ENV['BUNDLE_GEMFILE'] = GEM_FILE
268
- require 'bundler'
279
+ Bundler.ui = Bundler::UI::Shell.new
269
280
  Bundler.bundle_path = Pathname.new BUNDLE_PATH
270
-
271
281
  definition = Bundler.definition
272
282
  definition.validate_ruby!
273
283
  Bundler::Installer.install(Bundler.root, definition)
274
284
 
275
285
  # Restore RUBY_ENGINE (limit the scope of this hack)
276
- Object.const_set('RUBY_ENGINE', ruby_engine) if ruby_engine
286
+ old_verbose, $VERBOSE = $VERBOSE, nil
287
+ begin
288
+ Object.const_set('RUBY_ENGINE', ruby_engine)
289
+ ensure
290
+ $VERBOSE = old_verbose
291
+ end
277
292
  Gem.platforms = platforms
293
+ Gem.paths = gem_paths
278
294
 
279
295
  gem_paths = Dir["#{BUNDLE_PATH}/gems"]
280
296
  raise 'Gem path not found' if gem_paths.empty?
@@ -284,7 +300,7 @@ file BUNDLE_JAR => [GEM_FILE, GEM_LOCK_FILE] do
284
300
 
285
301
  if package != 'org.ruboto.core' && JRUBY_JARS.none? { |f| File.exists? f }
286
302
  Dir.chdir gem_path do
287
- Dir['{activerecord-jdbc-adapter, jruby-openssl}-*'].each do |g|
303
+ Dir['{activerecord-jdbc-adapter,jruby-openssl}-*'].each do |g|
288
304
  puts "Removing #{g} gem since it is included in the RubotoCore platform apk."
289
305
  FileUtils.rm_rf g
290
306
  end
@@ -361,6 +377,10 @@ Java::arjdbc.jdbc.AdapterJavaService.new.basicLoad(JRuby.runtime)
361
377
  # FileUtils.rm_f(files)
362
378
  # ODOT
363
379
 
380
+ # FIXME(uwe): Extract files with case sensitive names for ARJDBC 1.2.7-1.3.x
381
+ puts `jar xf #{jar} arjdbc/mssql/MSSQLRubyJdbcConnection.class arjdbc/sqlite3/SQLite3RubyJdbcConnection.class`
382
+ # EMXIF
383
+
364
384
  elsif jar =~ /shared\/jopenssl.jar$/
365
385
  jar_load_code = <<-END_CODE
366
386
  require 'jruby'
@@ -625,3 +645,141 @@ def stop_app
625
645
  output = `adb shell ps | grep #{package} | awk '{print $2}' | xargs adb shell kill`
626
646
  output !~ /Operation not permitted/
627
647
  end
648
+
649
+ def start_emulator
650
+ STDOUT.sync = true
651
+ # FIXME(uwe): Use RBConfig instead
652
+ if `uname -m`.chomp == 'x86_64'
653
+ emulator_cmd = 'emulator64-arm'
654
+ else
655
+ emulator_cmd = 'emulator-arm'
656
+ end
657
+
658
+ emulator_opts = '-partition-size 256'
659
+ if ENV['DISPLAY'].nil?
660
+ emulator_opts << ' -no-window -no-audio'
661
+ end
662
+
663
+ avd_name = "Android_#{sdk_level_name}"
664
+ new_snapshot = false
665
+ loop do
666
+ `killall -0 #{emulator_cmd} 2> /dev/null`
667
+ if $? == 0
668
+ `killall #{emulator_cmd}`
669
+ 10.times do |i|
670
+ `killall -0 #{emulator_cmd} 2> /dev/null`
671
+ if $? != 0
672
+ break
673
+ end
674
+ if i == 3
675
+ print 'Waiting for emulator to die: ...'
676
+ elsif i > 3
677
+ print '.'
678
+ end
679
+ sleep 1
680
+ end
681
+ puts
682
+ `killall -0 #{emulator_cmd} 2> /dev/null`
683
+ if $? == 0
684
+ puts 'Emulator still running.'
685
+ `killall -9 #{emulator_cmd}`
686
+ sleep 1
687
+ end
688
+ end
689
+
690
+ if [17, 16, 15, 13, 11].include? sdk_level
691
+ abi_opt = '--abi armeabi-v7a'
692
+ elsif sdk_level == 10
693
+ abi_opt = '--abi armeabi'
694
+ end
695
+
696
+ unless File.exists? "#{ENV['HOME']}/.android/avd/#{avd_name}.avd"
697
+ puts "Creating AVD #{avd_name}"
698
+ heap_size = File.read('AndroidManifest.xml') =~ 'largeHeap' ? 256 : 48
699
+ # FIXME(uwe): Use Ruby instead.
700
+ # FIXME(uwe): Only change the heap size to be larger.
701
+ # `sed -i.bak -e "s/vm.heapSize=[0-9]*/vm.heapSize=#{heap_size}/" #{ENV['ANDROID_HOME']}/platforms/*/*/*/hardware.ini`
702
+ `echo n | android create avd -a -n #{avd_name} -t android-#{sdk_level} #{abi_opt} -c 64M -s HVGA`
703
+ `sed -i.bak -e "s/vm.heapSize=[0-9]*/vm.heapSize=#{heap_size}/" #{ENV['HOME']}/.android/avd/#{avd_name}.avd/config.ini`
704
+ new_snapshot = true
705
+ end
706
+
707
+ puts 'Start emulator'
708
+ system "emulator -avd #{avd_name} #{emulator_opts} &"
709
+
710
+ 3.times do |i|
711
+ sleep 1
712
+ `killall -0 #{emulator_cmd} 2> /dev/null`
713
+ if $? == 0
714
+ break
715
+ end
716
+ if i == 3
717
+ print 'Waiting for emulator: ...'
718
+ elsif i > 3
719
+ print '.'
720
+ end
721
+ end
722
+ puts
723
+ `killall -0 #{emulator_cmd} 2> /dev/null`
724
+ if $? != 0
725
+ puts 'Unable to start the emulator. Retrying without loading snapshot.'
726
+ system "emulator -no-snapshot-load -avd #{avd_name} #{emulator_opts} &"
727
+ 10.times do |i|
728
+ `killall -0 #{emulator_cmd} 2> /dev/null`
729
+ if $? == 0
730
+ new_snapshot = true
731
+ break
732
+ end
733
+ if i == 3
734
+ print 'Waiting for emulator: ...'
735
+ elsif i > 3
736
+ print '.'
737
+ end
738
+ sleep 1
739
+ end
740
+ end
741
+
742
+ `killall -0 #{emulator_cmd} 2> /dev/null`
743
+ if $? == 0
744
+ print 'Emulator started: '
745
+ 50.times do
746
+ if `adb get-state`.chomp == 'device'
747
+ break
748
+ end
749
+ print '.'
750
+ sleep 1
751
+ end
752
+ puts
753
+ if `adb get-state`.chomp == 'device'
754
+ break
755
+ end
756
+ end
757
+ puts 'Unable to start the emulator.'
758
+ end
759
+
760
+ if new_snapshot
761
+ puts 'Allow the emulator to calm down a bit.'
762
+ sleep 15
763
+ end
764
+
765
+ system %Q{(
766
+ set +e
767
+ for i in 1 2 3 4 5 6 7 8 9 10 ; do
768
+ sleep 6
769
+ adb shell input keyevent 82 >/dev/null 2>&1
770
+ if [ "$?" == "0" ] ; then
771
+ set -e
772
+ adb shell input keyevent 82 >/dev/null 2>&1
773
+ adb shell input keyevent 4 >/dev/null 2>&1
774
+ exit 0
775
+ fi
776
+ done
777
+ echo "Failed to unlock screen"
778
+ set -e
779
+ exit 1
780
+ ) &}
781
+
782
+ system "adb logcat > adb_logcat.log &"
783
+
784
+ puts "Emulator #{avd_name} started OK."
785
+ end
@@ -6,7 +6,7 @@ ruboto_import_widgets :Button, :LinearLayout, :TextView
6
6
  # http://xkcd.com/378/
7
7
 
8
8
  class SampleActivity
9
- def on_create(bundle)
9
+ def onCreate(bundle)
10
10
  super
11
11
  set_title 'Domo arigato, Mr Ruboto!'
12
12
 
@@ -11,11 +11,11 @@ setup do |activity|
11
11
  end
12
12
 
13
13
  test('initial setup') do |activity|
14
- assert_equal "What hath Matz wrought?", @text_view.text
14
+ assert_equal 'What hath Matz wrought?', @text_view.text
15
15
  end
16
16
 
17
17
  test('button changes text') do |activity|
18
18
  button = activity.findViewById(43)
19
19
  button.performClick
20
- assert_equal "What hath Matz wrought!", @text_view.text
20
+ assert_equal 'What hath Matz wrought!', @text_view.text
21
21
  end
@@ -2,9 +2,9 @@ import android.util.Log
2
2
 
3
3
  class SampleBroadcastReceiver
4
4
  # will get called whenever the BroadcastReceiver receives an intent (whenever onReceive is called)
5
- def on_receive(context, intent)
6
- Log.v "SampleBroadcastReceiver", 'Broadcast received!'
7
- Log.v "SampleBroadcastReceiver", intent.getExtras.to_s
5
+ def onReceive(context, intent)
6
+ Log.v 'SampleBroadcastReceiver', 'Broadcast received!'
7
+ Log.v 'SampleBroadcastReceiver', intent.getExtras.to_s
8
8
  rescue Exception
9
9
  Log.e "Exception processing broadcast: #{$!.message}\n#{$!.backtrace.join("\n")}"
10
10
  end
@@ -27,7 +27,7 @@ test('broadcast changes title', :ui => false) do |activity|
27
27
  receiver_ready = true
28
28
  android.os.Looper.loop
29
29
  rescue
30
- puts "Exception starting receiver"
30
+ puts 'Exception starting receiver'
31
31
  puts $!.message
32
32
  puts $!.backtrace.join("\n")
33
33
  end
@@ -7,8 +7,8 @@ require 'ruboto/util/toast'
7
7
  # online:
8
8
  # http://developer.android.com/reference/android/app/Service.html
9
9
  class SampleService
10
- def on_start_command(intent, flags, startId)
11
- toast "Hello from the service"
10
+ def onStartCommand(intent, flags, startId)
11
+ toast 'Hello from the service'
12
12
  android.app.Service::START_NOT_STICKY
13
13
  end
14
14
  end
@@ -31,6 +31,9 @@ public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
31
31
  public void onReceive(android.content.Context context, android.content.Intent intent) {
32
32
  try {
33
33
  Log.d("onReceive: " + this);
34
+ if (ScriptLoader.isCalledFromJRuby()) {
35
+ return;
36
+ }
34
37
  if (!scriptLoaded) {
35
38
  if (JRubyAdapter.setUpJRuby(context)) {
36
39
  ScriptLoader.loadScript(this);
@@ -47,7 +50,13 @@ public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
47
50
  JRubyAdapter.put("$intent", intent);
48
51
  JRubyAdapter.runScriptlet("$broadcast_receiver.on_receive($context, $intent)");
49
52
  } else if (JRubyAdapter.isJRubyOneSeven()) {
53
+ // FIXME(uwe): Simplify when we stop support for snake case aliasing interface callback methods.
54
+ if ((Boolean)JRubyAdapter.runScriptlet(scriptInfo.getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :onReceive}")) {
55
+ JRubyAdapter.runRubyMethod(this, "onReceive", new Object[]{context, intent});
56
+ } else if ((Boolean)JRubyAdapter.runScriptlet(scriptInfo.getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :on_receive}")) {
50
57
  JRubyAdapter.runRubyMethod(this, "on_receive", new Object[]{context, intent});
58
+ }
59
+ // EMXIF
51
60
  } else {
52
61
  throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
53
62
  }
@@ -18,7 +18,10 @@ public class EntryPointActivity extends org.ruboto.RubotoActivity {
18
18
  private ProgressDialog loadingDialog;
19
19
  private boolean dialogCancelled = false;
20
20
  private BroadcastReceiver receiver;
21
+
22
+ // FIXME(uwe): Remove this field? Duplicated by ScriptInfo.isLoaded() ?
21
23
  protected boolean appStarted = false;
24
+ // EMXIF
22
25
 
23
26
  public void onCreate(Bundle bundle) {
24
27
  Log.d("onCreate: ");
@@ -250,7 +250,7 @@ public class JRubyAdapter {
250
250
  System.setProperty("jruby.objectspace.enabled", "false");
251
251
  System.setProperty("jruby.thread.pooling", "true");
252
252
  System.setProperty("jruby.native.enabled", "false");
253
- // System.setProperty("jruby.compat.version", "RUBY1_8"); // RUBY1_9 is the default in JRuby 1.7
253
+ // System.setProperty("jruby.compat.version", "RUBY2_0"); // RUBY1_9 is the default in JRuby 1.7
254
254
  System.setProperty("jruby.ir.passes", "LocalOptimizationPass,DeadCodeElimination");
255
255
  System.setProperty("jruby.backtrace.style", "normal"); // normal raw full mri
256
256
 
@@ -305,6 +305,59 @@ public class JRubyAdapter {
305
305
  }
306
306
 
307
307
  try {
308
+ //////////////////////////////////
309
+ //
310
+ // Set jruby.home
311
+ //
312
+
313
+ String jrubyHome = "file:" + apkName + "!/jruby.home";
314
+
315
+ // FIXME(uwe): Remove when we stop supporting RubotoCore 0.4.7
316
+ Log.i("RUBOTO_CORE_VERSION_NAME: " + RUBOTO_CORE_VERSION_NAME);
317
+ if (RUBOTO_CORE_VERSION_NAME != null &&
318
+ (RUBOTO_CORE_VERSION_NAME.equals("0.4.7") || RUBOTO_CORE_VERSION_NAME.equals("0.4.8"))) {
319
+ jrubyHome = "file:" + apkName + "!";
320
+ }
321
+ // EMXIF
322
+
323
+ Log.i("Setting JRUBY_HOME: " + jrubyHome);
324
+ // This needs to be set before the ScriptingContainer is initialized
325
+ System.setProperty("jruby.home", jrubyHome);
326
+
327
+ //////////////////////////////////
328
+ //
329
+ // Determine Output
330
+ //
331
+
332
+ if (out != null) {
333
+ output = out;
334
+ }
335
+
336
+ //////////////////////////////////
337
+ //
338
+ // Disable rubygems
339
+ //
340
+
341
+ Class rubyClass = Class.forName("org.jruby.Ruby", true, scriptingContainerClass.getClassLoader());
342
+ Class rubyInstanceConfigClass = Class.forName("org.jruby.RubyInstanceConfig", true, scriptingContainerClass.getClassLoader());
343
+
344
+ Object config = rubyInstanceConfigClass.getConstructor().newInstance();
345
+ rubyInstanceConfigClass.getMethod("setDisableGems", boolean.class).invoke(config, true);
346
+ rubyInstanceConfigClass.getMethod("setLoader", ClassLoader.class).invoke(config, classLoader);
347
+
348
+ if (output != null) {
349
+ rubyInstanceConfigClass.getMethod("setOutput", PrintStream.class).invoke(config, output);
350
+ rubyInstanceConfigClass.getMethod("setError", PrintStream.class).invoke(config, output);
351
+ }
352
+
353
+ // This will become the global runtime and be used by our ScriptingContainer
354
+ rubyClass.getMethod("newInstance", rubyInstanceConfigClass).invoke(null, config);
355
+
356
+ //////////////////////////////////
357
+ //
358
+ // Create the ScriptingContainer
359
+ //
360
+
308
361
  Class scopeClass = Class.forName("org.jruby.embed.LocalContextScope", true, scriptingContainerClass.getClassLoader());
309
362
  Class behaviorClass = Class.forName("org.jruby.embed.LocalVariableBehavior", true, scriptingContainerClass.getClassLoader());
310
363
 
@@ -330,28 +383,8 @@ public class JRubyAdapter {
330
383
  Log.e("Unable to find app files dir!");
331
384
  }
332
385
 
333
- if (out != null) {
334
- output = out;
335
- setOutputStream(out);
336
- } else if (output != null) {
337
- setOutputStream(output);
338
- }
339
-
340
- String jrubyHome = "file:" + apkName + "!/jruby.home";
341
-
342
- // FIXME(uwe): Remove when we stop supporting RubotoCore 0.4.7
343
- Log.i("RUBOTO_CORE_VERSION_NAME: " + RUBOTO_CORE_VERSION_NAME);
344
- if (RUBOTO_CORE_VERSION_NAME != null &&
345
- (RUBOTO_CORE_VERSION_NAME.equals("0.4.7") || RUBOTO_CORE_VERSION_NAME.equals("0.4.8"))) {
346
- jrubyHome = "file:" + apkName + "!";
347
- }
348
- // EMXIF
349
-
350
- Log.i("Setting JRUBY_HOME: " + jrubyHome);
351
- System.setProperty("jruby.home", jrubyHome);
352
-
353
386
  addLoadPath(scriptsDirName(appContext));
354
- put("$package_name", appContext.getPackageName());
387
+ put("$package_name", appContext.getPackageName());
355
388
 
356
389
  initialized = true;
357
390
  } catch (ClassNotFoundException e) {
@@ -443,7 +476,8 @@ public class JRubyAdapter {
443
476
 
444
477
  // FIXME(uwe): Remove when we stop supporting Ruby 1.8
445
478
  @Deprecated public static boolean isRubyOneNine() {
446
- return ((String)get("RUBY_VERSION")).startsWith("1.9.");
479
+ String rv = ((String)get("RUBY_VERSION"));
480
+ return rv.startsWith("2.0.") || rv.startsWith("1.9.");
447
481
  }
448
482
 
449
483
  static void printStackTrace(Throwable t) {
@@ -76,12 +76,15 @@ public class ScriptLoader {
76
76
  }
77
77
  System.out.println("Set class: " + rubyClass);
78
78
  JRubyAdapter.put(component.getScriptInfo().getRubyClassName(), rubyClass);
79
- Thread t = new Thread(new Runnable(){
79
+ // FIXME(uwe): Collect these threads in a ThreadGroup ?
80
+ Thread t = new Thread(null, new Runnable(){
80
81
  public void run() {
82
+ long loadStart = System.currentTimeMillis();
81
83
  JRubyAdapter.setScriptFilename(rubyScript.getAbsolutePath());
82
84
  JRubyAdapter.runScriptlet(script);
85
+ System.out.println("Script load took " + (System.currentTimeMillis() - loadStart) + "ms");
83
86
  }
84
- });
87
+ }, "ScriptLoader for " + rubyClass, 128 * 1024);
85
88
  try {
86
89
  t.start();
87
90
  t.join();
@@ -15,7 +15,7 @@ require 'ruboto/package'
15
15
  module Ruboto
16
16
  module Context
17
17
  def start_ruboto_dialog(remote_variable, theme=Java::android.R.style::Theme_Dialog, &block)
18
- java_import "org.ruboto.RubotoDialog"
18
+ java_import 'org.ruboto.RubotoDialog'
19
19
  start_ruboto_activity(remote_variable, RubotoDialog, theme, &block)
20
20
  end
21
21
 
@@ -28,22 +28,21 @@ module Ruboto
28
28
  else
29
29
  options = {}
30
30
  end
31
- global_variable_name = nil
32
31
  end
33
32
 
34
- class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
35
- if !Object.const_defined?(class_name)
36
- Object.const_set(class_name, Class.new(&block))
37
- else
33
+ class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split('/').last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
34
+ if Object.const_defined?(class_name)
38
35
  Object.const_get(class_name).class_eval(&block) if block_given?
36
+ else
37
+ Object.const_set(class_name, Class.new(&block))
39
38
  end
40
39
  b = Java::android.os.Bundle.new
41
- b.putInt("Theme", theme) if theme
42
- b.putString("ClassName", class_name)
43
- b.putString("Script", options[:script]) if options[:script]
40
+ b.putInt('Theme', theme) if theme
41
+ b.putString('ClassName', class_name)
42
+ b.putString('Script', options[:script]) if options[:script]
44
43
  i = android.content.Intent.new
45
44
  i.setClass self, klass.java_class
46
- i.putExtra("Ruboto Config", b)
45
+ i.putExtra('Ruboto Config', b)
47
46
  startActivity i
48
47
  self
49
48
  end
@@ -61,7 +60,7 @@ module Ruboto
61
60
 
62
61
  end
63
62
 
64
- java_import "android.content.Context"
63
+ java_import 'android.content.Context'
65
64
  Context.class_eval do
66
65
  include Ruboto::Context
67
66
  end
@@ -85,7 +84,7 @@ def ruboto_configure_activity(klass)
85
84
  end
86
85
  end
87
86
 
88
- java_import "android.app.Activity"
89
- java_import "org.ruboto.RubotoActivity"
87
+ java_import 'android.app.Activity'
88
+ java_import 'org.ruboto.RubotoActivity'
90
89
  ruboto_configure_activity(RubotoActivity)
91
90
 
@@ -21,5 +21,5 @@ module Kernel
21
21
  end
22
22
  end
23
23
 
24
- java_import "android.R"
25
- AndroidIds = JavaUtilities.get_proxy_class("android.R$id")
24
+ java_import 'android.R'
25
+ AndroidIds = JavaUtilities.get_proxy_class('android.R$id')
@@ -8,7 +8,7 @@
8
8
 
9
9
  require 'ruboto/base'
10
10
 
11
- java_import "org.ruboto.RubotoBroadcastReceiver"
11
+ java_import 'org.ruboto.RubotoBroadcastReceiver'
12
12
  module Ruboto
13
13
  module BroadcastReceiver
14
14
  end
@@ -1,10 +1,10 @@
1
- $package = eval("Java::#{$package_name}")
1
+ $package = eval("Java::#{$package_name}")
2
2
 
3
3
  module Ruboto
4
4
  java_import "#{$package_name}.R"
5
5
  begin
6
6
  Id = JavaUtilities.get_proxy_class("#{$package_name}.R$id")
7
7
  rescue NameError
8
- Java::android.util.Log.d "RUBOTO", "no R$id"
8
+ Java::android.util.Log.d 'RUBOTO', 'no R$id'
9
9
  end
10
10
  end
@@ -8,9 +8,9 @@
8
8
 
9
9
  require 'ruboto/activity'
10
10
 
11
- java_import "android.preference.PreferenceScreen"
12
- java_import "android.preference.Preference"
13
- java_import "org.ruboto.RubotoPreferenceActivity"
11
+ java_import 'android.preference.PreferenceScreen'
12
+ java_import 'android.preference.Preference'
13
+ java_import 'org.ruboto.RubotoPreferenceActivity'
14
14
  ruboto_configure_activity(RubotoPreferenceActivity)
15
15
 
16
16
  RubotoPreferenceActivity.class_eval do
@@ -49,7 +49,7 @@ def ruboto_import_preferences(*preferences)
49
49
  preferences.each { |i| ruboto_import_preference i }
50
50
  end
51
51
 
52
- def ruboto_import_preference(class_name, package_name="android.preference")
52
+ def ruboto_import_preference(class_name, package_name='android.preference')
53
53
  klass = java_import("#{package_name}.#{class_name}") || eval("Java::#{package_name}.#{class_name}")
54
54
  return unless klass
55
55
 
@@ -9,8 +9,8 @@ require 'ruboto/package'
9
9
  #
10
10
  #######################################################
11
11
 
12
- java_import "android.content.Context"
13
- java_import "org.ruboto.RubotoService"
12
+ java_import 'android.content.Context'
13
+ java_import 'org.ruboto.RubotoService'
14
14
 
15
15
  module Ruboto
16
16
  module Context
@@ -23,21 +23,20 @@ module Ruboto
23
23
  else
24
24
  options = {}
25
25
  end
26
- global_variable_name = nil
27
26
  end
28
27
 
29
- class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
30
- if !Object.const_defined?(class_name)
31
- Object.const_set(class_name, Class.new(&block))
32
- else
28
+ class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split('/').last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
29
+ if Object.const_defined?(class_name)
33
30
  Object.const_get(class_name).class_eval(&block) if block_given?
31
+ else
32
+ Object.const_set(class_name, Class.new(&block))
34
33
  end
35
34
  b = Java::android.os.Bundle.new
36
- b.putString("ClassName", class_name)
37
- b.putString("Script", options[:script]) if options[:script]
35
+ b.putString('ClassName', class_name)
36
+ b.putString('Script', options[:script]) if options[:script]
38
37
  i = android.content.Intent.new
39
38
  i.setClass self, klass.java_class
40
- i.putExtra("Ruboto Config", b)
39
+ i.putExtra('Ruboto Config', b)
41
40
  self.startService i
42
41
  self
43
42
  end