Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fin d'implémentation de FreeWalk
  • Loading branch information
joey-mbk committed May 11, 2012
1 parent 4f476c1 commit 06bd6e1
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 97 deletions.
2 changes: 2 additions & 0 deletions AndroidManifest.xml
Expand Up @@ -88,6 +88,8 @@
android:name=".activity.DeleteItinerary" android:name=".activity.DeleteItinerary"
android:label="Delete itinerary" > android:label="Delete itinerary" >
</activity> </activity>

<uses-library android:required="true" android:name="com.google.android.maps" />
</application> </application>


</manifest> </manifest>
3 changes: 1 addition & 2 deletions res/layout/free_walk.xml
Expand Up @@ -4,8 +4,7 @@




<com.google.android.maps.MapView <com.google.android.maps.MapView
android:id="@+id/myMapView1" android:id="@+id/map"

android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_x="0px" android:layout_x="0px"
Expand Down
5 changes: 1 addition & 4 deletions src/com/mobilecityguide/activity/Directions.java
Expand Up @@ -105,14 +105,11 @@ private void addDirections() {
@Override @Override
public void onLocationChanged(Location arg0) { public void onLocationChanged(Location arg0) {
System.out.println("Location changed"); System.out.println("Location changed");
System.out.println(arg0.getLatitude());
System.out.println(arg0.getLongitude());
System.out.println("Distance from POI: "+arg0.distanceTo(poiLocation));

/* if we're less than 50 meters away from the POI, show its informations */ /* if we're less than 50 meters away from the POI, show its informations */
if (arg0.distanceTo(poiLocation) <= 50) { if (arg0.distanceTo(poiLocation) <= 50) {
Intent intent = new Intent(this, PoiDetails.class); Intent intent = new Intent(this, PoiDetails.class);
intent.putExtra("itinerary", true); intent.putExtra("itinerary", true);
intent.putExtra("freewalk", false);
intent.putExtra("step", this.step); intent.putExtra("step", this.step);
intent.putExtra("poi", poi.getId()); intent.putExtra("poi", poi.getId());
startActivity(intent); startActivity(intent);
Expand Down
119 changes: 36 additions & 83 deletions src/com/mobilecityguide/activity/FreeWalk.java
Expand Up @@ -31,6 +31,7 @@
import android.widget.Toast; import android.widget.Toast;


import com.google.android.maps.GeoPoint; import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController; import com.google.android.maps.MapController;
import com.google.android.maps.MapView; import com.google.android.maps.MapView;
import com.google.android.maps.Overlay; import com.google.android.maps.Overlay;
Expand All @@ -43,7 +44,7 @@
import com.mobilecityguide.models.POI; import com.mobilecityguide.models.POI;
import com.mobilecityguide.models.Road; import com.mobilecityguide.models.Road;


public class FreeWalk extends Activity implements LocationListener { public class FreeWalk extends MapActivity implements LocationListener {


private Road mRoad; private Road mRoad;
private int step; private int step;
Expand All @@ -54,101 +55,60 @@ public class FreeWalk extends Activity implements LocationListener {


public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);


//step = 1; setContentView(R.layout.free_walk);

mapView = (MapView) findViewById(R.id.map);

try { try {
poi = POIController.getPOIOfCity(); poi = POIController.getPOIOfCity();
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} // retrieve this step POI }

/* Get user's location */
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
Location userLocation = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, true));

/* Monitor position changes */
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);



List<Overlay> listOfOverlays = null; List<Overlay> listOfOverlays = null;
GeoPoint points = null; GeoPoint point = null;


for (POI currentPoi : poi) { for (POI currentPoi : poi) {

point = new GeoPoint((int) (currentPoi.getLatitude()*1E6), (int) (currentPoi.getLongitude()*1E6));
poiLocation = new Location(LocationManager.GPS_PROVIDER); MapOverlay mapOverlay = new MapOverlay(point);
poiLocation.setLatitude(currentPoi.getLatitude());
poiLocation.setLongitude(currentPoi.getLongitude());

//String url = GPSController.getUrl(userLocation, currentPoi);
//InputStream is = getConnection(url);
//mRoad = GPSController.getRoute(is);

points = new GeoPoint(
(int) (currentPoi.getLatitude() * 1E6),
(int) (currentPoi.getLongitude() * 1E6));

MapOverlay mapOverlay = new MapOverlay(points);
listOfOverlays = mapView.getOverlays(); listOfOverlays = mapView.getOverlays();
listOfOverlays.add(mapOverlay); listOfOverlays.add(mapOverlay);


} }


MapController mapController = mapView.getController(); MapController mapController = mapView.getController();
mapController.animateTo(points); mapController.animateTo(point);
mapController.setZoom(17); mapController.setZoom(17);


mapView.setSatellite(true); mapView.setSatellite(true);
mapView.displayZoomControls(true); mapView.displayZoomControls(true);


setContentView(R.layout.free_walk); /* Get user's location */
//addDirections(); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
} Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
Location userLocation = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, true));


private void addDirections() { /* Monitor position changes */
for (int i = 0; i < mRoad.mPoints.length-1; i++) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
TextView container = new TextView(this); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
if (i == mRoad.mPoints.length-2) // if it's the last direction, no need to show distance
container.setText(mRoad.mPoints[i].mName);
else
container.setText(mRoad.mPoints[i].mName+" "+mRoad.mPoints[i].mDescription);
container.setId(i);
container.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
LinearLayout layout = (LinearLayout) findViewById(R.id.directions);
layout.addView(container);
}
}
/*
private void moveToNextPoi() {
this.step++;
this.previousPoi;
this.poi = UserController.selectedItinerary.getPOIList().get(new Integer(this.step));
this.poiLocation = new Location(LocationManager.GPS_PROVIDER);
this.poiLocation.setLatitude(poi.getLatitude());
this.poiLocation.setLongitude(poi.getLongitude());
} }
*/
@Override @Override
public void onLocationChanged(Location arg0) { public void onLocationChanged(Location arg0) {
System.out.println("Location changed"); System.out.println("Location changed");
System.out.println(arg0.getLatitude()); /* if we're less than 20 meters away from a POI, show its informations */
System.out.println(arg0.getLongitude()); for (POI aPoi : poi) {
System.out.println("Distance from POI: "+arg0.distanceTo(poiLocation)); poiLocation = new Location(LocationManager.GPS_PROVIDER);

poiLocation.setLatitude(aPoi.getLatitude());
/* if we're less than 50 meters away from the POI, show its informations */ poiLocation.setLongitude(aPoi.getLongitude());
for (POI poi2 : poi) {

if (arg0.distanceTo(poiLocation) <= 20) {
if (arg0.distanceTo(poiLocation) <= 50) {
Intent intent = new Intent(this, PoiDetails.class); Intent intent = new Intent(this, PoiDetails.class);
intent.putExtra("id", true); intent.putExtra("freewalk", true);
intent.putExtra("poi", poi2.getId()); intent.putExtra("poi", aPoi.getId());
startActivity(intent); startActivity(intent);

} }
} }
} }
Expand All @@ -168,19 +128,6 @@ public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
System.out.println("Status changed: "+arg0); System.out.println("Status changed: "+arg0);
} }


