简体   繁体   English

Delphi Android 10.3.3 上没有返回键的 OnKeyDown 事件

[英]No OnKeyDown event for Return key on Delphi Android 10.3.3

I am in the process of upgrading from Delphi 10.2.3 to 10.3.3.我正在从 Delphi 10.2.3 升级到 10.3.3。 My android apps are now not generating an OnKeyDown event from the virtual keyboard for the Return key.我的 android 应用程序现在没有从虚拟键盘为 Return 键生成 OnKeyDown 事件。 I have confirmed this using a very basic newly created project so it is nothing to do with the conversion from 10.2.3 it seems.我已经使用一个非常基本的新创建的项目确认了这一点,所以它似乎与 10.2.3 的转换无关。

Any ideas would be appreciated.任何想法,将不胜感激。

QA at embarcadero have come back with the following response: embarcadero 的 QA 回复如下:

"According to this documentation - Handle keyboard actions or this - KeyEvent : “根据此文档 - 处理键盘操作或此 - KeyEvent

When handling keyboard events with the KeyEvent class and related APIs, you should expect that such keyboard events come only from a hardware keyboard.使用 KeyEvent 类和相关 API 处理键盘事件时,您应该期望此类键盘事件仅来自硬件键盘。 You should never rely on receiving key events for any key on a soft input method (an on-screen keyboard).对于软输入法(屏幕键盘)上的任何键,您永远不应依赖接收键事件。

I think that using methods that fire up when text get changed is a sufficient workaround to this issue...我认为使用在文本更改时启动的方法是解决此问题的充分方法......

I think this Stackoverflow question and this Blogpost may be useful.我认为这个Stackoverflow问题和这个Blogpost可能有用。 "

The solution offered involves adding a TextListener to JFMXTextEditorProxy, and that latter interface has disappeared from delphi 10.3.提供的解决方案包括向 JFMXTextEditorProxy 添加一个 TextListener,而后一个接口已从 delphi 10.3 中消失。 I am currently attempting to implement something equivalent in 10.3, but would appreciate any guidance.我目前正在尝试在 10.3 中实现等效的东西,但希望得到任何指导。 BTW: Others will have different aims, but for my part all I want to see is the return key.顺便说一句:其他人会有不同的目标,但就我而言,我只想看到返回键。

Update: Originally this was assumed to be a bug.更新:最初这被认为是一个错误。 QA at embarcadero however take the view that it is not and one should not rely on the virtual keyboard to fire off keyboard events.然而,embarcadero 的 QA 认为它不是,也不应该依赖虚拟键盘来触发键盘事件。 But they offer no other viable alternatives.但他们没有提供其他可行的替代方案。 The blog post they cited is not suitable for 10.3, and it seems that it would never see the return key anyway.他们引用的博文不适用于10.3,而且似乎无论如何也看不到返回键。

I have stumbled across a workaround, which appears to work, though it too may be susceptible to future changes.我偶然发现了一种解决方法,它似乎有效,尽管它也可能容易受到未来变化的影响。

If one changes the ReturnKeyType of a Tedit to any of the values Go , Search or Send , the onkeydown event will fire for the return key.如果将 Tedit 的 ReturnKeyType 更改为GoSearchSend 中的任何值,则将为返回键触发 onkeydown 事件。 Another alternative would be to use the OnChange event.另一种选择是使用 OnChange 事件。 This does not fire for the return key, when the Tedit is set to Default ReturnKeyType either, but when set to any of the above values (plus Next also), it will fire.这不会为返回键触发,当 Tedit 设置为 Default ReturnKeyType 时,但当设置为上述任何值(加上 Next)时,它将触发。 ReturnKeyType is available at design time, and can also be changed in code eg: ReturnKeyType 在设计时可用,也可以在代码中更改,例如:

  edit1.ReturnKeyType := TReturnKeyType.Go;

And if really desperate, I have observed that the OnChange event will fire if the contents of the edit have indeed changed and one uses the Android "back" button to dismiss the virtual keyboard.如果真的很绝望,我观察到如果编辑的内容确实发生了变化并且使用 Android 的“后退”按钮关闭虚拟键盘,OnChange 事件将触发。

