Best code examples for Android KeyEvent class (android.view.KeyEvent)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android KeyEvent class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android KeyEvent examples from Open Source projects
This code example shows how to use the following methods: getAction, getRepeatCount, isCanceled
        mDialog.show();
    } 
     
    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK) {
            if (event.getAction() == KeyEvent.ACTION_DOWN
                    && event.getRepeatCount() == 0) {
                Window win = mDialog.getWindow();
                if (win != null) {
                    View decor = win.getDecorView();
                    if (decor != null) {
                        KeyEvent.DispatcherState ds = decor.getKeyDispatcherState();
                        if (ds != null) {
                            ds.startTracking(event, this);
                            return true; 
                        } 
                    } 
                } 
            } else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {
                Window win = mDialog.getWindow();

9
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode, isCanceled, isTracking, handleKeyUp
        getAudioManager().preDispatchKeyEvent(event, AudioManager.USE_DEFAULT_STREAM_TYPE);
    } 
 
    public boolean dispatchKeyEvent(KeyEvent event) {
 
        final int action = event.getAction();
        final int keyCode = event.getKeyCode();
 
        if (action == KeyEvent.ACTION_DOWN) {
            return onKeyDown(keyCode, event);
        } else { 
            return onKeyUp(keyCode, event);
        } 
    } 
     
    boolean onKeyDown(int keyCode, KeyEvent event) {
        /* **************************************************************************** 
         * HOW TO DECIDE WHERE YOUR KEY HANDLING GOES. 
         * See the comment in PhoneWindow.onKeyDown 
         * ****************************************************************************/ 

8
CodeRank
This code example shows how to use the following methods: getAction, getRepeatCount, isCanceled
        mDialog.show();
    } 
     
    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK) {
            if (event.getAction() == KeyEvent.ACTION_DOWN
                    && event.getRepeatCount() == 0) {
                Window win = mDialog.getWindow();
                if (win != null) {
                    View decor = win.getDecorView();
                    if (decor != null) {
                        KeyEvent.DispatcherState ds = decor.getKeyDispatcherState();
                        if (ds != null) {
                            ds.startTracking(event, this);
                            return true; 
                        } 
                    } 
                } 
            } else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {
                Window win = mDialog.getWindow();

8
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode
        } 
    } 
 
    @Override 
    public boolean dispatchKeyEvent(KeyEvent event) {
        boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            if (!down) {
                mService.animateCollapsePanels();
            } 
            return true; 
        } 
        return super.dispatchKeyEvent(event);
    } 
 
    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        boolean intercept = false;
        if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) {
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getDevice
@RunWith(TestRunners.WithDefaults.class) 
public class KeyEventTest { 
    @Test 
    public void canSetInputDeviceOnKeyEvent() throws Exception { 
        InputDevice myDevice = ShadowInputDevice.makeInputDeviceNamed("myDevice");
        KeyEvent keyEvent = new KeyEvent(1, 2);
        shadowOf(keyEvent).setDevice(myDevice);
        assertThat(keyEvent.getDevice().getName()).isEqualTo("myDevice");
    } 
} 
Full Snippet Info
7
CodeRank
Related Android KeyEvent Questions & Answers:
Other Android KeyEvent Examples
27:		
28:		@Override
29:		public boolean onKeyDown(int keyCode, KeyEvent event) {
30:		    if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
31:		    	webview.goBack();

Read More

2:	editText.setOnEditorActionListener(new OnEditorActionListener() {
3:	    @Override
4:	    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
5:	        boolean handled = false;
6:	        if (actionId == EditorInfo.IME_ACTION_SEND) {

Read More

See Code Examples for Android KeyEvent Methods: