public final class MotionEvent
- Object
- MotionEvent
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,yandzare in meters per second squared. - For
TYPE_GYROSCOPEthey are angular velocities in radians per second. - For
TYPE_MAGNETOMETERthey are the magnetic field in microtesla. - For
TYPE_ORIENTATIONxis the azimuth,ythe pitch andzthe roll, all expressed in radians. UsegetAzimuth(),getPitch()andgetRoll()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.
Constructors
public MotionEvent(int type, float x, float y, float z, long timestamp) | Creates a new immutable motion event. |
Methods
public int getType() | The sensor type that produced this event, one of the MotionSensorManager.TYPE_* constants. |
public float getX() | The value of the first (x) axis. |
public float getY() | The value of the second (y) axis. |
public float getZ() | The value of the third (z) axis. |
public float getAzimuth() | The azimuth (rotation around the z axis) in radians. |
public float getPitch() | The pitch (rotation around the x axis) in radians. |
public float getRoll() | The roll (rotation around the y axis) in radians. |
public double getMagnitude() | The Euclidean magnitude of the three axis values. |
public long getTimestamp() | The time at which this reading was sampled, in milliseconds, compatible with System.currentTimeMillis(). |
public String toString() | Returns a string representation of the object. |
Inherited methods
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
typeint- one of the
MotionSensorManager.TYPE_*constants xfloat- the first axis value
yfloat- the second axis value
zfloat- the third axis value
timestamplong- 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()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())