зеркало из https://github.com/mozilla/gecko-dev.git
Bug 857217 - Don't move focus to the layerview if joystick input events are in the dead zones. r=Cwiiis
This commit is contained in:
Родитель
a6ba211310
Коммит
222af36914
|
@ -12,6 +12,7 @@ import org.mozilla.gecko.Tabs;
|
|||
import org.mozilla.gecko.ZoomConstraints;
|
||||
import org.mozilla.gecko.util.EventDispatcher;
|
||||
import org.mozilla.gecko.util.FloatUtils;
|
||||
import org.mozilla.gecko.util.GamepadUtils;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
|
@ -510,34 +511,25 @@ class JavaPanZoomController
|
|||
return false;
|
||||
}
|
||||
|
||||
private float filterDeadZone(float value, InputDevice.MotionRange range) {
|
||||
// The 1e-2 here should really be range.getFlat() + range.getFuzz() but the
|
||||
// values those functions return on the Ouya are zero so we're just hard-coding
|
||||
// it for now.
|
||||
if (Math.abs(value) < 1e-2) {
|
||||
return 0;
|
||||
}
|
||||
return value;
|
||||
private float filterDeadZone(MotionEvent event, int axis) {
|
||||
return (GamepadUtils.isValueInDeadZone(event, axis) ? 0 : event.getAxisValue(axis));
|
||||
}
|
||||
|
||||
private float normalizeJoystickScroll(float value, InputDevice.MotionRange range) {
|
||||
return filterDeadZone(value, range) * MAX_SCROLL;
|
||||
private float normalizeJoystickScroll(MotionEvent event, int axis) {
|
||||
return filterDeadZone(event, axis) * MAX_SCROLL;
|
||||
}
|
||||
|
||||
private float normalizeJoystickZoom(float value, InputDevice.MotionRange range) {
|
||||
private float normalizeJoystickZoom(MotionEvent event, int axis) {
|
||||
// negate MAX_ZOOM_DELTA so that pushing up on the stick zooms in
|
||||
return filterDeadZone(value, range) * -MAX_ZOOM_DELTA;
|
||||
return filterDeadZone(event, axis) * -MAX_ZOOM_DELTA;
|
||||
}
|
||||
|
||||
// Since this event is a position-based event rather than a motion-based event, we need to
|
||||
// set up an AUTONAV animation to keep scrolling even while we don't get events.
|
||||
private boolean handleJoystickNav(MotionEvent event) {
|
||||
float velocityX = normalizeJoystickScroll(event.getAxisValue(MotionEvent.AXIS_X),
|
||||
event.getDevice().getMotionRange(MotionEvent.AXIS_X));
|
||||
float velocityY = normalizeJoystickScroll(event.getAxisValue(MotionEvent.AXIS_Y),
|
||||
event.getDevice().getMotionRange(MotionEvent.AXIS_Y));
|
||||
float zoomDelta = normalizeJoystickZoom(event.getAxisValue(MotionEvent.AXIS_RZ),
|
||||
event.getDevice().getMotionRange(MotionEvent.AXIS_RZ));
|
||||
float velocityX = normalizeJoystickScroll(event, MotionEvent.AXIS_X);
|
||||
float velocityY = normalizeJoystickScroll(event, MotionEvent.AXIS_Y);
|
||||
float zoomDelta = normalizeJoystickZoom(event, MotionEvent.AXIS_RZ);
|
||||
|
||||
if (velocityX == 0 && velocityY == 0 && zoomDelta == 0) {
|
||||
if (mState == PanZoomState.AUTONAV) {
|
||||
|
|
|
@ -39,11 +39,28 @@ public final class GamepadUtils {
|
|||
return (isGamepadKey(event) && (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B));
|
||||
}
|
||||
|
||||
public static boolean isValueInDeadZone(MotionEvent event, int axis) {
|
||||
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);
|
||||
}
|
||||
|
||||
public static boolean isPanningControl(MotionEvent event) {
|
||||
if (Build.VERSION.SDK_INT >= 12) {
|
||||
return (event.getSource() & InputDevice.SOURCE_CLASS_MASK) == InputDevice.SOURCE_CLASS_JOYSTICK;
|
||||
if (Build.VERSION.SDK_INT < 12) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_MASK) != InputDevice.SOURCE_CLASS_JOYSTICK) {
|
||||
return false;
|
||||
}
|
||||
if (isValueInDeadZone(event, MotionEvent.AXIS_X)
|
||||
&& isValueInDeadZone(event, MotionEvent.AXIS_Y)
|
||||
&& isValueInDeadZone(event, MotionEvent.AXIS_Z)
|
||||
&& isValueInDeadZone(event, MotionEvent.AXIS_RZ)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static View.OnKeyListener getClickDispatcher() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче