Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Issue #395 Display initial progress dialog while activity script is…

… loading.
  • Loading branch information...
commit cbe92864dc9693a040f7c5a6c5e2a88aa3a233d4 1 parent 902e14d
@donv donv authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- ruboto (0.11.0)
+ ruboto (0.12.0.dev)
main (>= 4.7.2)
GEM
View
2  assets/samples/sample_broadcast_receiver.rb
@@ -1,7 +1,7 @@
import android.util.Log
class SampleBroadcastReceiver
- # will get called whenever the BroadcastReceiver receives an intent (whenever onReceive is called)
+ # Will get called whenever the BroadcastReceiver receives an intent.
def onReceive(context, intent)
Log.v 'SampleBroadcastReceiver', 'Broadcast received!'
Log.v 'SampleBroadcastReceiver', intent.getExtras.to_s
View
5 assets/src/RubotoActivity.java
@@ -48,15 +48,18 @@ public void onCreate(Bundle bundle) {
}
if (JRubyAdapter.isInitialized() && scriptInfo.isReadyToLoad()) {
- ScriptLoader.loadScript(this, (Object[]) args);
+ ScriptLoader.loadScript(this);
+ ScriptLoader.callOnCreate(this, (Object[]) args);
} else {
super.onCreate(bundle);
}
}
+ // FIXME(uwe): What is this for?
public boolean rubotoAttachable() {
return true;
}
+ // EMXIF
/****************************************************************************************
*
View
5 assets/src/RubotoBroadcastReceiver.java
@@ -30,7 +30,7 @@ public THE_RUBOTO_CLASS(String name) {
public void onReceive(android.content.Context context, android.content.Intent intent) {
try {
- Log.d("onReceive: " + this);
+ Log.d("onReceive: " + this + " " + ScriptLoader.isCalledFromJRuby() + " " + scriptLoaded);
if (ScriptLoader.isCalledFromJRuby()) {
return;
}
@@ -43,6 +43,8 @@ public void onReceive(android.content.Context context, android.content.Intent in
}
}
+ Log.d("onReceive: JRuby version: " + JRubyAdapter.isJRubyPreOneSeven() + " " + JRubyAdapter.isJRubyOneSeven() + " " + JRubyAdapter.runScriptlet(scriptInfo.getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :onReceive}") + " " + scriptInfo.getRubyClassName());
+ Log.d("onReceive " + this + " " + scriptInfo.getRubyInstance() + "(" + scriptInfo.getRubyClassName() + "): " + JRubyAdapter.runScriptlet(scriptInfo.getRubyClassName() + ".instance_methods(false)"));
// FIXME(uwe): Simplify when we stop supporting JRuby 1.6.x
if (JRubyAdapter.isJRubyPreOneSeven()) {
JRubyAdapter.put("$broadcast_receiver", this);
@@ -52,6 +54,7 @@ public void onReceive(android.content.Context context, android.content.Intent in
} else if (JRubyAdapter.isJRubyOneSeven()) {
// FIXME(uwe): Simplify when we stop support for snake case aliasing interface callback methods.
if ((Boolean)JRubyAdapter.runScriptlet(scriptInfo.getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :onReceive}")) {
+ Log.d("onReceive: call method");
JRubyAdapter.runRubyMethod(this, "onReceive", new Object[]{context, intent});
} else if ((Boolean)JRubyAdapter.runScriptlet(scriptInfo.getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :on_receive}")) {
JRubyAdapter.runRubyMethod(this, "on_receive", new Object[]{context, intent});
View
72 assets/src/org/ruboto/EntryPointActivity.java
@@ -13,6 +13,13 @@
import android.widget.TextView;
import android.widget.Toast;
+/**
+ * This Activity acts as an entry point to the app. It must initialize the
+ * JRuby runtime before continuing its life cycle.
+ * While JRuby is initializing, a progress dialog is shown.
+ * If R.layout.splash is defined, by adding a res/layout/splash.xml file,
+ * this layout is displayed instead of the progress dialog.
+ */
public class EntryPointActivity extends org.ruboto.RubotoActivity {
private int splash = 0;
private ProgressDialog loadingDialog;
@@ -24,7 +31,7 @@
// EMXIF
public void onCreate(Bundle bundle) {
- Log.d("onCreate: ");
+ Log.d("EntryPointActivity onCreate:");
try {
splash = Class.forName(getPackageName() + ".R$layout").getField("splash").getInt(null);
@@ -34,6 +41,9 @@ public void onCreate(Bundle bundle) {
if (JRubyAdapter.isInitialized()) {
appStarted = true;
+ } else {
+ showProgress();
+ initJRuby(true);
}
super.onCreate(bundle);
}
@@ -53,26 +63,6 @@ public void onResume() {
fireRubotoActivity();
} else {
Log.d("Not initialized");
- showProgress();
- receiver = new BroadcastReceiver(){
- public void onReceive(Context context, Intent intent) {
- Log.i("received broadcast: " + intent);
- Log.i("URI: " + intent.getData());
- if (intent.getData().toString().equals("package:org.ruboto.core")) {
- Toast.makeText(context,"Ruboto Core is now installed.",Toast.LENGTH_SHORT).show();
- if (receiver != null) {
- unregisterReceiver(receiver);
- receiver = null;
- }
- showProgress();
- initJRuby(false);
- }
- }
- };
- IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
- filter.addDataScheme("package");
- registerReceiver(receiver, filter);
- initJRuby(true);
super.onResume();
}
}
@@ -103,12 +93,9 @@ public void run() {
final boolean jrubyOk = JRubyAdapter.setUpJRuby(EntryPointActivity.this);
if (jrubyOk) {
Log.d("onResume: JRuby OK");
- runOnUiThread(new Runnable() {
- public void run() {
- fireRubotoActivity();
- }
- });
+ fireRubotoActivity();
} else {
+ registerPackageInstallReceiver();
runOnUiThread(new Runnable() {
public void run() {
if (firstTime) {
@@ -152,10 +139,15 @@ protected void fireRubotoActivity() {
if(appStarted) return;
appStarted = true;
Log.i("Starting activity");
- ScriptLoader.loadScript(this, args[0]);
- onStart();
- super.onResume();
- hideProgress();
+ ScriptLoader.loadScript(this);
+ runOnUiThread(new Runnable() {
+ public void run() {
+ ScriptLoader.callOnCreate(EntryPointActivity.this, args[0]);
+ onStart();
+ onResume();
+ hideProgress();
+ }
+ });
}
private void showProgress() {
@@ -186,4 +178,24 @@ private void hideProgress() {
}
}
+ private void registerPackageInstallReceiver() {
+ receiver = new BroadcastReceiver(){
+ public void onReceive(Context context, Intent intent) {
+ Log.i("received broadcast: " + intent);
+ Log.i("URI: " + intent.getData());
+ if (intent.getData().toString().equals("package:org.ruboto.core")) {
+ Toast.makeText(context,"Ruboto Core is now installed.",Toast.LENGTH_SHORT).show();
+ if (receiver != null) {
+ unregisterReceiver(receiver);
+ receiver = null;
+ }
+ showProgress();
+ initJRuby(false);
+ }
+ }
+ };
+ IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+ filter.addDataScheme("package");
+ registerReceiver(receiver, filter);
+ }
}
View
70 assets/src/org/ruboto/ScriptLoader.java
@@ -21,15 +21,17 @@ public static boolean isCalledFromJRuby() {
return false;
}
- public static void loadScript(final RubotoComponent component, Object... args) {
+ public static void loadScript(final RubotoComponent component) {
try {
if (component.getScriptInfo().getScriptName() != null) {
- System.out.println("Looking for Ruby class: " + component.getScriptInfo().getRubyClassName());
+ Log.d("Loading component: " + component);
+ Log.d("Looking for Ruby class: " + component.getScriptInfo().getRubyClassName());
Object rubyClass = JRubyAdapter.get(component.getScriptInfo().getRubyClassName());
- System.out.println("Found: " + rubyClass);
+ Log.d("Found: " + rubyClass);
final Script rubyScript = new Script(component.getScriptInfo().getScriptName());
Object rubyInstance;
if (rubyScript.exists()) {
+ Log.d("Found script.");
rubyInstance = component;
final String script = rubyScript.getContents();
boolean scriptContainsClass = script.matches("(?s).*class "
@@ -38,12 +40,13 @@ public static void loadScript(final RubotoComponent component, Object... args) {
.equals(component.getClass().getSimpleName());
if (scriptContainsClass) {
if (hasBackingJavaClass) {
+ Log.d("hasBackingJavaClass");
if (rubyClass != null && !rubyClass.toString().startsWith("Java::")) {
- System.out.println("Found Ruby class instead of Java class. Reloading.");
+ Log.d("Found Ruby class instead of Java class. Reloading.");
rubyClass = null;
}
} else {
- System.out.println("Script defines methods on meta class");
+ Log.d("Script defines methods on meta class");
// FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
if (JRubyAdapter.isJRubyPreOneSeven() || JRubyAdapter.isRubyOneEight()) {
@@ -60,11 +63,11 @@ public static void loadScript(final RubotoComponent component, Object... args) {
}
}
if (rubyClass == null || !hasBackingJavaClass) {
- System.out.println("Loading script: " + component.getScriptInfo().getScriptName());
+ Log.d("Loading script: " + component.getScriptInfo().getScriptName());
if (scriptContainsClass) {
- System.out.println("Script contains class definition");
+ Log.d("Script contains class definition");
if (rubyClass == null && hasBackingJavaClass) {
- System.out.println("Script has separate Java class");
+ Log.d("Script has separate Java class");
// FIXME(uwe): Simplify when we stop support for JRuby < 1.7.0
if (!JRubyAdapter.isJRubyPreOneSeven()) {
@@ -74,7 +77,7 @@ public static void loadScript(final RubotoComponent component, Object... args) {
rubyClass = JRubyAdapter.runScriptlet("Java::" + component.getClass().getName());
}
- System.out.println("Set class: " + rubyClass);
+ Log.d("Set class: " + rubyClass);
JRubyAdapter.put(component.getScriptInfo().getRubyClassName(), rubyClass);
// FIXME(uwe): Collect these threads in a ThreadGroup ?
Thread t = new Thread(null, new Runnable(){
@@ -82,7 +85,7 @@ public void run() {
long loadStart = System.currentTimeMillis();
JRubyAdapter.setScriptFilename(rubyScript.getAbsolutePath());
JRubyAdapter.runScriptlet(script);
- System.out.println("Script load took " + (System.currentTimeMillis() - loadStart) + "ms");
+ Log.d("Script load took " + (System.currentTimeMillis() - loadStart) + "ms");
}
}, "ScriptLoader for " + rubyClass, 128 * 1024);
try {
@@ -101,19 +104,16 @@ public void run() {
}
} else if (rubyClass != null) {
// We have a predefined Ruby class without corresponding Ruby source file.
- System.out.println("Create separate Ruby instance for class: " + rubyClass);
+ Log.d("Create separate Ruby instance for class: " + rubyClass);
rubyInstance = JRubyAdapter.runRubyMethod(rubyClass, "new");
JRubyAdapter.runRubyMethod(rubyInstance, "instance_variable_set", "@ruboto_java_instance", component);
} else {
// Neither script file nor predefined class
+ Log.e("Missing script and class. Either script or predefined class must be present.");
throw new RuntimeException("Either script or predefined class must be present.");
}
- if (rubyClass != null) {
- if (component instanceof android.content.Context) {
- callOnCreate(rubyInstance, args, component.getScriptInfo().getRubyClassName());
- }
- }
component.getScriptInfo().setRubyInstance(rubyInstance);
+ Log.d(component.getScriptInfo().getRubyInstance() + "(" + component.getScriptInfo().getRubyClassName() + "): " + JRubyAdapter.runScriptlet(component.getScriptInfo().getRubyClassName() + ".instance_methods(false)"));
}
} catch(IOException e){
e.printStackTrace();
@@ -123,27 +123,29 @@ public void run() {
}
}
- private static final void callOnCreate(Object rubyInstance, Object[] args, String rubyClassName) {
- System.out.println("Call onCreate on: " + rubyInstance + ", " + JRubyAdapter.get("JRUBY_VERSION"));
- // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
- if (JRubyAdapter.isJRubyPreOneSeven()) {
- if (args.length > 0) {
- JRubyAdapter.put("$bundle", args[0]);
- }
- JRubyAdapter.put("$ruby_instance", rubyInstance);
- JRubyAdapter.runScriptlet("$ruby_instance.on_create(" + (args.length > 0 ? "$bundle" : "") + ")");
- } else if (JRubyAdapter.isJRubyOneSeven()) {
- // FIXME(uwe): Simplify when we stop support for snake case aliasing interface callback methods.
- if ((Boolean)JRubyAdapter.runScriptlet(rubyClassName + ".instance_methods(false).any?{|m| m.to_sym == :onCreate}")) {
- JRubyAdapter.runRubyMethod(rubyInstance, "onCreate", args);
- } else if ((Boolean)JRubyAdapter.runScriptlet(rubyClassName + ".instance_methods(false).any?{|m| m.to_sym == :on_create}")) {
- JRubyAdapter.runRubyMethod(rubyInstance, "on_create", args);
+ public static final void callOnCreate(final RubotoComponent component, Object... args) {
+ if (component instanceof android.content.Context) {
+ Log.d("Call onCreate on: " + component.getScriptInfo().getRubyInstance() + ", " + JRubyAdapter.get("JRUBY_VERSION"));
+ // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
+ if (JRubyAdapter.isJRubyPreOneSeven()) {
+ if (args.length > 0) {
+ JRubyAdapter.put("$bundle", args[0]);
+ }
+ JRubyAdapter.put("$ruby_instance", component.getScriptInfo().getRubyInstance());
+ JRubyAdapter.runScriptlet("$ruby_instance.on_create(" + (args.length > 0 ? "$bundle" : "") + ")");
+ } else if (JRubyAdapter.isJRubyOneSeven()) {
+ // FIXME(uwe): Simplify when we stop support for snake case aliasing interface callback methods.
+ if ((Boolean)JRubyAdapter.runScriptlet(component.getScriptInfo().getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :onCreate}")) {
+ JRubyAdapter.runRubyMethod(component.getScriptInfo().getRubyInstance(), "onCreate", args);
+ } else if ((Boolean)JRubyAdapter.runScriptlet(component.getScriptInfo().getRubyClassName() + ".instance_methods(false).any?{|m| m.to_sym == :on_create}")) {
+ JRubyAdapter.runRubyMethod(component.getScriptInfo().getRubyInstance(), "on_create", args);
+ }
+ // EMXIF
+ } else {
+ throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
}
// EMXIF
- } else {
- throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
}
- // EMXIF
}
}
View
0  performance.txt → doc/performance.txt
File renamed without changes
View
41 doc/startup.txt
@@ -0,0 +1,41 @@
+Different startup sequences
+
+Initial entry point activity:
+
+InheritedActivity EntryPointActivity RubotoActivity Activity
+=================================================================================
+onCreate
+scriptInfo.setClassName ===> onCreate
+ showProgress
+ initJRuby ===> onCreate ===> onCreate
+
+===========================> onResume ===> onResume ===> onResume
+
+===========================> fireRubotoActivity
+ ScriptLoader.loadScript
+ runOnUiThread:
+ ScriptLoader.callOnCreate
+ onStart ===> onStart ===> onStart Duplicate!
+ onResume ===> onResume ===> onResume Duplicate!
+ hideProgress
+
+Second entry point activity:
+
+InheritedActivity EntryPointActivity RubotoActivity Activity
+=================================================================================
+onCreate
+scriptInfo.setClassName
+setClassName ===> onCreate
+ appStarted = true ===> onCreate
+ ScriptLoader.loadScript
+ ScriptLoader.callOnCreate => onCreate
+
+===========================> onResume ===> onResume ===> onResume
+
+
+
+RubotoActivity with class name:
+
+RubotoActivity Activity
+=================================================================================
+onCreate
View
11 lib/ruboto/util/verify.rb
@@ -17,7 +17,10 @@ def verify_manifest
end
def save_manifest
- File.open("AndroidManifest.xml", 'w') {|f| REXML::Formatters::OrderedAttributes.new(4).write(verify_manifest.document, f)}
+ File.open('AndroidManifest.xml', 'w') do |f|
+ REXML::Formatters::OrderedAttributes.new(4).write(verify_manifest.document, f)
+ f.puts
+ end
end
def verify_test_manifest
@@ -27,7 +30,7 @@ def verify_test_manifest
end
def save_test_manifest
- File.open("test/AndroidManifest.xml", 'w') {|f| verify_test_manifest.document.write(f, 4)}
+ File.open('test/AndroidManifest.xml', 'w') {|f| verify_test_manifest.document.write(f, 4)}
end
def verify_package
@@ -42,7 +45,7 @@ def verify_activity
def verify_sdk_versions
verify_manifest
- @uses_sdk ||= @manifest.elements["uses-sdk"]
+ @uses_sdk ||= @manifest.elements['uses-sdk']
abort "you must specify your sdk level in the manifest (e.g., <uses-sdk android:minSdkVersion='3' android:targetSdkVersion='8' />)" unless @uses_sdk
@uses_sdk
end
@@ -82,7 +85,7 @@ def verify_ruboto_config
end
def save_ruboto_config
- File.open("ruboto.yml", 'w') {|f| YAML.dump verify_ruboto_config}
+ File.open('ruboto.yml', 'w') {|f| f << YAML.dump(verify_ruboto_config)}
end
end
View
2  lib/ruboto/version.rb
@@ -1,4 +1,4 @@
module Ruboto
- VERSION = '0.11.0'
+ VERSION = '0.12.0.dev'
UPDATE_VERSION_LIMIT = '0.7.0'
end
View
2  matrix_tests.sh
@@ -60,3 +60,5 @@ for ANDROID_TARGET in $ANDROID_TARGETS ; do
done
done
done
+
+echo Matrix tests completed OK!
View
11 test/activity/stack_activity_test.rb
@@ -10,9 +10,10 @@
assert @text_view
end
-# ANDROID: 10, PLATFORM: 0.4.7, JRuby: 1.7.0.dev '28334966' expected, but got '28335067'
-# ANDROID: 15, PLATFORM: STANDALONE, JRuby: 1.7.0 '[28, 33, 51, 68]' expected, but got '[28, 33, 47, 64]'
-# ANDROID: 16, PLATFORM: 0.4.8.dev, JRuby: 1.7.0.preview2 '[29, 34, 47, 64]' expected, but got '[28, 33, 47, 64]'
+# ANDROID: 10, PLATFORM: 0.4.7, JRuby: 1.7.0.dev '28334966' expected, but got '28335067'
+# ANDROID: 10, PLATFORM: 0.5.3, JRuby: 1.7.3 '[28, 33, 46, 63]' expected, but got '[43, 48, 45, 62]'
+# ANDROID: 15, PLATFORM: STANDALONE, JRuby: 1.7.0 '[28, 33, 51, 68]' expected, but got '[28, 33, 47, 64]'
+# ANDROID: 16, PLATFORM: 0.4.8.dev, JRuby: 1.7.0.preview2 '[29, 34, 47, 64]' expected, but got '[28, 33, 47, 64]'
test('stack depth') do |activity|
os_offset = {
10 => [0, 0, -1, -1],
@@ -31,8 +32,8 @@
version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, PLATFORM: #{org.ruboto.JRubyAdapter.uses_platform_apk ? org.ruboto.JRubyAdapter.platform_version_name : 'STANDALONE'}, JRuby: #{org.jruby.runtime.Constants::VERSION}"
assert_equal [28 + os_offset[0] + jruby_offset[0],
33 + os_offset[1] + jruby_offset[1],
- 47 + os_offset[2] + jruby_offset[2],
- 64 + os_offset[3] + jruby_offset[3]], [activity.find_view_by_id(42).text.to_i,
+ 46 + os_offset[2] + jruby_offset[2],
+ 63 + os_offset[3] + jruby_offset[3]], [activity.find_view_by_id(42).text.to_i,
activity.find_view_by_id(43).text.to_i,
activity.find_view_by_id(44).text.to_i,
activity.find_view_by_id(45).text.to_i], version_message
View
12 test/broadcast_receiver_test.rb
@@ -1,4 +1,4 @@
-require File.expand_path("test_helper", File.dirname(__FILE__))
+require File.expand_path('test_helper', File.dirname(__FILE__))
require 'fileutils'
class BroadcastReceiverTest < Test::Unit::TestCase
@@ -54,13 +54,13 @@ def butterfly
assert receiver_content.sub!(/ def onReceive\(context, intent\)\n.*?^ end\n/m, <<EOF)
def onReceive(context, intent)
- Log.d "RUBOTO TEST", "Changing UI text"
+ Log.d 'RUBOTO TEST', 'Changing UI text'
context.run_on_ui_thread{$broadcast_test_activity.find_view_by_id(42).text = '#{message}'}
- Log.d "RUBOTO TEST", "UI text changed OK!"
+ Log.d 'RUBOTO TEST', 'UI text changed OK!'
rescue Exception
- Log.e "RUBOTO TEST", "Exception changing UI text: \#{$!.message}"
- Log.e "RUBOTO TEST", $!.message
- Log.e "RUBOTO TEST", $!.backtrace.join("\\n")
+ Log.e 'RUBOTO TEST', "Exception changing UI text: \#{$!.message}"
+ Log.e 'RUBOTO TEST', $!.message
+ Log.e 'RUBOTO TEST', $!.backtrace.join("\\n")
end
EOF
File.open(receiver_filename, 'w') { |f| f << receiver_content }
View
5 welcome_bot.rb
@@ -1,4 +1,4 @@
-#!/usr/local/bin/ruby
+#!ruby
require 'socket'
require 'yaml'
@@ -35,10 +35,9 @@ def connect
end
def handle_server_input(s)
- puts s
case s.strip
when /^PING :(.+)$/i
- puts '[ Server ping ]'
+ puts "[ Server ping ]: #{s}"
send "PONG :#{$1}"
when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s.+\s:[\001]PING (.+)[\001]$/i
puts "[ CTCP PING from #{$1}!#{$2}@#{$3} ]"
Please sign in to comment.
Something went wrong with that request. Please try again.