Skip to content

Commit

Permalink
ANDROID: Merge touch mode and toggle keyboard buttons
Browse files Browse the repository at this point in the history
A long press on the button shows the keyboard
  • Loading branch information
lephilousophe authored and antoniou79 committed Jun 13, 2022
1 parent 57e27dc commit bbcdda6
Showing 1 changed file with 42 additions and 44 deletions.
86 changes: 42 additions & 44 deletions backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
Expand Up @@ -118,8 +118,7 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
FrameLayout _videoLayout = null;

private EditableSurfaceView _main_surface = null;
private ImageView _toggleTouchModeBtnIcon = null;
private ImageView _toggleKeyboardBtnIcon = null;
private ImageView _toggleTouchModeKeyboardBtnIcon = null;
private ImageView _openMenuBtnIcon = null;
private ImageView _revokeSafPermissionsBtnIcon = null;

Expand All @@ -142,7 +141,6 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);

final boolean hwKeyboard = isHWKeyboardConnected();
_toggleKeyboardBtnIcon.setVisibility(hwKeyboard ? View.GONE : View.VISIBLE);
if (hwKeyboard) {
hideScreenKeyboard();
}
Expand Down Expand Up @@ -520,6 +518,7 @@ public void showScreenKeyboard() {
//Log.d(ScummVM.LOG_TAG, "showScreenKeyboard - captureMouse(false)");
_main_surface.captureMouse(false);
//_main_surface.showSystemMouseCursor(true);
setupTouchModeBtn(_events.getTouchMode());
return;
}
//Log.d(ScummVM.LOG_TAG, "showScreenKeyboard: YOU SHOULD NOT SEE ME!!!");
Expand All @@ -541,6 +540,7 @@ public void hideScreenKeyboard() {
//Log.d(ScummVM.LOG_TAG, "hideScreenKeyboard - captureMouse(true)");
_main_surface.captureMouse(true);
//_main_surface.showSystemMouseCursor(false);
setupTouchModeBtn(_events.getTouchMode());
}
}
}
Expand Down Expand Up @@ -573,43 +573,55 @@ public View getScreenKeyboard() {
protected void setupTouchModeBtn(final int touchMode) {
int resId;

switch(touchMode) {
case ScummVMEventsBase.TOUCH_MODE_TOUCHPAD:
resId = R.drawable.ic_action_touchpad;
break;
case ScummVMEventsBase.TOUCH_MODE_MOUSE:
resId = R.drawable.ic_action_mouse;
break;
case ScummVMEventsBase.TOUCH_MODE_GAMEPAD:
resId = R.drawable.ic_action_gamepad;
break;
default:
throw new IllegalArgumentException("Invalid touchMode");
}

_toggleTouchModeBtnIcon.setImageResource(resId);
if (isScreenKeyboardShown()) {
resId = R.drawable.ic_action_keyboard;
} else {
switch(touchMode) {
case ScummVMEventsBase.TOUCH_MODE_TOUCHPAD:
resId = R.drawable.ic_action_touchpad;
break;
case ScummVMEventsBase.TOUCH_MODE_MOUSE:
resId = R.drawable.ic_action_mouse;
break;
case ScummVMEventsBase.TOUCH_MODE_GAMEPAD:
resId = R.drawable.ic_action_gamepad;
break;
default:
throw new IllegalArgumentException("Invalid touchMode");
}
}

_toggleTouchModeKeyboardBtnIcon.setImageResource(resId);
}

public final View.OnClickListener touchModeBtnOnClickListener = new View.OnClickListener() {
public final View.OnClickListener touchModeKeyboardBtnOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
runOnUiThread(new Runnable() {
public void run() {
int newTouchMode = _events.nextTouchMode();
setupTouchModeBtn(newTouchMode);
// On normal click, hide keyboard if it is shown
// Else, change touch mode
if (isScreenKeyboardShown()) {
hideScreenKeyboard();
} else {
int newTouchMode = _events.nextTouchMode();
setupTouchModeBtn(newTouchMode);
}
}
});
}
};

public final View.OnClickListener keyboardBtnOnClickListener = new View.OnClickListener() {
public final View.OnLongClickListener touchModeKeyboardBtnOnLongClickListener = new View.OnLongClickListener() {
@Override
public void onClick(View v) {
public boolean onLongClick(View v) {
runOnUiThread(new Runnable() {
public void run() {
// On long click, toggle screen keyboard (if there isn't any HW)
toggleScreenKeyboard();
}
});
return true;
}
};

Expand Down Expand Up @@ -1028,14 +1040,9 @@ public void onCreate(Bundle savedInstanceState) {
_videoLayout.addView(buttonLayout, buttonLayoutParams);
_videoLayout.bringChildToFront(buttonLayout);

_toggleTouchModeBtnIcon = new ImageView(this);
buttonLayout.addView(_toggleTouchModeBtnIcon, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
buttonLayout.bringChildToFront(_toggleTouchModeBtnIcon);

_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));
buttonLayout.bringChildToFront(_toggleKeyboardBtnIcon);
_toggleTouchModeKeyboardBtnIcon = new ImageView(this);
buttonLayout.addView(_toggleTouchModeKeyboardBtnIcon, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
buttonLayout.bringChildToFront(_toggleTouchModeKeyboardBtnIcon);

_openMenuBtnIcon = new ImageView(this);
_openMenuBtnIcon.setImageResource(R.drawable.ic_action_menu);
Expand Down Expand Up @@ -1143,8 +1150,8 @@ public void handle(int exitResult) {

// On screen button listener
//findViewById(R.id.show_keyboard).setOnClickListener(keyboardBtnOnClickListener);
_toggleTouchModeBtnIcon.setOnClickListener(touchModeBtnOnClickListener);
_toggleKeyboardBtnIcon.setOnClickListener(keyboardBtnOnClickListener);
_toggleTouchModeKeyboardBtnIcon.setOnClickListener(touchModeKeyboardBtnOnClickListener);
_toggleTouchModeKeyboardBtnIcon.setOnLongClickListener(touchModeKeyboardBtnOnLongClickListener);
_openMenuBtnIcon.setOnClickListener(menuBtnOnClickListener);
_revokeSafPermissionsBtnIcon.setOnClickListener(revokeSafPermissionsBtnOnClickListener);

Expand Down Expand Up @@ -1398,21 +1405,12 @@ private void hideSystemUI() {
// Show or hide the semi-transparent onscreen controls
// Called by the override of showKeyboardControl()
private void showToggleKeyboardBtnIcon(boolean show) {
//ImageView keyboardBtn = findViewById(R.id.show_keyboard);
if (_toggleKeyboardBtnIcon != null ) {
if (show && !isHWKeyboardConnected()) {
_toggleKeyboardBtnIcon.setVisibility(View.VISIBLE);
} else {
_toggleKeyboardBtnIcon.setVisibility(View.GONE);
}
}

if (_openMenuBtnIcon != null ) {
_openMenuBtnIcon.setVisibility(show ? View.VISIBLE : View.GONE);
}

if (_toggleTouchModeBtnIcon != null ) {
_toggleTouchModeBtnIcon.setVisibility(show ? View.VISIBLE : View.GONE);
if (_toggleTouchModeKeyboardBtnIcon != null ) {
_toggleTouchModeKeyboardBtnIcon.setVisibility(show ? View.VISIBLE : View.GONE);
}
}

Expand Down

0 comments on commit bbcdda6

Please sign in to comment.