private InputStream getConnection(String url) {
InputStream is = null;
try {
URLConnection conn = new URL(url).openConnection();
is = conn.getInputStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return is;
}

public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.menu, menu); inflater.inflate(R.layout.menu, menu);
Expand Down Expand Up @@ -279,6 +226,12 @@ public boolean onTouchEvent(MotionEvent event, MapView mapView)
else else
return false; return false;
} }
}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
} }


} }
49 changes: 41 additions & 8 deletions src/com/mobilecityguide/activity/PoiDetails.java
Expand Up @@ -22,6 +22,7 @@
public class PoiDetails extends Activity implements OnClickListener { public class PoiDetails extends Activity implements OnClickListener {


private boolean inItinerary; private boolean inItinerary;
private boolean freewalk;
private int step; private int step;


/** Called when the activity is first created. */ /** Called when the activity is first created. */
Expand All @@ -35,13 +36,19 @@ public void onCreate(Bundle savedInstanceState) {
int poiID = 0; int poiID = 0;
POI poi = null; POI poi = null;
try { try {
if (extras != null) if (extras != null) {
this.inItinerary = extras.getBoolean("itinerary"); this.inItinerary = extras.getBoolean("itinerary");
this.freewalk = extras.getBoolean("freewalk");
}
if (this.inItinerary) { if (this.inItinerary) {
this.step = extras.getInt("step"); this.step = extras.getInt("step");
poiID = extras.getInt("poi"); poiID = extras.getInt("poi");
poi = POIController.getPOI(poiID); poi = POIController.getPOI(poiID);
} }
else if (this.freewalk) {
poiID = extras.getInt("poi");
poi = POIController.getPOI(poiID);
}
else { else {
poiName = extras.getString("poi"); // retrieve the name of the POI poiName = extras.getString("poi"); // retrieve the name of the POI
poi = POIController.getPOI(poiName); poi = POIController.getPOI(poiName);
Expand All @@ -57,7 +64,16 @@ public void onCreate(Bundle savedInstanceState) {
if (desc != null) if (desc != null)
break; break;
} }


/* if no suitable description was found, try to find anyone */
if (desc == null) {
for (String lang : languages) {
desc = poi.getDescription("adult", lang);
if (desc != null)
break;
}
}

/* Set the details in corresponding text fields */ /* Set the details in corresponding text fields */
setContentView(R.layout.poi_details); setContentView(R.layout.poi_details);
((TextView) findViewById(R.id.description)).setText(desc); ((TextView) findViewById(R.id.description)).setText(desc);
Expand All @@ -79,6 +95,17 @@ public void onCreate(Bundle savedInstanceState) {
LinearLayout layout = (LinearLayout) findViewById(R.id.info_list); LinearLayout layout = (LinearLayout) findViewById(R.id.info_list);
layout.addView(container); layout.addView(container);
} }
else if (this.freewalk) {
Button container = new Button(this);
container.setText("Close");
container.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
container.setOnClickListener(this);
container.setBackgroundResource(R.drawable.buttonroundedcorners);
LinearLayout layout = (LinearLayout) findViewById(R.id.info_list);
layout.addView(container);
}
} }


public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
Expand Down Expand Up @@ -114,11 +141,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void onClick(View arg0) { public void onClick(View arg0) {
/* check if it's the last poi in the itinerary */ /* check if it's the last poi in the itinerary */
Intent intent; Intent intent;
if (UserController.selectedItinerary.getPOIList().size() == step) if (this.inItinerary) {
intent = new Intent(this, ItinerariesList.class); if (UserController.selectedItinerary.getPOIList().size() == step)
else intent = new Intent(this, ItinerariesList.class);
intent = new Intent(this, Directions.class); // get directions towards the next poi in the itinerary else
intent.putExtra("step", this.step+1); intent = new Intent(this, Directions.class); // get directions towards the next poi in the itinerary
startActivity(intent); intent.putExtra("step", this.step+1);
startActivity(intent);
}
else if (this.freewalk) {
intent = new Intent(this, FreeWalk.class);
startActivity(intent);
}
} }
} }
1 change: 1 addition & 0 deletions src/com/mobilecityguide/activity/PoisList.java
Expand Up @@ -104,6 +104,7 @@ private void setListeners() {
public void onItemClick(AdapterView<?> arg0,View arg1, int arg2, long id) { public void onItemClick(AdapterView<?> arg0,View arg1, int arg2, long id) {
Intent intent = new Intent(this, PoiDetails.class); Intent intent = new Intent(this, PoiDetails.class);
intent.putExtra("itinerary", false); intent.putExtra("itinerary", false);
intent.putExtra("freewalk", false);
intent.putExtra("poi", pois.get((int) id)); intent.putExtra("poi", pois.get((int) id));
startActivity(intent); startActivity(intent);
} }
Expand Down

0 comments on commit 06bd6e1

Please sign in to comment.