2010-10-31 13:12:01 +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>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "yesno.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "lang.h"
|
2010-11-06 01:01:01 +00:00
|
|
|
#include "kernel.h"
|
2010-10-31 13:12:01 +00:00
|
|
|
|
2011-03-16 14:33:55 +00:00
|
|
|
extern JNIEnv *env_ptr;
|
2010-10-31 13:12:01 +00:00
|
|
|
static jobject RockboxYesno_instance = NULL;
|
2010-11-06 01:01:01 +00:00
|
|
|
static jmethodID yesno_func;
|
2011-03-02 10:13:56 +00:00
|
|
|
static struct semaphore yesno_done;
|
2010-11-06 01:01:01 +00:00
|
|
|
static bool ret;
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_rockbox_RockboxYesno_put_1result(JNIEnv *env, jobject this, jboolean result)
|
|
|
|
{
|
|
|
|
(void)env;
|
|
|
|
(void)this;
|
|
|
|
ret = (bool)result;
|
2011-03-02 10:13:56 +00:00
|
|
|
semaphore_release(&yesno_done);
|
2010-11-06 01:01:01 +00:00
|
|
|
}
|
2010-10-31 13:12:01 +00:00
|
|
|
|
2011-03-16 14:33:55 +00:00
|
|
|
static void yesno_init(void)
|
2010-10-31 13:12:01 +00:00
|
|
|
{
|
|
|
|
JNIEnv e = *env_ptr;
|
2010-11-06 01:01:01 +00:00
|
|
|
static jmethodID yesno_is_usable;
|
2011-03-11 18:34:31 +00:00
|
|
|
if (RockboxYesno_instance == NULL)
|
2010-10-31 13:12:01 +00:00
|
|
|
{
|
2011-03-02 10:13:56 +00:00
|
|
|
semaphore_init(&yesno_done, 1, 0);
|
2010-10-31 13:12:01 +00:00
|
|
|
/* get the class and its constructor */
|
2011-03-11 19:23:00 +00:00
|
|
|
jclass RockboxYesno_class = e->FindClass(env_ptr,
|
|
|
|
"org/rockbox/RockboxYesno");
|
2010-10-31 13:12:01 +00:00
|
|
|
jmethodID constructor = e->GetMethodID(env_ptr,
|
2011-03-11 19:23:00 +00:00
|
|
|
RockboxYesno_class,
|
2010-10-31 13:12:01 +00:00
|
|
|
"<init>", "()V");
|
2011-03-11 19:23:00 +00:00
|
|
|
RockboxYesno_instance = e->NewObject(env_ptr,
|
|
|
|
RockboxYesno_class,
|
|
|
|
constructor);
|
|
|
|
yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class,
|
2010-11-06 01:40:24 +00:00
|
|
|
"yesno_display",
|
|
|
|
"(Ljava/lang/String;"
|
|
|
|
"Ljava/lang/String;"
|
|
|
|
"Ljava/lang/String;)V");
|
2011-03-11 19:23:00 +00:00
|
|
|
yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
|
2010-11-06 01:01:01 +00:00
|
|
|
"is_usable", "()Z");
|
2010-10-31 13:12:01 +00:00
|
|
|
}
|
|
|
|
/* need to get it every time incase the activity died/restarted */
|
|
|
|
while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance,
|
|
|
|
yesno_is_usable))
|
|
|
|
sleep(HZ/10);
|
|
|
|
}
|
|
|
|
|
2011-03-16 14:33:55 +00:00
|
|
|
jstring build_message(const struct text_message *message)
|
2010-10-31 13:12:01 +00:00
|
|
|
{
|
|
|
|
char msg[1024] = "";
|
|
|
|
JNIEnv e = *env_ptr;
|
|
|
|
int i;
|
|
|
|
for(i=0; i<message->nb_lines; i++)
|
|
|
|
{
|
|
|
|
char* text = P2STR((unsigned char *)message->message_lines[i]);
|
|
|
|
if (i>0)
|
|
|
|
strlcat(msg, "\n", 1024);
|
|
|
|
strlcat(msg, text, 1024);
|
|
|
|
}
|
|
|
|
/* make sure the questions end in a ?, for some reason they dont! */
|
|
|
|
if (!strrchr(msg, '?'))
|
|
|
|
strlcat(msg, "?", 1024);
|
|
|
|
return e->NewStringUTF(env_ptr, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
|
|
|
|
const struct text_message * yes_message,
|
|
|
|
const struct text_message * no_message)
|
|
|
|
{
|
|
|
|
(void)yes_message;
|
|
|
|
(void)no_message;
|
2011-03-16 14:33:55 +00:00
|
|
|
yesno_init();
|
|
|
|
|
2010-10-31 13:12:01 +00:00
|
|
|
JNIEnv e = *env_ptr;
|
2011-03-16 14:33:55 +00:00
|
|
|
jstring message = build_message(main_message);
|
2010-11-06 01:40:24 +00:00
|
|
|
jstring yes = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_YES));
|
|
|
|
jstring no = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_NO));
|
|
|
|
|
|
|
|
e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func,
|
|
|
|
message, yes, no);
|
2010-10-31 13:12:01 +00:00
|
|
|
|
2011-03-02 10:13:56 +00:00
|
|
|
semaphore_wait(&yesno_done, TIMEOUT_BLOCK);
|
2010-11-06 01:01:01 +00:00
|
|
|
|
|
|
|
e->DeleteLocalRef(env_ptr, message);
|
2010-11-06 01:40:24 +00:00
|
|
|
e->DeleteLocalRef(env_ptr, yes);
|
|
|
|
e->DeleteLocalRef(env_ptr, no);
|
2010-11-06 01:01:01 +00:00
|
|
|
|
2010-10-31 13:12:01 +00:00
|
|
|
return ret ? YESNO_YES : YESNO_NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|