Skip to content

Commit

Permalink
Pridany GPX tacky pro testovani. Detekce dobehnuti do cile pro usera
Browse files Browse the repository at this point in the history
  • Loading branch information
Saljack committed Nov 9, 2012
1 parent 0f3ac10 commit 7b80d72
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 23 deletions.
4 changes: 3 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher"
android:name="Zavody"
>
<uses-library android:name="com.google.android.maps" />
<activity android:name="MainActivity"
android:label="@string/app_name">
Expand Down
2 changes: 2 additions & 0 deletions res/raw/cesta.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="TrekView - http://www.trekview.cz/"><wpt lat="50.08501395897328" lon="14.512317180633545"><name>1</name></wpt><wpt lat="50.08530309284275" lon="14.513239860534668"><name>2</name></wpt><wpt lat="50.08546831141366" lon="14.513797760009766"><name>3</name></wpt><wpt lat="50.085151641985775" lon="14.514291286468506"><name>4</name></wpt><wpt lat="50.08487627556527" lon="14.514763355255127"><name>5</name></wpt><wpt lat="50.08477989694439" lon="14.51568603515625"><name>6</name></wpt><wpt lat="50.08477989694439" lon="14.516286849975586"><name>7</name></wpt><wpt lat="50.08471105495364" lon="14.51744556427002"><name>8</name></wpt><wpt lat="50.08476612855413" lon="14.518153667449951"><name>9</name></wpt><wpt lat="50.084628444434266" lon="14.51869010925293"><name>10</name></wpt><wpt lat="50.08442191751289" lon="14.51918363571167"><name>11</name></wpt><wpt lat="50.0838298687399" lon="14.520385265350342"><name>12</name></wpt><wpt lat="50.08349941973336" lon="14.520578384399414"><name>13</name></wpt><wpt lat="50.083471882213324" lon="14.521071910858154"><name>14</name></wpt><wpt lat="50.08340303834402" lon="14.523067474365234"><name>15</name></wpt><wpt lat="50.08337550076859" lon="14.524397850036621"><name>16</name></wpt><wpt lat="50.08336173197496" lon="14.526135921478271"><name>Finish</name></wpt></gpx>
69 changes: 69 additions & 0 deletions res/raw/faketrack.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0"?>
<gpx version="1.1"
creator="Marengo Route Creator - http://www.marengo-ltd.com/map/"
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd">
<trk>
<name>New Route</name>
<trkseg>
<trkpt lat="50.08530309284275" lon="14.513046741485596">
<name>Start</name>
<time>2009-10-17T18:37:26Z</time>
</trkpt>
<trkpt lat="50.085427006824325" lon="14.513883590698242">
<name>1</name>
<time>2009-10-17T18:38:26Z</time>
</trkpt>
<trkpt lat="50.085206715080055" lon="14.514291286468506">
<name>2</name>
<time>2009-10-17T18:39:26Z</time>
</trkpt>
<trkpt lat="50.084945117318725" lon="14.514656066894531">
<name>3</name>
<time>2009-10-17T18:40:26Z</time>
</trkpt>
<trkpt lat="50.08479366533065" lon="14.515278339385986">
<name>4</name>
<time>2009-10-17T18:41:26Z</time>
</trkpt>
<trkpt lat="50.08480743371297" lon="14.515986442565918">
<name>5</name>
<time>2009-10-17T18:42:26Z</time>
</trkpt>
<trkpt lat="50.08482120209134" lon="14.517059326171875">
<name>6</name>
<time>2009-10-17T18:43:26Z</time>
</trkpt>
<trkpt lat="50.08471105495364" lon="14.518003463745117">
<name>7</name>
<time>2009-10-17T18:46:26Z</time>
</trkpt>
<trkpt lat="50.084683518129665" lon="14.518561363220215">
<name>8</name>
<time>2009-10-17T18:47:26Z</time>
</trkpt>
<trkpt lat="50.08450452838823" lon="14.519033432006836">
<name>9</name>
<time>2009-10-17T18:48:26Z</time>
</trkpt>
<trkpt lat="50.08433930649519" lon="14.519484043121338">
<name>10</name>
<time>2009-10-17T18:49:26Z</time>
</trkpt>
<trkpt lat="50.08395378653005" lon="14.520213603973389">
<name>11</name>
<time>2009-10-17T18:50:26Z</time>
</trkpt>
<trkpt lat="50.08371971932418" lon="14.520471096038818">
<name>12</name>
<time>2009-10-17T18:51:26Z</time>
</trkpt>
<trkpt lat="50.08352695723759" lon="14.520556926727295">
<name>End</name>
<time>2009-10-17T18:52:26Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>
46 changes: 46 additions & 0 deletions src/cz/cvut/fel/nur/zavody/Zavody.java
Original file line number Diff line number Diff line change
@@ -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;
// }
}
22 changes: 4 additions & 18 deletions src/cz/cvut/fel/nur/zavody/activity/NormalMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -22,7 +23,7 @@
public class NormalMode extends MapActivity {

private MapController _controller;
private MyLocationOverlay _myLocationOverlay;
private UserOverlay _myLocationOverlay;
private MapView _mapView;

/**
Expand All @@ -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);


Expand Down
7 changes: 4 additions & 3 deletions src/cz/cvut/fel/nur/zavody/maps/FinishOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@

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;

/**
*
* @author saljack
*/
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(),
Expand Down
8 changes: 7 additions & 1 deletion src/cz/cvut/fel/nur/zavody/maps/RaceOverlays.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
public class RaceOverlays extends ItemizedOverlay<OverlayItem> {

private Context _ctx;
private FinishOverlay _finish;
private List<OverlayItem> _items = new ArrayList<OverlayItem>(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();
}
Expand All @@ -46,4 +48,8 @@ protected OverlayItem createItem(int i) {
public int size() {
return _items.size();
}

public FinishOverlay getFinishOverlay() {
return _finish;
}
}
56 changes: 56 additions & 0 deletions src/cz/cvut/fel/nur/zavody/maps/UserOverlay.java
Original file line number Diff line number Diff line change
@@ -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);

}
}

0 comments on commit 7b80d72

Please sign in to comment.