Bug 911510 - Refactor the dead-zone-threshold code for gamepads to facilitate preffing. r=bnicholson

This commit is contained in:
Kartikaya Gupta 2013-09-04 21:58:39 -04:00
Родитель a29411d399
Коммит 8105732b79
1 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@ -18,6 +18,7 @@ public final class GamepadUtils {
private static final int SONY_XPERIA_GAMEPAD_DEVICE_ID = 196611;
private static View.OnKeyListener sClickDispatcher;
private static float sDeadZoneThresholdOverride = 1e-2f;
private GamepadUtils() {
}
@ -42,11 +43,19 @@ public final class GamepadUtils {
}
public static boolean isValueInDeadZone(MotionEvent event, int axis) {
if (Build.VERSION.SDK_INT < 9) {
return false;
}
float threshold;
if (sDeadZoneThresholdOverride >= 0) {
threshold = sDeadZoneThresholdOverride;
} else {
InputDevice.MotionRange range = event.getDevice().getMotionRange(axis);
threshold = range.getFlat() + range.getFuzz();
}
float value = event.getAxisValue(axis);
// The 1e-2 here should really be range.getFlat() + range.getFuzz() (where range is
// event.getDevice().getMotionRange(axis)), but the values those functions return
// on the Ouya are zero so we're just hard-coding it for now.
return (Math.abs(value) < 1e-2);
return (Math.abs(value) < threshold);
}
public static boolean isPanningControl(MotionEvent event) {