1 |
/**
|
2 |
* Navit, a modular navigation system.
|
3 |
* Copyright (C) 2005-2008 Navit Team
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
#include <stdlib.h>
|
21 |
#include <glib.h>
|
22 |
#include "config.h"
|
23 |
#include "item.h"
|
24 |
#include "debug.h"
|
25 |
#include "plugin.h"
|
26 |
#include "android.h"
|
27 |
#include "speech.h"
|
28 |
#include "navit.h"
|
29 |
|
30 |
struct speech_priv
|
31 |
{
|
32 |
jclass NavitSpeechClass;
|
33 |
jobject NavitSpeech;
|
34 |
jmethodID NavitSpeech_say;
|
35 |
int flags;
|
36 |
};
|
37 |
|
38 |
|
39 |
jclass NavitClass4 = NULL;
|
40 |
jmethodID Navit_get_speech = NULL;
|
41 |
|
42 |
static int find_static_method(jclass class, char *name, char *args, jmethodID *ret)
|
43 |
{
|
44 |
JNIEnv *jnienv2;
|
45 |
jnienv2 = jni_getenv();
|
46 |
|
47 |
//DBG dbg(0,"EEnter\n");
|
48 |
*ret = (*jnienv2)->GetStaticMethodID(jnienv2, class, name, args);
|
49 |
if (*ret == NULL)
|
50 |
{
|
51 |
//DBG dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
|
52 |
return 0;
|
53 |
}
|
54 |
return 1;
|
55 |
}
|
56 |
|
57 |
static int
|
58 |
speech_android_say(struct speech_priv *this, const char *text)
|
59 |
{
|
60 |
JNIEnv *jnienv2;
|
61 |
jnienv2 = jni_getenv();
|
62 |
|
63 |
char *str=g_strdup(text);
|
64 |
jstring string;
|
65 |
int i;
|
66 |
|
67 |
/*
|
68 |
if (this->flags & 2)
|
69 |
{
|
70 |
for (i = 0 ; i < strlen(str) ; i++)
|
71 |
{
|
72 |
if (str[i] == 0xc3 && str[i+1] == 0x84) {
|
73 |
str[i]='A';
|
74 |
str[i+1]='e';
|
75 |
}
|
76 |
if (str[i] == 0xc3 && str[i+1] == 0x96) {
|
77 |
str[i]='O';
|
78 |
str[i+1]='e';
|
79 |
}
|
80 |
if (str[i] == 0xc3 && str[i+1] == 0x9c) {
|
81 |
str[i]='U';
|
82 |
str[i+1]='e';
|
83 |
}
|
84 |
if (str[i] == 0xc3 && str[i+1] == 0xa4) {
|
85 |
str[i]='a';
|
86 |
str[i+1]='e';
|
87 |
}
|
88 |
if (str[i] == 0xc3 && str[i+1] == 0xb6) {
|
89 |
str[i]='o';
|
90 |
str[i+1]='e';
|
91 |
}
|
92 |
if (str[i] == 0xc3 && str[i+1] == 0xbc) {
|
93 |
str[i]='u';
|
94 |
str[i+1]='e';
|
95 |
}
|
96 |
if (str[i] == 0xc3 && str[i+1] == 0x9f) {
|
97 |
str[i]='s';
|
98 |
str[i+1]='s';
|
99 |
}
|
100 |
}
|
101 |
}
|
102 |
*/
|
103 |
|
104 |
string = (*jnienv2)->NewStringUTF(jnienv2, str);
|
105 |
// dbg(0,"enter %s\n",str);
|
106 |
|
107 |
|
108 |
#ifdef NAVIT_DEBUG_SPEECH_POSITION
|
109 |
(*jnienv2)->CallVoidMethod(jnienv2, this->NavitSpeech, this->NavitSpeech_say, string, (int)(global_last_vehicle_pos_geo.lat * 100000.0f), (int)(global_last_vehicle_pos_geo.lng * 100000.0f));
|
110 |
#else
|
111 |
(*jnienv2)->CallVoidMethod(jnienv2, this->NavitSpeech, this->NavitSpeech_say, string, 0, 0);
|
112 |
#endif
|
113 |
|
114 |
|
115 |
(*jnienv2)->DeleteLocalRef(jnienv2, string);
|
116 |
|
117 |
g_free(str);
|
118 |
|
119 |
return 1;
|
120 |
}
|
121 |
|
122 |
static void
|
123 |
speech_android_destroy(struct speech_priv *this)
|
124 |
{
|
125 |
g_free(this);
|
126 |
}
|
127 |
|
128 |
static struct speech_methods speech_android_meth =
|
129 |
{
|
130 |
speech_android_destroy,
|
131 |
speech_android_say,
|
132 |
};
|
133 |
|
134 |
static int
|
135 |
speech_android_init(struct speech_priv *ret)
|
136 |
{
|
137 |
dbg(0,"EEnter\n");
|
138 |
|
139 |
int thread_id = gettid();
|
140 |
dbg(0, "THREAD ID=%d\n", thread_id);
|
141 |
|
142 |
JNIEnv *jnienv2;
|
143 |
jnienv2 = jni_getenv();
|
144 |
|
145 |
jmethodID cid;
|
146 |
char *class="com/zoffcc/applications/zanavi/NavitSpeech2";
|
147 |
|
148 |
// obsolete ----------
|
149 |
//if (ret->flags & 1)
|
150 |
//{
|
151 |
// class="com/zoffcc/applications/zanavi/NavitSpeech";
|
152 |
//}
|
153 |
// obsolete ----------
|
154 |
|
155 |
if (!android_find_class_global(class, &ret->NavitSpeechClass))
|
156 |
{
|
157 |
dbg(0,"No class found\n");
|
158 |
return 0;
|
159 |
}
|
160 |
|
161 |
if (!android_find_method(ret->NavitSpeechClass, "say", "(Ljava/lang/String;II)V", &ret->NavitSpeech_say))
|
162 |
{
|
163 |
return 0;
|
164 |
}
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
// --------------- Init the new Speech Object here -----------------
|
171 |
// --------------- Init the new Speech Object here -----------------
|
172 |
// --------------- Init the new Speech Object here -----------------
|
173 |
dbg(0,"Init the new Speech Object here\n");
|
174 |
|
175 |
if (NavitClass4 == NULL)
|
176 |
{
|
177 |
if (!android_find_class_global("com/zoffcc/applications/zanavi/Navit", &NavitClass4))
|
178 |
{
|
179 |
NavitClass4 = NULL;
|
180 |
return 0;
|
181 |
}
|
182 |
}
|
183 |
|
184 |
if (!find_static_method(NavitClass4, "get_speech_object", "()Lcom/zoffcc/applications/zanavi/NavitSpeech2;", &Navit_get_speech))
|
185 |
{
|
186 |
return 0;
|
187 |
}
|
188 |
|
189 |
|
190 |
/// --old-- ret->NavitSpeech=(*jnienv2)->NewObject(jnienv2, ret->NavitSpeechClass, cid, android_activity);
|
191 |
|
192 |
/// --new--
|
193 |
ret->NavitSpeech = (*jnienv2)->CallStaticObjectMethod(jnienv2, NavitClass4, Navit_get_speech);
|
194 |
/// --new--
|
195 |
|
196 |
// --------------- Init the new Speech Object here -----------------
|
197 |
// --------------- Init the new Speech Object here -----------------
|
198 |
// --------------- Init the new Speech Object here -----------------
|
199 |
|
200 |
|
201 |
|
202 |
if (!ret->NavitSpeech)
|
203 |
{
|
204 |
return 0;
|
205 |
}
|
206 |
if (ret->NavitSpeech)
|
207 |
{
|
208 |
ret->NavitSpeech = (*jnienv2)->NewGlobalRef(jnienv2, ret->NavitSpeech);
|
209 |
}
|
210 |
return 1;
|
211 |
}
|
212 |
|
213 |
struct speech_priv *
|
214 |
speech_android_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent)
|
215 |
{
|
216 |
dbg(0,"EEnter\n");
|
217 |
struct speech_priv *this;
|
218 |
struct attr *flags;
|
219 |
*meth=speech_android_meth;
|
220 |
this=g_new0(struct speech_priv,1);
|
221 |
|
222 |
if (!speech_android_init(this))
|
223 |
{
|
224 |
g_free(this);
|
225 |
this=NULL;
|
226 |
}
|
227 |
|
228 |
if (android_version < 4)
|
229 |
{
|
230 |
this->flags=3;
|
231 |
}
|
232 |
|
233 |
if ((flags = attr_search(attrs, NULL, attr_flags)))
|
234 |
{
|
235 |
this->flags=flags->u.num;
|
236 |
}
|
237 |
|
238 |
return this;
|
239 |
}
|
240 |
|
241 |
#ifdef PLUGSSS
|
242 |
void
|
243 |
plugin_init(void)
|
244 |
{
|
245 |
plugin_register_speech_type("android", speech_android_new);
|
246 |
}
|
247 |
#endif
|
248 |
|