/[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 27 - (show annotations) (download)
Mon Apr 9 21:27:36 2012 UTC (11 years, 11 months ago) by zoff99
File MIME type: text/plain
File size: 3881 byte(s)
lots of new stuff, tranlsations, bug fixes ...
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 static int
37 speech_android_say(struct speech_priv *this, const char *text)
38 {
39 char *str=g_strdup(text);
40 jstring string;
41 int i;
42
43 /*
44 if (this->flags & 2)
45 {
46 for (i = 0 ; i < strlen(str) ; i++)
47 {
48 if (str[i] == 0xc3 && str[i+1] == 0x84) {
49 str[i]='A';
50 str[i+1]='e';
51 }
52 if (str[i] == 0xc3 && str[i+1] == 0x96) {
53 str[i]='O';
54 str[i+1]='e';
55 }
56 if (str[i] == 0xc3 && str[i+1] == 0x9c) {
57 str[i]='U';
58 str[i+1]='e';
59 }
60 if (str[i] == 0xc3 && str[i+1] == 0xa4) {
61 str[i]='a';
62 str[i+1]='e';
63 }
64 if (str[i] == 0xc3 && str[i+1] == 0xb6) {
65 str[i]='o';
66 str[i+1]='e';
67 }
68 if (str[i] == 0xc3 && str[i+1] == 0xbc) {
69 str[i]='u';
70 str[i+1]='e';
71 }
72 if (str[i] == 0xc3 && str[i+1] == 0x9f) {
73 str[i]='s';
74 str[i+1]='s';
75 }
76 }
77 }
78 */
79
80 string = (*jnienv)->NewStringUTF(jnienv, str);
81 // dbg(0,"enter %s\n",str);
82 (*jnienv)->CallVoidMethod(jnienv, this->NavitSpeech, this->NavitSpeech_say, string);
83 (*jnienv)->DeleteLocalRef(jnienv, string);
84
85 g_free(str);
86
87 return 1;
88 }
89
90 static void
91 speech_android_destroy(struct speech_priv *this) {
92 g_free(this);
93 }
94
95 static struct speech_methods speech_android_meth = {
96 speech_android_destroy,
97 speech_android_say,
98 };
99
100 static int
101 speech_android_init(struct speech_priv *ret)
102 {
103 dbg(0,"EEnter\n");
104
105 jmethodID cid;
106 char *class="com/zoffcc/applications/zanavi/NavitSpeech2";
107
108 if (ret->flags & 1)
109 {
110 class="com/zoffcc/applications/zanavi/NavitSpeech";
111 }
112
113 if (!android_find_class_global(class, &ret->NavitSpeechClass))
114 {
115 dbg(0,"No class found\n");
116 return 0;
117 }
118
119 dbg(0,"at 3\n");
120 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitSpeechClass, "<init>", "(Lcom/zoffcc/applications/zanavi/Navit;)V");
121 if (cid == NULL)
122 {
123 dbg(0,"no method found\n");
124 return 0; /* exception thrown */
125 }
126 if (!android_find_method(ret->NavitSpeechClass, "say", "(Ljava/lang/String;)V", &ret->NavitSpeech_say))
127 {
128 return 0;
129 }
130 dbg(0,"at 4 android_activity=%p\n",android_activity);
131 ret->NavitSpeech=(*jnienv)->NewObject(jnienv, ret->NavitSpeechClass, cid, android_activity);
132 dbg(0,"result=%p\n",ret->NavitSpeech);
133 if (!ret->NavitSpeech)
134 {
135 return 0;
136 }
137 if (ret->NavitSpeech)
138 {
139 ret->NavitSpeech = (*jnienv)->NewGlobalRef(jnienv, ret->NavitSpeech);
140 }
141 return 1;
142 }
143
144 static struct speech_priv *
145 speech_android_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent)
146 {
147 dbg(0,"EEnter\n");
148 struct speech_priv *this;
149 struct attr *flags;
150 *meth=speech_android_meth;
151 this=g_new0(struct speech_priv,1);
152
153 if (!speech_android_init(this))
154 {
155 g_free(this);
156 this=NULL;
157 }
158 if (android_version < 4)
159 this->flags=3;
160 if ((flags = attr_search(attrs, NULL, attr_flags)))
161 this->flags=flags->u.num;
162
163 return this;
164 }
165
166
167 void
168 plugin_init(void)
169 {
170 plugin_register_speech_type("android", speech_android_new);
171 }

   
Visit the ZANavi Wiki