Android: double tap screen to press button
Added ingame option to select either wiimote A, B, 2 or Classic A
This commit is contained in:
parent
f993659249
commit
ec557eb3a2
|
@ -2,6 +2,7 @@ package org.dolphinemu.dolphinemu.activities;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
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.fragments.SaveLoadStateFragment;
|
||||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
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.MainActivity;
|
||||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
||||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
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_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_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
|
||||||
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
|
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
|
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_RUMBLE = 25;
|
||||||
public static final int MENU_ACTION_RESET_OVERLAY = 26;
|
public static final int MENU_ACTION_RESET_OVERLAY = 26;
|
||||||
public static final int MENU_SET_IR_SENSITIVITY = 27;
|
public static final int MENU_SET_IR_SENSITIVITY = 27;
|
||||||
|
public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
|
||||||
|
|
||||||
|
|
||||||
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
|
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);
|
.append(R.id.menu_emulation_reset_overlay, EmulationActivity.MENU_ACTION_RESET_OVERLAY);
|
||||||
buttonsActionsMap.append(R.id.menu_emulation_set_ir_sensitivity,
|
buttonsActionsMap.append(R.id.menu_emulation_set_ir_sensitivity,
|
||||||
EmulationActivity.MENU_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)
|
private static String[] scanForSecondDisc(GameFile gameFile)
|
||||||
|
@ -591,6 +597,10 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
setIRSensitivity();
|
setIRSensitivity();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case MENU_ACTION_CHOOSE_DOUBLETAP:
|
||||||
|
chooseDoubleTapButton();
|
||||||
|
return;
|
||||||
|
|
||||||
case MENU_ACTION_EXIT:
|
case MENU_ACTION_EXIT:
|
||||||
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
|
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
|
||||||
if (TvUtil.isLeanback(getApplicationContext()))
|
if (TvUtil.isLeanback(getApplicationContext()))
|
||||||
|
@ -721,6 +731,39 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
alertDialog.show();
|
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()
|
private void adjustScale()
|
||||||
{
|
{
|
||||||
LayoutInflater inflater = LayoutInflater.from(this);
|
LayoutInflater inflater = LayoutInflater.from(this);
|
||||||
|
|
|
@ -40,6 +40,12 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public final class InputOverlay extends SurfaceView implements OnTouchListener
|
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<InputOverlayDrawableButton> overlayButtons = new HashSet<>();
|
||||||
private final Set<InputOverlayDrawableDpad> overlayDpads = new HashSet<>();
|
private final Set<InputOverlayDrawableDpad> overlayDpads = new HashSet<>();
|
||||||
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<>();
|
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<>();
|
||||||
|
@ -666,7 +672,17 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EmulationActivity.isGameCubeGame())
|
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();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,22 +2,45 @@ package org.dolphinemu.dolphinemu.overlay;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class InputOverlayPointer
|
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 final float[] axes = {0f, 0f};
|
||||||
private float maxHeight;
|
private float maxHeight;
|
||||||
private float maxWidth;
|
private float maxWidth;
|
||||||
|
private boolean doubleTap = false;
|
||||||
|
private int doubleTapButton;
|
||||||
private int trackId = -1;
|
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();
|
Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
|
||||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||||
display.getMetrics(outMetrics);
|
display.getMetrics(outMetrics);
|
||||||
|
doubleTapButton = button;
|
||||||
maxWidth = outMetrics.widthPixels / 2;
|
maxWidth = outMetrics.widthPixels / 2;
|
||||||
maxHeight = outMetrics.heightPixels / 2;
|
maxHeight = outMetrics.heightPixels / 2;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +54,7 @@ public class InputOverlayPointer
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
trackId = event.getPointerId(pointerIndex);
|
trackId = event.getPointerId(pointerIndex);
|
||||||
|
touchPress();
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
|
@ -50,6 +74,22 @@ public class InputOverlayPointer
|
||||||
return false;
|
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()
|
public float[] getAxisValues()
|
||||||
{
|
{
|
||||||
float[] ir = {0f, 0f};
|
float[] ir = {0f, 0f};
|
||||||
|
|
|
@ -112,12 +112,21 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_choose_controller"
|
android:id="@+id/menu_emulation_choose_controller"
|
||||||
android:title="@string/emulation_choose_controller"/>
|
android:title="@string/emulation_choose_controller"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_set_ir_sensitivity"
|
android:id="@+id/menu_emulation_ir_group"
|
||||||
app:showAsAction="ifRoom"
|
android:title="@string/emulation_ir_group"
|
||||||
android:title="@string/emulation_ir_sensitivity"/>
|
app:showAsAction="never">
|
||||||
|
<menu>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_set_ir_sensitivity"
|
||||||
|
android:title="@string/emulation_ir_sensitivity"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_choose_doubletap"
|
||||||
|
android:title="@string/emulation_choose_doubletap"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_reset_overlay"
|
android:id="@+id/menu_emulation_reset_overlay"
|
||||||
android:title="@string/emulation_touch_overlay_reset"/>
|
android:title="@string/emulation_touch_overlay_reset"/>
|
||||||
|
|
|
@ -306,6 +306,19 @@
|
||||||
<item>Right Stick</item>
|
<item>Right Stick</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="doubleTap">
|
||||||
|
<item>Button A</item>
|
||||||
|
<item>Button B</item>
|
||||||
|
<item>Button 2</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="doubleTapWithClassic">
|
||||||
|
<item>Button A</item>
|
||||||
|
<item>Button B</item>
|
||||||
|
<item>Button 2</item>
|
||||||
|
<item>Classic A</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="gameSettingsMenusGC">
|
<string-array name="gameSettingsMenusGC">
|
||||||
<item>Core Settings</item>
|
<item>Core Settings</item>
|
||||||
<item>GFX Settings</item>
|
<item>GFX Settings</item>
|
||||||
|
|
|
@ -298,7 +298,9 @@
|
||||||
<string name="emulation_controller_changed">You may have to reload the game after changing extensions.</string>
|
<string name="emulation_controller_changed">You may have to reload the game after changing extensions.</string>
|
||||||
<string name="emulation_touch_button_help">Swipe down from the top of the screen to access the menu.</string>
|
<string name="emulation_touch_button_help">Swipe down from the top of the screen to access the menu.</string>
|
||||||
<string name="emulation_touch_overlay_reset">Reset Overlay</string>
|
<string name="emulation_touch_overlay_reset">Reset Overlay</string>
|
||||||
|
<string name="emulation_ir_group">Touch IR Pointer</string>
|
||||||
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
|
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
|
||||||
|
<string name="emulation_choose_doubletap">Double tap button</string>
|
||||||
|
|
||||||
<!-- GC Adapter Menu-->
|
<!-- GC Adapter Menu-->
|
||||||
<string name="gc_adapter_rumble">Enable Vibration</string>
|
<string name="gc_adapter_rumble">Enable Vibration</string>
|
||||||
|
|
Loading…
Reference in New Issue