summaryrefslogtreecommitdiff
path: root/apps
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
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')
-rw-r--r--apps/hosted/keyboard.c66
-rw-r--r--apps/hosted/yesno.c37
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
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)
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
32extern JNIEnv *env_ptr; 32extern JNIEnv *env_ptr;
33static jclass RockboxYesno_class = NULL; 33static jclass RockboxYesno_class = NULL;
34static jobject RockboxYesno_instance = NULL; 34static jobject RockboxYesno_instance = NULL;
35static jmethodID yesno_func, result_ready, yesno_result; 35static jmethodID yesno_func;
36static struct wakeup yesno_wakeup;
37static bool ret;
38
39JNIEXPORT void JNICALL
40Java_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
37static void yesno_init(void) 48static 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