@@ -0,0 +1,2686 @@
+package com.melons.input;%0A%0Aimport android.view.InputDevice;%0Aimport android.view.MotionEvent;%0A%0Aimport com.melons.common.Vec2;%0A%0Apublic class Joystick %7B%0A%0A%09public static boolean isJoystickDevice(MotionEvent event) %7B%0A%09%09%0A%09%09if ((event.getSource() & InputDevice.SOURCE_JOYSTICK)%0A%09%09%09%09== InputDevice.SOURCE_JOYSTICK) %7B%0A%09%09%09return true;%0A%09%09%7D else %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%7D%0A%09%0A%09public static boolean isMoveAction(MotionEvent event) %7B%0A%09%09%0A%09%09if (event.getAction() == MotionEvent.ACTION_MOVE) %7B%0A%09%09%09return true;%0A%09%09%7D else %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%7D%0A%09%0A%09public static Vec2 processJoystickInput(MotionEvent event, int historyPos) %7B%0A%0A%09    InputDevice mInputDevice = event.getDevice();%0A%0A%09    // Calculate the horizontal distance to move by%0A%09    // using the input value from one of these physical controls:%0A%09    // the left control stick, hat axis, or the right control stick.%0A%09    float x = getCenteredAxis(event, mInputDevice,%0A%09            MotionEvent.AXIS_X, historyPos);%0A%09    if (x == 0) %7B%0A%09        x = getCenteredAxis(event, mInputDevice,%0A%09                MotionEvent.AXIS_HAT_X, historyPos);%0A%09    %7D%0A%09    if (x == 0) %7B%0A%09        x = getCenteredAxis(event, mInputDevice,%0A%09                MotionEvent.AXIS_Z, historyPos);%0A%09    %7D%0A%0A%09    // Calculate the vertical distance to move by%0A%09    // using the input value from one of these physical controls:%0A%09    // the left control stick, hat switch, or the right control stick.%0A%09    float y = getCenteredAxis(event, mInputDevice,%0A%09            MotionEvent.AXIS_Y, historyPos);%0A%09    if (y == 0) %7B%0A%09        y = getCenteredAxis(event, mInputDevice,%0A%09                MotionEvent.AXIS_HAT_Y, historyPos);%0A%09    %7D%0A%09    if (y == 0) %7B%0A%09        y = getCenteredAxis(event, mInputDevice,%0A%09                MotionEvent.AXIS_RZ, historyPos);%0A%09    %7D%0A%0A%09    Vec2 ret = new Vec2(x, y);%0A%09    return ret;%0A%09%7D%0A%09%0A%09/*%0A%09 * Private static Methods%0A%09 */%0A%09private static float getCenteredAxis(MotionEvent event,%0A%09        InputDevice device, int axis, int historyPos) %7B%0A%09    final InputDevice.MotionRange range =%0A%09            device.getMotionRange(axis, event.getSource());%0A%0A%09    // A joystick at rest does not always report an absolute position of%0A%09    // (0,0). Use the getFlat() method to determine the range of values%0A%09    // bounding the joystick axis center.%0A%09    if (range != null) %7B%0A%09        final float flat = range.getFlat();%0A%09        final float value =%0A%09                historyPos %3C 0 ? event.getAxisValue(axis):%0A%09                event.getHistoricalAxisValue(axis, historyPos);%0A%0A%09        // Ignore axis values that are within the 'flat' region of the%0A%09        // joystick axis center.%0A%09        if (Math.abs(value) %3E flat) %7B%0A%09            return value;%0A%09        %7D%0A%09    %7D%0A%09    return 0;%0A%09%7D%0A%7D%0A

add JoyStick.java