/** * This class provides you with a cross platform way of listening to when the the orientation changes on the * device your application is running on. * * The {@link Ext.space.Orientation#orientationchange orientationchange} event gets passes the `alpha`, `beta` and * `gamma` values. * * You can find more information about these values and how to use them on the [W3C device orientation specification](http://dev.w3.org/geo/api/spec-source-orientation.html#deviceorientation). * * ## Example * * To listen to the device orientation, you can do the following: ** Ext.space.Orientation.on({* scope: this,* orientationchange: function(e) {* Ext.space.Logger.log('Alpha: ', e.alpha);* Ext.space.Logger.log('Beta: ', e.beta);* Ext.space.Logger.log('Gamma: ', e.gamma);* }* }); * * @mixins Ext.space.orientation.Abstract * * @aside guide native_apis */Ext.define('Ext.space.Orientation', { extend: Ext.space.Observable, singleton: true, /** * From the native shell, the callback needs to be invoked infinitely using a timer, ideally 50 times per second. * The callback expects one event object argument, the format of which should looks like this: * * { * alpha: 0, * beta: 0, * gamma: 0 * } * * Refer to [Safari DeviceOrientationEvent Class Reference][1] for more details. * * [1]: http://developer.apple.com/library/safari/#documentation/SafariDOMAdditions/Reference/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEvent.html */ startWatching: function() { Ext.space.Communicator.send({ command: 'Orientation#watch', callbacks: { callback: this.doDeviceOrientation }, scope: this }); }, onDeviceOrientation: function() { this.addListener.apply(this, arguments); }, doDeviceOrientation: function(e) { this.invokeListeners(e); } /** * @event orientationchange * Fired with the device's orientation changes. * @param {Object} event * @param {Number} event.alpha * @param {Number} event.beta * @param {Number} event.gamma */});