diff --git a/FindMyCarLib/res/layout/map.xml b/FindMyCarLib/res/layout/map.xml
index 4e31b3d..9ed1dc6 100755
--- a/FindMyCarLib/res/layout/map.xml
+++ b/FindMyCarLib/res/layout/map.xml
@@ -12,23 +12,18 @@
android:layout_alignParentTop="true"
layout="@layout/distancebar" />
-
-
-
+
-
+
+
@@ -47,7 +42,7 @@
android:textStyle="bold" />
0.009144){
+ Log.d(TAG, "FMC onLocationChanged()");
+
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ mHandler.sendMessage(mHandler.obtainMessage(ACCURACY,
+ distance(accuracy / 1E3)));
+
+ // if (point != null)
+ // if(isShowingBoth)
+ // if(GeoUtils.isPointOffMap(mMap.getMap(),point) ||
+ // GeoUtils.isPointOffMap(mMap.getMap(), mCarPoint))
+ // mHandler.sendEmptyMessage(SHOWBOTH);
+ //
+ if (mCarPoint != null && point != null) {
+ double distance = GeoUtils.distanceKm(point, mCarPoint);
+ mHandler.sendMessage(mHandler.obtainMessage(DISTANCE,
+ distance(distance)));
+
+ // value is set in KM. if user has gone 30 feet from car app
+ // is set to check for arrival
+ if (distance > 0.009144) {
hasLeftCar = true;
}
- //if user has gone back into 30 foot radius and has not found the car and has left the car then notify user of finding of car
- if (distance <= 0.009144 && isCarFound == false && hasLeftCar == true){
+ // if user has gone back into 30 foot radius and has not
+ // found the car and has left the car then notify user of
+ // finding of car
+ if (distance <= 0.009144 && isCarFound == false
+ && hasLeftCar == true) {
isCarFound = true;
-
+
mHandler.sendEmptyMessage(FOUND_CAR);
}
- }
+ }
}
}).start();
-
+
}
/**
- * handles menu selection
+ * handles menu selection
+ *
* @since 0.0.2
* @author ricky barrette 3-30-2010
*/
@Override
- public boolean onOptionsItemSelected (MenuItem item) {
- if(item.getItemId() == R.id.delete_car)
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.delete_car)
removeCar();
- else if (item.getItemId() == R.id.settings) {
+ else if (item.getItemId() == R.id.settings) {
startActivity(new Intent().setClass(getActivity(), Settings.class));
return true;
} else if (item.getItemId() == R.id.map_mode)
changeMapMode();
-
+
return false;
}
-
-
- /**
- * (non-Javadoc)
- * @see android.support.v4.app.Fragment#onPause()
- */
- @Override
- public void onPause() {
- mUserOverlay.disableCompass();
- mUserOverlay.disableMyLocation();
- mMapView.getOverlays().remove(mUserOverlay);
- mUserOverlay = null;
- super.onPause();
- }
-
- /**
- * Called each time the menu is created starting with the second instance.
- * Used to dynamicly modify the options menu
- */
-
+
/**
* (non-Javadoc)
+ *
* @see android.support.v4.app.Fragment#onResume()
*/
@Override
public void onResume() {
- if(mUserOverlay == null)
- mUserOverlay = new SkyHookUserOverlay(mMapView, getActivity());
-
- mMapView.getOverlays().add(mUserOverlay);
-
- //start all location based services
- mUserOverlay.enableMyLocation();
- if(!isGPSDialogEnabled)
- mUserOverlay.disableGPSDialog();
-
- mUserOverlay.registerListener(this);
- mUserOverlay.enableCompass();
-
loadSettings();
super.onResume();
}
-
- /**
- * reorders the overlays to the UserOverlay always on top
- * @author ricky barrette
- */
- private void reorderOverlays() {
- mMapView.getOverlays().remove(mUserOverlay);
- mMapView.getOverlays().add(mUserOverlay);
- }
/**
- * removes the previous car overlay and replaces it with a new car overlay that
- * represents the users car at a specific geopoint
+ * removes the previous car overlay and replaces it with a new car overlay
+ * that represents the users car at a specific geopoint
*
- * @param point for geopoint of car
+ * @param point
+ * for geopoint of car
* @author WWPowers 3-31-2010
* @author ricky barrette
*/
public void setCar(GeoPoint point) {
isCarFound = false;
- hasLeftCar = false;
+ hasLeftCar = false;
mCarPoint = point;
mCarOverlay = new FindMyCarOverlay(getActivity(), point);
- mMapView.getOverlays().add(mCarOverlay);
- mUserOverlay.setDestination(mCarPoint);
- reorderOverlays();
+ mMap.getMap().getOverlays().add(mCarOverlay);
+ mMap.setDestination(mCarPoint);
}
-
+
+// /**
+// * enables the GPS dialog
+// *
+// * @param b
+// * @author ricky barrette
+// */
+// public void setGPSDialogEnabled(boolean b) {
+// if (mMap != null)
+// if (b)
+// mMap.enableGPSDialog();
+// else
+// mMap.disableGPSDialog();
+// }
+
/**
- * enables the GPS dialog
- * @param b
- * @author ricky barrette
- */
- public void setGPSDialogEnabled(boolean b) {
- isGPSDialogEnabled = b;
- if(mUserOverlay != null)
- if(b)
- mUserOverlay.enableGPSDialog();
- else
- mUserOverlay.disableGPSDialog();
- }
-
- /**
- * Sets up the UI handler.
- * The UI handler will process messages from processing threads
+ * Sets up the UI handler. The UI handler will process messages from
+ * processing threads
*
* @author ricky barrette
*/
private void setUiHandler() {
- mHandler = new Handler(){
+ mHandler = new Handler() {
@Override
- public void handleMessage(Message msg){
- switch(msg.what){
- case ACCURACY:
- mAccuracy.setText( (String) msg.obj );
- break;
- case DISTANCE:
- mDistance.setText((String) msg.obj);
- break;
- case FOUND_CAR:
- /* remove the directions overlay & delete all navigation files when the car is found
- * this will prevent old directions from being displayed after the car is found.
- */
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case ACCURACY:
+ mAccuracy.setText((String) msg.obj);
+ break;
+ case DISTANCE:
+ mDistance.setText((String) msg.obj);
+ break;
+ case FOUND_CAR:
+ /*
+ * remove the directions overlay & delete all navigation
+ * files when the car is found this will prevent old
+ * directions from being displayed after the car is found.
+ */
- if(mDirections != null) {
- mDirections.removePath();
- mDirections = null;
- }
-
- Vibrator vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
- new AlertDialog.Builder(getActivity())
+ if (mDirections != null) {
+ mDirections.removePath();
+ mDirections = null;
+ }
+
+ Vibrator vib = (Vibrator) getActivity().getSystemService(
+ Context.VIBRATOR_SERVICE);
+ new AlertDialog.Builder(getActivity())
.setTitle(R.string.yay)
- .setMessage(R.string.found_car).setCancelable(false)
- .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
-
- }
- }).show();
- vib.vibrate(100);
- mDistance.setText("0");
- break;
- case SHOWBOTH:
- showBoth();
- break;
- case MIDPOINT:
- MidPoint mp = (MidPoint) msg.obj;
- panToGeoPoint(mp.getMidPoint(), false);
- mp.zoomToSpan(mMapView);
- break;
-
+ .setMessage(R.string.found_car)
+ .setCancelable(false)
+ .setPositiveButton(R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(
+ DialogInterface dialog, int id) {
+
+ }
+ }).show();
+ vib.vibrate(100);
+ mDistance.setText("0");
+ break;
+ case SHOWBOTH:
+ showBoth();
+ break;
+ case MIDPOINT:
+ MidPoint mp = (MidPoint) msg.obj;
+ panToGeoPoint(mp.getMidPoint(), false);
+ mp.zoomToSpan(mMap.getMap());
+ break;
+
}
}
};
}
/**
- * computes a geopoint the is the central geopoint between the user and the car.
- * also it zooms so both marks are visible on the map
+ * computes a geopoint the is the central geopoint between the user and the
+ * car. also it zooms so both marks are visible on the map
+ *
* @author ricky barrette
*/
- protected void showBoth(){
- if(mUserOverlay != null) {
- if (mCarPoint == null){
- Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
- } else if (mUserOverlay.getUserLocation() == null){
- Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
+ protected void showBoth() {
+ if (mMap != null) {
+ if (mCarPoint == null) {
+ Toast.makeText(getActivity(), R.string.mark_car_first,
+ Toast.LENGTH_LONG).show();
+ } else if (mMap.getUserLocation() == null) {
+ Toast.makeText(getActivity(), R.string.no_gps_signal,
+ Toast.LENGTH_LONG).show();
} else {
- if (mMapView != null) {
- mMapView.getController().stopAnimation(false);
- mUserOverlay.followUser(false);
-// isShowingBoth = true;
- final GeoPoint user = mUserOverlay.getUserLocation();
-
+ if (mMap.getMap() != null) {
+ mMap.getMap().getController().stopAnimation(false);
+ mMap.followUser(false);
+ // isShowingBoth = true;
+ final GeoPoint user = mMap.getUserLocation();
+
/*
- * here we null check our next set of value before we send them off to geoutils
- * if they have became null for some reason we disable show both mode
+ * here we null check our next set of value before we send
+ * them off to geoutils if they have became null for some
+ * reason we disable show both mode
*/
- if(mCarPoint!= null && user != null){
- new Thread(new Runnable(){
+ if (mCarPoint != null && user != null) {
+ new Thread(new Runnable() {
@Override
- public void run(){
- mHandler.sendMessage(mHandler.obtainMessage(MIDPOINT, GeoUtils.midPoint(mCarPoint, user)));
+ public void run() {
+ mHandler.sendMessage(mHandler.obtainMessage(
+ MIDPOINT,
+ GeoUtils.midPoint(mCarPoint, user)));
}
}).start();
-
- }
-// else
-// isShowingBoth = false;
-
-
+
+ }
+ // else
+ // isShowingBoth = false;
+
} else {
- Log.e(TAG, "showBoth.mMapView is null");
+ Log.e(TAG, "showBoth.mMap.getMap() is null");
}
}
}
@@ -557,6 +550,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
/**
* Sets the listener for this map fragment
+ *
* @param listener
* @author ricky barrette
*/
@@ -568,7 +562,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
public void onClick(View v) {
if (v.getId() == R.id.show_both)
showBoth();
- else if(v.getId() == R.id.mark_my_location)
+ else if (v.getId() == R.id.mark_my_location)
markMyLocation();
else if (v.getId() == R.id.my_location)
myLocation();
@@ -577,33 +571,38 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
else if (v.getId() == R.id.map_mode)
changeMapMode();
else if (v.getId() == R.id.parking_timer)
- if (! Main.isFull)
+ if (!Main.isFull)
Main.featureInFullDialog(getActivity());
else
- getActivity().startActivity(new Intent(getActivity(), ParkignTimerActivity.class));
+ getActivity().startActivity(
+ new Intent(getActivity(), ParkignTimerActivity.class));
}
/**
* Marks the user's location
+ *
* @author ricky barrette
*/
private void markMyLocation() {
- mUserOverlay.followUser(true);
-// isShowingBoth = false;
-
+ mMap.followUser(true);
+ // isShowingBoth = false;
+
/*
- * if we have a gps signal, then pan to user location and then
- * if there is no car, mark the car location as the users location
- * else show mark car dialog
+ * if we have a gps signal, then pan to user location and then if there
+ * is no car, mark the car location as the users location else show mark
+ * car dialog
*
- * we switch from MyLocationOverlay.getMyLocation() to referencing the static variable MyCustomLocationOverlay.gpUser
- * because for some reason getMyLocation() would become null.
- * @author ricky barrette
+ * we switch from MyLocationOverlay.getMyLocation() to referencing the
+ * static variable MyCustomLocationOverlay.gpUser because for some
+ * reason getMyLocation() would become null.
+ *
+ * @author ricky barrette
*/
- if (! panToGeoPoint(mUserOverlay.getUserLocation(), true)){
- Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
+ if (!panToGeoPoint(mMap.getUserLocation(), true)) {
+ Toast.makeText(getActivity(), R.string.no_gps_signal,
+ Toast.LENGTH_LONG).show();
} else {
- if (mCarPoint != null){
+ if (mCarPoint != null) {
markCarDialog();
} else {
markCar();
@@ -613,102 +612,116 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
/**
* pans the map to the user's location
+ *
* @author ricky barrette
*/
private void myLocation() {
- mUserOverlay.followUser(true);
-// isShowingBoth = false;
-
+ mMap.followUser(true);
+ // isShowingBoth = false;
+
/*
- * if we have a gps signal, then pan to user location
- * else notify user that there is no GPS signal
+ * if we have a gps signal, then pan to user location else notify user
+ * that there is no GPS signal
*
- * we switch from MyLocationOverlay.getMyLocation() to referencing the static variable MyCustomLocationOverlay.gpUser
- * because for some reason getMyLocation() would become null.
- * @author ricky barrette
+ * we switch from MyLocationOverlay.getMyLocation() to referencing the
+ * static variable MyCustomLocationOverlay.gpUser because for some
+ * reason getMyLocation() would become null.
+ *
+ * @author ricky barrette
*/
- if (! panToGeoPoint(mUserOverlay.getUserLocation(), true)){
- Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
- }
+ if (!panToGeoPoint(mMap.getUserLocation(), true)) {
+ Toast.makeText(getActivity(), R.string.no_gps_signal,
+ Toast.LENGTH_LONG).show();
+ }
}
/**
- * Displays the walking directions on the map
+ * Displays the walking directions on the map
+ *
* @author ricky barrette
*/
private void directions() {
if (Main.isFull) {
/*
- * if there is no car marked, then notify user
- * else check to see if there is directions
+ * if there is no car marked, then notify user else check to see if
+ * there is directions
*/
if (mCarPoint == null) {
- Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
+ Toast.makeText(getActivity(), R.string.mark_car_first,
+ Toast.LENGTH_LONG).show();
} else {
-
+
/*
* Remove old directions if the exist
*/
- if(mDirections != null)
+ if (mDirections != null)
mDirections.removePath();
-
- /*
- * if there is no location fix then notify user
- * else download directions and display them
- */
- if (mUserOverlay.getUserLocation() == null) {
- Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
- } else {
-
- mProgress = ProgressDialog.show(getActivity(), getText(R.string.directions), getText(R.string.calculating), true);
- new Thread(new Runnable(){
- /**
- * Notifys user about the error that occurred outside of the UI thread
- * @param e
- * @author ricky barrette
- */
- public void notify(final Exception e){
- e.printStackTrace();
- getActivity().runOnUiThread(new Runnable(){
- @Override
- public void run(){
- Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
- mProgress.dismiss();
- }
- });
- }
-
- @Override
- public void run(){
- try {
- mDirections = new DirectionsOverlay(mMapView, mUserOverlay.getUserLocation(), mCarPoint, MapFragment.this);
- } catch (IllegalStateException e) {
- notify(e);
- } catch (ClientProtocolException e) {
- notify(e);
- } catch (IOException e) {
- notify(e);
- } catch (JSONException e) {
- notify(e);
- }
- }
- }).start();
+ /*
+ * if there is no location fix then notify user else download
+ * directions and display them
+ */
+ if (mMap.getUserLocation() == null) {
+ Toast.makeText(getActivity(), R.string.no_gps_signal,
+ Toast.LENGTH_LONG).show();
+ } else {
- }
+ mProgress = ProgressDialog.show(getActivity(),
+ getText(R.string.directions),
+ getText(R.string.calculating), true);
+ new Thread(new Runnable() {
+
+ /**
+ * Notifys user about the error that occurred outside of
+ * the UI thread
+ *
+ * @param e
+ * @author ricky barrette
+ */
+ public void notify(final Exception e) {
+ e.printStackTrace();
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(getActivity(),
+ e.getMessage(), Toast.LENGTH_LONG)
+ .show();
+ mProgress.dismiss();
+ }
+ });
+ }
+
+ @Override
+ public void run() {
+ try {
+ mDirections = new DirectionsOverlay(mMap.getMap(), mMap.getUserLocation(), mCarPoint, MapFragment.this);
+ } catch (IllegalStateException e) {
+ notify(e);
+ } catch (ClientProtocolException e) {
+ notify(e);
+ } catch (IOException e) {
+ notify(e);
+ } catch (JSONException e) {
+ notify(e);
+ }
+ }
+ }).start();
+
+ }
}
-
+
} else
Main.featureInFullDialog(getActivity());
}
/**
* changes the map mode
+ *
* @author ricky barrette
*/
private void changeMapMode() {
- if(mMapView != null)
- mMapView.setSatellite(!mMapView.isSatellite());
+ if (mMap.getMap() != null)
+ mMap.getMap().setSatellite(!mMap.getMap().isSatellite());
}
-
+
}
\ No newline at end of file