bluepotion 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d63573b24ac2969163f7eb92fcb46e368dda0e9f
4
- data.tar.gz: 7dd7129bd3785eb9a27166f6cff5ecba0dc8b6eb
3
+ metadata.gz: 6dd3f2d3afeb74ed27d0462acbc47b6a15690f45
4
+ data.tar.gz: 8a045fc0e5135d3b915baf52e96b65cd1d617763
5
5
  SHA512:
6
- metadata.gz: 9e61f1e779c465eb103cc4747af76d263ecd2c3e19b7886a30fd4bd9002f7be6f2c9186b1459f6640c22d5c4f4811c1faaa6fe26a994345e1547e08e80b3b317
7
- data.tar.gz: 057cb3c8acda52faf7a9604cffb398345d5abd22570b4977998f641c8cb579980d88f90bb9b89630828f18a9c8c68eb25c4b7f6a4a7cefac16e5fb4f16ffd209
6
+ metadata.gz: e51238c06e1b09622ff5f2d62c909f2ecc2bb3e9015fd8a600cbbbf655c1d47cde5f295dcdb233511b7c836f5d96da2e2b0eccce4a3184097cfacda19cbd90a6
7
+ data.tar.gz: 4463dabf7934ab8ab4ec5051fbe121be0ee0f2020ca5fda508d31a2a2e96ff8115605ef109e471fadc72466b8b64f25b5ad39630436368567ea3a94849f52df7
@@ -0,0 +1,8 @@
1
+ class NilClass
2
+
3
+ # REMOVE when RubyMotion adds this
4
+ def empty?
5
+ self.to_s.empty?
6
+ end
7
+
8
+ end
@@ -46,6 +46,9 @@ class Object
46
46
  self.class.name.split('.').last
47
47
  end
48
48
 
49
+ def blank?
50
+ self.respond_to?(:empty?) ? self.empty? : !self
51
+ end
49
52
 
50
53
  # RMQ stuff
51
54
 
@@ -3,6 +3,8 @@ module Potion
3
3
  View = Android::View::View
4
4
  ViewGroup = Android::View::ViewGroup
5
5
  Integer = Java::Lang::Integer
6
+ ArrayList = Java::Util::ArrayList
7
+ Bundle = Android::Os::Bundle
6
8
 
7
9
  # layouts
8
10
  LinearLayout = Android::Widget::LinearLayout
@@ -21,8 +23,6 @@ module Potion
21
23
  # graphics
22
24
  Color = Android::Graphics::Color
23
25
  Typeface = Android::Graphics::Typeface
24
-
25
- ArrayList = Java::Util::ArrayList
26
26
  end
27
27
 
28
28
  #
@@ -33,6 +33,11 @@
33
33
  def clear_references
34
34
  end
35
35
 
36
+ def onCreateOptionsMenu(menu)
37
+ on_create_menu(menu)
38
+ end
39
+ def on_create_menu(_); end
40
+
36
41
  end
37
42
 
38
43
  #end
