Bug 2358 - [Android] Sort joystick axes - Fix by David Brady
authorGabriel Jacobo <gabomdq@gmail.com>
Fri, 24 Jan 2014 09:54:04 -0300
changeset 8123d7b7ec662687
parent 8122 7e01e3908f41
child 8124 5226058345bf
Bug 2358 - [Android] Sort joystick axes - Fix by David Brady
android-project/src/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Thu Jan 23 08:44:25 2014 -0300
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Fri Jan 24 09:54:04 2014 -0300
     1.3 @@ -2,6 +2,9 @@
     1.4  
     1.5  import java.util.ArrayList;
     1.6  import java.util.Arrays;
     1.7 +import java.util.Collections;
     1.8 +import java.util.Comparator;
     1.9 +import java.util.List;
    1.10  
    1.11  import android.app.*;
    1.12  import android.content.*;
    1.13 @@ -922,6 +925,13 @@
    1.14          public String name;
    1.15          public ArrayList<InputDevice.MotionRange> axes;
    1.16      }
    1.17 +    class RangeComparator implements Comparator<InputDevice.MotionRange>
    1.18 +    {
    1.19 +        @Override
    1.20 +        public int compare(InputDevice.MotionRange arg0, InputDevice.MotionRange arg1) {
    1.21 +            return arg0.getAxis() - arg1.getAxis();
    1.22 +        }
    1.23 +    }
    1.24      
    1.25      private ArrayList<SDLJoystick> mJoysticks;
    1.26      
    1.27 @@ -948,8 +958,10 @@
    1.28                      joystick.name = joystickDevice.getName();
    1.29                      joystick.axes = new ArrayList<InputDevice.MotionRange>();
    1.30                      
    1.31 -                    for (InputDevice.MotionRange range : joystickDevice.getMotionRanges()) {
    1.32 -                         if ( (range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
    1.33 +                    List<InputDevice.MotionRange> ranges = joystickDevice.getMotionRanges();
    1.34 +                    Collections.sort(ranges, new RangeComparator());
    1.35 +                    for (InputDevice.MotionRange range : ranges ) {
    1.36 +                        if ( (range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 ) {
    1.37                              joystick.axes.add(range);
    1.38                           }
    1.39                      }