ruboto 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Gemfile.lock +5 -5
  2. data/README.md +2 -2
  3. data/Rakefile +5 -6
  4. data/assets/Rakefile +32 -11
  5. data/assets/res/drawable/get_ruboto_core.png +0 -0
  6. data/assets/res/layout/get_ruboto_core.xml +1 -1
  7. data/assets/samples/sample_activity.rb +13 -11
  8. data/assets/samples/sample_broadcast_receiver.rb +6 -3
  9. data/assets/samples/sample_service.rb +10 -7
  10. data/assets/src/InheritingActivity.java +1 -186
  11. data/assets/src/RubotoActivity.java +9 -11
  12. data/assets/src/RubotoBroadcastReceiver.java +34 -27
  13. data/assets/src/RubotoService.java +9 -2
  14. data/assets/src/org/ruboto/EntryPointActivity.java +194 -0
  15. data/assets/src/org/ruboto/Script.java +29 -15
  16. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +17 -16
  17. data/assets/src/ruboto.rb +11 -608
  18. data/assets/src/ruboto/activity.rb +84 -0
  19. data/assets/src/ruboto/base.rb +88 -0
  20. data/assets/src/ruboto/broadcast_receiver.rb +31 -0
  21. data/assets/src/ruboto/legacy.rb +223 -0
  22. data/assets/src/ruboto/menu.rb +89 -0
  23. data/assets/src/ruboto/preference.rb +78 -0
  24. data/assets/src/ruboto/service.rb +74 -0
  25. data/assets/src/ruboto/util/stack.rb +34 -0
  26. data/assets/src/ruboto/util/toast.rb +18 -0
  27. data/assets/src/ruboto/widget.rb +188 -0
  28. data/assets/test/{assets/scripts → src}/test_helper.rb +4 -0
  29. data/bin/ruboto +7 -0
  30. data/lib/ruboto/commands/base.rb +4 -18
  31. data/lib/ruboto/util/build.rb +1 -2
  32. data/lib/ruboto/util/update.rb +77 -70
  33. data/lib/ruboto/version.rb +1 -1
  34. data/test/activity/psych_activity.rb +25 -0
  35. data/test/activity/psych_activity_test.rb +16 -0
  36. data/test/activity/stack_activity_test.rb +1 -1
  37. data/test/app_test_methods.rb +8 -4
  38. data/test/minimal_app_test.rb +6 -3
  39. data/test/rake_test.rb +1 -1
  40. data/test/ruboto_gen_test.rb +10 -1
  41. data/test/test_helper.rb +3 -5
  42. data/test/update_test_methods.rb +2 -2
  43. metadata +20 -8
  44. data/test/ruboto_gen_with_psych_test.rb +0 -16
  45. data/test/ruboto_update_with_psych_test.rb +0 -18
data/Gemfile.lock CHANGED
@@ -2,15 +2,15 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  arrayfields (4.7.4)
5
- chronic (0.6.2)
5
+ chronic (0.6.6)
6
6
  fattr (2.2.0)
7
- jruby-jars (1.6.4)
8
- main (4.7.3)
7
+ jruby-jars (1.6.5.1)
8
+ main (4.8.1)
9
9
  arrayfields (~> 4.7.4)
10
10
  chronic (~> 0.6.2)
11
11
  fattr (~> 2.2.0)
12
- map (~> 4.3.0)
13
- map (4.3.0)
12
+ map (~> 5.1.0)
13
+ map (5.1.0)
14
14
 
15
15
  PLATFORMS
16
16
  java
data/README.md CHANGED
@@ -203,8 +203,8 @@ Activities also have some special methods defined to make things easier. The eas
203
203
  Testing
204
204
  -------
205
205
 
206
- For each generated class, a ruby test script is created in the test/assets/scripts directory.
207
- For example if you generate a RubotoSampleAppActivity a file test/assets/scripts/ruboto_sample_app_activity_test.rb
206
+ For each generated class, a ruby test script is created in the test/src directory.
207
+ For example if you generate a RubotoSampleAppActivity a file test/src/ruboto_sample_app_activity_test.rb
208
208
  file is created containing a sample test script:
