Permalink
Browse files

Merge pull request #4048 from koying/fixdroidkbd

FIX: [droid] proper unicode with physical keyboard
  • Loading branch information...
2 parents f0dc349 + 22d9a78 commit eb25c19daa709bab375608e887398b07a23f052c @koying koying committed Jan 21, 2014
@@ -23,6 +23,7 @@
#include "XBMCApp.h"
#include "guilib/Key.h"
#include "windowing/WinEvents.h"
+#include "android/jni/KeyCharacterMap.h"
typedef struct {
@@ -165,6 +166,10 @@ bool CAndroidKey::onKeyboardEvent(AInputEvent *event)
int32_t repeat = AKeyEvent_getRepeatCount(event);
int32_t keycode = AKeyEvent_getKeyCode(event);
+ int32_t deviceId = AInputEvent_getDeviceId(event);
+ CJNIKeyCharacterMap map = CJNIKeyCharacterMap::load(deviceId);
+ uint16_t unicode = map.get(keycode, state);
+
// Check if we got some special key
uint16_t sym = XBMCK_UNKNOWN;
for (unsigned int index = 0; index < sizeof(keyMap) / sizeof(KeyMap); index++)
@@ -203,7 +208,7 @@ bool CAndroidKey::onKeyboardEvent(AInputEvent *event)
(state & AMETA_SHIFT_ON) ? "yes" : "no",
(state & AMETA_SYM_ON) ? "yes" : "no");
#endif
- XBMC_Key((uint8_t)keycode, sym, modifiers, false);
+ XBMC_Key((uint8_t)keycode, sym, modifiers, unicode, false);
return true;
case AKEY_EVENT_ACTION_UP:
@@ -214,7 +219,7 @@ bool CAndroidKey::onKeyboardEvent(AInputEvent *event)
(state & AMETA_SHIFT_ON) ? "yes" : "no",
(state & AMETA_SYM_ON) ? "yes" : "no");
#endif
- XBMC_Key((uint8_t)keycode, sym, modifiers, true);
+ XBMC_Key((uint8_t)keycode, sym, modifiers, unicode, true);
return true;
case AKEY_EVENT_ACTION_MULTIPLE:
@@ -241,7 +246,7 @@ bool CAndroidKey::onKeyboardEvent(AInputEvent *event)
return false;
}
-void CAndroidKey::XBMC_Key(uint8_t code, uint16_t key, uint16_t modifiers, bool up)
+void CAndroidKey::XBMC_Key(uint8_t code, uint16_t key, uint16_t modifiers, uint16_t unicode, bool up)
{
XBMC_Event newEvent;
memset(&newEvent, 0, sizeof(newEvent));
@@ -251,7 +256,7 @@ void CAndroidKey::XBMC_Key(uint8_t code, uint16_t key, uint16_t modifiers, bool
newEvent.key.type = type;
newEvent.key.keysym.scancode = code;
newEvent.key.keysym.sym = (XBMCKey)key;
- newEvent.key.keysym.unicode = key;
+ newEvent.key.keysym.unicode = unicode;
newEvent.key.keysym.mod = (XBMCMod)modifiers;
//CXBMCApp::android_printf("XBMC_Key(%u, %u, 0x%04X, %d)", code, key, modifiers, up);
@@ -32,6 +32,6 @@ class CAndroidKey
~CAndroidKey() {};
bool onKeyboardEvent(AInputEvent *event);
- void XBMC_Key(uint8_t code, uint16_t key, uint16_t modifiers, bool up);
+ void XBMC_Key(uint8_t code, uint16_t key, uint16_t modifiers, uint16_t unicode, bool up);
void XBMC_JoyButton(uint8_t id, uint8_t button, bool up);
};
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2013 Team XBMC
+ * http://xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "KeyCharacterMap.h"
+#include "jutils/jutils-details.hpp"
+
+using namespace jni;
+
+CJNIKeyCharacterMap CJNIKeyCharacterMap::load(int deviceId)
+{
+ return (CJNIKeyCharacterMap)call_static_method<jhobject>("android/view/KeyCharacterMap",
+ "load", "(I)Landroid/view/KeyCharacterMap;",
+ deviceId);
+}
+
+int CJNIKeyCharacterMap::get(int keyCode, int metaState)
+{
+ return call_method<int>(m_object,
+ "get", "(II)I",
+ keyCode, metaState);
+}
@@ -0,0 +1,33 @@
+#pragma once
+/*
+ * Copyright (C) 2013 Team XBMC
+ * http://xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "JNIBase.h"
+
+class CJNIURI;
+class CJNIKeyCharacterMap : public CJNIBase
+{
+public:
+ CJNIKeyCharacterMap(const jni::jhobject &object) : CJNIBase(object) {}
+ ~CJNIKeyCharacterMap() {}
+
+ static CJNIKeyCharacterMap load(int deviceId);
+ int get(int keyCode, int metaState);
+};
@@ -49,6 +49,7 @@ SRCS += SurfaceTexture.cpp
SRCS += View.cpp
SRCS += Window.cpp
SRCS += Build.cpp
+SRCS += KeyCharacterMap.cpp
LIB = jni.a

0 comments on commit eb25c19

Please sign in to comment.