ruboto-core 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/Rakefile +75 -0
- data/assets/Rakefile +76 -85
- data/assets/res/layout/get_ruboto_core.xml +25 -0
- data/assets/samples/sample_broadcast_receiver.rb +1 -2
- data/assets/src/InheritingActivity.java +181 -5
- data/assets/src/InheritingBroadcastReceiver.java +22 -5
- data/assets/src/InheritingClass.java +4 -13
- data/assets/src/RubotoActivity.java +78 -118
- data/assets/src/RubotoBroadcastReceiver.java +31 -50
- data/assets/src/RubotoService.java +13 -28
- data/assets/src/org/ruboto/Script.java +286 -114
- data/assets/src/org/ruboto/test/ActivityTest.java +25 -26
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +28 -29
- data/assets/{assets/scripts → src}/ruboto.rb +13 -8
- data/assets/test/assets/scripts/test_helper.rb +8 -4
- data/lib/ruboto/commands/base.rb +42 -6
- data/lib/ruboto/util/build.rb +25 -18
- data/lib/ruboto/util/update.rb +53 -30
- data/lib/ruboto/util/xml_element.rb +2 -2
- data/lib/ruboto/version.rb +3 -0
- data/test/activity/image_button_activity.rb +1 -1
- data/test/activity/image_button_and_button_activity.rb +1 -1
- data/test/activity/stack_activity.rb +21 -0
- data/test/activity/stack_activity_test.rb +24 -0
- data/test/app_test_methods.rb +25 -32
- data/test/rake_test.rb +15 -17
- data/test/ruboto_gen_test.rb +1 -16
- data/test/ruboto_gen_with_psych_test.rb +16 -0
- data/test/ruboto_update_test.rb +1 -47
- data/test/ruboto_update_with_psych_test.rb +18 -0
- data/test/service_test.rb +4 -2
- data/test/test_helper.rb +32 -22
- data/test/update_test_methods.rb +29 -0
- metadata +13 -22
@@ -2,144 +2,104 @@ package THE_PACKAGE;
|
|
2
2
|
|
3
3
|
import java.io.IOException;
|
4
4
|
|
5
|
-
import org.jruby.Ruby;
|
6
|
-
import org.jruby.embed.ScriptingContainer;
|
7
|
-
import org.jruby.exceptions.RaiseException;
|
8
|
-
import org.jruby.javasupport.JavaUtil;
|
9
|
-
import org.jruby.javasupport.util.RuntimeHelpers;
|
10
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
11
5
|
import org.ruboto.Script;
|
12
6
|
|
13
7
|
import android.app.ProgressDialog;
|
8
|
+
import android.content.Intent;
|
9
|
+
import android.net.Uri;
|
10
|
+
import android.os.Bundle;
|
14
11
|
import android.os.Handler;
|
12
|
+
import android.util.Log;
|
13
|
+
import android.view.View;
|
14
|
+
import android.widget.TextView;
|
15
15
|
|
16
16
|
public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
private int splash = 0;
|
22
|
-
private String remoteVariable = "";
|
23
|
-
public Object[] args;
|
24
|
-
private ProgressDialog loadingDialog;
|
17
|
+
private String scriptName;
|
18
|
+
private String remoteVariable = null;
|
19
|
+
private Object[] args;
|
20
|
+
private Bundle configBundle;
|
25
21
|
|
26
22
|
THE_CONSTANTS
|
27
|
-
private IRubyObject[] callbackProcs = new IRubyObject[CONSTANTS_COUNT];
|
28
23
|
|
29
|
-
|
30
|
-
if (__ruby__ == null) {
|
31
|
-
__ruby__ = Script.getRuby();
|
24
|
+
private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
__ruby__ = Script.getRuby();
|
36
|
-
}
|
26
|
+
public void setCallbackProc(int id, Object obj) {
|
27
|
+
callbackProcs[id] = obj;
|
37
28
|
}
|
38
|
-
|
39
|
-
return __ruby__;
|
40
|
-
}
|
41
|
-
|
42
|
-
public void setCallbackProc(int id, IRubyObject obj) {
|
43
|
-
callbackProcs[id] = obj;
|
44
|
-
}
|
45
29
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
30
|
+
public THE_RUBOTO_CLASS setRemoteVariable(String var) {
|
31
|
+
remoteVariable = var;
|
32
|
+
return this;
|
33
|
+
}
|
50
34
|
|
51
|
-
|
52
|
-
|
53
|
-
|
35
|
+
public String getRemoteVariableCall(String call) {
|
36
|
+
return (remoteVariable == null ? "" : (remoteVariable + ".")) + call;
|
37
|
+
}
|
54
38
|
|
55
|
-
|
56
|
-
|
57
|
-
|
39
|
+
public void setScriptName(String name) {
|
40
|
+
scriptName = name;
|
41
|
+
}
|
58
42
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
43
|
+
/****************************************************************************************
|
44
|
+
*
|
45
|
+
* Activity Lifecycle: onCreate
|
46
|
+
*/
|
63
47
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
48
|
+
@Override
|
49
|
+
public void onCreate(Bundle bundle) {
|
50
|
+
args = new Object[1];
|
51
|
+
args[0] = bundle;
|
52
|
+
|
53
|
+
configBundle = getIntent().getBundleExtra("RubotoActivity Config");
|
54
|
+
|
55
|
+
if (configBundle != null) {
|
56
|
+
if (configBundle.containsKey("Theme")) {
|
57
|
+
setTheme(configBundle.getInt("Theme"));
|
58
|
+
}
|
59
|
+
if (configBundle.containsKey("Script")) {
|
60
|
+
if (this.getClass().getName() == RubotoActivity.class.getName()) {
|
61
|
+
setScriptName(configBundle.getString("Script"));
|
62
|
+
} else {
|
63
|
+
throw new IllegalArgumentException("Only local Intents may set script name.");
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
74
67
|
|
75
|
-
|
68
|
+
super.onCreate(bundle);
|
76
69
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if (splash == 0) {
|
82
|
-
loadingDialog = ProgressDialog.show(this, null, "Loading...", true, false);
|
83
|
-
} else {
|
84
|
-
requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
|
85
|
-
setContentView(splash);
|
86
|
-
}
|
87
|
-
loadingThread.start();
|
70
|
+
if (Script.isInitialized()) {
|
71
|
+
prepareJRuby();
|
72
|
+
loadScript();
|
73
|
+
}
|
88
74
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
public void run(){
|
95
|
-
backgroundCreate();
|
96
|
-
loadingHandler.post(loadingComplete);
|
97
|
-
}
|
98
|
-
};
|
99
|
-
|
100
|
-
private final Runnable loadingComplete = new Runnable(){
|
101
|
-
public void run(){
|
102
|
-
if (loadingDialog != null) loadingDialog.dismiss();
|
103
|
-
finishCreate();
|
104
|
-
onStart();
|
105
|
-
onResume();
|
75
|
+
|
76
|
+
// This causes JRuby to initialize and takes while
|
77
|
+
protected void prepareJRuby() {
|
78
|
+
Script.put("$activity", this);
|
79
|
+
Script.put("$bundle", args[0]);
|
106
80
|
}
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
try {
|
129
|
-
new Script(scriptName).execute();
|
130
|
-
/* TODO(uwe): Add a way to add callbacks from a class or just forward all calls to the instance
|
131
|
-
rubyClassName = this.getClass().getSimpleName();
|
132
|
-
if (getRuby().get(rubyClassName) != null) {
|
133
|
-
rubyInstance = Script.exec(rubyClassName + ".new");
|
134
|
-
getRuby().callMethod(rubyInstance, "on_create", configBundle);
|
135
|
-
}
|
136
|
-
*/
|
137
|
-
} catch(IOException e){
|
138
|
-
e.printStackTrace();
|
139
|
-
ProgressDialog.show(this, "Script failed", "Something bad happened", true, true);
|
140
|
-
}
|
81
|
+
|
82
|
+
protected void loadScript() {
|
83
|
+
try {
|
84
|
+
if (scriptName != null) {
|
85
|
+
new Script(scriptName).execute();
|
86
|
+
} else if (configBundle != null && configBundle.getString("Remote Variable") != null) {
|
87
|
+
setRemoteVariable(configBundle.getString("Remote Variable"));
|
88
|
+
if (configBundle.getBoolean("Define Remote Variable")) {
|
89
|
+
Script.put(remoteVariable, this);
|
90
|
+
}
|
91
|
+
if (configBundle.getString("Initialize Script") != null) {
|
92
|
+
Script.execute(configBundle.getString("Initialize Script"));
|
93
|
+
}
|
94
|
+
Script.execute(getRemoteVariableCall("on_create($bundle)"));
|
95
|
+
} else {
|
96
|
+
throw new RuntimeException("Neither script name nor remote variable was set.");
|
97
|
+
}
|
98
|
+
} catch(IOException e){
|
99
|
+
e.printStackTrace();
|
100
|
+
ProgressDialog.show(this, "Script failed", "Something bad happened", true, true);
|
101
|
+
}
|
141
102
|
}
|
142
|
-
}
|
143
103
|
|
144
104
|
/****************************************************************************************
|
145
105
|
*
|
@@ -147,5 +107,5 @@ THE_CONSTANTS
|
|
147
107
|
*/
|
148
108
|
|
149
109
|
THE_METHODS
|
150
|
-
}
|
151
110
|
|
111
|
+
}
|
@@ -2,69 +2,50 @@ package THE_PACKAGE;
|
|
2
2
|
|
3
3
|
import java.io.IOException;
|
4
4
|
|
5
|
-
import org.jruby.embed.ScriptingContainer;
|
6
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
7
|
-
|
8
5
|
public abstract class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
|
9
|
-
|
10
|
-
|
11
|
-
private String remoteVariable = "";
|
12
|
-
public Object[] args;
|
6
|
+
private String scriptName;
|
7
|
+
private String remoteVariable = "";
|
13
8
|
|
14
9
|
THE_CONSTANTS
|
15
|
-
private IRubyObject[] callbackProcs = new IRubyObject[CONSTANTS_COUNT];
|
16
|
-
|
17
|
-
private ScriptingContainer getRuby() {
|
18
|
-
if (__ruby__ == null) {
|
19
|
-
__ruby__ = Script.getRuby();
|
20
|
-
}
|
21
|
-
|
22
|
-
return __ruby__;
|
23
|
-
}
|
24
|
-
|
25
|
-
public void setCallbackProc(int id, IRubyObject obj) {
|
26
|
-
callbackProcs[id] = obj;
|
27
|
-
}
|
28
|
-
|
29
|
-
public THE_RUBOTO_CLASS setRemoteVariable(String var) {
|
30
|
-
remoteVariable = ((var == null) ? "" : (var + "."));
|
31
|
-
return this;
|
32
|
-
}
|
33
10
|
|
34
|
-
|
35
|
-
scriptName = name;
|
36
|
-
}
|
11
|
+
private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
|
37
12
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
*/
|
13
|
+
public void setCallbackProc(int id, Object obj) {
|
14
|
+
callbackProcs[id] = obj;
|
15
|
+
}
|
42
16
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
args[1] = arg1;
|
17
|
+
public THE_RUBOTO_CLASS setRemoteVariable(String var) {
|
18
|
+
remoteVariable = ((var == null) ? "" : (var + "."));
|
19
|
+
return this;
|
20
|
+
}
|
48
21
|
|
49
|
-
|
22
|
+
public void setScriptName(String name){
|
23
|
+
scriptName = name;
|
24
|
+
}
|
50
25
|
|
51
|
-
|
52
|
-
|
53
|
-
|
26
|
+
public THE_RUBOTO_CLASS(String scriptName) {
|
27
|
+
setScriptName(scriptName);
|
28
|
+
if (Script.isInitialized()) {
|
29
|
+
loadScript();
|
30
|
+
}
|
31
|
+
}
|
54
32
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
33
|
+
protected void loadScript() {
|
34
|
+
Script.put("$broadcast_receiver", this);
|
35
|
+
try {
|
36
|
+
new Script(scriptName).execute();
|
37
|
+
} catch(IOException e) {
|
38
|
+
throw new RuntimeException("IOException loading broadcast receiver script", e);
|
39
|
+
}
|
59
40
|
}
|
60
|
-
}
|
61
41
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
42
|
+
/****************************************************************************************
|
43
|
+
*
|
44
|
+
* Generated Methods
|
45
|
+
*/
|
66
46
|
|
67
47
|
THE_METHODS
|
48
|
+
|
68
49
|
}
|
69
50
|
|
70
51
|
|
@@ -1,36 +1,19 @@
|
|
1
1
|
package THE_PACKAGE;
|
2
2
|
|
3
|
-
import org.jruby.Ruby;
|
4
|
-
import org.jruby.javasupport.util.RuntimeHelpers;
|
5
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
6
|
-
import org.jruby.javasupport.JavaUtil;
|
7
|
-
import org.jruby.embed.ScriptingContainer;
|
8
|
-
import org.jruby.exceptions.RaiseException;
|
9
3
|
import org.ruboto.Script;
|
10
4
|
import java.io.IOException;
|
11
5
|
import android.app.ProgressDialog;
|
12
6
|
|
13
7
|
public abstract class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
|
14
|
-
private ScriptingContainer __ruby__;
|
15
8
|
private String scriptName;
|
16
9
|
private String remoteVariable = "";
|
17
10
|
public Object[] args;
|
18
11
|
|
19
12
|
THE_CONSTANTS
|
20
|
-
private IRubyObject[] callbackProcs = new IRubyObject[CONSTANTS_COUNT];
|
21
13
|
|
22
|
-
private
|
23
|
-
if (__ruby__ == null) __ruby__ = Script.getRuby();
|
14
|
+
private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
|
24
15
|
|
25
|
-
|
26
|
-
Script.setUpJRuby(this);
|
27
|
-
__ruby__ = Script.getRuby();
|
28
|
-
}
|
29
|
-
|
30
|
-
return __ruby__;
|
31
|
-
}
|
32
|
-
|
33
|
-
public void setCallbackProc(int id, IRubyObject obj) {
|
16
|
+
public void setCallbackProc(int id, Object obj) {
|
34
17
|
callbackProcs[id] = obj;
|
35
18
|
}
|
36
19
|
|
@@ -54,14 +37,15 @@ THE_CONSTANTS
|
|
54
37
|
|
55
38
|
super.onCreate();
|
56
39
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
40
|
+
if (Script.setUpJRuby(this)) {
|
41
|
+
Script.defineGlobalVariable("$service", this);
|
42
|
+
try {
|
43
|
+
new Script(scriptName).execute();
|
44
|
+
} catch(IOException e) {
|
45
|
+
e.printStackTrace();
|
46
|
+
}
|
47
|
+
} else {
|
48
|
+
// FIXME(uwe): What to do if the Ruboto Core plarform cannot be found?
|
65
49
|
}
|
66
50
|
}
|
67
51
|
|
@@ -71,6 +55,7 @@ THE_CONSTANTS
|
|
71
55
|
*/
|
72
56
|
|
73
57
|
THE_METHODS
|
74
|
-
|
58
|
+
|
59
|
+
}
|
75
60
|
|
76
61
|
|