@@ -0,0 +1,3053 @@
+package com.melons.input;%0A%0Aimport android.view.InputDevice;%0Aimport android.view.InputEvent;%0Aimport android.view.KeyEvent;%0Aimport android.view.MotionEvent;%0A%0A/*%0A * %EC%9B%90%EB%B3%B8:%0A * https://developer.android.com/training/game-controllers/controller-input.html%0A * %EC%97%90%EC%84%9C %EC%88%98%EC%A0%95%ED%95%A8.%0A */%0A%0Apublic class Dpad %7B%0A%09public final static int IS_NOT_DPAD = -1;%0A%09public final static int UP          = 0;%0A%09public final static int LEFT        = 1;%0A%09public final static int RIGHT       = 2;%0A%09public final static int DOWN        = 3;%0A%09public final static int CENTER      = 4;%0A%0A    int directionPressed = -1; // initialized to -1%0A%0A    public int getDirectionPressed(InputEvent event) %7B%0A        if (!isDpadDevice(event)) %7B%0A           return Dpad.IS_NOT_DPAD;%0A        %7D%0A%0A        // If the input event is a MotionEvent, check its hat axis values.%0A        if (event instanceof MotionEvent) %7B%0A%0A            // Use the hat axis value to find the D-pad direction%0A            MotionEvent motionEvent = (MotionEvent) event;%0A            float xaxis = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_X);%0A            float yaxis = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_Y);%0A%0A            // Check if the AXIS_HAT_X value is -1 or 1, and set the D-pad%0A            // LEFT and RIGHT direction accordingly.%0A            if (Float.compare(xaxis, -1.0f) == 0) %7B%0A                directionPressed =  Dpad.LEFT;%0A            %7D else if (Float.compare(xaxis, 1.0f) == 0) %7B%0A                directionPressed =  Dpad.RIGHT;%0A            %7D%0A            // Check if the AXIS_HAT_Y value is -1 or 1, and set the D-pad%0A            // UP and DOWN direction accordingly.%0A            else if (Float.compare(yaxis, -1.0f) == 0) %7B%0A                directionPressed =  Dpad.UP;%0A            %7D else if (Float.compare(yaxis, 1.0f) == 0) %7B%0A                directionPressed =  Dpad.DOWN;%0A            %7D%0A        %7D%0A%0A        // If the input event is a KeyEvent, check its key code.%0A        else if (event instanceof KeyEvent) %7B%0A%0A           // Use the key code to find the D-pad direction.%0A            KeyEvent keyEvent = (KeyEvent) event;%0A            if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) %7B%0A                directionPressed = Dpad.LEFT;%0A            %7D else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) %7B%0A                directionPressed = Dpad.RIGHT;%0A            %7D else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) %7B%0A                directionPressed = Dpad.UP;%0A            %7D else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) %7B%0A                directionPressed = Dpad.DOWN;%0A            %7D else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) %7B%0A                directionPressed = Dpad.CENTER;%0A            %7D%0A        %7D%0A        return directionPressed;%0A    %7D%0A%0A    public static boolean isDpadDevice(InputEvent event) %7B%0A        // Check that input comes from a device with directional pads.%0A        if ((event.getSource() & InputDevice.SOURCE_DPAD)%0A             == InputDevice.SOURCE_DPAD) %7B%0A             return true;%0A         %7D else %7B%0A             return false;%0A         %7D%0A     %7D%0A%7D%0A

add Dpad.java