FileDocCategorySizeDatePackage
InputEventReceiver.javaAPI DocAndroid 5.1 API6883Thu Mar 12 22:22:10 GMT 2015android.view

InputEventReceiver

public abstract class InputEventReceiver extends Object
Provides a low-level mechanism for an application to receive input events.
hide

Fields Summary
private static final String
TAG
private final dalvik.system.CloseGuard
mCloseGuard
private long
mReceiverPtr
private InputChannel
mInputChannel
private android.os.MessageQueue
mMessageQueue
private final android.util.SparseIntArray
mSeqMap
Constructors Summary
public InputEventReceiver(InputChannel inputChannel, android.os.Looper looper)
Creates an input event receiver bound to the specified input channel.

param
inputChannel The input channel.
param
looper The looper to use when invoking callbacks.


         
               
         
             
         
             

                                  
         
        if (inputChannel == null) {
            throw new IllegalArgumentException("inputChannel must not be null");
        }
        if (looper == null) {
            throw new IllegalArgumentException("looper must not be null");
        }

        mInputChannel = inputChannel;
        mMessageQueue = looper.getQueue();
        mReceiverPtr = nativeInit(new WeakReference<InputEventReceiver>(this),
                inputChannel, mMessageQueue);

        mCloseGuard.open("dispose");
    
Methods Summary
public final booleanconsumeBatchedInputEvents(long frameTimeNanos)
Consumes all pending batched input events. Must be called on the same Looper thread to which the receiver is attached. This method forces all batched input events to be delivered immediately. Should be called just before animating or drawing a new frame in the UI.

param
frameTimeNanos The time in the {@link System#nanoTime()} time base when the current display frame started rendering, or -1 if unknown.
return
Whether a batch was consumed

        if (mReceiverPtr == 0) {
            Log.w(TAG, "Attempted to consume batched input events but the input event "
                    + "receiver has already been disposed.");
        } else {
            return nativeConsumeBatchedInputEvents(mReceiverPtr, frameTimeNanos);
        }
        return false;
    
private voiddispatchBatchedInputEventPending()

        onBatchedInputEventPending();
    
private voiddispatchInputEvent(int seq, InputEvent event)

        mSeqMap.put(event.getSequenceNumber(), seq);
        onInputEvent(event);
    
public voiddispose()
Disposes the receiver.

        dispose(false);
    
private voiddispose(boolean finalized)

        if (mCloseGuard != null) {
            if (finalized) {
                mCloseGuard.warnIfOpen();
            }
            mCloseGuard.close();
        }

        if (mReceiverPtr != 0) {
            nativeDispose(mReceiverPtr);
            mReceiverPtr = 0;
        }
        mInputChannel = null;
        mMessageQueue = null;
    
protected voidfinalize()

        try {
            dispose(true);
        } finally {
            super.finalize();
        }
    
public final voidfinishInputEvent(InputEvent event, boolean handled)
Finishes an input event and indicates whether it was handled. Must be called on the same Looper thread to which the receiver is attached.

param
event The input event that was finished.
param
handled True if the event was handled.

        if (event == null) {
            throw new IllegalArgumentException("event must not be null");
        }
        if (mReceiverPtr == 0) {
            Log.w(TAG, "Attempted to finish an input event but the input event "
                    + "receiver has already been disposed.");
        } else {
            int index = mSeqMap.indexOfKey(event.getSequenceNumber());
            if (index < 0) {
                Log.w(TAG, "Attempted to finish an input event that is not in progress.");
            } else {
                int seq = mSeqMap.valueAt(index);
                mSeqMap.removeAt(index);
                nativeFinishInputEvent(mReceiverPtr, seq, handled);
            }
        }
        event.recycleIfNeededAfterDispatch();
    
private static native booleannativeConsumeBatchedInputEvents(long receiverPtr, long frameTimeNanos)

private static native voidnativeDispose(long receiverPtr)

private static native voidnativeFinishInputEvent(long receiverPtr, int seq, boolean handled)

private static native longnativeInit(java.lang.ref.WeakReference receiver, InputChannel inputChannel, android.os.MessageQueue messageQueue)

public voidonBatchedInputEventPending()
Called when a batched input event is pending. The batched input event will continue to accumulate additional movement samples until the recipient calls {@link #consumeBatchedInputEvents} or an event is received that ends the batch and causes it to be consumed immediately (such as a pointer up event).

        consumeBatchedInputEvents(-1);
    
public voidonInputEvent(InputEvent event)
Called when an input event is received. The recipient should process the input event and then call {@link #finishInputEvent} to indicate whether the event was handled. No new input events will be received until {@link #finishInputEvent} is called.

param
event The input event that was received.

        finishInputEvent(event, false);