Class: RubyMotionQuery::Device

Inherits:
Object
  • Object
show all
Defined in:
motion/ruby_motion_query/device.rb

Constant Summary

ORIENTATIONS =
{ 
  UIDeviceOrientationUnknown => :unkown,
  UIDeviceOrientationPortrait => :portrait,
  UIDeviceOrientationPortraitUpsideDown => :portrait_upside_down,
  UIDeviceOrientationLandscapeLeft => :landscape_Left,
  UIDeviceOrientationLandscapeRight => :landscape_right,
  UIDeviceOrientationFaceUp => :face_up, 
  UIDeviceOrientationFaceDown => :face_down
}

Class Method Summary (collapse)

Class Method Details

+ (Boolean) four_inch?

Returns:

  • (Boolean)


45
46
47
48
# File 'motion/ruby_motion_query/device.rb', line 45

def four_inch?
  @_four_inch = (Device.height == 568.0) if @_four_inch.nil?
  @_four_inch
end

+ (Numeric) height

Returns:

  • (Numeric)


27
28
29
# File 'motion/ruby_motion_query/device.rb', line 27

def height
  @_height ||= Device.screen.bounds.size.height
end

+ (Boolean) ipad?

Returns:

  • (Boolean)


31
32
33
34
# File 'motion/ruby_motion_query/device.rb', line 31

def ipad?
  @_ipad = (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) if @_ipad.nil?
  @_ipad
end

+ (Boolean) iphone?

Returns:

  • (Boolean)


36
37
38
39
# File 'motion/ruby_motion_query/device.rb', line 36

def iphone?
  @_iphone = (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) if @_iphone.nil?
  @_iphone
end

+ (Boolean) landscape?

Returns:

  • (Boolean)


64
65
66
# File 'motion/ruby_motion_query/device.rb', line 64

def landscape?
  Device.orientation == :landscape_Left || Device.orientation == :landscape_right
end

+ (Object) orientation

Returns :unknown or from ORIENTATIONS

Returns:

  • :unknown or from ORIENTATIONS



60
61
62
# File 'motion/ruby_motion_query/device.rb', line 60

def orientation
  ORIENTATIONS[UIDevice.currentDevice.orientation] || :unknown
end

+ (Boolean) portrait?

Returns:

  • (Boolean)


68
69
70
# File 'motion/ruby_motion_query/device.rb', line 68

def portrait?
  Device.orientation == :portrait || Device.orientation == :unknown
end

+ (Boolean) retina?

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
# File 'motion/ruby_motion_query/device.rb', line 50

def retina?()
  if @_retina.nil?
    main_screen = Device.screen
    @_retina = !!(main_screen.respondsToSelector('displayLinkWithTarget:selector:') && main_screen.scale == 2.0)
  end

  @_retina
end

+ (UIScreen) screen

Returns:

  • (UIScreen)


17
18
19
# File 'motion/ruby_motion_query/device.rb', line 17

def screen
  UIScreen.mainScreen
end

+ (Boolean) simulator?

Returns:

  • (Boolean)


41
42
43
# File 'motion/ruby_motion_query/device.rb', line 41

def simulator?
  @_simulator ||= !(UIDevice.currentDevice.model =~ /simulator/i).nil?
end

+ (Numeric) width

Returns:

  • (Numeric)


22
23
24
# File 'motion/ruby_motion_query/device.rb', line 22

def width
  @_width ||= Device.screen.bounds.size.width
end