diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/SOURCES | 4 | ||||
-rw-r--r-- | apps/hosted/keyboard.c | 86 |
2 files changed, 90 insertions, 0 deletions
diff --git a/apps/SOURCES b/apps/SOURCES index ad1003bb0d..cb5e6ef876 100644 --- a/apps/SOURCES +++ b/apps/SOURCES | |||
@@ -116,7 +116,11 @@ player/keyboard.c | |||
116 | #ifdef HAVE_LCD_BITMAP | 116 | #ifdef HAVE_LCD_BITMAP |
117 | recorder/bmp.c | 117 | recorder/bmp.c |
118 | recorder/icons.c | 118 | recorder/icons.c |
119 | #if (CONFIG_PLATFORM&PLATFORM_ANDROID) | ||
120 | hosted/keyboard.c | ||
121 | #else | ||
119 | recorder/keyboard.c | 122 | recorder/keyboard.c |
123 | #endif | ||
120 | recorder/peakmeter.c | 124 | recorder/peakmeter.c |
121 | #if defined(HAVE_ALBUMART) || defined(HAVE_JPEG) | 125 | #if defined(HAVE_ALBUMART) || defined(HAVE_JPEG) |
122 | recorder/resize.c | 126 | recorder/resize.c |
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 | ||