KeyEvent getKeyCode - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for KeyEvent getKeyCode method.

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, 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) {
7
CodeRank
This code example shows how to use the following methods:getAction, getKeyCode
	} 
 
	@Override 
	public boolean dispatchKeyEvent(KeyEvent event) {
 
        int action = event.getAction();
        int keyCode = event.getKeyCode();
 
        if ( action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK && isDrawerOpen() ) {
            closeNavigationDrawer(); 
            return true; 
        } 
 
        if ( readingFragment.dispatchKeyEvent(event) ) {
            return true; 
        } 
 
        return super.dispatchKeyEvent(event);
	} 
 

7
CodeRank
This code example shows how to use the following methods:getAction, getKeyCode, getMetaState, getUnicodeChar
        super.onDestroy(); 
    } 
 
    @Override 
    public boolean dispatchKeyEvent(KeyEvent event) {
        switch (event.getAction()) {
            case KeyEvent.ACTION_DOWN:
                int uni = event.getUnicodeChar(event.getMetaState());
                return handleKeyDown(event.getKeyCode(), uni);
            case KeyEvent.ACTION_UP:
                return handleKeyUp(event.getKeyCode());
            default: 
                return false; 
        } 
    } 
 
    @Override 
    public void setTitle(CharSequence title) {
        mTitle.setText(title);
    } 
7
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:getKeyCode, isDown
     */ 
    @Override 
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (DBG) log("dispatchKeyEvent(" + event + ")...");
 
        int keyCode = event.getKeyCode();
        if (mDialer != null) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                case KeyEvent.KEYCODE_CALL:
                    return event.isDown() ? mDialer.onKeyDown(keyCode, event) :
                        mDialer.onKeyUp(keyCode, event);
            } 
        } 
 
        if (DBG) log("==> dispatchKeyEvent: forwarding event to the DTMFDialer");
        return super.dispatchKeyEvent(event);
    } 
 
    private void log(String msg) {
7
CodeRank
This code example shows how to use the following methods:getAction, getKeyCode, getRepeatCount, isCanceled
		parent_ = (MainActivity)context;
	} 
 
	@Override 
		public boolean dispatchKeyEventPreIme(KeyEvent event) {
			if (parent_ != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
				KeyEvent.DispatcherState state = getKeyDispatcherState();
				if (state != null) {
					if (event.getAction() == KeyEvent.ACTION_DOWN &&
							event.getRepeatCount() == 0) {
						state.startTracking(event, this);
						return true; 
					} else if (event.getAction() == KeyEvent.ACTION_UP &&
							!event.isCanceled() && state.isTracking(event)) {
						parent_.hideScreenKeyboard(0);
						return true; 
					} 
				} 
			} 
			return super.dispatchKeyEventPreIme(event);
7
CodeRank
This code example shows how to use the following methods:getAction, getEventTime, getKeyCode, getMetaState, getUnicodeChar
    } 
 
    boolean translateAndSendNativeEvents(KeyEvent event) {
        if (mNativeImeAdapterAndroid == 0) return false;
 
        int action = event.getAction();
        if (action != KeyEvent.ACTION_DOWN &&
            action != KeyEvent.ACTION_UP) {
            // action == KeyEvent.ACTION_MULTIPLE 
            // TODO(bulach): confirm the actual behavior. Apparently: 
            // If event.getKeyCode() == KEYCODE_UNKNOWN, we can send a 
            // composition key down (229) followed by a commit text with the 
            // string from event.getUnicodeChars(). 
            // Otherwise, we'd need to send an event with a 
            // WebInputEvent::IsAutoRepeat modifier. We also need to verify when 
            // we receive ACTION_MULTIPLE: we may receive it after an ACTION_DOWN, 
            // and if that's the case, we'll need to review when to send the Char 
            // event. 
            return false; 
        } 

7
CodeRank
This code example shows how to use the following methods:getAction, getKeyCode
    } 
 
    @Override 
    public boolean dispatchKeyEvent(KeyEvent event) {
 
        int action = event.getAction();
        int keyCode = event.getKeyCode();
 
        if ( action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK && isDrawerOpen() ) {
            closeNavigationDrawer(); 
            return true; 
        } 
 
        return super.dispatchKeyEvent(event);
    } 
 
    protected void closeNavigationDrawer() { 
        mDrawer.closeDrawers();
    } 
 
7
CodeRank
This code example shows how to use the following methods:getAction, getKeyCode, getUnicodeChar
        if (DEBUG) Log.w(TAG, "sendKeyEvent [" + event.getAction() + "]");
 
        // If this is a key-up, and backspace/del or if the key has a character representation, 
        // need to update the underlying Editable (i.e. the local representation of the text 
        // being edited). 
        if (event.getAction() == KeyEvent.ACTION_UP) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
                super.deleteSurroundingText(1, 0); 
            } else if (event.getKeyCode() == KeyEvent.KEYCODE_FORWARD_DEL) {
                super.deleteSurroundingText(0, 1); 
            } else { 
                int unicodeChar = event.getUnicodeChar();
                if (unicodeChar != 0) {
                    Editable editable = getEditable();
                    int selectionStart = Selection.getSelectionStart(editable);
                    int selectionEnd = Selection.getSelectionEnd(editable);
                    if (selectionStart > selectionEnd) {
                        int temp = selectionStart;
                        selectionStart = selectionEnd;
                        selectionEnd = temp;

7
CodeRank

Related KeyEvent getKeyCode Questions & Answers:

getKeyCode Method Overview
Retrieve the key code of the key event.
See Code Examples for other Android KeyEvent Methods: