Example usage for android.view InputDevice toString

List of usage examples for android.view InputDevice toString

Introduction

In this page you can find the example usage for android.view InputDevice toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:jmri.enginedriver.throttle.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    boolean isExternal = false;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        InputDevice idev = getDevice(event.getDeviceId());
        if (idev != null && idev.toString() != null && idev.toString().contains("Location: external"))
            isExternal = true;//from  w  ww. j ava 2 s .c o  m
    }

    if (isExternal) { // if has come from the phone itself, don't try to process it here
        if (!whichGamePadMode.equals(WHICH_GAMEPAD_MODE_NONE)) { // respond to the gamepad and keyboard inputs only if the preference is set

            boolean acceptEvent = true; // default to assuming that we will respond to the event

            int action = event.getAction();
            int keyCode = event.getKeyCode();
            int repeatCnt = event.getRepeatCount();
            int whichThrottle;
            int whichGamePadIsEventFrom = findWhichGamePadEventIsFrom(event.getDeviceId(), event.getKeyCode());

            if ((whichGamePadIsEventFrom > -1) && (whichGamePadIsEventFrom < gamePadDeviceIdsTested.length)) { // the event came from a gamepad
                if (gamePadDeviceIdsTested[getGamePadIndexFromThrottleNo(
                        whichGamePadIsEventFrom)] != GAMEPAD_GOOD) { //if not, testing for this gamepad is not complete or has failed
                    acceptEvent = false;
                }
            } else {
                acceptEvent = false;
            }

            if (acceptEvent) {
                if ((usingMultiplePads) && (whichGamePadIsEventFrom >= -1)) { // we have multiple gamepads AND the preference is set to make use of them AND the event came for a gamepad
                    if (whichGamePadIsEventFrom >= 0) {
                        whichThrottle = whichGamePadIsEventFrom;
                    } else {
                        GamepadFeedbackSound(true);
                        return (true);
                    }
                } else {
                    whichThrottle = whichVolume; // work out which throttle the volume keys are currently set to contol... and use that one
                }

                boolean isActive = getConsist(whichThrottle).isActive();

                if (keyCode != 0) {
                    Log.d("Engine_Driver", "keycode " + keyCode + " action " + action + " repeat " + repeatCnt);
                }

                if (action == ACTION_UP) {
                    mGamepadAutoIncrement = false;
                    mGamepadAutoDecrement = false;
                    GamepadFeedbackSoundStop();
                }

                if (keyCode == gamePadKeys[2]) { // DPAD Up Button
                    performButtonAction(5, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[3]) { // DPAD Down Button
                    performButtonAction(7, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[4]) { // DPAD Left Button
                    performButtonAction(8, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[5]) { // DPAD Right Button
                    performButtonAction(6, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[7]) { // ios button
                    performButtonAction(1, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys_Up[8]) { // X button
                    performButtonAction(3, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys_Up[9]) { // Triangle button
                    performButtonAction(2, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys_Up[10]) { // @ button
                    performButtonAction(4, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[6]) { // start button
                    performButtonAction(0, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[11]) { // Left Shoulder button
                    performButtonAction(10, action, isActive, whichThrottle, whichGamePadIsEventFrom,
                            repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[12]) { // Left Shoulder button
                    performButtonAction(11, action, isActive, whichThrottle, whichGamePadIsEventFrom,
                            repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[13]) { // Left Shoulder button
                    performButtonAction(12, action, isActive, whichThrottle, whichGamePadIsEventFrom,
                            repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[14]) { // Left Shoulder button
                    performButtonAction(13, action, isActive, whichThrottle, whichGamePadIsEventFrom,
                            repeatCnt);
                    return (true); // stop processing this key

                } else if (keyCode == gamePadKeys[1]) { // Return button
                    // NextThrottle
                    /* if ((action == ACTION_DOWN) && (repeatCnt == 0)) {
                        if (usingMultiplePads && whichGamePadIsEventFrom >= 0) {
                    whichGamePadIsEventFrom = swapToNextAvilableThrottleForGamePad(whichGamePadIsEventFrom, false);
                        } else {
                    setNextActiveThrottle(true);
                        }
                    } */
                    performButtonAction(9, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                    return (true); // stop processing this key
                }
            } else { // event is from a gamepad that has not finished testing. Ignore it
                return (true); // stop processing this key
            }
            //  for now pass all keystrokes not in gamePadKeys[] to super
            //  if problems occur, we can uncomment the next 2 lines
            //            else if (!((keyCode == KEYCODE_BACK) || (keyCode == KEYCODE_VOLUME_DOWN) || (keyCode == KEYCODE_VOLUME_UP) || (keyCode == KEYCODE_MENU)))
            //            return (true); // swallow all other keystrokes except back, menu and the volume keys
        }
    } else if (IS_ESU_MCII) {
        // Process ESU MCII keys
        int action = event.getAction();
        int keyCode = event.getKeyCode();
        int repeatCnt = event.getRepeatCount();
        boolean isActive = getConsist(whichVolume).isActive();

        if (keyCode != 0) {
            Log.d("Engine_Driver",
                    "ESU_MCII: keycode " + keyCode + " action " + action + " repeat " + repeatCnt);
            if (action == ACTION_UP) {
                esuButtonAutoIncrement = false;
                esuButtonAutoDecrement = false;
            }

            switch (keyCode) {
            case MobileControl2.KEYCODE_TOP_LEFT:
            case MobileControl2.KEYCODE_BOTTOM_LEFT:
            case MobileControl2.KEYCODE_TOP_RIGHT:
            case MobileControl2.KEYCODE_BOTTOM_RIGHT:
                performEsuMc2ButtonAction(keyCode, action, isActive, whichVolume, repeatCnt);
                return true; // stop processing this key
            default:
                // Unrecognised key - do nothing
                Log.d("Engine_Driver", "ESU_MCII: Unrecognised keyCode: " + keyCode);

            }
        }
    }
    return super.dispatchKeyEvent(event);
}