1. Download our Official Android App: Forums for Android!

Apps HELP WITH: Reading Game Controller into Basic GUI

Discussion in 'Android Development' started by Jo_Han_Solo, Oct 16, 2017.

  1. Jo_Han_Solo

    Jo_Han_Solo Newbie
    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    21
    Joined:
    Oct 4, 2017

    Oct 4, 2017
    21
    2
    26
    Male
    Hi Guys,

    I'm developing a very basic app in Android Studio.

    I'm trying to read a game controller from my Samsung Galaxy Note 2 into a basic GUI for seeing which button/joystick is being pressed/used. I basically just want like text boxes showing "Left Stick 0-100" "Button A pressed" or something like this.

    I've got almost every common game controller so if you know how to get a USB Xbox360 controller working but not a PS4 controller that's not a problem.
    I've got:
    - PS3 & PS4 Controllers
    - Steelseries Wireless Android Controller
    - Xbox360 & XboxOne Controllers

    I've found a few tutorials but I'm struggling with creating the app to do this.

    Any help at all would be greatly appreciated.

    Cheers!

    Johan
     

    Advertisement

  2. Jo_Han_Solo

    Jo_Han_Solo Newbie
    Thread Starter
    Rank:
    None
    Points:
    26
    Posts:
    21
    Joined:
    Oct 4, 2017

    Oct 4, 2017
    21
    2
    26
    Male
    I solved this problem using Googles own "Handling Game Controllers" guide as seen here: https://developer.android.com/training/game-controllers/controller-input.html

    It worked out quite well, there were quite a few things that to someone as fresh with Java as I am struggles with, but essentially I followed that guide very closely and in all places where it told me to

    "// Handle gamepad and D-pad button presses to navigate the ship"

    I simply turned these commands into TextView boxes in the layout and used myTextView.setText(String.ValueOf(*INTEGER_OR_FLOAT*));

    Using this I managed to create a simple app that reads out each button, dpad, analog sticks and triggers to a simple layout. I ended up using the Steelseries Controller.

    Also, the following code is how to make the triggers work, the first guide doesn't explain that:
    float LeftT = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_BRAKE,historyPos); //Left Trigger
    float RightT = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_GAS,historyPos); //Right Trigger

    It makes sense if you follow the rest of the guide.
     

Share This Page

Loading...