API Reference 0.5.1+4rikulo_accelerometerAccelerometer

Accelerometer class

Capture device motion in x, y, and z direction.

class Accelerometer {
 js.Proxy _accelerometer;

 factory Accelerometer() => accelerometer;

 Accelerometer._internal() {
   if (device == null)
     throw new StateError('device is not ready yet.');
   js.scoped(() {
     _accelerometer = js.context.navigator.accelerometer;
     js.retain(_accelerometer);
   });
 }

 /**
  * Returns the current motion Acceleration along x, y, and z axis.
  * The acceleration is returned via the [success] callback.
  */
 void getCurrentAcceleration(AccelerometerSuccessCB success,
                             AccelerometerErrorCB error) {
   js.scoped(() {
     var s0 = (p) => success(new Acceleration.fromProxy(p));
     List jsfns = JSUtil.newCallbackOnceGroup("acc", [s0, error], [1, 0]);
     var ok = jsfns[0];
     var fail = jsfns[1];
     _accelerometer.getCurrentAcceleration(ok, fail);
   });
 }

 /**
  * Register functions to get the Acceleration information in a regular
  * interval. This method returns an associated watchID which you can use to
  * clear this watch via [clearWatch] method.
  *
  * + [success] - success callback function.
  * + [error] - error callback function.
  * + [options] - optional parameter.
  */
 watchAcceleration(AccelerometerSuccessCB success,
                   AccelerometerErrorCB error, [AccelerometerOptions options]) {
   return js.scoped(() {
     var s0 = (p) => success(new Acceleration.fromProxy(p));
     var ok = new js.Callback.many(s0);
     var fail = new js.Callback.many(error);
     var opts = options == null ? null : js.map(options._toMap());
     var id = "acc_${_accelerometer.watchAcceleration(ok, fail, opts)}";
     JSUtil.addCallbacks(id, [ok, fail]);
     return id;
   });
 }

 /**
  * Stop watching the Acceleration that was associated with the specified
  * watchID.
  *
  * + [watchID] - the watch ID got from [watchAcceleration] method.
  */
 void clearWatch(var watchID) {
   js.scoped(() {
     _accelerometer.clearWatch(watchID.substring(4));
     JSUtil.delCallbacks(watchID);
   });
 }
}

Constructors

factory Accelerometer() #

factory Accelerometer() => accelerometer;

Methods

void clearWatch(watchID) #

Stop watching the Acceleration that was associated with the specified watchID.

void clearWatch(var watchID) {
 js.scoped(() {
   _accelerometer.clearWatch(watchID.substring(4));
   JSUtil.delCallbacks(watchID);
 });
}

void getCurrentAcceleration(AccelerometerSuccessCB success, AccelerometerErrorCB error) #

Returns the current motion Acceleration along x, y, and z axis. The acceleration is returned via the success callback.

void getCurrentAcceleration(AccelerometerSuccessCB success,
                           AccelerometerErrorCB error) {
 js.scoped(() {
   var s0 = (p) => success(new Acceleration.fromProxy(p));
   List jsfns = JSUtil.newCallbackOnceGroup("acc", [s0, error], [1, 0]);
   var ok = jsfns[0];
   var fail = jsfns[1];
   _accelerometer.getCurrentAcceleration(ok, fail);
 });
}

dynamic watchAcceleration(AccelerometerSuccessCB success, AccelerometerErrorCB error, [AccelerometerOptions options]) #

Register functions to get the Acceleration information in a regular interval. This method returns an associated watchID which you can use to clear this watch via clearWatch method.

  • success - success callback function.
  • error - error callback function.
  • options - optional parameter.
watchAcceleration(AccelerometerSuccessCB success,
                 AccelerometerErrorCB error, [AccelerometerOptions options]) {
 return js.scoped(() {
   var s0 = (p) => success(new Acceleration.fromProxy(p));
   var ok = new js.Callback.many(s0);
   var fail = new js.Callback.many(error);
   var opts = options == null ? null : js.map(options._toMap());
   var id = "acc_${_accelerometer.watchAcceleration(ok, fail, opts)}";
   JSUtil.addCallbacks(id, [ok, fail]);
   return id;
 });
}