From d32001f32c73e459390c1360506a339f25c42994 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Thu, 15 May 2014 18:23:47 +0900 Subject: [PATCH] Start to add rotation listening. --- .../components/stf/screen/screen-directive.js | 27 ++++++++++++++++--- res/app/device-list/device-list.jade | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/res/app/components/stf/screen/screen-directive.js b/res/app/components/stf/screen/screen-directive.js index 11bbbc8d..ea813ec8 100644 --- a/res/app/components/stf/screen/screen-directive.js +++ b/res/app/components/stf/screen/screen-directive.js @@ -7,7 +7,8 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo link: function (scope, element) { var canvas = element.find('canvas')[0] , imageRender = new FastImageRender(canvas, {render: 'canvas'}) - , displayDensity = BrowserInfo.retina ? 2 : 1 + , guestDisplayDensity = BrowserInfo.retina ? 2 : 1 + , guestDisplayRotation = 0 , finger = element.find('span') , input = element.find('textarea') , boundingWidth = 0 // TODO: cache inside FastImageRender? @@ -118,8 +119,8 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo if (!loading && scope.$parent.showScreen && scope.device) { loading = true imageRender.load(scope.device.display.url + - '?width=' + boundingWidth * displayDensity + - '&height=' + boundingHeight * displayDensity + + '?width=' + boundingWidth * guestDisplayDensity + + '&height=' + boundingHeight * guestDisplayDensity + '&time=' + Date.now() ) } @@ -236,6 +237,10 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo } else { element.unbind('mousedown', downListener) } + + if (BrowserInfo.deviceorientation) { + window.unbind('deviceorientation', guestDisplayRotatated) + } } scope.$watch('$parent.showScreen', function (val) { @@ -265,6 +270,22 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo 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) } } diff --git a/res/app/device-list/device-list.jade b/res/app/device-list/device-list.jade index ff68bfce..08d343aa 100644 --- a/res/app/device-list/device-list.jade +++ b/res/app/device-list/device-list.jade @@ -35,7 +35,7 @@ div.stf-device-list button.btn.btn-default.btn-xs.device-status {{device.state|statusName}} .clear-fix - tab(active='activeTabs.details', ng-if='!$root.basicMode') + tab(active='activeTabs.details') tab-heading i.fa.fa-list(translate) span(translate) Details