To address the various things that have come up in this discussion:为了解决本次讨论中出现的各种问题:

  1. RSP-27496 has been re-opened RSP-27496已重新开放
  2. You can fix the issue by making an edit to C:\\Program Files (x86)\\Embarcadero\\Studio\\20.0\\source\\rtl\\androiddex\\java\\fmx\\src\\com\\embarcadero\\firemonkey\\text\\FMXEditText.java and rebuilding the Java files required by Delphi Android apps.您可以通过编辑 C:\\Program Files (x86)\\Embarcadero\\Studio\\20.0\\source\\rtl\\androiddex\\java\\fmx\\src\\com\\embarcadero\\firemonkey\\text\\FMXEditText.java 并重建来解决此问题Delphi Android 应用程序所需的 Java 文件。 This allows the Return key to get OnKeyDown and OnKeyUp events as required, without having to use TomB's workaround.这允许 Return 键根据需要获取OnKeyDownOnKeyUp事件,而无需使用 TomB 的解决方法。

What edit to make to FMXEditText.java对 FMXEditText.java 进行什么编辑

In the method onEditorAction , which has just an if statement with code in both the if and else branches, take the code out of the else branch and make it unconditional.onEditorAction方法中,它只有一个 if 语句,在 if 和 else 分支中都有代码,从 else 分支中取出代码并使其成为无条件的。

In other words, where it says (and I'm posting a representative code snippet rather than pasting the actual code to avoid being accused of doing 'naughty' things):换句话说,它说的地方(我发布了一个代表性的代码片段,而不是粘贴实际代码以避免被指责做“淘气”的事情):

public void onEditorAction(int actionCode) {
    if (condition) {
        // if block
    } else {
        // else block
    }
}

change it to say:改成这样:

public void onEditorAction(int actionCode) {
    if (condition) {
        // if block
    }
    // else block
}

How to rebuild the Java RTL files如何重建 Java RTL 文件

This bit is a little complicated to go into detail on here, but what you need is a command script that will basically do the job for you.在这里详细介绍这一点有点复杂,但是您需要的是一个基本上可以为您完成工作的命令脚本。 For fixing a Java issue in 10.3.0 I had a command script available on a blog post here in amongst discussion of the issue being fixed, and for 10.3.3 a post solely for how to rebuild the Java files can be found here .为了修复 10.3.0 中的 Java 问题,我在此处的博客文章中提供了一个命令脚本,其中讨论了正在修复的问题,而对于 10.3.3, 可以在此处找到仅介绍如何重建 Java 文件的文章。

However, to avoid the comments about solutions on external links being inappropriate as those links may evaporate over time, here is the full command script.但是,为了避免有关外部链接解决方案的评论不合适,因为这些链接可能会随着时间的推移而消失,这里是完整的命令脚本。 Check all the paths being plumbed into the variables are correct, store the script in a file called BuildFMX.cmd, run an administrative command prompt and invoke the script from there:检查所有插入变量的路径是否正确,将脚本存储在名为 BuildFMX.cmd 的文件中,运行管理命令提示符并从那里调用脚本:

@echo off
cls

rem Android RTL Java files rebuilder for RAD Studio 10.3.3

setlocal enabledelayedexpansion

rem Set environment variables
rem *NOTE*: check these folders match your setup

set EMBT=Embarcadero\Studio\20.0
set BDS=%ProgramFiles(x86)%\%EMBT%
set JAVA_PATH=%ProgramFiles%\Java\jdk1.8.0_60\bin
rem This is the default path for the Android SDK when installed from the .iso installer
set SDK_PATH=%PUBLIC%\Documents\%EMBT%\PlatformSDKs\android-sdk-windows
if not exist "%SDK_PATH%\" (
  rem This is the default path for the Android SDK when installed from the web install (aka ESD install)
  set SDK_PATH=%PUBLIC%\Documents\%EMBT%\CatalogRepository\AndroidSDK-2525_20.0.36039.7899
)

rem Set more environment variables based on those above

set DX_PATH=%SDK_PATH%\build-tools\28.0.2
set ANDROID_JAR=%SDK_PATH%\platforms\android-26\android.jar
set BDS_LIB=%BDS%\lib
set BDS_DEBUG_LIB=%BDS%\lib\android\debug
set BDS_RELEASE_LIB=%BDS%\lib\android\release
set FMX_SRC_PATH=%BDS%\source\rtl\androiddex\java\fmx
set CLASS_PATH=%ANDROID_JAR%
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\android-support-v4.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\cloud-messaging.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-base.16.0.1.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-maps.16.1.0.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\debug\com-google-android-gms.play-services-ads.17.2.0.jar
rem For adListener
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-ads-lite.17.2.0.jar
rem For AbstractSafeParcelable
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-basement.16.2.0.jar
rem For ReflectedParcelable
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-basement.16.2.0.jar

