bubble-wrap 1.2.0 → 1.3.0.osx
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 +8 -8
- data/CHANGELOG.md +4 -2
- data/Gemfile.lock +1 -1
- data/README.md +217 -7
- data/Rakefile +23 -2
- data/lib/bubble-wrap/camera.rb +10 -6
- data/lib/bubble-wrap/core.rb +14 -1
- data/lib/bubble-wrap/ext/motion_project_app.rb +8 -0
- data/lib/bubble-wrap/font.rb +3 -1
- data/lib/bubble-wrap/http.rb +2 -0
- data/lib/bubble-wrap/loader.rb +17 -2
- data/lib/bubble-wrap/location.rb +9 -6
- data/lib/bubble-wrap/media.rb +10 -6
- data/lib/bubble-wrap/test.rb +6 -1
- data/lib/bubble-wrap/ui.rb +5 -2
- data/lib/bubble-wrap/version.rb +2 -7
- data/motion/core.rb +6 -1
- data/motion/core/app.rb +3 -64
- data/motion/core/device.rb +0 -55
- data/motion/core/device/{camera.rb → ios/camera.rb} +0 -0
- data/motion/core/device/{camera_wrapper.rb → ios/camera_wrapper.rb} +0 -0
- data/motion/core/device/ios/screen.rb +75 -0
- data/motion/core/device/osx/screen.rb +18 -0
- data/motion/core/device/screen.rb +1 -69
- data/motion/core/ios/app.rb +71 -0
- data/motion/core/ios/device.rb +59 -0
- data/motion/core/osx/app.rb +15 -0
- data/motion/core/osx/device.rb +6 -0
- data/motion/core/string.rb +3 -2
- data/motion/http.rb +0 -364
- data/motion/http/query.rb +367 -0
- data/motion/http/response.rb +32 -0
- data/motion/test_suite_delegate.rb +58 -0
- data/motion/ui/ui_alert_view.rb +169 -0
- data/motion/ui/ui_bar_button_item.rb +55 -53
- data/motion/util/constants.rb +34 -32
- data/samples/alert/.gitignore +16 -0
- data/samples/alert/Gemfile +3 -0
- data/samples/alert/Rakefile +10 -0
- data/samples/alert/app/app_delegate.rb +8 -0
- data/samples/alert/app/controllers/alert_view_controller.rb +74 -0
- data/samples/alert/resources/Default-568h@2x.png +0 -0
- data/samples/alert/spec/main_spec.rb +9 -0
- data/samples/media/.gitignore +16 -0
- data/samples/media/Rakefile +11 -0
- data/samples/media/app/app_delegate.rb +8 -0
- data/samples/media/app/controllers/play_controller.rb +46 -0
- data/samples/media/resources/Default-568h@2x.png +0 -0
- data/samples/media/resources/test.mp3 +0 -0
- data/samples/media/spec/main_spec.rb +9 -0
- data/samples/osx/Gemfile +3 -0
- data/samples/osx/Gemfile.lock +10 -0
- data/samples/osx/Rakefile +11 -0
- data/samples/osx/app/app_delegate.rb +69 -0
- data/samples/osx/app/menu.rb +108 -0
- data/samples/osx/resources/Credits.rtf +29 -0
- data/samples/osx/spec/main_spec.rb +9 -0
- data/spec/motion/core/app_spec.rb +5 -164
- data/spec/motion/core/device/{camera_spec.rb → ios/camera_spec.rb} +0 -0
- data/spec/motion/core/device/{camera_wrapper_spec.rb → ios/camera_wrapper_spec.rb} +0 -0
- data/spec/motion/core/device/ios/device_spec.rb +74 -0
- data/spec/motion/core/device/{screen_spec.rb → ios/screen_spec.rb} +2 -1
- data/spec/motion/core/device/osx/screen_spec.rb +26 -0
- data/spec/motion/core/device_spec.rb +0 -71
- data/spec/motion/core/ios/app_spec.rb +180 -0
- data/spec/motion/core/kvo_spec.rb +23 -7
- data/spec/motion/core/ns_index_path_spec.rb +10 -2
- data/spec/motion/core/osx/app_spec.rb +15 -0
- data/spec/motion/core/string_spec.rb +11 -5
- data/spec/motion/core_spec.rb +13 -2
- data/spec/motion/http/query_spec.rb +731 -0
- data/spec/motion/http/response_spec.rb +44 -0
- data/spec/motion/http_spec.rb +0 -722
- data/spec/motion/{core → ui}/gestures_spec.rb +0 -0
- data/spec/motion/ui/ui_alert_view_spec.rb +1188 -0
- data/spec/motion/{core → ui}/ui_bar_button_item_spec.rb +80 -24
- data/spec/motion/{core → ui}/ui_control_spec.rb +0 -0
- data/spec/motion/util/constants_spec.rb +4 -4
- metadata +86 -26
data/lib/bubble-wrap/location.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'bubble-wrap/loader'
|
2
|
-
|
3
|
-
BubbleWrap.
|
4
|
-
BubbleWrap.require('motion/
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
|
3
|
+
BubbleWrap.require_ios("location") do
|
4
|
+
BubbleWrap.require('motion/util/constants.rb')
|
5
|
+
BubbleWrap.require('motion/core/string.rb')
|
6
|
+
BubbleWrap.require('motion/location/**/*.rb') do
|
7
|
+
file('motion/location/pollute.rb').depends_on 'motion/location/location.rb'
|
8
|
+
file('motion/location/location.rb').depends_on 'motion/util/constants.rb'
|
9
|
+
file('motion/location/location.rb').uses_framework('CoreLocation')
|
10
|
+
end
|
8
11
|
end
|
data/lib/bubble-wrap/media.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'bubble-wrap/loader'
|
2
|
-
|
3
|
-
BubbleWrap.
|
4
|
-
BubbleWrap.require('motion/
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
|
3
|
+
BubbleWrap.require_ios("media") do
|
4
|
+
BubbleWrap.require('motion/core/app.rb')
|
5
|
+
BubbleWrap.require('motion/core/string.rb')
|
6
|
+
BubbleWrap.require('motion/core/ns_notification_center.rb')
|
7
|
+
BubbleWrap.require('motion/media/**/*.rb') do
|
8
|
+
file('motion/media/media.rb').depends_on('motion/media/player.rb')
|
9
|
+
file('motion/media/player.rb').depends_on 'motion/core/string.rb'
|
10
|
+
file('motion/media/player.rb').uses_framework('MediaPlayer')
|
11
|
+
end
|
8
12
|
end
|
data/lib/bubble-wrap/test.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'bubble-wrap/loader'
|
2
|
+
BW.require 'motion/util/*.rb'
|
2
3
|
BW.require 'motion/test_suite_delegate.rb'
|
3
4
|
|
4
5
|
Motion::Project::App.setup do |app|
|
5
6
|
app.development do
|
6
|
-
|
7
|
+
if Motion::Project::App.osx?
|
8
|
+
app.delegate_class = 'TestSuiteOSXDelegate'
|
9
|
+
else
|
10
|
+
app.delegate_class = 'TestSuiteDelegate'
|
11
|
+
end
|
7
12
|
end
|
8
13
|
end
|
data/lib/bubble-wrap/ui.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'bubble-wrap/loader'
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
BubbleWrap.require_ios("ui") do
|
4
|
+
BubbleWrap.require('motion/ui/**/*.rb') do
|
5
|
+
file('motion/ui/pollute.rb').depends_on 'motion/ui/ui_control.rb'
|
6
|
+
end
|
4
7
|
end
|
data/lib/bubble-wrap/version.rb
CHANGED
@@ -1,9 +1,4 @@
|
|
1
1
|
module BubbleWrap
|
2
|
-
VERSION = '1.
|
3
|
-
MIN_MOTION_VERSION = '1.
|
4
|
-
|
5
|
-
module_function
|
6
|
-
def minor_version(version_str)
|
7
|
-
version_str.split(".")[1].to_i
|
8
|
-
end
|
2
|
+
VERSION = '1.3.0.osx' unless defined?(BubbleWrap::VERSION)
|
3
|
+
MIN_MOTION_VERSION = '1.36'
|
9
4
|
end
|
data/motion/core.rb
CHANGED
@@ -8,7 +8,12 @@ module BubbleWrap
|
|
8
8
|
|
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 App.osx?
|
13
|
+
NSColor.colorWithDeviceRed(r, green: g, blue: b, alpha: a)
|
14
|
+
else
|
15
|
+
UIColor.colorWithRed(r, green: g, blue:b, alpha:a)
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
def localized_string(key, value)
|
data/motion/core/app.rb
CHANGED
@@ -26,34 +26,6 @@ module BubbleWrap
|
|
26
26
|
NSUserDefaults.standardUserDefaults
|
27
27
|
end
|
28
28
|
|
29
|
-
# Displays a UIAlertView.
|
30
|
-
#
|
31
|
-
# title - The title as a String.
|
32
|
-
# args - The title of the cancel button as a String, or a Hash of options.
|
33
|
-
# (Default: { cancel_button_title: 'OK' })
|
34
|
-
# cancel_button_title - The title of the cancel button as a String.
|
35
|
-
# message - The main message as a String.
|
36
|
-
# block - Yields the alert object if a block is given, and does so before the alert is shown.
|
37
|
-
def alert(title, *args, &block)
|
38
|
-
options = { cancel_button_title: 'OK' }
|
39
|
-
options.merge!(args.pop) if args.last.is_a?(Hash)
|
40
|
-
|
41
|
-
if args.size > 0 && args.first.is_a?(String)
|
42
|
-
options[:cancel_button_title] = args.shift
|
43
|
-
end
|
44
|
-
|
45
|
-
alert = UIAlertView.alloc.initWithTitle title,
|
46
|
-
message: options[:message],
|
47
|
-
delegate: nil,
|
48
|
-
cancelButtonTitle: options[:cancel_button_title],
|
49
|
-
otherButtonTitles: nil
|
50
|
-
|
51
|
-
yield(alert) if block_given?
|
52
|
-
|
53
|
-
alert.show
|
54
|
-
alert
|
55
|
-
end
|
56
|
-
|
57
29
|
# Executes a block after a certain delay
|
58
30
|
# Usage example:
|
59
31
|
# App.run_after(0.5) { p "It's #{Time.now}" }
|
@@ -65,17 +37,6 @@ module BubbleWrap
|
|
65
37
|
repeats: false)
|
66
38
|
end
|
67
39
|
|
68
|
-
# Opens an url (string or instance of `NSURL`)
|
69
|
-
# in the device's web browser.
|
70
|
-
# Usage Example:
|
71
|
-
# App.open_url("http://matt.aimonetti.net")
|
72
|
-
def open_url(url)
|
73
|
-
unless url.is_a?(NSURL)
|
74
|
-
url = NSURL.URLWithString(url)
|
75
|
-
end
|
76
|
-
UIApplication.sharedApplication.openURL(url)
|
77
|
-
end
|
78
|
-
|
79
40
|
@states = {}
|
80
41
|
|
81
42
|
def states
|
@@ -94,31 +55,6 @@ module BubbleWrap
|
|
94
55
|
NSBundle.mainBundle.infoDictionary['CFBundleVersion']
|
95
56
|
end
|
96
57
|
|
97
|
-
# Return application frame
|
98
|
-
def frame
|
99
|
-
UIScreen.mainScreen.applicationFrame
|
100
|
-
end
|
101
|
-
|
102
|
-
# Main Screen bounds. Useful when starting the app
|
103
|
-
def bounds
|
104
|
-
UIScreen.mainScreen.bounds
|
105
|
-
end
|
106
|
-
|
107
|
-
# Application Delegate
|
108
|
-
def delegate
|
109
|
-
UIApplication.sharedApplication.delegate
|
110
|
-
end
|
111
|
-
|
112
|
-
# the Application object.
|
113
|
-
def shared
|
114
|
-
UIApplication.sharedApplication
|
115
|
-
end
|
116
|
-
|
117
|
-
# the Application Window
|
118
|
-
def window
|
119
|
-
UIApplication.sharedApplication.keyWindow || UIApplication.sharedApplication.windows[0]
|
120
|
-
end
|
121
|
-
|
122
58
|
# @return [NSLocale] locale of user settings
|
123
59
|
def current_locale
|
124
60
|
languages = NSLocale.preferredLanguages
|
@@ -146,6 +82,9 @@ module BubbleWrap
|
|
146
82
|
environment == 'release'
|
147
83
|
end
|
148
84
|
|
85
|
+
def osx?
|
86
|
+
Kernel.const_defined?(:NSApplication)
|
87
|
+
end
|
149
88
|
end
|
150
89
|
end
|
151
90
|
::App = BubbleWrap::App unless defined?(::App)
|
data/motion/core/device.rb
CHANGED
@@ -2,55 +2,6 @@ module BubbleWrap
|
|
2
2
|
module Device
|
3
3
|
module_function
|
4
4
|
|
5
|
-
# Verifies that the device running the app is an iPhone.
|
6
|
-
# @return [TrueClass, FalseClass] true will be returned if the device is an iPhone, false otherwise.
|
7
|
-
def iphone?(idiom=UIDevice.currentDevice.userInterfaceIdiom)
|
8
|
-
idiom == UIUserInterfaceIdiomPhone
|
9
|
-
end
|
10
|
-
|
11
|
-
# Verifies that the device running the app is an iPad.
|
12
|
-
# @return [TrueClass, FalseClass] true will be returned if the device is an iPad, false otherwise.
|
13
|
-
def ipad?(idiom=UIDevice.currentDevice.userInterfaceIdiom)
|
14
|
-
idiom == UIUserInterfaceIdiomPad
|
15
|
-
end
|
16
|
-
|
17
|
-
# Verifies that the device having a long screen (4 inch iPhone/iPod)
|
18
|
-
# @return [TrueClass, FalseClass] true will be returned if the device is an iPhone/iPod with 4 inche screen, false otherwise.
|
19
|
-
def long_screen?(idiom=UIDevice.currentDevice.userInterfaceIdiom, screen_height=UIScreen.mainScreen.bounds.size.height)
|
20
|
-
iphone?(idiom) && screen_height == 568.0
|
21
|
-
end
|
22
|
-
|
23
|
-
# Use this to make a DSL-style call for picking images
|
24
|
-
# @example Device.camera.front
|
25
|
-
# @return [Device::Camera::CameraWrapper]
|
26
|
-
def camera
|
27
|
-
BubbleWrap::Device::CameraWrapper
|
28
|
-
end
|
29
|
-
|
30
|
-
# Verifies that the device running has a front facing camera.
|
31
|
-
# @return [TrueClass, FalseClass] true will be returned if the device has a front facing camera, false otherwise.
|
32
|
-
def front_camera?(picker=UIImagePickerController)
|
33
|
-
p "This method (front_camera?) is DEPRECATED. Transition to using Device.camera.front?"
|
34
|
-
picker.isCameraDeviceAvailable(UIImagePickerControllerCameraDeviceFront)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Verifies that the device running has a rear facing camera.
|
38
|
-
# @return [TrueClass, FalseClass] true will be returned if the device has a rear facing camera, false otherwise.
|
39
|
-
def rear_camera?(picker=UIImagePickerController)
|
40
|
-
p "This method (rear_camera?) is DEPRECATED. Transition to using Device.camera.rear?"
|
41
|
-
picker.isCameraDeviceAvailable(UIImagePickerControllerCameraDeviceRear)
|
42
|
-
end
|
43
|
-
|
44
|
-
def simulator?
|
45
|
-
@simulator_state ||= !(UIDevice.currentDevice.model =~ /simulator/i).nil?
|
46
|
-
end
|
47
|
-
|
48
|
-
# Returns the IOS SDK version currently running (i.e. "5.1" or "6.0" etc)
|
49
|
-
# @return [String] the IOS SDK version currently running
|
50
|
-
def ios_version
|
51
|
-
UIDevice.currentDevice.systemVersion
|
52
|
-
end
|
53
|
-
|
54
5
|
# Shameless shorthand for accessing BubbleWrap::Screen
|
55
6
|
def screen
|
56
7
|
BubbleWrap::Device::Screen
|
@@ -60,12 +11,6 @@ module BubbleWrap
|
|
60
11
|
def retina?
|
61
12
|
screen.retina?
|
62
13
|
end
|
63
|
-
|
64
|
-
# Delegates to BubbleWrap::Screen.orientation
|
65
|
-
def orientation
|
66
|
-
screen.orientation
|
67
|
-
end
|
68
|
-
|
69
14
|
end
|
70
15
|
end
|
71
16
|
::Device = BubbleWrap::Device unless defined?(::Device)
|
File without changes
|
File without changes
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module BubbleWrap
|
2
|
+
module Device
|
3
|
+
module Screen
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Certifies that the device running the app has a Retina display
|
8
|
+
# @return [TrueClass, FalseClass] true will be returned if the device has a Retina display, false otherwise.
|
9
|
+
def retina?(screen=UIScreen.mainScreen)
|
10
|
+
if screen.respondsToSelector('displayLinkWithTarget:selector:') && screen.scale == 2.0
|
11
|
+
true
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Figure out the current physical orientation of the device
|
18
|
+
# @return [:portrait, :portrait_upside_down, :landscape_left, :landscape_right, :face_up, :face_down, :unknown]
|
19
|
+
def orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true)
|
20
|
+
case device_orientation
|
21
|
+
when UIDeviceOrientationPortrait then :portrait
|
22
|
+
when UIDeviceOrientationPortraitUpsideDown then :portrait_upside_down
|
23
|
+
when UIDeviceOrientationLandscapeLeft then :landscape_left
|
24
|
+
when UIDeviceOrientationLandscapeRight then :landscape_right
|
25
|
+
when UIDeviceOrientationFaceUp then :face_up
|
26
|
+
when UIDeviceOrientationFaceDown then :face_down
|
27
|
+
else
|
28
|
+
# In some cases, the accelerometer can't get an accurate read of orientation so we fall back on the orientation of
|
29
|
+
# the status bar.
|
30
|
+
if fallback && (device_orientation != UIApplication.sharedApplication.statusBarOrientation)
|
31
|
+
orientation(UIApplication.sharedApplication.statusBarOrientation)
|
32
|
+
else
|
33
|
+
:unknown
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# The width of the device's screen.
|
39
|
+
# The real resolution is dependant on the scale
|
40
|
+
# factor (see `retina?`) but the coordinate system
|
41
|
+
# is in non-retina pixels. You can get pixel
|
42
|
+
# accuracy by using half-coordinates.
|
43
|
+
# This is a Float
|
44
|
+
def width
|
45
|
+
UIScreen.mainScreen.bounds.size.width
|
46
|
+
end
|
47
|
+
|
48
|
+
# The height of the device's screen.
|
49
|
+
# The real resolution is dependant on the scale
|
50
|
+
# factor (see `retina?`) but the coordinate system
|
51
|
+
# is in non-retina pixels. You can get pixel
|
52
|
+
# accuracy by using half-coordinates.
|
53
|
+
# This is a Float
|
54
|
+
def height
|
55
|
+
UIScreen.mainScreen.bounds.size.height
|
56
|
+
end
|
57
|
+
|
58
|
+
# The same as `.width` and `.height` but
|
59
|
+
# compensating for screen rotation (which
|
60
|
+
# can do your head in).
|
61
|
+
def width_for_orientation(o=orientation)
|
62
|
+
return height if (o == :landscape_left) || (o == :landscape_right)
|
63
|
+
width
|
64
|
+
end
|
65
|
+
|
66
|
+
# The same as `.width` and `.height` but
|
67
|
+
# compensating for screen rotation (which
|
68
|
+
# can do your head in).
|
69
|
+
def height_for_orientation(o=orientation)
|
70
|
+
return width if (o == :landscape_left) || (o == :landscape_right)
|
71
|
+
height
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BubbleWrap
|
2
|
+
module Device
|
3
|
+
module Screen
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Certifies that the device running the app has a Retina display
|
8
|
+
# @return [TrueClass, FalseClass] true will be returned if the device has a Retina display, false otherwise.
|
9
|
+
def retina?(screen=NSScreen.mainScreen)
|
10
|
+
if screen.respondsToSelector('backingScaleFactor') && screen.backingScaleFactor == 2.0
|
11
|
+
true
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,74 +2,6 @@ module BubbleWrap
|
|
2
2
|
module Device
|
3
3
|
module Screen
|
4
4
|
|
5
|
-
module_function
|
6
|
-
|
7
|
-
# Certifies that the device running the app has a Retina display
|
8
|
-
# @return [TrueClass, FalseClass] true will be returned if the device has a Retina display, false otherwise.
|
9
|
-
def retina?(screen=UIScreen.mainScreen)
|
10
|
-
if screen.respondsToSelector('displayLinkWithTarget:selector:') && screen.scale == 2.0
|
11
|
-
true
|
12
|
-
else
|
13
|
-
false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Figure out the current physical orientation of the device
|
18
|
-
# @return [:portrait, :portrait_upside_down, :landscape_left, :landscape_right, :face_up, :face_down, :unknown]
|
19
|
-
def orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true)
|
20
|
-
case device_orientation
|
21
|
-
when UIDeviceOrientationPortrait then :portrait
|
22
|
-
when UIDeviceOrientationPortraitUpsideDown then :portrait_upside_down
|
23
|
-
when UIDeviceOrientationLandscapeLeft then :landscape_left
|
24
|
-
when UIDeviceOrientationLandscapeRight then :landscape_right
|
25
|
-
when UIDeviceOrientationFaceUp then :face_up
|
26
|
-
when UIDeviceOrientationFaceDown then :face_down
|
27
|
-
else
|
28
|
-
# In some cases, the accelerometer can't get an accurate read of orientation so we fall back on the orientation of
|
29
|
-
# the status bar.
|
30
|
-
if fallback && (device_orientation != UIApplication.sharedApplication.statusBarOrientation)
|
31
|
-
orientation(UIApplication.sharedApplication.statusBarOrientation)
|
32
|
-
else
|
33
|
-
:unknown
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# The width of the device's screen.
|
39
|
-
# The real resolution is dependant on the scale
|
40
|
-
# factor (see `retina?`) but the coordinate system
|
41
|
-
# is in non-retina pixels. You can get pixel
|
42
|
-
# accuracy by using half-coordinates.
|
43
|
-
# This is a Float
|
44
|
-
def width
|
45
|
-
UIScreen.mainScreen.bounds.size.width
|
46
|
-
end
|
47
|
-
|
48
|
-
# The height of the device's screen.
|
49
|
-
# The real resolution is dependant on the scale
|
50
|
-
# factor (see `retina?`) but the coordinate system
|
51
|
-
# is in non-retina pixels. You can get pixel
|
52
|
-
# accuracy by using half-coordinates.
|
53
|
-
# This is a Float
|
54
|
-
def height
|
55
|
-
UIScreen.mainScreen.bounds.size.height
|
56
|
-
end
|
57
|
-
|
58
|
-
# The same as `.width` and `.height` but
|
59
|
-
# compensating for screen rotation (which
|
60
|
-
# can do your head in).
|
61
|
-
def width_for_orientation(o=orientation)
|
62
|
-
return height if (o == :landscape_left) || (o == :landscape_right)
|
63
|
-
width
|
64
|
-
end
|
65
|
-
|
66
|
-
# The same as `.width` and `.height` but
|
67
|
-
# compensating for screen rotation (which
|
68
|
-
# can do your head in).
|
69
|
-
def height_for_orientation(o=orientation)
|
70
|
-
return width if (o == :landscape_left) || (o == :landscape_right)
|
71
|
-
height
|
72
|
-
end
|
73
5
|
end
|
74
6
|
end
|
75
|
-
end
|
7
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module BubbleWrap
|
2
|
+
module App
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Opens an url (string or instance of `NSURL`)
|
6
|
+
# in the device's web browser.
|
7
|
+
# Usage Example:
|
8
|
+
# App.open_url("http://matt.aimonetti.net")
|
9
|
+
def open_url(url)
|
10
|
+
unless url.is_a?(NSURL)
|
11
|
+
url = NSURL.URLWithString(url)
|
12
|
+
end
|
13
|
+
UIApplication.sharedApplication.openURL(url)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Displays a UIAlertView.
|
17
|
+
#
|
18
|
+
# title - The title as a String.
|
19
|
+
# args - The title of the cancel button as a String, or a Hash of options.
|
20
|
+
# (Default: { cancel_button_title: 'OK' })
|
21
|
+
# cancel_button_title - The title of the cancel button as a String.
|
22
|
+
# message - The main message as a String.
|
23
|
+
# block - Yields the alert object if a block is given, and does so before the alert is shown.
|
24
|
+
#
|
25
|
+
# Returns an instance of BW::UIAlertView
|
26
|
+
def alert(title, *args, &block)
|
27
|
+
options = { cancel_button_title: 'OK' }
|
28
|
+
options.merge!(args.pop) if args.last.is_a?(Hash)
|
29
|
+
|
30
|
+
if args.size > 0 && args.first.is_a?(String)
|
31
|
+
options[:cancel_button_title] = args.shift
|
32
|
+
end
|
33
|
+
|
34
|
+
options[:title] = title
|
35
|
+
options[:buttons] = options[:cancel_button_title]
|
36
|
+
options[:cancel_button_index] = 0 # FIXME: alerts don't have "Cancel" buttons
|
37
|
+
|
38
|
+
alert = UIAlertView.default(options)
|
39
|
+
|
40
|
+
yield(alert) if block_given?
|
41
|
+
|
42
|
+
alert.show
|
43
|
+
alert
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return application frame
|
47
|
+
def frame
|
48
|
+
UIScreen.mainScreen.applicationFrame
|
49
|
+
end
|
50
|
+
|
51
|
+
# Main Screen bounds. Useful when starting the app
|
52
|
+
def bounds
|
53
|
+
UIScreen.mainScreen.bounds
|
54
|
+
end
|
55
|
+
|
56
|
+
# Application Delegate
|
57
|
+
def delegate
|
58
|
+
UIApplication.sharedApplication.delegate
|
59
|
+
end
|
60
|
+
|
61
|
+
# the Application object.
|
62
|
+
def shared
|
63
|
+
UIApplication.sharedApplication
|
64
|
+
end
|
65
|
+
|
66
|
+
# the Application Window
|
67
|
+
def window
|
68
|
+
UIApplication.sharedApplication.keyWindow || UIApplication.sharedApplication.windows[0]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|