209
209
 
210
210
  activity Java::org.ruboto.sample_app.RubotoSampleAppActivity
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rake/clean'
1
2
  require 'rexml/document'
2
3
  require 'lib/ruboto/version'
3
4
 
@@ -21,6 +22,7 @@ JRUBY_JARS_VERSION = gem_spec.version
21
22
  ON_JRUBY_JARS_1_5_6 = JRUBY_JARS_VERSION == Gem::Version.new('1.5.6')
22
23
  # FIXME end
23
24
 
25
+ CLEAN.include('ruboto-*.gem', 'tmp')
24
26
 
25
27
  task :default => :gem
26
28
 
@@ -66,20 +68,17 @@ namespace :platform do
66
68
  task :project => PLATFORM_PROJECT
67
69
 
68
70
  file PLATFORM_PROJECT do
69
- sh "ruby -rubygems -I#{File.expand_path('lib', File.dirname(__FILE__))} bin/ruboto gen app --package org.ruboto.core --name RubotoCore --with-jruby #{'--with-psych' unless ON_JRUBY_JARS_1_5_6} --path #{PLATFORM_PROJECT}"
71
+ sh "ruby -rubygems -I#{File.expand_path('lib', File.dirname(__FILE__))} bin/ruboto gen app --package org.ruboto.core --name RubotoCore --with-jruby --path #{PLATFORM_PROJECT}"
70
72
  Dir.chdir(PLATFORM_PROJECT) do
71
73
  manifest = REXML::Document.new(File.read(MANIFEST_FILE))
72
74
  manifest.root.attributes['android:versionCode'] = '408'
73
- manifest.root.attributes['android:versionName'] = '0.4.8.dev'
75
+ manifest.root.attributes['android:versionName'] = '0.4.8'
74
76
  manifest.root.attributes['android:installLocation'] = 'auto' # or 'preferExternal' ?
75
77
  manifest.root.elements['uses-sdk'].attributes['android:targetSdkVersion'] = '8'
76
78
  File.open(MANIFEST_FILE, 'w') { |f| manifest.document.write(f, 4) }
77
79
  File.open('project.properties', 'w'){|f| f << "target=android-8\n"}
78
80
  File.open('Gemfile.apk', 'w'){|f| f << "source :rubygems\n\ngem 'activerecord-jdbc-adapter'\n"}
79
- keystore_file = File.expand_path('~/android_market.keystore')
80
- if File.exists?(keystore_file)
81
- File.open('local.properties', 'a'){|f| f << "key.store=#{keystore_file}\nkey.alias=android_market\n"}
82
- end
81
+ File.open('ant.properties', 'a'){|f| f << "key.store=${user.home}/ruboto_core.keystore\nkey.alias=Ruboto\n"}
83
82
  end
84
83
  end
85
84
 
data/assets/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
+ if `ant -version` !~ /version (\d+)\.(\d+)\.(\d+)/ || $1.to_i < 1 || ($1.to_i == 1 && $2.to_i < 8)
2
+ puts "ANT version 1.8.0 or later required. Version found: #{$1}.#{$2}.#{$3}"
3
+ exit 1
4
+ end
5
+
1
6
  require 'time'
2
7
 
3
8
  def manifest() @manifest ||= REXML::Document.new(File.read(MANIFEST_FILE)) end
@@ -10,9 +15,9 @@ require 'rake/clean'
10
15
  require 'rexml/document'
11
16
 
12
17
  PROJECT_DIR = Dir.getwd
13
- UPDATE_MARKER_FILE = File.expand_path(File.join('tmp', 'LAST_UPDATE'), File.dirname(__FILE__))
18
+ UPDATE_MARKER_FILE = File.expand_path(File.join('bin', 'LAST_UPDATE'), File.dirname(__FILE__))
14
19
  BUNDLE_JAR = File.expand_path 'libs/bundle.jar'
