motion/core/device/screen.rb in bubble-wrap-1.1.4 vs motion/core/device/screen.rb in bubble-wrap-1.1.5
- old
+ new
@@ -14,19 +14,25 @@
end
end
# Figure out the current physical orientation of the device
# @return [:portrait, :portrait_upside_down, :landscape_left, :landscape_right, :face_up, :face_down, :unknown]
- def orientation(device_orientation=UIDevice.currentDevice.orientation)
+ 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
- :unknown
+ # 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
# The width of the device's screen.
# The real resolution is dependant on the scale