bluepotion 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8d94399c2e9d10b9b2610cd594612ebe79aa34a
4
- data.tar.gz: d4fd79eeba234aec607d8d264431aaee962abd25
3
+ metadata.gz: 2144e6cc671ff757a2afd611680884628dc5422a
4
+ data.tar.gz: e067abe21100a273fd70c6a245f99f06e5355b29
5
5
  SHA512:
6
- metadata.gz: 6fed1b097d48b24177cf2dfcb38f986283f7180950a13ca7360f63158d95fbdfda3f2292c7f6a06bf4a7f4485ed14f0e568fc9d7736af5221449bb946779c6bb
7
- data.tar.gz: e4d2b0f568f4e0e50c2f45ee98902f99628fe8d43df249817fd1c9b69c20e6cdc4b35abceec06ccd134d7696bd5ee114b4860247934dde0b6e605f6420bfcbac
6
+ metadata.gz: 3a8f167141409255d7ab4f83cf3172f9c81ed45639cf4ce16eb562779697e9fe31e9188def5994ab5a13b4dabade23d38a080314c9d8c81cfcd2ebbb309eee35
7
+ data.tar.gz: 5f8826fbdc43efb2f2f7612078d298350a04a4b28348eeb2bd6854d478e7fdadc2f161c5c63a8a88e896cf325556ecef164f826d633798a9b11202aa5c76711f
data/README.md CHANGED
@@ -5,6 +5,45 @@
5
5
  BluePotion
6
6
  -----------
7
7
 
8
- Like [RedPotion](http://redpotion.org), but for RubyMotion Android.
8
+ ## Warning, BluePotion is an alpha release.
9
9
 
10
- ## BluePotion is pre-alpha right now!
10
+ BluePotion is the Android version of [RedPotion](http://redpotion.org). We're spending a lot of time working on it right now. It's currently in Alpha.
11
+
12
+ We are building RMQ Android, ProMotion Android, and BluePotion all at once, and they all are inside BluePotion.
13
+
14
+ We're supporting Android XML layouts, using RMQ stylesheets the standard Android way, and eventually an exact copy of RedPotion's layout system.
15
+
16
+ Many things work, but there is a lot to do, so use it at your own risk.
17
+
18
+ To try it out:
19
+
20
+ ```
21
+ gem install bluepotion
22
+ bluepotion create myapp
23
+ cd myapp
24
+ bundle
25
+ rake newclear
26
+ ```
27
+
28
+ In your REPL, do this for fun:
29
+
30
+ ```
31
+ rmq.log_tree
32
+ find(Potion::View).log
33
+ # etc
34
+ ```
35
+
36
+ If you haven't setup Android yet, read this first: [Gant Laborde's post on Genymotion](http://www.iconoclastlabs.com/blog/rubymotion-android-in-the-emulator-with-genymotion).
37
+
38
+
39
+ Contributing
40
+
41
+ 0. Create an issue in GitHub to make sure your PR will be accepted.
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Write tests for your changes
45
+ 4. Make your changes
46
+ 5. Document your changes in the `docs` folder
47
+ 6. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 7. Push to the branch (`git push origin my-new-feature`)
49
+ 8. Create new Pull Request
@@ -2,6 +2,7 @@ module Potion
2
2
  Activity = Android::App::Activity
3
3
  View = Android::View::View
4
4
  ViewGroup = Android::View::ViewGroup
5
+ Integer = Java::Lang::Integer
5
6
 
6
7
  # layouts
7
8
  LinearLayout = Android::Widget::LinearLayout
@@ -14,6 +15,7 @@ module Potion
14
15
  TextView = Android::Widget::TextView
15
16
  ImageView = Android::Widget::ImageView
16
17
  Button = Android::Widget::Button
18
+ CalendarView = Android::Widget::CalendarView
17
19
  Toast = Android::Widget::Toast
18
20
 
19
21
  # graphics
@@ -56,7 +56,6 @@
56
56
  self.rmq.all.each do |view|
57
57
  if ren = view.resource_entry_name
58
58
  self.rmq.build(view).tag(ren.to_sym)
59
- #view.rmq_data.tag(ren.to_sym)
60
59
  end
61
60
  end
62
61
  end
@@ -5,26 +5,118 @@ class RMQViewStyler
5
5
  attr_accessor :corner_radius
6
6
 
7
7
  def initialize(view, context)
8
+ @needs_finalize = false
8
9
  @view = view
9
10
  @context = context
10
11
  @bg_color = nil
11
12
  @corner_radius = nil
12
13
  end
13
14
 
15
+ def convert_dimension_value(value)
16
+ case value
17
+ when :match_parent, :full
18
+ Android::View::ViewGroup::LayoutParams::MATCH_PARENT
19
+ when :wrap_content
20
+ Android::View::ViewGroup::LayoutParams::WRAP_CONTENT
21
+ else
22
+ dp2px(value)
23
+ end
24
+ end
25
+
26
+ def layout_params
27
+ @layout_params ||= @view.getLayoutParams
28
+ end
29
+
30
+ def layout=(value)
31
+ lp = layout_params
32
+
33
+ if value == :full
34
+ lp.width = convert_dimension_value(:full)
35
+ lp.height = convert_dimension_value(:full)
36
+ @view.setLayoutParams(lp)
37
+ elsif value.is_a?(Hash)
38
+ hash = value
39
+ if w = (hash[:w] || hash[:width])
40
+ lp.width = convert_dimension_value(w)
41
+ end
42
+ if h = (hash[:h] || hash[:height])
43
+ lp.height = convert_dimension_value(h)
44
+ end
45
+ if l = (hash[:l] || hash[:left] || hash[:left_margin])
46
+ lp.leftMargin = convert_dimension_value(l)
47
+ end
48
+ if t = (hash[:t] || hash[:top] || hash[:top_margin])
49
+ lp.topMargin = convert_dimension_value(t)
50
+ end
51
+ if fr = (hash[:fr] || hash[:from_right] || hash[:right_margin])
52
+ lp.rightMargin = convert_dimension_value(fr)
53
+ end
54
+ if fb = (hash[:fb] || hash[:from_bottom] || hash[:bottom_margin])
55
+ lp.bottomMargin = convert_dimension_value(fb)
56
+ end
57
+
58
+ # TODO do center
59
+
60
+ # TODO gravity
61
+
62
+ # TODO do the relative bits
63
+
64
+ @view.setLayoutParams(lp)
65
+
66
+ if pad = hash[:padding]
67
+ self.padding = pad
68
+ end
69
+ end
70
+
71
+ end
72
+ alias :frame= :layout=
73
+
74
+ def padding=(pad)
75
+ if pad.is_a?(Potion::Integer)
76
+ pad = convert_dimension_value(pad)
77
+ @view.setPadding(pad, pad, pad, pad)
78
+ elsif pad.is_a?(Hash)
79
+ @view.setPadding(
80
+ convert_dimension_value(pad[:l] || pad[:left] || 0),
81
+ convert_dimension_value(pad[:t] || pad[:top] || 0),
82
+ convert_dimension_value(pad[:r] || pad[:right] || 0),
83
+ convert_dimension_value(pad[:b] || pad[:bottom] || 0))
84
+ else
85
+ mp pad.class.name
86
+ end
87
+ end
88
+
89
+ # use this if you need to do something after all style methods have been called (e.g.
90
+ # applying layout params)
91
+ def finalize
92
+ return unless @needs_finalize
93
+
94
+ create_rounded_bg if corner_radius
95
+ layout_params.setMargins(margin[:left],
96
+ margin[:top],
97
+ margin[:right],
98
+ margin[:bottom]) if layout_params.respond_to?(:setMargins)
99
+ @view.setLayoutParams(layout_params)
100
+
101
+ @view.setPadding(padding[:left], padding[:top], padding[:right], padding[:bottom])
102
+ end
103
+
104
+
14
105
  def background_color=(color)
15
106
  @view.backgroundColor = @bg_color = convert_color(color)
16
107
  end
17
- alias_method :backgroundColor=, :background_color=
18
108
 
19
109
  def background_resource=(bg)
20
110
  @view.backgroundResource = bg
21
111
  end
22
112
 
23
113
  def layout_width=(layout_width)
114
+ @needs_finalize = true
24
115
  layout_params.width = convert_dimension_value(layout_width)
25
116
  end
26
117
 
27
118
  def layout_height=(layout_height)
119
+ @needs_finalize = true
28
120
  layout_params.height = convert_dimension_value(layout_height)
29
121
  end
30
122
 
@@ -33,110 +125,101 @@ class RMQViewStyler
33
125
  end
34
126
 
35
127
  def layout_center_in_parent=(center_in_parent)
128
+ @needs_finalize = true
36
129
  center = center_in_parent ? Android::Widget::RelativeLayout::TRUE :
37
130
  Android::Widget::RelativeLayout::FALSE
38
131
  layout_params.addRule(Android::Widget::RelativeLayout::CENTER_IN_PARENT, center)
39
132
  end
40
- alias_method :layout_centerInParent=, :layout_center_in_parent=
41
133
 
42
134
  def layout_center_vertical=(center_vertical)
135
+ @needs_finalize = true
43
136
  center = center_vertical ? Android::Widget::RelativeLayout::TRUE :
44
137
  Android::Widget::RelativeLayout::FALSE
45
138
  layout_params.addRule(Android::Widget::RelativeLayout::CENTER_VERTICAL, center)
46
139
  end
47
- alias_method :layout_centerVertical=, :layout_center_in_parent=
140
+
141
+ def layout_center_horizontal=(center_horizontal)
142
+ @needs_finalize = true
143
+ center = center_horizontal ? Android::Widget::RelativeLayout::TRUE :
144
+ Android::Widget::RelativeLayout::FALSE
145
+ layout_params.addRule(Android::Widget::RelativeLayout::CENTER_HORIZONTAL, center)
146
+ end
48
147
 
49
148
  def layout_align_parent_left=(left_in_parent)
149
+ @needs_finalize = true
50
150
  left = left_in_parent ? Android::Widget::RelativeLayout::TRUE :
51
151
  Android::Widget::RelativeLayout::FALSE
52
152
  layout_params.addRule(Android::Widget::RelativeLayout::ALIGN_PARENT_LEFT, left)
53
153
  end
54
- alias_method :layout_alignParentLeft=, :layout_align_parent_left=
55
154
 
56
155
  def layout_align_parent_right=(right_in_parent)
156
+ @needs_finalize = true
57
157
  right = right_in_parent ? Android::Widget::RelativeLayout::TRUE :
58
158
  Android::Widget::RelativeLayout::FALSE
59
159
  layout_params.addRule(Android::Widget::RelativeLayout::ALIGN_PARENT_RIGHT, right)
60
160
  end
61
- alias_method :layout_alignParentRight=, :layout_align_parent_right=
62
161
 
63
162
  def padding_left=(pad_left)
163
+ @needs_finalize = true
64
164
  padding[:left] = dp2px(pad_left)
65
165
  end
66
- alias_method :paddingLeft=, :padding_left=
67
166
 
68
167
  def padding_top=(pad_top)
168
+ @needs_finalize = true
69
169
  padding[:top] = dp2px(pad_top)
70
170
  end
71
- alias_method :paddingTop=, :padding_top=
72
171
 
73
172
  def padding_right=(pad_right)
173
+ @needs_finalize = true
74
174
  padding[:right] = dp2px(pad_right)
75
175
  end
76
- alias_method :paddingRight=, :padding_right=
77
176
 
78
177
  def padding_bottom=(pad_bottom)
178
+ @needs_finalize = true
79
179
  padding[:bottom] = dp2px(pad_bottom)
80
180
  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
181
 
87
182
  def margin_left=(m_left)
183
+ @needs_finalize = true
88
184
  margin[:left] = dp2px(m_left)
89
185
  end
90
- alias_method :marginLeft=, :margin_left=
91
186
 
92
187
  def margin_top=(m_top)
188
+ @needs_finalize = true
93
189
  margin[:top] = dp2px(m_top)
94
190
  end
95
- alias_method :marginTop=, :margin_top=
96
191
 
97
192
  def margin_right=(m_right)
193
+ @needs_finalize = true
98
194
  margin[:right] = dp2px(m_right)
99
195
  end
100
- alias_method :marginRight=, :margin_right=
101
196
 
102
197
  def margin_bottom=(m_bottom)
198
+ @needs_finalize = true
103
199
  margin[:bottom] = dp2px(m_bottom)
104
200
  end
105
- alias_method :marginBottom=, :margin_bottom=
106
201
 
107
202
  def margin=(m)
203
+ @needs_finalize = true
108
204
  margin[:left] = margin[:top] = margin[:right] = margin[:bottom] = dp2px(m)
109
205
  end
110
206
 
111
- # this can only be used on a widget that's within a LinearLayout
207
+ # This can only be used on a widget that's within a LinearLayout
112
208
  def layout_weight=(weight)
209
+ @needs_finalize = true
113
210
  layout_params.weight = weight
114
211
  end
115
212
 
116
213
  def layout_gravity=(gravity)
214
+ @needs_finalize = true
117
215
  layout_params.gravity = convert_gravity(gravity)
118
216
  end
119
217
 
120
218
  def corner_radius(corner_radius)
219
+ @needs_finalize = true
121
220
  @corner_radius = dp2px(corner_radius)
122
221
  end
123
222
 
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
223
  def convert_color(color)
141
224
  return ColorFactory.from_hex(color) if color.is_a?(String)
142
225
  color
@@ -1,3 +1,3 @@
1
1
  module BluePotion
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluepotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfiniteRed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake