summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/AndroidManifest.xml3
-rw-r--r--android/res/values/strings.xml2
-rw-r--r--android/src/org/rockbox/KeyboardActivity.java1
-rw-r--r--android/src/org/rockbox/RockboxYesno.java73
-rw-r--r--android/src/org/rockbox/YesnoActivity.java37
-rw-r--r--apps/SOURCES4
-rw-r--r--apps/hosted/yesno.c110
7 files changed, 229 insertions, 1 deletions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index c52cac2753..c52d83fd2c 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -17,7 +17,8 @@
17 </activity> 17 </activity>
18 <service android:name=".RockboxService"/> 18 <service android:name=".RockboxService"/>
19 19
20 <activity android:name="KeyboardActivity" android:launchMode="singleTop"></activity> 20 <activity android:name="KeyboardActivity"></activity>
21 <activity android:name="YesnoActivity"></activity>
21</application> 22</application>
22<uses-sdk android:minSdkVersion="4" /> 23<uses-sdk android:minSdkVersion="4" />
23<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 24<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml
index b0d41f133d..a2762ddd74 100644
--- a/android/res/values/strings.xml
+++ b/android/res/values/strings.xml
@@ -6,4 +6,6 @@
6<string name="OK">OK</string> 6<string name="OK">OK</string>
7<string name="Cancel">Cancel</string> 7<string name="Cancel">Cancel</string>
8<string name="KbdInputTitle">Rockbox Keyboard Input</string> 8<string name="KbdInputTitle">Rockbox Keyboard Input</string>
9<string name="Yes">Yes</string>
10<string name="No">No</string>
9</resources> 11</resources>
diff --git a/android/src/org/rockbox/KeyboardActivity.java b/android/src/org/rockbox/KeyboardActivity.java
index c77f686780..7436031f9d 100644
--- a/android/src/org/rockbox/KeyboardActivity.java
+++ b/android/src/org/rockbox/KeyboardActivity.java
@@ -23,6 +23,7 @@ public class KeyboardActivity extends Activity
23 .setTitle(R.string.KbdInputTitle) 23 .setTitle(R.string.KbdInputTitle)
24 .setView(addView) 24 .setView(addView)
25 .setIcon(R.drawable.icon) 25 .setIcon(R.drawable.icon)
26 .setCancelable(false)
26 .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() 27 .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener()
27 { 28 {
28 public void onClick(DialogInterface dialog, int whichButton) { 29 public void onClick(DialogInterface dialog, int whichButton) {
diff --git a/android/src/org/rockbox/RockboxYesno.java b/android/src/org/rockbox/RockboxYesno.java
new file mode 100644
index 0000000000..fd43fc6ab4
--- /dev/null
+++ b/android/src/org/rockbox/RockboxYesno.java
@@ -0,0 +1,73 @@
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
22package org.rockbox;
23
24import android.app.Activity;
25import android.content.Intent;
26import android.util.Log;
27
28public class RockboxYesno
29{
30 private boolean result;
31 private boolean have_result;
32
33 public RockboxYesno()
34 {
35 have_result = false;
36 }
37
38 public void yesno_display(String text)
39 {
40 RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity();
41 Intent kbd = new Intent(a, YesnoActivity.class);
42 kbd.putExtra("value", text);
43 a.waitForActivity(kbd, new HostCallback()
44 {
45 public void onComplete(int resultCode, Intent data)
46 {
47 if (resultCode == Activity.RESULT_OK)
48 {
49 result = true;
50 have_result = true;
51 }
52 else {
53 result = false;
54 have_result = true;
55 }
56 }
57 });
58 }
59
60 public boolean result_ready()
61 {
62 return have_result;
63 }
64 public boolean get_result()
65 {
66 return result;
67 }
68
69 public boolean is_usable()
70 {
71 return RockboxService.get_instance().get_activity() != null;
72 }
73}
diff --git a/android/src/org/rockbox/YesnoActivity.java b/android/src/org/rockbox/YesnoActivity.java
new file mode 100644
index 0000000000..5a67ec5ff7
--- /dev/null
+++ b/android/src/org/rockbox/YesnoActivity.java
@@ -0,0 +1,37 @@
1package org.rockbox;
2
3import android.app.Activity;
4import android.app.AlertDialog;
5import android.content.DialogInterface;
6import android.os.Bundle;
7import android.util.Log;
8
9public class YesnoActivity extends Activity
10{
11 public void onCreate(Bundle savedInstanceState)
12 {
13 super.onCreate(savedInstanceState);
14 new AlertDialog.Builder(this)
15 .setTitle(R.string.KbdInputTitle)
16 .setIcon(R.drawable.icon)
17 .setCancelable(false)
18 .setMessage(getIntent().getStringExtra("value"))
19 .setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener()
20 {
21 public void onClick(DialogInterface dialog, int whichButton) {
22 setResult(RESULT_OK, getIntent());
23 finish();
24 }
25 })
26
27 .setNegativeButton(R.string.No, new DialogInterface.OnClickListener()
28 {
29 public void onClick(DialogInterface dialog, int whichButton)
30 {
31 setResult(RESULT_CANCELED, getIntent());
32 finish();
33 }
34 })
35 .show();
36 }
37}
diff --git a/apps/SOURCES b/apps/SOURCES
index cb5e6ef876..c3020ecb2f 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -89,7 +89,11 @@ gui/statusbar.c
89#ifdef HAVE_LCD_BITMAP 89#ifdef HAVE_LCD_BITMAP
90gui/statusbar-skinned.c 90gui/statusbar-skinned.c
91#endif 91#endif
92#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
93hosted/yesno.c
94#else
92gui/yesno.c 95gui/yesno.c
96#endif
93gui/viewport.c 97gui/viewport.c
94 98
95gui/skin_engine/skin_backdrops.c 99gui/skin_engine/skin_backdrops.c
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