assets/src/org/ruboto/ScriptLoader.java in ruboto-0.10.1 vs assets/src/org/ruboto/ScriptLoader.java in ruboto-0.10.2.rc.0
- old
+ new
@@ -2,10 +2,11 @@
import java.io.IOException;
import android.app.ProgressDialog;
import android.content.Context;
+import android.os.Bundle;
public class ScriptLoader {
/**
Return true if we are called from JRuby.
*/
@@ -104,11 +105,11 @@
// Neither script file nor predefined class
throw new RuntimeException("Either script or predefined class must be present.");
}
if (rubyClass != null) {
if (component instanceof android.content.Context) {
- callOnCreate(rubyInstance, args);
+ callOnCreate(rubyInstance, args, component.getScriptInfo().getRubyClassName());
}
}
component.getScriptInfo().setRubyInstance(rubyInstance);
}
} catch(IOException e){
@@ -117,22 +118,29 @@
ProgressDialog.show((android.content.Context) component, "Script failed", "Something bad happened", true, true);
}
}
}
- private static final void callOnCreate(Object rubyInstance, Object[] args) {
- System.out.println("Call on_create on: " + rubyInstance + ", " + JRubyAdapter.get("JRUBY_VERSION"));
+ 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()) {
- JRubyAdapter.runRubyMethod(rubyInstance, "on_create", (Object[]) args);
+ // 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);
+ }
+ // EMXIF
} else {
throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
}
+ // EMXIF
}
}