bluepotion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +10 -0
  3. data/lib/bluepotion.rb +16 -0
  4. data/lib/project/ext/activity.rb +62 -0
  5. data/lib/project/ext/array_list.rb +25 -0
  6. data/lib/project/ext/fragment.rb +2 -0
  7. data/lib/project/ext/object.rb +105 -0
  8. data/lib/project/ext/string.rb +23 -0
  9. data/lib/project/ext/view.rb +81 -0
  10. data/lib/project/potion.rb +50 -0
  11. data/lib/project/pro_motion/pm_activity.rb +38 -0
  12. data/lib/project/pro_motion/pm_application.rb +71 -0
  13. data/lib/project/pro_motion/pm_home_activity.rb +14 -0
  14. data/lib/project/pro_motion/pm_screen.rb +67 -0
  15. data/lib/project/pro_motion/pm_screen_module.rb +165 -0
  16. data/lib/project/pro_motion/pm_single_fragment_activity.rb +31 -0
  17. data/lib/project/ruby_motion_query/rmq/actions.rb +48 -0
  18. data/lib/project/ruby_motion_query/rmq/base.rb +260 -0
  19. data/lib/project/ruby_motion_query/rmq/data.rb +64 -0
  20. data/lib/project/ruby_motion_query/rmq/debug.rb +9 -0
  21. data/lib/project/ruby_motion_query/rmq/enumerablish.rb +99 -0
  22. data/lib/project/ruby_motion_query/rmq/events.rb +28 -0
  23. data/lib/project/ruby_motion_query/rmq/factory.rb +47 -0
  24. data/lib/project/ruby_motion_query/rmq/position.rb +2 -0
  25. data/lib/project/ruby_motion_query/rmq/selectors.rb +72 -0
  26. data/lib/project/ruby_motion_query/rmq/styles.rb +108 -0
  27. data/lib/project/ruby_motion_query/rmq/subviews.rb +95 -0
  28. data/lib/project/ruby_motion_query/rmq/tags.rb +58 -0
  29. data/lib/project/ruby_motion_query/rmq/traverse.rb +287 -0
  30. data/lib/project/ruby_motion_query/rmq/utils.rb +36 -0
  31. data/lib/project/ruby_motion_query/rmq/version.rb +6 -0
  32. data/lib/project/ruby_motion_query/rmq_activity_data.rb +3 -0
  33. data/lib/project/ruby_motion_query/rmq_app.rb +9 -0
  34. data/lib/project/ruby_motion_query/rmq_color.rb +121 -0
  35. data/lib/project/ruby_motion_query/rmq_device.rb +47 -0
  36. data/lib/project/ruby_motion_query/rmq_event.rb +1 -0
  37. data/lib/project/ruby_motion_query/rmq_font.rb +61 -0
  38. data/lib/project/ruby_motion_query/rmq_image.rb +55 -0
  39. data/lib/project/ruby_motion_query/rmq_rect.rb +576 -0
  40. data/lib/project/ruby_motion_query/rmq_screen_data.rb +3 -0
  41. data/lib/project/ruby_motion_query/rmq_stylesheet.rb +39 -0
  42. data/lib/project/ruby_motion_query/rmq_view_data.rb +88 -0
  43. data/lib/project/ruby_motion_query/stylers/rmq_button_styler.rb +3 -0
  44. data/lib/project/ruby_motion_query/stylers/rmq_image_button_styler.rb +3 -0
  45. data/lib/project/ruby_motion_query/stylers/rmq_image_view_styler.rb +24 -0
  46. data/lib/project/ruby_motion_query/stylers/rmq_linear_layout_styler.rb +32 -0
  47. data/lib/project/ruby_motion_query/stylers/rmq_relative_layout_styler.rb +7 -0
  48. data/lib/project/ruby_motion_query/stylers/rmq_styler_helper.rb +3 -0
  49. data/lib/project/ruby_motion_query/stylers/rmq_text_view_styler.rb +50 -0
  50. data/lib/project/ruby_motion_query/stylers/rmq_view_styler.rb +201 -0
  51. data/lib/project/version.rb +3 -0
  52. data/templates/screen/app/screens/name_screen.rb +20 -0
  53. data/templates/screen/app/stylesheets/name_screen_stylesheet.rb +24 -0
  54. data/templates/screen/spec/screens/name_screen_spec.rb +8 -0
  55. metadata +119 -0
