Example usage for android.view View getKeyDispatcherState

List of usage examples for android.view View getKeyDispatcherState

Introduction

In this page you can find the example usage for android.view View getKeyDispatcherState.

Prototype

public KeyEvent.DispatcherState getKeyDispatcherState() 

Source Link

Document

Return the global KeyEvent.DispatcherState KeyEvent.DispatcherState for this view's window.

Usage

From source file:com.atwal.wakeup.battery.util.Utilities.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean isViewAttachedToWindow(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return v.isAttachedToWindow();
    } else {/* w  w  w. ja v  a 2 s. co  m*/
        // A proxy call which returns null, if the view is not attached to the window.
        return v.getKeyDispatcherState() != null;
    }
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * Filter pre-IME key events. By forwarding {@link View#onKeyPreIme(int, KeyEvent)}
 * events to this function, views using ListPopupWindow can have it dismiss the popup
 * when the back key is pressed./*  w  w w . ja  va2 s  . c  o m*/
 *
 * @param keyCode keyCode param passed to the host view's onKeyPreIme
 * @param event event param passed to the host view's onKeyPreIme
 * @return true if the event was handled, false if it was ignored.
 * @see #setModal(boolean)
 */
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && isShowing()) {
        // special case for the back key, we do not even try to send it
        // to the drop down list but instead, consume it immediately
        final View anchorView = mDropDownAnchorView;
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState();
            if (state != null) {
                state.startTracking(event, this);
            }
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState();
            if (state != null) {
                state.handleUpEvent(event);
            }
            if (event.isTracking() && !event.isCanceled()) {
                dismiss();
                return true;
            }
        }
    }
    return false;
}

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.
 * /* ww  w  . j  av a 2 s. c  o m*/
 * @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);
}