Example usage for android.view MotionEvent AXIS_Z

List of usage examples for android.view MotionEvent AXIS_Z

Introduction

In this page you can find the example usage for android.view MotionEvent AXIS_Z.

Prototype

int AXIS_Z

To view the source code for android.view MotionEvent AXIS_Z.

Click Source Link

Document

Axis constant: Z axis of a motion event.

Usage

From source file:tv.piratemedia.flightcontroller.ControlActivity.java

private void processJoystickInput(MotionEvent event, int historyPos) {

    InputDevice mInputDevice = event.getDevice();

    float x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_X, historyPos);

    float y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Y, historyPos);

    float z = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Z, historyPos);

    float rz = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_RZ, historyPos);

    float l = getTriggerValue(event, mInputDevice, MotionEvent.AXIS_LTRIGGER, historyPos);

    float r = getTriggerValue(event, mInputDevice, MotionEvent.AXIS_RTRIGGER, historyPos);

    if (lStickCache[0] != x || lStickCache[1] != y) {
        fragment.LeftStick.setPosition(x, y);
        lStickCache[0] = x;/* ww w. j  a v a 2s  . c o m*/
        lStickCache[1] = y;
    }

    if (rStickCache[0] != z || rStickCache[1] != rz) {
        fragment.RightStick.setPosition(z, rz);
        rStickCache[0] = z;
        rStickCache[1] = rz;
    }

    if (0f != l || 0f != r) {
        int range = fragment.throttle.getMax();
        float throttle = (float) fragment.throttle.getProgress() / range;
        if (l > 0) {
            if (l > triggerCache[0]) {
                throttle += (l - triggerCache[0]) / 2f;
            }
        } else {
            if (r > triggerCache[1]) {
                throttle -= (r - triggerCache[1]) / 2f;
            }
        }

        fragment.throttle.setProgress((int) (throttle * (float) range));
        fragment.throttle.invalidate();
    }
    triggerCache[0] = l;
    triggerCache[1] = r;
}

From source file:com.vladstirbu.cordova.Gamepad.java

/**
 * @param cordova The context of the main Activity.
 * @param webView The associated CordovaWebView.
 *///  w ww . ja  v a2s.c om
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    this.map.put("KEYCODE_BUTTON_A", 0);
    this.map.put("KEYCODE_BUTTON_B", 1);
    this.map.put("KEYCODE_BUTTON_Y", 3);
    this.map.put("KEYCODE_BUTTON_X", 2);
    this.map.put("KEYCODE_BUTTON_L1", 4);
    this.map.put("KEYCODE_BUTTON_R1", 5);
    this.map.put("KEYCODE_BUTTON_L2", 6);
    this.map.put("KEYCODE_BUTTON_R2", 7);
    this.map.put("KEYCODE_SPACE", 8);
    this.map.put("KEYCODE_SELECT", 8);
    this.map.put("KEYCODE_ENTER", 9);
    this.map.put("KEYCODE_START", 9);
    this.map.put("KEYCODE_BUTTON_THUMBL", 10);
    this.map.put("KEYCODE_BUTTON_THUMBR", 11);
    this.map.put("KEYCODE_DPAD_UP", 12);
    this.map.put("KEYCODE_DPAD_DOWN", 13);
    this.map.put("KEYCODE_DPAD_LEFT", 14);
    this.map.put("KEYCODE_DPAD_RIGHT", 15);
    this.map.put("KEYCODE_BACK", 16);
    this.map.put("KEYCODE_BUTTON_MODE", 16);

    this.webView.setFocusable(true);
    this.webView.setFocusableInTouchMode(true);
    this.webView.requestFocus();

    this.webView.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            //Log.v("Keyboards", String.valueOf(InputDevice.getDeviceIds().length));
            //Log.v("Input", InputDevice.getDevice(1).getName());
            //Log.v("Input", String.valueOf(InputDevice.getDevice(1).getSources()));

            //Log.v("Device id", String.valueOf(event.getDeviceId()));
            //Log.v("Source id", String.valueOf(event.getSource()));
            //Log.v("Input device", String.valueOf(InputDevice.getDevice(event.getDeviceId()).getName()));
            Log.v("KEY", String.valueOf(event.getScanCode()));
            Log.v("KEY", KeyEvent.keyCodeToString(keyCode));
            //Log.v("GamePad", String.valueOf(KeyEvent.isGamepadButton(keyCode)));

            String jsStr = jsString(keyCode, event);
            if (!jsStr.isEmpty()) {
                self.webView.sendJavascript(jsStr);
            }
            return true;
        }
    });
    this.webView.setOnGenericMotionListener(new OnGenericMotionListener() {
        public boolean onGenericMotion(View v, MotionEvent event) {
            if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
                if (event.getAction() == MotionEvent.ACTION_MOVE) {
                    // process the joystick movement...
                    JSONObject data = new JSONObject();
                    JSONArray axes = new JSONArray();
                    try {
                        axes.put(event.getAxisValue(MotionEvent.AXIS_X));
                        axes.put(event.getAxisValue(MotionEvent.AXIS_Y));
                        axes.put(event.getAxisValue(MotionEvent.AXIS_Z));
                        axes.put(event.getAxisValue(MotionEvent.AXIS_RZ));
                        data.put("deviceId", event.getDeviceId());
                        data.put("axes", axes);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    self.webView.sendJavascript(
                            "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");

                    data = new JSONObject();
                    try {
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 6);
                        data.put("value", event.getAxisValue(MotionEvent.AXIS_LTRIGGER));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    self.webView.sendJavascript(
                            "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");

                    data = new JSONObject();
                    try {
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 7);
                        data.put("value", event.getAxisValue(MotionEvent.AXIS_RTRIGGER));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    self.webView.sendJavascript(
                            "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");

                    float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
                    float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
                    try {
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 14);
                        data.put("value", hatX < 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 15);
                        data.put("value", hatX > 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                    } catch (JSONException e) {
                    }
                    try {
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 12);
                        data.put("value", hatY < 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 13);
                        data.put("value", hatY > 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                    } catch (JSONException e) {
                    }
                }
                Log.v("MOTION", event.toString());
                return true;
            }
            return false;
        }
    });

    Log.v("GamepadButtons", "initialized");
}

