Example usage for android.view KeyEvent KEYCODE_DPAD_CENTER

List of usage examples for android.view KeyEvent KEYCODE_DPAD_CENTER

Introduction

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

Prototype

int KEYCODE_DPAD_CENTER

To view the source code for android.view KeyEvent KEYCODE_DPAD_CENTER.

Click Source Link

Document

Key code constant: Directional Pad Center key.

Usage

From source file:com.google.android.apps.santatracker.rocketsleigh.EndGameActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
    case KeyEvent.KEYCODE_BUTTON_A:
        //fall through
    case KeyEvent.KEYCODE_DPAD_CENTER:
        performPlayClick();//from w ww  . j  a  v  a2  s. c o  m
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:gov.nasa.arc.geocam.geocam.CameraPreviewActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_DPAD_CENTER:
        // Return here after catching camera keycode so we don't launch the built-in camera app
        return true;
    }//from   w w w .  j av a 2  s .  c om
    return super.onKeyDown(keyCode, event);
}

From source file:com.volosyukivan.WiFiInputMethod.java

void sendKey(int code, boolean down, boolean resetModifiers) {
    long time = System.currentTimeMillis();
    if (time - lastWake > 5000) {
        wakeLock.acquire();//from   w ww  .jav a  2s  . co m
        wakeLock.release();
        lastWake = time;
    }
    InputConnection conn = getCurrentInputConnection();
    if (conn == null) {
        //      Debug.d("connection closed");
        return;
    }
    if (code < 0) {
        if (down == false)
            return;
        switch (code) {
        case KEY_HOME:
            keyHome(conn);
            break;
        case KEY_END:
            keyEnd(conn);
            break;
        case KEY_DEL:
            keyDel(conn);
            break;
        }
        return;
    }

    if (code == KeyEvent.KEYCODE_DPAD_LEFT && pressedKeys.contains(KEY_CONTROL)) {
        if (down == false)
            return;
        wordLeft(conn);
        return;
    } else if (code == KeyEvent.KEYCODE_DPAD_RIGHT && pressedKeys.contains(KEY_CONTROL)) {
        if (down == false)
            return;
        wordRight(conn);
        return;
    } else if (code == KeyEvent.KEYCODE_DPAD_CENTER) {
        if (pressedKeys.contains(KEY_CONTROL)) {
            if (!down)
                return;
            copy(conn);
            return;
        }
        if (pressedKeys.contains(KeyEvent.KEYCODE_SHIFT_LEFT)) {
            if (!down)
                return;
            paste(conn);
            return;
        }
    }

    //    if (pressedKeys.contains(KEY_CONTROL)) {
    //      if (down == false) return;
    //      switch (code) {
    //      case KeyEvent.KEYCODE_A: selectAll(conn); break;
    //      case KeyEvent.KEYCODE_X: cut(conn); break;
    //      case KeyEvent.KEYCODE_C: copy(conn); break;
    //      case KeyEvent.KEYCODE_V: paste(conn); break;
    //      }
    //      return;
    //    }

    conn.sendKeyEvent(new KeyEvent(down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, code));
    if (resetModifiers) {
        conn.clearMetaKeyStates(KeyEvent.META_ALT_ON | KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON);
    }
}

From source file:butter.droid.tv.fragments.TVPlaybackOverlayFragment.java

@Override
public boolean handleInputEvent(@NonNull InputEvent event) {
    if (event instanceof KeyEvent) {
        KeyEvent keyEvent = (KeyEvent) event;
        if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_DPAD_CENTER)
            return false;
        if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
            if (mFastForwardAction != null && mSelectedActionId == mFastForwardAction.getId()) {
                if (keyEvent.getRepeatCount() == 0) {
                    mCurrentMode = MODE_FAST_FORWARD;
                    invokeFastForwardAction();
                }/*from  w  ww  . j  a  v a 2 s  .  c om*/
            } else if (mRewindAction != null && mSelectedActionId == mRewindAction.getId()) {
                if (keyEvent.getRepeatCount() == 0) {
                    mCurrentMode = MODE_REWIND;
                    invokeRewindAction();
                }
            }
        } else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
            mCurrentMode = MODE_NOTHING;
        }
    }
    return false;
}

From source file:com.xee.auth.SignInButton.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER
            || event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
        if (mListener != null) {
            mListener.onClick(this);
        }/*from   w ww  .jav a 2  s.c o m*/
        if (mConnectionCallback != null) {
            signIn();
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:org.mariotaku.harmony.activity.MusicPlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mService == null)
        return super.onKeyDown(keyCode, event);
    final int repcnt = event.getRepeatCount();

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }/*from   www . ja v a  2s.c  o m*/
        if (!mPrevButton.hasFocus()) {
            mPrevButton.requestFocus();
        }
        scanBackward(repcnt, event.getEventTime() - event.getDownTime());
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mNextButton.hasFocus()) {
            mNextButton.requestFocus();
        }
        scanForward(repcnt, event.getEventTime() - event.getDownTime());
        return true;

    // case KeyEvent.KEYCODE_R:
    // toggleRepeat();
    // return true;
    //
    // case KeyEvent.KEYCODE_S:
    // toggleShuffle();
    // return true;

    case KeyEvent.KEYCODE_N: {
        doNext();
        return true;
    }
    case KeyEvent.KEYCODE_P: {
        doPrev();
        return true;
    }
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE: {
        doPauseResume();
        return true;
    }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:gov.nasa.arc.geocam.geocam.CameraActivity.java

public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_FOCUS:
        mFocusRect.setImageDrawable(getResources().getDrawable(R.drawable.frame_unfocused_64x48));
        mLensIsFocused = false;/*  ww  w  .  j  av  a  2s .  c  om*/
        break;

    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_DPAD_CENTER:
        mPictureTaken = false;
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:gov.nasa.arc.geocam.geocam.CameraActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_FOCUS:
        if (!mLensIsFocused) {
            mFocusRect.setImageDrawable(getResources().getDrawable(R.drawable.frame_unfocused_64x48));
            mLensIsFocused = true;/*from  w  w  w . j  a  v a  2s  . c  o  m*/
            this.focusLens(false);
        }
        break;
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_DPAD_CENTER:
        if (!mPictureTaken) {
            mPictureTaken = true;
            if (!mLensIsFocused) {
                mFocusRect.setImageDrawable(getResources().getDrawable(R.drawable.frame_unfocused_64x48));
                mLensIsFocused = true;
                this.focusLens(true);
            } else {
                this.takePicture();
            }
        }
        // Return here after catching camera keycode so we don't launch the built-in camera app
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.duy.pascal.ui.editor.view.CodeSuggestsEditText.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    boolean consumed = mPopup.onKeyUp(keyCode, event);
    if (consumed) {
        switch (keyCode) {
        // if the list accepts the key events and the key event
        // was a click, the text view gets the selected item
        // from the drop down as its content
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_TAB:
            if (event.hasNoModifiers()) {
                performCompletion();/*from   ww  w  .  j  a  va2  s  .c o  m*/
            }
            return true;
        }
    }

    if (isPopupShowing() && keyCode == KeyEvent.KEYCODE_TAB && event.hasNoModifiers()) {
        performCompletion();
        return true;
    }

    return super.onKeyUp(keyCode, event);
}

From source file:com.android2.calculator3.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    // Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }//from   w ww .  j  a v a 2s  .co m

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
     * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the DOWN event isn't received, only the UP. So the workaround is to act on UP... http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}