Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 2358 - [Android] Sort joystick axes - Fix by David Brady
  • Loading branch information
gabomdq committed Jan 24, 2014
1 parent 50befa6 commit e78be5d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -2,6 +2,9 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.app.*;
import android.content.*;
Expand Down Expand Up @@ -922,6 +925,13 @@ class SDLJoystick {
public String name;
public ArrayList<InputDevice.MotionRange> axes;
}
class RangeComparator implements Comparator<InputDevice.MotionRange>
{
@Override
public int compare(InputDevice.MotionRange arg0, InputDevice.MotionRange arg1) {
return arg0.getAxis() - arg1.getAxis();
}
}

private ArrayList<SDLJoystick> mJoysticks;

Expand All @@ -948,8 +958,10 @@ public void pollInputDevices() {
joystick.name = joystickDevice.getName();
joystick.axes = new ArrayList<InputDevice.MotionRange>();

for (InputDevice.MotionRange range : joystickDevice.getMotionRanges()) {
if ( (range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
List<InputDevice.MotionRange> ranges = joystickDevice.getMotionRanges();
Collections.sort(ranges, new RangeComparator());
for (InputDevice.MotionRange range : ranges ) {
if ( (range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 ) {
joystick.axes.add(range);
}
}
Expand Down

0 comments on commit e78be5d

Please sign in to comment.