1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 03:50:04 +02:00

Start to add rotation listening.

This commit is contained in:
Gunther Brunner 2014-05-15 18:23:47 +09:00
parent 74a6682537
commit d32001f32c
2 changed files with 25 additions and 4 deletions

View file

@ -7,7 +7,8 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo
link: function (scope, element) { link: function (scope, element) {
var canvas = element.find('canvas')[0] var canvas = element.find('canvas')[0]
, imageRender = new FastImageRender(canvas, {render: 'canvas'}) , imageRender = new FastImageRender(canvas, {render: 'canvas'})
, displayDensity = BrowserInfo.retina ? 2 : 1 , guestDisplayDensity = BrowserInfo.retina ? 2 : 1
, guestDisplayRotation = 0
, finger = element.find('span') , finger = element.find('span')
, input = element.find('textarea') , input = element.find('textarea')
, boundingWidth = 0 // TODO: cache inside FastImageRender? , boundingWidth = 0 // TODO: cache inside FastImageRender?
@ -118,8 +119,8 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo
if (!loading && scope.$parent.showScreen && scope.device) { if (!loading && scope.$parent.showScreen && scope.device) {
loading = true loading = true
imageRender.load(scope.device.display.url + imageRender.load(scope.device.display.url +
'?width=' + boundingWidth * displayDensity + '?width=' + boundingWidth * guestDisplayDensity +
'&height=' + boundingHeight * displayDensity + '&height=' + boundingHeight * guestDisplayDensity +
'&time=' + Date.now() '&time=' + Date.now()
) )
} }
@ -236,6 +237,10 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo
} else { } else {
element.unbind('mousedown', downListener) element.unbind('mousedown', downListener)
} }
if (BrowserInfo.deviceorientation) {
window.unbind('deviceorientation', guestDisplayRotatated)
}
} }
scope.$watch('$parent.showScreen', function (val) { scope.$watch('$parent.showScreen', function (val) {
@ -265,6 +270,22 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo
rotation = r || 0 rotation = r || 0
}) })
function guestDisplayRotatated(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
// beta is the front-to-back tilt in degrees, where front is positive
var tiltFB = eventData.beta;
// alpha is the compass direction the device is facing in degrees
var dir = eventData.alpha
console.log(eventData)
}
if (BrowserInfo.deviceorientation) {
window.addEventListener('deviceorientation', guestDisplayRotatated, true)
}
scope.$on('$destroy', off) scope.$on('$destroy', off)
} }
} }

View file

@ -35,7 +35,7 @@ div.stf-device-list
button.btn.btn-default.btn-xs.device-status {{device.state|statusName}} button.btn.btn-default.btn-xs.device-status {{device.state|statusName}}
.clear-fix .clear-fix
tab(active='activeTabs.details', ng-if='!$root.basicMode') tab(active='activeTabs.details')
tab-heading tab-heading
i.fa.fa-list(translate) i.fa.fa-list(translate)
span(translate) Details span(translate) Details