summaryrefslogtreecommitdiff
path: root/apps/hosted/keyboard.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-11-06 01:01:01 +0000
committerThomas Martitz <kugel@rockbox.org>2010-11-06 01:01:01 +0000
commit988bdc1cc4d4cbe88da848de80d79aeac195464e (patch)
tree123bbcdd00fbe1ed9d43b304ccb13e8346980564 /apps/hosted/keyboard.c
parentbe51be6a9917574db9cf8fe69089cdb44d5b1eb3 (diff)
downloadrockbox-988bdc1cc4d4cbe88da848de80d79aeac195464e.tar.gz
rockbox-988bdc1cc4d4cbe88da848de80d79aeac195464e.zip
Android: Use wakeup objects instead of polling for the dialog results in the keyboard and yesno dialog, allowing a lot of code to be removed.
First part of FS#11708 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28512 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/hosted/keyboard.c')
-rw-r--r--apps/hosted/keyboard.c66
1 files changed, 41 insertions, 25 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
30extern JNIEnv *env_ptr; 29extern JNIEnv *env_ptr;
31static jclass RockboxKeyboardInput_class; 30static jclass RockboxKeyboardInput_class;
32static jobject RockboxKeyboardInput_instance; 31static jobject RockboxKeyboardInput_instance;
33static jmethodID kbd_inputfunc, kbd_result; 32static jmethodID kbd_inputfunc;
33static struct wakeup kbd_wakeup;
34static bool accepted;
35static jstring new_string;
36
37JNIEXPORT void JNICALL
38Java_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
35static void kdb_init(void) 53static 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
87int load_kbd(unsigned char* filename) 103int load_kbd(unsigned char* filename)