2010-10-31 10:35:55 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jonathan Gordon
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
|
|
|
|
#include <jni.h>
|
|
|
|
#include <stdbool.h>
|
2010-11-06 01:01:01 +00:00
|
|
|
#include "string-extra.h"
|
|
|
|
#include "kernel.h"
|
2010-11-06 01:40:24 +00:00
|
|
|
#include "lang.h"
|
2010-10-31 10:35:55 +00:00
|
|
|
|
2011-03-16 14:33:55 +00:00
|
|
|
extern JNIEnv *env_ptr;
|
2010-11-06 01:01:01 +00:00
|
|
|
static jclass RockboxKeyboardInput_class;
|
|
|
|
static jobject RockboxKeyboardInput_instance;
|
|
|
|
static jmethodID kbd_inputfunc;
|
2011-03-02 10:13:56 +00:00
|
|
|
static struct semaphore kbd_wakeup;
|
2010-11-06 01:01:01 +00:00
|
|
|
static bool accepted;
|
|
|
|
static jstring new_string;
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_rockbox_RockboxKeyboardInput_put_1result(JNIEnv *env, jobject this,
|
|
|
|
jboolean _accepted,
|
|
|
|
jstring _new_string)
|
|
|
|
{
|
|
|
|
(void)env;(void)this;
|
|
|
|
|
|
|
|
accepted = (bool)_accepted;
|
|
|
|
if (accepted)
|
|
|
|
{
|
|
|
|
new_string = _new_string;
|
|
|
|
(*env)->NewGlobalRef(env, new_string); /* prevet GC'ing */
|
|
|
|
}
|
2011-03-02 10:13:56 +00:00
|
|
|
semaphore_release(&kbd_wakeup);
|
2010-11-06 01:01:01 +00:00
|
|
|
}
|
2010-10-31 10:35:55 +00:00
|
|
|
|
|
|
|
static void kdb_init(void)
|
|
|
|
{
|
|
|
|
JNIEnv e = *env_ptr;
|
2010-11-06 01:01:01 +00:00
|
|
|
static jmethodID kbd_is_usable;
|
2010-10-31 10:35:55 +00:00
|
|
|
if (RockboxKeyboardInput_class == NULL)
|
|
|
|
{
|
2011-03-02 10:13:56 +00:00
|
|
|
semaphore_init(&kbd_wakeup, 1, 0);
|
2010-10-31 10:35:55 +00:00
|
|
|
/* get the class and its constructor */
|
2011-03-11 19:23:00 +00:00
|
|
|
RockboxKeyboardInput_class = e->FindClass(env_ptr,
|
2010-10-31 12:00:03 +00:00
|
|
|
"org/rockbox/RockboxKeyboardInput");
|
|
|
|
jmethodID constructor = e->GetMethodID(env_ptr,
|
|
|
|
RockboxKeyboardInput_class,
|
|
|
|
"<init>", "()V");
|
2011-03-11 19:23:00 +00:00
|
|
|
RockboxKeyboardInput_instance = e->NewObject(env_ptr,
|
|
|
|
RockboxKeyboardInput_class,
|
|
|
|
constructor);
|
2010-10-31 10:35:55 +00:00
|
|
|
kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
2010-11-06 01:40:24 +00:00
|
|
|
"kbd_input",
|
|
|
|
"(Ljava/lang/String;"
|
|
|
|
"Ljava/lang/String;"
|
|
|
|
"Ljava/lang/String;)V");
|
2010-11-06 01:01:01 +00:00
|
|
|
kbd_is_usable = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
|
|
|
"is_usable", "()Z");
|
2010-10-31 10:35:55 +00:00
|
|
|
}
|
2010-11-06 01:01:01 +00:00
|
|
|
|
2010-10-31 10:35:55 +00:00
|
|
|
/* need to get it every time incase the activity died/restarted */
|
2010-10-31 12:00:03 +00:00
|
|
|
while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance,
|
|
|
|
kbd_is_usable))
|
2010-10-31 10:35:55 +00:00
|
|
|
sleep(HZ/10);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kbd_input(char* text, int buflen)
|
|
|
|
{
|
2010-11-06 01:40:24 +00:00
|
|
|
JNIEnv e = *env_ptr;
|
|
|
|
jstring str = e->NewStringUTF(env_ptr, text);
|
|
|
|
jstring ok_text = e->NewStringUTF(env_ptr, str(LANG_KBD_OK));
|
|
|
|
jstring cancel_text = e->NewStringUTF(env_ptr, str(LANG_KBD_CANCEL));
|
2010-11-06 01:01:01 +00:00
|
|
|
const char *utf8_string;
|
2010-10-31 10:35:55 +00:00
|
|
|
kdb_init();
|
|
|
|
|
2010-11-06 01:40:24 +00:00
|
|
|
e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance,kbd_inputfunc,
|
|
|
|
str, ok_text, cancel_text);
|
2010-10-31 10:35:55 +00:00
|
|
|
|
2011-03-02 10:13:56 +00:00
|
|
|
semaphore_wait(&kbd_wakeup, TIMEOUT_BLOCK);
|
2010-11-06 01:01:01 +00:00
|
|
|
|
|
|
|
if (accepted)
|
|
|
|
{
|
|
|
|
utf8_string = e->GetStringUTFChars(env_ptr, new_string, 0);
|
|
|
|
strlcpy(text, utf8_string, buflen);
|
|
|
|
e->ReleaseStringUTFChars(env_ptr, new_string, utf8_string);
|
|
|
|
e->DeleteGlobalRef(env_ptr, new_string);
|
|
|
|
}
|
2010-11-06 01:45:21 +00:00
|
|
|
e->DeleteLocalRef(env_ptr, str);
|
|
|
|
e->DeleteLocalRef(env_ptr, ok_text);
|
|
|
|
e->DeleteLocalRef(env_ptr, cancel_text);
|
2010-10-31 10:35:55 +00:00
|
|
|
|
2010-11-06 01:01:01 +00:00
|
|
|
return !accepted; /* return 0 on success */
|
2010-10-31 10:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int load_kbd(unsigned char* filename)
|
|
|
|
{
|
|
|
|
(void)filename;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|