FileDocCategorySizeDatePackage
InputEventSender.javaAPI DocAndroid 5.1 API4611Thu Mar 12 22:22:10 GMT 2015android.view

InputEventSender

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

Fields Summary
private static final String
TAG
private final dalvik.system.CloseGuard
mCloseGuard
private long
mSenderPtr
private InputChannel
mInputChannel
private android.os.MessageQueue
mMessageQueue
Constructors Summary
public InputEventSender(InputChannel inputChannel, android.os.Looper looper)
Creates an input event sender 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();
        mSenderPtr = nativeInit(new WeakReference<InputEventSender>(this),
                inputChannel, mMessageQueue);

        mCloseGuard.open("dispose");
    
Methods Summary
private voiddispatchInputEventFinished(int seq, boolean handled)

        onInputEventFinished(seq, handled);
    
public voiddispose()
Disposes the receiver.

        dispose(false);
    
private voiddispose(boolean finalized)

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

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

        try {
            dispose(true);
        } finally {
            super.finalize();
        }
    
private static native voidnativeDispose(long senderPtr)

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

private static native booleannativeSendKeyEvent(long senderPtr, int seq, KeyEvent event)

private static native booleannativeSendMotionEvent(long senderPtr, int seq, MotionEvent event)

public voidonInputEventFinished(int seq, boolean handled)
Called when an input event is finished.

param
seq The input event sequence number.
param
handled True if the input event was handled.

    
public final booleansendInputEvent(int seq, InputEvent event)
Sends an input event. Must be called on the same Looper thread to which the sender is attached.

param
seq The input event sequence number.
param
event The input event to send.
return
True if the entire event was sent successfully. May return false if the input channel buffer filled before all samples were dispatched.

        if (event == null) {
            throw new IllegalArgumentException("event must not be null");
        }
        if (mSenderPtr == 0) {
            Log.w(TAG, "Attempted to send an input event but the input event "
                    + "sender has already been disposed.");
            return false;
        }

        if (event instanceof KeyEvent) {
            return nativeSendKeyEvent(mSenderPtr, seq, (KeyEvent)event);
        } else {
            return nativeSendMotionEvent(mSenderPtr, seq, (MotionEvent)event);
        }