From source file:com.amazon.appstream.fireclient.FireClientActivity.java

/**
 * A "generic motion event" includes joystick and mouse motion
 * when the mouse button isn't down. In our simple sample, we're
 * not handling the joystick, but this is where any such code
 * would live.//  w ww  .  j  a va2  s.  c o m
 *
 * This will only ever be called in HONEYCOMB_MR1 (12) or later, so I'm marking the
 * function using \@TargetApi to allow it to call the super.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    if (event.getSource() == InputDevice.SOURCE_MOUSE) {
        event.getPointerCoords(0, mCoordHolder);
        switch (event.getAction()) {
        case MotionEvent.ACTION_HOVER_MOVE:
            AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, 0);
            break;

        default:
            return super.dispatchGenericMotionEvent(event);
        }
        return true;
    } else if (event.getSource() == InputDevice.SOURCE_JOYSTICK) {
        Log.v(TAG, "Joystick event:" + event.toString());

        if (!mInitializedJoystick) {
            mInitializedJoystick = true;

            InputDevice joystick = InputDevice.getDevice(event.getDeviceId());
            InputDevice.MotionRange lThumbX = joystick.getMotionRange(MotionEvent.AXIS_X,
                    InputDevice.SOURCE_JOYSTICK);
            InputDevice.MotionRange lThumbY = joystick.getMotionRange(MotionEvent.AXIS_Y,
                    InputDevice.SOURCE_JOYSTICK);
            InputDevice.MotionRange rThumbX = joystick.getMotionRange(MotionEvent.AXIS_Z);
            InputDevice.MotionRange rThumbY = joystick.getMotionRange(MotionEvent.AXIS_RZ);
            InputDevice.MotionRange rTrigger = joystick.getMotionRange(MotionEvent.AXIS_GAS);
            if (rTrigger == null) {
                rTrigger = joystick.getMotionRange(MotionEvent.AXIS_RTRIGGER);
                mRTrigger = MotionEvent.AXIS_RTRIGGER;
            }

            InputDevice.MotionRange lTrigger = joystick.getMotionRange(MotionEvent.AXIS_BRAKE);
            if (lTrigger == null) {
                lTrigger = joystick.getMotionRange(MotionEvent.AXIS_LTRIGGER);
                mLTrigger = MotionEvent.AXIS_LTRIGGER;
            }

            List<InputDevice.MotionRange> ranges = joystick.getMotionRanges();

            InputDevice.MotionRange dPad = null;
            String name = joystick.getName();

            /*
            The Amazon Fire Game Controller follows the NVidia standard of sending
            AXIS_HAT_X/AXIS_HAT_Y results when the user hits the D-Pad. Only if we
            return false from dispatchGenericMotionEvent() will it then send
            DPAD keycodes.
                    
            But the most popular Android joystick on the market at this time, the
            Nyko Playpad Pro, returns AXIS_HAT_X/AXIS_HAT_Y results when the left
            analog stick hits its extremes, meaning that the analog stick will
            generate DPAD keys if we return false. The Nyko generates DPAD keys
            directly for the DPAD controller.
                    
            So we have two incompatible standards fighting with each other. Probably
            the safest thing to do would be to ask the user to press on their DPAD
            and see what messages we get, but that is beyond the scope of this
            example code.
            */
            if (name.equals("Amazon Fire Game Controler")) {
                for (int i = 0; i < ranges.size(); ++i) {
                    InputDevice.MotionRange range = ranges.get(i);
                    int axis = range.getAxis();

                    if (axis == MotionEvent.AXIS_HAT_X || axis == MotionEvent.AXIS_HAT_Y) {
                        dPad = ranges.get(i);
                        break;
                    }
                }
            }

            JoystickHelper.joystickDeadZones(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, dPad);
        }

        float lThumbX = event.getAxisValue(MotionEvent.AXIS_X);
        float lThumbY = -event.getAxisValue(MotionEvent.AXIS_Y);
        float rThumbX = event.getAxisValue(MotionEvent.AXIS_Z);
        float rThumbY = -event.getAxisValue(MotionEvent.AXIS_RZ);
        float lTrigger = event.getAxisValue(mLTrigger);
        float rTrigger = event.getAxisValue(mRTrigger);
        float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
        float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);

        JoystickHelper.setJoystickState(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, hatX, hatY);
        return true;
    }

    return super.dispatchGenericMotionEvent(event);
}

