source: other-projects/tipple-android/src/org/tipple/mapDisplay/copyOfLocationManager.java@ 26523

Last change on this file since 26523 was 26523, checked in by davidb, 11 years ago

A version of Tipple with the mods Casey made for her Masters work

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