1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Jonathan Gordon
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #if (CONFIG_PLATFORM&PLATFORM_ANDROID)
26 #include "string-extra.h"
30 extern JNIEnv
*env_ptr
;
31 static jclass RockboxKeyboardInput_class
;
32 static jobject RockboxKeyboardInput_instance
;
33 static jmethodID kbd_inputfunc
;
34 static struct wakeup kbd_wakeup
;
36 static jstring new_string
;
38 JNIEXPORT
void JNICALL
39 Java_org_rockbox_RockboxKeyboardInput_put_1result(JNIEnv
*env
, jobject
this,
45 accepted
= (bool)_accepted
;
48 new_string
= _new_string
;
49 (*env
)->NewGlobalRef(env
, new_string
); /* prevet GC'ing */
51 wakeup_signal(&kbd_wakeup
);
54 static void kdb_init(void)
57 static jmethodID kbd_is_usable
;
58 if (RockboxKeyboardInput_class
== NULL
)
60 wakeup_init(&kbd_wakeup
);
61 /* get the class and its constructor */
62 RockboxKeyboardInput_class
= e
->FindClass(env_ptr
,
63 "org/rockbox/RockboxKeyboardInput");
64 jmethodID constructor
= e
->GetMethodID(env_ptr
,
65 RockboxKeyboardInput_class
,
67 RockboxKeyboardInput_instance
= e
->NewObject(env_ptr
,
68 RockboxKeyboardInput_class
,
70 kbd_inputfunc
= e
->GetMethodID(env_ptr
, RockboxKeyboardInput_class
,
74 "Ljava/lang/String;)V");
75 kbd_is_usable
= e
->GetMethodID(env_ptr
, RockboxKeyboardInput_class
,
79 /* need to get it every time incase the activity died/restarted */
80 while (!e
->CallBooleanMethod(env_ptr
, RockboxKeyboardInput_instance
,
85 int kbd_input(char* text
, int buflen
)
88 jstring str
= e
->NewStringUTF(env_ptr
, text
);
89 jstring ok_text
= e
->NewStringUTF(env_ptr
, str(LANG_KBD_OK
));
90 jstring cancel_text
= e
->NewStringUTF(env_ptr
, str(LANG_KBD_CANCEL
));
91 const char *utf8_string
;
94 e
->CallVoidMethod(env_ptr
, RockboxKeyboardInput_instance
,kbd_inputfunc
,
95 str
, ok_text
, cancel_text
);
97 wakeup_wait(&kbd_wakeup
, TIMEOUT_BLOCK
);
101 utf8_string
= e
->GetStringUTFChars(env_ptr
, new_string
, 0);
102 strlcpy(text
, utf8_string
, buflen
);
103 e
->ReleaseStringUTFChars(env_ptr
, new_string
, utf8_string
);
104 e
->DeleteGlobalRef(env_ptr
, new_string
);
106 e
->DeleteLocalRef(env_ptr
, str
);
107 e
->DeleteLocalRef(env_ptr
, ok_text
);
108 e
->DeleteLocalRef(env_ptr
, cancel_text
);
110 return !accepted
; /* return 0 on success */
113 int load_kbd(unsigned char* filename
)