mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 21:55:31 +00:00
Bug 911510 - Refactor the dead-zone-threshold code for gamepads to facilitate preffing. r=bnicholson
This commit is contained in:
parent
a29411d399
commit
8105732b79
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user