fix a mem leak by calling the corect ReleaseString method
[maemo-rb.git] / apps / hosted / keyboard.c
blobbe5c70c8962ec4214f32494388751e37666fb947
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
23 #if (CONFIG_PLATFORM&PLATFORM_ANDROID)
24 #include <jni.h>
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <system.h>
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)
36 JNIEnv e = *env_ptr;
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,
51 "is_usable", "()Z");
52 while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance, kbd_is_usable))
53 sleep(HZ/10);
56 int kbd_input(char* text, int buflen)
58 JNIEnv e = *env_ptr;
59 jstring str = e->NewStringUTF(env_ptr, text);
60 jobject ret;
61 const char* retchars;
62 kdb_init();
64 e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance, kbd_inputfunc, str);
66 do {
67 sleep(HZ/10);
68 ret = e->CallObjectMethod(env_ptr, RockboxKeyboardInput_instance, kbd_result);
69 } while (!ret);
71 e->ReleaseStringUTFChars(env_ptr, str, NULL);
72 retchars = e->GetStringUTFChars(env_ptr, ret, 0);
73 if (retchars[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)
82 (void)filename;
83 return 1;
86 #endif