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,64 @@
1
+ class RMQ
2
+ def data(new_data = :rmq_not_provided)
3
+ if new_data != :rmq_not_provided
4
+ selected.each do |view|
5
+ case view
6
+ #when UILabel then view.setText new_data # set is faster than =
7
+ #when UIButton then view.setTitle(new_data, forState: UIControlStateNormal)
8
+ #when UIImageView then view.image = new_data
9
+ #when UITableView then
10
+ #when UISwitch then view.setOn(new_data)
11
+ #when UIDatePicker then
12
+ #when UISegmentedControl then
13
+ #when UIRefreshControl then
14
+ #when UIPageControl then
15
+ #when UISlider then
16
+ #when UIStepper then
17
+ #when UITabBar then
18
+ #when UITableViewCell then
19
+ when Potion::TextView then view.text = new_data
20
+ #when UITextField then view.text = new_data
21
+ #when UINavigationBar then
22
+ #when UIScrollView then
23
+ #when UIProgressView then view.setProgress(new_data, animated: true)
24
+
25
+ # TODO, finish
26
+ end
27
+ end
28
+
29
+ self
30
+ else
31
+ out = selected.map do |view|
32
+ case view
33
+ #when UILabel then view.text
34
+ #when UIButton then view.titleForState(UIControlStateNormal)
35
+ #when UIImageView then view.image
36
+ #when UITableView then
37
+ #when UISwitch then
38
+ #when UIDatePicker then
39
+ #when UISegmentedControl then
40
+ #when UIRefreshControl then
41
+ #when UIPageControl then
42
+ #when UISlider then
43
+ #when UIStepper then
44
+ #when UITabBar then
45
+ #when UITableViewCell then
46
+ when Potion::TextView then view.text
47
+ #when UITextField then view.text
48
+ #when UINavigationBar then
49
+ #when UIScrollView then
50
+ #when UIProgressView then view.progress
51
+
52
+ # TODO, finish
53
+ end
54
+ end
55
+
56
+ out = out.first if out.length == 1
57
+ out
58
+ end
59
+ end
60
+
61
+ def data=(new_data)
62
+ self.data(new_data)
63
+ end
64
+ end
@@ -0,0 +1,9 @@
1
+ class RMQ
2
+ def self.debugging?
3
+ @debugging ||= ENV['rmq_debug'] == 'true'
4
+ end
5
+
6
+ def self.debugging=(flag)
7
+ @debugging = flag
8
+ end
9
+ end
@@ -0,0 +1,99 @@
1
+ class RMQ
2
+ # I'm purposly not including Enumerable,
3
+ # please use to_a if you want one
4
+
5
+
6
+ # @return [RMQ]
7
+ def <<(value)
8
+ selected << value if value.is_a?(UIView)
9
+ self
10
+ end
11
+
12
+ # @return [RMQ]
13
+ #
14
+ # @example
15
+ # rmq(UILabel)[3]
16
+ # or
17
+ # rmq(UILabel)[1..5]
18
+ # or
19
+ # rmq(UILabel)[2,3]
20
+ def [](*args)
21
+ RMQ.create_with_array_and_selectors(Array(selected[*args]), @selectors, @originated_from)
22
+ end
23
+ alias :eq :[]
24
+
25
+ # @return [RMQ]
26
+ def each(&block)
27
+ return self unless block
28
+ RMQ.create_with_array_and_selectors(selected.each(&block), @selectors, @originated_from)
29
+ end
30
+
31
+ # @return [RMQ]
32
+ def map(&block)
33
+ return self unless block
34
+ RMQ.create_with_array_and_selectors(selected.map(&block), @selectors, @originated_from)
35
+ end
36
+ alias :collect :map
37
+
38
+ # @return [RMQ]
39
+ def select(&block)
40
+ return self unless block
41
+ RMQ.create_with_array_and_selectors(selected.select(&block), @selectors, @originated_from)
42
+ end
43
+
44
+ # @return [RMQ]
45
+ def detect(&block) # Unlike enumerable, detect and find are not the same. See find in transverse
46
+ return self unless block
47
+ RMQ.create_with_array_and_selectors(selected.select(&block), @selectors, @originated_from)
48
+ end
49
+
50
+ # @return [RMQ]
51
+ def grep(&block)
52
+ return self unless block
53
+ RMQ.create_with_array_and_selectors(selected.grep(&block), @selectors, @originated_from)
54
+ end
55
+
56
+ # @return [RMQ]
57
+ def reject(&block)
58
+ return self unless block
59
+ RMQ.create_with_array_and_selectors(selected.reject(&block), @selectors, @originated_from)
60
+ end
61
+
62
+ # @return [RMQ]
63
+ def inject(o, &block)
64
+ return self unless block
65
+ RMQ.create_with_array_and_selectors(selected.inject(o, &block), @selectors, @originated_from)
66
+ end
67
+ alias :reduce :inject
68
+
69
+ # @return [RMQ]
70
+ def first
71
+ # TODO, check if it fails with nil
72
+ RMQ.create_with_array_and_selectors([selected.first], @selectors, @originated_from)
73
+ end
74
+ # @return [RMQ]
75
+ def last
76
+ # TODO, check if it fails with nil
77
+ RMQ.create_with_array_and_selectors([selected.last], @selectors, @originated_from)
78
+ end
79
+
80
+ # @return [Array]
81
+ def to_a
82
+ selected
83
+ end
84
+
85
+ # @return [Integer] number of views selected
86
+ def length
87
+ selected.length
88
+ end
89
+ def size
90
+ length
91
+ end
92
+ def count
93
+ length
94
+ end
95
+ #alias :size :length
96
+ #alias :count :length
97
+ end
98
+
99
+
@@ -0,0 +1,28 @@
1
+ class RMQ
2
+ def on(event, args={}, &block)
3
+ self.selected.each do |view|
4
+
5
+ case event
6
+ when :click, :tap, :touch
7
+ view.onClickListener = RMQClickHandler.new(&block)
8
+ else
9
+ raise "[RMQ ERROR] Unrecognized event: #{event}"
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ class RMQClickHandler
18
+ attr_accessor :click_block
19
+
20
+ def initialize(&block)
21
+ @click_block = block
22
+ end
23
+
24
+ def onClick(view)
25
+ click_block.call(view)
26
+ end
27
+
28
+ end
@@ -0,0 +1,47 @@
1
+ class RMQ
2
+ # This is used internally, to get a new rmq instance, just call "rmq" in your view or controller or
3
+ # just create a new one like so: RubyMotionQuery::RMQ.new
4
+ #
5
+ # @return [RMQ]
6
+ def create_blank_rmq
7
+ RMQ.create_with_array_and_selectors([], self.selectors, @originated_from)
8
+ end
9
+
10
+ # This is used internally, to get a new rmq instance, just call "rmq" in your view or controller or
11
+ # just create a new one like so: RubyMotionQuery::RMQ.new
12
+ #
13
+ # @return [RMQ]
14
+ def create_rmq_in_originated_from(*working_selectors)
15
+ RMQ.create_with_selectors(working_selectors, @originated_from)
16
+ end
17
+
18
+ class << self
19
+
20
+ # This is used internally, to get a new rmq instance, just call "rmq" in your view or controller or
21
+ # just create a new one like so: RubyMotionQuery::RMQ.new
22
+ #
23
+ # @return [RMQ]
24
+ def create_with_selectors(working_selectors, originated_from, working_parent_rmq = nil)
25
+ q = RMQ.new
26
+ q.originated_from = originated_from
27
+ q.parent_rmq = working_parent_rmq
28
+ q.selectors = working_selectors
29
+ q
30
+ end
31
+
32
+ # This is used internally, to get a new rmq instance, just call "rmq" in your view or controller or
33
+ # just create a new one like so: RubyMotionQuery::RMQ.new
34
+ #
35
+ # @return [RMQ]
36
+ def create_with_array_and_selectors(array, working_selectors, local_originated_from, working_parent_rmq = nil) # TODO, convert to opts
37
+ q = RMQ.new
38
+ q.originated_from = local_originated_from
39
+ q.selectors = working_selectors
40
+ q.parent_rmq = working_parent_rmq
41
+ q.selected = array # Must be last
42
+ q
43
+ end
44
+
45
+ end
46
+ end
47
+
@@ -0,0 +1,2 @@
1
+ class RMQ
2
+ end
@@ -0,0 +1,72 @@
1
+ class RMQ
2
+ # Do not use
3
+ def selectors=(value)
4
+ @selected_dirty = true
5
+ normalize_selectors(value)
6
+ @_selectors = value
7
+ end
8
+
9
+ def selectors
10
+ @_selectors
11
+ end
12
+
13
+ def match(view, new_selectors)
14
+ out = false
15
+
16
+ # This method is written strange because the return in this example doesn't actually return (RM bug)
17
+ # elsif selector == :tagged
18
+ # return true unless view.rmq_data.has_tag?
19
+
20
+ new_selectors.each do |selector|
21
+ if selector.is_a?(Java::Lang::Integer)
22
+ if view.id == selector
23
+ out = true
24
+ break
25
+ end
26
+ elsif selector == :tagged
27
+ if view.rmq_data.has_tag?
28
+ out = true
29
+ break
30
+ end
31
+ elsif selector.is_a?(Symbol)
32
+ if (view.rmq_data.has_style?(selector)) || view.rmq_data.has_tag?(selector)
33
+ out = true
34
+ break
35
+ end
36
+ elsif selector.is_a?(Hash)
37
+ if match_hash(view, selector)
38
+ out = true
39
+ break
40
+ end
41
+ elsif RMQ.is_class?(selector)
42
+ if view.is_a?(selector)
43
+ out = true
44
+ break
45
+ end
46
+ else
47
+ if view == selector
48
+ out = true
49
+ break
50
+ end
51
+ end
52
+ end
53
+
54
+ out
55
+ end
56
+
57
+ private
58
+
59
+ def match_hash(view, hash)
60
+ # TODO, check speed, and do sub hashes for stuff like origin
61
+ # it's probably pretty slow
62
+ hash.each do |k,v|
63
+ return true if view.respond_to?(k) && (view.send(k) == v)
64
+ end
65
+ false
66
+ end
67
+
68
+ def normalize_selectors(a = self.selectors)
69
+ a.flatten! if a
70
+ a
71
+ end
72
+ end
@@ -0,0 +1,108 @@
1
+ class RMQ
2
+
3
+ def stylesheet=(value)
4
+ controller = self.screen || self.activity
5
+ unless value.is_a?(RMQStylesheet)
6
+ value = value.new(controller)
7
+ end
8
+ @_stylesheet = value
9
+ controller.rmq_data.stylesheet = value
10
+ self
11
+ end
12
+
13
+ def stylesheet
14
+ @_stylesheet ||= begin
15
+ if self.controller && (ss = self.controller.rmq_data.stylesheet)
16
+ ss
17
+ elsif (prmq = self.parent_rmq) && prmq.stylesheet
18
+ prmq.stylesheet
19
+ end
20
+ end
21
+ end
22
+
23
+ def styler_for(view)
24
+ context = RMQ.app.context
25
+ styler = case view
26
+ when Android::Widget::RelativeLayout then RMQRelativeLayoutStyler.new(view, context)
27
+ when Android::Widget::LinearLayout then RMQLinearLayoutStyler.new(view, context)
28
+ when Android::Widget::TextView then RMQTextViewStyler.new(view, context)
29
+ when Android::Widget::ImageView then RMQImageViewStyler.new(view, context)
30
+ when Android::Widget::ImageButton then RMQImageButtonStyler.new(view, context)
31
+ when Android::Widget::Button then RMQButtonStyler.new(view, context)
32
+ else
33
+ RMQViewStyler.new(view, context)
34
+ end
35
+ styler
36
+ end
37
+
38
+ def apply_style(*style_names)
39
+ if style_names
40
+ selected.each do |selected_view|
41
+ style_names.each do |style_name|
42
+ apply_style_to_view selected_view, style_name
43
+ end
44
+ end
45
+ end
46
+ self
47
+ end
48
+ alias :apply_styles :apply_style
49
+
50
+ def apply_style_to_view(view, style_name)
51
+ #begin
52
+ styler = self.styler_for(view)
53
+ self.stylesheet.send(style_name, styler)
54
+ styler.finalize
55
+
56
+ view.rmq_data.styles << style_name unless view.rmq_data.has_style?(style_name)
57
+ view.rmq_style_applied
58
+ #rescue NoMethodError => e
59
+ #if e.message =~ /.*#{style_name.to_s}.*/
60
+ #$stderr.puts "\n[RMQ ERROR] style_name :#{style_name} doesn't exist for a #{view.class.name}. Add 'def #{style_name}(st)' to #{stylesheet.class.name} class\n\n"
61
+ #else
62
+ #raise e
63
+ #end
64
+ #end
65
+ end
66
+
67
+ def style
68
+ selected.each do |view|
69
+ yield(styler_for(view))
70
+ end
71
+ self
72
+ end
73
+
74
+ def styles
75
+ out = selected.map do |view|
76
+ view.rmq_data.styles
77
+ end
78
+ out.flatten!.uniq
79
+ end
80
+
81
+
82
+
83
+ end
84
+
85
+
86
+ __END__
87
+
88
+ # # these only work if widget is in a RelativeLayout
89
+ #
90
+ #def align_to_left_of(other)
91
+ #set_alignment_to(other, Android::Widget::RelativeLayout::LEFT_OF)
92
+ #end
93
+
94
+ #def align_to_right_of(other)
95
+ #set_alignment_to(other, Android::Widget::RelativeLayout::RIGHT_OF)
96
+ #end
97
+
98
+ #def align_below(other)
99
+ #set_alignment_to(other, Android::Widget::RelativeLayout::BELOW)
100
+ #end
101
+
102
+ #private
103
+
104
+ #def set_alignment_to(other, rule)
105
+ #params = @view.layoutParams
106
+ #params.addRule(rule, other.get.id)
107
+ #@view.setLayoutParams(params)
108
+ #end
@@ -0,0 +1,95 @@
1
+ class RMQ
2
+ def add_subview(view_or_class, opts={})
3
+ subviews_added = []
4
+
5
+ selected.each do |selected_view|
6
+ created = false
7
+ appended = false
8
+ built = false
9
+
10
+ if view_or_class.is_a?(Potion::View)
11
+ new_view = view_or_class
12
+ else
13
+ created = true
14
+ new_view = view_or_class.new(RMQ.app.context)
15
+ new_view.setId(Potion::ViewIdGenerator.generate)
16
+ end
17
+
18
+ rmq_data = new_view.rmq_data
19
+
20
+ unless rmq_data.built
21
+ rmq_data.built = true # build only once
22
+ built = true
23
+ end
24
+
25
+ rmq_data.activity = self.activity
26
+ rmq_data.screen = self.screen
27
+
28
+ subviews_added << new_view
29
+
30
+ unless opts[:do_not_add]
31
+ #if at_index = opts[:at_index]
32
+ #selected_view.insertSubview(new_view, atIndex: at_index)
33
+ #elsif below_view = opts[:below_view]
34
+ #selected_view.insertSubview(new_view, belowSubview: below_view)
35
+ #else
36
+ selected_view.addView(new_view)
37
+ #end
38
+
39
+ appended = true
40
+ end
41
+
42
+ if created
43
+ new_view.rmq_created
44
+ end
45
+ new_view.rmq_build if built
46
+ new_view.rmq_appended if appended
47
+
48
+ if self.stylesheet
49
+ apply_style_to_view(new_view, opts[:style]) if opts[:style]
50
+ end
51
+ end
52
+
53
+ viewq = RMQ.create_with_array_and_selectors(subviews_added, selectors, @originated_from, self)
54
+ opts[:block].call viewq if opts[:block]
55
+ opts[:raw_block].call viewq.get if opts[:raw_block]
56
+ viewq
57
+ end
58
+ alias :insert :add_subview
59
+
60
+ def append_view(view_or_class, style=nil, opts={})
61
+ opts[:style] = style
62
+ #opts[:block] = block if block
63
+ out = self.add_subview(view_or_class, opts)
64
+ out
65
+ end
66
+
67
+ def append_view!(view_or_class, style=nil, opts={})
68
+ self.append_view(view_or_class, style, opts).get
69
+ end
70
+
71
+ def create(view_or_constant, style = nil, opts = {}, &block)
72
+ # TODO, refactor so that add_subview uses create, not backwards like it is now
73
+ opts[:do_not_add] = true
74
+ opts[:style] = style
75
+ opts[:block] = block if block
76
+ add_subview view_or_constant, opts
77
+ end
78
+
79
+ def create!(view_or_constant, style=nil, opts = {}, &block)
80
+ opts[:raw_block] = block if block
81
+ create(view_or_constant, style, opts).get
82
+ end
83
+
84
+ def build(view_or_constant, style = nil, opts = {}, &block)
85
+ opts[:do_not_add] = true
86
+ opts[:style] = style
87
+ opts[:block] = block if block
88
+ add_subview view_or_constant, opts
89
+ end
90
+
91
+ def build!(view_or_constant, style = nil, opts = {}, &block)
92
+ opts[:raw_block] = block if block
93
+ build(view_or_constant, style, opts).get
94
+ end
95
+ end