echo.
echo Checking environment variables

if not exist "%BDS%\" (
  echo Path used to set BDS environment variable does not exist^^! Is RAD Studio installed elsewhere?
  goto :Error
)

if not exist "%JAVA_PATH%\" (
  echo Path used to set JAVA_PATH environment variable does not exist^^! Is the JDK installed elsewhere?
  goto :Error
)

if not exist "%SDK_PATH%\" (
  echo Path used to set SDK_PATH environment variable does not exist^^! Is the Android SDK installed elsewhere?
  goto :Error
)

if not exist "%ANDROID_JAR%" (
  echo Path used to set ANDROID_JAR environment variable does not exist^^! Is your android.jar in a different platform folder?
  goto :Error
)

echo.
echo Changing to the FMX source folder
echo.

pushd %FMX_SRC_PATH%

echo Getting fully qualified list of all Java source file we need to rebuild
echo.

if not exist bin\classes mkdir bin\classes
if not exist bin\debug mkdir bin\debug
if not exist bin\release mkdir bin\release
dir src\android\bluetooth\*.java /s /b > JavaSources.txt
dir src\android\telephony\*.java /s /b >> JavaSources.txt
dir src\com\*.java /s /b >> JavaSources.txt

echo Ensuring FMX source path ends in a '\'
echo.

set LAST_CHAR=%FMX_SRC_PATH:~-1%
if not "%LAST_CHAR%"=="\" set FMX_SRC_PATH=%FMX_SRC_PATH%\

echo Making Java source file paths relative to current directory
echo.

if exist JavaSources2.txt del JavaSources2.txt
for /F "tokens=*" %%A in (JavaSources.txt) do (
  set STR=%%A
  set "STR=!STR:%FMX_SRC_PATH%=!"
  echo !STR!>>JavaSources2.txt
)

echo Compiling all the FMX Java code into class files with debug info
echo.

"%JAVA_PATH%"\javac -g -d bin\classes -classpath "%CLASS_PATH%" -encoding UTF-8 -g @JavaSources2.txt
if errorlevel 1 (
  echo.
  echo Problem encountered during Java compilation
  goto :Error
)

echo.
echo Creating jar containing the new compiled FMX Java classes with debug info
echo.

"%JAVA_PATH%"\jar cf bin\debug\fmx.jar -C bin\classes .
if errorlevel 1 (
  echo.
  echo Problem encountered during Java archiving
  goto :Error
)

echo Creating DEX jar containing the new compiled FMX Java classes with debug info
echo.

call %DX_PATH%\dx --dex --output=bin\debug\fmx.dex.jar --positions=lines bin\debug\fmx.jar
if errorlevel 1 (
  echo.
  echo Problem encountered during DEXing
  goto :Error
)

echo Compiling all the FMX Java code into class files without debug info
echo.

"%JAVA_PATH%"\javac -g:none -d bin\classes -classpath "%CLASS_PATH%" -encoding UTF-8 @JavaSources2.txt
if errorlevel 1 (
  echo.
  echo Problem encountered during Java compilation
  goto :Error
)

echo.
echo Creating jar containing the new compiled FMX Java classes without debug info
echo.

"%JAVA_PATH%"\jar cf bin\release\fmx.jar -C bin\classes .
if errorlevel 1 (
  echo.
  echo Problem encountered during Java archiving
  goto :Error
)

echo Creating DEX jar containing the new compiled FMX Java classes without debug info
echo.

call %DX_PATH%\dx --dex --output=bin\release\fmx.dex.jar --positions=lines bin\release\fmx.jar
if errorlevel 1 (
  echo.
  echo Problem encountered during DEXing
  goto :Error
)

copy bin\debug\* "%BDS_DEBUG_LIB%"
copy bin\release\* "%BDS_RELEASE_LIB%"

echo Tidying up...
echo.
if exist JavaSources.txt del JavaSources.txt
if exist JavaSources2.txt del JavaSources2.txt
rd /s /q bin

goto :End

:Error
echo.
echo Sorry, we had a problem :(
echo.

:End

echo Changing back to the folder we started in

popd

endlocal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM