diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-10-31 10:35:55 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-10-31 10:35:55 +0000 |
commit | eaff333bf526225cfca84cd686fe5332b852e506 (patch) | |
tree | 98fda966dfe1091295928cfa0f660e4ce9bc7f6b /apps/hosted | |
parent | 26f7ee13ce024b21c83cf68ca7fd27306a0bf5be (diff) | |
download | rockbox-eaff333bf526225cfca84cd686fe5332b852e506.tar.gz rockbox-eaff333bf526225cfca84cd686fe5332b852e506.zip |
Use a Native keyboard GUI instead of rockbox's internal one on android
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28407 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/hosted')
-rw-r--r-- | apps/hosted/keyboard.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/apps/hosted/keyboard.c b/apps/hosted/keyboard.c new file mode 100644 index 0000000000..b395168156 --- /dev/null +++ b/apps/hosted/keyboard.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | |||
23 | #if (CONFIG_PLATFORM&PLATFORM_ANDROID) | ||
24 | #include <jni.h> | ||
25 | #include <stdbool.h> | ||
26 | #include <stdio.h> | ||
27 | #include <system.h> | ||
28 | |||
29 | extern JNIEnv *env_ptr; | ||
30 | static jclass RockboxKeyboardInput_class = NULL; | ||
31 | static jobject RockboxKeyboardInput_instance; | ||
32 | static jmethodID kbd_inputfunc, kbd_result; | ||
33 | |||
34 | static void kdb_init(void) | ||
35 | { | ||
36 | JNIEnv e = *env_ptr; | ||
37 | jmethodID kbd_is_usable; | ||
38 | if (RockboxKeyboardInput_class == NULL) | ||
39 | { | ||
40 | /* get the class and its constructor */ | ||
41 | RockboxKeyboardInput_class = e->FindClass(env_ptr, "org/rockbox/RockboxKeyboardInput"); | ||
42 | jmethodID constructor = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, "<init>", "()V"); | ||
43 | RockboxKeyboardInput_instance = e->NewObject(env_ptr, RockboxKeyboardInput_class, constructor); | ||
44 | kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, | ||
45 | "kbd_input", "(Ljava/lang/String;)V"); | ||
46 | kbd_result = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, | ||
47 | "get_result", "()Ljava/lang/String;"); | ||
48 | } | ||
49 | /* need to get it every time incase the activity died/restarted */ | ||
50 | kbd_is_usable = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, | ||
51 | "is_usable", "()Z"); | ||
52 | while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance, kbd_is_usable)) | ||
53 | sleep(HZ/10); | ||
54 | } | ||
55 | |||
56 | int kbd_input(char* text, int buflen) | ||
57 | { | ||
58 | JNIEnv e = *env_ptr; | ||
59 | jstring str = e->NewStringUTF(env_ptr, text); | ||
60 | jobject ret; | ||
61 | const char* retchars; | ||
62 | kdb_init(); | ||
63 | |||
64 | e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance, kbd_inputfunc, str); | ||
65 | |||
66 | do { | ||
67 | sleep(HZ/10); | ||
68 | ret = e->CallObjectMethod(env_ptr, RockboxKeyboardInput_instance, kbd_result); | ||
69 | } while (!ret); | ||
70 | |||
71 | e->ReleaseStringChars(env_ptr, str, NULL); | ||
72 | retchars = e->GetStringUTFChars(env_ptr, ret, 0); | ||
73 | if (retchars[0]) | ||
74 | snprintf(text, buflen, retchars); | ||
75 | e->ReleaseStringUTFChars(env_ptr, ret, retchars); | ||
76 | |||
77 | return retchars[0]?0:1; /* return 0 on success */ | ||
78 | } | ||
79 | |||
80 | int load_kbd(unsigned char* filename) | ||
81 | { | ||
82 | (void)filename; | ||
83 | return 1; | ||
84 | } | ||
85 | |||
86 | #endif | ||