Browse files

Merge branch 'master' of ssh://github.com/phyrex1an/PathPal

  • Loading branch information...
2 parents 16a78e6 + a93b3a4 commit 9227f31c0738b463699819b4a6c3b19803742693 @phyrex1an committed May 6, 2011
View
3 AndroidManifest.xml
@@ -4,6 +4,9 @@
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
+
+
<application android:icon="@drawable/icon" android:label="@string/app_name">
View
1 res/menu/gmapmenu.xml
@@ -3,4 +3,5 @@
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/find_path" android:title="Find path"></item>
<item android:id="@+id/exit" android:title="Exit"></item>
+<item android:id="@+id/your_location" android:title="Toggle follow your location"></item>
</menu>
View
BIN res/raw/locator.pgf
Binary file not shown.
View
137 src/org/pathpal/GMapsActivity.java
@@ -11,12 +11,9 @@
import android.app.AlertDialog;
import android.app.Dialog;
-import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -34,9 +31,7 @@
import android.view.MenuInflater;
import android.view.MenuItem;
-
import com.amelie.driving.DrivingDirections;
-import com.amelie.driving.Placemark;
import com.amelie.driving.Route;
import com.amelie.driving.DrivingDirections.IDirectionsListener;
import com.amelie.driving.DrivingDirections.Mode;
@@ -49,75 +44,40 @@
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;
-public class GMapsActivity extends MapActivity implements IDirectionsListener {
+public class GMapsActivity extends MapActivity implements IDirectionsListener, LocationListener {
private MapView mapView;
private Projection projection;
private CustomItemizedOverlay itemizedOverlay;
- private GeoPoint gpsPoint;
private MapController mapController;
+ private MyLocationOverlay myLocationOverlay;
+
private List<Overlay> mapOverlays;
+
+ private boolean follow_your_location;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gmapslayout);
+ follow_your_location = true;
+
mapView = (MapView) findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
projection = mapView.getProjection();
- DrivingDirections dd = new DrivingDirectionsGoogleKML();
- GeoPoint gp_start = new GeoPoint(37985339, 23716735);
- GeoPoint gp_end = new GeoPoint(38036160, 23787610);
- dd.driveTo(gp_start, gp_end, Mode.DRIVING, this);
-
-/* Geocoder gc = new Geocoder(getApplicationContext());
- try {
- System.out.println("HEJSAN");
- System.out.println("HEJSAN");
- System.out.println("HEJSAN");
- System.out.println("HEJSAN");
- System.out.println("HEJSAN");
- System.out.println("HEJSAN");
- System.out.println("HEJSAN");
- System.out.println("HEJSAN");
- List<Address> hej = gc.getFromLocationName("ullevi", 10);
- for(Address a : hej){
- System.out.println("=======================" + a.getAddressLine(0));
- System.out.println("=======================" + a.getAddressLine(1));
- System.out.println("=======================" + a.getAddressLine(2));
- System.out.println("=======================" + a.getFeatureName());
- System.out.println("=======================" + a.getFeatureName());
- System.out.println("=======================" + a.getFeatureName());
- System.out.println("=======================" + a.getFeatureName());
- System.out.println("=======================" + a.getFeatureName());
- System.out.println("=======================" + a.getFeatureName());
- System.out.println("=======================" + a.getFeatureName());
- }
- System.out.println("Getting current location");
- LocationManager lm = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
- if (lm == null) System.out.println("lm is null");
- Location l = lm.getLastKnownLocation(lm.getBestProvider(new Criteria(), true));
- if (l == null) System.out.println("l is null");
- double lon = l.getLongitude();
- double lat = l.getLatitude();
- System.out.println("Printing current location");
- for (Address adr : gc.getFromLocation(lat, lon, 1)) {
- System.out.println(adr.getAddressLine(0) + "; " + adr.getAddressLine(1));
- }
-
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-*/
+
+ LocationManager lm = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
+ lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this);
+
mapController = mapView.getController();
- mapController.animateTo(gp_start);
- mapController.setZoom(10);
+ mapController.setZoom(14);
+
}
@@ -195,6 +155,8 @@ public void draw(Canvas canvas, MapView mapv, boolean shadow){
}
+
+
// define the menu from the XML
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -205,6 +167,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
static final int FIND_PATH_REQUEST_CODE = 0;
+ static final int YOUR_LOCATION_REQUEST_CODE = 1;
// method to handle a menu button action when you press the menu button
@Override
@@ -218,6 +181,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
Intent myIntent = new Intent(this, GMapsFindPathActivity.class);
startActivityForResult(myIntent, FIND_PATH_REQUEST_CODE);
return true;
+ case R.id.your_location:
+ if (follow_your_location) {
+ follow_your_location = false;
+ mapController.animateTo(myLocationOverlay.getGeoPoint());
+ }else{
+ follow_your_location = true;
+ }
+
default:
return super.onOptionsItemSelected(item);
}
@@ -248,7 +219,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
boolean work =TranslatorApi.translateString(nlp, directionForm, getResources().openRawResource(R.raw.locator));
if(!work){
- System.out.println("ERORORORORORRO ====================");
+ System.out.println("ERROR: Could not parse");
return;
}
directionForm.startAt("ullevi");
@@ -264,15 +235,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
e1.printStackTrace();
}
-
-
-
- // directionForm.goToAddress(to);
-
-
-
-
- // DO SOMETHING WITH THE RESULT FROM FIND_PATH
Address fromAddress = null;
Address toAddress = null;
try {
@@ -286,8 +248,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("==================" + fromAddress.getLatitude() + "===============" + (int) (fromAddress.getLatitude()*convert));
- GeoPoint startPos = new GeoPoint((int) (fromAddress.getLatitude()*convert), (int) (fromAddress.getLongitude()*convert));
- GeoPoint endPos = new GeoPoint((int) (toAddress.getLatitude()*convert), (int) (toAddress.getLongitude() * convert) );
+ GeoPoint startPos = geopointfromDouble(fromAddress.getLatitude(), fromAddress.getLongitude());
+ GeoPoint endPos = geopointfromDouble(toAddress.getLatitude(), toAddress.getLongitude());
DrivingDirections dd = new DrivingDirectionsGoogleKML();
dd.driveTo(startPos, endPos, Mode.DRIVING, this);
mapController.animateTo(startPos);
@@ -301,11 +263,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
} catch (IOException e) {
e.printStackTrace();
} catch (IndexOutOfBoundsException e){
- showDialog(NO_PATH_ID);
- // Builder noPathDialog = new AlertDialog.Builder(getApplicationContext());
- // noPathDialog.setMessage("Could not find path, try another one!");
- // noPathDialog.show();
-
+ showDialog(NO_PATH_ID);
}
@@ -334,4 +292,41 @@ public void onClick(DialogInterface dialog, int id) {
return d;
}
+ protected GeoPoint geopointfromDouble(double latitude, double longitude){
+ final int convert = 1000000;
+ return new GeoPoint( ((int)(latitude * convert)) , ((int)(longitude * convert)) );
+ }
+
+
+
+ public void onLocationChanged(Location location) {
+ if (location != null) {
+ double lat = location.getLatitude();
+ double lng = location.getLongitude();
+ GeoPoint p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
+
+ mapView.getOverlays().remove(myLocationOverlay);
+ myLocationOverlay = new MyLocationOverlay(p);
+ mapView.getOverlays().add(myLocationOverlay);
+
+ if(follow_your_location)
+ mapController.animateTo(p);
+ }
+ }
+
+ public void onProviderDisabled(String provider) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onProviderEnabled(String provider) {
+ // TODO Auto-generated method stub
+ }
+
+ public void onStatusChanged(String provider, int status, Bundle extras) {
+ // TODO Auto-generated method stub
+
+ }
+
+
}
View
41 src/org/pathpal/MyLocationOverlay.java
@@ -0,0 +1,41 @@
+package org.pathpal;
+
+import com.google.android.maps.GeoPoint;
+import com.google.android.maps.MapView;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+class MyLocationOverlay extends com.google.android.maps.Overlay {
+
+ private GeoPoint p;
+ public MyLocationOverlay(GeoPoint p) {
+ this.p = p;
+ }
+
+ @Override
+ public void draw(Canvas canvas, MapView mapView, boolean shadow) {
+
+ super.draw(canvas, mapView, shadow);
+ Paint paint = new Paint();
+ // Converts lat/lng-Point to OUR coordinates on the screen.
+ Point myScreenCoords = new Point();
+ mapView.getProjection().toPixels(p, myScreenCoords);
+ paint.setStrokeWidth(1);
+ paint.setARGB(255, 255, 255, 255);
+ paint.setStyle(Paint.Style.STROKE);
+ Bitmap bmp = BitmapFactory.decodeResource(mapView.getResources(), R.drawable.icon);
+ canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
+ canvas.drawText("YOU", myScreenCoords.x, myScreenCoords.y, paint);
+
+
+ }
+
+ public GeoPoint getGeoPoint() {
+ // TODO Auto-generated method stub
+ return p;
+ }
+}
View
17 src/org/pathpal/grammar/Locator.gf
@@ -0,0 +1,17 @@
+abstract Locator = {
+ flags startcat = Phrase ;
+ cat
+ Phrase;
+ Adress;
+ AdressTree;
+ StoreType;
+ Answer;
+ fun
+ GoTo : AdressTree -> Phrase ;
+ AdressT : String -> AdressTree -> AdressTree;
+ AdressL : String -> AdressTree;
+ GoFromTo : AdressTree -> AdressTree -> Phrase;
+ FindStore : StoreType -> Phrase ;
+ WalkOrTrans : Answer -> Phrase;
+ Walking, Transportation: Answer;
+}
View
16 src/org/pathpal/grammar/LocatorEng.gf
@@ -0,0 +1,16 @@
+concrete LocatorEng of Locator = {
+ lincat
+ Phrase,Adress,StoreType,Answer,AdressTree= {s : Str} ;
+ lin
+ GoTo it = {s = "I need to go to" ++ it.s} ;
+ GoFromTo it it' = {s = "I need to go from" ++ it.s ++ "to" ++ it'.s} ;
+ FindStore it = {s = "Where is the nearest" ++ it.s ++ "store"} ;
+
+ AdressT i i' = {s = i.s ++ i'.s} ;
+ AdressL i = {s = i.s} ;
+
+ WalkOrTrans item = {s = item.s} ;
+
+ Walking = {s = "Walking"} ;
+ Transportation = {s = "Transportation"} ;
+}
View
16 src/org/pathpal/grammar/LocatorSwe.gf
@@ -0,0 +1,16 @@
+concrete LocatorSwe of Locator = {
+ lincat
+ Phrase,Adress,StoreType,Answer,AdressTree= {s : Str} ;
+ lin
+ GoTo it = {s = "Jag måste gå till" ++ it.s} ;
+ GoFromTo i i' = {s = "Jag måste gå från" ++ i.s ++ "till" ++ i'.s} ;
+ FindStore item = {s = "Var är närmaste" ++ item.s} ;
+
+ AdressT i i' = {s = i.s ++ i'.s} ;
+ AdressL i = {s = i.s} ;
+
+ WalkOrTrans item = {s = item.s} ;
+
+ Walking = {s = "Gående"} ;
+ Transportation = {s = "Transport"} ;
+}

0 comments on commit 9227f31

Please sign in to comment.