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,3 @@
1
+ class RMQScreenData
2
+ attr_accessor :stylesheet, :cached_rmq
3
+ end
@@ -0,0 +1,39 @@
1
+ class RMQStylesheet
2
+ attr_accessor :controller
3
+
4
+ def initialize(controller)
5
+ unless RMQStylesheet.application_was_setup
6
+ RMQStylesheet.application_was_setup = true
7
+ application_setup
8
+ end
9
+ @controller = controller
10
+ setup
11
+ end
12
+
13
+ def application_setup
14
+ # Override to do your overall setup for your applications. This
15
+ # is where you want to add your custom fonts and colors
16
+ # This only gets called once
17
+ end
18
+
19
+ def setup
20
+ # Override if you need to do setup in your specific stylesheet
21
+ end
22
+
23
+ def color(*params)
24
+ RMQ.color(*params)
25
+ end
26
+
27
+ def font
28
+ rmq.font
29
+ end
30
+
31
+ def image
32
+ rmq.image
33
+ end
34
+
35
+ class << self
36
+ attr_accessor :application_was_setup
37
+ end
38
+
39
+ end
@@ -0,0 +1,88 @@
1
+ class RMQViewData
2
+ attr_accessor :events, :built, :is_screen_root_view, :activity, :screen
3
+
4
+ def screen_root_view?
5
+ !@is_screen_root_view.nil?
6
+ end
7
+
8
+ # @return [Hash] Array of tag names assigned to to this view
9
+ def tags
10
+ @_tags ||= {}
11
+ end
12
+
13
+ # @return [Array] Array of tag names assigned to to this view
14
+ def tag_names
15
+ tags.keys
16
+ end
17
+
18
+ # *Do not* use this, use {RMQ#tag} instead:
19
+ # @example
20
+ # rmq(my_view).tag(:foo)
21
+ def tag(*tag_or_tags)
22
+ tag_or_tags.flatten!
23
+ tag_or_tags = tag_or_tags.first if tag_or_tags.length == 1
24
+
25
+ if tag_or_tags.is_a?(Array)
26
+ tag_or_tags.each do |tag_name|
27
+ tags[tag_name] = 1
28
+ end
29
+ elsif tag_or_tags.is_a?(Hash)
30
+ tag_or_tags.each do |tag_name, tag_value|
31
+ tags[tag_name] = tag_value
32
+ end
33
+ elsif tag_or_tags.is_a?(Symbol)
34
+ tags[tag_or_tags] = 1
35
+ end
36
+ end
37
+
38
+ # *Do not* use this, use {RMQ#untag} instead:
39
+ # @example
40
+ # rmq(my_view).untag(:foo, :bar)
41
+ # Do nothing if no tag supplied or tag not present
42
+ def untag(*tag_or_tags)
43
+ tag_or_tags.flatten.each do |tag_name|
44
+ tags.delete tag_name
45
+ end
46
+ end
47
+
48
+ # Check if this view contains a specific tag
49
+ #
50
+ # @param tag_name name of tag to check
51
+ # @return [Boolean] true if this view has the tag provided
52
+ def has_tag?(tag_name = nil)
53
+ if tag_name
54
+ tags.include?(tag_name)
55
+ else
56
+ RMQ.is_blank?(@_tags)
57
+ end
58
+ end
59
+
60
+ def style_name
61
+ self.styles.first
62
+ end
63
+
64
+ # Sets first style name, this is only here for backwards compatibility and as
65
+ # a convenience method
66
+ def style_name=(value)
67
+ self.styles[0] = value
68
+ end
69
+
70
+ #view.rmq_data.styles
71
+ def styles
72
+ @_styles ||= []
73
+ end
74
+
75
+ #view.rmq_data.has_style?(:style_name_here)
76
+ def has_style?(name = nil)
77
+ if name
78
+ self.styles.include?(name)
79
+ else
80
+ RMQ.is_blank?(@_styles)
81
+ end
82
+ end
83
+
84
+ def validation_errors; @_validation_errors ||= {}; end
85
+ def validation_errors=(value); @_validation_errors = value; end
86
+ def validations; @_validations ||= []; end
87
+ def validations=(value); @_validations = value; end
88
+ end
@@ -0,0 +1,3 @@
1
+ class RMQButtonStyler < RMQTextViewStyler
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class RMQImageButtonStyler < RMQViewStyler
2
+
3
+ end
@@ -0,0 +1,24 @@
1
+ class RMQImageViewStyler < RMQViewStyler
2
+
3
+ def image_resource=(resource_id)
4
+ @view.imageResource = resource_id
5
+ end
6
+ alias_method :image=, :image_resource=
7
+
8
+ def adjust_view_bounds=(adjust_view_bounds)
9
+ @view.adjustViewBounds = adjust_view_bounds
10
+ end
11
+
12
+ def max_height=(max_height)
13
+ @view.maxHeight = dp2px(max_height)
14
+ end
15
+
16
+ def max_width=(max_width)
17
+ @view.maxWidth = dp2px(max_width)
18
+ end
19
+
20
+ def tint=(t)
21
+ @view.setColorFilter(convert_color(t))
22
+ end
23
+
24
+ end
@@ -0,0 +1,32 @@
1
+ class RMQLinearLayoutStyler < RMQViewStyler
2
+
3
+ def weight_sum=(weight_sum)
4
+ @view.setWeightSum weight_sum
5
+ end
6
+
7
+ def orientation=(orientation)
8
+ @view.setOrientation convert_orientation(orientation)
9
+ end
10
+
11
+ def gravity=(gravity)
12
+ @view.gravity = convert_gravity(gravity)
13
+ end
14
+
15
+ def finalize
16
+ @view.setLayoutParams(layout_params)
17
+ end
18
+
19
+ private
20
+
21
+ def convert_orientation(orientation)
22
+ case orientation
23
+ when :horizontal
24
+ Android::Widget::LinearLayout::HORIZONTAL
25
+ when :vertical
26
+ Android::Widget::LinearLayout::VERTICAL
27
+ else
28
+ orientation
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,7 @@
1
+ class RMQRelativeLayoutStyler < RMQViewStyler
2
+
3
+ def finalize
4
+ @view.setLayoutParams(layout_params)
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ class RMQStylerHelper
2
+ # createRoundRect defined in Java extension, to work around RM bug
3
+ end
@@ -0,0 +1,50 @@
1
+ class RMQTextViewStyler < RMQViewStyler
2
+ def text_size=(text_size)
3
+ @view.textSize = text_size
4
+ end
5
+
6
+ def font_family=(font_family)
7
+ @font_family = font_family
8
+ end
9
+
10
+ def text_style=(text_style)
11
+ @text_style =
12
+ case text_style.to_s.downcase
13
+ when "bold"
14
+ Android::Graphics::Typeface::BOLD
15
+ when "italic"
16
+ Android::Graphics::Typeface::ITALIC
17
+ when "bold italic"
18
+ Android::Graphics::Typeface::BOLD_ITALIC
19
+ when "normal"
20
+ Android::Graphics::Typeface::NORMAL
21
+ end
22
+ end
23
+
24
+ def text_color=(text_color)
25
+ @view.textColor = convert_color(text_color)
26
+ end
27
+ def color=(text_color)
28
+ @view.textColor = convert_color(text_color)
29
+ end
30
+
31
+ def text=(text)
32
+ @view.text = text
33
+ end
34
+
35
+ def font=(rmq_font)
36
+ @view.setTypeface(rmq_font.to_typeface, rmq_font.sdk_text_style)
37
+ @view.textSize = rmq_font.size
38
+ end
39
+
40
+ def gravity=(gravity)
41
+ @view.gravity = convert_gravity(gravity)
42
+ end
43
+
44
+ def finalize
45
+ super
46
+ @text_style ||= Android::Graphics::Typeface::NORMAL
47
+ typeface = Android::Graphics::Typeface.create(@font_family, @text_style) if @font_family
48
+ @view.setTypeface(typeface, @text_style) # ok for typeface to be nil
49
+ end
50
+ end
@@ -0,0 +1,201 @@
1
+ class RMQViewStyler
2
+ attr_accessor :view
3
+ attr_accessor :context
4
+ attr_accessor :bg_color
5
+ attr_accessor :corner_radius
6
+
7
+ def initialize(view, context)
8
+ @view = view
9
+ @context = context
10
+ @bg_color = nil
11
+ @corner_radius = nil
12
+ end
13
+
14
+ def background_color=(color)
15
+ @view.backgroundColor = @bg_color = convert_color(color)
16
+ end
17
+ alias_method :backgroundColor=, :background_color=
18
+
19
+ def background_resource=(bg)
20
+ @view.backgroundResource = bg
21
+ end
22
+
23
+ def layout_width=(layout_width)
24
+ layout_params.width = convert_dimension_value(layout_width)
25
+ end
26
+
27
+ def layout_height=(layout_height)
28
+ layout_params.height = convert_dimension_value(layout_height)
29
+ end
30
+
31
+ def gravity=(gravity)
32
+ layout_params.gravity = convert_gravity(gravity)
33
+ end
34
+
35
+ def layout_center_in_parent=(center_in_parent)
36
+ center = center_in_parent ? Android::Widget::RelativeLayout::TRUE :
37
+ Android::Widget::RelativeLayout::FALSE
38
+ layout_params.addRule(Android::Widget::RelativeLayout::CENTER_IN_PARENT, center)
39
+ end
40
+ alias_method :layout_centerInParent=, :layout_center_in_parent=
41
+
42
+ def layout_center_vertical=(center_vertical)
43
+ center = center_vertical ? Android::Widget::RelativeLayout::TRUE :
44
+ Android::Widget::RelativeLayout::FALSE
45
+ layout_params.addRule(Android::Widget::RelativeLayout::CENTER_VERTICAL, center)
46
+ end
47
+ alias_method :layout_centerVertical=, :layout_center_in_parent=
48
+
49
+ def layout_align_parent_left=(left_in_parent)
50
+ left = left_in_parent ? Android::Widget::RelativeLayout::TRUE :
51
+ Android::Widget::RelativeLayout::FALSE
52
+ layout_params.addRule(Android::Widget::RelativeLayout::ALIGN_PARENT_LEFT, left)
53
+ end
54
+ alias_method :layout_alignParentLeft=, :layout_align_parent_left=
55
+
56
+ def layout_align_parent_right=(right_in_parent)
57
+ right = right_in_parent ? Android::Widget::RelativeLayout::TRUE :
58
+ Android::Widget::RelativeLayout::FALSE
59
+ layout_params.addRule(Android::Widget::RelativeLayout::ALIGN_PARENT_RIGHT, right)
60
+ end
61
+ alias_method :layout_alignParentRight=, :layout_align_parent_right=
62
+
63
+ def padding_left=(pad_left)
64
+ padding[:left] = dp2px(pad_left)
65
+ end
66
+ alias_method :paddingLeft=, :padding_left=
67
+
68
+ def padding_top=(pad_top)
69
+ padding[:top] = dp2px(pad_top)
70
+ end
71
+ alias_method :paddingTop=, :padding_top=
72
+
73
+ def padding_right=(pad_right)
74
+ padding[:right] = dp2px(pad_right)
75
+ end
76
+ alias_method :paddingRight=, :padding_right=
77
+
78
+ def padding_bottom=(pad_bottom)
79
+ padding[:bottom] = dp2px(pad_bottom)
80
+ end
81
+ alias_method :paddingBottom=, :padding_bottom=
82
+
83
+ def padding=(pad)
84
+ padding[:left] = padding[:top] = padding[:right] = padding[:bottom] = dp2px(pad)
85
+ end
86
+
87
+ def margin_left=(m_left)
88
+ margin[:left] = dp2px(m_left)
89
+ end
90
+ alias_method :marginLeft=, :margin_left=
91
+
92
+ def margin_top=(m_top)
93
+ margin[:top] = dp2px(m_top)
94
+ end
95
+ alias_method :marginTop=, :margin_top=
96
+
97
+ def margin_right=(m_right)
98
+ margin[:right] = dp2px(m_right)
99
+ end
100
+ alias_method :marginRight=, :margin_right=
101
+
102
+ def margin_bottom=(m_bottom)
103
+ margin[:bottom] = dp2px(m_bottom)
104
+ end
105
+ alias_method :marginBottom=, :margin_bottom=
106
+
107
+ def margin=(m)
108
+ margin[:left] = margin[:top] = margin[:right] = margin[:bottom] = dp2px(m)
109
+ end
110
+
111
+ # this can only be used on a widget that's within a LinearLayout
112
+ def layout_weight=(weight)
113
+ layout_params.weight = weight
114
+ end
115
+
116
+ def layout_gravity=(gravity)
117
+ layout_params.gravity = convert_gravity(gravity)
118
+ end
119
+
120
+ def corner_radius(corner_radius)
121
+ @corner_radius = dp2px(corner_radius)
122
+ end
123
+
124
+ # use this if you need to do something after all style methods have been called (e.g.
125
+ # applying layout params)
126
+ def finalize
127
+ create_rounded_bg if corner_radius
128
+ @view.setPadding(padding[:left], padding[:top], padding[:right], padding[:bottom])
129
+ layout_params.setMargins(margin[:left],
130
+ margin[:top],
131
+ margin[:right],
132
+ margin[:bottom]) if layout_params.respond_to?(:setMargins)
133
+ @view.setLayoutParams(layout_params)
134
+ end
135
+
136
+ def layout_params
137
+ @layout_params ||= @view.getLayoutParams()
138
+ end
139
+
140
+ def convert_color(color)
141
+ return ColorFactory.from_hex(color) if color.is_a?(String)
142
+ color
143
+ end
144
+
145
+ def convert_gravity(gravity)
146
+ case gravity
147
+ when :center then Android::View::Gravity::CENTER
148
+ when :left then Android::View::Gravity::LEFT
149
+ else
150
+ gravity
151
+ end
152
+ end
153
+
154
+ def dp2px(dp_val)
155
+ (dp_val * density + 0.5).to_i
156
+ end
157
+
158
+ def density
159
+ @density ||= context.getResources.getDisplayMetrics.density
160
+ end
161
+
162
+ def create_drawable(corner_radius)
163
+ createDrawable(corner_radius)
164
+ end
165
+
166
+ private
167
+
168
+ def padding
169
+ @padding ||= { left: 0, top: 0, right: 0, bottom: 0 }
170
+ end
171
+
172
+ def margin
173
+ @margin ||= { left: 0, top: 0, right: 0, bottom: 0 }
174
+ end
175
+
176
+ def convert_dimension_value(value)
177
+ case value
178
+ when :match_parent, :full
179
+ Android::View::ViewGroup::LayoutParams::MATCH_PARENT
180
+ when :wrap_content
181
+ Android::View::ViewGroup::LayoutParams::WRAP_CONTENT
182
+ else
183
+ dp2px(value)
184
+ end
185
+ end
186
+
187
+ def create_rounded_bg
188
+ # creating this shape in Ruby raises an ART error, but it works in Java
189
+ #radii = [corner_radius, corner_radius, corner_radius, corner_radius,
190
+ # corner_radius, corner_radius, corner_radius, corner_radius]
191
+ #shape = Android::Graphics::Drawable::Shapes::RoundRectShape.new(radii, nil, nil)
192
+
193
+ # StyleHelper contains a Java extension
194
+ shape = StylerHelper.shared.createRoundRect(dp2px(corner_radius))
195
+
196
+ drawable = Android::Graphics::Drawable::ShapeDrawable.new(shape)
197
+ drawable.paint.color = bg_color
198
+ @view.setBackgroundDrawable(drawable)
199
+ end
200
+
201
+ end