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.
Files changed (35) hide show
  1. data/README.md +3 -3
  2. data/Rakefile +75 -0
  3. data/assets/Rakefile +76 -85
  4. data/assets/res/layout/get_ruboto_core.xml +25 -0
  5. data/assets/samples/sample_broadcast_receiver.rb +1 -2
  6. data/assets/src/InheritingActivity.java +181 -5
  7. data/assets/src/InheritingBroadcastReceiver.java +22 -5
  8. data/assets/src/InheritingClass.java +4 -13
  9. data/assets/src/RubotoActivity.java +78 -118
  10. data/assets/src/RubotoBroadcastReceiver.java +31 -50
  11. data/assets/src/RubotoService.java +13 -28
  12. data/assets/src/org/ruboto/Script.java +286 -114
  13. data/assets/src/org/ruboto/test/ActivityTest.java +25 -26
  14. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +28 -29
  15. data/assets/{assets/scripts → src}/ruboto.rb +13 -8
  16. data/assets/test/assets/scripts/test_helper.rb +8 -4
  17. data/lib/ruboto/commands/base.rb +42 -6
  18. data/lib/ruboto/util/build.rb +25 -18
  19. data/lib/ruboto/util/update.rb +53 -30
  20. data/lib/ruboto/util/xml_element.rb +2 -2
  21. data/lib/ruboto/version.rb +3 -0
  22. data/test/activity/image_button_activity.rb +1 -1
  23. data/test/activity/image_button_and_button_activity.rb +1 -1
  24. data/test/activity/stack_activity.rb +21 -0
  25. data/test/activity/stack_activity_test.rb +24 -0
  26. data/test/app_test_methods.rb +25 -32
  27. data/test/rake_test.rb +15 -17
  28. data/test/ruboto_gen_test.rb +1 -16
  29. data/test/ruboto_gen_with_psych_test.rb +16 -0
  30. data/test/ruboto_update_test.rb +1 -47
  31. data/test/ruboto_update_with_psych_test.rb +18 -0
  32. data/test/service_test.rb +4 -2
  33. data/test/test_helper.rb +32 -22
  34. data/test/update_test_methods.rb +29 -0
  35. 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
- private ScriptingContainer __ruby__;
18
- private String scriptName;
19
- private String rubyClassName;
20
- private Object rubyInstance;
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
- private ScriptingContainer getRuby() {
30
- if (__ruby__ == null) {
31
- __ruby__ = Script.getRuby();
24
+ private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
32
25
 
33
- if (__ruby__ == null) {
34
- Script.setUpJRuby(this);
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
- public THE_RUBOTO_CLASS setRemoteVariable(String var) {
47
- remoteVariable = ((var == null) ? "" : (var + "."));
48
- return this;
49
- }
30
+ public THE_RUBOTO_CLASS setRemoteVariable(String var) {
31
+ remoteVariable = var;
32
+ return this;
33
+ }
50
34
 
51
- public void setSplash(int a_res){
52
- splash = a_res;
53
- }
35
+ public String getRemoteVariableCall(String call) {
36
+ return (remoteVariable == null ? "" : (remoteVariable + ".")) + call;
37
+ }
54
38
 
55
- public void setScriptName(String name){
56
- scriptName = name;
57
- }
39
+ public void setScriptName(String name) {
40
+ scriptName = name;
41
+ }
58
42
 
59
- /****************************************************************************************
60
- *
61
- * Activity Lifecycle: onCreate
62
- */
43
+ /****************************************************************************************
44
+ *
45
+ * Activity Lifecycle: onCreate
46
+ */
63
47
 
64
- @Override
65
- public void onCreate(android.os.Bundle arg0) {
66
- args = new Object[1];
67
- args[0] = arg0;
68
-
69
- android.os.Bundle configBundle = getIntent().getBundleExtra("RubotoActivity Config");
70
-
71
- if (configBundle != null && configBundle.containsKey("Theme")) {
72
- setTheme(configBundle.getInt("Theme"));
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
- super.onCreate(arg0);
68
+ super.onCreate(bundle);
76
69
 
77
- if (Script.getRuby() != null) {
78
- backgroundCreate();
79
- finishCreate();
80
- } else {
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
- private final Handler loadingHandler = new Handler();
92
-
93
- private final Thread loadingThread = new Thread() {
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
- private void backgroundCreate() {
110
- getRuby().put("$activity", this);
111
- getRuby().put("$bundle", args[0]);
112
- }
113
-
114
- private void finishCreate() {
115
- android.os.Bundle configBundle = getIntent().getBundleExtra("RubotoActivity Config");
116
-
117
- if (configBundle != null) {
118
- setRemoteVariable(configBundle.getString("Remote Variable"));
119
- if (configBundle.getBoolean("Define Remote Variable")) {
120
- Script.defineGlobalVariable(configBundle.getString("Remote Variable"), this);
121
- setRemoteVariable(configBundle.getString("Remote Variable"));
122
- }
123
- if (configBundle.getString("Initialize Script") != null) {
124
- Script.execute(configBundle.getString("Initialize Script"));
125
- }
126
- Script.execute(remoteVariable + "on_create($bundle)");
127
- } else {
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
- private ScriptingContainer __ruby__;
10
- private String scriptName;
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
- public void setScriptName(String name){
35
- scriptName = name;
36
- }
11
+ private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
37
12
 
38
- /****************************************************************************************
39
- *
40
- * Activity Lifecycle: onCreate
41
- */
13
+ public void setCallbackProc(int id, Object obj) {
14
+ callbackProcs[id] = obj;
15
+ }
42
16
 
43
- @Override
44
- public void onReceive(android.content.Context arg0, android.content.Intent arg1) {
45
- args = new Object[2];
46
- args[0] = arg0;
47
- args[1] = arg1;
17
+ public THE_RUBOTO_CLASS setRemoteVariable(String var) {
18
+ remoteVariable = ((var == null) ? "" : (var + "."));
19
+ return this;
20
+ }
48
21
 
49
- getRuby();
22
+ public void setScriptName(String name){
23
+ scriptName = name;
24
+ }
50
25
 
51
- Script.defineGlobalVariable("$broadcast_receiver", this);
52
- Script.defineGlobalVariable("$broadcast_context", arg0);
53
- Script.defineGlobalVariable("$broadcast_intent", arg1);
26
+ public THE_RUBOTO_CLASS(String scriptName) {
27
+ setScriptName(scriptName);
28
+ if (Script.isInitialized()) {
29
+ loadScript();
30
+ }
31
+ }
54
32
 
55
- try {
56
- new Script(scriptName).execute();
57
- } catch(IOException e) {
58
- e.printStackTrace();
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
- * Generated Methods
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 ScriptingContainer getRuby() {
23
- if (__ruby__ == null) __ruby__ = Script.getRuby();
14
+ private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
24
15
 
25
- if (__ruby__ == null) {
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
- getRuby();
58
-
59
- Script.defineGlobalVariable("$service", this);
60
-
61
- try {
62
- new Script(scriptName).execute();
63
- } catch(IOException e) {
64
- e.printStackTrace();
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