Top Level Namespace
Defined Under Namespace
Modules: Droiuby, JavaMethodHelper
Classes: Accelerometer, Activity, Animator, AnimatorListenerWrapper, Array, AssetHandler, AsyncWrapper, BitmapDrawableWrapper, ButtonWrapper, Canvas, CompoundButtonWrapper, DroiubyFramework, EditTextWrapper, Fixnum, Hash, ImageButtonWrapper, IntentWrapper, LinearLayoutWrapper, ListAdapterWrapper, ListViewWrapper, MotionEventsWrapper, Object, Paint, PayloadWrapper, Preferences, Project, Rect, RunnableWrapper, String, SurfaceHolderWrapper, SurfaceViewWrapper, TextViewWrapper, Thread, ThreadPoolWrapper, ViewArray, ViewGroupWrapper, ViewWrapper, WebViewWrapper
Instance Method Summary
collapse
-
#_active_bundles ⇒ Object
-
#_activity_builder ⇒ Object
-
#_container_payload ⇒ Object
-
#_current_activity ⇒ Object
-
#_current_app ⇒ Object
-
#_current_page ⇒ Object
-
#_current_page_url ⇒ Object
-
#_errors ⇒ Object
-
#_execution_bundle ⇒ Object
-
#_gc ⇒ Object
-
#_namespace ⇒ Object
-
#_nano_time ⇒ Object
-
#_P ⇒ Object
-
#_pool(&block) ⇒ Object
-
#_R(attr) ⇒ Object
-
#_rect(left = 0, top = 0, right = 0, bottom = 0) ⇒ Object
-
#_scripting_container ⇒ Object
-
#_sleep(delay = 0) ⇒ Object
-
#_switch(bundle) ⇒ Object
-
#_thread(&block) ⇒ Object
-
#_time ⇒ Object
-
#after_partial_setup(view_group) ⇒ Object
-
#after_view_setup ⇒ Object
-
#Android ⇒ Object
-
#async ⇒ Object
-
#async_get(url, params = {}, options = {}, &block) ⇒ Object
-
#canvas(&block) ⇒ Object
-
#http_get(url, params = {}, options = {}) ⇒ Object
-
#launch(url) ⇒ Object
-
#log_debug(message = '', tag = 'ruby') ⇒ Object
-
#on_ui_thread(&block) ⇒ Object
-
#render(url, params = {}) ⇒ Object
-
#reverse_resolve(view_id) ⇒ Object
-
#set_content_view(view = nil) ⇒ Object
-
#start_droiuby_plugins ⇒ Object
-
#surface(&block) ⇒ Object
-
#toast(text = '', duration = :short) ⇒ Object
-
#V(selectors = nil) ⇒ Object
-
#wrap_native(object) ⇒ Object
-
#wrap_native_view(view) ⇒ Object
#java_native_method, #java_native_method_on, #java_native_singleton, #java_native_singleton_on
Instance Method Details
#_active_bundles ⇒ Object
51
52
53
|
# File 'lib/droiuby/bootstrap.rb', line 51
def _active_bundles
Java::com.droiuby.client.core.ExecutionBundleFactory.listActiveBundles.collect { |i| i.to_s }
end
|
#_activity_builder ⇒ Object
39
40
41
|
# File 'lib/droiuby/bootstrap.rb', line 39
def _activity_builder
PayloadWrapper.java_getActivityBuilder
end
|
#_container_payload ⇒ Object
15
16
17
|
# File 'lib/droiuby/bootstrap.rb', line 15
def _container_payload
$container_payload
end
|
#_current_activity ⇒ Object
35
36
37
|
# File 'lib/droiuby/bootstrap.rb', line 35
def _current_activity
PayloadWrapper.java_getCurrentActivity
end
|
#_current_app ⇒ Object
27
28
29
|
# File 'lib/droiuby/bootstrap.rb', line 27
def _current_app
PayloadWrapper.java_getActiveApp
end
|
#_current_page ⇒ Object
19
20
21
|
# File 'lib/droiuby/bootstrap.rb', line 19
def _current_page
PayloadWrapper.java_getCurrentPage
end
|
#_current_page_url ⇒ Object
43
44
45
|
# File 'lib/droiuby/bootstrap.rb', line 43
def _current_page_url
_execution_bundle.getCurrentUrl
end
|
55
56
57
|
# File 'lib/droiuby/bootstrap.rb', line 55
def _errors
_execution_bundle.getScriptErrors.collect { |i| i.to_s }
end
|
#_execution_bundle ⇒ Object
31
32
33
|
# File 'lib/droiuby/bootstrap.rb', line 31
def _execution_bundle
PayloadWrapper.java_getExecutionBundle
end
|
128
129
130
|
# File 'lib/droiuby/bootstrap.rb', line 128
def _gc
Droiuby::SystemWrapper.java_gc
end
|
#_namespace ⇒ Object
74
75
76
|
# File 'lib/droiuby/bootstrap.rb', line 74
def _namespace
_execution_bundle.getName
end
|
#_nano_time ⇒ Object
132
133
134
|
# File 'lib/droiuby/bootstrap.rb', line 132
def _nano_time
Droiuby::SystemWrapper.java_nanoTime
end
|
231
232
233
|
# File 'lib/droiuby/bootstrap.rb', line 231
def _P
Preferences.new(Java::com.droiuby.client.core.utils.Utils.getCurrentPreferences(_current_app, _current_activity))
end
|
#_pool(&block) ⇒ Object
148
149
150
151
152
|
# File 'lib/droiuby/bootstrap.rb', line 148
def _pool(&block)
thread_pool = ThreadPoolWrapper.new
block.call(thread_pool)
thread_pool.start
end
|
59
60
61
|
# File 'lib/droiuby/bootstrap.rb', line 59
def _R(attr)
Java::com.droiuby.client.core.builder.ActivityBuilder.resolveResource(_current_activity, attr)
end
|
#_rect(left = 0, top = 0, right = 0, bottom = 0) ⇒ Object
29
30
31
|
# File 'lib/droiuby/wrappers/canvas.rb', line 29
def _rect(left = 0, top = 0, right = 0, bottom = 0)
Rect.new(nil, left, top, right, bottom)
end
|
#_scripting_container ⇒ Object
23
24
25
|
# File 'lib/droiuby/bootstrap.rb', line 23
def _scripting_container
PayloadWrapper.java_getContainer
end
|
#_sleep(delay = 0) ⇒ Object
140
141
142
|
# File 'lib/droiuby/bootstrap.rb', line 140
def _sleep(delay = 0)
Droiuby::SystemWrapper.java_sleep(delay)
end
|
#_switch(bundle) ⇒ Object
63
64
65
66
67
|
# File 'lib/droiuby/bootstrap.rb', line 63
def _switch(bundle)
bundle = Java::com.droiuby.client.core.ExecutionBundleFactory.getBundle(bundle)
$container_payload = bundle.getPayload
true
end
|
#_thread(&block) ⇒ Object
144
145
146
|
# File 'lib/droiuby/bootstrap.rb', line 144
def _thread(&block)
Java::com.droiuby.client.core.wrappers.ThreadWrapper.new(block, _execution_bundle)
end
|
136
137
138
|
# File 'lib/droiuby/bootstrap.rb', line 136
def _time
Droiuby::SystemWrapper.java_currentTimeMillis
end
|
#after_partial_setup(view_group) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/droiuby/preload.rb', line 24
def after_partial_setup(view_group)
$droiuby_plugins.each do |plugin|
puts "plugin attach #{plugin.class.to_s}"
plugin.after_partial_setup(view_group)
end unless $droiuby_plugins.blank?
end
|
#after_view_setup ⇒ Object
17
18
19
20
21
22
|
# File 'lib/droiuby/preload.rb', line 17
def after_view_setup
$droiuby_plugins.each do |plugin|
puts "plugin attach #{plugin.class.to_s}"
plugin.after_view_setup
end unless $droiuby_plugins.blank?
end
|
207
208
209
|
# File 'lib/droiuby/bootstrap.rb', line 207
def Android
Droiuby::Android
end
|
235
236
237
|
# File 'lib/droiuby/bootstrap.rb', line 235
def async
AsyncWrapper.new
end
|
#async_get(url, params = {}, options = {}, &block) ⇒ Object
239
240
241
242
243
244
245
|
# File 'lib/droiuby/bootstrap.rb', line 239
def async_get(url, params = {}, options ={}, &block)
async.perform {
http_get(url, params, options)
}.done { |result|
block.call result
}
end
|
#canvas(&block) ⇒ Object
202
203
204
205
|
# File 'lib/droiuby/bootstrap.rb', line 202
def canvas(&block)
auto_wrap_block = Proc.new { |v| block.call(Canvas.new(v))}
wrap_native_view(Java::com.droiuby.client.core.wrappers.ViewWrapper.new(auto_wrap_block, _execution_bundle))
end
|
#http_get(url, params = {}, options = {}) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/droiuby/bootstrap.rb', line 247
def http_get(url, params = {}, options = {})
encoded_params = []
params.each do |k,v|
encoded_params << "#{k.to_s}=#{CGI::escape(v.to_s)}"
end
url_string = url
if encoded_params.size > 0
url_string = "#{url}?#{encoded_params.join('&')}"
end
Java::com.droiuby.client.core.utils.Utils.load(_current_activity, url_string, _execution_bundle);
end
|
#launch(url) ⇒ Object
78
79
80
|
# File 'lib/droiuby/bootstrap.rb', line 78
def launch(url)
Java::com.droiuby.client.core.DroiubyLauncher.launch(_current_activity, url)
end
|
#log_debug(message = '', tag = 'ruby') ⇒ Object
110
111
112
113
|
# File 'lib/droiuby/bootstrap.rb', line 110
def log_debug(message = '', tag = 'ruby')
Droiuby::SystemWrapper.java_d(tag.to_s, message.to_s)
nil
end
|
#on_ui_thread(&block) ⇒ Object
69
70
71
72
|
# File 'lib/droiuby/bootstrap.rb', line 69
def on_ui_thread(&block)
_current_activity.runOnUiThread(RunnableWrapper.new(block).to_native);
nil
end
|
#render(url, params = {}) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/droiuby/bootstrap.rb', line 88
def render(url, params = {})
http_method = Java::com.droiuby.client.core.utils.Utils::HTTP_GET
if params[:method] && (params[:method] == :post)
http_method = Java::com.droiuby.client.core.utils.Utils::HTTP_POST
end
new_activity = params[:activity] ? true : false;
async.perform {
Java::com.droiuby.client.core.DroiubyLauncher.loadPage(_current_activity, _execution_bundle, url, http_method)
}.done { |result|
if new_activity
Java::com.droiuby.client.core.DroiubyLauncher.startNewActivity(_current_activity, result)
else
Java::com.droiuby.client.core.DroiubyLauncher.runController(_current_activity, _execution_bundle, page)
after_view_setup
end
}
end
|
#reverse_resolve(view_id) ⇒ Object
47
48
49
|
# File 'lib/droiuby/bootstrap.rb', line 47
def reverse_resolve(view_id)
_activity_builder.reverseLookupId(view_id)
end
|
#set_content_view(view = nil) ⇒ Object
82
83
84
85
86
|
# File 'lib/droiuby/bootstrap.rb', line 82
def set_content_view(view = nil)
if view.nil?
Java::com.droiuby.client.core.DroiubyLauncher.setPage(_current_activity, _execution_bundle, _current_page)
end
end
|
#start_droiuby_plugins ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/droiuby/preload.rb', line 2
def start_droiuby_plugins
puts "starting plugins"
$droiuby_plugins = []
puts "loading plugins"
Droiuby::Plugins.descendants.each { |klass|
puts "plugin -> #{klass.to_s}"
$droiuby_plugins << klass.new
}
$droiuby_plugins.each do |plugin|
puts "plugin attach #{plugin.class.to_s}"
plugin.after_bootstrap
end unless $droiuby_plugins.blank?
end
|
#surface(&block) ⇒ Object
196
197
198
199
200
|
# File 'lib/droiuby/bootstrap.rb', line 196
def surface(&block)
s = SurfaceViewWrapper.new
block.call(s)
s
end
|
#toast(text = '', duration = :short) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/droiuby/bootstrap.rb', line 115
def toast(text = '', duration = :short)
j_duration = Java::android.widget.Toast::LENGTH_SHORT
j_duration = case(duration)
when :short
Java::android.widget.Toast::LENGTH_SHORT
when :long
Java::android.widget.Toast::LENGTH_LONG
end
Java::android.widget.Toast.makeText(_current_activity, text, j_duration).show();
end
|
#V(selectors = nil) ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/droiuby/bootstrap.rb', line 211
def V(selectors = nil)
if selectors.nil?
view = _activity_builder.getRootView
elsif (selectors == 'top')
view = _activity_builder.getTopView
else
view = _activity_builder.findViewByName(selectors)
end
if (view.kind_of? Java::java.util.ArrayList)
wrapped_views = view.toArray.to_a.collect do |element|
wrap_native_view(element)
end
ViewArray.new(wrapped_views)
else
wrap_native_view(view) if view
end
end
|
#wrap_native(object) ⇒ Object
190
191
192
193
194
|
# File 'lib/droiuby/bootstrap.rb', line 190
def wrap_native(object)
if (object.class == Java::android.content.Intent)
return IntentWrapper.new(object)
end
end
|
#wrap_native_view(view) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/droiuby/bootstrap.rb', line 154
def wrap_native_view(view)
return nil unless view
wrapped = if (view.class < Java::android.view.View)
if (view.class == Java::android.widget.Button)
ButtonWrapper.new(view)
elsif (view.class == Java::android.widget.TextView)
TextViewWrapper.new(view)
elsif (view.class == Java::android.widget.EditText)
EditTextWrapper.new(view)
elsif (view.class == Java::android.widget.LinearLayout)
LinearLayoutWrapper.new(view)
elsif (view.class == Java::android.webkit.WebView)
WebViewWrapper.new(view)
elsif (view.class == Java::android.widget.ListView)
ListViewWrapper.new(view)
elsif (view.class < Java::android.view.ViewGroup)
ViewGroupWrapper.new(view)
elsif (view.class < Java::android.widget.CompoundButton)
CompoundButtonWrapper.new(view)
elsif (view.class < Java::com.droiuby.client.core.wrappers.SurfaceViewWrapper)
SurfaceViewWrapper.new(view)
elsif (view.class < Java::android.view.View)
ViewWrapper.new(view)
else
view
end
elsif (view.class == Java::android.view.MotionEvent)
MotionEventsWrapper.new(view)
else
view
end
wrapped
end
|