Android: Make ControllerMappingHelper methods static

This class has no state.
This commit is contained in:
JosJuice
2018-07-11 09:41:26 +02:00
parent 78cb1c2914
commit 7f6be99ad9
2 changed files with 6 additions and 8 deletions

View File

@ -23,7 +23,6 @@ public final class MotionAlertDialog extends AlertDialog
{ {
// The selected input preference // The selected input preference
private final InputBindingSetting setting; private final InputBindingSetting setting;
private final ControllerMappingHelper mControllerMappingHelper;
private final ArrayList<Float> mPreviousValues = new ArrayList<>(); private final ArrayList<Float> mPreviousValues = new ArrayList<>();
private int mPrevDeviceId = 0; private int mPrevDeviceId = 0;
private boolean mWaitingForEvent = true; private boolean mWaitingForEvent = true;
@ -39,7 +38,6 @@ public final class MotionAlertDialog extends AlertDialog
super(context); super(context);
this.setting = setting; this.setting = setting;
this.mControllerMappingHelper = new ControllerMappingHelper();
} }
public boolean onKeyEvent(int keyCode, KeyEvent event) public boolean onKeyEvent(int keyCode, KeyEvent event)
@ -48,7 +46,7 @@ public final class MotionAlertDialog extends AlertDialog
switch (event.getAction()) switch (event.getAction())
{ {
case KeyEvent.ACTION_DOWN: case KeyEvent.ACTION_DOWN:
if (!mControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode)) if (!ControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
{ {
saveKeyInput(event); saveKeyInput(event);
} }
@ -103,7 +101,7 @@ public final class MotionAlertDialog extends AlertDialog
InputDevice.MotionRange range = motionRanges.get(i); InputDevice.MotionRange range = motionRanges.get(i);
int axis = range.getAxis(); int axis = range.getAxis();
float origValue = event.getAxisValue(axis); float origValue = event.getAxisValue(axis);
float value = mControllerMappingHelper.scaleAxis(input, axis, origValue); float value = ControllerMappingHelper.scaleAxis(input, axis, origValue);
if (firstEvent) if (firstEvent)
{ {
mPreviousValues.add(value); mPreviousValues.add(value);

View File

@ -8,7 +8,7 @@ import android.view.MotionEvent;
public class ControllerMappingHelper public class ControllerMappingHelper
{ {
/** Some controllers report extra button presses that can be ignored. */ /** Some controllers report extra button presses that can be ignored. */
public boolean shouldKeyBeIgnored(InputDevice inputDevice, int keyCode) public static boolean shouldKeyBeIgnored(InputDevice inputDevice, int keyCode)
{ {
if (isDualShock4(inputDevice)) { if (isDualShock4(inputDevice)) {
// The two analog triggers generate analog motion events as well as a keycode. // The two analog triggers generate analog motion events as well as a keycode.
@ -20,7 +20,7 @@ public class ControllerMappingHelper
} }
/** Scale an axis to be zero-centered with a proper range. */ /** Scale an axis to be zero-centered with a proper range. */
public float scaleAxis(InputDevice inputDevice, int axis, float value) public static float scaleAxis(InputDevice inputDevice, int axis, float value)
{ {
if (isDualShock4(inputDevice)) if (isDualShock4(inputDevice))
{ {
@ -43,13 +43,13 @@ public class ControllerMappingHelper
return value; return value;
} }
private boolean isDualShock4(InputDevice inputDevice) private static boolean isDualShock4(InputDevice inputDevice)
{ {
// Sony DualShock 4 controller // Sony DualShock 4 controller
return inputDevice.getVendorId() == 0x54c && inputDevice.getProductId() == 0x9cc; return inputDevice.getVendorId() == 0x54c && inputDevice.getProductId() == 0x9cc;
} }
private boolean isXboxOneWireless(InputDevice inputDevice) private static boolean isXboxOneWireless(InputDevice inputDevice)
{ {
// Microsoft Xbox One controller // Microsoft Xbox One controller
return inputDevice.getVendorId() == 0x45e && inputDevice.getProductId() == 0x2e0; return inputDevice.getVendorId() == 0x45e && inputDevice.getProductId() == 0x2e0;