# Class MotionEvent

java.lang.Object
com.codename1.sensors.MotionEvent

public final class MotionEvent extends Object

A single immutable reading from a motion sensor delivered to a `MotionSensorListener`. The meaning of the three axis values depends on the sensor type that produced the event (see `MotionSensorManager` for the constants and their units):

- For the acceleration sensors (`TYPE_ACCELEROMETER`, `TYPE_LINEAR_ACCELERATION`, `TYPE_GRAVITY`) `x`, `y` and `z` are in meters per second squared.
- For `TYPE_GYROSCOPE` they are angular velocities in radians per second.
- For `TYPE_MAGNETOMETER` they are the magnetic field in microtesla.
- For `TYPE_ORIENTATION` `x` is the azimuth, `y` the pitch and `z` the roll, all expressed in radians. Use `getAzimuth()`, `getPitch()` and `getRoll()` for readable access.

All ports normalize their readings to the axis convention of a device held upright in portrait: `x` points to the right, `y` points up and `z` points out of the screen towards the user.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MotionEvent(int type, float x, float y, float z, long timestamp)`
  Creates a new immutable motion event.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `float`
  `getAzimuth()`
  The azimuth (rotation around the z axis) in radians.
  `double`
  `getMagnitude()`
  The Euclidean magnitude of the three axis values.
  `float`
  `getPitch()`
  The pitch (rotation around the x axis) in radians.
  `float`
  `getRoll()`
  The roll (rotation around the y axis) in radians.
  `long`
  `getTimestamp()`
  The time at which this reading was sampled, in milliseconds, compatible with `System.currentTimeMillis()`.
  `int`
  `getType()`
  The sensor type that produced this event, one of the `MotionSensorManager.TYPE_*` constants.
  `float`
  `getX()`
  The value of the first (x) axis.
  `float`
  `getY()`
  The value of the second (y) axis.
  `float`
  `getZ()`
  The value of the third (z) axis.
  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### MotionEvent

    public MotionEvent(int type, float x, float y, float z, long timestamp)

    Creates a new immutable motion event. Application code does not normally construct these; they are delivered by the framework.

    ###### Parameters

    - `type`: one of the `MotionSensorManager.TYPE_*` constants
    - `x`: the first axis value
    - `y`: the second axis value
    - `z`: the third axis value
    - `timestamp`: the event time in milliseconds (see `System.currentTimeMillis()`)

- ## Method Details

  - ### getType

    public int getType()
    The sensor type that produced this event, one of the `MotionSensorManager.TYPE_*` constants.

  - ### getX

    public float getX()
    The value of the first (x) axis. See the class documentation for the unit which depends on the sensor type.

  - ### getY

    public float getY()
    The value of the second (y) axis. See the class documentation for the unit which depends on the sensor type.

  - ### getZ

    public float getZ()
    The value of the third (z) axis. See the class documentation for the unit which depends on the sensor type.

  - ### getAzimuth

    public float getAzimuth()
    The azimuth (rotation around the z axis) in radians. Only meaningful for `TYPE_ORIENTATION` events; equivalent to `getX()`.

  - ### getPitch

    public float getPitch()
    The pitch (rotation around the x axis) in radians. Only meaningful for `TYPE_ORIENTATION` events; equivalent to `getY()`.

  - ### getRoll

    public float getRoll()
    The roll (rotation around the y axis) in radians. Only meaningful for `TYPE_ORIENTATION` events; equivalent to `getZ()`.

  - ### getMagnitude

    public double getMagnitude()
    The Euclidean magnitude of the three axis values. For the acceleration sensors this is the total acceleration in meters per second squared.

  - ### getTimestamp

    public long getTimestamp()
    The time at which this reading was sampled, in milliseconds, compatible with `System.currentTimeMillis()`.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
    Overrides:
      `toString` in class `Object`