bubble-wrap 1.5.0 → 1.6.0.rc1

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: 4070f3da9b1e9a37c918c5da7aead8bff4fd4b4e
4
- data.tar.gz: e654090e81f9ab2b0d2618b95ac3e33935a3bb46
3
+ metadata.gz: 601f1626c9a3a557c7120181febf1f2acf29ecd1
4
+ data.tar.gz: 53ea079e1921fe8d05d3ec03f98f4496d19d2040
5
5
  SHA512:
6
- metadata.gz: d51233858de91c048f290b62989d1a5dce864044ec28465e33582fb65c46baf8008b2209eb77086a870b399b8537468b46d2a1618c697a3f744806a99ea2a778
7
- data.tar.gz: bdd4ea650406adfc467181c9a38ea069ad886b0f14e6a91bfc703923104f61013dc40d577f15aafd54fa3dfc635e6eb29ffda2b1b30e2ce5c7fb162fa7f5fea8
6
+ metadata.gz: b95bf54c3049c7ba4e5bf97df0593195bd63588bc541beb40179f2ccac93eeb1fd33d99d0778facb8d7e20635775e21a32674509fd1bbbf51eb28b34513699d1
7
+ data.tar.gz: 1ba1653a02a10eca8ff65529afe6d6afc0946fc4b4dbce45545afef2728334aaad163f5fb59fbf8cd8b4e7ca9db083377ff143b510ea6181318b3f8d908388a4
@@ -3,4 +3,9 @@ before_install:
3
3
  - (ruby --version)
4
4
  - mkdir -p ~/Library/RubyMotion/build
5
5
  - sudo motion update
