summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorsigmabeta <sigmabeta@users.noreply.github.com>2015-06-08 20:07:43 -0400
committersigmabeta <sigmabeta@users.noreply.github.com>2015-06-08 20:07:43 -0400
commitd56f27857b76c9c7bc00a4f5e9de38e597fa7fa6 (patch)
tree74c29bd208cd640641b0e30505897314602b17f4 /Source/Android/app/src/main/java
parent6f3279d62716b3242c16aed1a629e7c425337955 (diff)
Android: Don't remove input configuration related files from old UI.
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java128
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InputBindingPreference.java56
2 files changed, 184 insertions, 0 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java
new file mode 100644
index 0000000000..4f9b7de0a3
--- /dev/null
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java
@@ -0,0 +1,128 @@
+package org.dolphinemu.dolphinemu.dialogs;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.preference.Preference;
+import android.util.Log;
+import android.view.InputDevice;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+import org.dolphinemu.dolphinemu.NativeLibrary;
+import org.dolphinemu.dolphinemu.utils.InputConfigFragment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * {@link AlertDialog} derivative that listens for
+ * motion events from controllers and joysticks.
+ */
+public 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 The current {@link Context}.
+ * @param inputPref The Preference to show this dialog for.
+ */
+ 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())
+ {
+ case KeyEvent.ACTION_DOWN:
+ case KeyEvent.ACTION_UP:
+ InputDevice input = event.getDevice();
+ String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Button " + event.getKeyCode();
+ NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
+ inputPref.setSummary(bindStr);
+ dismiss();
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+
+ // Method that will be called within dispatchGenericMotionEvent
+ // that handles joystick/controller movements.
+ private boolean onMotionEvent(MotionEvent event)
+ {
+ if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
+ return false;
+
+ Log.d("InputConfigFragment", "Received motion event: " + event.getAction());
+
+ InputDevice input = event.getDevice();
+ List<InputDevice.MotionRange> motions = input.getMotionRanges();
+ if (firstEvent)
+ {
+ m_values.clear();
+
+ for (InputDevice.MotionRange range : motions)
+ {
+ m_values.add(event.getAxisValue(range.getAxis()));
+ }
+
+ firstEvent = false;
+ }
+ else
+ {
+ for (int a = 0; a < motions.size(); ++a)
+ {
+ InputDevice.MotionRange range = motions.get(a);
+
+ 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", 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", inputPref.getKey(), bindStr);
+ inputPref.setSummary(bindStr);
+ dismiss();
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event)
+ {
+ if (onKeyDown(event.getKeyCode(), event))
+ return true;
+
+ return super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ public boolean dispatchGenericMotionEvent(MotionEvent event)
+ {
+ if (onMotionEvent(event))
+ return true;
+
+ return super.dispatchGenericMotionEvent(event);
+ }
+} \ No newline at end of file
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InputBindingPreference.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InputBindingPreference.java
new file mode 100644
index 0000000000..cb67b90a18
--- /dev/null
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InputBindingPreference.java
@@ -0,0 +1,56 @@
+package org.dolphinemu.dolphinemu.utils;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.preference.Preference;
+import android.util.AttributeSet;
+
+import org.dolphinemu.dolphinemu.R;
+import org.dolphinemu.dolphinemu.dialogs.MotionAlertDialog;
+
+/**
+ * {@link Preference} subclass that represents a preference
+ * used for assigning a key bind.
+ */
+public final class InputBindingPreference extends Preference
+{
+ /**
+ * Constructor that is called when inflating an InputBindingPreference from XML.
+ *
+ * @param context The current {@link Context}.
+ * @param attrs The attributes of the XML tag that is inflating the preference.
+ */
+ public InputBindingPreference(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void onClick()
+ {
+ // Begin the creation of the input alert.
+ final MotionAlertDialog dialog = new MotionAlertDialog(getContext(), this);
+
+ // Set the cancel button.
+ dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getContext().getString(R.string.cancel), new AlertDialog.OnClickListener()
+ {
+ @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(getContext().getString(R.string.input_binding_descrip), 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();
+ }
+}