@@ -0,0 +1,83 @@
1
+ class PMHashBundle
2
+ KEYS_KEY = "pm_hash_bundle_hash_keys"
3
+ VALUE_TYPES_KEY = "pm_hash_bundle_value_types"
4
+
5
+ def initialize(bundle, hash)
6
+ @bundle = bundle
7
+ @hash = hash
8
+ end
9
+
10
+ def to_bundle
11
+ @bundle
12
+ end
13
+
14
+ def to_h
15
+ @hash
16
+ end
17
+
18
+ class << self
19
+
20
+ def from_bundle(bundle)
21
+ #hash_keys = fragment_arguments.getStringArrayList("hash_keys")
22
+ h = {}
23
+
24
+ keys = bundle.getStringArrayList(PMHashBundle::KEYS_KEY)
25
+ value_types = bundle.getStringArrayList(PMHashBundle::VALUE_TYPES_KEY)
26
+
27
+ keys.each_with_index do |key, i|
28
+ value_type = value_types[i]
29
+
30
+ value = case value_type
31
+ when "com.rubymotion.String"
32
+ bundle.getString(key)
33
+ when "java.lang.Integer"
34
+ bundle.getInt(key)
35
+ when "java.lang.Double"
36
+ bundle.getFloat(key)
37
+ when "java.util.ArrayList"
38
+ bundle.getStringArrayList(key)
39
+ # TODO, do more types
40
+ else
41
+ raise "[BluePotion ERROR] In PMHashBundle#from_hash: invalid type for: #{key}"
42
+ end
43
+
44
+ h[key.to_sym] = value
45
+ end
46
+
47
+ PMHashBundle.new(bundle, h)
48
+ end
49
+
50
+ def from_hash(h)
51
+ bundle = Potion::Bundle.new
52
+ keys = h.keys.map(&:to_s)
53
+ values = h.values
54
+ value_types = h.values.map do |value|
55
+ value.class.name
56
+ end
57
+ bundle.putStringArrayList(PMHashBundle::KEYS_KEY, keys)
58
+ bundle.putStringArrayList(PMHashBundle::VALUE_TYPES_KEY, value_types)
59
+
60
+ keys.each_with_index do |key, i|
61
+ value_type = value_types[i]
62
+ value = values[i]
63
+
64
+ case value_type
65
+ when "com.rubymotion.String"
66
+ bundle.putString(key, value)
67
+ when "java.lang.Integer"
68
+ bundle.putInt(key, value)
69
+ when "java.lang.Double"
70
+ bundle.putFloat(key, value)
71
+ when "java.util.ArrayList"
72
+ value = value.map{|o| o.to_s}
73
+ bundle.putStringArrayList(key, value)
74
+ # TODO, do more types
75
+ else
76
+ raise "[BluePotion ERROR] In PMHashBundle#from_hash: invalid type for: #{key}"
77
+ end
78
+ end
79
+
80
+ PMHashBundle.new(bundle, h)
81
+ end
82
+ end
83
+ end
@@ -6,6 +6,12 @@
6
6
 
7
7
  attr_accessor :view
8
8
 
9
+ def onAttach(activity); super; on_attach(activity); end
10
+ def on_attach(activity); end
11
+
12
+ def onCreate(bundle); super; on_create(bundle); end
13
+ def on_create(bundle); end
14
+
9
15
  def onCreateView(inflater, parent, saved_instance_state)
10
16
  super
11
17
 
@@ -18,8 +24,11 @@
18
24
 
19
25
  action_bar.hide if hide_action_bar?
20
26
 
27
+ on_create_view(inflater, parent, saved_instance_state)
28
+
21
29
  @view
22
30
  end
31
+ def on_create_view(inflater, parent, saved_instance_state); end
23
32
 
24
33
  def load_view
25
34
  Potion::FrameLayout.new(self.activity)
@@ -45,8 +54,34 @@
45
54
  self.activity.title = self.class.bars_title
46
55
 
47
56
  on_load
57
+ on_activity_created
48
58
  end
59
+ def on_load; end
60
+ def on_activity_created; end
61
+
62
+ def onStart; super; on_start; end
63
+ def on_start; end
64
+ alias :on_appear :on_start
65
+
66
+ def onResume; super; on_resume; end
67
+ def on_resume; end
68
+
69
+ def on_create_menu(menu); end
70
+
71
+ def onPause; super; on_pause; end
72
+ def on_pause; end
73
+
74
+ def onStop; super; on_stop; end
75
+ def on_stop; end
76
+
77
+ def onDestroyView; super; on_destroy_view; end
78
+ def on_destroy_view; end
79
+
80
+ def onDestroy; super; on_destroy; end
81
+ def on_destroy; end
49
82
 
83
+ def onDetach; super; on_detach; end
84
+ def on_detach; end
50
85
 
51
86
  private
52
87
 
@@ -18,13 +18,16 @@
18
18
  @rmq_style_sheet_class
19
19
  end
20
20
 
21
- def uses_xml(xml_resource=nil)
21
+ def xml_layout(xml_resource=nil)
22
22
  @xml_resource = xml_resource ||= deduce_resource_id
23
23
  end
24
+ alias_method :uses_xml, :xml_layout
24
25
 
25
- def uses_action_bar(show_action_bar)
26
+ def action_bar(show_action_bar)
26
27
  @show_action_bar = show_action_bar
27
28
  end
29
+ alias_method :nav_bar, :action_bar
30
+ alias_method :uses_action_bar, :action_bar
28
31
 
29
32
  def title(new_title)
30
33
  @bars_title = new_title
@@ -105,7 +108,7 @@
105
108
 
106
109
  def open(screen_class, options={})
107
110
  mp "ScreenModule open", debugging_only: true
108
- activity_class = options[:activity] || PMSingleFragmentActivity
111
+ activity_class = options.delete(:activity) || PMSingleFragmentActivity
109
112
 
110
113
  # TODO: replace the fragment in the activity when possible
111
114
  # replace the fragment if we can; otherwise launch a new activity
@@ -115,16 +118,26 @@
115
118
  intent = Android::Content::Intent.new(self.activity, activity_class)
116
119
  intent.putExtra PMSingleFragmentActivity::EXTRA_FRAGMENT_CLASS, screen_class.to_s
117
120
 
118
- ## TODO: limited support for extras for now - should reimplement with fragment arguments
119
- if options[:extras]
120
- options[:extras].keys.each do |key|
121
- intent.putExtra key.to_s, options[:extras][key].toString
121
+ if extras = options.delete(:extras)
122
+ extras.keys.each do |key, value|
123
+ # TODO, cahnge to bundle and do like below
124
+ intent.putExtra key.to_s, value.toString
122
125
  end
123
126
  end
124
127
 
128
+ unless options.blank?
129
+ # The rest of the options are screen accessors, we use fragment arguments for this
130
+ hash_bundle = PMHashBundle.from_hash(options)
131
+ intent.putExtra PMSingleFragmentActivity::EXTRA_FRAGMENT_ARGUMENTS, hash_bundle.to_bundle
132
+ end
133
+
125
134
  self.activity.startActivity intent
126
135
  end
127
136
 
137
+ def close(options={})
138
+ self.activity.finish
139
+ end
140
+
128
141
  def start_activity(activity_class)
129
142
  intent = Android::Content::Intent.new(self.activity, activity_class)
130
143
  #intent.putExtra("key", value); # Optional parameters
@@ -154,5 +167,31 @@
154
167
  activity.getActionBar()
155
168
  end
156
169
 
170
+ def menu
171
+ activity.menu
172
+ end
173
+
174
+ # Example: add_action_bar_button(title: "My text", show: :if_room)
175
+ def add_action_bar_button(options={})
176
+ unless menu
177
+ mp "#{self.inspect}#add_action_bar_button: No menu set up yet."
178
+ return
179
+ end
180
+
181
+ options[:show] ||= :always
182
+
183
+ # Should be something like Android::MenuItem::SHOW_AS_ACTION_IF_ROOM
184
+ show_as_action = 0 if options[:show] == :never
185
+ show_as_action = 1 if options[:show] == :if_room
186
+ show_as_action = 2 if options[:show] == :always
187
+ show_as_action = 4 if options[:show] == :with_text
188
+ show_as_action = 8 if options[:show] == :collapse
189
+
190
+ btn = self.activity.menu.add(options.fetch(:group, 0), options.fetch(:item_id, 0), options.fetch(:order, 0), options.fetch(:title, "Untitled"))
191
+ btn.setShowAsAction(show_as_action) if show_as_action
192
+ btn.setIcon(options[:icon]) if options[:icon]
193
+ btn
194
+ end
195
+
157
196
  end
158
197
  #end
@@ -2,9 +2,10 @@
2
2
  # RM-733
3
3
  #module ProMotion
4
4
  class PMSingleFragmentActivity < PMActivity
5
- attr_accessor :fragment_container, :fragment
5
+ attr_accessor :fragment_container, :fragment, :menu
6
6
 
7
7
  EXTRA_FRAGMENT_CLASS = "fragment_class"
8
+ EXTRA_FRAGMENT_ARGUMENTS = "fragment_arguments"
8
9
 
9
10
  def on_create(saved_instance_state)
10
11
  super
@@ -16,8 +17,18 @@
16
17
  self.contentView = @fragment_container
17
18
 
18
19
  if (fragment_class = intent.getStringExtra(EXTRA_FRAGMENT_CLASS))
19
- # TODO weird way to create this intance, look at this later
20
- set_fragment Kernel.const_get(fragment_class.to_s).new
20
+ if fragment_instance = Kernel.const_get(fragment_class.to_s).new
21
+ set_fragment fragment_instance
22
+
23
+ # Grab the fragment arguments and call them on the class
24
+ if fragment_arguments = intent.getBundleExtra(EXTRA_FRAGMENT_ARGUMENTS)
25
+ fragment_arguments = PMHashBundle.from_bundle(fragment_arguments).to_h
26
+
27
+ fragment_arguments.each do |key, value|
28
+ fragment_instance.send "#{key}=", value
29
+ end
30
+ end
31
+ end
21
32
  end
22
33
  end
23
34
 
@@ -27,5 +38,10 @@
27
38
  fragmentManager.beginTransaction.add(@fragment_container.getId, fragment, fragment.class.to_s).commit
28
39
  end
29
40
 
41
+ def on_create_menu(menu)
42
+ @menu = menu
43
+ self.fragment.on_create_menu(menu) if self.fragment
44
+ end
45
+
30
46
  end
31
47
  #end
@@ -2,13 +2,17 @@ class RMQ
2
2
  # I'm purposly not including Enumerable,
3
3
  # please use to_a if you want one
4
4
 
5
-
6
5
  # @return [RMQ]
7
6
  def <<(value)
8
7
  selected << value if value.is_a?(UIView)
9
8
  self
10
9
  end
11
10
 
11
+ def empty?
12
+ selected.length == 0
13
+ end
14
+ alias :is_blank? :empty?
15
+
12
16
  # @return [RMQ]
13
17
  #
14
18
  # @example
@@ -0,0 +1,23 @@
1
+ class RMQClickBase
2
+ attr_accessor :click_block
3
+
4
+ def initialize(&block)
5
+ @click_block = block
6
+ end
7
+ end
8
+
9
+ class RMQClick < RMQClickBase
10
+
11
+ def onClick(view)
12
+ click_block.call(view)
13
+ end
14
+
15
+ end
16
+
17
+ class RMQItemClick < RMQClickBase
18
+
19
+ def onItemClick(parent, view, position, id)
20
+ click_block.call(parent, view, position, id)
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ class RMQSeekChange
2
+ attr_accessor :change_block
3
+
4
+ def initialize(action=:change, &block)
5
+ @action = action
6
+ # Empty hash from RMQ Events means we keep our default
7
+ @action = :change if @action == {}
8
+ @change_block = block
9
+ end
10
+
11
+ def onStopTrackingTouch(seek_bar)
12
+ @change_block.call(seek_bar) if @action == :stop
13
+ end
14
+
15
+ def onStartTrackingTouch(seek_bar)
16
+ @change_block.call(seek_bar) if @action == :start
17
+ end
18
+
19
+ def onProgressChanged(seek_bar, progress, from_user)
20
+ @change_block.call(seek_bar, progress, from_user) if @action == :change
21
+ end
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ # http://developer.android.com/reference/android/text/TextWatcher.html
2
+ # there seems to be a bug with this particular interface - subclassing this class works around it
3
+ # http://community.rubymotion.com/t/how-to-use-textwatcher-to-listen-to-changes-of-an-edittext/522
4
+ class RMQTextChange < Android::Telephony::PhoneNumberFormattingTextWatcher
5
+ attr_accessor :change_block
6
+
7
+ def initialize(action=:after, &block)
8
+ @action = action
9
+ @change_block = block
10
+ end
11
+
12
+ def onTextChanged(s, start, before, count)
13
+ @change_block.call(s, start, before, count) if @action == :on
14
+ end
15
+
16
+ def beforeTextChanged(s, start, count, after)
17
+ @change_block.call(s, start, count, after) if @action == :before
18
+ end
19
+
20
+ def afterTextChanged(s)
21
+ @change_block.call(s) if @action == :after
22
+ end
23
+
24
+ end
@@ -1,28 +1,41 @@
1
1
  class RMQ
2
2
  def on(event, args={}, &block)
3
3
  self.selected.each do |view|
4
-
5
4
  case event
6
5
  when :click, :tap, :touch
7
- view.onClickListener = RMQClickHandler.new(&block)
6
+ handle_click(view, &block)
7
+ when :change
8
+ handle_change(view, &block)
8
9
  else
9
10
  raise "[RMQ ERROR] Unrecognized event: #{event}"
