mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
app: plumbing for physical android key events
This is only the first half of physical key event mapping. The modifiers and hardware key codes will be in a followup CL. I'm splitting this out because it covers two other parts of the problem: first is maintaining a JNIEnv pointer for the main routine, the second is access to the Android unicode key map. The NDK does not have a method to give us the key mapping, so we get to it via GoNativeActivity. Tested with a USB keyboard. I'll attempt an abd-based unit test later, but I suspect it will be difficult to set a device ID. Change-Id: Ie93700d1f2a5d382a9b17cdd668cb4acaa6e4bcc Reviewed-on: https://go-review.googlesource.com/13649 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyCharacterMap;
|
||||
|
||||
public class GoNativeActivity extends NativeActivity {
|
||||
private static GoNativeActivity goNativeActivity;
|
||||
@@ -20,6 +21,21 @@ public class GoNativeActivity extends NativeActivity {
|
||||
return getCacheDir().getAbsolutePath();
|
||||
}
|
||||
|
||||
int getRune(int deviceId, int keyCode, int metaState) {
|
||||
try {
|
||||
int rune = KeyCharacterMap.load(deviceId).get(keyCode, metaState);
|
||||
if (rune == 0) {
|
||||
return -1;
|
||||
}
|
||||
return rune;
|
||||
} catch (KeyCharacterMap.UnavailableException e) {
|
||||
return -1;
|
||||
} catch (Exception e) {
|
||||
Log.e("Go", "exception reading KeyCharacterMap", e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void load() {
|
||||
// Interestingly, NativeActivity uses a different method
|
||||
// to find native code to execute, avoiding
|
||||
|
||||
Reference in New Issue
Block a user