1 | package org.tipple.mapDisplay;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.net.URL;
|
---|
5 | import java.text.DecimalFormat;
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.HashMap;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import javax.xml.parsers.SAXParser;
|
---|
11 | import javax.xml.parsers.SAXParserFactory;
|
---|
12 |
|
---|
13 | import org.mapsforge.android.maps.ArrayItemizedMarkerOverlay;
|
---|
14 | import org.mapsforge.android.maps.ArrayItemizedTextAudioOverlay;
|
---|
15 | import org.mapsforge.android.maps.CirclesOverlay;
|
---|
16 | import org.mapsforge.android.maps.GeoPoint;
|
---|
17 | import org.mapsforge.android.maps.MapView;
|
---|
18 | import org.mapsforge.android.maps.Overlay;
|
---|
19 | import org.mapsforge.android.maps.OverlayItem;
|
---|
20 | import org.mapsforge.android.maps.OverlayMarkerItem;
|
---|
21 | import org.mapsforge.android.maps.OverlayTextAudioItem;
|
---|
22 | import org.mapsforge.android.maps.RouteOverlayResetable;
|
---|
23 | import org.xml.sax.InputSource;
|
---|
24 | import org.xml.sax.XMLReader;
|
---|
25 |
|
---|
26 | import android.app.Activity;
|
---|
27 | import android.graphics.Color;
|
---|
28 | import android.graphics.DashPathEffect;
|
---|
29 | import android.graphics.Paint;
|
---|
30 | import android.graphics.drawable.Drawable;
|
---|
31 | import android.location.Location;
|
---|
32 | import android.location.LocationManager;
|
---|
33 | import android.speech.tts.TextToSpeech;
|
---|
34 | import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
|
---|
35 | import android.util.Log;
|
---|
36 | import android.widget.Button;
|
---|
37 | import android.widget.TextView;
|
---|
38 | import android.widget.Toast;
|
---|
39 |
|
---|
40 | public class TippleLocationManagerVersion2 {
|
---|
41 | protected LocationManager locationManager;
|
---|
42 | protected static MapView mapview;
|
---|
43 | protected ArrayList<tippleLocation> locations;
|
---|
44 | protected Button retrieveLocationButton;
|
---|
45 | protected double currentLongitude;
|
---|
46 | protected double currentLatitude;
|
---|
47 | protected double currentNodeId;
|
---|
48 | protected String nodeId;
|
---|
49 | protected Boolean bookSelected = true;
|
---|
50 |
|
---|
51 | public static String hamiltonGardenURL = "HASH4e454a5d938158a2a3fcde";
|
---|
52 | public static String stationOfCrossURL = "HASH0158acd736565602cd1f1b1b";
|
---|
53 | Activity activity_;
|
---|
54 | AudioPlayerView audio_player_view_;
|
---|
55 | TextToSpeech tts_;
|
---|
56 | TextView textview;
|
---|
57 | protected tippleActivity.bookModeEnum current_book_mode_;
|
---|
58 |
|
---|
59 | public static CirclesOverlay circlesOverlay = null;
|
---|
60 | public static ArrayItemizedMarkerOverlay itemizedMarkerOverlay;
|
---|
61 | public static ArrayList<OverlayItem> itemizedMarkerOverlayArrayList;
|
---|
62 | public static ArrayList<GeoPoint> circlesOverlayGeoPoints;
|
---|
63 | public static ArrayList<Integer> circlesOverlayRadii;
|
---|
64 |
|
---|
65 | public static RouteOverlayResetable routeOverlay = null;
|
---|
66 | public static RouteOverlayResetable routeOverlay2 = null;
|
---|
67 | public static ArrayItemizedTextAudioOverlay routeMarkerOverlay;
|
---|
68 | public static GeoPoint[] routeOverlayArray;
|
---|
69 | public static ArrayList<String> nodeIDArray;
|
---|
70 | public static GeoPoint[] routeOverlayArray2;
|
---|
71 | public static int lengthOfFirstBook = 0;
|
---|
72 | public static int lengthOfSecondBook = 0;
|
---|
73 |
|
---|
74 | // paint color for route
|
---|
75 | Paint fillPaint, fillPaint2, outlinePaint, outlinePaint2;
|
---|
76 |
|
---|
77 | public static ArrayList<OverlayItem> routeMarkerOverlayArrayList;
|
---|
78 | public static HashMap<Integer, OverlayMarkerItem> highlight_marker_hash_;
|
---|
79 | public static String prevVisitedFilename;
|
---|
80 | Drawable defaultMarker;// declare as global variable
|
---|
81 |
|
---|
82 | ArrayList<tippleLocation> preLocations = null;
|
---|
83 | ArrayList<tippleLocation> temLocations = null;
|
---|
84 | Location thislocation;
|
---|
85 |
|
---|
86 | TippleLocationManagerVersion2(Activity activity, MapView mapview,
|
---|
87 | TextView textview, LocationManager manager,
|
---|
88 | AudioPlayerView audio_player_view, TextToSpeech tts) {
|
---|
89 | activity_ = activity;
|
---|
90 | audio_player_view_ = audio_player_view;
|
---|
91 | tts_ = tts;
|
---|
92 | this.locationManager = manager;
|
---|
93 | this.mapview = mapview;
|
---|
94 | this.textview = textview;
|
---|
95 |
|
---|
96 | Paint circleFillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
97 | circleFillPaint.setStyle(Paint.Style.FILL);
|
---|
98 | circleFillPaint.setColor(Color.BLUE);
|
---|
99 | circleFillPaint.setAlpha(64);
|
---|
100 |
|
---|
101 | Paint circleOutlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
102 | circleOutlinePaint.setStyle(Paint.Style.STROKE);
|
---|
103 | circleOutlinePaint.setColor(Color.BLUE);
|
---|
104 | circleOutlinePaint.setAlpha(64);
|
---|
105 | circleOutlinePaint.setStrokeWidth(1);
|
---|
106 | circlesOverlay = new CirclesOverlay(circleFillPaint, circleOutlinePaint);
|
---|
107 | circlesOverlayGeoPoints = new ArrayList<GeoPoint>();
|
---|
108 | circlesOverlayRadii = new ArrayList<Integer>();
|
---|
109 | defaultMarker = activity_.getResources().getDrawable(R.drawable.marker);
|
---|
110 | itemizedMarkerOverlay = new ArrayItemizedMarkerOverlay(defaultMarker,
|
---|
111 | activity_);
|
---|
112 | itemizedMarkerOverlayArrayList = new ArrayList<OverlayItem>();
|
---|
113 | highlight_marker_hash_ = new HashMap<Integer, OverlayMarkerItem>();
|
---|
114 | fillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
115 | // deal with routeoverlay
|
---|
116 | fillPaint.setStyle(Paint.Style.STROKE);
|
---|
117 | fillPaint.setColor(Color.BLUE);
|
---|
118 | fillPaint.setAlpha(160);
|
---|
119 | fillPaint.setStrokeWidth(7);
|
---|
120 | fillPaint.setStrokeCap(Paint.Cap.BUTT);
|
---|
121 | fillPaint.setStrokeJoin(Paint.Join.ROUND);
|
---|
122 | fillPaint.setPathEffect(new DashPathEffect(new float[] { 20, 20 }, 0));
|
---|
123 |
|
---|
124 | outlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
125 | outlinePaint.setStyle(Paint.Style.STROKE);
|
---|
126 | outlinePaint.setColor(Color.BLUE);
|
---|
127 | outlinePaint.setAlpha(96);
|
---|
128 | outlinePaint.setStrokeWidth(7);
|
---|
129 | outlinePaint.setStrokeCap(Paint.Cap.BUTT);
|
---|
130 | outlinePaint.setStrokeJoin(Paint.Join.ROUND);
|
---|
131 | fillPaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
132 | // deal with routeoverlay
|
---|
133 | fillPaint2.setStyle(Paint.Style.STROKE);
|
---|
134 | fillPaint2.setColor(Color.RED);
|
---|
135 | fillPaint2.setAlpha(160);
|
---|
136 | fillPaint2.setStrokeWidth(7);
|
---|
137 | fillPaint2.setStrokeCap(Paint.Cap.BUTT);
|
---|
138 | fillPaint2.setStrokeJoin(Paint.Join.ROUND);
|
---|
139 | fillPaint2.setPathEffect(new DashPathEffect(new float[] { 20, 20 }, 0));
|
---|
140 |
|
---|
141 | outlinePaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
142 | outlinePaint2.setStyle(Paint.Style.STROKE);
|
---|
143 | outlinePaint2.setColor(Color.BLUE);
|
---|
144 | outlinePaint2.setAlpha(96);
|
---|
145 | outlinePaint2.setStrokeWidth(7);
|
---|
146 | outlinePaint2.setStrokeCap(Paint.Cap.BUTT);
|
---|
147 | outlinePaint2.setStrokeJoin(Paint.Join.ROUND);
|
---|
148 |
|
---|
149 | routeOverlay = new RouteOverlayResetable(fillPaint, outlinePaint);
|
---|
150 | routeOverlay2 = new RouteOverlayResetable(fillPaint2, outlinePaint2);
|
---|
151 |
|
---|
152 | }
|
---|
153 |
|
---|
154 | protected String getCurrentLocation() {
|
---|
155 | String myCurrentLongitude = null;
|
---|
156 | thislocation = locationListener.lastKnownLocation;
|
---|
157 | if (thislocation != null) {
|
---|
158 | currentLongitude = thislocation.getLongitude();
|
---|
159 | currentLatitude = thislocation.getLatitude();
|
---|
160 | String[] result = (String.valueOf(currentLatitude)).split("\\.");
|
---|
161 | myCurrentLongitude = result[0].substring(1, 3);// image start
|
---|
162 | DecimalFormat trunPlaces = new DecimalFormat("0.0000");
|
---|
163 | String text_mess = "(Long,Lat): ("
|
---|
164 | + trunPlaces.format(currentLongitude) + ","
|
---|
165 | + trunPlaces.format(currentLatitude) + ")";
|
---|
166 | textview.setText(text_mess);
|
---|
167 |
|
---|
168 | } else {
|
---|
169 | Toast.makeText(activity_, "failed to get GPS", Toast.LENGTH_LONG)
|
---|
170 | .show();
|
---|
171 |
|
---|
172 | }
|
---|
173 | return myCurrentLongitude;
|
---|
174 | }
|
---|
175 |
|
---|
176 | // protected void createLogRouteLocationsOverlay(MapView mapView,
|
---|
177 | // ArrayList<tippleLocation> locations) {
|
---|
178 | // Paint fillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
179 | // fillPaint.setStyle(Paint.Style.STROKE);
|
---|
180 | // fillPaint.setColor(Color.BLUE);
|
---|
181 | // fillPaint.setAlpha(160);
|
---|
182 | // fillPaint.setStrokeWidth(7);
|
---|
183 | // fillPaint.setStrokeCap(Paint.Cap.BUTT);
|
---|
184 | // fillPaint.setStrokeJoin(Paint.Join.ROUND);
|
---|
185 | // fillPaint.setPathEffect(new DashPathEffect(new float[] { 20, 20 }, 0));
|
---|
186 | //
|
---|
187 | // Paint outlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
---|
188 | // outlinePaint.setStyle(Paint.Style.STROKE);
|
---|
189 | // outlinePaint.setColor(Color.BLUE);
|
---|
190 | // outlinePaint.setAlpha(96);
|
---|
191 | // outlinePaint.setStrokeWidth(7);
|
---|
192 | // outlinePaint.setStrokeCap(Paint.Cap.BUTT);
|
---|
193 | // outlinePaint.setStrokeJoin(Paint.Join.ROUND);
|
---|
194 | //
|
---|
195 | // Drawable defaultMarker = activity_.getResources().getDrawable(
|
---|
196 | // R.drawable.routemarker);
|
---|
197 | //
|
---|
198 | // if (routeOverlay == null) {
|
---|
199 | // routeOverlay = new RouteOverlayResetable(fillPaint, outlinePaint);
|
---|
200 | // routeMarkerOverlay = new ArrayItemizedTextAudioOverlay(
|
---|
201 | // defaultMarker, activity_, tts_);
|
---|
202 | // routeMarkerOverlayArrayList = new ArrayList<OverlayItem>();
|
---|
203 | //
|
---|
204 | // }
|
---|
205 | // // This one needs to be done again, incase it is of a different size
|
---|
206 | // routeOverlayArray = new GeoPoint[locations.size()];
|
---|
207 | //
|
---|
208 | // for (int i = 0; i < locations.size(); i++) {
|
---|
209 | // tippleLocation location = locations.get(i);
|
---|
210 | // double latitude = location.getlatitude();
|
---|
211 | // double longitude = location.getlongitude();
|
---|
212 | // String title = location.getTitle();
|
---|
213 | // String text = location.getContent();
|
---|
214 | // String tts_text = location.getTTSText();
|
---|
215 | // GeoPoint geoPoint = new GeoPoint(latitude, longitude);
|
---|
216 | //
|
---|
217 | // routeOverlayArray[i] = geoPoint;
|
---|
218 | //
|
---|
219 | // // if (title.startsWith("Manual")) {
|
---|
220 | // // ItemizedOverlay => display marker with text for info pop-up
|
---|
221 | // // window
|
---|
222 | // OverlayTextAudioItem overlayItem = new OverlayTextAudioItem(
|
---|
223 | // geoPoint, title, text, tts_text);
|
---|
224 | //
|
---|
225 | // // routeMarkerOverlay.addOverlay(overlayItem);
|
---|
226 | // routeMarkerOverlayArrayList.add(overlayItem);
|
---|
227 | // // }
|
---|
228 | // }
|
---|
229 | //
|
---|
230 | // // routeOverlay.setRouteData(routeOverlayArray);
|
---|
231 | //
|
---|
232 | // // Only add in if not already present
|
---|
233 | // List<Overlay> overlays = mapView.getOverlays();
|
---|
234 | // if (!overlays.contains(routeOverlay)) {
|
---|
235 | // overlays.add(routeOverlay);
|
---|
236 | // }
|
---|
237 | // if (!overlays.contains(routeMarkerOverlay)) {
|
---|
238 | // overlays.add(routeMarkerOverlay);
|
---|
239 | // }
|
---|
240 | // }
|
---|
241 | //
|
---|
242 | // protected void addLogRouteLocations(MapView mapView) {
|
---|
243 | // for (int i = 0; i < routeMarkerOverlayArrayList.size(); i++) {
|
---|
244 | //
|
---|
245 | // OverlayItem overlay_item = routeMarkerOverlayArrayList.get(i);
|
---|
246 | // routeMarkerOverlay.addOverlay(overlay_item);
|
---|
247 | // }
|
---|
248 | // routeOverlay.setRouteData(routeOverlayArray);
|
---|
249 | //
|
---|
250 | // mapView.invalidate();
|
---|
251 | //
|
---|
252 | // }
|
---|
253 | //
|
---|
254 | // protected void removeLogRouteLocations(MapView mapView) {
|
---|
255 | //
|
---|
256 | // for (int i = 0; i < routeMarkerOverlayArrayList.size(); i++) {
|
---|
257 | //
|
---|
258 | // OverlayItem overlay_item = routeMarkerOverlayArrayList.get(i);
|
---|
259 | // routeMarkerOverlay.removeOverlay(overlay_item);
|
---|
260 | //
|
---|
261 | // }
|
---|
262 | //
|
---|
263 | // routeOverlay.reset();
|
---|
264 | //
|
---|
265 | // mapView.invalidate();
|
---|
266 | // }
|
---|
267 |
|
---|
268 | protected void createTourLocationsOverlay(MapView mapView,
|
---|
269 | ArrayList<tippleLocation> locations) {
|
---|
270 | System.out.println("createTourLocaitonOverlay"
|
---|
271 | + String.valueOf(lengthOfFirstBook) + "size"
|
---|
272 | + String.valueOf(lengthOfSecondBook)
|
---|
273 | + "check two locations size");
|
---|
274 | routeOverlayArray = new GeoPoint[lengthOfFirstBook];
|
---|
275 | routeOverlayArray2 = new GeoPoint[lengthOfSecondBook];
|
---|
276 |
|
---|
277 | System.out
|
---|
278 | .println("createTourLocaitonOverlay" + routeOverlayArray.length
|
---|
279 | + "size" + routeOverlayArray2.length);
|
---|
280 |
|
---|
281 | int numOfFirstRoute = 0;
|
---|
282 | int numOfSecondRoute = 0;
|
---|
283 | for (int i = 0; i < locations.size(); i++) {
|
---|
284 | tippleLocation location = locations.get(i);
|
---|
285 | double latitude = location.getlatitude();
|
---|
286 | double longitude = location.getlongitude();
|
---|
287 | int radius = (int) Math.round(1000.0 * location.getradius());
|
---|
288 | String title = location.getTitle();
|
---|
289 | String text = location.getContent();
|
---|
290 | String tts_text = location.getTTSText();
|
---|
291 | String chapter = location.getChapter();
|
---|
292 | String nodeID = location.getNodeID();
|
---|
293 | String[] curbookId = nodeID.split("\\.");
|
---|
294 | GeoPoint geoPoint = new GeoPoint(latitude, longitude);
|
---|
295 | circlesOverlayGeoPoints.add(geoPoint);
|
---|
296 | circlesOverlayRadii.add(radius);
|
---|
297 |
|
---|
298 | OverlayTextAudioItem overlayItem = new OverlayTextAudioItem(
|
---|
299 | geoPoint, title, text, tts_text, chapter, nodeID);
|
---|
300 |
|
---|
301 | itemizedMarkerOverlayArrayList.add(overlayItem);
|
---|
302 |
|
---|
303 | if (curbookId[0].equalsIgnoreCase(stationOfCrossURL)) {
|
---|
304 | routeOverlayArray2[numOfSecondRoute] = geoPoint;
|
---|
305 | numOfSecondRoute++;
|
---|
306 | }
|
---|
307 |
|
---|
308 | else {
|
---|
309 | routeOverlayArray[numOfFirstRoute] = geoPoint;
|
---|
310 | numOfFirstRoute++;
|
---|
311 | }
|
---|
312 |
|
---|
313 | }
|
---|
314 |
|
---|
315 | // Only add in if not already present
|
---|
316 | List<Overlay> overlays = mapView.getOverlays();
|
---|
317 |
|
---|
318 | if (!overlays.contains(itemizedMarkerOverlay)) {
|
---|
319 | overlays.add(itemizedMarkerOverlay);
|
---|
320 | }
|
---|
321 | if (!overlays.contains(circlesOverlay)) {
|
---|
322 | overlays.add(circlesOverlay);
|
---|
323 | }
|
---|
324 |
|
---|
325 | if (!overlays.contains(routeOverlay)) {
|
---|
326 | overlays.add(routeOverlay);
|
---|
327 | }
|
---|
328 | if (!overlays.contains(routeOverlay2)) {
|
---|
329 | overlays.add(routeOverlay2);
|
---|
330 | }
|
---|
331 |
|
---|
332 | }
|
---|
333 |
|
---|
334 | protected void addTourLocations(MapView mapView, Boolean showTrail) {
|
---|
335 | for (int i = 0; i < itemizedMarkerOverlayArrayList.size(); i++) {
|
---|
336 |
|
---|
337 | OverlayTextAudioItem here_marker_item = (OverlayTextAudioItem) itemizedMarkerOverlayArrayList
|
---|
338 | .get(i);
|
---|
339 |
|
---|
340 | GeoPoint dm_geopoint = here_marker_item.getPoint();
|
---|
341 | String chapter = here_marker_item.getChapter();
|
---|
342 | String description = here_marker_item.getTitle();
|
---|
343 | String content = here_marker_item.getSnippet();
|
---|
344 | String[] bookId = (here_marker_item.getNodeID()).split("\\.");
|
---|
345 | Drawable marker;
|
---|
346 | OverlayMarkerItem highlight_marker_item;
|
---|
347 | if (bookId[0].equalsIgnoreCase(stationOfCrossURL)) {//
|
---|
348 | // Garden
|
---|
349 | // Design:HASH012992fff824b01e87d30f32
|
---|
350 | // hamilton
|
---|
351 | // Garden;
|
---|
352 | // HASHe280873a5c76118bd7e1a7
|
---|
353 | marker = activity_.getResources().getDrawable(
|
---|
354 | R.drawable.markergreen);// green color
|
---|
355 | highlight_marker_item = new OverlayMarkerItem(dm_geopoint,
|
---|
356 | chapter, description, content);
|
---|
357 | highlight_marker_item.setMarker((marker));
|
---|
358 | routeOverlay.setPaint(fillPaint2, outlinePaint2);
|
---|
359 |
|
---|
360 | } else {
|
---|
361 | highlight_marker_item = new OverlayMarkerItem(dm_geopoint,
|
---|
362 | chapter, description, content);
|
---|
363 | itemizedMarkerOverlay.setMarker(defaultMarker);// red color
|
---|
364 | routeOverlay2.setPaint(fillPaint, outlinePaint);
|
---|
365 | }
|
---|
366 |
|
---|
367 | highlight_marker_hash_.put(i, highlight_marker_item);
|
---|
368 | itemizedMarkerOverlay.addOverlay(highlight_marker_item);
|
---|
369 |
|
---|
370 | GeoPoint geo_point = circlesOverlayGeoPoints.get(i);
|
---|
371 | int radius = circlesOverlayRadii.get(i);
|
---|
372 | circlesOverlay.addCircleData(geo_point, radius);
|
---|
373 | }
|
---|
374 | // check the routeOverlay nodeID
|
---|
375 | if (showTrail) {
|
---|
376 |
|
---|
377 | if (lengthOfFirstBook > 0)
|
---|
378 | routeOverlay.setRouteData(routeOverlayArray);
|
---|
379 |
|
---|
380 | if (lengthOfSecondBook > 0)
|
---|
381 | routeOverlay2.setRouteData(routeOverlayArray2);
|
---|
382 | }
|
---|
383 |
|
---|
384 | mapView.invalidate();
|
---|
385 | }
|
---|
386 |
|
---|
387 | protected void removeTourLocations(MapView mapView) {
|
---|
388 | if (itemizedMarkerOverlayArrayList.size() > 0) {
|
---|
389 | for (int i = 0; i < itemizedMarkerOverlayArrayList.size(); i++) {
|
---|
390 |
|
---|
391 | OverlayMarkerItem highlight_marker_item = highlight_marker_hash_
|
---|
392 | .remove(i);
|
---|
393 | itemizedMarkerOverlay.removeOverlay(highlight_marker_item);
|
---|
394 | }
|
---|
395 | highlight_marker_hash_.clear();
|
---|
396 | circlesOverlay.reset();
|
---|
397 | // remove routeOverlay item from the map
|
---|
398 | if ((routeOverlay != null) || (routeOverlay2 != null)) {
|
---|
399 |
|
---|
400 | routeOverlay.reset();
|
---|
401 | routeOverlay2.reset();
|
---|
402 | }
|
---|
403 | mapView.invalidate();
|
---|
404 | } else {
|
---|
405 | System.out.println("removeTourLocation "
|
---|
406 | + itemizedMarkerOverlayArrayList.size());
|
---|
407 | }
|
---|
408 |
|
---|
409 | }
|
---|
410 |
|
---|
411 | private String queryString(Boolean bookOption) {
|
---|
412 |
|
---|
413 | String urlLocation = "";
|
---|
414 |
|
---|
415 | this.bookSelected = bookOption;
|
---|
416 |
|
---|
417 | if (bookSelected) {
|
---|
418 | urlLocation = "http://130.217.244.51:8383/greenstone3/dev?a=d&ed=1&book=off"
|
---|
419 | + "&c=hamilton&d=";// HASH4e454a5d938158a2a3fcde
|
---|
420 | urlLocation += hamiltonGardenURL;
|
---|
421 | urlLocation += "&dt=hierarchy&p.a=b&p.sa=&p.s=ClassifierBrowse&o=xml";
|
---|
422 | }
|
---|
423 | // book 2
|
---|
424 | else
|
---|
425 | // bookSelected for the book B : Garden Design
|
---|
426 | {
|
---|
427 | urlLocation = "http://130.217.244.51:8383/greenstone3/dev?a=d&ed=1&book=off"
|
---|
428 | + "&c=hamilton&d=";// HASH012992fff824b01e87d30f32
|
---|
429 | urlLocation += stationOfCrossURL;
|
---|
430 | urlLocation += "&dt=hierarchy&p.a=b&p.sa=&p.s=ClassifierBrowse&o=xml";
|
---|
431 | }
|
---|
432 | return urlLocation;
|
---|
433 | }
|
---|
434 |
|
---|
435 | /*
|
---|
436 | * parseXML translate cml data to location instance
|
---|
437 | */
|
---|
438 | protected ArrayList<HashMap<String, String>> parseXMLToHashMapArrayList(
|
---|
439 | Boolean bookOption) {
|
---|
440 |
|
---|
441 | ArrayList<HashMap<String, String>> hashmap_list = null;
|
---|
442 | String urlLocation;
|
---|
443 | try {
|
---|
444 | urlLocation = queryString(bookOption);
|
---|
445 | URL url = new URL(urlLocation);
|
---|
446 | SAXParserFactory spf = SAXParserFactory.newInstance();
|
---|
447 | SAXParser sp = spf.newSAXParser();
|
---|
448 | XMLReader xr = sp.getXMLReader();
|
---|
449 | xmlHandler myExampleHandler = new xmlHandler("documentNode");
|
---|
450 | xr.setContentHandler(myExampleHandler);
|
---|
451 | xr.parse(new InputSource(url.openStream()));
|
---|
452 | hashmap_list = myExampleHandler.getHashmapList();
|
---|
453 |
|
---|
454 | } catch (Exception e) {
|
---|
455 | System.out.println("can't connect to the DL server");
|
---|
456 | }
|
---|
457 | return hashmap_list;
|
---|
458 |
|
---|
459 | }
|
---|
460 |
|
---|
461 | public ArrayList<tippleLocation> loadTour(Boolean bookOption) {
|
---|
462 |
|
---|
463 | ArrayList<HashMap<String, String>> location_hashmap_list = parseXMLToHashMapArrayList(bookOption);
|
---|
464 |
|
---|
465 | if (location_hashmap_list != null) {
|
---|
466 | Log.d("TippleActivity::loadTour()", "XML Tour File Parsed");
|
---|
467 | }
|
---|
468 |
|
---|
469 | ArrayList<tippleLocation> locations = new ArrayList<tippleLocation>();
|
---|
470 | System.out.println(" LoadTour size of hashmaplist "
|
---|
471 | + location_hashmap_list.size());
|
---|
472 | for (int i = 0; i < location_hashmap_list.size() - 1; i++) {
|
---|
473 | HashMap<String, String> location_hashmap = location_hashmap_list
|
---|
474 | .get(i);
|
---|
475 | tippleLocation location = new tippleLocation(location_hashmap);
|
---|
476 | locations.add(location);
|
---|
477 |
|
---|
478 | }
|
---|
479 | location_hashmap_list.clear();
|
---|
480 | location_hashmap_list = null;
|
---|
481 | if (bookOption)
|
---|
482 | lengthOfFirstBook = locations.size();
|
---|
483 | else
|
---|
484 | lengthOfSecondBook = locations.size();
|
---|
485 | return locations;
|
---|
486 | }
|
---|
487 |
|
---|
488 | public ArrayList<tippleLocation> loadTourDescription() {
|
---|
489 | preLocations = loadTour(true);// load book A
|
---|
490 | lengthOfFirstBook = preLocations.size();
|
---|
491 | temLocations = new ArrayList<tippleLocation>();
|
---|
492 | temLocations = loadTour(false);// load book B
|
---|
493 | lengthOfSecondBook = temLocations.size();
|
---|
494 |
|
---|
495 | for (int i = 0; i < preLocations.size(); i++) {
|
---|
496 | tippleLocation preLocation = preLocations.get(i);
|
---|
497 | temLocations.add(preLocation);
|
---|
498 | }
|
---|
499 | return temLocations;
|
---|
500 |
|
---|
501 | }
|
---|
502 |
|
---|
503 | /*
|
---|
504 | * clear route data, allows route reset data based on the showTrail option.
|
---|
505 | */
|
---|
506 | public void resetRouteOverlay() {
|
---|
507 | if (routeOverlay != null) {
|
---|
508 | routeOverlay.reset();
|
---|
509 | }
|
---|
510 | if (routeOverlay2 != null)
|
---|
511 | routeOverlay2.reset();
|
---|
512 | if (routeMarkerOverlay != null) {
|
---|
513 | // routeMarkerOverlay.stop();
|
---|
514 | routeMarkerOverlay.clear();
|
---|
515 | }
|
---|
516 |
|
---|
517 | }
|
---|
518 |
|
---|
519 | /*
|
---|
520 | * clear route data, circle data and locations data
|
---|
521 | */
|
---|
522 | public void resetOverlayThreads() {
|
---|
523 | resetRouteOverlay();// reset route data
|
---|
524 | if (circlesOverlayGeoPoints != null) {
|
---|
525 | circlesOverlayGeoPoints.clear();
|
---|
526 | // circlesOverlayGeoPoints = null;
|
---|
527 | }
|
---|
528 | if (circlesOverlayRadii != null) {
|
---|
529 | circlesOverlayRadii.clear();
|
---|
530 | // circlesOverlayRadii = null;
|
---|
531 | }
|
---|
532 | if (circlesOverlay != null) {
|
---|
533 | // circlesOverlay.stop();
|
---|
534 | circlesOverlay.reset();
|
---|
535 |
|
---|
536 | // circlesOverlay = null;
|
---|
537 | }
|
---|
538 |
|
---|
539 | if (itemizedMarkerOverlay != null) {
|
---|
540 | itemizedMarkerOverlay.clear();
|
---|
541 | // itemizedMarkerOverlay = null;
|
---|
542 | }
|
---|
543 | if (highlight_marker_hash_ != null)
|
---|
544 |
|
---|
545 | {
|
---|
546 | highlight_marker_hash_.clear();
|
---|
547 | // highlight_marker_hash_ = null;
|
---|
548 | }
|
---|
549 |
|
---|
550 | if (itemizedMarkerOverlayArrayList != null) {
|
---|
551 | itemizedMarkerOverlayArrayList.clear();
|
---|
552 | // itemizedMarkerOverlayArrayList = null;
|
---|
553 | }
|
---|
554 | lengthOfFirstBook = 0;
|
---|
555 | lengthOfSecondBook = 0;
|
---|
556 | if (routeOverlayArray != null)
|
---|
557 | routeOverlayArray = null;
|
---|
558 | if (routeOverlayArray2 != null)
|
---|
559 | routeOverlayArray = null;
|
---|
560 | System.gc();
|
---|
561 |
|
---|
562 | }
|
---|
563 |
|
---|
564 | public static void stopOverlayThreads() {
|
---|
565 | if (circlesOverlay != null) {
|
---|
566 | // circlesOverlay.stop();
|
---|
567 | circlesOverlay = null;
|
---|
568 | }
|
---|
569 |
|
---|
570 | if (itemizedMarkerOverlay != null) {
|
---|
571 | // itemizedMarkerOverlay.stop();
|
---|
572 | itemizedMarkerOverlay = null;
|
---|
573 | }
|
---|
574 |
|
---|
575 | if (routeOverlay != null) {
|
---|
576 | // routeOverlay.stop();
|
---|
577 | routeOverlay = null;
|
---|
578 | }
|
---|
579 | if (routeOverlay2 != null) {
|
---|
580 | routeOverlay2 = null;
|
---|
581 | }
|
---|
582 | if (routeMarkerOverlay != null) {
|
---|
583 | // routeMarkerOverlay.stop();
|
---|
584 | routeMarkerOverlay = null;
|
---|
585 | }
|
---|
586 | }
|
---|
587 |
|
---|
588 | protected String SyncSynthesizeToFile(String text, String id,
|
---|
589 | String root_utterance) {
|
---|
590 | // String audio_dir = tippleActivity.audioDirectory;
|
---|
591 | String audio_dir = "/sdcard/";
|
---|
592 | File tts_file = new File(audio_dir, id + "-" + root_utterance
|
---|
593 | + "-TTS.wav");
|
---|
594 | // check if the mps file already exist
|
---|
595 | // File tts_file_mps= new
|
---|
596 | // File(audio_dir,id+"-"+root_utterance+"TTS.mp3");
|
---|
597 | String tts_filename = tts_file.getAbsolutePath();
|
---|
598 | if (tts_file.exists()) {
|
---|
599 |
|
---|
600 | // already synthesized this
|
---|
601 | return tts_filename;
|
---|
602 | }
|
---|
603 | // if(tts_file_mps.exists())
|
---|
604 | // {
|
---|
605 | // tts_filename= tts_file_mps.getAbsolutePath();
|
---|
606 | // // already synthesized this
|
---|
607 | // return tts_filename;
|
---|
608 | // }
|
---|
609 | // Rendering the supplied text of the id+utterance derived WAV file
|
---|
610 | HashMap<String, String> hashRender = new HashMap<String, String>();
|
---|
611 | hashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, text);
|
---|
612 |
|
---|
613 | String UTTERANCE = root_utterance + "-utterance";
|
---|
614 |
|
---|
615 | hashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UTTERANCE);
|
---|
616 | UtteranceWaitListener listener = new UtteranceWaitListener(UTTERANCE);
|
---|
617 | tts_.setOnUtteranceCompletedListener(listener);
|
---|
618 |
|
---|
619 | tts_.synthesizeToFile(text, hashRender, tts_filename);
|
---|
620 |
|
---|
621 | try {
|
---|
622 | listener.waitForComplete();
|
---|
623 | } catch (Exception e) {
|
---|
624 | e.printStackTrace();
|
---|
625 | return null;
|
---|
626 | }
|
---|
627 |
|
---|
628 | return tts_filename;
|
---|
629 | }
|
---|
630 |
|
---|
631 | boolean genPrevVisited = true;
|
---|
632 |
|
---|
633 | public boolean textToSpeechToLocation(tippleLocation curtip_location,
|
---|
634 | boolean visited_previously) {
|
---|
635 | if (genPrevVisited) {
|
---|
636 | prevVisitedFilename = SyncSynthesizeToFile("Previously visited.",
|
---|
637 | "Previously-visited", "cue");
|
---|
638 | System.err
|
---|
639 | .println("** Prev visisted file = " + prevVisitedFilename);
|
---|
640 | genPrevVisited = false;
|
---|
641 | }
|
---|
642 | // get updated location and talk to DL, update locations content data
|
---|
643 | // tippleLocation tip_location = loadLocationContent(curtip_location);
|
---|
644 | String title = curtip_location.getTitle();
|
---|
645 | String text = curtip_location.getContent();
|
---|
646 | String id = curtip_location.getID();
|
---|
647 |
|
---|
648 | String title_filename = SyncSynthesizeToFile(title, id, "title");
|
---|
649 | String text_filename = SyncSynthesizeToFile(text, id, "text");
|
---|
650 |
|
---|
651 | if ((title_filename != null) && (text_filename != null)) {
|
---|
652 | String audio_dir = tippleActivity.audioDirectory;
|
---|
653 | File ding_file = new File(audio_dir, "DingExtended.wav");
|
---|
654 | String ding_filename = ding_file.getAbsolutePath();
|
---|
655 | //
|
---|
656 | if (audio_player_view_.addAudio(id)) {
|
---|
657 | audio_player_view_.queueAudio(title_filename, id, title,
|
---|
658 | visited_previously);
|
---|
659 | audio_player_view_.queueAudio(text_filename, id, text);
|
---|
660 | audio_player_view_
|
---|
661 | .queueAudio(ding_filename, id, "[Audio Bing]");
|
---|
662 |
|
---|
663 | audio_player_view_.updateTextViewIfHeadIsNewLocation();
|
---|
664 | System.out
|
---|
665 | .println("the size of audio player view queue should be at least 1"
|
---|
666 | + audio_player_view_.audioPlayerQueue_.size());
|
---|
667 | }
|
---|
668 | }
|
---|
669 | System.out.println("the size "
|
---|
670 | + audio_player_view_.audioPlayerQueue_.size());
|
---|
671 | return true;
|
---|
672 | }
|
---|
673 |
|
---|
674 | private static class UtteranceWaitListener implements
|
---|
675 | OnUtteranceCompletedListener {
|
---|
676 | private boolean mIsComplete = false;
|
---|
677 | private final String mExpectedUtterance;
|
---|
678 |
|
---|
679 | public UtteranceWaitListener(String expectedUtteranceId) {
|
---|
680 | mExpectedUtterance = expectedUtteranceId;
|
---|
681 | }
|
---|
682 |
|
---|
683 | public void onUtteranceCompleted(String utteranceId) {
|
---|
684 | if (mExpectedUtterance.equals(utteranceId)) {
|
---|
685 | synchronized (this) {
|
---|
686 | mIsComplete = true;
|
---|
687 | notify();
|
---|
688 | }
|
---|
689 | }
|
---|
690 | }
|
---|
691 |
|
---|
692 | public boolean waitForComplete() throws InterruptedException {
|
---|
693 | if (mIsComplete) {
|
---|
694 | return true;
|
---|
695 | }
|
---|
696 | //
|
---|
697 | synchronized (this) {
|
---|
698 | int TTS_SPEECH_MAX_WAIT_TIME = 5 * 1000;
|
---|
699 | wait(TTS_SPEECH_MAX_WAIT_TIME);
|
---|
700 | return mIsComplete;
|
---|
701 | }
|
---|
702 | }
|
---|
703 |
|
---|
704 | }
|
---|
705 |
|
---|
706 | }
|
---|