ruboto 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/COPYING +19 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +21 -0
  4. data/README.md +293 -0
  5. data/Rakefile +114 -0
  6. data/assets/Rakefile +386 -0
  7. data/assets/res/drawable-hdpi/icon.png +0 -0
  8. data/assets/res/drawable-ldpi/icon.png +0 -0
  9. data/assets/res/drawable-mdpi/icon.png +0 -0
  10. data/assets/res/layout/get_ruboto_core.xml +25 -0
  11. data/assets/samples/sample_activity.rb +21 -0
  12. data/assets/samples/sample_activity_test.rb +21 -0
  13. data/assets/samples/sample_broadcast_receiver.rb +6 -0
  14. data/assets/samples/sample_broadcast_receiver_test.rb +1 -0
  15. data/assets/samples/sample_service.rb +14 -0
  16. data/assets/samples/sample_service_test.rb +1 -0
  17. data/assets/src/InheritingActivity.java +195 -0
  18. data/assets/src/InheritingBroadcastReceiver.java +27 -0
  19. data/assets/src/InheritingClass.java +19 -0
  20. data/assets/src/InheritingService.java +9 -0
  21. data/assets/src/RubotoActivity.java +111 -0
  22. data/assets/src/RubotoBroadcastReceiver.java +51 -0
  23. data/assets/src/RubotoService.java +61 -0
  24. data/assets/src/org/ruboto/RubotoDialog.java +11 -0
  25. data/assets/src/org/ruboto/Script.java +545 -0
  26. data/assets/src/org/ruboto/test/ActivityTest.java +63 -0
  27. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +124 -0
  28. data/assets/src/ruboto.rb +621 -0
  29. data/assets/test/assets/scripts/test_helper.rb +13 -0
  30. data/bin/ruboto +5 -0
  31. data/lib/java_class_gen/InheritingClass.java.erb +10 -0
  32. data/lib/java_class_gen/android_api.xml +1 -0
  33. data/lib/ruboto.rb +16 -0
  34. data/lib/ruboto/api.rb +21 -0
  35. data/lib/ruboto/commands/base.rb +392 -0
  36. data/lib/ruboto/core_ext/array.rb +6 -0
  37. data/lib/ruboto/core_ext/object.rb +10 -0
  38. data/lib/ruboto/util/asset_copier.rb +27 -0
  39. data/lib/ruboto/util/build.rb +201 -0
  40. data/lib/ruboto/util/code_formatting.rb +22 -0
  41. data/lib/ruboto/util/log_action.rb +20 -0
  42. data/lib/ruboto/util/main_fix.rb +13 -0
  43. data/lib/ruboto/util/objectspace.rb +8 -0
  44. data/lib/ruboto/util/scan_in_api.rb +40 -0
  45. data/lib/ruboto/util/update.rb +420 -0
  46. data/lib/ruboto/util/verify.rb +87 -0
  47. data/lib/ruboto/util/xml_element.rb +200 -0
  48. data/lib/ruboto/version.rb +3 -0
  49. data/test/activity/image_button_activity.rb +21 -0
  50. data/test/activity/image_button_activity_test.rb +21 -0
  51. data/test/activity/image_button_and_button_activity.rb +24 -0
  52. data/test/activity/image_button_and_button_activity_test.rb +27 -0
  53. data/test/activity/option_menu_activity.rb +21 -0
  54. data/test/activity/option_menu_activity_test.rb +20 -0
  55. data/test/activity/stack_activity.rb +21 -0
  56. data/test/activity/stack_activity_test.rb +23 -0
  57. data/test/app_test_methods.rb +41 -0
  58. data/test/minimal_app_test.rb +23 -0
  59. data/test/rake_test.rb +40 -0
  60. data/test/ruboto_gen_test.rb +32 -0
  61. data/test/ruboto_gen_with_psych_test.rb +16 -0
  62. data/test/ruboto_update_test.rb +5 -0
  63. data/test/ruboto_update_with_psych_test.rb +18 -0
  64. data/test/service_test.rb +49 -0
  65. data/test/test_helper.rb +177 -0
  66. data/test/update_test_methods.rb +33 -0
  67. metadata +157 -0
