ANDROID: Allow user to enable touch controls

This commit is contained in:
Le Philousophe 2021-12-25 23:25:55 +01:00
parent 639d633f12
commit 523b226243
4 changed files with 53 additions and 5 deletions

View File

@ -118,6 +118,7 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
FrameLayout _videoLayout = null;
private EditableSurfaceView _main_surface = null;
private ImageView _toggleGamepadBtnIcon = null;
private ImageView _toggleKeyboardBtnIcon = null;
private ImageView _openMenuBtnIcon = null;
private ImageView _revokeSafPermissionsBtnIcon = null;
@ -569,6 +570,19 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
// ---------------------------------------------------------------------------------------------------------------------------
//
public final View.OnClickListener gamepadBtnOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
runOnUiThread(new Runnable() {
public void run() {
boolean touch3DMode = !_events.getTouch3DMode();
_events.setTouch3DMode(touch3DMode);
_toggleGamepadBtnIcon.setImageResource(touch3DMode ? R.drawable.ic_action_mouse : R.drawable.ic_action_gamepad);
}
});
}
};
public final View.OnClickListener keyboardBtnOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -726,9 +740,13 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
@Override
protected void setTouch3DMode(final boolean touch3DMode) {
if (_events.getTouch3DMode() == touch3DMode) {
return;
}
runOnUiThread(new Runnable() {
public void run() {
_events.setTouch3DMode(touch3DMode);
_toggleGamepadBtnIcon.setImageResource(touch3DMode ? R.drawable.ic_action_mouse : R.drawable.ic_action_gamepad);
}
});
}
@ -986,6 +1004,11 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
_videoLayout.addView(buttonLayout, buttonLayoutParams);
_videoLayout.bringChildToFront(buttonLayout);
_toggleGamepadBtnIcon = new ImageView(this);
_toggleGamepadBtnIcon.setImageResource(R.drawable.ic_action_gamepad);
buttonLayout.addView(_toggleGamepadBtnIcon, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
buttonLayout.bringChildToFront(_toggleGamepadBtnIcon);
_toggleKeyboardBtnIcon = new ImageView(this);
_toggleKeyboardBtnIcon.setImageResource(R.drawable.ic_action_keyboard);
buttonLayout.addView(_toggleKeyboardBtnIcon, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
@ -1095,6 +1118,7 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
// On screen button listener
//findViewById(R.id.show_keyboard).setOnClickListener(keyboardBtnOnClickListener);
_toggleGamepadBtnIcon.setOnClickListener(gamepadBtnOnClickListener);
_toggleKeyboardBtnIcon.setOnClickListener(keyboardBtnOnClickListener);
_openMenuBtnIcon.setOnClickListener(menuBtnOnClickListener);
_revokeSafPermissionsBtnIcon.setOnClickListener(revokeSafPermissionsBtnOnClickListener);
@ -1359,11 +1383,11 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
}
if (_openMenuBtnIcon != null ) {
if (show) {
_openMenuBtnIcon.setVisibility(View.VISIBLE);
} else {
_openMenuBtnIcon.setVisibility(View.GONE);
}
_openMenuBtnIcon.setVisibility(show ? View.VISIBLE : View.GONE);
}
if (_toggleGamepadBtnIcon != null ) {
_toggleGamepadBtnIcon.setVisibility(show ? View.VISIBLE : View.GONE);
}
}

View File

@ -142,6 +142,10 @@ public class ScummVMEventsBase implements
}
}
final public boolean getTouch3DMode() {
return _touch3DMode;
}
final public void setTouch3DMode(boolean touch3DMode) {
if (_touch3DMode != touch3DMode && !touch3DMode) {
_scummvm.updateTouch(JACTION_CANCEL, 0, 0, 0);

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:alpha="0.5">
<path
android:fillColor="#ffffff"
android:pathData="M42,12L6,12c-2.2,0 -4,1.8 -4,4v16c0,2.2 1.8,4 4,4h36c2.2,0 4,-1.8 4,-4L46,16c0,-2.2 -1.8,-4 -4,-4zM22,26L16,26v6L12,32v-6L6,26v-4h6L12,16h4v6h6v4zM31,30c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM39,24c-1.66,0 -3,-1.34 -3,-3S37.34,18 39,18s3,1.34 3,3 -1.34,3 -3,3z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:alpha="0.5">
<path
android:fillColor="#ffffff"
android:pathData="M26,2.14L26,18h14c0,-8.16 -6.1,-14.88 -14,-15.86zM8,30c0,8.84 7.16,16 16,16s16,-7.16 16,-16v-8L8,22v8zM22,2.14C14.1,3.12 8,9.84 8,18h14L22,2.14z"/>
</vector>