summaryrefslogtreecommitdiff
path: root/apps/hosted/yesno.c
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2010-10-31 13:12:01 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2010-10-31 13:12:01 +0000
commitb92eabd38b6c06d598e85dcfc6e2244631efa11f (patch)
tree7e234d07b1f0dd9a7a7344400dfa534c46616130 /apps/hosted/yesno.c
parent1e47628a9f5d51218d2e385b7f85e09dd75df860 (diff)
downloadrockbox-b92eabd38b6c06d598e85dcfc6e2244631efa11f.tar.gz
rockbox-b92eabd38b6c06d598e85dcfc6e2244631efa11f.zip
Use a native yes/no dialog instead of rockbox's internal one on android
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28415 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/hosted/yesno.c')
-rw-r--r--apps/hosted/yesno.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/apps/hosted/yesno.c b/apps/hosted/yesno.c
new file mode 100644
index 0000000000..1e05e193f7
--- /dev/null
+++ b/apps/hosted/yesno.c
@@ -0,0 +1,110 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Jonathan Gordon
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22
23#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
24#include <jni.h>
25#include <stdbool.h>
26#include <stdio.h>
27#include <system.h>
28#include "yesno.h"
29#include "settings.h"
30#include "lang.h"
31
32extern JNIEnv *env_ptr;
33static jclass RockboxYesno_class = NULL;
34static jobject RockboxYesno_instance = NULL;
35static jmethodID yesno_func, result_ready, yesno_result;
36
37static void yesno_init(void)
38{
39 JNIEnv e = *env_ptr;
40 jmethodID yesno_is_usable;
41 if (RockboxYesno_class == NULL)
42 {
43 /* get the class and its constructor */
44 RockboxYesno_class = e->FindClass(env_ptr,
45 "org/rockbox/RockboxYesno");
46 jmethodID constructor = e->GetMethodID(env_ptr,
47 RockboxYesno_class,
48 "<init>", "()V");
49 RockboxYesno_instance = e->NewObject(env_ptr,
50 RockboxYesno_class,
51 constructor);
52 yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class,
53 "yesno_display", "(Ljava/lang/String;)V");
54 yesno_result = e->GetMethodID(env_ptr, RockboxYesno_class,
55 "get_result", "()Z");
56 result_ready = e->GetMethodID(env_ptr, RockboxYesno_class,
57 "result_ready", "()Z");
58 }
59 /* need to get it every time incase the activity died/restarted */
60 yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
61 "is_usable", "()Z");
62 while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance,
63 yesno_is_usable))
64 sleep(HZ/10);
65}
66
67jstring build_message(const struct text_message *message)
68{
69 char msg[1024] = "";
70 JNIEnv e = *env_ptr;
71 int i;
72 for(i=0; i<message->nb_lines; i++)
73 {
74 char* text = P2STR((unsigned char *)message->message_lines[i]);
75 if (i>0)
76 strlcat(msg, "\n", 1024);
77 strlcat(msg, text, 1024);
78 }
79 /* make sure the questions end in a ?, for some reason they dont! */
80 if (!strrchr(msg, '?'))
81 strlcat(msg, "?", 1024);
82 return e->NewStringUTF(env_ptr, msg);
83}
84
85enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
86 const struct text_message * yes_message,
87 const struct text_message * no_message)
88{
89 (void)yes_message;
90 (void)no_message;
91 yesno_init();
92
93 JNIEnv e = *env_ptr;
94 jstring message = build_message(main_message);
95 jboolean ret;
96
97 e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message);
98 e->ReleaseStringUTFChars(env_ptr, message, NULL);
99
100
101 do {
102 sleep(HZ/10);
103 ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, result_ready);
104 } while (!ret);
105
106 ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, yesno_result);
107 return ret ? YESNO_YES : YESNO_NO;
108}
109
110#endif