IT. Expert System.

Android Reference

MotionEvent


android.view

Class MotionEvent

  • All Implemented Interfaces:
    Parcelable


    public final class MotionEvent
    extends InputEvent
    implements Parcelable
    Object used to report movement (mouse, pen, finger, trackball) events. Motion events may hold either absolute or relative movements and other data, depending on the type of device.

    Overview

    Motion events describe movements in terms of an action code and a set of axis values. The action code specifies the state change that occurred such as a pointer going down or up. The axis values describe the position and other movement properties.

    For example, when the user first touches the screen, the system delivers a touch event to the appropriate View with the action code ACTION_DOWN and a set of axis values that include the X and Y coordinates of the touch and information about the pressure, size and orientation of the contact area.

    Some devices can report multiple movement traces at the same time. Multi-touch screens emit one movement trace for each finger. The individual fingers or other objects that generate movement traces are referred to as pointers. Motion events contain information about all of the pointers that are currently active even if some of them have not moved since the last event was delivered.

    The number of pointers only ever changes by one as individual pointers go up and down, except when the gesture is canceled.

    Each pointer has a unique id that is assigned when it first goes down (indicated by ACTION_DOWN or ACTION_POINTER_DOWN). A pointer id remains valid until the pointer eventually goes up (indicated by ACTION_UP or ACTION_POINTER_UP) or when the gesture is canceled (indicated by ACTION_CANCEL).

    The MotionEvent class provides many methods to query the position and other properties of pointers, such as getX(int), getY(int), getAxisValue(int), getPointerId(int), getToolType(int), and many others. Most of these methods accept the pointer index as a parameter rather than the pointer id. The pointer index of each pointer in the event ranges from 0 to one less than the value returned by getPointerCount().

    The order in which individual pointers appear within a motion event is undefined. Thus the pointer index of a pointer can change from one event to the next but the pointer id of a pointer is guaranteed to remain constant as long as the pointer remains active. Use the getPointerId(int) method to obtain the pointer id of a pointer to track it across all subsequent motion events in a gesture. Then for successive motion events, use the findPointerIndex(int) method to obtain the pointer index for a given pointer id in that motion event.

    Mouse and stylus buttons can be retrieved using getButtonState(). It is a good idea to check the button state while handling ACTION_DOWN as part of a touch event. The application may choose to perform some different action if the touch event starts due to a secondary button click, such as presenting a context menu.

    Batching

    For efficiency, motion events with ACTION_MOVE may batch together multiple movement samples within a single object. The most current pointer coordinates are available using getX(int) and getY(int). Earlier coordinates within the batch are accessed using getHistoricalX(int, int) and getHistoricalY(int, int). The coordinates are "historical" only insofar as they are older than the current coordinates in the batch; however, they are still distinct from any other coordinates reported in prior motion events. To process all coordinates in the batch in time order, first consume the historical coordinates then consume the current coordinates.

    Example: Consuming all samples for all pointers in a motion event in time order.

    
     void printSamples(MotionEvent ev) {
         final int historySize = ev.getHistorySize();
         final int pointerCount = ev.getPointerCount();
         for (int h = 0; h < historySize; h++) {
             System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
             for (int p = 0; p < pointerCount; p++) {
                 System.out.printf("  pointer %d: (%f,%f)",
                     ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
             }
         }
         System.out.printf("At time %d:", ev.getEventTime());
         for (int p = 0; p < pointerCount; p++) {
             System.out.printf("  pointer %d: (%f,%f)",
                 ev.getPointerId(p), ev.getX(p), ev.getY(p));
         }
     }
     

    Device Types

    The interpretation of the contents of a MotionEvent varies significantly depending on the source class of the device.

    On pointing devices with source class InputDevice.SOURCE_CLASS_POINTER such as touch screens, the pointer coordinates specify absolute positions such as view X/Y coordinates. Each complete gesture is represented by a sequence of motion events with actions that describe pointer state transitions and movements. A gesture starts with a motion event with ACTION_DOWN that provides the location of the first pointer down. As each additional pointer that goes down or up, the framework will generate a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP accordingly. Pointer movements are described by motion events with ACTION_MOVE. Finally, a gesture end either when the final pointer goes up as represented by a motion event with ACTION_UP or when gesture is canceled with ACTION_CANCEL.

    Some pointing devices such as mice may support vertical and/or horizontal scrolling. A scroll event is reported as a generic motion event with ACTION_SCROLL that includes the relative scroll offset in the AXIS_VSCROLL and AXIS_HSCROLL axes. See getAxisValue(int) for information about retrieving these additional axes.

    On trackball devices with source class InputDevice.SOURCE_CLASS_TRACKBALL, the pointer coordinates specify relative movements as X/Y deltas. A trackball gesture consists of a sequence of movements described by motion events with ACTION_MOVE interspersed with occasional ACTION_DOWN or ACTION_UP motion events when the trackball button is pressed or released.

    On joystick devices with source class InputDevice.SOURCE_CLASS_JOYSTICK, the pointer coordinates specify the absolute position of the joystick axes. The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds to the center position. More information about the set of available axes and the range of motion can be obtained using InputDevice.getMotionRange(int). Some common joystick axes are AXIS_X, AXIS_Y, AXIS_HAT_X, AXIS_HAT_Y, AXIS_Z and AXIS_RZ.

    Refer to InputDevice for more information about how different kinds of input devices and sources represent pointer coordinates.

    Consistency Guarantees

    Motion events are always delivered to views as a consistent stream of events. What constitutes a consistent stream varies depending on the type of device. For touch events, consistency implies that pointers go down one at a time, move around as a group and then go up one at a time or are canceled.

    While the framework tries to deliver consistent streams of motion events to views, it cannot guarantee it. Some events may be dropped or modified by containing views in the application before they are delivered thereby making the stream of events inconsistent. Views should always be prepared to handle ACTION_CANCEL and should tolerate anomalous situations such as receiving a new ACTION_DOWN without first having received an ACTION_UP for the prior gesture.

    • Method Detail

      • finalize

        protected void finalize()
                         throws Throwable
        Description copied from class: Object
        Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

        Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

        If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

        Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

        Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

        Overrides:
        finalize in class Object
        Throws:
        Throwable
      • obtain

        public static MotionEvent obtain(long downTime,
                         long eventTime,
                         int action,
                         int pointerCount,
                         MotionEvent.PointerProperties[] pointerProperties,
                         MotionEvent.PointerCoords[] pointerCoords,
                         int metaState,
                         int buttonState,
                         float xPrecision,
                         float yPrecision,
                         int deviceId,
                         int edgeFlags,
                         int source,
                         int flags)
        Create a new MotionEvent, filling in all of the basic values that define the motion.
        Parameters:
        downTime - The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock.uptimeMillis().
        eventTime - The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.uptimeMillis().
        action - The kind of action being performed, such as ACTION_DOWN.
        pointerCount - The number of pointers that will be in this event.
        pointerProperties - An array of pointerCount values providing a MotionEvent.PointerProperties property object for each pointer, which must include the pointer identifier.
        pointerCoords - An array of pointerCount values providing a MotionEvent.PointerCoords coordinate object for each pointer.
        metaState - The state of any meta / modifier keys that were in effect when the event was generated.
        buttonState - The state of buttons that are pressed.
        xPrecision - The precision of the X coordinate being reported.
        yPrecision - The precision of the Y coordinate being reported.
        deviceId - The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
        edgeFlags - A bitfield indicating which edges, if any, were touched by this MotionEvent.
        source - The source of this event.
        flags - The motion event flags.
      • obtain

        @Deprecated
        public static MotionEvent obtain(long downTime,
                                    long eventTime,
                                    int action,
                                    int pointerCount,
                                    int[] pointerIds,
                                    MotionEvent.PointerCoords[] pointerCoords,
                                    int metaState,
                                    float xPrecision,
                                    float yPrecision,
                                    int deviceId,
                                    int edgeFlags,
                                    int source,
                                    int flags)
        Create a new MotionEvent, filling in all of the basic values that define the motion.
        Parameters:
        downTime - The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock.uptimeMillis().
        eventTime - The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.uptimeMillis().
        action - The kind of action being performed, such as ACTION_DOWN.
        pointerCount - The number of pointers that will be in this event.
        pointerIds - An array of pointerCount values providing an identifier for each pointer.
        pointerCoords - An array of pointerCount values providing a MotionEvent.PointerCoords coordinate object for each pointer.
        metaState - The state of any meta / modifier keys that were in effect when the event was generated.
        xPrecision - The precision of the X coordinate being reported.
        yPrecision - The precision of the Y coordinate being reported.
        deviceId - The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
        edgeFlags - A bitfield indicating which edges, if any, were touched by this MotionEvent.
        source - The source of this event.
        flags - The motion event flags.
      • obtain

        public static MotionEvent obtain(long downTime,
                         long eventTime,
                         int action,
                         float x,
                         float y,
                         float pressure,
                         float size,
                         int metaState,
                         float xPrecision,
                         float yPrecision,
                         int deviceId,
                         int edgeFlags)
        Create a new MotionEvent, filling in all of the basic values that define the motion.
        Parameters:
        downTime - The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock.uptimeMillis().
        eventTime - The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.uptimeMillis().
        action - The kind of action being performed, such as ACTION_DOWN.
        x - The X coordinate of this event.
        y - The Y coordinate of this event.
        pressure - The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
        size - A scaled value of the approximate size of the area being pressed when touched with the finger. The actual value in pixels corresponding to the finger touch is normalized with a device specific range of values and scaled to a value between 0 and 1.
        metaState - The state of any meta / modifier keys that were in effect when the event was generated.
        xPrecision - The precision of the X coordinate being reported.
        yPrecision - The precision of the Y coordinate being reported.
        deviceId - The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
        edgeFlags - A bitfield indicating which edges, if any, were touched by this MotionEvent.
      • obtain

        @Deprecated
        public static MotionEvent obtain(long downTime,
                                    long eventTime,
                                    int action,
                                    int pointerCount,
                                    float x,
                                    float y,
                                    float pressure,
                                    float size,
                                    int metaState,
                                    float xPrecision,
                                    float yPrecision,
                                    int deviceId,
                                    int edgeFlags)
        Create a new MotionEvent, filling in all of the basic values that define the motion.
        Parameters:
        downTime - The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock.uptimeMillis().
        eventTime - The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.uptimeMillis().
        action - The kind of action being performed, such as ACTION_DOWN.
        pointerCount - The number of pointers that are active in this event.
        x - The X coordinate of this event.
        y - The Y coordinate of this event.
        pressure - The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
        size - A scaled value of the approximate size of the area being pressed when touched with the finger. The actual value in pixels corresponding to the finger touch is normalized with a device specific range of values and scaled to a value between 0 and 1.
        metaState - The state of any meta / modifier keys that were in effect when the event was generated.
        xPrecision - The precision of the X coordinate being reported.
        yPrecision - The precision of the Y coordinate being reported.
        deviceId - The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
        edgeFlags - A bitfield indicating which edges, if any, were touched by this MotionEvent.
      • obtain

        public static MotionEvent obtain(long downTime,
                         long eventTime,
                         int action,
                         float x,
                         float y,
                         int metaState)
        Create a new MotionEvent, filling in a subset of the basic motion values. Those not specified here are: device id (always 0), pressure and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
        Parameters:
        downTime - The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock.uptimeMillis().
        eventTime - The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.uptimeMillis().
        action - The kind of action being performed, such as ACTION_DOWN.
        x - The X coordinate of this event.
        y - The Y coordinate of this event.
        metaState - The state of any meta / modifier keys that were in effect when the event was generated.
      • obtain

        public static MotionEvent obtain(MotionEvent other)
        Create a new MotionEvent, copying from an existing one.
      • obtainNoHistory

        public static MotionEvent obtainNoHistory(MotionEvent other)
        Create a new MotionEvent, copying from an existing one, but not including any historical point information.
      • recycle

        public final void recycle()
        Recycle the MotionEvent, to be re-used by a later caller. After calling this function you must not ever touch the event again.
        Overrides:
        recycle in class InputEvent
      • scale

        public final void scale(float scale)
        Applies a scale factor to all points within this event. This method is used to adjust touch events to simulate different density displays for compatibility mode. The values returned by getRawX(), getRawY(), getXPrecision() and getYPrecision() are also affected by the scale factor.
        Parameters:
        scale - The scale factor to apply.
      • getDeviceId

        public final int getDeviceId()
        Gets the id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn't depend on the values.
        Specified by:
        getDeviceId in class InputEvent
        Returns:
        The device id.
        See Also:
        InputDevice.getDevice(int)
      • setSource

        public final void setSource(int source)
        Modifies the source of the event.
        Specified by:
        setSource in class InputEvent
        Parameters:
        source - The new source.
      • getActionMasked

        public final int getActionMasked()
        Return the masked action being performed, without pointer index information. Use getActionIndex() to return the index associated with pointer actions.
        Returns:
        The action, such as ACTION_DOWN or ACTION_POINTER_DOWN.
      • isTouchEvent

        public final boolean isTouchEvent()
        Returns true if this motion event is a touch event.

        Specifically excludes pointer events with action ACTION_HOVER_MOVE, ACTION_HOVER_ENTER, ACTION_HOVER_EXIT, or ACTION_SCROLL because they are not actually touch events (the pointer is not down).

        Returns:
        True if this motion event is a touch event.
      • isTainted

        public final boolean isTainted()
        Description copied from class: InputEvent
        Gets a private flag that indicates when the system has detected that this input event may be inconsistent with respect to the sequence of previously delivered input events, such as when a key up event is sent but the key was not down or when a pointer move event is sent but the pointer is not down.
        Specified by:
        isTainted in class InputEvent
        Returns:
        True if this event is tainted.
      • setTainted

        public final void setTainted(boolean tainted)
        Description copied from class: InputEvent
        Sets a private flag that indicates when the system has detected that this input event may be inconsistent with respect to the sequence of previously delivered input events, such as when a key up event is sent but the key was not down or when a pointer move event is sent but the pointer is not down.
        Specified by:
        setTainted in class InputEvent
        Parameters:
        tainted - True if this event is tainted.
      • getDownTime

        public final long getDownTime()
        Returns the time (in ms) when the user originally pressed down to start a stream of position events.
      • setDownTime

        public final void setDownTime(long downTime)
        Sets the time (in ms) when the user originally pressed down to start a stream of position events.
      • getEventTimeNano

        public final long getEventTimeNano()
        Retrieve the time this event occurred, in the SystemClock.uptimeMillis() time base but with nanosecond precision.

        The value is in nanosecond precision but it may not have nanosecond accuracy.

        Specified by:
        getEventTimeNano in class InputEvent
        Returns:
        Returns the time this event occurred, in the SystemClock.uptimeMillis() time base but with nanosecond precision.
      • getX

        public final float getX()
        getX(int) for the first pointer index (may be an arbitrary pointer identifier).
        See Also:
        AXIS_X
      • getY

        public final float getY()
        getY(int) for the first pointer index (may be an arbitrary pointer identifier).
        See Also:
        AXIS_Y
      • getPressure

        public final float getPressure()
        getPressure(int) for the first pointer index (may be an arbitrary pointer identifier).
        See Also:
        AXIS_PRESSURE
      • getSize

        public final float getSize()
        getSize(int) for the first pointer index (may be an arbitrary pointer identifier).
        See Also:
        AXIS_SIZE
      • getToolMajor

        public final float getToolMajor()
        getToolMajor(int) for the first pointer index (may be an arbitrary pointer identifier).
        See Also:
        AXIS_TOOL_MAJOR
      • getToolMinor

        public final float getToolMinor()
        getToolMinor(int) for the first pointer index (may be an arbitrary pointer identifier).
        See Also:
        AXIS_TOOL_MINOR
      • getAxisValue

        public final float getAxisValue(int axis)
        getAxisValue(int) for the first pointer index (may be an arbitrary pointer identifier).
        Parameters:
        axis - The axis identifier for the axis value to retrieve.
        See Also:
        AXIS_X, AXIS_Y
      • getPointerCount

        public final int getPointerCount()
        The number of pointers of data contained in this event. Always >= 1.
      • getPointerId

        public final int getPointerId(int pointerIndex)
        Return the pointer identifier associated with a particular pointer data index is this event. The identifier tells you the actual pointer number associated with the data, accounting for individual pointers going up and down since the start of the current gesture.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
      • getToolType

        public final int getToolType(int pointerIndex)
        Gets the tool type of a pointer for the given pointer index. The tool type indicates the type of tool used to make contact such as a finger or stylus, if known.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        Returns:
        The tool type of the pointer.
        See Also:
        TOOL_TYPE_UNKNOWN, TOOL_TYPE_FINGER, TOOL_TYPE_STYLUS, TOOL_TYPE_MOUSE, #TOOL_TYPE_INDIRECT_FINGER, #TOOL_TYPE_INDIRECT_STYLUS
      • findPointerIndex

        public final int findPointerIndex(int pointerId)
        Given a pointer identifier, find the index of its data in the event.
        Parameters:
        pointerId - The identifier of the pointer to be found.
        Returns:
        Returns either the index of the pointer (for use with getX(int) et al.), or -1 if there is no data available for that pointer identifier.
      • getX

        public final float getX(int pointerIndex)
        Returns the X coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_X
      • getY

        public final float getY(int pointerIndex)
        Returns the Y coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_Y
      • getPressure

        public final float getPressure(int pointerIndex)
        Returns the current pressure of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_PRESSURE
      • getSize

        public final float getSize(int pointerIndex)
        Returns a scaled value of the approximate size for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). This represents some approximation of the area of the screen being pressed; the actual value in pixels corresponding to the touch is normalized with the device specific range of values and scaled to a value between 0 and 1. The value of size can be used to determine fat touch events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_SIZE
      • getTouchMajor

        public final float getTouchMajor(int pointerIndex)
        Returns the length of the major axis of an ellipse that describes the touch area at the point of contact for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_TOUCH_MAJOR
      • getTouchMinor

        public final float getTouchMinor(int pointerIndex)
        Returns the length of the minor axis of an ellipse that describes the touch area at the point of contact for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_TOUCH_MINOR
      • getToolMajor

        public final float getToolMajor(int pointerIndex)
        Returns the length of the major axis of an ellipse that describes the size of the approaching tool for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). The tool area represents the estimated size of the finger or pen that is touching the device independent of its actual touch area at the point of contact.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_TOOL_MAJOR
      • getToolMinor

        public final float getToolMinor(int pointerIndex)
        Returns the length of the minor axis of an ellipse that describes the size of the approaching tool for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). The tool area represents the estimated size of the finger or pen that is touching the device independent of its actual touch area at the point of contact.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_TOOL_MINOR
      • getOrientation

        public final float getOrientation(int pointerIndex)
        Returns the orientation of the touch area and tool area in radians clockwise from vertical for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). An angle of 0 radians indicates that the major axis of contact is oriented upwards, is perfectly circular or is of unknown orientation. A positive angle indicates that the major axis of contact is oriented to the right. A negative angle indicates that the major axis of contact is oriented to the left. The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians (finger pointing fully right).
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        See Also:
        AXIS_ORIENTATION
      • getAxisValue

        public final float getAxisValue(int axis,
                         int pointerIndex)
        Returns the value of the requested axis for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
        Parameters:
        axis - The axis identifier for the axis value to retrieve.
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        Returns:
        The value of the axis, or 0 if the axis is not available.
        See Also:
        AXIS_X, AXIS_Y
      • getMetaState

        public final int getMetaState()
        Returns the state of any meta / modifier keys that were in effect when the event was generated. This is the same values as those returned by KeyEvent.getMetaState.
        Returns:
        an integer in which each bit set to 1 represents a pressed meta key
        See Also:
        KeyEvent.getMetaState()
      • getRawX

        public final float getRawX()
        Returns the original raw X coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.
        See Also:
        getX(), AXIS_X
      • getRawY

        public final float getRawY()
        Returns the original raw Y coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.
        See Also:
        getY(), AXIS_Y
      • getXPrecision

        public final float getXPrecision()
        Return the precision of the X coordinates being reported. You can multiply this number with getX() to find the actual hardware value of the X coordinate.
        Returns:
        Returns the precision of X coordinates being reported.
        See Also:
        AXIS_X
      • getYPrecision

        public final float getYPrecision()
        Return the precision of the Y coordinates being reported. You can multiply this number with getY() to find the actual hardware value of the Y coordinate.
        Returns:
        Returns the precision of Y coordinates being reported.
        See Also:
        AXIS_Y
      • getHistorySize

        public final int getHistorySize()
        Returns the number of historical points in this event. These are movements that have occurred between this event and the previous event. This only applies to ACTION_MOVE events -- all other actions will have a size of 0.
        Returns:
        Returns the number of historical points in the event.
      • getHistoricalEventTime

        public final long getHistoricalEventTime(int pos)
        Returns the time that a historical movement occurred between this event and the previous event, in the SystemClock.uptimeMillis() time base.

        This only applies to ACTION_MOVE events.

        Parameters:
        pos - Which historical value to return; must be less than getHistorySize()
        Returns:
        Returns the time that a historical movement occurred between this event and the previous event, in the SystemClock.uptimeMillis() time base.
        See Also:
        getHistorySize(), getEventTime()
      • getHistoricalEventTimeNano

        public final long getHistoricalEventTimeNano(int pos)
        Returns the time that a historical movement occurred between this event and the previous event, in the SystemClock.uptimeMillis() time base but with nanosecond (instead of millisecond) precision.

        This only applies to ACTION_MOVE events.

        The value is in nanosecond precision but it may not have nanosecond accuracy.

        Parameters:
        pos - Which historical value to return; must be less than getHistorySize()
        Returns:
        Returns the time that a historical movement occurred between this event and the previous event, in the SystemClock.uptimeMillis() time base but with nanosecond (instead of millisecond) precision.
        See Also:
        getHistorySize(), getEventTime()
      • getHistoricalX

        public final float getHistoricalX(int pointerIndex,
                           int pos)
        Returns a historical X coordinate, as per getX(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getX(int), AXIS_X
      • getHistoricalY

        public final float getHistoricalY(int pointerIndex,
                           int pos)
        Returns a historical Y coordinate, as per getY(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getY(int), AXIS_Y
      • getHistoricalPressure

        public final float getHistoricalPressure(int pointerIndex,
                                  int pos)
        Returns a historical pressure coordinate, as per getPressure(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getPressure(int), AXIS_PRESSURE
      • getHistoricalSize

        public final float getHistoricalSize(int pointerIndex,
                              int pos)
        Returns a historical size coordinate, as per getSize(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getSize(int), AXIS_SIZE
      • getHistoricalTouchMajor

        public final float getHistoricalTouchMajor(int pointerIndex,
                                    int pos)
        Returns a historical touch major axis coordinate, as per getTouchMajor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getTouchMajor(int), AXIS_TOUCH_MAJOR
      • getHistoricalTouchMinor

        public final float getHistoricalTouchMinor(int pointerIndex,
                                    int pos)
        Returns a historical touch minor axis coordinate, as per getTouchMinor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getTouchMinor(int), AXIS_TOUCH_MINOR
      • getHistoricalToolMajor

        public final float getHistoricalToolMajor(int pointerIndex,
                                   int pos)
        Returns a historical tool major axis coordinate, as per getToolMajor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getToolMajor(int), AXIS_TOOL_MAJOR
      • getHistoricalToolMinor

        public final float getHistoricalToolMinor(int pointerIndex,
                                   int pos)
        Returns a historical tool minor axis coordinate, as per getToolMinor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getToolMinor(int), AXIS_TOOL_MINOR
      • getHistoricalOrientation

        public final float getHistoricalOrientation(int pointerIndex,
                                     int pos)
        Returns a historical orientation coordinate, as per getOrientation(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        See Also:
        getHistorySize(), getOrientation(int), AXIS_ORIENTATION
      • getHistoricalAxisValue

        public final float getHistoricalAxisValue(int axis,
                                   int pointerIndex,
                                   int pos)
        Returns the historical value of the requested axis, as per getAxisValue(int, int), occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.
        Parameters:
        axis - The axis identifier for the axis value to retrieve.
        pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
        pos - Which historical value to return; must be less than getHistorySize()
        Returns:
        The value of the axis, or 0 if the axis is not available.
        See Also:
        AXIS_X, AXIS_Y
      • getEdgeFlags

        public final int getEdgeFlags()
        Returns a bitfield indicating which edges, if any, were touched by this MotionEvent. For touch events, clients can use this to determine if the user's finger was touching the edge of the display. This property is only set for ACTION_DOWN events.
        See Also:
        EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM
      • setEdgeFlags

        public final void setEdgeFlags(int flags)
        Sets the bitfield indicating which edges, if any, were touched by this MotionEvent.
        See Also:
        getEdgeFlags()
      • setAction

        public final void setAction(int action)
        Sets this event's action.
      • offsetLocation

        public final void offsetLocation(float deltaX,
                          float deltaY)
        Adjust this event's location.
        Parameters:
        deltaX - Amount to add to the current X coordinate of the event.
        deltaY - Amount to add to the current Y coordinate of the event.
      • setLocation

        public final void setLocation(float x,
                       float y)
        Set this event's location. Applies offsetLocation(float, float) with a delta from the current location to the given new location.
        Parameters:
        x - New absolute X location.
        y - New absolute Y location.
      • transform

        public final void transform(Matrix matrix)
        Applies a transformation matrix to all of the points in the event.
        Parameters:
        matrix - The transformation matrix to apply.
      • addBatch

        public final void addBatch(long eventTime,
                    float x,
                    float y,
                    float pressure,
                    float size,
                    int metaState)
        Add a new movement to the batch of movements in this event. The event's current location, position and size is updated to the new values. The current values in the event are added to a list of historical values. Only applies to ACTION_MOVE or ACTION_HOVER_MOVE events.
        Parameters:
        eventTime - The time stamp (in ms) for this data.
        x - The new X position.
        y - The new Y position.
        pressure - The new pressure.
        size - The new size.
        metaState - Meta key state.
      • addBatch

        public final void addBatch(long eventTime,
                    MotionEvent.PointerCoords[] pointerCoords,
                    int metaState)
        Add a new movement to the batch of movements in this event. The event's current location, position and size is updated to the new values. The current values in the event are added to a list of historical values. Only applies to ACTION_MOVE or ACTION_HOVER_MOVE events.
        Parameters:
        eventTime - The time stamp (in ms) for this data.
        pointerCoords - The new pointer coordinates.
        metaState - Meta key state.
      • addBatch

        public final boolean addBatch(MotionEvent event)
        Adds all of the movement samples of the specified event to this one if it is compatible. To be compatible, the event must have the same device id, source, action, flags, pointer count, pointer properties. Only applies to ACTION_MOVE or ACTION_HOVER_MOVE events.
        Parameters:
        event - The event whose movements samples should be added to this one if possible.
        Returns:
        True if batching was performed or false if batching was not possible.
      • isWithinBoundsNoHistory

        public final boolean isWithinBoundsNoHistory(float left,
                                      float top,
                                      float right,
                                      float bottom)
        Returns true if all points in the motion event are completely within the specified bounds.
      • clampNoHistory

        public final MotionEvent clampNoHistory(float left,
                                 float top,
                                 float right,
                                 float bottom)
        Returns a new motion events whose points have been clamped to the specified bounds.
      • getPointerIdBits

        public final int getPointerIdBits()
        Gets an integer where each pointer id present in the event is marked as a bit.
      • split

        public final MotionEvent split(int idBits)
        Splits a motion event such that it includes only a subset of pointer ids.
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • actionToString

        public static String actionToString(int action)
        Returns a string that represents the symbolic name of the specified action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant such as "35" if unknown.
        Parameters:
        action - The action.
        Returns:
        The symbolic name of the specified action.
      • axisToString

        public static String axisToString(int axis)
        Returns a string that represents the symbolic name of the specified axis such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
        Parameters:
        axis - The axis
        Returns:
        The symbolic name of the specified axis.
      • axisFromString

        public static int axisFromString(String symbolicName)
        Gets an axis by its symbolic name such as "AXIS_X" or an equivalent numeric constant such as "42".
        Parameters:
        symbolicName - The symbolic name of the axis.
        Returns:
        The axis or -1 if not found.
        See Also:
        #keycodeToString
      • buttonStateToString

        public static String buttonStateToString(int buttonState)
        Returns a string that represents the symbolic name of the specified combined button state flags such as "0", "BUTTON_PRIMARY", "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000" if unknown.
        Parameters:
        buttonState - The button state.
        Returns:
        The symbolic name of the specified combined button state flags.
      • toolTypeToString

        public static String toolTypeToString(int toolType)
        Returns a string that represents the symbolic name of the specified tool type such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.
        Parameters:
        toolType - The tool type.
        Returns:
        The symbolic name of the specified tool type.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 496 / 158674749. Delta: 0.12516 с