Example usage for android.view KeyEvent dispatch

List of usage examples for android.view KeyEvent dispatch

Introduction

In this page you can find the example usage for android.view KeyEvent dispatch.

Prototype

public final boolean dispatch(Callback receiver, DispatcherState state, Object target) 

Source Link

Document

Deliver this key event to a Callback interface.

Usage

From source file:com.manning.androidhacks.hack017.view.CreateAccountGallery.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    boolean handled = false;

    if (getFocusedChild() != null) {
        handled = getFocusedChild().dispatchKeyEvent(event);
    }//from  w  w  w  . j  a v  a2  s  . co m

    if (!handled) {
        handled = event.dispatch(this, null, null);
    }

    return handled;
}

From source file:android.widget.Gallery.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Gallery steals all key events
    return event.dispatch(this, null, null);
}

From source file:android.app.Activity.java

/**
 * Called to process key events.  You can override this to intercept all 
 * key events before they are dispatched to the window.  Be sure to call 
 * this implementation for key events that should be handled normally.
 * //from ww w  .  jav  a  2s  .  c  om
 * @param event The key event.
 * 
 * @return boolean Return true if this event was consumed.
 */
public boolean dispatchKeyEvent(KeyEvent event) {
    onUserInteraction();
    Window win = getWindow();
    if (win.superDispatchKeyEvent(event)) {
        return true;
    }
    View decor = mDecor;
    if (decor == null)
        decor = win.getDecorView();
    return event.dispatch(this, decor != null ? decor.getKeyDispatcherState() : null, this);
}