diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/hosted/keyboard.c | 66 | ||||
-rw-r--r-- | apps/hosted/yesno.c | 37 |
2 files changed, 62 insertions, 41 deletions
diff --git a/apps/hosted/keyboard.c b/apps/hosted/keyboard.c index 2b77825af0..6cc14d654f 100644 --- a/apps/hosted/keyboard.c +++ b/apps/hosted/keyboard.c | |||
@@ -23,21 +23,40 @@ | |||
23 | #if (CONFIG_PLATFORM&PLATFORM_ANDROID) | 23 | #if (CONFIG_PLATFORM&PLATFORM_ANDROID) |
24 | #include <jni.h> | 24 | #include <jni.h> |
25 | #include <stdbool.h> | 25 | #include <stdbool.h> |
26 | #include <stdio.h> | 26 | #include "string-extra.h" |
27 | #include <string.h> | 27 | #include "kernel.h" |
28 | #include <system.h> | ||
29 | 28 | ||
30 | extern JNIEnv *env_ptr; | 29 | extern JNIEnv *env_ptr; |
31 | static jclass RockboxKeyboardInput_class; | 30 | static jclass RockboxKeyboardInput_class; |
32 | static jobject RockboxKeyboardInput_instance; | 31 | static jobject RockboxKeyboardInput_instance; |
33 | static jmethodID kbd_inputfunc, kbd_result; | 32 | static jmethodID kbd_inputfunc; |
33 | static struct wakeup kbd_wakeup; | ||
34 | static bool accepted; | ||
35 | static jstring new_string; | ||
36 | |||
37 | JNIEXPORT void JNICALL | ||
38 | Java_org_rockbox_RockboxKeyboardInput_put_1result(JNIEnv *env, jobject this, | ||
39 | jboolean _accepted, | ||
40 | jstring _new_string) | ||
41 | { | ||
42 | (void)env;(void)this; | ||
43 | |||
44 | accepted = (bool)_accepted; | ||
45 | if (accepted) | ||
46 | { | ||
47 | new_string = _new_string; | ||
48 | (*env)->NewGlobalRef(env, new_string); /* prevet GC'ing */ | ||
49 | } | ||
50 | wakeup_signal(&kbd_wakeup); | ||
51 | } | ||
34 | 52 | ||
35 | static void kdb_init(void) | 53 | static void kdb_init(void) |
36 | { | 54 | { |
37 | JNIEnv e = *env_ptr; | 55 | JNIEnv e = *env_ptr; |
38 | jmethodID kbd_is_usable; | 56 | static jmethodID kbd_is_usable; |
39 | if (RockboxKeyboardInput_class == NULL) | 57 | if (RockboxKeyboardInput_class == NULL) |
40 | { | 58 | { |
59 | wakeup_init(&kbd_wakeup); | ||
41 | /* get the class and its constructor */ | 60 | /* get the class and its constructor */ |
42 | RockboxKeyboardInput_class = e->FindClass(env_ptr, | 61 | RockboxKeyboardInput_class = e->FindClass(env_ptr, |
43 | "org/rockbox/RockboxKeyboardInput"); | 62 | "org/rockbox/RockboxKeyboardInput"); |
@@ -49,12 +68,11 @@ static void kdb_init(void) | |||
49 | constructor); | 68 | constructor); |
50 | kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, | 69 | kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, |
51 | "kbd_input", "(Ljava/lang/String;)V"); | 70 | "kbd_input", "(Ljava/lang/String;)V"); |
52 | kbd_result = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, | 71 | kbd_is_usable = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, |
53 | "get_result", "()Ljava/lang/String;"); | 72 | "is_usable", "()Z"); |
54 | } | 73 | } |
74 | |||
55 | /* need to get it every time incase the activity died/restarted */ | 75 | /* need to get it every time incase the activity died/restarted */ |
56 | kbd_is_usable = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, | ||
57 | "is_usable", "()Z"); | ||
58 | while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance, | 76 | while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance, |
59 | kbd_is_usable)) | 77 | kbd_is_usable)) |
60 | sleep(HZ/10); | 78 | sleep(HZ/10); |
@@ -64,24 +82,22 @@ int kbd_input(char* text, int buflen) | |||
64 | { | 82 | { |
65 | JNIEnv e = *env_ptr; | 83 | JNIEnv e = *env_ptr; |
66 | jstring str = e->NewStringUTF(env_ptr, text); | 84 | jstring str = e->NewStringUTF(env_ptr, text); |
67 | jobject ret; | 85 | const char *utf8_string; |
68 | const char* retchars; | ||
69 | kdb_init(); | 86 | kdb_init(); |
70 | 87 | ||
71 | e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance,kbd_inputfunc,str); | 88 | e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance,kbd_inputfunc,str); |
72 | 89 | ||
73 | do { | 90 | wakeup_wait(&kbd_wakeup, TIMEOUT_BLOCK); |
74 | sleep(HZ/10); | 91 | |
75 | ret = e->CallObjectMethod(env_ptr, RockboxKeyboardInput_instance, | 92 | if (accepted) |
76 | kbd_result); | 93 | { |
77 | } while (!ret); | 94 | utf8_string = e->GetStringUTFChars(env_ptr, new_string, 0); |
78 | 95 | strlcpy(text, utf8_string, buflen); | |
79 | retchars = e->GetStringUTFChars(env_ptr, ret, 0); | 96 | e->ReleaseStringUTFChars(env_ptr, new_string, utf8_string); |
80 | if (retchars[0]) | 97 | e->DeleteGlobalRef(env_ptr, new_string); |
81 | strncpy(text, retchars, buflen); | 98 | } |
82 | e->ReleaseStringUTFChars(env_ptr, ret, retchars); | ||
83 | 99 | ||
84 | return text[0] ? 0 : 1; /* return 0 on success */ | 100 | return !accepted; /* return 0 on success */ |
85 | } | 101 | } |
86 | 102 | ||
87 | int load_kbd(unsigned char* filename) | 103 | int load_kbd(unsigned char* filename) |
diff --git a/apps/hosted/yesno.c b/apps/hosted/yesno.c index 9858e66438..2a8c02edd5 100644 --- a/apps/hosted/yesno.c +++ b/apps/hosted/yesno.c | |||
@@ -24,22 +24,34 @@ | |||
24 | #include <jni.h> | 24 | #include <jni.h> |
25 | #include <stdbool.h> | 25 | #include <stdbool.h> |
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | #include <system.h> | ||
28 | #include "yesno.h" | 27 | #include "yesno.h" |
29 | #include "settings.h" | 28 | #include "settings.h" |
30 | #include "lang.h" | 29 | #include "lang.h" |
30 | #include "kernel.h" | ||
31 | 31 | ||
32 | extern JNIEnv *env_ptr; | 32 | extern JNIEnv *env_ptr; |
33 | static jclass RockboxYesno_class = NULL; | 33 | static jclass RockboxYesno_class = NULL; |
34 | static jobject RockboxYesno_instance = NULL; | 34 | static jobject RockboxYesno_instance = NULL; |
35 | static jmethodID yesno_func, result_ready, yesno_result; | 35 | static jmethodID yesno_func; |
36 | static struct wakeup yesno_wakeup; | ||
37 | static bool ret; | ||
38 | |||
39 | JNIEXPORT void JNICALL | ||
40 | Java_org_rockbox_RockboxYesno_put_1result(JNIEnv *env, jobject this, jboolean result) | ||
41 | { | ||
42 | (void)env; | ||
43 | (void)this; | ||
44 | ret = (bool)result; | ||
45 | wakeup_signal(&yesno_wakeup); | ||
46 | } | ||
36 | 47 | ||
37 | static void yesno_init(void) | 48 | static void yesno_init(void) |
38 | { | 49 | { |
39 | JNIEnv e = *env_ptr; | 50 | JNIEnv e = *env_ptr; |
40 | jmethodID yesno_is_usable; | 51 | static jmethodID yesno_is_usable; |
41 | if (RockboxYesno_class == NULL) | 52 | if (RockboxYesno_class == NULL) |
42 | { | 53 | { |
54 | wakeup_init(&yesno_wakeup); | ||
43 | /* get the class and its constructor */ | 55 | /* get the class and its constructor */ |
44 | RockboxYesno_class = e->FindClass(env_ptr, | 56 | RockboxYesno_class = e->FindClass(env_ptr, |
45 | "org/rockbox/RockboxYesno"); | 57 | "org/rockbox/RockboxYesno"); |
@@ -51,14 +63,10 @@ static void yesno_init(void) | |||
51 | constructor); | 63 | constructor); |
52 | yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class, | 64 | yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class, |
53 | "yesno_display", "(Ljava/lang/String;)V"); | 65 | "yesno_display", "(Ljava/lang/String;)V"); |
54 | yesno_result = e->GetMethodID(env_ptr, RockboxYesno_class, | 66 | yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class, |
55 | "get_result", "()Z"); | 67 | "is_usable", "()Z"); |
56 | result_ready = e->GetMethodID(env_ptr, RockboxYesno_class, | ||
57 | "result_ready", "()Z"); | ||
58 | } | 68 | } |
59 | /* need to get it every time incase the activity died/restarted */ | 69 | /* need to get it every time incase the activity died/restarted */ |
60 | yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class, | ||
61 | "is_usable", "()Z"); | ||
62 | while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance, | 70 | while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance, |
63 | yesno_is_usable)) | 71 | yesno_is_usable)) |
64 | sleep(HZ/10); | 72 | sleep(HZ/10); |
@@ -92,16 +100,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | |||
92 | 100 | ||
93 | JNIEnv e = *env_ptr; | 101 | JNIEnv e = *env_ptr; |
94 | jstring message = build_message(main_message); | 102 | jstring message = build_message(main_message); |
95 | jboolean ret; | ||
96 | 103 | ||
97 | e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message); | 104 | e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message); |
98 | |||
99 | do { | ||
100 | sleep(HZ/10); | ||
101 | ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, result_ready); | ||
102 | } while (!ret); | ||
103 | 105 | ||
104 | ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, yesno_result); | 106 | wakeup_wait(&yesno_wakeup, TIMEOUT_BLOCK); |
107 | |||
108 | e->DeleteLocalRef(env_ptr, message); | ||
109 | |||
105 | return ret ? YESNO_YES : YESNO_NO; | 110 | return ret ? YESNO_YES : YESNO_NO; |
106 | } | 111 | } |
107 | 112 | ||