ruboto 0.9.0 → 0.10.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -13
- data/Rakefile +4 -4
- data/assets/rakelib/ruboto.rake +8 -4
- data/assets/samples/sample_broadcast_receiver.rb +0 -8
- data/assets/src/InheritingBroadcastReceiver.java +0 -19
- data/assets/src/InheritingClass.java +1 -8
- data/assets/src/RubotoActivity.java +1 -20
- data/assets/src/RubotoBroadcastReceiver.java +15 -25
- data/assets/src/RubotoService.java +1 -15
- data/assets/src/org/ruboto/EntryPointActivity.java +0 -1
- data/assets/src/org/ruboto/JRubyAdapter.java +9 -8
- data/assets/src/org/ruboto/RubotoComponent.java +0 -3
- data/assets/src/org/ruboto/Script.java +9 -9
- data/assets/src/org/ruboto/ScriptInfo.java +0 -15
- data/assets/src/org/ruboto/ScriptLoader.java +31 -43
- data/assets/src/ruboto/activity.rb +16 -41
- data/assets/src/ruboto/base.rb +0 -70
- data/assets/src/ruboto/broadcast_receiver.rb +2 -22
- data/assets/src/ruboto/package.rb +0 -1
- data/assets/src/ruboto/preference.rb +7 -3
- data/assets/src/ruboto/service.rb +14 -51
- data/assets/src/ruboto/widget.rb +2 -2
- data/lib/DexClient.java +10 -3
- data/lib/ruboto/util/build.rb +0 -5
- data/lib/ruboto/util/code_formatting.rb +1 -1
- data/lib/ruboto/util/update.rb +69 -50
- data/lib/ruboto/util/verify.rb +6 -5
- data/lib/ruboto/util/xml_element.rb +16 -29
- data/lib/ruboto/version.rb +2 -2
- data/test/activity/mytest_activity.rb +56 -0
- data/test/activity/mytest_activity_test.rb +52 -0
- data/test/activity/mytest_otherfile_activity.rb +12 -0
- data/test/activity/navigation_activity.rb +1 -1
- data/test/activity/subclass_activity.rb +10 -5
- data/test/activity/subclass_activity_test.rb +17 -2
- data/test/activity/view_constants_activity.rb +42 -0
- data/test/activity/view_constants_activity_test.rb +30 -0
- data/test/app_test_methods.rb +31 -26
- data/test/broadcast_receiver_test.rb +3 -1
- data/test/ruboto_gen_test.rb +4 -4
- data/test/test_helper.rb +5 -2
- metadata +18 -38
- data/assets/src/ruboto.rb +0 -25
- data/assets/src/ruboto/legacy.rb +0 -220
- data/assets/src/ruboto/menu.rb +0 -88
- data/lib/java_class_gen/InheritingClass.java.erb +0 -10
- data/test/block_def_activity/image_button_activity.rb +0 -23
- data/test/block_def_activity/image_button_activity_test.rb +0 -21
- data/test/block_def_activity/image_button_and_button_activity.rb +0 -20
- data/test/block_def_activity/image_button_and_button_activity_test.rb +0 -27
- data/test/block_def_activity/margins_activity.rb +0 -18
- data/test/block_def_activity/margins_activity_test.rb +0 -25
- data/test/block_def_activity/option_menu_activity.rb +0 -26
- data/test/block_def_activity/option_menu_activity_test.rb +0 -17
- data/test/block_def_activity/psych_activity.rb +0 -35
- data/test/block_def_activity/psych_activity_test.rb +0 -16
- data/test/block_def_activity/stack_activity.rb +0 -25
- data/test/block_def_activity/stack_activity_test.rb +0 -39
- data/test/handle_activity/image_button_activity.rb +0 -21
- data/test/handle_activity/image_button_activity_test.rb +0 -21
- data/test/handle_activity/image_button_and_button_activity.rb +0 -24
- data/test/handle_activity/image_button_and_button_activity_test.rb +0 -27
- data/test/handle_activity/margins_activity.rb +0 -15
- data/test/handle_activity/margins_activity_test.rb +0 -25
- data/test/handle_activity/option_menu_activity.rb +0 -25
- data/test/handle_activity/option_menu_activity_test.rb +0 -20
- data/test/handle_activity/psych_activity.rb +0 -31
- data/test/handle_activity/psych_activity_test.rb +0 -16
- data/test/handle_activity/stack_activity.rb +0 -24
- data/test/handle_activity/stack_activity_test.rb +0 -47
- data/test/view_constants_test.rb +0 -103
@@ -152,15 +152,15 @@ public class Script {
|
|
152
152
|
}
|
153
153
|
}
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
155
|
+
public File getFile() {
|
156
|
+
for (String dir : scriptsDir) {
|
157
|
+
File f = new File(dir, name);
|
158
|
+
if (f.exists()) {
|
159
|
+
return f;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
return new File(scriptsDir[0], name);
|
163
|
+
}
|
164
164
|
|
165
165
|
public String getName() {
|
166
166
|
return name;
|
@@ -5,21 +5,6 @@ public class ScriptInfo {
|
|
5
5
|
private String scriptName;
|
6
6
|
private Object rubyInstance;
|
7
7
|
|
8
|
-
// FIXME(uwe): Only used for legacy handle_xxx callbacks. Remove when we stop supporting these.
|
9
|
-
private final Object[] callbackProcs;
|
10
|
-
|
11
|
-
public ScriptInfo(int callbackSize) {
|
12
|
-
callbackProcs = new Object[callbackSize];
|
13
|
-
}
|
14
|
-
|
15
|
-
public Object[] getCallbackProcs() {
|
16
|
-
return callbackProcs;
|
17
|
-
}
|
18
|
-
|
19
|
-
public void setCallbackProc(int id, Object obj) {
|
20
|
-
callbackProcs[id] = obj;
|
21
|
-
}
|
22
|
-
|
23
8
|
public String getRubyClassName() {
|
24
9
|
if (rubyClassName == null && scriptName != null) {
|
25
10
|
return Script.toCamelCase(scriptName);
|
@@ -31,34 +31,43 @@ public class ScriptLoader {
|
|
31
31
|
if (rubyScript.exists()) {
|
32
32
|
rubyInstance = component;
|
33
33
|
final String script = rubyScript.getContents();
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
boolean scriptContainsClass = script.matches("(?s).*class "
|
35
|
+
+ component.getScriptInfo().getRubyClassName() + ".*");
|
36
|
+
boolean hasBackingJavaClass = component.getScriptInfo().getRubyClassName()
|
37
|
+
.equals(component.getClass().getSimpleName());
|
38
|
+
if (scriptContainsClass && !hasBackingJavaClass) {
|
39
|
+
System.out.println("Script defines methods on meta class");
|
40
|
+
|
41
|
+
// FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
|
42
|
+
if (JRubyAdapter.isJRubyPreOneSeven() || JRubyAdapter.isRubyOneEight()) {
|
43
|
+
JRubyAdapter.put("$java_instance", component);
|
44
|
+
rubyClass = JRubyAdapter.runScriptlet("class << $java_instance; self; end");
|
45
|
+
} else if (JRubyAdapter.isJRubyOneSeven() && JRubyAdapter.isRubyOneNine()) {
|
46
|
+
JRubyAdapter.runScriptlet("Java::" + component.getClass().getName() + ".__persistent__ = true");
|
47
|
+
rubyClass = JRubyAdapter.runRubyMethod(component, "singleton_class");
|
48
|
+
} else {
|
49
|
+
throw new RuntimeException("Unknown JRuby/Ruby version: " + JRubyAdapter.get("JRUBY_VERSION") + "/" + JRubyAdapter.get("RUBY_VERSION"));
|
47
50
|
}
|
51
|
+
// EMXIF
|
52
|
+
|
48
53
|
}
|
49
|
-
if (rubyClass == null) {
|
54
|
+
if (rubyClass == null || !hasBackingJavaClass) {
|
50
55
|
System.out.println("Loading script: " + component.getScriptInfo().getScriptName());
|
51
|
-
if (
|
56
|
+
if (scriptContainsClass) {
|
52
57
|
System.out.println("Script contains class definition");
|
53
|
-
if (
|
58
|
+
if (rubyClass == null && hasBackingJavaClass) {
|
54
59
|
System.out.println("Script has separate Java class");
|
60
|
+
|
55
61
|
// FIXME(uwe): Simplify when we stop support for JRuby < 1.7.0
|
56
62
|
if (!JRubyAdapter.isJRubyPreOneSeven()) {
|
57
63
|
JRubyAdapter.runScriptlet("Java::" + component.getClass().getName() + ".__persistent__ = true");
|
58
64
|
}
|
59
|
-
|
65
|
+
// EMXIF
|
66
|
+
|
67
|
+
rubyClass = JRubyAdapter.runScriptlet("Java::" + component.getClass().getName());
|
60
68
|
}
|
61
|
-
System.out.println("Set class: " +
|
69
|
+
System.out.println("Set class: " + rubyClass);
|
70
|
+
JRubyAdapter.put(component.getScriptInfo().getRubyClassName(), rubyClass);
|
62
71
|
Thread t = new Thread(new Runnable(){
|
63
72
|
public void run() {
|
64
73
|
JRubyAdapter.setScriptFilename(rubyScript.getAbsolutePath());
|
@@ -72,17 +81,11 @@ public class ScriptLoader {
|
|
72
81
|
Thread.currentThread().interrupt();
|
73
82
|
throw new RuntimeException("Interrupted loading script.", ie);
|
74
83
|
}
|
75
|
-
rubyClass = JRubyAdapter.get(component.getScriptInfo().getRubyClassName());
|
76
84
|
} else {
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
}
|
82
|
-
JRubyAdapter.runScriptlet("$activity.instance_variable_set '@ruboto_java_class', '" + component.getScriptInfo().getRubyClassName() + "'");
|
83
|
-
JRubyAdapter.runScriptlet("puts %Q{$activity: #$activity}");
|
84
|
-
JRubyAdapter.setScriptFilename(rubyScript.getAbsolutePath());
|
85
|
-
JRubyAdapter.runScriptlet(script);
|
85
|
+
throw new RuntimeException("Expected file "
|
86
|
+
+ component.getScriptInfo().getScriptName()
|
87
|
+
+ " to define class "
|
88
|
+
+ component.getScriptInfo().getRubyClassName());
|
86
89
|
}
|
87
90
|
}
|
88
91
|
} else if (rubyClass != null) {
|
@@ -98,23 +101,8 @@ public class ScriptLoader {
|
|
98
101
|
if (component instanceof android.content.Context) {
|
99
102
|
callOnCreate(rubyInstance, args);
|
100
103
|
}
|
101
|
-
} else {
|
102
|
-
// FIXME(uwe): Remove when we stop supporting block based main activities.
|
103
|
-
component.onCreateSuper();
|
104
104
|
}
|
105
105
|
component.getScriptInfo().setRubyInstance(rubyInstance);
|
106
|
-
} else { // if (configBundle != null) {
|
107
|
-
// FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
|
108
|
-
if (JRubyAdapter.isJRubyPreOneSeven()) {
|
109
|
-
JRubyAdapter.runScriptlet("$activity.initialize_ruboto");
|
110
|
-
} else if (JRubyAdapter.isJRubyOneSeven()) {
|
111
|
-
JRubyAdapter.runRubyMethod(component, "initialize_ruboto");
|
112
|
-
} else {
|
113
|
-
throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
|
114
|
-
}
|
115
|
-
if (component instanceof android.content.Context) {
|
116
|
-
callOnCreate(component, args);
|
117
|
-
}
|
118
106
|
}
|
119
107
|
} catch(IOException e){
|
120
108
|
e.printStackTrace();
|
@@ -5,34 +5,21 @@ require 'ruboto/package'
|
|
5
5
|
#
|
6
6
|
# ruboto/activity.rb
|
7
7
|
#
|
8
|
-
# Basic activity set up
|
8
|
+
# Basic activity set up.
|
9
9
|
#
|
10
10
|
#######################################################
|
11
11
|
|
12
12
|
#
|
13
13
|
# Context
|
14
14
|
#
|
15
|
-
|
16
15
|
module Ruboto
|
17
16
|
module Context
|
18
|
-
def initialize_ruboto()
|
19
|
-
eval("#{$new_context_global} = self")
|
20
|
-
$new_context_global = nil
|
21
|
-
|
22
|
-
instance_eval &$context_init_block if $context_init_block
|
23
|
-
$context_init_block = nil
|
24
|
-
setup_ruboto_callbacks
|
25
|
-
|
26
|
-
@initialized = true
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
17
|
def start_ruboto_dialog(remote_variable, theme=Java::android.R.style::Theme_Dialog, &block)
|
31
|
-
|
18
|
+
java_import "org.ruboto.RubotoDialog"
|
32
19
|
start_ruboto_activity(remote_variable, RubotoDialog, theme, &block)
|
33
20
|
end
|
34
|
-
|
35
|
-
def start_ruboto_activity(global_variable_name = '$
|
21
|
+
|
22
|
+
def start_ruboto_activity(global_variable_name = '$block_based_activity', klass=RubotoActivity, theme=nil, options = nil, &block)
|
36
23
|
# FIXME(uwe): Translate old positional signature to new options-based signature.
|
37
24
|
# FIXME(uwe): Remove when we stop supporting Ruboto 0.8.0 or older.
|
38
25
|
if options.nil?
|
@@ -44,31 +31,19 @@ module Ruboto
|
|
44
31
|
global_variable_name = nil
|
45
32
|
end
|
46
33
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if @ruboto_java_class and not @ruboto_java_class_initialized
|
51
|
-
@ruboto_java_class_initialized = true
|
52
|
-
puts "Block based main activity definition"
|
53
|
-
instance_eval &block if block
|
54
|
-
setup_ruboto_callbacks
|
55
|
-
on_create nil
|
34
|
+
class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
|
35
|
+
if !Object.const_defined?(class_name)
|
36
|
+
Object.const_set(class_name, Class.new(&block))
|
56
37
|
else
|
57
|
-
|
58
|
-
class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.]+/, '_')}_#{source_descriptor(block)[1]}"
|
59
|
-
if !Object.const_defined?(class_name)
|
60
|
-
Object.const_set(class_name, Class.new(&block))
|
61
|
-
else
|
62
|
-
Object.const_get(class_name).class_eval(&block)
|
63
|
-
end
|
64
|
-
b = Java::android.os.Bundle.new
|
65
|
-
b.putInt("Theme", theme) if theme
|
66
|
-
b.putString("ClassName", class_name)
|
67
|
-
i = android.content.Intent.new
|
68
|
-
i.setClass self, klass.java_class
|
69
|
-
i.putExtra("RubotoActivity Config", b)
|
70
|
-
startActivity i
|
38
|
+
Object.const_get(class_name).class_eval(&block) if block_given?
|
71
39
|
end
|
40
|
+
b = Java::android.os.Bundle.new
|
41
|
+
b.putInt("Theme", theme) if theme
|
42
|
+
b.putString("ClassName", class_name)
|
43
|
+
i = android.content.Intent.new
|
44
|
+
i.setClass self, klass.java_class
|
45
|
+
i.putExtra("RubotoActivity Config", b)
|
46
|
+
startActivity i
|
72
47
|
self
|
73
48
|
end
|
74
49
|
|
@@ -110,6 +85,6 @@ def ruboto_configure_activity(klass)
|
|
110
85
|
end
|
111
86
|
|
112
87
|
java_import "android.app.Activity"
|
113
|
-
|
88
|
+
java_import "org.ruboto.RubotoActivity"
|
114
89
|
ruboto_configure_activity(RubotoActivity)
|
115
90
|
|
data/assets/src/ruboto/base.rb
CHANGED
@@ -6,15 +6,6 @@
|
|
6
6
|
#
|
7
7
|
#######################################################
|
8
8
|
|
9
|
-
# Only used needed for ruboto-core apps
|
10
|
-
require 'ruboto/version'
|
11
|
-
$RUBOTO_VERSION = 10
|
12
|
-
|
13
|
-
def confirm_ruboto_version(required_version, exact=true)
|
14
|
-
raise "requires $RUBOTO_VERSION=#{required_version} or greater, current version #{$RUBOTO_VERSION}" if $RUBOTO_VERSION < required_version and not exact
|
15
|
-
raise "requires $RUBOTO_VERSION=#{required_version}, current version #{$RUBOTO_VERSION}" if $RUBOTO_VERSION != required_version and exact
|
16
|
-
end
|
17
|
-
|
18
9
|
require 'java'
|
19
10
|
|
20
11
|
# Create convenience method for top-level android package so we do not need to prefix with 'Java::'.
|
@@ -32,64 +23,3 @@ end
|
|
32
23
|
|
33
24
|
java_import "android.R"
|
34
25
|
AndroidIds = JavaUtilities.get_proxy_class("android.R$id")
|
35
|
-
|
36
|
-
#
|
37
|
-
# Callbacks
|
38
|
-
#
|
39
|
-
|
40
|
-
module Ruboto
|
41
|
-
module CallbackClass
|
42
|
-
def new_with_callbacks(*args, &block)
|
43
|
-
new(*args).initialize_ruboto_callbacks(&block)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
module Callbacks
|
48
|
-
def initialize_ruboto_callbacks &block
|
49
|
-
instance_eval &block
|
50
|
-
setup_ruboto_callbacks
|
51
|
-
self
|
52
|
-
end
|
53
|
-
|
54
|
-
def ruboto_callback_methods
|
55
|
-
# FIXME(uwe): Remove to_sym conversion when we stop supporting Ruby 1.8 mode
|
56
|
-
(singleton_methods - ["on_create", "on_receive"]).select{|i| self.class.constants.map(&:to_sym).include?(i.to_s.sub(/^on_/, "CB_").upcase.to_sym) || self.class.constants.map(&:to_sym).include?("CB_#{i}".upcase.to_sym)}
|
57
|
-
end
|
58
|
-
|
59
|
-
def setup_ruboto_callbacks
|
60
|
-
ruboto_callback_methods.each do |i|
|
61
|
-
begin
|
62
|
-
# FIXME(uwe): Remove to_sym conversion when we stop supporting Ruby 1.8 mode
|
63
|
-
scriptInfo.setCallbackProc((self.class.constants.map(&:to_sym).include?(i.to_s.sub(/^on_/, "CB_").upcase.to_sym) && self.class.const_get(i.to_s.sub(/^on_/, "CB_").upcase)) || (self.class.constants.map(&:to_sym).include?("CB_#{i}".upcase.to_sym) && self.class.const_get("CB_#{i}".upcase)), method(i))
|
64
|
-
rescue
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Import a class and set it up for handlers
|
73
|
-
#
|
74
|
-
|
75
|
-
def ruboto_import(*package_classes)
|
76
|
-
already_classes = package_classes.select{|i| not i.is_a?(String) and not i.is_a?(Symbol)}
|
77
|
-
imported_classes = package_classes - already_classes
|
78
|
-
|
79
|
-
unless imported_classes.empty?
|
80
|
-
# TODO(uwe): The first part of this "if" is only needed for JRuby 1.6.x. Simplify when we stop supporting JRuby 1.6.x
|
81
|
-
if imported_classes.size == 1
|
82
|
-
imported_classes = [*(java_import(*imported_classes) || eval("Java::#{imported_classes[0]}"))]
|
83
|
-
else
|
84
|
-
imported_classes = java_import(imported_classes)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
(already_classes + imported_classes).each do |package_class|
|
89
|
-
package_class.class_eval do
|
90
|
-
extend Ruboto::CallbackClass
|
91
|
-
include Ruboto::Callbacks
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
@@ -2,33 +2,13 @@
|
|
2
2
|
#
|
3
3
|
# ruboto/broadcast_receiver.rb
|
4
4
|
#
|
5
|
-
# Basic broadcast_receiver set up
|
5
|
+
# Basic broadcast_receiver set up.
|
6
6
|
#
|
7
7
|
#######################################################
|
8
8
|
|
9
9
|
require 'ruboto/base'
|
10
10
|
|
11
|
-
|
12
|
-
RubotoBroadcastReceiver.class_eval do
|
13
|
-
def self.new_with_callbacks &block
|
14
|
-
(($broadcast_receiver.nil? || $broadcast_receiver.initialized) ? new : $broadcast_receiver).initialize_ruboto_callbacks &block
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialized
|
18
|
-
@initialized ||= false
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize_ruboto_callbacks &block
|
22
|
-
instance_eval &block
|
23
|
-
setup_ruboto_callbacks
|
24
|
-
@initialized = true
|
25
|
-
self
|
26
|
-
end
|
27
|
-
|
28
|
-
def on_receive(context, intent)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
11
|
+
java_import "org.ruboto.RubotoBroadcastReceiver"
|
32
12
|
module Ruboto
|
33
13
|
module BroadcastReceiver
|
34
14
|
end
|
@@ -10,14 +10,16 @@ require 'ruboto/activity'
|
|
10
10
|
|
11
11
|
java_import "android.preference.PreferenceScreen"
|
12
12
|
java_import "android.preference.Preference"
|
13
|
-
|
13
|
+
java_import "org.ruboto.RubotoPreferenceActivity"
|
14
14
|
ruboto_configure_activity(RubotoPreferenceActivity)
|
15
15
|
|
16
16
|
RubotoPreferenceActivity.class_eval do
|
17
17
|
def preference_screen(params={})
|
18
18
|
rv = self.getPreferenceManager.createPreferenceScreen(self)
|
19
|
+
parent = params.delete(:parent) || @parent
|
19
20
|
rv.configure self, params
|
20
|
-
|
21
|
+
parent.addPreference(rv) if parent
|
22
|
+
|
21
23
|
if block_given?
|
22
24
|
old_parent, @parent = @parent, rv
|
23
25
|
yield
|
@@ -54,8 +56,10 @@ def ruboto_import_preference(class_name, package_name="android.preference")
|
|
54
56
|
RubotoPreferenceActivity.class_eval "
|
55
57
|
def #{(class_name.to_s.gsub(/([A-Z])/) { '_' + $1.downcase })[1..-1]}(params={})
|
56
58
|
rv = #{class_name}.new self
|
59
|
+
parent = params.delete(:parent) || @parent
|
57
60
|
rv.configure self, params
|
58
|
-
|
61
|
+
parent.addPreference(rv) if parent
|
62
|
+
|
59
63
|
if block_given?
|
60
64
|
old_parent, @parent = @parent, rv
|
61
65
|
yield
|
@@ -5,71 +5,34 @@ require 'ruboto/package'
|
|
5
5
|
#
|
6
6
|
# ruboto/service.rb
|
7
7
|
#
|
8
|
-
# Basic service set up
|
8
|
+
# Basic service set up.
|
9
9
|
#
|
10
10
|
#######################################################
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
#
|
12
|
+
java_import "android.content.Context"
|
13
|
+
java_import "org.ruboto.RubotoService"
|
15
14
|
|
16
15
|
module Ruboto
|
17
16
|
module Context
|
18
|
-
def initialize_ruboto()
|
19
|
-
eval("#{$new_context_global} = self")
|
20
|
-
$new_context_global = nil
|
21
|
-
|
22
|
-
instance_eval &$context_init_block if $context_init_block
|
23
|
-
$context_init_block = nil
|
24
|
-
setup_ruboto_callbacks
|
25
|
-
|
26
|
-
@initialized = true
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
17
|
def start_ruboto_service(global_variable_name = '$service', klass=RubotoService, &block)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if @initialized or (self == $service) or ($service == nil) # FIx mix between activity and service
|
35
|
-
self.startService Java::android.content.Intent.new(self, klass.java_class)
|
18
|
+
class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
|
19
|
+
if !Object.const_defined?(class_name)
|
20
|
+
Object.const_set(class_name, Class.new(&block))
|
36
21
|
else
|
37
|
-
|
38
|
-
on_create
|
22
|
+
Object.const_get(class_name).class_eval(&block) if block_given?
|
39
23
|
end
|
40
|
-
|
24
|
+
b = Java::android.os.Bundle.new
|
25
|
+
b.putInt("Theme", theme) if theme
|
26
|
+
b.putString("ClassName", class_name)
|
27
|
+
i = android.content.Intent.new
|
28
|
+
i.setClass self, klass.java_class
|
29
|
+
i.putExtra("RubotoActivity Config", b)
|
30
|
+
self.startService Java::android.content.Intent.new(self, klass.java_class)
|
41
31
|
self
|
42
32
|
end
|
43
33
|
end
|
44
34
|
end
|
45
35
|
|
46
|
-
java_import "android.content.Context"
|
47
36
|
Context.class_eval do
|
48
37
|
include Ruboto::Context
|
49
38
|
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# Leave for legacy Service Subclass Setup
|
53
|
-
#
|
54
|
-
|
55
|
-
module Ruboto
|
56
|
-
module Service
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# Basic Service Setup
|
62
|
-
#
|
63
|
-
|
64
|
-
def ruboto_configure_service(klass)
|
65
|
-
klass.class_eval do
|
66
|
-
include Ruboto::Service
|
67
|
-
|
68
|
-
def on_create
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
ruboto_import "org.ruboto.RubotoService"
|
74
|
-
ruboto_configure_service(RubotoService)
|
75
|
-
|