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)
32 extern JNIEnv
*env_ptr
;
33 static jobject RockboxYesno_instance
= NULL
;
34 static jmethodID yesno_func
;
35 static struct semaphore yesno_done
;
38 JNIEXPORT
void JNICALL
39 Java_org_rockbox_RockboxYesno_put_1result(JNIEnv
*env
, jobject
this, jboolean result
)
44 semaphore_release(&yesno_done
);
47 static void yesno_init(void)
50 static jmethodID yesno_is_usable
;
51 if (RockboxYesno_instance
== NULL
)
53 semaphore_init(&yesno_done
, 1, 0);
54 /* get the class and its constructor */
55 jclass yesno_class
= e
->FindClass(env_ptr
,
56 "org/rockbox/RockboxYesno");
57 jmethodID constructor
= e
->GetMethodID(env_ptr
,
60 jobject yesno_instance
= e
->NewObject(env_ptr
,
63 RockboxYesno_instance
= e
->NewGlobalRef(env_ptr
, yesno_instance
);
64 yesno_func
= e
->GetMethodID(env_ptr
, yesno_class
,
68 "Ljava/lang/String;)V");
69 yesno_is_usable
= e
->GetMethodID(env_ptr
, yesno_class
,
72 /* need to get it every time incase the activity died/restarted */
73 while (!e
->CallBooleanMethod(env_ptr
, RockboxYesno_instance
,
78 jstring
build_message(const struct text_message
*message
)
83 for(i
=0; i
<message
->nb_lines
; i
++)
85 char* text
= P2STR((unsigned char *)message
->message_lines
[i
]);
87 strlcat(msg
, "\n", 1024);
88 strlcat(msg
, text
, 1024);
90 /* make sure the questions end in a ?, for some reason they dont! */
91 if (!strrchr(msg
, '?'))
92 strlcat(msg
, "?", 1024);
93 return e
->NewStringUTF(env_ptr
, msg
);
96 enum yesno_res
gui_syncyesno_run(const struct text_message
* main_message
,
97 const struct text_message
* yes_message
,
98 const struct text_message
* no_message
)
105 jstring message
= build_message(main_message
);
106 jstring yes
= (*env_ptr
)->NewStringUTF(env_ptr
, str(LANG_SET_BOOL_YES
));
107 jstring no
= (*env_ptr
)->NewStringUTF(env_ptr
, str(LANG_SET_BOOL_NO
));
109 e
->CallVoidMethod(env_ptr
, RockboxYesno_instance
, yesno_func
,
112 semaphore_wait(&yesno_done
, TIMEOUT_BLOCK
);
114 e
->DeleteLocalRef(env_ptr
, message
);
115 e
->DeleteLocalRef(env_ptr
, yes
);
116 e
->DeleteLocalRef(env_ptr
, no
);
118 return ret
? YESNO_YES
: YESNO_NO
;