Permalink
Browse files

Fin d'implémentation de FreeWalk

  • Loading branch information...
joey-mbk committed May 11, 2012
1 parent 4f476c1 commit 06bd6e1455ef0084023993e63230fb907f99d7a5
View
@@ -88,6 +88,8 @@
android:name=".activity.DeleteItinerary"
android:label="Delete itinerary" >
</activity>
<uses-library android:required="true" android:name="com.google.android.maps" />
</application>
</manifest>
View
@@ -4,8 +4,7 @@
<com.google.android.maps.MapView
android:id="@+id/myMapView1"
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_x="0px"
@@ -105,14 +105,11 @@ private void addDirections() {
@Override
public void onLocationChanged(Location arg0) {
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 (arg0.distanceTo(poiLocation) <= 50) {
Intent intent = new Intent(this, PoiDetails.class);
intent.putExtra("itinerary", true);
intent.putExtra("freewalk", false);
intent.putExtra("step", this.step);
intent.putExtra("poi", poi.getId());
startActivity(intent);
@@ -31,6 +31,7 @@
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
@@ -43,7 +44,7 @@
import com.mobilecityguide.models.POI;
import com.mobilecityguide.models.Road;
public class FreeWalk extends Activity implements LocationListener {
public class FreeWalk extends MapActivity implements LocationListener {
private Road mRoad;
private int step;
@@ -54,101 +55,60 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//step = 1;
setContentView(R.layout.free_walk);
mapView = (MapView) findViewById(R.id.map);
try {
poi = POIController.getPOIOfCity();
} catch (Exception e) {
// TODO Auto-generated catch block
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;
GeoPoint points = null;
GeoPoint point = null;
for (POI currentPoi : poi) {
poiLocation = new Location(LocationManager.GPS_PROVIDER);
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);
point = new GeoPoint((int) (currentPoi.getLatitude()*1E6), (int) (currentPoi.getLongitude()*1E6));
MapOverlay mapOverlay = new MapOverlay(point);
listOfOverlays = mapView.getOverlays();
listOfOverlays.add(mapOverlay);
}
MapController mapController = mapView.getController();
mapController.animateTo(points);
mapController.animateTo(point);
mapController.setZoom(17);
mapView.setSatellite(true);
mapView.displayZoomControls(true);
setContentView(R.layout.free_walk);
//addDirections();
}
/* 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));
private void addDirections() {
for (int i = 0; i < mRoad.mPoints.length-1; i++) {
TextView container = new TextView(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());
/* Monitor position changes */
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
*/
@Override
public void onLocationChanged(Location arg0) {
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 */
for (POI poi2 : poi) {
if (arg0.distanceTo(poiLocation) <= 50) {
/* if we're less than 20 meters away from a POI, show its informations */
for (POI aPoi : poi) {
poiLocation = new Location(LocationManager.GPS_PROVIDER);
poiLocation.setLatitude(aPoi.getLatitude());
poiLocation.setLongitude(aPoi.getLongitude());
if (arg0.distanceTo(poiLocation) <= 20) {
Intent intent = new Intent(this, PoiDetails.class);
intent.putExtra("id", true);
intent.putExtra("poi", poi2.getId());
intent.putExtra("freewalk", true);
intent.putExtra("poi", aPoi.getId());
startActivity(intent);
}
}
}
@@ -168,19 +128,6 @@ public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
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) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.menu, menu);
@@ -279,6 +226,12 @@ public boolean onTouchEvent(MotionEvent event, MapView mapView)
else
return false;
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
@@ -22,6 +22,7 @@
public class PoiDetails extends Activity implements OnClickListener {
private boolean inItinerary;
private boolean freewalk;
private int step;
/** Called when the activity is first created. */
@@ -35,13 +36,19 @@ public void onCreate(Bundle savedInstanceState) {
int poiID = 0;
POI poi = null;
try {
if (extras != null)
if (extras != null) {
this.inItinerary = extras.getBoolean("itinerary");
this.freewalk = extras.getBoolean("freewalk");
}
if (this.inItinerary) {
this.step = extras.getInt("step");
poiID = extras.getInt("poi");
poi = POIController.getPOI(poiID);
}
else if (this.freewalk) {
poiID = extras.getInt("poi");
poi = POIController.getPOI(poiID);
}
else {
poiName = extras.getString("poi"); // retrieve the name of the POI
poi = POIController.getPOI(poiName);
@@ -57,7 +64,16 @@ public void onCreate(Bundle savedInstanceState) {
if (desc != null)
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 */
setContentView(R.layout.poi_details);
((TextView) findViewById(R.id.description)).setText(desc);
@@ -79,6 +95,17 @@ public void onCreate(Bundle savedInstanceState) {
LinearLayout layout = (LinearLayout) findViewById(R.id.info_list);
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) {
@@ -114,11 +141,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void onClick(View arg0) {
/* check if it's the last poi in the itinerary */
Intent intent;
if (UserController.selectedItinerary.getPOIList().size() == step)
intent = new Intent(this, ItinerariesList.class);
else
intent = new Intent(this, Directions.class); // get directions towards the next poi in the itinerary
intent.putExtra("step", this.step+1);
startActivity(intent);
if (this.inItinerary) {
if (UserController.selectedItinerary.getPOIList().size() == step)
intent = new Intent(this, ItinerariesList.class);
else
intent = new Intent(this, Directions.class); // get directions towards the next poi in the itinerary
intent.putExtra("step", this.step+1);
startActivity(intent);
}
else if (this.freewalk) {
intent = new Intent(this, FreeWalk.class);
startActivity(intent);
}
}
}
@@ -104,6 +104,7 @@ private void setListeners() {
public void onItemClick(AdapterView<?> arg0,View arg1, int arg2, long id) {
Intent intent = new Intent(this, PoiDetails.class);
intent.putExtra("itinerary", false);
intent.putExtra("freewalk", false);
intent.putExtra("poi", pois.get((int) id));
startActivity(intent);
}

0 comments on commit 06bd6e1

Please sign in to comment.