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
@@ -0,0 +1,33 @@
1
+ class AsyncWrapper
2
+ def initialize
3
+ @native = Java::com.droiuby.client.core.async.AsyncWrapper.new(_execution_bundle)
4
+ end
5
+
6
+ def native
7
+ @native
8
+ end
9
+
10
+ def before(&block)
11
+ @native.setPre_execute(block)
12
+ self
13
+ end
14
+
15
+ def perform(&block)
16
+ @native.setBackground_task(block)
17
+ self
18
+ end
19
+
20
+ def done(&block)
21
+ @native.setPost_execute(block)
22
+ self
23
+ end
24
+
25
+ def execute
26
+ @native.execute(nil, nil, nil)
27
+ self
28
+ end
29
+
30
+ def start
31
+ execute
32
+ end
33
+ end
@@ -0,0 +1,2 @@
1
+ class ButtonWrapper < TextViewWrapper
2
+ end
@@ -0,0 +1,147 @@
1
+
2
+ class Rect
3
+ def initialize(rect = nil, left = 0, top = 0, right = 0, bottom = 0)
4
+ if (rect.nil?)
5
+ @native = Java::android.graphics.Rect.new(left, top, right, bottom)
6
+ else
7
+ @native = rect
8
+ end
9
+
10
+ end
11
+
12
+ def native
13
+ @native
14
+ end
15
+
16
+ def height
17
+ @native.height
18
+ end
19
+
20
+ def width
21
+ @native.width
22
+ end
23
+
24
+ def set(left, top, right, bottom)
25
+ @native.set(left, top, right, bottom)
26
+ end
27
+ end
28
+
29
+ def _rect(left = 0, top = 0, right = 0, bottom = 0)
30
+ Rect.new(nil, left, top, right, bottom)
31
+ end
32
+
33
+ class Paint
34
+ def initialize
35
+ @native = Java::android.graphics.Paint.new
36
+ end
37
+
38
+ def native
39
+ @native
40
+ end
41
+
42
+ def alpha=(value)
43
+ @native.setAlpha(Java::android.graphics.Color.parseColor(value))
44
+ end
45
+
46
+ def alpha
47
+ @native.getAlpha
48
+ end
49
+
50
+ def color=(value)
51
+ if (value.kind_of String)
52
+ value = value.to_color
53
+ end
54
+ @native.setColor(value)
55
+ end
56
+
57
+ def color
58
+ @native.getColor
59
+ end
60
+
61
+ def stroke_width=(width)
62
+ @native.setStrokeWidth(width)
63
+ end
64
+
65
+ def stroke_width
66
+ @native.getStrokeWidth
67
+ end
68
+ end
69
+
70
+ class Canvas
71
+
72
+ include JavaMethodHelper
73
+ include Droiuby::ViewHelper
74
+
75
+ java_fast_reader Java::android.graphics.Canvas, :width
76
+ java_fast_reader Java::android.graphics.Canvas, :height
77
+
78
+ java_native_method Java::android.graphics.Canvas, :drawColor, [Java::int]
79
+ java_native_method Java::android.graphics.Canvas, :drawText, [Java::java.lang.String, Java::float, Java::float, Java::android.graphics.Paint]
80
+ java_native_method Java::android.graphics.Canvas, :drawBitmap, [Java::android.graphics.Bitmap, Java::float, Java::float, Java::android.graphics.Paint]
81
+ java_native_method Java::android.graphics.Canvas, :drawCircle, [Java::float, Java::float, Java::float, Java::android.graphics.Paint]
82
+ java_native_method Java::android.graphics.Canvas, :drawLine, [Java::float, Java::float, Java::float, Java::float, Java::android.graphics.Paint]
83
+ java_native_method Java::android.graphics.Canvas, :drawRoundRect, [Java::android.graphics.RectF, Java::float, Java::float, Java::android.graphics.Paint]
84
+
85
+ def initialize(native)
86
+ @native = native
87
+ @paint = make_paint
88
+ end
89
+
90
+ def native
91
+ @native
92
+ end
93
+
94
+ def make_paint
95
+ Paint.new
96
+ end
97
+
98
+ def make_rect(left, top, right, bottom)
99
+ Java::android.graphics.RectF.new(left, top, right, bottom)
100
+ end
101
+
102
+ def paint
103
+ @paint
104
+ end
105
+
106
+ def paint=(p)
107
+ @paint = p
108
+ end
109
+
110
+ def draw_color(value)
111
+ if (value.kind_of? String)
112
+ value = value.to_color
113
+ end
114
+
115
+ java_drawColor(value)
116
+ end
117
+
118
+ def text(msg, x, y, paint = nil)
119
+ paint = @paint if paint.nil?
120
+
121
+ java_drawText(msg, x, y, paint.native);
122
+ end
123
+
124
+ def circle(x, y, size, paint = nil)
125
+ paint = @paint if paint.nil?
126
+ java_drawCircle(x, y, size, paint.native);
127
+ end
128
+
129
+ def line(x, y, x1, y1, paint = nil)
130
+ paint = @paint if paint.nil?
131
+ java_drawLine(x, y, x1, y1, paint.native);
132
+ end
133
+
134
+ def bitmap(bitmap, x, y, paint = nil, options = {})
135
+ paint = @paint if paint.nil?
136
+ if bitmap.class == BitmapDrawableWrapper
137
+ bitmap = bitmap.to_bitmap
138
+ end
139
+ # native.drawBitmap(bitmap, x.to_f, y.to_f, paint.native)
140
+ java_drawBitmap(bitmap, x.to_f, y.to_f, paint.native)
141
+ end
142
+
143
+ def round_rect(rect, x, y, paint = nil)
144
+ paint = @paint if paint.nil?
145
+ java_drawRoundRect(rect, x, y, paint.native)
146
+ end
147
+ end
@@ -0,0 +1,21 @@
1
+ class ViewArray
2
+
3
+ def initialize(elements = [])
4
+ @elements = elements
5
+ end
6
+
7
+ def method_missing(meth, *args, &block)
8
+ @elements.send(meth, *args, &block)
9
+ end
10
+
11
+ def on(symbol, &block)
12
+ @elements.each { |elem|
13
+ elem.on(symbol, &block)
14
+ }
15
+ end
16
+
17
+ def to_a
18
+ @elements
19
+ end
20
+
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'droiuby/wrappers/view_wrapper'
2
+
3
+ class CompoundButtonWrapper < ViewWrapper
4
+
5
+
6
+ def on(event,&block)
7
+ listener_ref = event.to_s.camelize
8
+ case event.to_sym
9
+ when :checked_change
10
+ self.native.send(:"setOn#{listener_ref}Listener",_listener("On#{listener_ref}Listener", 'android.widget.CompoundButton', &block))
11
+ else
12
+ super(event, &block)
13
+ end
14
+ end
15
+
16
+ def checked?
17
+ self.native.isChecked
18
+ end
19
+
20
+ def checked=(value)
21
+ self.native.setChecked(value)
22
+ end
23
+
24
+
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'droiuby/wrappers/view_wrapper'
2
+
3
+ class EditTextWrapper < TextViewWrapper
4
+
5
+ java_attr_accessor :hint
6
+
7
+ def text=(text)
8
+ @view.setText(text)
9
+ end
10
+
11
+ def text
12
+ @view.getText.toString
13
+ end
14
+
15
+ def color=(value)
16
+ @view.setTextColor(value)
17
+ end
18
+
19
+ def color
20
+ @view.getTextColors.getDefaultColor
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ class ImageButtonWrapper < ViewWrapper
2
+ def image
3
+ end
4
+
5
+ def image=(src)
6
+ end
7
+
8
+ end
@@ -0,0 +1,24 @@
1
+ require 'droiuby/wrappers/java_helpers/view_helper'
2
+
3
+ class IntentWrapper
4
+
5
+ include Droiuby::ViewHelper
6
+
7
+ java_attr_reader :action
8
+
9
+ def initialize(intent)
10
+ if (intent.nil?)
11
+ @native = Java::android.content.Intent.new
12
+ else
13
+ @native = intent
14
+ end
15
+ end
16
+
17
+ def get_string_extra(name)
18
+ @native.getStringExtra(name)
19
+ end
20
+
21
+ def native
22
+ @native
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ #speed up java native calls by binding the methods
2
+ module JavaMethodHelper
3
+
4
+ def self.included(klass)
5
+ klass.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def java_native_singleton_on(object, java_klass, method_sym, params = [])
11
+ unbound_method = java_klass.java_method(method_sym, params)
12
+ define_singleton_method "java_#{method_sym.to_s}".to_sym do |*args|
13
+ unbound_method.bind(object).call(*args)
14
+ end
15
+ end
16
+
17
+ def java_native_method_on(object, java_klass, method_sym, params = [], method_name = nil)
18
+ unbound_method = java_klass.java_method(method_sym, params)
19
+ method_name = "java_#{method_sym.to_s}" if method_name.nil?
20
+ define_method method_name.to_sym do |*args|
21
+ unbound_method.bind(object).call(*args)
22
+ end
23
+ end
24
+
25
+
26
+ def java_native_method(java_klass, method_sym, params = [], method_name = nil)
27
+ unbound_method = java_klass.java_method(method_sym, params)
28
+ method_name = "java_#{method_sym.to_s}" if method_name.nil?
29
+ define_method method_name.to_sym do |*args|
30
+ unbound_method.bind(self.native).call(*args)
31
+ end
32
+ end
33
+
34
+ def java_native_singleton(java_klass, method_sym, params = [])
35
+ unbound_method = java_klass.java_method(method_sym, params)
36
+ define_singleton_method "java_#{method_sym.to_s}".to_sym do |*args|
37
+ unbound_method.call(*args)
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,84 @@
1
+ #convenience methods to help droiuby deal with ruby-to-java calls
2
+ module Droiuby
3
+ module ViewHelper
4
+
5
+ def self.included(klass)
6
+ klass.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ def java_fast_reader(java_klass, *symbols)
12
+ symbols.each do |s|
13
+ java_getter_method = "get#{s.to_s.camelize}".to_sym
14
+
15
+ unbound_getter_method = java_klass.java_method(java_getter_method, [])
16
+
17
+ define_method(s) do
18
+ unbound_getter_method.bind(self.native).call
19
+ end
20
+ end
21
+ end
22
+
23
+ def java_fast_accessor(java_klass, params = [], *symbols)
24
+ symbols.each do |s|
25
+ java_getter_method = "get#{s.to_s.camelize}".to_sym
26
+ java_setter_method = "set#{s.to_s.camelize}".to_sym
27
+
28
+ unbound_getter_method = java_klass.java_method(java_getter_method, [])
29
+ unbound_setter_method = java_klass.java_method(java_setter_method, params)
30
+
31
+ define_method(s) do
32
+ unbound_getter_method.bind(self.native).call
33
+ end
34
+
35
+ define_method("#{s}=".to_sym) do |arg|
36
+ unbound_setter_method.bind(self.native).call(arg)
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ def java_attr_reader(*symbols)
43
+ symbols.each do |s|
44
+ java_getter_method = "get#{s.to_s.camelize}".to_sym
45
+ define_method(s) do
46
+ native.send(java_getter_method)
47
+ end
48
+ end
49
+ end
50
+
51
+ def java_attr_writer(*symbols)
52
+ symbols.each do |s|
53
+ java_setter_method = "set#{s.to_s.camelize}".to_sym
54
+ define_method("#{s}=".to_sym) do |value|
55
+ native.send(java_setter_method, value)
56
+ end
57
+ end
58
+ end
59
+
60
+ def java_attr_boolean_reader(*symbols)
61
+ symbols.each do |s|
62
+ java_getter_method = "is#{s.to_s.camelize}".to_sym
63
+ define_method(s) do
64
+ native.send(java_getter_method)
65
+ end
66
+ end
67
+ end
68
+
69
+ def java_attr_accessor(*symbols)
70
+ symbols.each do |s|
71
+ java_setter_method = "set#{s.to_s.camelize}".to_sym
72
+ java_getter_method = "get#{s.to_s.camelize}".to_sym
73
+ define_method(s) do
74
+ native.send(java_getter_method)
75
+ end
76
+ define_method("#{s}=".to_sym) do |value|
77
+ native.send(java_setter_method,value)
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,15 @@
1
+ require 'droiuby/wrappers/view_wrapper'
2
+
3
+ class LinearLayoutWrapper < ViewGroupWrapper
4
+
5
+ java_attr_accessor :baseline_algined, :orientation
6
+
7
+ def initialize(view = nil)
8
+ if view.nil?
9
+ @view = Java::android.widget.LinearLayout.new(_current_activity)
10
+ else
11
+ super(view)
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,61 @@
1
+ class ListAdapterWrapper
2
+
3
+ def initialize
4
+ @native = Java::com.droiuby.wrappers.ListAdapterRubyWrapper.new(_execution_bundle, self)
5
+ end
6
+
7
+ def native
8
+ @native
9
+ end
10
+
11
+ def get_count(&block)
12
+ @native.setGetCountBody(block)
13
+ self
14
+ end
15
+
16
+ def get_item(&block)
17
+ @native.setGetItemBody(block)
18
+ self
19
+ end
20
+
21
+ def get_item_id(&block)
22
+ @native.setGetItemIdBody(block)
23
+ self
24
+ end
25
+
26
+ def get_item_view_type(&block)
27
+ @native.setGetItemViewTypeBody(block)
28
+ self
29
+ end
30
+
31
+ def get_view(&block)
32
+ @native.setGetViewBody(block)
33
+ self
34
+ end
35
+
36
+ def get_view_type_count(&block)
37
+ @native.setGetViewTypeCountBody(block)
38
+ self
39
+ end
40
+
41
+ def has_stable_id?(&block)
42
+ @native.setHasStableIdBody(block)
43
+ self
44
+ end
45
+
46
+ def is_empty?(&block)
47
+ @native.setIsEmptyBody(block)
48
+ self
49
+ end
50
+
51
+ def register_data_set_observer(&block)
52
+ @native.setRegisterDataSetObserverBody(block)
53
+ self
54
+ end
55
+
56
+ def unregister_data_set_observer(&block)
57
+ @native.unregisterDataSetObserver(block)
58
+ self
59
+ end
60
+
61
+ end