summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java/org
diff options
context:
space:
mode:
authorzackhow <zackhow@gmail.com>2019-01-10 21:18:16 -0500
committerzackhow <zackhow@gmail.com>2019-01-23 17:19:50 -0500
commitec557eb3a2ffa331254a002da3be7b3081be92ce (patch)
tree2c518e251d54370bbab069cd9004496e8abf0c7c /Source/Android/app/src/main/java/org
parentf9936592493d46392e0def1c04936679009b972f (diff)
Android: double tap screen to press button
Added ingame option to select either wiimote A, B, 2 or Classic A
Diffstat (limited to 'Source/Android/app/src/main/java/org')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java45
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java18
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java42
3 files changed, 102 insertions, 3 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
index 012b11de7c..001676b900 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
@@ -2,6 +2,7 @@ package org.dolphinemu.dolphinemu.activities;
import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
@@ -38,6 +39,8 @@ import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
+import org.dolphinemu.dolphinemu.overlay.InputOverlay;
+import org.dolphinemu.dolphinemu.overlay.InputOverlayPointer;
import org.dolphinemu.dolphinemu.ui.main.MainActivity;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
@@ -93,7 +96,7 @@ public final class EmulationActivity extends AppCompatActivity
MENU_ACTION_SAVE_SLOT6, MENU_ACTION_LOAD_SLOT1, MENU_ACTION_LOAD_SLOT2,
MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
- MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY})
+ MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP})
public @interface MenuAction
{
}
@@ -126,6 +129,7 @@ public final class EmulationActivity extends AppCompatActivity
public static final int MENU_ACTION_RUMBLE = 25;
public static final int MENU_ACTION_RESET_OVERLAY = 26;
public static final int MENU_SET_IR_SENSITIVITY = 27;
+ public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
@@ -170,6 +174,8 @@ public final class EmulationActivity extends AppCompatActivity
.append(R.id.menu_emulation_reset_overlay, EmulationActivity.MENU_ACTION_RESET_OVERLAY);
buttonsActionsMap.append(R.id.menu_emulation_set_ir_sensitivity,
EmulationActivity.MENU_SET_IR_SENSITIVITY);
+ buttonsActionsMap.append(R.id.menu_emulation_choose_doubletap,
+ EmulationActivity.MENU_ACTION_CHOOSE_DOUBLETAP);
}
private static String[] scanForSecondDisc(GameFile gameFile)
@@ -591,6 +597,10 @@ public final class EmulationActivity extends AppCompatActivity
setIRSensitivity();
return;
+ case MENU_ACTION_CHOOSE_DOUBLETAP:
+ chooseDoubleTapButton();
+ return;
+
case MENU_ACTION_EXIT:
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
if (TvUtil.isLeanback(getApplicationContext()))
@@ -721,6 +731,39 @@ public final class EmulationActivity extends AppCompatActivity
alertDialog.show();
}
+ public void chooseDoubleTapButton()
+ {
+ final SharedPreferences.Editor editor = mPreferences.edit();
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+
+ int currentController =
+ mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUCK);
+
+ int currentValue = mPreferences.getInt("doubleTapButton",
+ InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(InputOverlayPointer.DOUBLE_TAP_A));
+
+ int buttonList = currentController == InputOverlay.OVERLAY_WIIMOTE_CLASSIC ?
+ R.array.doubleTapWithClassic : R.array.doubleTap;
+
+ if (currentController != InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
+ currentValue == InputOverlay.OVERLAY_WIIMOTE_CLASSIC)
+ {
+ currentValue = InputOverlay.OVERLAY_WIIMOTE;
+ }
+
+ builder.setSingleChoiceItems(buttonList, currentValue, (DialogInterface dialog, int which) ->
+ editor.putInt("doubleTapButton", InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(which)));
+
+ builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
+ {
+ editor.commit();
+ mEmulationFragment.refreshInputOverlay();
+ });
+
+ AlertDialog alertDialog = builder.create();
+ alertDialog.show();
+ }
+
private void adjustScale()
{
LayoutInflater inflater = LayoutInflater.from(this);
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
index e7ad7dbae7..86edc6b38a 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
@@ -40,6 +40,12 @@ import java.util.Set;
*/
public final class InputOverlay extends SurfaceView implements OnTouchListener
{
+ public static final int OVERLAY_GAMECUBE = 0;
+ public static final int OVERLAY_WIIMOTE = 1;
+ public static final int OVERLAY_WIIMOTE_SIDEWAYS = 2;
+ public static final int OVERLAY_WIIMOTE_NUNCHUCK = 3;
+ public static final int OVERLAY_WIIMOTE_CLASSIC = 4;
+
private final Set<InputOverlayDrawableButton> overlayButtons = new HashSet<>();
private final Set<InputOverlayDrawableDpad> overlayDpads = new HashSet<>();
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<>();
@@ -666,7 +672,17 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
}
if (!EmulationActivity.isGameCubeGame())
- overlayPointer = new InputOverlayPointer(this.getContext());
+ {
+ int doubleTapButton = mPreferences.getInt("doubleTapButton",
+ InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(InputOverlayPointer.DOUBLE_TAP_A));
+
+ if (mPreferences.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUCK) !=
+ InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
+ doubleTapButton == InputOverlayPointer.DOUBLE_TAP_CLASSIC_A)
+ doubleTapButton = InputOverlayPointer.DOUBLE_TAP_A;
+
+ overlayPointer = new InputOverlayPointer(this.getContext(), doubleTapButton);
+ }
invalidate();
}
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java
index 1191d2dc7a..917a3f4436 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java
@@ -2,22 +2,45 @@ package org.dolphinemu.dolphinemu.overlay;
import android.app.Activity;
import android.content.Context;
+import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
+import org.dolphinemu.dolphinemu.NativeLibrary;
+
+import java.util.ArrayList;
+
public class InputOverlayPointer
{
+ public static final int DOUBLE_TAP_A = 0;
+ public static final int DOUBLE_TAP_B = 1;
+ public static final int DOUBLE_TAP_2 = 2;
+ public static final int DOUBLE_TAP_CLASSIC_A = 3;
+
private final float[] axes = {0f, 0f};
private float maxHeight;
private float maxWidth;
+ private boolean doubleTap = false;
+ private int doubleTapButton;
private int trackId = -1;
- public InputOverlayPointer(Context context)
+ public static ArrayList<Integer> DOUBLE_TAP_OPTIONS = new ArrayList<>();
+
+ static
+ {
+ DOUBLE_TAP_OPTIONS.add(NativeLibrary.ButtonType.WIIMOTE_BUTTON_A);
+ DOUBLE_TAP_OPTIONS.add(NativeLibrary.ButtonType.WIIMOTE_BUTTON_B);
+ DOUBLE_TAP_OPTIONS.add(NativeLibrary.ButtonType.WIIMOTE_BUTTON_2);
+ DOUBLE_TAP_OPTIONS.add(NativeLibrary.ButtonType.CLASSIC_BUTTON_A);
+ }
+
+ public InputOverlayPointer(Context context, int button)
{
Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
+ doubleTapButton = button;
maxWidth = outMetrics.widthPixels / 2;
maxHeight = outMetrics.heightPixels / 2;
}
@@ -31,6 +54,7 @@ public class InputOverlayPointer
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
trackId = event.getPointerId(pointerIndex);
+ touchPress();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
@@ -50,6 +74,22 @@ public class InputOverlayPointer
return false;
}
+ private void touchPress()
+ {
+ if (doubleTap)
+ {
+ NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
+ doubleTapButton, NativeLibrary.ButtonState.PRESSED);
+ new Handler().postDelayed(() -> NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
+ doubleTapButton, NativeLibrary.ButtonState.RELEASED), 50);
+ }
+ else
+ {
+ doubleTap = true;
+ new Handler().postDelayed(() -> doubleTap = false, 300);
+ }
+ }
+
public float[] getAxisValues()
{
float[] ir = {0f, 0f};