[Scummvm-git-logs] scummvm master -> 6906bba959bd7ea1f9571c7d2b776fb85ee08e9e

antoniou79 a.antoniou79 at gmail.com
Wed Sep 16 17:35:54 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6906bba959 ANDROID: Revert chnage for long press AC_BACK handler


Commit: 6906bba959bd7ea1f9571c7d2b776fb85ee08e9e
    https://github.com/scummvm/scummvm/commit/6906bba959bd7ea1f9571c7d2b776fb85ee08e9e
Author: antoniou (a.antoniou79 at gmail.com)
Date: 2020-09-16T20:34:49+03:00

Commit Message:
ANDROID: Revert chnage for long press AC_BACK handler

Huawei Android 9 seemed to not be working ok (or at all) with the change

Changed paths:
    backends/platform/android/android.cpp
    backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java


diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 2cc1771033..daef0f1c11 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -311,11 +311,10 @@ void OSystem_Android::initBackend() {
 	ConfMan.registerDefault("aspect_ratio", true);
 	ConfMan.registerDefault("touchpad_mouse_mode", true);
 	ConfMan.registerDefault("onscreen_control", true);
-	// The swap_menu_and_back is a legacy configuration key
+	// The swap_menu_and_back is a deprecated configuration key
 	// It is no longer relevant, after introducing the keymapper functionality
 	// since the behaviour of the menu and back buttons is now handled by the keymapper.
-	// The key is thus registered to default to a "false" value
-	ConfMan.registerDefault("swap_menu_and_back", false);
+	// We now ignore it completely
 
 	ConfMan.registerDefault("autosave_period", 0);
 	ConfMan.setBool("FM_high_quality", false);
@@ -328,10 +327,12 @@ void OSystem_Android::initBackend() {
 		ConfMan.set("browser_lastpath", "/");
 	}
 
-	if (ConfMan.hasKey("touchpad_mouse_mode"))
+	if (ConfMan.hasKey("touchpad_mouse_mode")) {
 		_touchpad_mode = ConfMan.getBool("touchpad_mouse_mode");
-	else
+	} else {
 		ConfMan.setBool("touchpad_mouse_mode", true);
+		_touchpad_mode = true;
+	}
 
 	if (ConfMan.hasKey("onscreen_control"))
 		JNI::showKeyboardControl(ConfMan.getBool("onscreen_control"));
@@ -425,18 +426,10 @@ Common::KeymapperDefaultBindings *OSystem_Android::getKeymapperDefaultBindings()
 	Common::KeymapperDefaultBindings *keymapperDefaultBindings = new Common::KeymapperDefaultBindings();
 
 	// The swap_menu_and_back is a legacy configuration key
-	// It is only checked here for compatibility with old config files
-	// where it may have been set as "true"
-	// TODO Why not just ignore it entirely anyway?
-	if (ConfMan.hasKey("swap_menu_and_back")  && ConfMan.getBool("swap_menu_and_back")) {
-		keymapperDefaultBindings->setDefaultBinding(Common::kGlobalKeymapName, "MENU", "AC_BACK");
-		keymapperDefaultBindings->setDefaultBinding("engine-default", Common::kStandardActionSkip, "MENU");
-		keymapperDefaultBindings->setDefaultBinding(Common::kGuiKeymapName, "CLOS", "MENU");
-	} else {
-		keymapperDefaultBindings->setDefaultBinding(Common::kGlobalKeymapName, "MENU", "MENU");
-		keymapperDefaultBindings->setDefaultBinding("engine-default", Common::kStandardActionSkip, "AC_BACK");
-		keymapperDefaultBindings->setDefaultBinding(Common::kGuiKeymapName, "CLOS", "AC_BACK");
-	}
+	// We now ignore it entirely (it as always false -- ie. back short press is AC_BACK)
+	keymapperDefaultBindings->setDefaultBinding(Common::kGlobalKeymapName, "MENU", "MENU");
+	keymapperDefaultBindings->setDefaultBinding("engine-default", Common::kStandardActionSkip, "AC_BACK");
+	keymapperDefaultBindings->setDefaultBinding(Common::kGuiKeymapName, "CLOS", "AC_BACK");
 
 	return keymapperDefaultBindings;
 }
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java
index 414033ab78..632adbf2de 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java
@@ -1,9 +1,10 @@
 package org.scummvm.scummvm;
 
-import androidx.annotation.NonNull;
+//import androidx.annotation.NonNull;
 import android.os.Handler;
 import android.os.Message;
 import android.content.Context;
+//import android.util.Log;
 import android.view.KeyEvent;
 import android.view.KeyCharacterMap;
 import android.view.MotionEvent;
@@ -13,7 +14,7 @@ import android.view.GestureDetector;
 import android.view.InputDevice;
 import android.view.inputmethod.InputMethodManager;
 
-import java.lang.ref.WeakReference;
+//import java.lang.ref.WeakReference;
 
 public class ScummVMEvents implements
 		android.view.View.OnKeyListener,
@@ -51,7 +52,29 @@ public class ScummVMEvents implements
 	final protected int _longPress;
 	final protected MouseHelper _mouseHelper;
 
-	final private ScummVMEventHandler keyHandler;
+	// Reverted code back to using the native Handler function instead of a static custom,
+	// since that had issues detecting the long-presses for some reason
+	// So for now we shall ignore the Android Studio warning for "This Handler class should be static or leaks might occur (anonymous android.os.Handler)"
+	//
+	// TODO investigate further why our static custom Handler based on https://stackoverflow.com/a/57926736 was not receiving messages *especially* on a recent enough Android 9 device (Huawei MediaPad M5 CMR-W09)
+	//
+	final private Handler _keyHandler = new Handler() {
+		@Override
+		public void handleMessage(Message msg) {
+			if (msg.what == MSG_SMENU_LONG_PRESS) {
+				// this displays the android keyboard (see showVirtualKeyboard() in ScummVMActivity.java)
+				// when menu key is long-pressed
+				InputMethodManager imm = (InputMethodManager)
+					_context.getSystemService(Context.INPUT_METHOD_SERVICE);
+
+				if (imm != null)
+					imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+			} else if (msg.what == MSG_SBACK_LONG_PRESS) {
+				_scummvm.pushEvent(JE_SYS_KEY, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU, 0, 0, 0, 0);
+				_scummvm.pushEvent(JE_SYS_KEY, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU, 0, 0, 0, 0);
+			}
+		}
+	};
 
 	public ScummVMEvents(Context context, ScummVM scummvm, MouseHelper mouseHelper) {
 		_context = context;
@@ -63,29 +86,9 @@ public class ScummVMEvents implements
 		_gd.setIsLongpressEnabled(false);
 
 		_longPress = ViewConfiguration.getLongPressTimeout();
-
-		keyHandler = new ScummVMEventHandler(new ScummVMEventHandler.OnMessageReceivedListener() {
-			@Override
-			public void handleMessage(final Message msg) {
-				if (msg.what == MSG_SMENU_LONG_PRESS) {
-					// this displays the android keyboard (see showVirtualKeyboard() in ScummVMActivity.java)
-					// when menu key is long-pressed
-					InputMethodManager imm = (InputMethodManager)
-						_context.getSystemService(Context.INPUT_METHOD_SERVICE);
-
-					if (imm != null)
-						imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
-				} else if (msg.what == MSG_SBACK_LONG_PRESS) {
-					_scummvm.pushEvent(JE_SYS_KEY, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU, 0, 0, 0, 0);
-					_scummvm.pushEvent(JE_SYS_KEY, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU, 0, 0, 0, 0);
-				}
-			}
-		});
 	}
 
-	public void clearEventHandler() {
-		keyHandler.clear();
-	}
+	public void clearEventHandler() { }
 
 	final public void sendQuitEvent() {
 		_scummvm.pushEvent(JE_QUIT, 0, 0, 0, 0, 0, 0);
@@ -106,32 +109,6 @@ public class ScummVMEvents implements
 	final static int MSG_SMENU_LONG_PRESS = 1;
 	final static int MSG_SBACK_LONG_PRESS = 2;
 
-	// Custom handler code (to avoid mem leaks, see warning "This Handler Class Should Be Static Or Leaks Might Occur”) based on:
-	// https://stackoverflow.com/a/57926736
-	public static class ScummVMEventHandler extends Handler {
-
-		WeakReference<OnMessageReceivedListener> mListenerReference;
-
-		public ScummVMEventHandler(OnMessageReceivedListener listener) {
-			mListenerReference = new WeakReference<>(listener);
-		}
-
-		public synchronized void handleMessage(@NonNull Message msg) {
-			OnMessageReceivedListener listener = mListenerReference.get();
-			if(listener != null) {
-				listener.handleMessage(msg);
-			}
-		}
-
-		public void clear() {
-			mListenerReference.clear();
-		}
-
-		public interface OnMessageReceivedListener {
-			void handleMessage(final Message message);
-		}
-	}
-
 	// OnKeyListener
 	@Override
 	final public boolean onKey(View v, int keyCode, KeyEvent e) {
@@ -179,13 +156,12 @@ public class ScummVMEvents implements
 					typeOfLongPressMessage = MSG_SBACK_LONG_PRESS;
 				}
 
-				final boolean fired = !keyHandler.hasMessages(typeOfLongPressMessage);
+				final boolean fired = !_keyHandler.hasMessages(typeOfLongPressMessage);
 
-				keyHandler.removeMessages(typeOfLongPressMessage);
+				_keyHandler.removeMessages(typeOfLongPressMessage);
 
 				if (action == KeyEvent.ACTION_DOWN) {
-					keyHandler.sendMessageDelayed(keyHandler.obtainMessage(
-									typeOfLongPressMessage), _longPress);
+					_keyHandler.sendMessageDelayed(_keyHandler.obtainMessage(typeOfLongPressMessage), _longPress);
 					return true;
 				} else if (action != KeyEvent.ACTION_UP) {
 					return true;




More information about the Scummvm-git-logs mailing list