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)
29 extern JNIEnv
*env_ptr
;
30 static jclass RockboxKeyboardInput_class
= NULL
;
31 static jobject RockboxKeyboardInput_instance
;
32 static jmethodID kbd_inputfunc
, kbd_result
;
34 static void kdb_init(void)
37 jmethodID kbd_is_usable
;
38 if (RockboxKeyboardInput_class
== NULL
)
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;");
49 /* need to get it every time incase the activity died/restarted */
50 kbd_is_usable
= e
->GetMethodID(env_ptr
, RockboxKeyboardInput_class
,
52 while (!e
->CallBooleanMethod(env_ptr
, RockboxKeyboardInput_instance
, kbd_is_usable
))
56 int kbd_input(char* text
, int buflen
)
59 jstring str
= e
->NewStringUTF(env_ptr
, text
);
64 e
->CallVoidMethod(env_ptr
, RockboxKeyboardInput_instance
, kbd_inputfunc
, str
);
68 ret
= e
->CallObjectMethod(env_ptr
, RockboxKeyboardInput_instance
, kbd_result
);
71 e
->ReleaseStringUTFChars(env_ptr
, str
, NULL
);
72 retchars
= e
->GetStringUTFChars(env_ptr
, ret
, 0);
74 snprintf(text
, buflen
, retchars
);
75 e
->ReleaseStringUTFChars(env_ptr
, ret
, retchars
);
77 return retchars
[0]?0:1; /* return 0 on success */
80 int load_kbd(unsigned char* filename
)