@@ -0,0 +1,6 @@
1
+ require 'ruboto'
2
+
3
+ # will get called whenever the BroadcastReceiver receives an intent (whenever onReceive is called)
4
+ $broadcast_receiver.handle_receive do |context, intent|
5
+ Log.v "MYAPP", intent.getExtras.to_s
6
+ end
@@ -0,0 +1,14 @@
1
+ require 'ruboto'
2
+
3
+ $service.handle_create do
4
+ # define what your service does. Directly put any code that you want
5
+ # executed when onCreate gets called. Define the rest of the
6
+ # behavior with handle_ blocks. See the README for more info.
7
+
8
+ # Services are complicated and don't really make sense unless you
9
+ # show the interaction between the Service and other parts of your
10
+ # app
11
+ # For now, just take a look at the explanation and example in
12
+ # online:
13
+ # http://developer.android.com/reference/android/app/Service.html
14
+ end
@@ -0,0 +1 @@
1
+ # TODO
@@ -0,0 +1,195 @@
1
+ package THE_PACKAGE;
2
+
3
+ import java.io.File;
4
+ import java.io.IOException;
5
+
6
+ import org.ruboto.Script;
7
+
8
+ import android.app.ProgressDialog;
9
+ import android.content.BroadcastReceiver;
10
+ import android.content.Context;
11
+ import android.content.DialogInterface;
12
+ import android.content.DialogInterface.OnCancelListener;
13
+ import android.content.Intent;
14
+ import android.content.IntentFilter;
15
+ import android.net.Uri;
16
+ import android.os.Bundle;
17
+ import android.os.Handler;
18
+ import android.util.Log;
19
+ import android.view.View;
20
+ import android.widget.TextView;
21
+ import android.widget.Toast;
22
+
23
+ public class InheritingActivity extends org.ruboto.RubotoActivity {
24
+ private int splash = 0;
25
+ private ProgressDialog loadingDialog;
26
+ private boolean dialogCancelled = false;
27
+ private BroadcastReceiver receiver;
28
+ private boolean appStarted = false;
29
+
30
+ public void onCreate(Bundle bundle) {
31
+ Log.d("RUBOTO", "onCreate: ");
32
+
33
+ try {
34
+ splash = Class.forName(getPackageName() + ".R$layout").getField("splash").getInt(null);
35
+ } catch (Exception e) {
36
+ splash = -1;
37
+ }
38
+
39
+ setScriptName("start.rb");
40
+ if (Script.isInitialized()) {
41
+ appStarted = true;
42
+ }
43
+ super.onCreate(bundle);
44
+ }
45
+
46
+ public void onResume() {
47
+ Log.d("RUBOTO", "onResume: ");
48
+
49
+ if(appStarted) {
50
+ Log.d("RUBOTO", "onResume: App already started!");
51
+ super.onResume();
52
+ return;
53
+ }
54
+
55
+ Log.d("RUBOTO", "onResume: Checking JRuby");
56
+ if (Script.isInitialized()) {
57
+ Log.d("RUBOTO", "Already initialized");
58
+ fireRubotoActivity();
59
+ } else {
60
+ Log.d("RUBOTO", "Not initialized");
61
+ showProgress();
62
+ receiver = new BroadcastReceiver(){
63
+ public void onReceive(Context context, Intent intent) {
64
+ Log.i("RUBOTO", "received broadcast: " + intent);
65
+ Log.i("RUBOTO", "URI: " + intent.getData());
66
+ if (intent.getData().toString().equals("package:org.ruboto.core")) {
67
+ Toast.makeText(context,"Ruboto Core is now installed.",Toast.LENGTH_SHORT).show();
68
+ if (receiver != null) {
69
+ unregisterReceiver(receiver);
70
+ receiver = null;
71
+ }
72
+ showProgress();
73
+ initJRuby(false);
74
+ }
75
+ }
76
+ };
77
+ IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
78
+ filter.addDataScheme("package");
79
+ registerReceiver(receiver, filter);
80
+ initJRuby(true);
81
+ super.onResume();
82
+ }
83
+ }
84
+
85
+ public void onPause() {
86
+ Log.d("RUBOTO", "onPause: ");
87
+
88
+ if (receiver != null) {
89
+ unregisterReceiver(receiver);
90
+ receiver = null;
91
+ }
92
+ super.onPause();
93
+ }
94
+
95
+ public void onDestroy() {
96
+ Log.d("RUBOTO", "onDestroy: ");
97
+
98
+ super.onDestroy();
99
+ if (dialogCancelled) {
100
+ System.runFinalizersOnExit(true);
101
+ System.exit(0);
102
+ }
103
+ }
104
+
105
+ private void initJRuby(final boolean firstTime) {
106
+ new Thread(new Runnable() {
107
+ public void run() {
108
+ final boolean jrubyOk = Script.setUpJRuby(InheritingActivity.this);
109
+ if (jrubyOk) {
110
+ Log.d("RUBOTO", "onResume: JRuby OK");
111
+ prepareJRuby();
112
+ runOnUiThread(new Runnable() {
113
+ public void run() {
114
+ fireRubotoActivity();
115
+ }
116
+ });
117
+ } else {
118
+ runOnUiThread(new Runnable() {
119
+ public void run() {
120
+ if (firstTime) {
121
+ Log.d("RUBOTO", "onResume: Checking JRuby - IN UI thread");
122
+ try {
123
+ setContentView(Class.forName(getPackageName() + ".R$layout").getField("get_ruboto_core").getInt(null));
124
+ } catch (Exception e) {
125
+ }
126
+ } else {
127
+ Toast.makeText(InheritingActivity.this,"Failed to initialize Ruboto Core.",Toast.LENGTH_SHORT).show();
128
+ try {
129
+ TextView textView = (TextView) findViewById(Class.forName(getPackageName() + ".R$id").getField("text").getInt(null));
130
+ textView.setText("Woops! Ruboto Core was installed, but it failed to initialize properly! I am not sure how to proceed from here. If you can, please file an error report at http://ruboto.org/");
131
+ } catch (Exception e) {
132
+ }
133
+ }
134
+ hideProgress();
135
+ }
136
+ });
137
+ }
138
+ }
139
+ }).start();
140
+ }
141
+
142
+ private static final String RUBOTO_APK = "RubotoCore-release.apk";
143
+ private static final String RUBOTO_URL = "https://github.com/downloads/ruboto/ruboto/" + RUBOTO_APK;
144
+
145
+ // Called when the button is pressed.
146
+ public void getRubotoCore(View view) {
147
+ try {
148
+ startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://details?id=org.ruboto.core")));
149
+ } catch (android.content.ActivityNotFoundException anfe) {
150
+ try {
151
+ TextView textView = (TextView) findViewById(Class.forName(getPackageName() + ".R$id").getField("text").getInt(null));
152
+ Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(RUBOTO_URL));
153
+ startActivity(intent);
154
+ } catch (Exception e) {}
155
+ }
156
+ }
157
+
158
+ private void fireRubotoActivity() {
159
+ if(appStarted) return;
160
+ appStarted = true;
161
+ Log.i("RUBOTO", "Starting activity");
162
+ loadScript();
163
+ onStart();
164
+ super.onResume();
165
+ hideProgress();
166
+ }
167
+
168
+ private void showProgress() {
169
+ if (loadingDialog == null) {
170
+ Log.i("RUBOTO", "Showing progress");
171
+ if (splash > 0) {
172
+ requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
173
+ setContentView(splash);
174
+ } else {
175
+ loadingDialog = ProgressDialog.show(this, null, "Starting...", true, true);
176
+ loadingDialog.setCanceledOnTouchOutside(false);
177
+ loadingDialog.setOnCancelListener(new OnCancelListener() {
178
+ public void onCancel(DialogInterface dialog) {
179
+ dialogCancelled = true;
180
+ finish();
181
+ }
182
+ });
183
+ }
184
+ }
185
+ }
186
+
187
+ private void hideProgress() {
188
+ if (loadingDialog != null) {
189
+ Log.d("RUBOTO", "Hide progress");
190
+ loadingDialog.dismiss();
191
+ loadingDialog = null;
192
+ }
193
+ }
194
+
195
+ }
@@ -0,0 +1,27 @@
1
+ package THE_PACKAGE;
2
+
3
+ import org.ruboto.Script;
4
+
5
+ public class InheritingBroadcastReceiver extends org.ruboto.RubotoBroadcastReceiver {
6
+ private boolean scriptLoaded = false;
7
+
8
+ public InheritingBroadcastReceiver() {
9
+ super("start.rb");
10
+ if (Script.isInitialized()) {
11
+ scriptLoaded = true;
12
+ }
13
+ }
14
+
15
+ public void onReceive(android.content.Context context, android.content.Intent intent) {
16
+ if (!scriptLoaded) {
17
+ if (Script.setUpJRuby(context)) {
18
+ loadScript();
19
+ scriptLoaded = true;
20
+ } else {
21
+ // FIXME(uwe): What to do if the Ruboto Core platform is missing?
22
+ }
23
+ }
24
+ super.onReceive(context, intent);
25
+ }
26
+
27
+ }
@@ -0,0 +1,19 @@
1
+ package THE_PACKAGE;
2
+
3
+ import org.ruboto.Script;
4
+
5
+ public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
6
+
7
+ THE_CONSTANTS
8
+
9
+ private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
10
+
11
+ THE_CONSTRUCTORS
12
+
13
+ public void setCallbackProc(int id, Object obj) {
14
+ callbackProcs[id] = obj;
15
+ }
16
+
17
+ THE_METHODS
18
+
19
+ }
@@ -0,0 +1,9 @@
1
+ package THE_PACKAGE;
2
+
3
+ public class InheritingService extends org.ruboto.RubotoService {
4
+ public void onCreate() {
5
+ setScriptName("start.rb");
6
+ super.onCreate();
7
+ }
8
+
9
+ }
@@ -0,0 +1,111 @@
1
+ package THE_PACKAGE;
2
+
3
+ import java.io.IOException;
4
+
5
+ import org.ruboto.Script;
6
+
7
+ import android.app.ProgressDialog;
8
+ import android.content.Intent;
9
+ import android.net.Uri;
10
+ import android.os.Bundle;
11
+ import android.os.Handler;
12
+ import android.util.Log;
13
+ import android.view.View;
14
+ import android.widget.TextView;
15
+
16
+ public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
17
+ private String scriptName;
18
+ private String remoteVariable = null;
19
+ private Object[] args;
20
+ private Bundle configBundle;
21
+
22
+ THE_CONSTANTS
23
+
24
+ private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
25
+
26
+ public void setCallbackProc(int id, Object obj) {
27
+ callbackProcs[id] = obj;
28
+ }
29
+
30
+ public THE_RUBOTO_CLASS setRemoteVariable(String var) {
31
+ remoteVariable = var;
32
+ return this;
33
+ }
34
+
35
+ public String getRemoteVariableCall(String call) {
36
+ return (remoteVariable == null ? "" : (remoteVariable + ".")) + call;
37
+ }
38
+
39
+ public void setScriptName(String name) {
40
+ scriptName = name;
41
+ }
42
+
43
+ /****************************************************************************************
44
+ *
45
+ * Activity Lifecycle: onCreate
46
+ */
47
+
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
+ }
67
+
68
+ super.onCreate(bundle);
69
+
70
+ if (Script.isInitialized()) {
71
+ prepareJRuby();
72
+ loadScript();
73
+ }
74
+ }
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]);
80
+ }
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
+ }
102
+ }
103
+
104
+ /****************************************************************************************
105
+ *
106
+ * Generated Methods
107
+ */
108
+
109
+ THE_METHODS
110
+
111
+ }
@@ -0,0 +1,51 @@
1
+ package THE_PACKAGE;
2
+
3
+ import java.io.IOException;
4
+
5
+ public abstract class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
6
+ private String scriptName;
7
+ private String remoteVariable = "";
8
+
9
+ THE_CONSTANTS
10
+
11
+ private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
12
+
13
+ public void setCallbackProc(int id, Object obj) {
14
+ callbackProcs[id] = obj;
15
+ }
16
+
17
+ public THE_RUBOTO_CLASS setRemoteVariable(String var) {
18
+ remoteVariable = ((var == null) ? "" : (var + "."));
19
+ return this;
20
+ }
21
+
22
+ public void setScriptName(String name){
23
+ scriptName = name;
24
+ }
25
+
26
+ public THE_RUBOTO_CLASS(String scriptName) {
27
+ setScriptName(scriptName);
28
+ if (Script.isInitialized()) {
29
+ loadScript();
30
+ }
31
+ }
32
+
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
+ }
40
+ }
41
+
42
+ /****************************************************************************************
43
+ *
44
+ * Generated Methods
45
+ */
46
+
47
+ THE_METHODS
48
+
49
+ }
50
+
51
+