15
- BUNDLE_PATH = File.expand_path 'tmp/bundle'
20
+ BUNDLE_PATH = File.expand_path 'bin/bundle'
16
21
  MANIFEST_FILE = File.expand_path 'AndroidManifest.xml'
17
22
  RUBOTO_CONFIG_FILE = File.expand_path 'ruboto.yml'
18
23
  GEM_FILE = File.expand_path('Gemfile.apk')
@@ -25,8 +30,10 @@ RESOURCE_FILES = Dir[File.expand_path 'res/**/*']
25
30
  JAVA_SOURCE_FILES = Dir[File.expand_path 'src/**/*.java']
26
31
  RUBY_SOURCE_FILES = Dir[File.expand_path 'src/**/*.rb']
27
32
  APK_DEPENDENCIES = [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES + RUBY_SOURCE_FILES
33
+ KEYSTORE_FILE = (key_store = File.readlines('ant.properties').grep(/^key.store=/).first) ? key_store.chomp.sub(/^key.store=/, '') : "#{build_project_name}.keystore"
34
+ KEYSTORE_ALIAS = (key_alias = File.readlines('ant.properties').grep(/^key.alias=/).first) ? key_alias.chomp.sub(/^key.alias=/, '') : build_project_name
28
35
 
29
- CLEAN.include('tmp', 'bin')
36
+ CLEAN.include('bin')
30
37
 
31
38
  task :default => :debug
32
39
 
@@ -72,21 +79,35 @@ namespace :install do
72
79
  end
73
80
  end
74
81
 
82
+ desc 'Build APK for release'
75
83
  task :release => RELEASE_APK_FILE
76
84
 
77
- file RELEASE_APK_FILE => APK_DEPENDENCIES do |t|
85
+ file RELEASE_APK_FILE => [KEYSTORE_FILE] + APK_DEPENDENCIES do |t|
78
86
  build_apk(t, true)
79
87
  end
80
88
 
89
+ desc 'Create a keystore for signing the release APK'
90
+ file KEYSTORE_FILE do
91
+ unless File.read('ant.properties') =~ /^key.store=/
92
+ File.open('ant.properties', 'a'){|f| f << "\nkey.store=#{KEYSTORE_FILE}\n"}
93
+ end
94
+ unless File.read('ant.properties') =~ /^key.alias=/
95
+ File.open('ant.properties', 'a'){|f| f << "\nkey.alias=#{KEYSTORE_ALIAS}\n"}
96
+ end
97
+ sh "keytool -genkey -v -keystore #{KEYSTORE_FILE} -alias #{KEYSTORE_ALIAS} -keyalg RSA -keysize 2048 -validity 10000"
98
+ end
99
+
100
+ desc 'Tag this working copy with the current version'
81
101
  task :tag => :release do
82
102
  unless `git branch` =~ /^\* master$/
83
103
  puts "You must be on the master branch to release!"
84
104
  exit!
85
105
  end
86
- sh "git commit --allow-empty -a -m 'Release #{version}'"
106
+ # sh "git commit --allow-empty -a -m 'Release #{version}'"
107
+ output = `git status --porcelain`
108
+ raise "Workspace not clean!\n#{output}" unless output.empty?
87
109
  sh "git tag #{version}"
88
110
  sh "git push origin master --tags"
89
- #sh "gem push pkg/#{name}-#{version}.gem"
90
111
  end
91
112
 
92
113
  task :sign => :release do
@@ -136,11 +157,10 @@ end
136
157
  namespace :update_scripts do
137
158
  desc 'Copy scripts to emulator and restart the app'
138
159
  task :restart => APK_DEPENDENCIES do |t|
139
- if stop_app
140
- update_scripts
141
- else
142
- build_apk(t, false)
160
+ if build_apk(t, false) || !stop_app
143
161
  install_apk
162
+ else
163
+ update_scripts
144
164
  end
145
165
  start_app
146
166
  end
@@ -326,7 +346,7 @@ def build_apk(t, release)
326
346
  changed_prereqs = t.prerequisites.select do |p|
327
347
  File.file?(p) && !Dir[p].empty? && Dir[p].map { |f| File.mtime(f) }.max > File.mtime(APK_FILE)
328
348
  end
329
- return if changed_prereqs.empty?
349
+ return false if changed_prereqs.empty?
330
350
  changed_prereqs.each { |f| puts "#{f} changed." }
331
351
  puts "Forcing rebuild of #{apk_file}."
332
352
  end
@@ -335,6 +355,7 @@ def build_apk(t, release)
335
355
  else
336
356
  sh 'ant debug'
337
357
  end
358
+ return true
338
359
  end
339
360
 
340
361
  def install_apk
@@ -12,7 +12,7 @@
12
12
  android:id="@+id/image"
13
13
  android:layout_width="fill_parent"
14
14
  android:layout_height="fill_parent"
15
- android:src="@drawable/icon"
15
+ android:src="@drawable/get_ruboto_core"
16
16
  android:layout_weight="1"
17
17
  android:scaleType="fitCenter"
18
18
  android:onClick="getRubotoCore"
@@ -1,21 +1,23 @@
1
- require 'ruboto'
1
+ require 'ruboto/activity'
2
+ require 'ruboto/widget'
3
+ require 'ruboto/util/toast'
2
4
 
3
5
  ruboto_import_widgets :Button, :LinearLayout, :TextView
4
6
 
5
- $activity.handle_create do |bundle|
7
+ $activity.start_ruboto_activity "$sample_activity" do
6
8
  setTitle 'This is the Title'
7
9
 
8
- setup_content do
9
- linear_layout :orientation => LinearLayout::VERTICAL do
10
- @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
11
- button :text => 'M-x butterfly', :width => :wrap_content, :id => 43
12
- end
10
+ def on_create(bundle)
11
+ self.content_view =
12
+ linear_layout(:orientation => :vertical) do
13
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
14
+ button :text => 'M-x butterfly', :width => :wrap_content, :id => 43,
15
+ :on_click_listener => @handle_click
16
+ end
13
17
  end
14
18
 
15
- handle_click do |view|
16
- if view.getText == 'M-x butterfly'
17
- @text_view.setText 'What hath Matz wrought!'
19
+ @handle_click = proc do |view|
20
+ @text_view.text = 'What hath Matz wrought!'
18
21
  toast 'Flipped a bit via butterfly'
19
- end
20
22
  end
21
23
  end
@@ -1,6 +1,9 @@
1
- require 'ruboto'
1
+ require 'ruboto/broadcast_receiver'
2
2
 
3
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
4
+ RubotoBroadcastReceiver.new_with_callbacks do
5
+ def on_receive(context, intent)
6
+ Log.v "MYAPP", intent.getExtras.to_s
7
+ end
6
8
  end
9
+
@@ -1,14 +1,17 @@
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.
1
+ require 'ruboto/service'
2
+ require 'ruboto/util/toast'
7
3
 
4
+ $context.start_ruboto_service do
8
5
  # Services are complicated and don't really make sense unless you
9
6
  # show the interaction between the Service and other parts of your
10
- # app
7
+ # app.
11
8
  # For now, just take a look at the explanation and example in
12
9
  # online:
13
10
  # http://developer.android.com/reference/android/app/Service.html
11
+
12
+ def on_start_command(intent, flags, startId)
13
+ toast "Hello from the service"
14
+ self.class::START_NOT_STICKY
15
+ end
16
+
14
17
  end
@@ -1,195 +1,10 @@
1
1
  package THE_PACKAGE;
2
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
3
  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
4
 
5
+ public class InheritingActivity extends org.ruboto.EntryPointActivity {
30
6
  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
7
  setScriptName("start.rb");
40
- if (Script.isInitialized()) {
41
- appStarted = true;
42
- }
43
8
  super.onCreate(bundle);
44
9
  }
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
10
  }