FileDocCategorySizeDatePackage
InputEvent.javaAPI DocAndroid 5.1 API7793Thu Mar 12 22:22:10 GMT 2015android.view

InputEvent

public abstract class InputEvent extends Object implements android.os.Parcelable
Common base class for input events.

Fields Summary
protected static final int
PARCEL_TOKEN_MOTION_EVENT
protected static final int
PARCEL_TOKEN_KEY_EVENT
private static final AtomicInteger
mNextSeq
protected int
mSeq
protected boolean
mRecycled
private static final boolean
TRACK_RECYCLED_LOCATION
private RuntimeException
mRecycledLocation
public static final Parcelable.Creator
CREATOR
Constructors Summary
InputEvent()


    /*package*/  
        mSeq = mNextSeq.getAndIncrement();
    
Methods Summary
public abstract voidcancel()
Marks the input event as being canceled.

hide

public abstract android.view.InputEventcopy()
Copies the event.

return
A deep copy of the event.
hide

public intdescribeContents()

        return 0;
    
public final InputDevicegetDevice()
Gets the device that this event came from.

return
The device, or null if unknown.

        return InputDevice.getDevice(getDeviceId());
    
public abstract intgetDeviceId()
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.

return
The device id.
see
InputDevice#getDevice

public abstract longgetEventTime()
Retrieve the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base.

return
Returns the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base.

public abstract longgetEventTimeNano()
Retrieve the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base but with nanosecond (instead of millisecond) precision.

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

return
Returns the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base but with nanosecond (instead of millisecond) precision.
hide

public intgetSequenceNumber()
Gets the unique sequence number of this event. Every input event that is created or received by a process has a unique sequence number. Moreover, a new sequence number is obtained each time an event object is recycled. Sequence numbers are only guaranteed to be locally unique within a process. Sequence numbers are not preserved when events are parceled.

return
The unique sequence number of this event.
hide

        return mSeq;
    
public abstract intgetSource()
Gets the source of the event.

return
The event source or {@link InputDevice#SOURCE_UNKNOWN} if unknown.
see
InputDevice#getSources

public booleanisFromSource(int source)
Determines whether the event is from the given source.

param
source The input source to check against. This can be a specific device type, such as {@link InputDevice#SOURCE_TOUCH_NAVIGATION}, or a more generic device class, such as {@link InputDevice#SOURCE_CLASS_POINTER}.
return
Whether the event is from the given source.

        return (getSource() & source) == source;
    
public abstract booleanisTainted()
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.

return
True if this event is tainted.
hide

protected voidprepareForReuse()
Reinitializes the event on reuse (after recycling).

hide

        mRecycled = false;
        mRecycledLocation = null;
        mSeq = mNextSeq.getAndIncrement();
    
public voidrecycle()
Recycles the event. This method should only be used by the system since applications do not expect {@link KeyEvent} objects to be recycled, although {@link MotionEvent} objects are fine. See {@link KeyEvent#recycle()} for details.

hide

        if (TRACK_RECYCLED_LOCATION) {
            if (mRecycledLocation != null) {
                throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
            }
            mRecycledLocation = new RuntimeException("Last recycled here");
        } else {
            if (mRecycled) {
                throw new RuntimeException(toString() + " recycled twice!");
            }
            mRecycled = true;
        }
    
public voidrecycleIfNeededAfterDispatch()
Conditionally recycled the event if it is appropriate to do so after dispatching the event to an application. If the event is a {@link MotionEvent} then it is recycled. If the event is a {@link KeyEvent} then it is NOT recycled, because applications expect key events to be immutable so once the event has been dispatched to the application we can no longer recycle it.

hide

        recycle();
    
public abstract voidsetSource(int source)
Modifies the source of the event.

param
source The new source.
hide

public abstract voidsetTainted(boolean tainted)
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.

param
tainted True if this event is tainted.
hide