From 7b80d7282447001ee73c40e90bfa38beeac6a633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Poledn=C3=BD?= Date: Fri, 9 Nov 2012 11:12:53 +0100 Subject: [PATCH] Pridany GPX tacky pro testovani. Detekce dobehnuti do cile pro usera --- AndroidManifest.xml | 4 +- res/raw/cesta.gpx | 2 + res/raw/faketrack.gpx | 69 +++++++++++++++++++ src/cz/cvut/fel/nur/zavody/Zavody.java | 46 +++++++++++++ .../fel/nur/zavody/activity/NormalMode.java | 22 ++---- .../fel/nur/zavody/maps/FinishOverlay.java | 7 +- .../fel/nur/zavody/maps/RaceOverlays.java | 8 ++- .../cvut/fel/nur/zavody/maps/UserOverlay.java | 56 +++++++++++++++ 8 files changed, 191 insertions(+), 23 deletions(-) create mode 100644 res/raw/cesta.gpx create mode 100644 res/raw/faketrack.gpx create mode 100644 src/cz/cvut/fel/nur/zavody/Zavody.java create mode 100644 src/cz/cvut/fel/nur/zavody/maps/UserOverlay.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f771ae7..2889b2f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -13,7 +13,9 @@ - + diff --git a/res/raw/cesta.gpx b/res/raw/cesta.gpx new file mode 100644 index 0000000..3ac2148 --- /dev/null +++ b/res/raw/cesta.gpx @@ -0,0 +1,2 @@ + +12345678910111213141516Finish diff --git a/res/raw/faketrack.gpx b/res/raw/faketrack.gpx new file mode 100644 index 0000000..09eefe0 --- /dev/null +++ b/res/raw/faketrack.gpx @@ -0,0 +1,69 @@ + + + + New Route + + + Start + + + + 1 + + + + 2 + + + + 3 + + + + 4 + + + + 5 + + + + 6 + + + + 7 + + + + 8 + + + + 9 + + + + 10 + + + + 11 + + + + 12 + + + + End + + + + + \ No newline at end of file diff --git a/src/cz/cvut/fel/nur/zavody/Zavody.java b/src/cz/cvut/fel/nur/zavody/Zavody.java new file mode 100644 index 0000000..6d1b614 --- /dev/null +++ b/src/cz/cvut/fel/nur/zavody/Zavody.java @@ -0,0 +1,46 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package cz.cvut.fel.nur.zavody; + +import android.app.Application; +import android.location.Location; +import com.google.android.maps.GeoPoint; + +/** + * + * @author saljack + */ +public class Zavody extends Application { + + /** + * Finish position + */ + public static final int LATITUDE = (int) (14.5205569 * 1E6); + public static final int LONGITUDE = (int) (50.08352695 * 1E6); + public static final int MIN_DISTANCE = 15;//meters + private GeoPoint _finishGeoPoint; +// private Location _finishLocation; + + @Override + public void onCreate() { + super.onCreate(); + setFinish(new GeoPoint(LONGITUDE, LATITUDE)); + } + + public void setFinish(GeoPoint point) { + _finishGeoPoint = point; +// _finishLocation = new Location("Finish"); +// _finishLocation.setLatitude(point.getLatitudeE6() / 1E6); +// _finishLocation.setLongitude(point.getLongitudeE6() / 1E6); + } + + public GeoPoint getFinishGeoPoint() { + return _finishGeoPoint; + } + +// public Location getFinishLocation() { +// return _finishLocation; +// } +} diff --git a/src/cz/cvut/fel/nur/zavody/activity/NormalMode.java b/src/cz/cvut/fel/nur/zavody/activity/NormalMode.java index d19b84b..7b60928 100644 --- a/src/cz/cvut/fel/nur/zavody/activity/NormalMode.java +++ b/src/cz/cvut/fel/nur/zavody/activity/NormalMode.java @@ -14,6 +14,7 @@ import com.google.android.maps.MyLocationOverlay; import cz.cvut.fel.nur.zavody.R; import cz.cvut.fel.nur.zavody.maps.RaceOverlays; +import cz.cvut.fel.nur.zavody.maps.UserOverlay; /** * @@ -22,7 +23,7 @@ public class NormalMode extends MapActivity { private MapController _controller; - private MyLocationOverlay _myLocationOverlay; + private UserOverlay _myLocationOverlay; private MapView _mapView; /** @@ -35,26 +36,11 @@ public void onCreate(Bundle icicle) { _mapView = (MapView) findViewById(R.id.nm_map); _mapView.setBuiltInZoomControls(true); _controller = _mapView.getController(); - _myLocationOverlay = new MyLocationOverlay(this, _mapView) { - @Override - public synchronized void onLocationChanged(Location location) { - super.onLocationChanged(location); - int lat = (int) (location.getLatitude() * 1E6); - int lng = (int) (location.getLongitude() * 1E6); - GeoPoint point = new GeoPoint(lat, lng); - _controller.animateTo(point); - } - - @Override - protected void drawMyLocation(Canvas arg0, MapView arg1, Location arg2, GeoPoint arg3, long arg4) { - super.drawMyLocation(arg0, arg1, arg2, arg3, arg4); - - } - }; - + _myLocationOverlay = new UserOverlay(this, _mapView); _controller.setZoom(17); _mapView.getOverlays().add(_myLocationOverlay); RaceOverlays raceOverlays = new RaceOverlays(getResources().getDrawable(R.drawable.ic_launcher), this); + _mapView.getOverlays().add(raceOverlays); diff --git a/src/cz/cvut/fel/nur/zavody/maps/FinishOverlay.java b/src/cz/cvut/fel/nur/zavody/maps/FinishOverlay.java index 27fd124..ab9f13a 100644 --- a/src/cz/cvut/fel/nur/zavody/maps/FinishOverlay.java +++ b/src/cz/cvut/fel/nur/zavody/maps/FinishOverlay.java @@ -6,10 +6,12 @@ import android.content.Context; import android.graphics.drawable.Drawable; +import android.location.Location; import android.util.Log; import com.google.android.maps.GeoPoint; import com.google.android.maps.OverlayItem; import cz.cvut.fel.nur.zavody.R; +import cz.cvut.fel.nur.zavody.Zavody; /** * @@ -17,13 +19,12 @@ */ public class FinishOverlay extends OverlayItem { - public static final int LATITUDE = (int) (14.516599 * 1E6); - public static final int LONGITUDE = (int) (50.084988 * 1E6); + private Context _ctx; private Drawable _marker; public FinishOverlay(Context ctx) { - super(new GeoPoint(LONGITUDE, LATITUDE), "Opponent", "Opponent position"); + super(((Zavody)ctx.getApplicationContext()).getFinishGeoPoint(), "Opponent", "Opponent position"); _ctx = ctx; _marker = _ctx.getResources().getDrawable(R.drawable.finish); _marker.setBounds(0 - _marker.getIntrinsicWidth() / 2, 0 - _marker.getIntrinsicHeight(), diff --git a/src/cz/cvut/fel/nur/zavody/maps/RaceOverlays.java b/src/cz/cvut/fel/nur/zavody/maps/RaceOverlays.java index 21b3a60..69526ac 100644 --- a/src/cz/cvut/fel/nur/zavody/maps/RaceOverlays.java +++ b/src/cz/cvut/fel/nur/zavody/maps/RaceOverlays.java @@ -18,12 +18,14 @@ public class RaceOverlays extends ItemizedOverlay { private Context _ctx; + private FinishOverlay _finish; private List _items = new ArrayList(2); public RaceOverlays(Drawable marker, Context ctx) { super(boundCenterBottom(marker)); _ctx = ctx; - _items.add(new FinishOverlay(ctx)); + _finish = new FinishOverlay(ctx); + _items.add(_finish); _items.add(new OpponentOverlay(ctx)); populate(); } @@ -46,4 +48,8 @@ protected OverlayItem createItem(int i) { public int size() { return _items.size(); } + + public FinishOverlay getFinishOverlay() { + return _finish; + } } diff --git a/src/cz/cvut/fel/nur/zavody/maps/UserOverlay.java b/src/cz/cvut/fel/nur/zavody/maps/UserOverlay.java new file mode 100644 index 0000000..1a62b8a --- /dev/null +++ b/src/cz/cvut/fel/nur/zavody/maps/UserOverlay.java @@ -0,0 +1,56 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package cz.cvut.fel.nur.zavody.maps; + +import android.content.Context; +import android.graphics.Canvas; +import android.location.Location; +import android.widget.Toast; +import com.google.android.maps.GeoPoint; +import com.google.android.maps.MapView; +import com.google.android.maps.MyLocationOverlay; +import cz.cvut.fel.nur.zavody.Zavody; + +/** + * + * @author saljack + */ +public class UserOverlay extends MyLocationOverlay { + + private MapView _view; + private Context _ctx; + + public UserOverlay(Context ctx, MapView mapView) { + super(ctx, mapView); + _view = mapView; + _ctx = ctx; + } + + @Override + public synchronized void onLocationChanged(Location location) { + super.onLocationChanged(location); + int lat = (int) (location.getLatitude() * 1E6); + int lng = (int) (location.getLongitude() * 1E6); + GeoPoint point = new GeoPoint(lat, lng); + + if (_view != null) { + _view.getController().animateTo(point); + } + + GeoPoint finish = ((Zavody) _ctx.getApplicationContext()).getFinishGeoPoint(); + float[] dist = new float[1]; + Location.distanceBetween(finish.getLatitudeE6() / 1E6, finish.getLongitudeE6() / 1E6, location.getLatitude(), location.getLongitude(), dist); + if (dist[0] < Zavody.MIN_DISTANCE) { + Toast.makeText(_ctx, "You win!", Toast.LENGTH_LONG).show(); + } + + } + + @Override + protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) { + super.drawMyLocation(canvas, mapView, lastFix, myLocation, when); + + } +}