From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java

private void processJoystickInput(MotionEvent event, int historyPos) {

    InputDevice mInputDevice = event.getDevice();

    // Calculate the horizontal distance to move by
    // using the input value from one of these physical controls:
    // the left control stick, hat axis, or the right control stick.
    float x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_X, historyPos);
    if (x == 0) {
        x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_HAT_X, historyPos);
    }/*  w w w  .j a  va 2  s .  c o m*/
    if (x == 0) {
        x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Z, historyPos);
    }

    // Calculate the vertical distance to move by
    // using the input value from one of these physical controls:
    // the left control stick, hat switch, or the right control stick.
    float y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Y, historyPos);
    if (y == 0) {
        y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_HAT_Y, historyPos);
    }
    if (y == 0) {
        y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_RZ, historyPos);
    }

    deltaJoystick = ((Math.abs(oldJoystickX - x) >= 0.1) || (Math.abs(oldJoystickY - y) >= 0.1));

    JoystickData joystickDataX = new JoystickData("x", x);
    JoystickData joystickDataY = new JoystickData("y", y);

    if (deltaJoystick) {

        mPitch.setText("y is :" + y);
        oldJoystickX = x;
        oldJoystickY = y;

        if (client != null) {
            try {

                //client.send("servo01", "moveTo",(roll+90.0));
                client.send("joystick", "publishJoystickInput", joystickDataX);
                client.send("joystick", "publishJoystickInput", joystickDataY);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private void processJoystickInput(MotionEvent event, int historyPos) {
    float hatX = 0.0f;
    InputDevice.MotionRange range = event.getDevice().getMotionRange(MotionEvent.AXIS_HAT_X, event.getSource());
    if (range != null) {
        if (historyPos >= 0) {
            hatX = InputDeviceState.ProcessAxis(range,
                    event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_X, historyPos));
        } else {/*from w  ww .j ava  2s . c o  m*/
            hatX = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_HAT_X));
        }
    }

    float hatY = 0.0f;
    range = event.getDevice().getMotionRange(MotionEvent.AXIS_HAT_Y, event.getSource());
    if (range != null) {
        if (historyPos >= 0) {
            hatY = InputDeviceState.ProcessAxis(range,
                    event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_Y, historyPos));
        } else {
            hatY = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_HAT_Y));
        }
    }

    float joyX = 0.0f;
    range = event.getDevice().getMotionRange(MotionEvent.AXIS_X, event.getSource());
    if (range != null) {
        if (historyPos >= 0) {
            joyX = InputDeviceState.ProcessAxis(range,
                    event.getHistoricalAxisValue(MotionEvent.AXIS_X, historyPos));
        } else {
            joyX = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_X));
        }
    }

    float joyY = 0.0f;
    range = event.getDevice().getMotionRange(MotionEvent.AXIS_Y, event.getSource());
    if (range != null) {
        if (historyPos >= 0) {
            joyY = InputDeviceState.ProcessAxis(range,
                    event.getHistoricalAxisValue(MotionEvent.AXIS_Y, historyPos));
        } else {
            joyY = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_Y));
        }
    }

    float joy2X = 0.0f;
    range = event.getDevice().getMotionRange(MotionEvent.AXIS_Z, event.getSource());
    if (range != null) {
        if (historyPos >= 0) {
            joy2X = InputDeviceState.ProcessAxis(range,
                    event.getHistoricalAxisValue(MotionEvent.AXIS_Z, historyPos));
        } else {
            joy2X = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_Z));
        }
    }

    float joy2Y = 0.0f;
    range = event.getDevice().getMotionRange(MotionEvent.AXIS_RZ, event.getSource());
    if (range != null) {
        if (historyPos >= 0) {
            joy2Y = InputDeviceState.ProcessAxis(range,
                    event.getHistoricalAxisValue(MotionEvent.AXIS_RZ, historyPos));
        } else {
            joy2Y = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_RZ));
        }
    }

    if (mAnalogStickPref == 0) {
        mMouseThread.setCoord(
                (int) ((Math.abs(joyX * 32.0f) > DEADZONE) ? (-joyX * 32.0f * mMouseSensitivityX) : 0),
                (int) ((Math.abs(joyY * 32.0f) > DEADZONE) ? (-joyY * 32.0f * mMouseSensitivityY) : 0));
        DosBoxControl.nativeJoystick((int) ((joy2X * 256.0f) + mJoyCenterX),
                (int) ((joy2Y * 256.0f) + mJoyCenterY), ACTION_MOVE, -1);
    } else {
        mMouseThread.setCoord(
                (int) ((Math.abs(joy2X * 32.0f) > DEADZONE) ? (-joy2X * 32.0f * mMouseSensitivityX) : 0),
                (int) ((Math.abs(joy2Y * 32.0f) > DEADZONE) ? (-joy2Y * 32.0f * mMouseSensitivityY) : 0));
        DosBoxControl.nativeJoystick((int) ((joyX * 256.0f) + mJoyCenterX),
                (int) ((joyY * 256.0f) + mJoyCenterY), ACTION_MOVE, -1);
    }

    // Handle all other keyevents
    int value = 0;
    int tKeyCode = MAP_NONE;

    if (hatX < 0) {
        value = customMap.get(KeyEvent.KEYCODE_DPAD_LEFT);
        if (value > 0) {
            // found a valid mapping
            tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT));
            if (tKeyCode > MAP_NONE) {
                DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift);
            }
        }
        hatXlast = hatX;
    } else if (hatX > 0) {
        value = customMap.get(KeyEvent.KEYCODE_DPAD_RIGHT);
        if (value > 0) {
            // found a valid mapping
            tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT));
            if (tKeyCode > MAP_NONE) {
                DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift);
            }
        }
        hatXlast = hatX;
    } else {
        // released
        if (hatX != hatXlast) {
            if (hatXlast < 0) {
                value = customMap.get(KeyEvent.KEYCODE_DPAD_LEFT);
                if (value > 0) {
                    // found a valid mapping
                    tKeyCode = getMappedKeyCode(value,
                            new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_LEFT));
                    if (tKeyCode > MAP_NONE) {
                        DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt,
                                mModifierShift);
                    }
                }
            } else if (hatXlast > 0) {
                value = customMap.get(KeyEvent.KEYCODE_DPAD_RIGHT);
                if (value > 0) {
                    // found a valid mapping
                    tKeyCode = getMappedKeyCode(value,
                            new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_RIGHT));
                    if (tKeyCode > MAP_NONE) {
                        DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt,
                                mModifierShift);
                    }
                }
            }
        }
        hatXlast = hatX;
    }
    if (hatY < 0) {
        value = customMap.get(KeyEvent.KEYCODE_DPAD_UP);
        if (value > 0) {
            // found a valid mapping
            tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP));
            if (tKeyCode > MAP_NONE) {
                DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift);
            }
        }
        hatYlast = hatY;
    } else if (hatY > 0) {
        value = customMap.get(KeyEvent.KEYCODE_DPAD_DOWN);
        if (value > 0) {
            // found a valid mapping
            tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN));
            if (tKeyCode > MAP_NONE) {
                DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift);
            }
        }
        hatYlast = hatY;
    } else {
        // released
        if (hatY != hatYlast) {
            if (hatYlast < 0) {
                value = customMap.get(KeyEvent.KEYCODE_DPAD_UP);
                if (value > 0) {
                    // found a valid mapping
                    tKeyCode = getMappedKeyCode(value,
                            new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_UP));
                    if (tKeyCode > MAP_NONE) {
                        DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt,
                                mModifierShift);
                    }
                }
            } else if (hatYlast > 0) {
                value = customMap.get(KeyEvent.KEYCODE_DPAD_DOWN);
                if (value > 0) {
                    // found a valid mapping
                    tKeyCode = getMappedKeyCode(value,
                            new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN));
                    if (tKeyCode > MAP_NONE) {
                        DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt,
                                mModifierShift);
                    }
                }
            }
        }
        hatYlast = hatY;
    }
}

