Example usage for android.view KeyEvent KEYCODE_DPAD_RIGHT

List of usage examples for android.view KeyEvent KEYCODE_DPAD_RIGHT

Introduction

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

Prototype

int KEYCODE_DPAD_RIGHT

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

Click Source Link

Document

Key code constant: Directional Pad Right key.

Usage

From source file:Main.java

/**
 * Checks whether the given event is any of DPAD right or NUMPAD right.
 * @param event Event to be checked.//from www. j  av  a2  s . c o m
 * @return Whether the event should be processed as a navigation right.
 */
public static boolean isGoRight(KeyEvent event) {
    return isActionDown(event) && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT
            || (!event.isNumLockOn() && event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_6));
}

From source file:Main.java

public static String getChar(int keyCode) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_0:
        return "0";
    case KeyEvent.KEYCODE_1:
        return "1";
    case KeyEvent.KEYCODE_2:
        return "2";
    case KeyEvent.KEYCODE_3:
        return "3";
    case KeyEvent.KEYCODE_4:
        return "4";
    case KeyEvent.KEYCODE_5:
        return "5";
    case KeyEvent.KEYCODE_6:
        return "6";
    case KeyEvent.KEYCODE_7:
        return "7";
    case KeyEvent.KEYCODE_8:
        return "8";
    case KeyEvent.KEYCODE_9:
        return "9";
    case KeyEvent.KEYCODE_A:
        return "a";
    case KeyEvent.KEYCODE_B:
        return "b";
    case KeyEvent.KEYCODE_C:
        return "c";
    case KeyEvent.KEYCODE_D:
        return "d";
    case KeyEvent.KEYCODE_E:
        return "e";
    case KeyEvent.KEYCODE_F:
        return "f";
    case KeyEvent.KEYCODE_G:
        return "g";
    case KeyEvent.KEYCODE_H:
        return "h";
    case KeyEvent.KEYCODE_I:
        return "i";
    case KeyEvent.KEYCODE_J:
        return "j";
    case KeyEvent.KEYCODE_K:
        return "k";
    case KeyEvent.KEYCODE_L:
        return "l";
    case KeyEvent.KEYCODE_M:
        return "m";
    case KeyEvent.KEYCODE_N:
        return "n";
    case KeyEvent.KEYCODE_O:
        return "o";
    case KeyEvent.KEYCODE_P:
        return "p";
    case KeyEvent.KEYCODE_Q:
        return "q";
    case KeyEvent.KEYCODE_R:
        return "r";
    case KeyEvent.KEYCODE_S:
        return "s";
    case KeyEvent.KEYCODE_T:
        return "t";
    case KeyEvent.KEYCODE_U:
        return "u";
    case KeyEvent.KEYCODE_V:
        return "v";
    case KeyEvent.KEYCODE_W:
        return "w";
    case KeyEvent.KEYCODE_X:
        return "x";
    case KeyEvent.KEYCODE_Y:
        return "y";
    case KeyEvent.KEYCODE_Z:
        return "z";
    case KeyEvent.KEYCODE_DEL:
        return "{BKSP}";
    case KeyEvent.KEYCODE_ENTER:
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "{ENTER}";
    case KeyEvent.KEYCODE_SPACE:
        return " ";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "{DOWN}";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "{UP}";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "{LEFT}";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "{RIGHT}";
    }//from   ww w  .ja  va2 s. c  o m
    return null;
}

From source file:com.oda.calculator.EventListener.java

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

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/*from  w  ww . j  a v  a2 s  .  c o m*/

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    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;
}

From source file:com.aman.stockcalculator.EventListener.java

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

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/* w ww .j ava  2  s .  co m*/

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    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;
}

From source file:com.seuf.arseuf.arseuf.java

public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (event.getRepeatCount() == 0) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            startActivity(new Intent(this, Preferences.class));
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
            sendRequestToArduino("fwd");
            break; // Cross = FORWARD
        case KeyEvent.KEYCODE_BUTTON_X:
            sendRequestToArduino("back");
            break; // square = BACKWARD
        case KeyEvent.KEYCODE_DPAD_LEFT:
            sendRequestToArduino("tl");
            break; // Left Dpad = turn left
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            sendRequestToArduino("tr");
            break; // Right Dpad = turn right
        case KeyEvent.KEYCODE_BUTTON_Y:
            sendRequestToArduino("play");
            break; // triangle = klaxon
        }//from www .ja  v a2s  .  c om
    }
    return true;
}

From source file:android.support.v17.leanback.app.BrowseFragmentTest.java

public void testTwoBackKeysWithBackStack() throws Throwable {
    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), BrowseFragmentTestActivity.class);
    intent.putExtra(BrowseFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, (long) 1000);
    intent.putExtra(BrowseFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK, true);
    initActivity(intent);/*from   w  w  w  . j  a  va2 s .  co m*/

    sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    Thread.sleep(TRANSITION_LENGTH);

    sendKeys(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BACK);
}

From source file:tinkercoder.stockcalculator.calculator.EventListener.java

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

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }//  www  .ja v  a2s  .c o  m

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    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) {
        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;
}

From source file:android.support.v17.leanback.app.BrowseSupportFragmentTest.java

public void testTwoBackKeysWithBackStack() throws Throwable {
    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), BrowseSupportFragmentTestActivity.class);
    intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, (long) 1000);
    intent.putExtra(BrowseSupportFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK, true);
    initActivity(intent);//from   w  ww  .ja va  2 s.co m

    sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    Thread.sleep(TRANSITION_LENGTH);

    sendKeys(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BACK);
}

From source file:com.manning.androidhacks.hack017.CreateAccountActivity.java

@Override
public void scroll(int type) {

    switch (type) {
    case FORWARD:
    default://from   w  ww.  j  a va  2 s  .  com

        if (mGalleryPosition < mGallery.getCount() - 1) {
            mGallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, new KeyEvent(0, 0));
            mGalleryPosition++;
        }
        break;

    case BACKWARD:
        if (mGalleryPosition > 0) {
            mGallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, new KeyEvent(0, 0));
            mGalleryPosition--;
        }
    }
}

From source file:android.support.v17.leanback.app.BrowseFragmentTest.java

public void testTwoBackKeysWithoutBackStack() throws Throwable {
    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), BrowseFragmentTestActivity.class);
    intent.putExtra(BrowseFragmentTestActivity.EXTRA_LOAD_DATA_DELAY, (long) 1000);
    intent.putExtra(BrowseFragmentTestActivity.EXTRA_ADD_TO_BACKSTACK, false);
    initActivity(intent);//from   w  ww  .j  a  v a  2s.  c o  m

    sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    Thread.sleep(TRANSITION_LENGTH);

    sendKeys(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BACK);
}