Skip to content

Commit

Permalink
Catch up with ruboto-core
Browse files Browse the repository at this point in the history
  • Loading branch information
rscottm committed Sep 8, 2011
1 parent 2026dbf commit 08c8e73
Showing 1 changed file with 51 additions and 5 deletions.
56 changes: 51 additions & 5 deletions src/org/ruboto/RubotoPreferenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class RubotoPreferenceActivity extends android.preference.PreferenceActivity {
private String scriptName;
private String remoteVariable = "";
private String remoteVariable = null;
private Object[] args;
private Bundle configBundle;

Expand Down Expand Up @@ -57,18 +57,26 @@ public class RubotoPreferenceActivity extends android.preference.PreferenceActiv
public static final int CB_WINDOW_FOCUS_CHANGED = 35;
public static final int CB_USER_INTERACTION = 36;
public static final int CB_USER_LEAVE_HINT = 37;
public static final int CB_ATTACHED_TO_WINDOW = 38;
public static final int CB_BACK_PRESSED = 39;
public static final int CB_DETACHED_FROM_WINDOW = 40;
public static final int CB_KEY_LONG_PRESS = 41;

private Object[] callbackProcs = new Object[38];
private Object[] callbackProcs = new Object[42];

public void setCallbackProc(int id, Object obj) {
callbackProcs[id] = obj;
}

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

public String getRemoteVariableCall(String call) {
return (remoteVariable == null ? "" : (remoteVariable + ".")) + call;
}

public void setScriptName(String name) {
scriptName = name;
}
Expand Down Expand Up @@ -119,12 +127,14 @@ protected void loadScript() {
} else if (configBundle != null && configBundle.getString("Remote Variable") != null) {
setRemoteVariable(configBundle.getString("Remote Variable"));
if (configBundle.getBoolean("Define Remote Variable")) {
Script.defineGlobalVariable(remoteVariable, this);
Script.put(remoteVariable, this);
}
if (configBundle.getString("Initialize Script") != null) {
Script.execute(configBundle.getString("Initialize Script"));
}
Script.execute(remoteVariable + "on_create($bundle)");
Script.execute(getRemoteVariableCall("on_create($bundle)"));
} else {
throw new RuntimeException("Neither script name nor remote variable was set.");
}
} catch(IOException e){
e.printStackTrace();
Expand Down Expand Up @@ -479,4 +489,40 @@ public void onUserLeaveHint() {
}
}

public void onAttachedToWindow() {
if (callbackProcs[CB_ATTACHED_TO_WINDOW] != null) {
super.onAttachedToWindow();
Script.callMethod(callbackProcs[CB_ATTACHED_TO_WINDOW], "call" );
} else {
super.onAttachedToWindow();
}
}

public void onBackPressed() {
if (callbackProcs[CB_BACK_PRESSED] != null) {
super.onBackPressed();
Script.callMethod(callbackProcs[CB_BACK_PRESSED], "call" );
} else {
super.onBackPressed();
}
}

public void onDetachedFromWindow() {
if (callbackProcs[CB_DETACHED_FROM_WINDOW] != null) {
super.onDetachedFromWindow();
Script.callMethod(callbackProcs[CB_DETACHED_FROM_WINDOW], "call" );
} else {
super.onDetachedFromWindow();
}
}

public boolean onKeyLongPress(int keyCode, android.view.KeyEvent event) {
if (callbackProcs[CB_KEY_LONG_PRESS] != null) {
super.onKeyLongPress(keyCode, event);
return (Boolean) Script.callMethod(callbackProcs[CB_KEY_LONG_PRESS], "call" , new Object[]{keyCode, event}, Boolean.class);
} else {
return super.onKeyLongPress(keyCode, event);
}
}

}

0 comments on commit 08c8e73

Please sign in to comment.