|
|
|
@@ -6,7 +6,6 @@
|
|
|
|
|
|
|
|
|
|
package org.dolphinemu.dolphinemu.settings;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
import android.app.Fragment;
|
|
|
|
|
import android.content.Context;
|
|
|
|
@@ -31,10 +30,6 @@ import org.dolphinemu.dolphinemu.R;
|
|
|
|
|
*/
|
|
|
|
|
public final class InputConfigFragment extends PreferenceFragment
|
|
|
|
|
{
|
|
|
|
|
private Activity m_activity;
|
|
|
|
|
private boolean firstEvent = true;
|
|
|
|
|
private static final ArrayList<Float> m_values = new ArrayList<Float>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the descriptor for the given {@link InputDevice}.
|
|
|
|
|
*
|
|
|
|
@@ -92,15 +87,65 @@ public final class InputConfigFragment extends PreferenceFragment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceTreeClick(final PreferenceScreen screen, final Preference pref)
|
|
|
|
|
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference pref)
|
|
|
|
|
{
|
|
|
|
|
// If the user is on the preference screen to set Gamecube input bindings.
|
|
|
|
|
if (screen.getTitle().equals(getString(R.string.gamecube_bindings)))
|
|
|
|
|
{
|
|
|
|
|
// Begin the creation of the input alert.
|
|
|
|
|
final MotionAlertDialog dialog = new MotionAlertDialog(m_activity);
|
|
|
|
|
final MotionAlertDialog dialog = new MotionAlertDialog(getActivity(), pref);
|
|
|
|
|
|
|
|
|
|
// Set the key listener
|
|
|
|
|
dialog.setOnKeyListener(new AlertDialog.OnKeyListener()
|
|
|
|
|
// Set the cancel button.
|
|
|
|
|
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), new AlertDialog.OnClickListener()
|
|
|
|
|
{
|
|
|
|
|
public boolean onKey(DialogInterface dlg, int keyCode, KeyEvent event)
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
|
{
|
|
|
|
|
// Do nothing. Just makes the cancel button show up.
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Set the title and description message.
|
|
|
|
|
dialog.setTitle(R.string.input_binding);
|
|
|
|
|
dialog.setMessage(String.format(getString(R.string.input_binding_descrip), pref.getTitle()));
|
|
|
|
|
|
|
|
|
|
// Don't allow the dialog to close when a user taps
|
|
|
|
|
// outside of it. They must press cancel or provide an input.
|
|
|
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
|
|
|
|
|
|
|
|
// Everything is set, show the dialog.
|
|
|
|
|
dialog.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@link AlertDialog} derivative that listens for
|
|
|
|
|
* motion events from controllers and joysticks.
|
|
|
|
|
*/
|
|
|
|
|
private static final class MotionAlertDialog extends AlertDialog
|
|
|
|
|
{
|
|
|
|
|
// The selected input preference
|
|
|
|
|
private final Preference inputPref;
|
|
|
|
|
|
|
|
|
|
private boolean firstEvent = true;
|
|
|
|
|
private final ArrayList<Float> m_values = new ArrayList<Float>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param ctx context to use this dialog in.
|
|
|
|
|
*/
|
|
|
|
|
public MotionAlertDialog(Context ctx, Preference inputPref)
|
|
|
|
|
{
|
|
|
|
|
super(ctx);
|
|
|
|
|
|
|
|
|
|
this.inputPref = inputPref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
|
|
|
|
{
|
|
|
|
|
Log.d("InputConfigFragment", "Received key event: " + event.getAction());
|
|
|
|
|
switch (event.getAction())
|
|
|
|
@@ -109,9 +154,9 @@ public final class InputConfigFragment extends PreferenceFragment
|
|
|
|
|
case KeyEvent.ACTION_UP:
|
|
|
|
|
InputDevice input = event.getDevice();
|
|
|
|
|
String bindStr = "Device '" + getInputDesc(input) + "'-Button " + event.getKeyCode();
|
|
|
|
|
NativeLibrary.SetConfig("Dolphin.ini", "Android", pref.getKey(), bindStr);
|
|
|
|
|
pref.setSummary(bindStr);
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
|
|
|
|
inputPref.setSummary(bindStr);
|
|
|
|
|
dismiss();
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
@@ -120,14 +165,12 @@ public final class InputConfigFragment extends PreferenceFragment
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Set the motion event listener.
|
|
|
|
|
dialog.setOnMotionEventListener(new MotionAlertDialog.OnMotionEventListener()
|
|
|
|
|
|
|
|
|
|
// Method that will be within dispatchGeneticMotionEvent that listens for joystick/controller movements.
|
|
|
|
|
private boolean onMotionEvent(MotionEvent event)
|
|
|
|
|
{
|
|
|
|
|
public boolean onMotion(MotionEvent event)
|
|
|
|
|
{
|
|
|
|
|
if (event == null || (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
|
|
|
|
|
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Log.d("InputConfigFragment", "Received motion event: " + event.getAction());
|
|
|
|
@@ -154,100 +197,22 @@ public final class InputConfigFragment extends PreferenceFragment
|
|
|
|
|
if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f))
|
|
|
|
|
{
|
|
|
|
|
String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "-";
|
|
|
|
|
NativeLibrary.SetConfig("Dolphin.ini", "Android", pref.getKey(), bindStr);
|
|
|
|
|
pref.setSummary(bindStr);
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
|
|
|
|
inputPref.setSummary(bindStr);
|
|
|
|
|
dismiss();
|
|
|
|
|
}
|
|
|
|
|
else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
|
|
|
|
|
{
|
|
|
|
|
String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "+";
|
|
|
|
|
NativeLibrary.SetConfig("Dolphin.ini", "Android", pref.getKey(), bindStr);
|
|
|
|
|
pref.setSummary(bindStr);
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
|
|
|
|
inputPref.setSummary(bindStr);
|
|
|
|
|
dismiss();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Set the cancel button.
|
|
|
|
|
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), new AlertDialog.OnClickListener()
|
|
|
|
|
{
|
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
|
{
|
|
|
|
|
// Do nothing. This just makes the cancel button appear.
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Set the title and description message.
|
|
|
|
|
dialog.setTitle(R.string.input_binding);
|
|
|
|
|
dialog.setMessage(String.format(getString(R.string.input_binding_descrip), pref.getTitle()));
|
|
|
|
|
|
|
|
|
|
// Don't allow the dialog to close when a user taps
|
|
|
|
|
// outside of it. They must press cancel or provide an input.
|
|
|
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
|
|
|
|
|
|
|
|
// Everything is set, show the dialog.
|
|
|
|
|
dialog.show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAttach(Activity activity)
|
|
|
|
|
{
|
|
|
|
|
super.onAttach(activity);
|
|
|
|
|
|
|
|
|
|
// Cache the activity instance.
|
|
|
|
|
m_activity = activity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@link AlertDialog} class derivative that allows the motion listener
|
|
|
|
|
* to be set anonymously, so the creation of an explicit class for
|
|
|
|
|
* providing functionality is not necessary.
|
|
|
|
|
*/
|
|
|
|
|
private static final class MotionAlertDialog extends AlertDialog
|
|
|
|
|
{
|
|
|
|
|
private OnMotionEventListener motionListener;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param ctx context to use this dialog in.
|
|
|
|
|
*/
|
|
|
|
|
public MotionAlertDialog(Context ctx)
|
|
|
|
|
{
|
|
|
|
|
super(ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface which defines a callback method for general
|
|
|
|
|
* motion events. This allows motion event code to be set
|
|
|
|
|
* in the event anonymous classes of this dialog are used.
|
|
|
|
|
*/
|
|
|
|
|
public interface OnMotionEventListener
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Denotes the behavior that should happen when a motion event occurs.
|
|
|
|
|
*
|
|
|
|
|
* @param event Reference to the {@link MotionEvent} that occurred.
|
|
|
|
|
*
|
|
|
|
|
* @return true if the {@link MotionEvent} is consumed in this call; false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
boolean onMotion(MotionEvent event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the motion listener.
|
|
|
|
|
*
|
|
|
|
|
* @param listener The motion listener to set.
|
|
|
|
|
*/
|
|
|
|
|
public void setOnMotionEventListener(OnMotionEventListener listener)
|
|
|
|
|
{
|
|
|
|
|
this.motionListener = listener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean dispatchKeyEvent(KeyEvent event)
|
|
|
|
@@ -261,7 +226,7 @@ public final class InputConfigFragment extends PreferenceFragment
|
|
|
|
|
@Override
|
|
|
|
|
public boolean dispatchGenericMotionEvent(MotionEvent event)
|
|
|
|
|
{
|
|
|
|
|
if (motionListener.onMotion(event))
|
|
|
|
|
if (onMotionEvent(event))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return super.dispatchGenericMotionEvent(event);
|
|
|
|
|