6
- script: ./travis.sh
6
+ script:
7
+ - bundle install
8
+ - bundle exec rake clean
9
+ - bundle exec rake spec
10
+ - bundle exec rake clean
11
+ - bundle exec rake spec osx=true
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bubble-wrap (1.5.0)
4
+ bubble-wrap (1.6.0.rc1)
5
+ bubble-wrap-http (= 1.6.0.rc1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  bacon (1.1.0)
11
+ bubble-wrap-http (1.6.0.rc1)
10
12
  metaclass (0.0.1)
11
13
  mocha (0.11.4)
12
14
  metaclass (~> 0.0.1)
data/README.md CHANGED
@@ -26,7 +26,7 @@ require 'bubble-wrap'
26
26
  If you using Bundler:
27
27
 
28
28
  ```ruby
29
- gem "bubble-wrap", "~> 1.4.0"
29
+ gem "bubble-wrap", "~> 1.5.0"
30
30
  ```
31
31
 
32
32
  BubbleWrap is split into multiple modules so that you can easily choose which parts
@@ -93,6 +93,12 @@ If you wish to only include the `SMS` wrapper:
93
93
  require 'bubble-wrap/sms'
94
94
  ```
95
95
 
96
+ If you wish to only include the `NetworkIndicator` wrapper:
97
+
98
+ ```ruby
99
+ require 'bubble-wrap/network-indicator'
100
+ ```
101
+
96
102
  If you want to include everything (ie kitchen sink mode) you can save time and do:
97
103
 
98
104
  ```ruby
@@ -146,6 +152,8 @@ BubbleWrap.rgb_color(23, 45, 12)
146
152
  => #<UICachedDeviceWhiteColor:0x8bb5be0>
147
153
  '#FF8A19'.to_color
148
154
  => #<UIDeviceRGBColor:0x8d54110>
155
+ '#88FF8A19'.to_color # ARGB format
156
+ => #<UIDeviceRGBColor:0xca0fe00>
149
157
  ```
150
158
 
151
159
  Debug flag:
@@ -178,7 +186,10 @@ A module with useful methods related to the running application
178
186
  > App.run_after(0.5) { p "It's #{Time.now}" }
179
187
  # Runs the block after 0.5 seconds.
180
188
  > App.open_url("http://matt.aimonetti.net")
181
- # Opens the url using the device's browser. (accepts a string url or an instance of `NSURL`.
189
+ > App.open_url("tel://123456789")
190
+ # Opens the url using the device's browser. Can also open custom URL schemas (accepts a string url or an instance of `NSURL`.)
191
+ > App.can_open_url("tel://")
192
+ # Returns whether the app can open a given URL resource.
182
193
  > App::Persistence['channels'] # application specific persistence storage
183
194
  # ['NBC', 'ABC', 'Fox', 'CBS', 'PBS']
184
195
  > App::Persistence['channels'] = ['TF1', 'France 2', 'France 3']
@@ -375,7 +386,7 @@ iso8601 formatted string into a Time instance.
375
386
 
376
387
  ## Location
377
388
 
378
- Added interface for Ruby-like GPS access:
389
+ Added interface for Ruby-like GPS and compass access:
379
390
 
380
391
  ```ruby
381
392
  BW::Location.get do |result|
@@ -384,6 +395,15 @@ BW::Location.get do |result|
384
395
  end
385
396
  ```
386
397
 
398
+ ```ruby
399
+ BW::Location.get_compass do |result|
400
+ p result[:magnetic_heading] # Heading towards magnetic north
401
+ p result[:true_heading] # Heading towards true north
402
+ p result[:accuracy] # Potential error between magnetic and true heading
403
+ p result[:timestamp] # Timestamp of the heading calculation
404
+ end
405
+ ```
406
+
387
407
  Also available is `BW::Location.get_significant`, for monitoring significant location changes.
388
408
 
389
409
  ## Media
@@ -443,7 +463,36 @@ Wrapper for showing an in-app message (SMS) composer view.
443
463
  result.canceled? # => boolean
444
464
  result.failed? # => boolean
445
465
  error # => NSError
446
- }
466
+ }
467
+ ```
468
+
469
+ ## NetworkIndicator
470
+
471
+ Wrapper for showing and hiding the network indicator (the status bar spinner).
472
+
473
+ ```ruby
474
+ BW::NetworkIndicator.show # starts the spinner
475
+ BW::NetworkIndicator.hide # stops it
476
+
477
+ # the nice thing is if you call 'show' multiple times, the 'hide' method will
478
+ # not have any effect until you've called it the same number of times.
479
+ BW::NetworkIndicator.show
480
+ # ...somewhere else
481
+ BW::NetworkIndicator.show
482
+
483
+ # ...down the line
484
+ BW::NetworkIndicator.hide
485
+ # indicator is still visible
486
+
487
+ BW::NetworkIndicator.hide
488
+ # NOW the indicator is hidden!
489
+
490
+ # If you *really* want to hide the indicator immediately, you can call `reset!`
491
+ # but this is in no way encouraged.
492
+ BW::NetworkIndicator.reset!
493
+
494
+ # and for completeness, a check to see if the indicator is visible
495
+ BW::NetworkIndicator.visible?
447
496
  ```
448
497
 
449
498
  ## UI
@@ -594,6 +643,50 @@ And the `.system` button types are:
594
643
  :page_curl
595
644
  ```
596
645
 
646
+ ### UIActivityViewController
647
+
648
+ `BW::UIActivityViewController` is a subclass of `UIActivityViewController` with an natural Ruby syntax.
649
+
650
+ You can initiate a `UIActivityViewController` with or without a completion handler block. For more information on `UIActivityViewController`s, see [Apple's documentation](https://developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html).
651
+
652
+ ```ruby
653
+ # Without a completion handler
654
+ BW::UIActivityViewController.new(
655
+ items: "Some Text", # or ["Some Text", NSURL.URLWithString('http://www.rubymotion.com')] or a UIImage
656
+ animated: true, # Defaults to true
657
+ excluded: :add_to_reading_list # One item or an array
658
+ )
659
+
660
+ # With completion handler
661
+ BW::UIActivityViewController.new(
662
+ items: "Some Text",
663
+ animated: true,
664
+ excluded: [:add_to_reading_list, :print, :air_drop]
665
+ ) do |activity_type, completed|
666
+ puts "completed with activity: #{activity_type} - finished?: #{completed}"
667
+ end
668
+ ```
669
+
670
+ Built in activities that can be passed to the `excluded` option are defined as `UIActivity` class `UIActivityType` constants:
671
+
672
+ ```ruby
673
+ :post_to_facebook
674
+ :post_to_twitter
675
+ :post_to_weibo
676
+ :message
677
+ :mail
678
+ :print
679
+ :copy_to_pasteboard
680
+ :assign_to_contact
681
+ :save_to_camera_roll
682
+ :add_to_reading_list
683
+ :post_to_flickr
684
+ :post_to_vimeo
685
+ :post_to_tencent_weibo
686
+ :air_drop
687
+ ```
688
+
689
+
597
690
  ## HTTP
598
691
 
599
692
  `BW::HTTP` wraps `NSURLRequest`, `NSURLConnection` and friends to provide Ruby developers with a more familiar and easier to use API.
@@ -677,7 +770,7 @@ class HttpClient
677
770
  BW::HTTP.get(user_url(user_id)) do |response|
678
771
  # ..
679
772
  end
680
- end
773
+ end
681
774
  end
682
775
  ```
683
776
 
data/Rakefile CHANGED
@@ -28,7 +28,7 @@ Motion::Project::App.setup do |app|
28
28
  app.spec_files
29
29
  if Motion::Project::App.osx?
30
30
  app.spec_files -= Dir.glob("./spec/motion/**/ios/**.rb")
31
- ["font", "location", "media", "ui", "mail", "sms"].each do |package|
31
+ ["font", "location", "media", "ui", "mail", "sms", "network-indicator"].each do |package|
32
32
  app.spec_files -= Dir.glob("./spec/motion/#{package}/**/*.rb")
33
33
  end
34
34
  else
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.extra_rdoc_files = gem.files.grep(%r{motion})
18
18
 
19
+ gem.add_dependency 'bubble-wrap-http', BubbleWrap::VERSION
19
20
  gem.add_development_dependency 'mocha', '0.11.4'
20
21
  gem.add_development_dependency 'mocha-on-bacon'
21
22
  gem.add_development_dependency 'bacon'
@@ -1,4 +1,4 @@
1
1
  require File.expand_path('../loader', __FILE__)
2
- ['core', 'http', 'reactor', 'rss_parser', 'ui', 'location', 'media', 'font', 'mail','sms'].each { |sub|
2
+ ['core', 'http', 'reactor', 'rss_parser', 'ui', 'location', 'media', 'font', 'mail','sms', 'network-indicator'].each { |sub|
3
3
  require File.expand_path("../#{sub}", __FILE__)
4
4
  }
@@ -1,7 +1,7 @@
1
1
  require 'bubble-wrap/version' unless defined?(BubbleWrap::VERSION)
2
2
  require 'bubble-wrap/loader'
3
- BubbleWrap.require('motion/core/ns_url_request.rb')
4
- BubbleWrap.require('motion/core.rb')
5
- BubbleWrap.require('motion/http.rb')
6
- BubbleWrap.require('motion/http/query.rb')
7
- BubbleWrap.require('motion/http/response.rb')
3
+ require 'bubble-wrap/network-indicator'
4
+ require 'bubble-wrap-http'
5
+ Motion::Project::App.warn "BubbleWrap::HTTP is deprecated and will be removed, see https://github.com/rubymotion/BubbleWrap/issues/308"
6
+ Motion::Project::App.warn "Switch to a different networking library soon - consider AFNetworking: http://afnetworking.com/"
7
+ Motion::Project::App.warn "You can use the 'bubble-wrap-http' gem if you need compatibility: https://github.com/rubymotion/BubbleWrap-HTTP"
@@ -0,0 +1,6 @@
1
+ require 'bubble-wrap/loader'
2
+
3
+ BubbleWrap.require_ios("network-indicator") do
4
+ BubbleWrap.require('motion/core/app.rb')
5
+ BubbleWrap.require('motion/network-indicator/**/*.rb')
6
+ end
@@ -1,6 +1,7 @@
1
1
  require 'bubble-wrap/loader'
2
2
 
3
3
  BubbleWrap.require_ios("ui") do
4
+ BubbleWrap.require('motion/util/constants.rb')
4
5
  BubbleWrap.require('motion/ui/**/*.rb') do
5
6
  file('motion/ui/pollute.rb').depends_on %w(
6
7
  motion/ui/ui_control_wrapper.rb
@@ -1,4 +1,4 @@
1
1
  module BubbleWrap
2
- VERSION = '1.5.0' unless defined?(BubbleWrap::VERSION)
2
+ VERSION = '1.6.0.rc1' unless defined?(BubbleWrap::VERSION)
3
3
  MIN_MOTION_VERSION = '2.17'
4
4
  end
@@ -9,6 +9,9 @@ module BubbleWrap
9
9
  # @return [UIcolor]
10
10
  def rgba_color(r,g,b,a)
11
11
  r,g,b = [r,g,b].map { |i| i / 255.0}
12
+ if a > 1.0
13
+ a = a / 255.0
14
+ end
12
15
  if App.osx?
13
16
  NSColor.colorWithDeviceRed(r, green: g, blue: b, alpha: a)
14
17
  else
@@ -3,9 +3,10 @@ module BubbleWrap
3
3
  module_function
4
4
 
5
5
  # Opens an url (string or instance of `NSURL`)
6
- # in the device's web browser.
6
+ # in the device's web browser or in the correspondent app for custom schemas
7
7
  # Usage Example:
8
8
  # App.open_url("http://matt.aimonetti.net")
9
+ # App.open_url("fb://profile")
9
10
  def open_url(url)
10
11
  unless url.is_a?(NSURL)
11
12
  url = NSURL.URLWithString(url)
@@ -13,6 +14,17 @@ module BubbleWrap
13
14
  UIApplication.sharedApplication.openURL(url)
14
15
  end
15
16
 
17
+ # Returns whether an app can open a given URL resource (string or instance of `NSURL`)
18
+ # Useful to check if certain apps are installed before calling to their custom schemas.
19
+ # Usage Example:
20
+ # App.open_url("fb://profile") if App.can_open_url("fb://")
21
+ def can_open_url(url)
22
+ unless url.is_a?(NSURL)
23
+ url = NSURL.URLWithString(url)
24
+ end
25
+ UIApplication.sharedApplication.canOpenURL(url)
26
+ end
27
+
16
28
  # Displays a UIAlertView.
17
29
  #
18
30
  # title - The title as a String.
@@ -80,4 +92,4 @@ module BubbleWrap
80
92
  key_window || normal_windows.first
81
93
  end
82
94
  end
83
- end
95
+ end
@@ -58,11 +58,15 @@ module BubbleWrap
58
58
  colors = hex_color.scan(%r{[0-9A-Fa-f]}).map!{ |el| (el * 2).to_i(16) }
59
59
  when 6
60
60
  colors = hex_color.scan(%r<[0-9A-Fa-f]{2}>).map!{ |el| el.to_i(16) }
61
+ when 8
62
+ colors = hex_color.scan(%r<[0-9A-Fa-f]{2}>).map!{ |el| el.to_i(16) }
61
63
  else
62
64
  raise ArgumentError
63
65
  end
64
66
  if colors.size == 3
65
67
  BubbleWrap.rgb_color(colors[0], colors[1], colors[2])
68
+ elsif colors.size == 4
69
+ BubbleWrap.rgba_color(colors[1], colors[2], colors[3], colors[0])
66
70
  else
67
71
  raise ArgumentError
68
72
  end
@@ -70,6 +70,8 @@ module BubbleWrap
70
70
 
71
71
  if @options[:significant]
72
72
  self.location_manager.startMonitoringSignificantLocationChanges
73
+ elsif @options[:compass]
74
+ self.location_manager.startUpdatingHeading
73
75
  else
74
76
  self.location_manager.startUpdatingLocation
75
77
  end
@@ -83,10 +85,21 @@ module BubbleWrap
83
85
  get(options.merge(once: true), &block)
84
86
  end
85
87
 
88
+ def get_compass(options = {}, &block)
89
+ get(options.merge(compass: true), &block)
90
+ end
91
+
92
+ def get_compass_once(options = {}, &block)
93
+ get_compass(options.merge(once: true), &block)
94
+ end
95
+
86
96
  # Stop getting locations
87
97
  def stop
98
+ return unless @options
88
99
  if @options[:significant]
89
100
  self.location_manager.stopMonitoringSignificantLocationChanges
101
+ elsif @options[:compass]
102
+ self.location_manager.stopUpdatingHeading
90
103
  else
91
104
  self.location_manager.stopUpdatingLocation
92
105
  end
@@ -121,6 +134,23 @@ module BubbleWrap
121
134
  end
122
135
  end
123
136
 
137
+ def locationManager(manager, didUpdateHeading:newHeading)
138
+ heading = {
139
+ magnetic_heading: newHeading.magneticHeading,
140
+ true_heading: newHeading.trueHeading,
141
+ accuracy: newHeading.headingAccuracy,
142
+ timestamp: newHeading.timestamp,
143
+ }
144
+
145
+ if @options[:once]
146
+ @callback && @callback.call(heading)
147
+ @callback = proc { |result| }
148
+ stop
149
+ else
150
+ @callback && @callback.call(heading)
151
+ end
152
+ end
153
+
124
154
  def locationManager(manager, didFailWithError:error)
125
155
  if error.domain == KCLErrorDomain
126
156
  case error.code
@@ -152,4 +182,4 @@ module BubbleWrap
152
182
  end
153
183
  end
154
184
  end
155
- ::Location = BubbleWrap::Location unless defined?(::Location)
185
+ ::Location = BubbleWrap::Location unless defined?(::Location)
@@ -0,0 +1,67 @@
1
+ module BubbleWrap
2
+ module NetworkIndicator
3
+ DELAY = 0.2
4
+
5
+ module_function
6
+
7
+ def counter
8
+ @counter ||= 0
9
+ end
10
+
11
+ def show
12
+ if Dispatch::Queue.current.to_s == 'com.apple.main-thread'
13
+ @counter = self.counter + 1
14
+ self.update_spinner
15
+ else
16
+ Dispatch::Queue.main.async do
17
+ self.show
18
+ end
19
+ end
20
+ end
21
+
22
+ def hide
23
+ if Dispatch::Queue.current.to_s == 'com.apple.main-thread'
24
+ @counter = [self.counter - 1, 0].max
25
+ if self.counter == 0
26
+ if @hide_indicator_timer
27
+ @hide_indicator_timer.invalidate
28
+ end
29
+ @hide_indicator_timer = NSTimer.timerWithTimeInterval(DELAY - 0.01, target: self, selector: :update_spinner_timer, userInfo: nil, repeats: false)
30
+ NSRunLoop.mainRunLoop.addTimer(@hide_indicator_timer, forMode:NSRunLoopCommonModes)
31
+ end
32
+ else
33
+ Dispatch::Queue.main.async do
34
+ self.hide
35
+ end
36
+ end
37
+ end
38
+
39
+ def update_spinner_timer
40
+ update_spinner
41
+ end
42
+
43
+ def update_spinner
44
+ if Dispatch::Queue.current.to_s == 'com.apple.main-thread'
45
+ if @hide_indicator_timer
46
+ @hide_indicator_timer.invalidate
47
+ @hide_indicator_timer = nil
48
+ end
49
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = (@counter > 0)
50
+ else
51
+ Dispatch::Queue.main.async do
52
+ self.update_spinner
53
+ end
54
+ end
55
+ end
56
+
57
+ def visible?
58
+ UIApplication.sharedApplication.networkActivityIndicatorVisible?
59
+ end
60
+
61
+ def reset!
62
+ @counter = 0
63
+ self.update_spinner
64
+ end
65
+
66
+ end
67
+ end