Interface AccelerometerService

All Known Implementing Classes:
AndroidAccelerometerService, DummyAccelerometerService, IOSAccelerometerService, MobileAccelerometerService

public interface AccelerometerService
An accelerometer measures the acceleration force that is applied to a device in all three physical axes (x, y and z).

The AccelerometerService provides a read-only acceleration property that is updated at regular intervals by the underlying platform implementation. A user of the AccelerometerService can listen to changes of the acceleration force, by registering a ChangeListener to the acceleration property.

Example

 AccelerometerService.create().ifPresent(service -> {
      service.start();
      Acceleration acceleration = service.getCurrentAcceleration();
      System.out.printf("Current acceleration: %.2f, %.2f, %.2f",
              acceleration.getX(), acceleration.getY(), acceleration.getZ());
  });

Android Configuration: none

iOS Configuration: none

Since:
3.0.0
  • Property Details

    • acceleration

      javafx.beans.property.ReadOnlyObjectProperty<Acceleration> accelerationProperty
      A frequently-updated reading from the accelerometer.
  • Field Details

    • DEFAULT_PARAMETERS

      static final Parameters DEFAULT_PARAMETERS
      Default frequency is 50 Hz (50 samples per second). By default, gravity is not filtered.
  • Method Details

    • create

      static Optional<AccelerometerService> create()
      Returns an instance of AccelerometerService.
      Returns:
      An instance of AccelerometerService.
    • getCurrentAcceleration

      Acceleration getCurrentAcceleration()
      Returns a single reading from the accelerometer.
      Returns:
      the current accelerometer reading
    • accelerationProperty

      javafx.beans.property.ReadOnlyObjectProperty<Acceleration> accelerationProperty()
      A frequently-updated reading from the accelerometer.
    • start

      void start()
      Starts the service with DEFAULT_PARAMETERS.
      Since:
      4.0.11
    • start

      void start(Parameters parameters)
      Starts the service with given parameters.
      Parameters:
      parameters - Parameters for configuring the service
      Since:
      4.0.11
    • stop

      void stop()
      Stops the service.
      Since:
      4.0.11