10
11
  end
11
-
12
12
  end
13
13
 
14
14
  end
15
- end
16
15
 
17
- class RMQClickHandler
18
- attr_accessor :click_block
16
+ private
19
17
 
20
- def initialize(&block)
21
- @click_block = block
18
+ def handle_click(view, &block)
19
+ # Click event for ListItems
20
+ if view.respond_to? :setOnItemClickListener
21
+ view.onItemClickListener = RMQItemClick.new(&block)
22
+ # Generic Click
23
+ else
24
+ view.onClickListener = RMQClick.new(&block)
25
+ end
22
26
  end
23
27
 
24
- def onClick(view)
25
- click_block.call(view)
28
+ def handle_change(view, &block)
29
+ # Seek bar change
30
+ if view.respond_to? :setOnSeekBarChangeListener
31
+ view.onSeekBarChangeListener = RMQSeekChange.new(args, &block)
32
+ # Text change
33
+ elsif view.respond_to? :addTextChangeListener
34
+ view.addTextChangedListener(RMQTextChange.new(&block))
35
+ end
26
36
  end
27
37
 
28
38
  end
39
+
40
+
41
+
@@ -4,6 +4,7 @@ class RMQImageViewStyler < RMQViewStyler
4
4
  @view.imageResource = resource_id
5
5
  end
6
6
  alias_method :image=, :image_resource=
7
+ alias_method :src=, :image_resource=
7
8
 
8
9
  def adjust_view_bounds=(adjust_view_bounds)
9
10
  @view.adjustViewBounds = adjust_view_bounds
@@ -21,9 +21,9 @@ class RMQLinearLayoutStyler < RMQViewStyler
21
21
  def convert_orientation(orientation)
22
22
  case orientation
23
23
  when :horizontal
24
- Android::Widget::LinearLayout::HORIZONTAL
24
+ Potion::LinearLayout::HORIZONTAL
25
25
  when :vertical
26
- Android::Widget::LinearLayout::VERTICAL
26
+ Potion::LinearLayout::VERTICAL
27
27
  else
28
28
  orientation
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module BluePotion
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluepotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfiniteRed
8
+ - ClearSight Studio
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-05-31 00:00:00.000000000 Z
12
+ date: 2015-06-03 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
@@ -27,6 +28,7 @@ dependencies:
27
28
  description: BluePotion - Just like RedPotion, but for Android
28
29
  email:
29
30
  - hello@infinitered.com
31
+ - hello@clearsightstudio.com
30
32
  executables:
31
33
  - bluepotion
32
34
  extensions: []
@@ -38,12 +40,14 @@ files:
38
40
  - lib/project/ext/activity.rb
39
41
  - lib/project/ext/array_list.rb
40
42
  - lib/project/ext/fragment.rb
43
+ - lib/project/ext/nil.rb
41
44
  - lib/project/ext/object.rb
42
45
  - lib/project/ext/string.rb
43
46
  - lib/project/ext/view.rb
44
47
  - lib/project/potion.rb
45
48
  - lib/project/pro_motion/pm_activity.rb
46
49
  - lib/project/pro_motion/pm_application.rb
50
+ - lib/project/pro_motion/pm_hash_bundle.rb
47
51
  - lib/project/pro_motion/pm_home_activity.rb
48
52
  - lib/project/pro_motion/pm_screen.rb
49
53
  - lib/project/pro_motion/pm_screen_module.rb
@@ -53,6 +57,9 @@ files:
53
57
  - lib/project/ruby_motion_query/rmq/data.rb
54
58
  - lib/project/ruby_motion_query/rmq/debug.rb
55
59
  - lib/project/ruby_motion_query/rmq/enumerablish.rb
60
+ - lib/project/ruby_motion_query/rmq/event_wrappers/rmq_click.rb
61
+ - lib/project/ruby_motion_query/rmq/event_wrappers/rmq_seek_change.rb
62
+ - lib/project/ruby_motion_query/rmq/event_wrappers/rmq_text_change.rb
56
63
  - lib/project/ruby_motion_query/rmq/events.rb
57
64
  - lib/project/ruby_motion_query/rmq/factory.rb
58
65
  - lib/project/ruby_motion_query/rmq/position.rb