From source file:jmri.enginedriver.throttle.java

@Override
public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) {
    //Log.d("Engine_Driver", "dgme " + event.getAction());
    //        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) {
    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;
        int whichThrottle;
        int repeatCnt = 0;
        int whichGamePadIsEventFrom = findWhichGamePadEventIsFrom(event.getDeviceId(), 0); // dummy eventKeyCode

        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;/*from w w  w.  j  av a  2s.c  o  m*/
            }
        } else {
            acceptEvent = false;
        }

        if (acceptEvent) {
            float xAxis;
            xAxis = event.getAxisValue(MotionEvent.AXIS_X);
            float yAxis = event.getAxisValue(MotionEvent.AXIS_Y);
            float xAxis2 = event.getAxisValue(MotionEvent.AXIS_Z);
            float yAxis2 = event.getAxisValue(MotionEvent.AXIS_RZ);

            if ((xAxis != 0) || (yAxis != 0)) {
                action = ACTION_DOWN;
            } else {
                action = ACTION_UP;
            }
            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 (action == ACTION_UP) {
                mGamepadAutoIncrement = false;
                mGamepadAutoDecrement = false;
                GamepadFeedbackSoundStop();
            }

            if (yAxis == -1) { // DPAD Up Button
                performButtonAction(5, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                return (true); // stop processing this key

            } else if (yAxis == 1) { // DPAD Down Button
                performButtonAction(7, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                return (true); // stop processing this key

            } else if (xAxis == -1) { // DPAD Left Button
                performButtonAction(8, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                return (true); // stop processing this key

            } else if (xAxis == 1) { // DPAD Right Button
                performButtonAction(6, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                return (true); // stop processing this key
            }

            if (yAxis2 == -1) { // DPAD2 Up Button
                performButtonAction(5, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                return (true); // stop processing this key

            } else if (yAxis2 == 1) { // DPAD2 Down Button
                performButtonAction(7, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                return (true); // stop processing this key

            } else if (xAxis2 == -1) { // DPAD2 Left Button
                performButtonAction(8, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt);
                return (true); // stop processing this key

            } else if (xAxis2 == 1) { // DPAD2 Right Button
                performButtonAction(6, 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
        }
        //            }
    }
    return super.dispatchGenericMotionEvent(event);
}