Class MotionEvent
java.lang.Object
com.codename1.sensors.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.
-
Constructor Summary
ConstructorsConstructorDescriptionMotionEvent(int type, float x, float y, float z, long timestamp) Creates a new immutable motion event. -
Method Summary
Modifier and TypeMethodDescriptionfloatThe azimuth (rotation around the z axis) in radians.doubleThe Euclidean magnitude of the three axis values.floatgetPitch()The pitch (rotation around the x axis) in radians.floatgetRoll()The roll (rotation around the y axis) in radians.longThe time at which this reading was sampled, in milliseconds, compatible withSystem.currentTimeMillis().intgetType()The sensor type that produced this event, one of theMotionSensorManager.TYPE_*constants.floatgetX()The value of the first (x) axis.floatgetY()The value of the second (y) axis.floatgetZ()The value of the third (z) axis.toString()Returns a string representation of the object.
-
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 theMotionSensorManager.TYPE_*constantsx: the first axis valuey: the second axis valuez: the third axis valuetimestamp: the event time in milliseconds (seeSystem.currentTimeMillis())
-
-
Method Details
-
getType
public int getType()The sensor type that produced this event, one of theMotionSensorManager.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 forTYPE_ORIENTATIONevents; equivalent togetX(). -
getPitch
public float getPitch()The pitch (rotation around the x axis) in radians. Only meaningful forTYPE_ORIENTATIONevents; equivalent togetY(). -
getRoll
public float getRoll()The roll (rotation around the y axis) in radians. Only meaningful forTYPE_ORIENTATIONevents; equivalent togetZ(). -
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 withSystem.currentTimeMillis(). -
toString
Description copied from class:ObjectReturns 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())
-