droiuby 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/lib/droiuby.rb +1 -1
  3. data/lib/droiuby/android.rb +59 -0
  4. data/lib/droiuby/application.rb +30 -0
  5. data/lib/droiuby/bootstrap.rb +263 -0
  6. data/lib/droiuby/droiuby.rb +47 -0
  7. data/lib/droiuby/loader.rb +36 -0
  8. data/lib/droiuby/plugins/plugins.rb +25 -0
  9. data/lib/droiuby/preload.rb +29 -0
  10. data/lib/droiuby/{project.rb → scripts/project.rb} +15 -6
  11. data/lib/droiuby/scripts/templates/ruby/Gemfile.erb +3 -0
  12. data/lib/droiuby/{templates → scripts/templates}/ruby/application.css.erb +0 -0
  13. data/lib/droiuby/{templates → scripts/templates}/ruby/config.droiuby.erb +0 -0
  14. data/lib/droiuby/{templates → scripts/templates}/ruby/gitignore.erb +0 -0
  15. data/lib/droiuby/{templates → scripts/templates}/ruby/index.rb.erb +0 -0
  16. data/lib/droiuby/{templates → scripts/templates}/ruby/index.xml.erb +0 -0
  17. data/lib/droiuby/support/asset.rb +47 -0
  18. data/lib/droiuby/support/autoload.rb +22 -0
  19. data/lib/droiuby/support/fixnum.rb +11 -0
  20. data/lib/droiuby/support/object.rb +11 -0
  21. data/lib/droiuby/support/string.rb +38 -0
  22. data/lib/droiuby/support/system.rb +14 -0
  23. data/lib/droiuby/support/thread.rb +17 -0
  24. data/lib/droiuby/support/to_query.rb +28 -0
  25. data/lib/droiuby/support/utils.rb +10 -0
  26. data/lib/droiuby/wrappers/accelerometer.rb +17 -0
  27. data/lib/droiuby/wrappers/activity.rb +64 -0
  28. data/lib/droiuby/wrappers/animation.rb +141 -0
  29. data/lib/droiuby/wrappers/async.rb +33 -0
  30. data/lib/droiuby/wrappers/button.rb +2 -0
  31. data/lib/droiuby/wrappers/canvas.rb +147 -0
  32. data/lib/droiuby/wrappers/collection/view_array.rb +21 -0
  33. data/lib/droiuby/wrappers/compound_button_wrapper.rb +25 -0
  34. data/lib/droiuby/wrappers/edit_text.rb +22 -0
  35. data/lib/droiuby/wrappers/image_button.rb +8 -0
  36. data/lib/droiuby/wrappers/intent.rb +24 -0
  37. data/lib/droiuby/wrappers/java_helpers/java_method_helper.rb +42 -0
  38. data/lib/droiuby/wrappers/java_helpers/view_helper.rb +84 -0
  39. data/lib/droiuby/wrappers/linear_layout.rb +15 -0
  40. data/lib/droiuby/wrappers/list_adapter_wrapper.rb +61 -0
  41. data/lib/droiuby/wrappers/list_view.rb +10 -0
  42. data/lib/droiuby/wrappers/listeners/auto_wrap.rb +72 -0
  43. data/lib/droiuby/wrappers/listeners/on_click_listener.rb +21 -0
  44. data/lib/droiuby/wrappers/listeners/on_web_console_ready_listener.rb +23 -0
  45. data/lib/droiuby/wrappers/motion_events.rb +34 -0
  46. data/lib/droiuby/wrappers/preferences.rb +59 -0
  47. data/lib/droiuby/wrappers/proxy_builder/interface_builder.rb +25 -0
  48. data/lib/droiuby/wrappers/runnable_wrapper.rb +16 -0
  49. data/lib/droiuby/wrappers/surface_view_wrapper.rb +59 -0
  50. data/lib/droiuby/wrappers/text_view.rb +28 -0
  51. data/lib/droiuby/wrappers/thread_pool.rb +18 -0
  52. data/lib/droiuby/wrappers/view_group_wrapper.rb +87 -0
  53. data/lib/droiuby/wrappers/view_wrapper.rb +221 -0
  54. data/lib/droiuby/wrappers/web_view.rb +16 -0
  55. data/lib/droiuby/wrappers/wrappers.rb +5 -0
  56. metadata +77 -51
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 108871acdcd1b66a9b5053135da790d76c5f455f
4
+ data.tar.gz: 9eea77086a4b774bad27968287208a3a284c53ec
5
+ SHA512:
6
+ metadata.gz: e513de3ca8fb4d523949b5a7eed566035660bc2be16df4edb4f311b1b3b7e14b5cce8be103eb46b8e0c0b5656e9ea669f99ceccf6c638b1b74e452925fe8d393
7
+ data.tar.gz: fd51d02e8959d9bebc29df6c4feb566e6577f9ddfedcde4ca40dcf8f87f30bbd6bd70e5b82382b0e30539e9f1c2d490d74422878b299f4faec1df20a45db87ec
data/lib/droiuby.rb CHANGED
@@ -1 +1 @@
1
- require 'droiuby/project'
1
+ require 'droiuby/scripts/project'
@@ -0,0 +1,59 @@
1
+ module Droiuby
2
+ class Android
3
+ class Otherwise
4
+
5
+ def initialize
6
+ end
7
+
8
+ def otherwise(&block)
9
+ @return_value = block.call
10
+ end
11
+
12
+ def value
13
+ @return_value
14
+ end
15
+ end
16
+
17
+ class DummyOtherwise
18
+
19
+ def initialize(return_value)
20
+ @return_value = return_value
21
+ end
22
+
23
+ def otherwise(&block)
24
+ @return_value
25
+ end
26
+
27
+ def value
28
+ @return_value
29
+ end
30
+ end
31
+
32
+ def self.when_api(verb, level, &block)
33
+ current_api_level = Java::android.os.Build::VERSION::SDK_INT
34
+ case verb
35
+ when :greater_than
36
+ if current_api_level > level
37
+ return DummyOtherwise.new(block.call)
38
+ end
39
+ when :less_than
40
+ if current_api_level < level
41
+ block.call
42
+ return DummyOtherwise.new(block.call)
43
+ end
44
+ when :at_least
45
+ if current_api_level >= level
46
+ block.call
47
+ return DummyOtherwise.new(block.call)
48
+ end
49
+ when :at_most
50
+ if current_api_level <= level
51
+ block.call
52
+ return DummyOtherwise.new(block.call)
53
+ end
54
+ end
55
+ return Otherwise.new
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,30 @@
1
+ #Droiuby app introspection class
2
+ module Droiuby
3
+ class Application
4
+ def self.assets
5
+ @active_app = @active_app || _current_app
6
+ assets = {}
7
+ @active_app.getAssets.each { |k,v|
8
+ assets[k] = v
9
+ }
10
+ assets
11
+ end
12
+
13
+ def self.name
14
+ @active_app = @active_app || _current_app
15
+ @active_app.getName
16
+ end
17
+
18
+ def self.base_url
19
+ @active_app = @active_app || _current_app
20
+ @active_app.getBaseUrl
21
+ end
22
+
23
+
24
+ def self.main_url
25
+ @active_app = @active_app || _current_app
26
+ @active_app.getMainUrl
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,263 @@
1
+ puts 'initializing bootstrap'
2
+
3
+ include JavaMethodHelper::ClassMethods
4
+
5
+ class PayloadWrapper
6
+ [:getContainer, :getActiveApp, :getExecutionBundle, :getActivityBuilder, :getCurrentPage].each do |method|
7
+ java_native_singleton_on($container_payload, Java::com.droiuby.client.core.RubyContainerPayload, method, [])
8
+ end
9
+
10
+ java_native_singleton_on($container_payload.getExecutionBundle, Java::com.droiuby.client.core.ExecutionBundle,
11
+ :getCurrentActivity, [])
12
+
13
+ end
14
+
15
+ def _container_payload
16
+ $container_payload
17
+ end
18
+
19
+ def _current_page
20
+ PayloadWrapper.java_getCurrentPage
21
+ end
22
+
23
+ def _scripting_container
24
+ PayloadWrapper.java_getContainer
25
+ end
26
+
27
+ def _current_app
28
+ PayloadWrapper.java_getActiveApp
29
+ end
30
+
31
+ def _execution_bundle
32
+ PayloadWrapper.java_getExecutionBundle
33
+ end
34
+
35
+ def _current_activity
36
+ PayloadWrapper.java_getCurrentActivity
37
+ end
38
+
39
+ def _activity_builder
40
+ PayloadWrapper.java_getActivityBuilder
41
+ end
42
+
43
+ def _current_page_url
44
+ _execution_bundle.getCurrentUrl
45
+ end
46
+
47
+ def reverse_resolve(view_id)
48
+ _activity_builder.reverseLookupId(view_id)
49
+ end
50
+
51
+ def _active_bundles
52
+ Java::com.droiuby.client.core.ExecutionBundleFactory.listActiveBundles.collect { |i| i.to_s }
53
+ end
54
+
55
+ def _errors
56
+ _execution_bundle.getScriptErrors.collect { |i| i.to_s }
57
+ end
58
+
59
+ def _R(attr)
60
+ Java::com.droiuby.client.core.builder.ActivityBuilder.resolveResource(_current_activity, attr)
61
+ end
62
+
63
+ def _switch(bundle)
64
+ bundle = Java::com.droiuby.client.core.ExecutionBundleFactory.getBundle(bundle)
65
+ $container_payload = bundle.getPayload
66
+ true
67
+ end
68
+
69
+ def on_ui_thread(&block)
70
+ _current_activity.runOnUiThread(RunnableWrapper.new(block).to_native);
71
+ nil
72
+ end
73
+
74
+ def _namespace
75
+ _execution_bundle.getName
76
+ end
77
+
78
+ def launch(url)
79
+ Java::com.droiuby.client.core.DroiubyLauncher.launch(_current_activity, url)
80
+ end
81
+
82
+ def set_content_view(view = nil)
83
+ if view.nil?
84
+ Java::com.droiuby.client.core.DroiubyLauncher.setPage(_current_activity, _execution_bundle, _current_page)
85
+ end
86
+ end
87
+
88
+ def render(url, params = {})
89
+ http_method = Java::com.droiuby.client.core.utils.Utils::HTTP_GET
90
+ if params[:method] && (params[:method] == :post)
91
+ http_method = Java::com.droiuby.client.core.utils.Utils::HTTP_POST
92
+ end
93
+
94
+ new_activity = params[:activity] ? true : false;
95
+
96
+ async.perform {
97
+ Java::com.droiuby.client.core.DroiubyLauncher.loadPage(_current_activity, _execution_bundle, url, http_method)
98
+ }.done { |result|
99
+ if new_activity
100
+ Java::com.droiuby.client.core.DroiubyLauncher.startNewActivity(_current_activity, result)
101
+ else
102
+ Java::com.droiuby.client.core.DroiubyLauncher.runController(_current_activity, _execution_bundle, page)
103
+ #execute plugins
104
+ after_view_setup
105
+ end
106
+ }
107
+
108
+ end
109
+
110
+ def log_debug(message = '', tag = 'ruby')
111
+ Droiuby::SystemWrapper.java_d(tag.to_s, message.to_s)
112
+ nil
113
+ end
114
+
115
+ def toast(text = '', duration = :short)
116
+ j_duration = Java::android.widget.Toast::LENGTH_SHORT
117
+
118
+ j_duration = case(duration)
119
+ when :short
120
+ Java::android.widget.Toast::LENGTH_SHORT
121
+ when :long
122
+ Java::android.widget.Toast::LENGTH_LONG
123
+ end
124
+
125
+ Java::android.widget.Toast.makeText(_current_activity, text, j_duration).show();
126
+ end
127
+
128
+ def _gc
129
+ Droiuby::SystemWrapper.java_gc
130
+ end
131
+
132
+ def _nano_time
133
+ Droiuby::SystemWrapper.java_nanoTime
134
+ end
135
+
136
+ def _time
137
+ Droiuby::SystemWrapper.java_currentTimeMillis
138
+ end
139
+
140
+ def _sleep(delay = 0)
141
+ Droiuby::SystemWrapper.java_sleep(delay)
142
+ end
143
+
144
+ def _thread(&block)
145
+ Java::com.droiuby.client.core.wrappers.ThreadWrapper.new(block, _execution_bundle)
146
+ end
147
+
148
+ def _pool(&block)
149
+ thread_pool = ThreadPoolWrapper.new
150
+ block.call(thread_pool)
151
+ thread_pool.start
152
+ end
153
+
154
+ def wrap_native_view(view)
155
+ return nil unless view
156
+
157
+ wrapped = if (view.class < Java::android.view.View)
158
+ if (view.class == Java::android.widget.Button)
159
+ ButtonWrapper.new(view)
160
+ elsif (view.class == Java::android.widget.TextView)
161
+ TextViewWrapper.new(view)
162
+ elsif (view.class == Java::android.widget.EditText)
163
+ EditTextWrapper.new(view)
164
+ elsif (view.class == Java::android.widget.LinearLayout)
165
+ LinearLayoutWrapper.new(view)
166
+ elsif (view.class == Java::android.webkit.WebView)
167
+ WebViewWrapper.new(view)
168
+ elsif (view.class == Java::android.widget.ListView)
169
+ ListViewWrapper.new(view)
170
+ elsif (view.class < Java::android.view.ViewGroup)
171
+ ViewGroupWrapper.new(view)
172
+ elsif (view.class < Java::android.widget.CompoundButton)
173
+ CompoundButtonWrapper.new(view)
174
+ elsif (view.class < Java::com.droiuby.client.core.wrappers.SurfaceViewWrapper)
175
+ SurfaceViewWrapper.new(view)
176
+ elsif (view.class < Java::android.view.View)
177
+ ViewWrapper.new(view)
178
+ else
179
+ view
180
+ end
181
+ elsif (view.class == Java::android.view.MotionEvent)
182
+ MotionEventsWrapper.new(view)
183
+ else
184
+ view
185
+ end
186
+
187
+ wrapped
188
+ end
189
+
190
+ def wrap_native(object)
191
+ if (object.class == Java::android.content.Intent)
192
+ return IntentWrapper.new(object)
193
+ end
194
+ end
195
+
196
+ def surface(&block)
197
+ s = SurfaceViewWrapper.new
198
+ block.call(s)
199
+ s
200
+ end
201
+
202
+ def canvas(&block)
203
+ auto_wrap_block = Proc.new { |v| block.call(Canvas.new(v))}
204
+ wrap_native_view(Java::com.droiuby.client.core.wrappers.ViewWrapper.new(auto_wrap_block, _execution_bundle))
205
+ end
206
+
207
+ def Android
208
+ Droiuby::Android
209
+ end
210
+
211
+ def V(selectors = nil)
212
+ if selectors.nil? # Get root node if nil
213
+ view = _activity_builder.getRootView
214
+ elsif (selectors == 'top')
215
+ view = _activity_builder.getTopView
216
+ else
217
+ view = _activity_builder.findViewByName(selectors)
218
+ end
219
+
220
+ if (view.kind_of? Java::java.util.ArrayList)
221
+ wrapped_views = view.toArray.to_a.collect do |element|
222
+ wrap_native_view(element)
223
+ end
224
+ ViewArray.new(wrapped_views)
225
+ else
226
+ wrap_native_view(view) if view
227
+ end
228
+
229
+ end
230
+
231
+ def _P
232
+ Preferences.new(Java::com.droiuby.client.core.utils.Utils.getCurrentPreferences(_current_app, _current_activity))
233
+ end
234
+
235
+ def async
236
+ AsyncWrapper.new
237
+ end
238
+
239
+ def async_get(url, params = {}, options ={}, &block)
240
+ async.perform {
241
+ http_get(url, params, options)
242
+ }.done { |result|
243
+ block.call result
244
+ }
245
+ end
246
+
247
+ def http_get(url, params = {}, options = {})
248
+
249
+ encoded_params = []
250
+
251
+ params.each do |k,v|
252
+ encoded_params << "#{k.to_s}=#{CGI::escape(v.to_s)}"
253
+ end
254
+
255
+ url_string = url
256
+
257
+ if encoded_params.size > 0
258
+ url_string = "#{url}?#{encoded_params.join('&')}"
259
+ end
260
+
261
+ Java::com.droiuby.client.core.utils.Utils.load(_current_activity, url_string, _execution_bundle);
262
+ end
263
+
@@ -0,0 +1,47 @@
1
+ require 'droiuby/loader'
2
+
3
+ #Droiuby Framework class
4
+ class DroiubyFramework
5
+
6
+ def before_activity_setup
7
+ fname = "#{File.dirname(__FILE__)}/bootstrap.rb"
8
+ @bootstrap = @bootstrap || File.read(fname)
9
+ eval(@bootstrap, TOPLEVEL_BINDING, fname, __LINE__)
10
+ end
11
+
12
+ def preload
13
+ fname = "#{File.dirname(__FILE__)}/preload.rb"
14
+ @preload = @preload || File.read(fname)
15
+ eval(@preload, TOPLEVEL_BINDING, fname, __LINE__)
16
+ end
17
+
18
+ def on_click(view)
19
+ end
20
+
21
+ def script(controller)
22
+ klass = controller.camelize.constantize
23
+ instance = klass.new
24
+
25
+ skip_content_view = if instance.respond_to? :before_content_render
26
+ instance.before_content_render
27
+ end
28
+
29
+ set_content_view unless skip_content_view
30
+
31
+ instance.on_create
32
+ instance
33
+ end
34
+
35
+ def resolve_view(name, node)
36
+ klass = name.constantize
37
+ instance = klass.new
38
+ if instance < ViewWrapper
39
+ instance.native
40
+ else
41
+ instance
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ $framework = DroiubyFramework.new
@@ -0,0 +1,36 @@
1
+ require 'java'
2
+ require 'droiuby/support/utils'
3
+ require 'droiuby/support/fixnum'
4
+ require 'droiuby/wrappers/activity'
5
+ require 'droiuby/wrappers/collection/view_array'
6
+ require 'droiuby/wrappers/proxy_builder/interface_builder'
7
+ require 'droiuby/wrappers/listeners/auto_wrap'
8
+ require 'droiuby/wrappers/listeners/on_web_console_ready_listener'
9
+ require 'droiuby/support/string'
10
+ require 'droiuby/support/thread'
11
+ require 'droiuby/support/object'
12
+ require 'droiuby/support/autoload'
13
+ require 'droiuby/support/to_query'
14
+ require 'droiuby/support/asset'
15
+ require 'droiuby/wrappers/java_helpers/java_method_helper'
16
+ require 'droiuby/support/system'
17
+ require 'droiuby/wrappers/async'
18
+ require 'droiuby/wrappers/view_group_wrapper'
19
+ require 'droiuby/wrappers/linear_layout'
20
+ require 'droiuby/wrappers/text_view'
21
+ require 'droiuby/wrappers/button'
22
+ require 'droiuby/wrappers/edit_text'
23
+ require 'droiuby/wrappers/preferences'
24
+ require 'droiuby/wrappers/web_view'
25
+ require 'droiuby/wrappers/compound_button_wrapper'
26
+ require 'droiuby/wrappers/motion_events'
27
+ require 'droiuby/wrappers/intent'
28
+ require 'droiuby/wrappers/canvas'
29
+ require 'droiuby/wrappers/surface_view_wrapper'
30
+ require 'droiuby/wrappers/thread_pool'
31
+ require 'droiuby/wrappers/list_adapter_wrapper'
32
+ require 'droiuby/wrappers/accelerometer'
33
+ require 'droiuby/wrappers/runnable_wrapper'
34
+ require 'droiuby/plugins/plugins'
35
+ require 'droiuby/application'
36
+ require 'droiuby/android'