Skip to content

Commit

Permalink
Match new start up process
Browse files Browse the repository at this point in the history
  • Loading branch information
rscottm committed Sep 22, 2011
1 parent 8e98f0e commit bddd359
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 45 deletions.
17 changes: 7 additions & 10 deletions assets/src/RubotoActivity.java
Expand Up @@ -75,6 +75,7 @@ public void onCreate(Bundle bundle) {

// This causes JRuby to initialize and takes while
protected void prepareJRuby() {
Script.put("$context", this);
Script.put("$activity", this);
Script.put("$bundle", args[0]);
}
Expand All @@ -83,17 +84,13 @@ protected void loadScript() {
try {
if (scriptName != null) {
new Script(scriptName).execute();
} else if (configBundle != null && configBundle.getString("Remote Variable") != null) {
setRemoteVariable(configBundle.getString("Remote Variable"));
if (configBundle.getBoolean("Define Remote Variable")) {
Script.put(remoteVariable, this);
}
if (configBundle.getString("Initialize Script") != null) {
Script.execute(configBundle.getString("Initialize Script"));
}
Script.execute(getRemoteVariableCall("on_create($bundle)"));
} else {
throw new RuntimeException("Neither script name nor remote variable was set.");
// TODO: Why doesn't this work?
// Script.callMethod(this, "initialize_ruboto");
Script.execute("$activity.initialize_ruboto");
// TODO: Why doesn't this work?
// Script.callMethod(this, "on_create", args[0]);
Script.execute("$activity.on_create($bundle)");
}
} catch(IOException e){
e.printStackTrace();
Expand Down
62 changes: 29 additions & 33 deletions assets/src/RubotoBroadcastReceiver.java
@@ -1,51 +1,47 @@
package THE_PACKAGE;

import java.io.IOException;

public abstract class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
private String scriptName;
private String remoteVariable = "";

THE_CONSTANTS

private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
private boolean initialized = false;

public void setCallbackProc(int id, Object obj) {
callbackProcs[id] = obj;
// Error: no callbacks
throw new RuntimeException("RubotoBroadcastReceiver does not accept callbacks");
}

public THE_RUBOTO_CLASS setRemoteVariable(String var) {
remoteVariable = ((var == null) ? "" : (var + "."));
return this;
}

public void setScriptName(String name){
scriptName = name;
}

public THE_RUBOTO_CLASS(String scriptName) {
setScriptName(scriptName);
if (Script.isInitialized()) {
loadScript();
}
}

protected void loadScript() {
Script.put("$broadcast_receiver", this);
try {
new Script(scriptName).execute();
} catch(IOException e) {
throw new RuntimeException("IOException loading broadcast receiver script", e);
}
public THE_RUBOTO_CLASS() {
this(null);
}

/****************************************************************************************
*
* Generated Methods
*/
public THE_RUBOTO_CLASS(String name) {
super();

THE_METHODS
if (name != null)
setScriptName(name);
}

public void onReceive(android.content.Context context, android.content.Intent intent) {
if (Script.setUpJRuby(context)) {
Script.defineGlobalVariable("$context", context);
Script.defineGlobalVariable("$broadcast_receiver", this);
Script.defineGlobalVariable("$intent", intent);

try {
if (scriptName != null && !initialized) {
new Script(scriptName).execute();
initialized = true;
} else {
Script.execute("$broadcast_receiver.on_receive($context, $intent)");
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
}


11 changes: 9 additions & 2 deletions assets/src/RubotoService.java
Expand Up @@ -4,7 +4,7 @@
import java.io.IOException;
import android.app.ProgressDialog;

public abstract class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
private String scriptName;
private String remoteVariable = "";
public Object[] args;
Expand Down Expand Up @@ -38,9 +38,16 @@ public void onCreate() {
super.onCreate();

if (Script.setUpJRuby(this)) {
Script.defineGlobalVariable("$context", this);
Script.defineGlobalVariable("$service", this);

try {
new Script(scriptName).execute();
if (scriptName != null) {
new Script(scriptName).execute();
} else {
Script.execute("$service.initialize_ruboto");
Script.execute("$service.on_create");
}
} catch(IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit bddd359

Please sign in to comment.