@@ -0,0 +1,58 @@
1
+ class RMQ
2
+
3
+ # Add tags
4
+ # @example
5
+ # rmq(my_view).tag(:your_tag)
6
+ # rmq(my_view).clear_tags.tag(:your_new_tag)
7
+ # rmq(my_view).find(UILabel).tag(:selected, :customer)
8
+ #
9
+ # You can optionally store a value in the tag, which can be super useful in some rare situations
10
+ # @example
11
+ # rmq(my_view).tag(your_tag: 22)
12
+ # rmq(my_view).tag(your_tag: 22, your_other_tag: 'Hello world')
13
+ #
14
+ # @return [RMQ]
15
+ def tag(*tag_or_tags)
16
+ selected.each do |view|
17
+ view.rmq_data.tag(tag_or_tags)
18
+ end
19
+ self
20
+ end
21
+
22
+ def untag(*tag_or_tags)
23
+ selected.each do |view|
24
+ view.rmq_data.untag(tag_or_tags)
25
+ end
26
+ self
27
+ end
28
+
29
+ # @return [RMQ]
30
+ def clear_tags
31
+ selected.each do |view|
32
+ view.rmq_data.tags.clear
33
+ end
34
+ self
35
+ end
36
+
37
+ # Check if any of the selected has a given tag
38
+ # @example
39
+ # rmq(my_view).has_tag?(:your_tag) #false
40
+ # rmq(my_view).tag(:your_tag)
41
+ # rmq(my_view).has_tag?(:your_tag) #true
42
+ #
43
+ # @return [Boolean] true if any selection views have tag provided
44
+ def has_tag? tag
45
+ out = false
46
+ selected.each do |view|
47
+ if view.rmq_data.has_tag?(tag)
48
+ out = true # This is weird because of RM android bug
49
+ break
50
+ end
51
+ end
52
+
53
+ out
54
+ end
55
+ # See data.rb for the rest of the tag stuff
56
+
57
+ end
58
+
@@ -0,0 +1,287 @@
1
+ class RMQ
2
+ def activity
3
+ # TODO we can get the activity in better ways, and in more
4
+ # situations
5
+ if @originated_from.is_a?(PMScreen)
6
+ @originated_from.activity
7
+ elsif @originated_from.is_a?(Potion::Activity)
8
+ @originated_from
9
+ elsif @originated_from.is_a?(Potion::View)
10
+ if @originated_from.rmq_data
11
+ @originated_from.rmq_data.activity
12
+ else
13
+ RMQ.app.current_activity
14
+ end
15
+ else
16
+ RMQ.app.current_activity
17
+ end
18
+ end
19
+
20
+ def screen
21
+ # TODO we can get the screen in better ways, and in more
22
+ # situations
23
+ if @originated_from.is_a?(PMScreen)
24
+ @originated_from
25
+ elsif @originated_from.is_a?(Potion::View)
26
+ if @originated_from.rmq_data
27
+ @originated_from.rmq_data.screen
28
+ else
29
+ RMQ.app.current_screen
30
+ end
31
+ else
32
+ RMQ.app.current_screen
33
+ end
34
+ end
35
+
36
+ def controller
37
+ self.screen || self.activity
38
+ end
39
+
40
+ def root_view
41
+ if @originated_from.is_a?(Android::App::Activity)
42
+ @originated_from.root_view
43
+ else
44
+ self.controller.root_view
45
+ end
46
+ end
47
+
48
+ def filter(opts = {}, &block)
49
+ out = []
50
+ limit = opts[:limit]
51
+
52
+ selected.each do |view|
53
+ results = yield(view)
54
+ unless RMQ.is_blank?(results)
55
+ out << results
56
+ break if limit && (out.length >= limit)
57
+ end
58
+ end
59
+ out.flatten!
60
+ out = out.uniq if opts[:uniq]
61
+
62
+ if opts[:return_array]
63
+ out
64
+ else
65
+ RMQ.create_with_array_and_selectors(out, selectors, @originated_from, self)
66
+ end
67
+ end
68
+
69
+ def all
70
+ wrap(root_view).find
71
+ end
72
+
73
+ def children(*working_selectors)
74
+ normalize_selectors(working_selectors)
75
+
76
+ filter do |view|
77
+ sbvws = view.subviews
78
+
79
+ if RMQ.is_blank?(working_selectors)
80
+ sbvws
81
+ else
82
+ sbvws.inject([]) do |out, subview|
83
+ out << subview if match(subview, working_selectors)
84
+ out
85
+ end
86
+ end
87
+ end
88
+ end
89
+ alias :subviews :children
90
+
91
+ def find(*working_selectors)
92
+ normalize_selectors(working_selectors)
93
+
94
+ #if working_selectors.length == 1 && self.selected.length == 1 && working_selectors.first.is_a?(Java::Lang::Integer)
95
+ #return selected_first.findViewById(r(:id, working_selectors.first))
96
+ #end
97
+
98
+ filter(uniq: true) do |view|
99
+ sbvws = all_subviews_for(view)
100
+
101
+ if RMQ.is_blank?(working_selectors)
102
+ sbvws
103
+ else
104
+ sbvws.inject([]) do |out, subview|
105
+ out << subview if match(subview, working_selectors)
106
+ out
107
+ end
108
+ end
109
+ end # filter
110
+
111
+ end
112
+
113
+ # @return [RMQ] A new rmq instance reducing selected views to those that match selectors provided
114
+ #
115
+ # @param selectors your selector
116
+ #
117
+ # @example
118
+ # rmq(UIImage).and(:some_tag).attr(image: nil)
119
+ def and(*working_selectors)
120
+ return self unless working_selectors
121
+ normalize_selectors(working_selectors)
122
+
123
+ self.select do |view|
124
+ match(view, working_selectors)
125
+ end
126
+ end
127
+
128
+ # @return [RMQ] A new rmq instance removing selected views that match selectors provided
129
+ #
130
+ # @param selectors
131
+ #
132
+ # @example
133
+ # # Entire family of labels from siblings on down
134
+ # rmq(my_label).parent.find(UILabel).not(my_label).move(left: 10)
135
+ def not(*working_selectors)
136
+ return self unless working_selectors
137
+ normalize_selectors(working_selectors)
138
+
139
+ self.reject do |view|
140
+ match(view, working_selectors)
141
+ end
142
+ end
143
+
144
+ # @return [RMQ] A new rmq instance adding the context to the selected views
145
+ #
146
+ # @example
147
+ # rmq(my_view).children.and_self
148
+ def and_self
149
+ if self.parent_rmq
150
+ out = self.parent_rmq.selected.dup
151
+ out << selected
152
+ out.flatten!
153
+ RMQ.create_with_array_and_selectors(out, selectors, @context, self)
154
+ else
155
+ self
156
+ end
157
+ end
158
+ alias :add_self :and_self
159
+
160
+ # @return [RMQ] The parent rmq instance. This is useful when you want to go down
161
+ # into the tree, then move back up to do more work. Like jQuery's "end"
162
+ #
163
+ # @example
164
+ # rmq(test_view).find(Potion::Button).tag(:foo).back.find(UILabel).tag(:bar)
165
+ def back
166
+ self.parent_rmq || self
167
+ end
168
+
169
+ # @return [RMQ] rmq instance selecting the parent of the selected view(s)
170
+ #
171
+ # @example
172
+ # rmq(my_view).parent.find(:delete_button).toggle_enabled
173
+ def parent
174
+ closest(Potion::View)
175
+ end
176
+ alias :superview :parent
177
+
178
+ # @return [RMQ] Instance selecting the parents, grandparents, etc, all the way up the tree
179
+ # of the selected view(s)
180
+ #
181
+ # @param selectors
182
+ #
183
+ # @example
184
+ # rmq(my_view).parents.log
185
+ def parents(*working_selectors)
186
+ normalize_selectors(working_selectors)
187
+
188
+ filter(uniq: true) do |view|
189
+ superviews = all_superviews_for(view)
190
+
191
+ if RMQ.is_blank?(working_selectors)
192
+ superviews
193
+ else
194
+ superviews.inject([]) do |subview, out|
195
+ out << subview if match(subview, working_selectors)
196
+ out
197
+ end
198
+ end
199
+ end
200
+ end
201
+ alias :superviews :parents
202
+
203
+ # @return [RMQ] Siblings of the selected view(s)
204
+ #
205
+ # @param selectors
206
+ #
207
+ # @example
208
+ # rmq(my_view).siblings.send(:poke)
209
+ def siblings(*working_selectors)
210
+ normalize_selectors(working_selectors)
211
+
212
+ self.parent.children.not(selected)
213
+ end
214
+
215
+ # @return [RMQ] Sibling below the selected view(s) (in the subview array)
216
+ #
217
+ # @param selectors
218
+ #
219
+ # @example
220
+ # rmq(my_view).next.hide
221
+ # rmq(my_view).next(UITextField).focus
222
+ def next(*working_selectors)
223
+ normalize_selectors(working_selectors)
224
+
225
+ filter do |view|
226
+ subs = view.superview.subviews
227
+ location = subs.index(view)
228
+ if location < subs.length - 1
229
+ subs[location + 1]
230
+ end
231
+ end
232
+ end
233
+
234
+ # @return [RMQ] Sibling above the selected view(s) (in the subview array)
235
+ #
236
+ # @param selectors
237
+ #
238
+ # @example
239
+ # rmq(my_view).prev.hid
240
+ # rmq(my_view).prev(UITextField).focus
241
+ def prev(*working_selectors)
242
+ normalize_selectors(working_selectors)
243
+
244
+ filter do |view|
245
+ if sv = view.superview
246
+ subs = sv.subviews
247
+ location = subs.index(view)
248
+ if location > 0
249
+ subs[location - 1]
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ # For each selected view, get the first view that matches the selector(s) by testing the view's parent and
256
+ # traversing up through its ancestors in the tree
257
+ #
258
+ # @return [RMQ] Instance selecting the first parent or grandparent or ancestor up the tree of the selected view(s)
259
+ #
260
+ # @param selectors
261
+ #
262
+ # @example
263
+ # rmq.closest(Potion::View).get.setContentOffset([0,0])
264
+ def closest(*working_selectors)
265
+ normalize_selectors(working_selectors)
266
+
267
+ filter do |view|
268
+ closest_view(view, working_selectors)
269
+ end
270
+ end
271
+
272
+
273
+ protected
274
+
275
+ def closest_view(view, working_selectors)
276
+ if nr = view.superview
277
+ if match(nr, working_selectors)
278
+ nr
279
+ else
280
+ closest_view(nr,working_selectors)
281
+ end
282
+ else
283
+ nil
284
+ end
285
+ end
286
+
287
+ end
@@ -0,0 +1,36 @@
1
+ class RMQ
2
+ class << self
3
+
4
+ def is_class?(o)
5
+ o.class == Java::Lang::Class
6
+ end
7
+
8
+ def is_blank?(o)
9
+ if o.is_a?(RMQ)
10
+ RMQ.is_blank?(o.to_a)
11
+ else
12
+ o.respond_to?(:empty?) ? o.empty? : !o
13
+ end
14
+ end
15
+
16
+ def weak_ref(o)
17
+ o
18
+ end
19
+
20
+ def weak_ref_to_strong_ref(weak_ref)
21
+ weak_ref
22
+ end
23
+
24
+ def is_object_weak_ref?(o)
25
+ false
26
+ end
27
+
28
+ def weak_ref_value(o)
29
+ o
30
+ end
31
+
32
+ def symbolize(s)
33
+ s.to_s.gsub(/\s+/,"_").gsub(/\W+/,"").downcase.to_sym
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ class RMQ
2
+ VERSION = "0.1.0"
3
+ def version
4
+ VERSION
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ class RMQActivityData
2
+ attr_accessor :stylesheet, :cached_rmq
3
+ end
@@ -0,0 +1,9 @@
1
+ class RMQ
2
+ def app
3
+ PMApplication.current_application
4
+ end
5
+
6
+ def self.app
7
+ PMApplication.current_application
8
+ end
9
+ end
@@ -0,0 +1,121 @@
1
+ # many hacks in this: we can't duplicate the iOS implementation because
2
+ # define_singleton_method isn't implemented in Android :'(
3
+ class RMQ
4
+
5
+ def self.color(*params)
6
+ if params.empty?
7
+ RMQColor
8
+ else
9
+ RMQColorFactory.build(params)
10
+ end
11
+ end
12
+
13
+ def color(*params)
14
+ self.class.color(*params)
15
+ end
16
+
17
+ end
18
+
19
+ class RMQColor < Android::Graphics::Color
20
+ class << self
21
+ def clear ; self::TRANSPARENT ; end
22
+ def transparent ; self::TRANSPARENT ; end
23
+
24
+ def white ; self::WHITE ; end
25
+ def light_gray ; self::LTGRAY ; end
26
+ def gray ; self::GRAY ; end
27
+ def dark_gray ; self::DKGRAY ; end
28
+ def black ; self::BLACK ; end
29
+
30
+ #def cyan ; self::CYAN ; end
31
+ #def magenta ; self::MAGENTA ; end
32
+ #def yellow ; self::YELLOW ; end
33
+
34
+ # These are special as the methods already exist
35
+ #def blue ; self::BLUE ; end
36
+ #def green ; self::GREEN ; end
37
+ #def red ; self::RED ; end
38
+ #def blue_color ; self::BLUE ; end
39
+ #def green_color ; self::GREEN ; end
40
+ #def red_color ; self::RED ; end
41
+
42
+ # Maybe we should change this to: color(:white) rather than color.white, TOL
43
+
44
+
45
+ def add_named(key, hex_or_color)
46
+ c = if hex_or_color.is_a?(String)
47
+ RMQColor.parseColor(hex_or_color)
48
+ else
49
+ hex_or_color
50
+ end
51
+
52
+ rmq_color_cache[key] = c
53
+ end
54
+
55
+ def method_missing(color_key)
56
+ # define_singleton_method isn't implemented in Android :'(
57
+ rmq_color_cache[color_key]
58
+ end
59
+
60
+ # Creates a color from a hex triplet (rgb) or quartet (rgba)
61
+ #
62
+ # @param hex with or without the #
63
+ # @return [UIColor]
64
+ # @example
65
+ # color.from_hex('#ffffff')
66
+ # color.from_hex('ffffff')
67
+ # color.from_hex('#336699cc')
68
+ # color.from_hex('369c')
69
+ def from_hex(str)
70
+ RMQColorFactory.from_hex(str)
71
+ end
72
+
73
+ # @return [UIColor]
74
+ #
75
+ # @example
76
+ # rmq.color.from_rgba(255,255,255,0.5)
77
+ def from_rgba(r,g,b,a)
78
+ RMQColorFactory.from_rgba(r,g,b,a)
79
+ end
80
+
81
+ def random
82
+ RMQColorFactory.from_rgba(rand(255), rand(255), rand(255), 1.0)
83
+ end
84
+
85
+ def rmq_color_cache
86
+ @_rmq_color_cache ||= {}
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ class RMQColorFactory
93
+
94
+ class << self
95
+ def build(params)
96
+ return RMQColor if params.empty?
97
+ return from_rgba(*params) if params.count > 1
98
+
99
+ param = params.first
100
+ return from_hex(params.join) if param.is_a?(String)
101
+
102
+ #return from_base_color(param) if base_values(param)
103
+ #return try_rgba(param) if rgba_values(param)
104
+ #return try_hsva(param) if hsva_values(param)
105
+ #return try_hex(param) if hex_values(param)
106
+ end
107
+
108
+ def from_hex(hex_string)
109
+ if hex_string.length == 7
110
+ # this is #RRGGBB format - we need to add the alpha
111
+ color_str = "#FF#{hex_string[1..hex_string.length]}"
112
+ end
113
+ RMQColor.parseColor(hex_string)
114
+ end
115
+
116
+ def from_rgba(r, g, b, a)
117
+ RMQColor.argb(a, r, b, g)
118
+ end
119
+ end
120
+
121
+ end