KeyEvent getAction - 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 getAction method.

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) {
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: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
        return a.getInt(index, 0);
    } 
 
    @Override 
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (event.getAction() != KeyEvent.ACTION_UP) {
            if (keyCode == KeyEvent.KEYCODE_PLUS
                    || keyCode == KeyEvent.KEYCODE_EQUALS) {
                setProgress(getProgress() + 1); 
                return true; 
            } 
            if (keyCode == KeyEvent.KEYCODE_MINUS) {
                setProgress(getProgress() - 1); 
                return true; 
            } 
        } 
        return false; 
    } 
 
    @Override 
7
CodeRank

Related KeyEvent getAction Questions & Answers:

getAction Method Overview
Retrieve the action of this key event.
See Code Examples for other Android KeyEvent Methods: