Skip to content
Browse files

Changed DirectionsForm to depend on API, removed the use of

  • Loading branch information...
1 parent e5d1923 commit d91deaea31c23f1b38bf485cc610896c2cbdcdfa @phyrex1an committed May 17, 2011
View
55 src/org/pathpal/DirectionsForm.java
@@ -84,9 +84,11 @@ public AddressPlace findAddress(SearchApi api) throws IOException {
private class AmbiguousWaypointQuestion implements Question {
private WaypointInfo waypointinfo;
+ private List<AddressPlace> waypoints;
public AmbiguousWaypointQuestion(List<AddressPlace> waypoints,
WaypointInfo w) {
+ this.waypoints = waypoints;
this.waypointinfo = w;
}
@@ -96,8 +98,15 @@ public boolean answerQuestion(FunApp answer) {
}
public String concreteQuestion() {
- // TODO Auto-generated method stub
- return null;
+ String question = "Do you want to go to ";
+ String places = "";
+ for (AddressPlace place : this.waypoints) {
+ if (!places.equals("")) {
+ places = places + ", ";
+ }
+ places = places + place.description;
+ }
+ return question + places + "?";
}
}
@@ -193,8 +202,10 @@ public void method(TravelMethod method) {
private WaypointInfo startAt = new WaypointInfo(null);
private List<Leg> travelPath;
+ private SearchApi api;
- public DirectionsForm() {
+ public DirectionsForm(SearchApi api) {
+ this.api = api;
this.reset();
}
@@ -207,12 +218,42 @@ public Waypoint startingLocation() {
return startAt.waypoint;
}
- public void startAt(Waypoint startAt) {
+ public DirectionsForm startAt(Waypoint startAt) {
this.startAt.waypoint = startAt;
+ return this;
+ }
+
+ private Waypoint fromAddress(String address) {
+ List<AddressPlace> places = new ArrayList<AddressPlace>();
+ try
+ {
+ List<Address> addresses = this.api.geocoder.getFromLocationName(address, 3, 57.44, 11.60, 57.82, 12.10);
+ for (Address a : addresses) {
+ GeoPoint g = new GeoPoint( (int)(a.getLatitude()*1000000), (int)(a.getLongitude()*1000000));
+ places.add(new AddressPlace(g, a.getFeatureName()));
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ Waypoint w;
+ switch (places.size()) {
+ case 0:
+ throw new RuntimeException("no path");
+ //w = new UnknownWaypoint();
+ //break;
+ case 1:
+ w = new UnambiguousWaypoint(places.get(0));
+ break;
+
+ default:
+ w = new AmbiguousWaypoint(places);
+ break;
+ }
+ return w;
}
- public void startAt(String address) {
- startAt(new WaypointAddress(address));
+ public DirectionsForm startAt(String address) {
+ return startAt(fromAddress(address));
}
public void byCar() {
@@ -225,7 +266,7 @@ public DirectionsForm travelTo(Waypoint destination) {
}
public DirectionsForm travelTo(String address) {
- return this.travelTo(new WaypointAddress(address));
+ return this.travelTo(fromAddress(address));
}
public DirectionsForm andBackHere() {
View
12 src/org/pathpal/GMapsActivity.java
@@ -223,10 +223,11 @@ private void updatePath(){
public void questionHandler(){
// if there are questions then take care of them
if(directionForm.questions().size()>0){
+ System.out.println("QUESTIONS: " + directionForm.questions().size());
activeQuestion = directionForm.questions().get(0); // select a question as active
removeDialog(QUESTION_ID); // clean up the dialog first
showDialog(QUESTION_ID); // then show the dialog
- }
+ }
}
@Override
@@ -241,12 +242,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Get your current location and create a new SearchApi with your current location
AddressPlace l = new AddressPlace(myLocationOverlay.getGeoPoint(), "You are here");
- api = new SearchApi(new Geocoder(getApplicationContext()), l);
- api.geocoder = new Geocoder(getApplicationContext());
+
// create a new directionForm if needed
if(directionForm == null){
- directionForm = new DirectionsForm();
+ api = new SearchApi(new Geocoder(getApplicationContext()), l);
+ api.geocoder = new Geocoder(getApplicationContext());
+ directionForm = new DirectionsForm(api);
+ } else {
+ api.startLocation = l;
}
View
2 src/org/pathpal/test/DirectionsFormTest.java
@@ -21,7 +21,7 @@
private SearchApi api;
public void setUp() {
- form = new DirectionsForm();
+ form = new DirectionsForm(api);
destination = new DummyWaypoint();
}
View
6 src/org/pathpal/test/translateStringTest.java
@@ -27,9 +27,9 @@ public void testTranslateString() throws FileNotFoundException, IOException, Unk
{
public String travelTo;
public String startAt;
- public MockDirectionsForm() { super(); }
- public DirectionsForm travelTo(String t) { travelTo = t; return null; }
- public void startAt(String t) { startAt = t; }
+ public MockDirectionsForm() { super(null); }
+ public DirectionsForm travelTo(String t) { travelTo = t; return this; }
+ public DirectionsForm startAt(String t) { startAt = t; return this; }
}
}

0 comments on commit d91deae

Please sign in to comment.
Something went wrong with that request. Please try again.