From ec557eb3a2ffa331254a002da3be7b3081be92ce Mon Sep 17 00:00:00 2001 From: zackhow Date: Thu, 10 Jan 2019 21:18:16 -0500 Subject: [PATCH] Android: double tap screen to press button Added ingame option to select either wiimote A, B, 2 or Classic A --- .../activities/EmulationActivity.java | 45 ++++++++++++++++++- .../dolphinemu/overlay/InputOverlay.java | 18 +++++++- .../overlay/InputOverlayPointer.java | 42 ++++++++++++++++- .../src/main/res/menu/menu_emulation_wii.xml | 19 +++++--- .../app/src/main/res/values/arrays.xml | 13 ++++++ .../app/src/main/res/values/strings.xml | 2 + 6 files changed, 131 insertions(+), 8 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 overlayButtons = new HashSet<>(); private final Set overlayDpads = new HashSet<>(); private final Set 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 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}; diff --git a/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml b/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml index 8a5a729783..465e582aff 100644 --- a/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml +++ b/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml @@ -112,12 +112,21 @@ - - + android:id="@+id/menu_emulation_ir_group" + android:title="@string/emulation_ir_group" + app:showAsAction="never"> + + + + + diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml index 403e27b2b1..503788998a 100644 --- a/Source/Android/app/src/main/res/values/arrays.xml +++ b/Source/Android/app/src/main/res/values/arrays.xml @@ -306,6 +306,19 @@ Right Stick + + Button A + Button B + Button 2 + + + + Button A + Button B + Button 2 + Classic A + + Core Settings GFX Settings diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index a33db04ac8..0e13855779 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -298,7 +298,9 @@ You may have to reload the game after changing extensions. Swipe down from the top of the screen to access the menu. Reset Overlay + Touch IR Pointer IR Sensitivity + Double tap button Enable Vibration