Module: BubbleWrap::Device::Screen

Defined in:
motion/core/device/screen.rb,
motion/core/device/ios/screen.rb,
motion/core/device/osx/screen.rb

Class Method Summary collapse

Class Method Details

.heightObject

The height of the device’s screen. The real resolution is dependant on the scale factor (see retina?) but the coordinate system is in non-retina pixels. You can get pixel accuracy by using half-coordinates. This is a Float



73
74
75
# File 'motion/core/device/ios/screen.rb', line 73

def height
  UIScreen.mainScreen.bounds.size.height
end

.height_for_orientation(o = orientation) ⇒ Object

The same as .width and .height but compensating for screen rotation (which can do your head in).



88
89
90
91
# File 'motion/core/device/ios/screen.rb', line 88

def height_for_orientation(o=orientation)
  return width if (o == :landscape_left) || (o == :landscape_right)
  height
end

.interface_orientation(device_orientation = UIDevice.currentDevice.orientation, fallback = true) ⇒ :portrait, ...

Figure out the current orientation of the interface



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'motion/core/device/ios/screen.rb', line 40

def interface_orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true)
  case device_orientation
  when UIInterfaceOrientationPortrait then :portrait
  when UIInterfaceOrientationPortraitUpsideDown then :portrait_upside_down
  when UIInterfaceOrientationLandscapeLeft then :landscape_left
  when UIInterfaceOrientationLandscapeRight then :landscape_right
  else
    # In some cases, the accelerometer can't get an accurate read of orientation so we fall back on the orientation of
    # the status bar.
    if fallback && (device_orientation != UIApplication.sharedApplication.statusBarOrientation)
      orientation(UIApplication.sharedApplication.statusBarOrientation)
    else
      :unknown
    end
  end
end

.orientation(device_orientation = UIDevice.currentDevice.orientation, fallback = true) ⇒ :portrait, ...

Figure out the current physical orientation of the device



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'motion/core/device/ios/screen.rb', line 19

def orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true)
  case device_orientation
  when UIDeviceOrientationPortrait then :portrait
  when UIDeviceOrientationPortraitUpsideDown then :portrait_upside_down
  when UIDeviceOrientationLandscapeLeft then :landscape_left
  when UIDeviceOrientationLandscapeRight then :landscape_right
  when UIDeviceOrientationFaceUp then :face_up
  when UIDeviceOrientationFaceDown then :face_down
  else
    # In some cases, the accelerometer can't get an accurate read of orientation so we fall back on the orientation of
    # the status bar.
    if fallback && (device_orientation != UIApplication.sharedApplication.statusBarOrientation)
      orientation(UIApplication.sharedApplication.statusBarOrientation)
    else
      :unknown
    end
  end
end

.retina?(screen = NSScreen.mainScreen) ⇒ TrueClass, FalseClass

Certifies that the device running the app has a Retina display



9
10
11
12
13
14
15
# File 'motion/core/device/ios/screen.rb', line 9

def retina?(screen=UIScreen.mainScreen)
  if screen.respondsToSelector('displayLinkWithTarget:selector:') && screen.scale == 2.0
    true
  else
    false
  end
end

.widthObject

The width of the device’s screen. The real resolution is dependant on the scale factor (see retina?) but the coordinate system is in non-retina pixels. You can get pixel accuracy by using half-coordinates. This is a Float



63
64
65
# File 'motion/core/device/ios/screen.rb', line 63

def width
  UIScreen.mainScreen.bounds.size.width
end

.width_for_orientation(o = orientation) ⇒ Object

The same as .width and .height but compensating for screen rotation (which can do your head in).



80
81
82
83
# File 'motion/core/device/ios/screen.rb', line 80

def width_for_orientation(o=orientation)
  return height if (o == :landscape_left) || (o == :landscape_right)
  width
end