ruboto-core 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,126 +0,0 @@
1
- /**********************************************************************************************
2
- *
3
- * RubotoBroadcastReceiver.java is generated from RubotoClass.java.erb. Any changes needed in should be
4
- * made within the erb template or they will be lost.
5
- *
6
- */
7
-
8
- package org.ruboto;
9
-
10
- import java.io.IOException;
11
- import android.content.BroadcastReceiver;
12
- import android.os.Handler;
13
- import android.os.Bundle;
14
-
15
- import org.jruby.Ruby;
16
- import org.jruby.javasupport.util.RuntimeHelpers;
17
- import org.jruby.runtime.builtin.IRubyObject;
18
- import org.jruby.javasupport.JavaUtil;
19
- import org.jruby.exceptions.RaiseException;
20
-
21
- public abstract class RubotoBroadcastReceiver extends BroadcastReceiver
22
-
23
- {
24
- public static final int CB_CHECK_SYNCHRONOUS_HINT = 0;
25
- public static final int CB_PEEK_SERVICE = 1;
26
- public static final int CB_LAST = 2;
27
-
28
- private boolean[] callbackOptions = new boolean [CB_LAST];
29
-
30
- private String remoteVariable = "";
31
-
32
- private final Handler loadingHandler = new Handler();
33
- private IRubyObject __this__;
34
- private Ruby __ruby__;
35
- private String scriptName;
36
- public Object[] args;
37
-
38
- public RubotoBroadcastReceiver setRemoteVariable(String var) {
39
- remoteVariable = ((var == null) ? "" : (var + "."));
40
- return this;
41
- }
42
-
43
- /**********************************************************************************
44
- *
45
- * Callback management
46
- */
47
-
48
- public void requestCallback(int id) {
49
- callbackOptions[id] = true;
50
- }
51
-
52
- public void removeCallback(int id) {
53
- callbackOptions[id] = false;
54
- }
55
-
56
- /*
57
- * Activity Lifecycle: onCreate
58
- */
59
-
60
- @Override
61
- public void onReceive(android.content.Context arg0, android.content.Intent arg1) {
62
-
63
- args = new Object[2];
64
- args[0] = arg0;
65
- args[1] = arg1;
66
-
67
-
68
- if (Script.getRuby() == null){
69
- Script.setUpJRuby(null);
70
- }
71
- Script.defineGlobalVariable("$broadcast_receiver", this);
72
-
73
-
74
- __ruby__ = Script.getRuby();
75
- __this__ = JavaUtil.convertJavaToRuby(__ruby__, RubotoBroadcastReceiver.this);
76
-
77
- try {
78
- new Script(scriptName).execute();
79
- }
80
- catch(IOException e){
81
-
82
- }
83
- }
84
-
85
- public void setScriptName(String name){
86
- scriptName = name;
87
- }
88
-
89
-
90
-
91
- /*********************************************************************************
92
- *
93
- * Ruby Generated Callback Methods
94
- */
95
-
96
- /*
97
- * android.content.BroadcastReceiver
98
- */
99
-
100
- public void checkSynchronousHint() {
101
- if (callbackOptions[CB_CHECK_SYNCHRONOUS_HINT]) {
102
-
103
- try {
104
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "check_synchronous_hint");
105
- } catch (RaiseException re) {
106
- re.printStackTrace(__ruby__.getErrorStream());
107
-
108
- }
109
- }
110
- }
111
-
112
- public android.os.IBinder peekService(android.content.Context arg0, android.content.Intent arg1) {
113
- if (callbackOptions[CB_PEEK_SERVICE]) {
114
-
115
- try {
116
- return (android.os.IBinder)RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "peek_service", JavaUtil.convertJavaToRuby(__ruby__, arg0), JavaUtil.convertJavaToRuby(__ruby__, arg1)).toJava(android.os.IBinder.class);
117
- } catch (RaiseException re) {
118
- re.printStackTrace(__ruby__.getErrorStream());
119
- return null;
120
- }
121
- } else {
122
- return null;
123
- }
124
- }
125
-
126
- }
@@ -1,233 +0,0 @@
1
- /**********************************************************************************************
2
- *
3
- * RubotoService.java is generated from RubotoClass.java.erb. Any changes needed in should be
4
- * made within the erb template or they will be lost.
5
- *
6
- */
7
-
8
- package org.ruboto;
9
-
10
- import java.io.IOException;
11
- import android.app.Service;
12
- import android.os.Handler;
13
- import android.os.Bundle;
14
-
15
- import org.jruby.Ruby;
16
- import org.jruby.javasupport.util.RuntimeHelpers;
17
- import org.jruby.runtime.builtin.IRubyObject;
18
- import org.jruby.javasupport.JavaUtil;
19
- import org.jruby.exceptions.RaiseException;
20
-
21
- public abstract class RubotoService extends Service
22
-
23
- {
24
- public static final int CB_LOW_MEMORY = 0;
25
- public static final int CB_DUMP = 1;
26
- public static final int CB_UNBIND = 2;
27
- public static final int CB_START_COMMAND = 3;
28
- public static final int CB_FINALIZE = 4;
29
- public static final int CB_START = 5;
30
- public static final int CB_DESTROY = 6;
31
- public static final int CB_REBIND = 7;
32
- public static final int CB_CONFIGURATION_CHANGED = 8;
33
- public static final int CB_BIND = 9;
34
- public static final int CB_LAST = 10;
35
-
36
- private boolean[] callbackOptions = new boolean [CB_LAST];
37
-
38
- private String remoteVariable = "";
39
-
40
- private final Handler loadingHandler = new Handler();
41
- private IRubyObject __this__;
42
- private Ruby __ruby__;
43
- private String scriptName;
44
- public Object[] args;
45
-
46
- public RubotoService setRemoteVariable(String var) {
47
- remoteVariable = ((var == null) ? "" : (var + "."));
48
- return this;
49
- }
50
-
51
- /**********************************************************************************
52
- *
53
- * Callback management
54
- */
55
-
56
- public void requestCallback(int id) {
57
- callbackOptions[id] = true;
58
- }
59
-
60
- public void removeCallback(int id) {
61
- callbackOptions[id] = false;
62
- }
63
-
64
- /*
65
- * Activity Lifecycle: onCreate
66
- */
67
-
68
- @Override
69
- public void onCreate() {
70
-
71
- args = new Object[0];
72
- super.onCreate();
73
-
74
-
75
- if (Script.getRuby() == null){
76
- Script.setUpJRuby(null);
77
- }
78
- Script.defineGlobalVariable("$service", this);
79
-
80
-
81
- __ruby__ = Script.getRuby();
82
- __this__ = JavaUtil.convertJavaToRuby(__ruby__, RubotoService.this);
83
-
84
- try {
85
- new Script(scriptName).execute();
86
- }
87
- catch(IOException e){
88
-
89
- }
90
- }
91
-
92
- public void setScriptName(String name){
93
- scriptName = name;
94
- }
95
-
96
-
97
-
98
- /*********************************************************************************
99
- *
100
- * Ruby Generated Callback Methods
101
- */
102
-
103
- /*
104
- * android.app.Service
105
- */
106
-
107
- public void onLowMemory() {
108
- if (callbackOptions[CB_LOW_MEMORY]) {
109
-
110
- try {
111
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_low_memory");
112
- } catch (RaiseException re) {
113
- re.printStackTrace(__ruby__.getErrorStream());
114
-
115
- }
116
- }
117
- }
118
-
119
- public void dump(java.io.FileDescriptor arg0, java.io.PrintWriter arg1, java.lang.String[] arg2) {
120
- if (callbackOptions[CB_DUMP]) {
121
-
122
- try {
123
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "dump", JavaUtil.convertJavaToRuby(__ruby__, arg0), JavaUtil.convertJavaToRuby(__ruby__, arg1), JavaUtil.convertJavaToRuby(__ruby__, arg2));
124
- } catch (RaiseException re) {
125
- re.printStackTrace(__ruby__.getErrorStream());
126
-
127
- }
128
- }
129
- }
130
-
131
- public boolean onUnbind(android.content.Intent arg0) {
132
- if (callbackOptions[CB_UNBIND]) {
133
-
134
- try {
135
- return (Boolean)RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_unbind", JavaUtil.convertJavaToRuby(__ruby__, arg0)).toJava(boolean.class);
136
- } catch (RaiseException re) {
137
- re.printStackTrace(__ruby__.getErrorStream());
138
- return false;
139
- }
140
- } else {
141
- return false;
142
- }
143
- }
144
-
145
- public int onStartCommand(android.content.Intent arg0, int arg1, int arg2) {
146
- if (callbackOptions[CB_START_COMMAND]) {
147
-
148
- try {
149
- return (Integer)RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_start_command", JavaUtil.convertJavaToRuby(__ruby__, arg0), JavaUtil.convertJavaToRuby(__ruby__, arg1), JavaUtil.convertJavaToRuby(__ruby__, arg2)).toJava(int.class);
150
- } catch (RaiseException re) {
151
- re.printStackTrace(__ruby__.getErrorStream());
152
- return 0;
153
- }
154
- } else {
155
- return 0;
156
- }
157
- }
158
-
159
- public void finalize() {
160
- if (callbackOptions[CB_FINALIZE]) {
161
-
162
- try {
163
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "finalize");
164
- } catch (RaiseException re) {
165
- re.printStackTrace(__ruby__.getErrorStream());
166
-
167
- }
168
- }
169
- }
170
-
171
- public void onStart(android.content.Intent arg0, int arg1) {
172
- if (callbackOptions[CB_START]) {
173
-
174
- try {
175
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_start", JavaUtil.convertJavaToRuby(__ruby__, arg0), JavaUtil.convertJavaToRuby(__ruby__, arg1));
176
- } catch (RaiseException re) {
177
- re.printStackTrace(__ruby__.getErrorStream());
178
-
179
- }
180
- }
181
- }
182
-
183
- public void onDestroy() {
184
- if (callbackOptions[CB_DESTROY]) {
185
-
186
- try {
187
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_destroy");
188
- } catch (RaiseException re) {
189
- re.printStackTrace(__ruby__.getErrorStream());
190
-
191
- }
192
- }
193
- }
194
-
195
- public void onRebind(android.content.Intent arg0) {
196
- if (callbackOptions[CB_REBIND]) {
197
-
198
- try {
199
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_rebind", JavaUtil.convertJavaToRuby(__ruby__, arg0));
200
- } catch (RaiseException re) {
201
- re.printStackTrace(__ruby__.getErrorStream());
202
-
203
- }
204
- }
205
- }
206
-
207
- public void onConfigurationChanged(android.content.res.Configuration arg0) {
208
- if (callbackOptions[CB_CONFIGURATION_CHANGED]) {
209
-
210
- try {
211
- RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_configuration_changed", JavaUtil.convertJavaToRuby(__ruby__, arg0));
212
- } catch (RaiseException re) {
213
- re.printStackTrace(__ruby__.getErrorStream());
214
-
215
- }
216
- }
217
- }
218
-
219
- public android.os.IBinder onBind(android.content.Intent arg0) {
220
- if (callbackOptions[CB_BIND]) {
221
-
222
- try {
223
- return (android.os.IBinder)RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "on_bind", JavaUtil.convertJavaToRuby(__ruby__, arg0)).toJava(android.os.IBinder.class);
224
- } catch (RaiseException re) {
225
- re.printStackTrace(__ruby__.getErrorStream());
226
- return null;
227
- }
228
- } else {
229
- return null;
230
- }
231
- }
232
-
233
- }
@@ -1,30 +0,0 @@
1
- package org.ruboto;
2
-
3
- import android.content.Context;
4
- import android.graphics.Canvas;
5
- import android.util.AttributeSet;
6
- import android.view.View;
7
-
8
- public class RubotoView extends View {
9
- public RubotoView(Context context) {
10
- super(context);
11
- }
12
-
13
- public RubotoView(Context context, AttributeSet attrs) {
14
- super(context, attrs);
15
- }
16
-
17
- public RubotoView(Context context, AttributeSet attrs, int defStyle) {
18
- super(context, attrs, defStyle);
19
- }
20
-
21
- @Override
22
- protected void onDraw(Canvas canvas) {
23
- ((RubotoActivity) getContext()).onDraw(this, canvas);
24
- }
25
-
26
- @Override
27
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
28
- ((RubotoActivity) getContext()).onSizeChanged(this, w, h, oldw, oldh);
29
- }
30
- }
@@ -1,197 +0,0 @@
1
- /**********************************************************************************************
2
- *
3
- * Ruboto<%= @class %>.java is generated from RubotoClass.java.erb. Any changes needed in should be
4
- * made within the erb template or they will be lost.
5
- *
6
- */
7
-
8
- package org.ruboto;
9
-
10
- import java.io.IOException;
11
- import <%= @full_class %>;
12
- % if @class == "Activity"
13
- import android.app.ProgressDialog;
14
- % end
15
- import android.os.Handler;
16
- import android.os.Bundle;
17
-
18
- import org.jruby.Ruby;
19
- import org.jruby.javasupport.util.RuntimeHelpers;
20
- import org.jruby.runtime.builtin.IRubyObject;
21
- import org.jruby.javasupport.JavaUtil;
22
- import org.jruby.exceptions.RaiseException;
23
-
24
- public<%= @class == "Activity" ? "" : " abstract" %> class Ruboto<%= @class %> extends <%= @class %>
25
- %##############################################################################################
26
- %#
27
- %# Implement all interfaces
28
- %#
29
- <%= "implements\n #{@implements.join(",\n ")}" unless @implements.empty? %>
30
- %##############################################################################################
31
- {
32
- %##############################################################################################
33
- %#
34
- %# Create constants for all callbacks (may get rid of this means of requesting callbacks later)
35
- %#
36
- % @constants.each_with_index do |c, i|
37
- <%= " public static final int #{c} = #{i};" %>
38
- % end
39
- %##############################################################################################
40
- public static final int CB_LAST = <%= @constants.size %>;
41
-
42
- private boolean[] callbackOptions = new boolean [CB_LAST];
43
-
44
- private String remoteVariable = "";
45
-
46
- private final Handler loadingHandler = new Handler();
47
- private IRubyObject __this__;
48
- private Ruby __ruby__;
49
- private String scriptName;
50
- public Object[] args;
51
-
52
- public Ruboto<%= @class %> setRemoteVariable(String var) {
53
- remoteVariable = ((var == null) ? "" : (var + "."));
54
- return this;
55
- }
56
-
57
- /**********************************************************************************
58
- *
59
- * Callback management
60
- */
61
-
62
- public void requestCallback(int id) {
63
- callbackOptions[id] = true;
64
- }
65
-
66
- public void removeCallback(int id) {
67
- callbackOptions[id] = false;
68
- }
69
-
70
- /*
71
- * Activity Lifecycle: onCreate
72
- */
73
-
74
- @Override
75
- % v = @callbacks[@full_class].delete(@first_method)
76
- public <%= "#{v["return_type"]} #{v["interface_method"]}(#{v["args_with_types"] })" %> {
77
-
78
- args = new Object[<%= v["args_alone"].length %>];
79
- % v["args_alone"].each_with_index do |arg, index|
80
- args[<%= index %>] = <%= arg %>;
81
- % end
82
- % unless v["abstract"]
83
- super.<%= @first_method %>(<%= v["args_alone"].join(',') %>);
84
- % end
85
-
86
- % if @class == "Activity"
87
- % # we'll assume the first thing that happens is an activity gets spawned. no need to do this in other classes
88
- Script.copyScriptsIfNeeded(getFilesDir().getAbsolutePath() + "/scripts", getAssets());
89
- % end
90
-
91
- if (Script.getRuby() == null){
92
- Script.setUpJRuby(null);
93
- }
94
- Script.defineGlobalVariable("$<%= underscore(@class) %>", this);
95
-
96
-
97
- __ruby__ = Script.getRuby();
98
- __this__ = JavaUtil.convertJavaToRuby(__ruby__, Ruboto<%= @class %>.this);
99
-
100
- % if @class == "Activity"
101
- Bundle configBundle = getIntent().getBundleExtra("RubotoActivity Config");
102
-
103
- Script.defineGlobalVariable("$bundle", arg0);
104
-
105
- if (configBundle != null) {
106
- setRemoteVariable(configBundle.getString("Remote Variable"));
107
- if (configBundle.getBoolean("Define Remote Variable")) {
108
- Script.defineGlobalVariable(configBundle.getString("Remote Variable"), this);
109
- setRemoteVariable(configBundle.getString("Remote Variable"));
110
- }
111
- if (configBundle.getString("Initialize Script") != null) {
112
- Script.execute(configBundle.getString("Initialize Script"));
113
- }
114
- Script.execute(remoteVariable + "on_create($bundle)");
115
- } else {
116
- Script.defineGlobalVariable("$activity", this);
117
-
118
- try {
119
- new Script(scriptName).execute();
120
- }
121
- catch(IOException e){
122
- ProgressDialog.show(this, "Script failed", "Something bad happened", true, false);
123
- }
124
- }
125
- % else
126
- try {
127
- new Script(scriptName).execute();
128
- }
129
- catch(IOException e){
130
-
131
- }
132
- % end
133
- }
134
-
135
- public void setScriptName(String name){
136
- scriptName = name;
137
- }
138
-
139
-
140
-
141
- /*********************************************************************************
142
- *
143
- * Ruby Generated Callback Methods
144
- */
145
-
146
- %##############################################################################################
147
- %#
148
- %# Create one Java callback methods
149
- %#
150
- % @callbacks.each do |interface,i_info|
151
- /*
152
- * <%= interface %>
153
- */
154
-
155
- % i_info.each do |method,v|
156
- public <%= "#{v["return_type"]} #{v["interface_method"]}(#{v["args_with_types"] })" %> {
157
- if (callbackOptions[<%= v['constant']%>]) {
158
- <%= "super.#{v["method"]}(#{v["args_alone"].join(", ")});" if v["interface"] == "Activity" %>
159
- try {
160
- % if v["args_alone"].size > 3
161
- IRubyObject[] args = {<%= v["args_alone"].map{|i| "JavaUtil.convertJavaToRuby(__ruby__, #{i})"}.join(", ") %>};
162
- <%= "return (#{transform_return_type v["return_type"]})" if v["return_type"] != "void" %>RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "<%=v["ruby_method"]%>", args)<%= ".toJava(#{v["return_type"]}.class)" if v["return_type"] != "void" %>;
163
- % elsif v["args_alone"].size > 0
164
- <%= "return (#{transform_return_type v["return_type"]})" if v["return_type"] != "void" %>RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "<%=v["ruby_method"]%>", <%= v["args_alone"].map{|i| "JavaUtil.convertJavaToRuby(__ruby__, #{i})"}.join(", ") %>)<%= ".toJava(#{v["return_type"]}.class)" if v["return_type"] != "void"%>;
165
- % else
166
- <%= "return (#{transform_return_type v["return_type"]})" if v["return_type"] != "void" %>RuntimeHelpers.invoke(__ruby__.getCurrentContext(), __this__, "<%=v["ruby_method"]%>")<%= ".toJava(#{v["return_type"]}.class)" if v["return_type"] != "void"%>;
167
- % end
168
- } catch (RaiseException re) {
169
- re.printStackTrace(__ruby__.getErrorStream());
170
- <%= case v["return_type"]
171
- when "boolean": "return false;"
172
- when "int": "return 0;"
173
- when "void": ""
174
- else "return null;"
175
- end
176
- %>
177
- }
178
- % if v["interface"] == "Activity"
179
- } else {
180
- <%= "return " unless v["return_type"] == "void" %><%= "super.#{v["method"]}(#{v["args_alone"].join(", ")});" %>
181
- % elsif v["return_type"] != "void"
182
- } else {
183
- <%= case v["return_type"]
184
- when "boolean": "return false;"
185
- when "int": "return 0;"
186
- when "void": ""
187
- else "return null;"
188
- end
189
- %>
190
- % end
191
- }
192
- }
193
-
194
- % end
195
- % end
196
- %##############################################################################################
197
- }