/[zanavi_public1]/navit/navit/speech/android/speech_android.c
ZANavi

Contents of /navit/navit/speech/android/speech_android.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (show annotations) (download)
Wed Aug 22 17:01:27 2012 UTC (11 years, 7 months ago) by zoff99
File MIME type: text/plain
File size: 5086 byte(s)
ZANavi 2.0, lots of changes, everything in its own thread, more performance
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
29 struct speech_priv {
30 jclass NavitSpeechClass;
31 jobject NavitSpeech;
32 jmethodID NavitSpeech_say;
33 int flags;
34 };
35
36
37 jclass NavitClass4 = NULL;
38 jmethodID Navit_get_speech;
39
40 static int find_static_method(jclass class, char *name, char *args, jmethodID *ret)
41 {
42 JNIEnv *jnienv2;
43 jnienv2 = jni_getenv();
44
45 //DBG dbg(0,"EEnter\n");
46 *ret = (*jnienv2)->GetStaticMethodID(jnienv2, class, name, args);
47 if (*ret == NULL)
48 {
49 //DBG dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
50 return 0;
51 }
52 return 1;
53 }
54
55 static int
56 speech_android_say(struct speech_priv *this, const char *text)
57 {
58 JNIEnv *jnienv2;
59 jnienv2 = jni_getenv();
60
61 char *str=g_strdup(text);
62 jstring string;
63 int i;
64
65 /*
66 if (this->flags & 2)
67 {
68 for (i = 0 ; i < strlen(str) ; i++)
69 {
70 if (str[i] == 0xc3 && str[i+1] == 0x84) {
71 str[i]='A';
72 str[i+1]='e';
73 }
74 if (str[i] == 0xc3 && str[i+1] == 0x96) {
75 str[i]='O';
76 str[i+1]='e';
77 }
78 if (str[i] == 0xc3 && str[i+1] == 0x9c) {
79 str[i]='U';
80 str[i+1]='e';
81 }
82 if (str[i] == 0xc3 && str[i+1] == 0xa4) {
83 str[i]='a';
84 str[i+1]='e';
85 }
86 if (str[i] == 0xc3 && str[i+1] == 0xb6) {
87 str[i]='o';
88 str[i+1]='e';
89 }
90 if (str[i] == 0xc3 && str[i+1] == 0xbc) {
91 str[i]='u';
92 str[i+1]='e';
93 }
94 if (str[i] == 0xc3 && str[i+1] == 0x9f) {
95 str[i]='s';
96 str[i+1]='s';
97 }
98 }
99 }
100 */
101
102 string = (*jnienv2)->NewStringUTF(jnienv2, str);
103 // dbg(0,"enter %s\n",str);
104 (*jnienv2)->CallVoidMethod(jnienv2, this->NavitSpeech, this->NavitSpeech_say, string);
105 (*jnienv2)->DeleteLocalRef(jnienv2, string);
106
107 g_free(str);
108
109 return 1;
110 }
111
112 static void
113 speech_android_destroy(struct speech_priv *this)
114 {
115 g_free(this);
116 }
117
118 static struct speech_methods speech_android_meth =
119 {
120 speech_android_destroy,
121 speech_android_say,
122 };
123
124 static int
125 speech_android_init(struct speech_priv *ret)
126 {
127 dbg(0,"EEnter\n");
128
129 int thread_id = gettid();
130 dbg(0, "THREAD ID=%d\n", thread_id);
131
132 JNIEnv *jnienv2;
133 jnienv2 = jni_getenv();
134
135 jmethodID cid;
136 char *class="com/zoffcc/applications/zanavi/NavitSpeech2";
137
138 // obsolete ----------
139 //if (ret->flags & 1)
140 //{
141 // class="com/zoffcc/applications/zanavi/NavitSpeech";
142 //}
143 // obsolete ----------
144
145 if (!android_find_class_global(class, &ret->NavitSpeechClass))
146 {
147 dbg(0,"No class found\n");
148 return 0;
149 }
150
151 if (!android_find_method(ret->NavitSpeechClass, "say", "(Ljava/lang/String;)V", &ret->NavitSpeech_say))
152 {
153 return 0;
154 }
155
156
157
158
159
160 // --------------- Init the new Speech Object here -----------------
161 // --------------- Init the new Speech Object here -----------------
162 // --------------- Init the new Speech Object here -----------------
163 dbg(0,"Init the new Speech Object here\n");
164
165 if (NavitClass4 == NULL)
166 {
167 if (!android_find_class_global("com/zoffcc/applications/zanavi/Navit", &NavitClass4))
168 {
169 NavitClass4 = NULL;
170 return 0;
171 }
172 }
173
174 if (!find_static_method(NavitClass4, "get_speech_object", "()Lcom/zoffcc/applications/zanavi/NavitSpeech2;", &Navit_get_speech))
175 return 0;
176
177
178 /// --old-- ret->NavitSpeech=(*jnienv2)->NewObject(jnienv2, ret->NavitSpeechClass, cid, android_activity);
179
180 /// --new--
181 ret->NavitSpeech = (*jnienv2)->CallStaticObjectMethod(jnienv2, NavitClass4, Navit_get_speech);
182 /// --new--
183
184 // --------------- Init the new Speech Object here -----------------
185 // --------------- Init the new Speech Object here -----------------
186 // --------------- Init the new Speech Object here -----------------
187
188
189
190 if (!ret->NavitSpeech)
191 {
192 return 0;
193 }
194 if (ret->NavitSpeech)
195 {
196 ret->NavitSpeech = (*jnienv2)->NewGlobalRef(jnienv2, ret->NavitSpeech);
197 }
198 return 1;
199 }
200
201 static struct speech_priv *
202 speech_android_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent)
203 {
204 dbg(0,"EEnter\n");
205 struct speech_priv *this;
206 struct attr *flags;
207 *meth=speech_android_meth;
208 this=g_new0(struct speech_priv,1);
209
210 if (!speech_android_init(this))
211 {
212 g_free(this);
213 this=NULL;
214 }
215
216 if (android_version < 4)
217 {
218 this->flags=3;
219 }
220
221 if ((flags = attr_search(attrs, NULL, attr_flags)))
222 {
223 this->flags=flags->u.num;
224 }
225
226 return this;
227 }
228
229
230 void
231 plugin_init(void)
232 {
233 plugin_register_speech_type("android", speech_android_new);
234 }
235

   
Visit the ZANavi Wiki