Android: Refactor the saveInput function.
In its prior state, it had xor parameters, which is confusing.
This commit is contained in:
parent
774fca4d01
commit
b8d45ad4be
|
@ -8,8 +8,6 @@ import android.view.InputDevice;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
|
||||||
import org.dolphinemu.dolphinemu.model.settings.StringSetting;
|
|
||||||
import org.dolphinemu.dolphinemu.model.settings.view.InputBindingSetting;
|
import org.dolphinemu.dolphinemu.model.settings.view.InputBindingSetting;
|
||||||
import org.dolphinemu.dolphinemu.utils.Log;
|
import org.dolphinemu.dolphinemu.utils.Log;
|
||||||
|
|
||||||
|
@ -49,9 +47,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
{
|
{
|
||||||
case KeyEvent.ACTION_DOWN:
|
case KeyEvent.ACTION_DOWN:
|
||||||
case KeyEvent.ACTION_UP:
|
case KeyEvent.ACTION_UP:
|
||||||
|
saveKeyInput(event);
|
||||||
InputDevice input = event.getDevice();
|
|
||||||
saveInput(input, event, null, false);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -91,11 +87,11 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
|
|
||||||
if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f))
|
if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f))
|
||||||
{
|
{
|
||||||
saveInput(input, null, range, false);
|
saveMotionInput(input, range, '-');
|
||||||
}
|
}
|
||||||
else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
|
else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
|
||||||
{
|
{
|
||||||
saveInput(input, null, range, true);
|
saveMotionInput(input, range, '+');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,61 +112,46 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the provided input setting both to the INI file (so native code can use it) and as an
|
* Saves the provided key input setting both to the INI file (so native code can use it) and as
|
||||||
* Android preference (so it persists correctly, and is human-readable.)
|
* an Android preference (so it persists correctly and is human-readable.)
|
||||||
*
|
*
|
||||||
* @param device Required; the InputDevice from which the input event originated.
|
* @param keyEvent KeyEvent of this key press.
|
||||||
* @param keyEvent If the event was a button push, this KeyEvent represents it and is required.
|
|
||||||
* @param motionRange If the event was an axis movement, this MotionRange represents it and is required.
|
|
||||||
* @param axisPositive If the event was an axis movement, this boolean indicates the direction and is required.
|
|
||||||
*/
|
*/
|
||||||
private void saveInput(InputDevice device, KeyEvent keyEvent, InputDevice.MotionRange motionRange, boolean axisPositive)
|
private void saveKeyInput(KeyEvent keyEvent)
|
||||||
{
|
{
|
||||||
String bindStr = null;
|
InputDevice device = keyEvent.getDevice();
|
||||||
String uiString = null;
|
String bindStr = "Device '" + device.getDescriptor() + "'-Button " + keyEvent.getKeyCode();
|
||||||
|
String uiString = device.getName() + ": Button " + keyEvent.getKeyCode();
|
||||||
|
|
||||||
if (keyEvent != null)
|
saveInput(bindStr, uiString);
|
||||||
{
|
|
||||||
bindStr = "Device '" + device.getDescriptor() + "'-Button " + keyEvent.getKeyCode();
|
|
||||||
uiString = device.getName() + ": Button " + keyEvent.getKeyCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (motionRange != null)
|
/**
|
||||||
|
* Saves the provided motion input setting both to the INI file (so native code can use it) and as
|
||||||
|
* an Android preference (so it persists correctly and is human-readable.)
|
||||||
|
*
|
||||||
|
* @param device InputDevice from which the input event originated.
|
||||||
|
* @param motionRange MotionRange of the movement
|
||||||
|
* @param axisDir Either '-' or '+'
|
||||||
|
*/
|
||||||
|
private void saveMotionInput(InputDevice device, InputDevice.MotionRange motionRange, char axisDir)
|
||||||
{
|
{
|
||||||
if (axisPositive)
|
String bindStr = "Device '" + device.getDescriptor() + "'-Axis " + motionRange.getAxis() + axisDir;
|
||||||
{
|
String uiString = device.getName() + ": Axis " + motionRange.getAxis() + axisDir;
|
||||||
bindStr = "Device '" + device.getDescriptor() + "'-Axis " + motionRange.getAxis() + "+";
|
|
||||||
uiString = device.getName() + ": Axis " + motionRange.getAxis() + "+";
|
saveInput(bindStr, uiString);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bindStr = "Device '" + device.getDescriptor() + "'-Axis " + motionRange.getAxis() + "-";
|
|
||||||
uiString = device.getName() + ": Axis " + motionRange.getAxis() + "-";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bindStr != null)
|
/** Save the input string to settings and SharedPreferences, then dismiss this Dialog. */
|
||||||
|
private void saveInput(String bind, String ui)
|
||||||
{
|
{
|
||||||
setting.setValue(bindStr);
|
setting.setValue(bind);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.error("[MotionAlertDialog] Failed to save input to INI.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (uiString != null)
|
|
||||||
{
|
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
|
||||||
editor.putString(setting.getKey(), uiString);
|
editor.putString(setting.getKey(), ui);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.error("[MotionAlertDialog] Failed to save input to preference.");
|
|
||||||
}
|
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue