Finished converting FMC over to the new SkyHookUserOverlayMapFragment

Change-Id: I9059afeec89b5e5fea735c3800b7465bb9ff6e72
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-03-04 14:43:23 -05:00
parent bdeb5cbe02
commit 186ad1703f
3 changed files with 388 additions and 379 deletions

View File

@@ -12,23 +12,18 @@
android:layout_alignParentTop="true"
layout="@layout/distancebar" />
<!-- ricky beta release 0rKmsWMM0D-IRAEgcSZEqwZCs_8AUwxjYjj0bnA -->
<!-- ricky 0rKmsWMM0D-KC9KXr1WbA5aEb-2ozQ0SHTvV46g -->
<!-- TWENTYCODES 0rKmsWMM0D-K15bEM_kwabPbNhsn4dp4rcq2q5Q -->
<fragment
android:id="@+id/map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.TwentyCodes.android.SkyHook.SkyHoookUserOverlayMapFragment" >
<com.TwentyCodes.android.location.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/buttons"
android:layout_below="@id/table"
android:apiKey="0rKmsWMM0D-K15bEM_kwabPbNhsn4dp4rcq2q5Q"
android:clickable="true" />
<!-- Preview: layout=@layout/map_fragment -->
</fragment>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/mapview"
android:id="@id/map_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/table" />
@@ -47,7 +42,7 @@
android:textStyle="bold" />
<include
android:id="@id/buttons"
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"

View File

@@ -128,9 +128,9 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
*/
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
enableGPSdialog(Main.this);
else
if(mMap != null)
mMap.setGPSDialogEnabled(true);
// else
// if(mMap != null)
// mMap.setGPSDialogEnabled(true);
/*
* the map is no longer needed, clear it from memory
@@ -448,7 +448,7 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
* Shows the splash screen over the full Activity
*/
protected void showSplashScreen() {
mMap.setGPSDialogEnabled(false);
// mMap.setGPSDialogEnabled(false);
mSplashDialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
mSplashDialog.setContentView(R.layout.powered_by_skyhook);
mSplashDialog.setCancelable(false);
@@ -498,9 +498,10 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
*/
if(mSettings.getInt(Settings.BUILD_NUMBER, 0) < build_number || Debug.FORCE_FIRSTBOOT_DIALOG){
displayWelcomeDialog();
} else {
mMap.setGPSDialogEnabled(true);
}
// else {
// mMap.setGPSDialogEnabled(true);
// }
mSettings.edit().putInt(Settings.BUILD_NUMBER, build_number).commit();
} catch (NameNotFoundException e) {

View File

@@ -18,14 +18,12 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -43,7 +41,7 @@ import com.TwentyCodes.android.FindMyCarLib.Settings;
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay;
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay.OnDirectionsCompleteListener;
import com.TwentyCodes.android.FindMyCarLib.UI.FindMyCarOverlay;
import com.TwentyCodes.android.SkyHook.SkyHookUserOverlay;
import com.TwentyCodes.android.SkyHook.SkyHoookUserOverlayMapFragment;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.GeoUtils;
import com.TwentyCodes.android.location.MapView;
@@ -52,6 +50,7 @@ import com.google.android.maps.GeoPoint;
/**
* this is the main class FindMyCar Full
*
* @author WWPowers
* @author ricky barrette
*/
@@ -71,23 +70,25 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
public static TextView mDistance;
public static boolean isMetric = true;
public static TextView mAccuracy;
public static SkyHookUserOverlay mUserOverlay;
public static MapView mMapView;
private SharedPreferences mSettings;
private Handler mHandler;
private ProgressDialog mProgress;
private boolean isGPSDialogEnabled = true;
protected DirectionsOverlay mDirections;
private MapFragmentListener mListener;
private SkyHoookUserOverlayMapFragment mMap;
public interface MapFragmentListener {
public void onCarDeleted();
public void onDirectionsDisplayed(DirectionsOverlay directions);
}
/**
* returns a string distance that is based on the users measurement unit preference
* @param distance in kilometers
* returns a string distance that is based on the users measurement unit
* preference
*
* @param distance
* in kilometers
* @return string distance
* @author ricky barrette
*/
@@ -97,9 +98,9 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
/*
* if blnUnit is true, the distance computed will be in metric units,
* else, standard units are used
* meters are used until 1 kilometer is reached, then kilometers are used
* feet are used until 1 mile is reached, then miles are used
* else, standard units are used meters are used until 1 kilometer is
* reached, then kilometers are used feet are used until 1 mile is
* reached, then miles are used
*/
if (isMetric) {
if (distance < 1) {
@@ -117,23 +118,26 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
}
/**
* pans maps to where the a geopoint is, and if zoomIn is true, zooms in to level 20
* @param GeoPoint point - lat and lon of point to pan to
* pans maps to where the a geopoint is, and if zoomIn is true, zooms in to
* level 20
*
* @param GeoPoint
* point - lat and lon of point to pan to
* @param boolean zoomIn - true if map needs to be zoomed in
* @return boolean false it geopoint is null
* @author ricky barrette
*/
public boolean panToGeoPoint(GeoPoint point, boolean zoomIn) {
if (point != null) {
if (mMapView != null) {
if (mMap != null) {
try {
mMapView.getController().stopAnimation(false);
mMapView.getController().setCenter(point);
mMap.getMap().getController().setCenter(point);
} catch (Exception e) {
e.printStackTrace();
}
if (zoomIn) {
mMapView.getController().setZoom((mMapView.getMaxZoomLevel() - 2));
mMap.getMap().getController()
.setZoom((mMap.getMap().getMaxZoomLevel() - 2));
}
} else {
Log.e(TAG, "panToGeoPoint call. mapcontroller was null");
@@ -147,6 +151,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
/**
* removes the car overlay from the mapview.
*
* @return true if successful
* @author ricky barrette
*/
@@ -163,7 +168,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
}
try {
mMapView.getOverlays().remove(mCarOverlay);
mMap.getMap().getOverlays().remove(mCarOverlay);
} catch (Exception e) {
return false;
}
@@ -171,11 +176,12 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
}
public MapView getMap() {
return mMapView;
return mMap.getMap();
}
/**
* loads saved settings from files
*
* @author ricky barrette
*/
private void loadSettings() {
@@ -201,24 +207,20 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
// load compass options
String compass_option = mSettings.getString(Settings.COMPASS_OPTION, "Small");
int px;
Resources r = getResources();
if (compass_option.equalsIgnoreCase("Large")) {
px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 110, r.getDisplayMetrics());
mUserOverlay.setCompassDrawables(R.drawable.needle_lrg, R.drawable.compass_lrg, px, px);
mMap.setCompassDrawables(R.drawable.needle_lrg, R.drawable.compass_lrg, 110, 110);
} else if (compass_option.equalsIgnoreCase("Small")) {
px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, r.getDisplayMetrics());
mUserOverlay.setCompassDrawables(R.drawable.needle_sm, R.drawable.compass_sm, px, px);
mMap.setCompassDrawables(R.drawable.needle_sm, R.drawable.compass_sm, 40, 40);
} else {
px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, r.getDisplayMetrics());
mUserOverlay.setCompassDrawables(R.drawable.needle_med, R.drawable.compass_med, px, px);
mMap.setCompassDrawables(R.drawable.needle_med, R.drawable.compass_med, 70, 70);
}
}
/**
* using the users lat/lon saves car location to lat/lon files and passes that geopoint info to setCar
* also writes address to notes
* using the users lat/lon saves car location to lat/lon files and passes
* that geopoint info to setCar also writes address to notes
*
* @author ricky barrette 3-31-2010
* @author WWPowers 3-31-2010
*/
@@ -226,78 +228,87 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
// removed old parking timer
// ParkingTimerDialog.stopTimer(this);
GeoPoint user = mUserOverlay.getUserLocation();
GeoPoint user = mMap.getUserLocation();
/*
* if the user location is not null then
* save car lat and lon to files
* pass geopoint info to set car, which will setup and show the car overlay
* get address info and add it to the notes file
* if the user location is not null then save car lat and lon to files
* pass geopoint info to set car, which will setup and show the car
* overlay get address info and add it to the notes file
*
* else inform user that they dont have a gps signal
*/
if (user != null) {
mSettings.edit()
.putInt(Settings.LAT, user.getLatitudeE6())
.putInt(Settings.LON, user.getLongitudeE6())
.commit();
mSettings.edit().putInt(Settings.LAT, user.getLatitudeE6())
.putInt(Settings.LON, user.getLongitudeE6()).commit();
setCar(user);
// TODO get address
} else {
Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), R.string.no_gps_signal,
Toast.LENGTH_LONG).show();
}
}
/**
* ask user if they want to replace current car marker with a new one
*
* @since 0.1.1
* @author ricky barrette
*/
public void markCarDialog() {
new AlertDialog.Builder(getActivity())
.setMessage(R.string.mark_car_warning).setCancelable(false)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
.setMessage(R.string.mark_car_warning)
.setCancelable(false)
.setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
removeCar();
markCar();
dialog.cancel();
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
.setNegativeButton(R.string.no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.show();
}).show();
}
/**
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateOptionsMenu(android.view.Menu, android.view.MenuInflater)
*
* @see android.support.v4.app.Fragment#onCreateOptionsMenu(android.view.Menu,
* android.view.MenuInflater)
*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.map_action_bar, menu);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.google.android.maps.MapActivity#onCreate(android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
container.removeAllViews();
View view = inflater.inflate(R.layout.map, container, false);
mMapView = (MapView) view.findViewById(R.id.mapview);
mMap = (SkyHoookUserOverlayMapFragment) getFragmentManager()
.findFragmentById(R.id.map_fragment);
setUiHandler();
mAccuracy = (TextView) view.findViewById(R.id.tvAccuracy2);
mDistance = (TextView) view.findViewById(R.id.tvDistance2);
mSettings = getActivity().getSharedPreferences(Settings.SETTINGS, Context.MODE_WORLD_WRITEABLE);
mSettings = getActivity().getSharedPreferences(Settings.SETTINGS,
Context.MODE_WORLD_WRITEABLE);
view.findViewById(R.id.my_location).setOnClickListener(this);
view.findViewById(R.id.mark_my_location).setOnClickListener(this);
@@ -316,10 +327,13 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
if (mListener != null)
mListener.onDirectionsDisplayed(directionsOverlay);
}
/**
* here we will overrride onLocationChanged() so we can update the FindMyCarUI
* (non-Javadoc)
* @see com.TwentyCodes.android.SkyHook.map.SkyHookUserOverlay#onLocationChanged(com.google.android.maps.GeoPoint, int)
* here we will overrride onLocationChanged() so we can update the
* FindMyCarUI (non-Javadoc)
*
* @see com.TwentyCodes.android.SkyHook.map.SkyHookUserOverlay#onLocationChanged(com.google.android.maps.GeoPoint,
* int)
* @param point
* @param accuracy
* @author Ricky Barrette
@@ -332,23 +346,30 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
new Thread(new Runnable() {
@Override
public void run() {
mHandler.sendMessage(mHandler.obtainMessage(ACCURACY, distance(accuracy/1E3)));
mHandler.sendMessage(mHandler.obtainMessage(ACCURACY,
distance(accuracy / 1E3)));
// if (point != null)
// if(isShowingBoth)
// if(GeoUtils.isPointOffMap(mMapView,point) || GeoUtils.isPointOffMap(mMapView, mCarPoint))
// 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)));
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
// 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);
@@ -361,6 +382,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
/**
* handles menu selection
*
* @since 0.0.2
* @author ricky barrette 3-30-2010
*/
@@ -377,62 +399,23 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
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
*/
@@ -441,28 +424,27 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
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) {
isGPSDialogEnabled = b;
if(mUserOverlay != null)
if(b)
mUserOverlay.enableGPSDialog();
else
mUserOverlay.disableGPSDialog();
}
// /**
// * enables the GPS dialog
// *
// * @param b
// * @author ricky barrette
// */
// public void setGPSDialogEnabled(boolean b) {
// if (mMap != null)
// if (b)
// mMap.enableGPSDialog();
// else
// mMap.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
*/
@@ -478,8 +460,10 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
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.
/*
* 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) {
@@ -487,12 +471,16 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
mDirections = null;
}
Vibrator vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
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) {
.setMessage(R.string.found_car)
.setCancelable(false)
.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog, int id) {
}
}).show();
@@ -505,7 +493,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
case MIDPOINT:
MidPoint mp = (MidPoint) msg.obj;
panToGeoPoint(mp.getMidPoint(), false);
mp.zoomToSpan(mMapView);
mp.zoomToSpan(mMap.getMap());
break;
}
@@ -514,32 +502,38 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
}
/**
* 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 (mMap != 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();
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);
if (mMap.getMap() != null) {
mMap.getMap().getController().stopAnimation(false);
mMap.followUser(false);
// isShowingBoth = true;
final GeoPoint user = mUserOverlay.getUserLocation();
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() {
@Override
public void run() {
mHandler.sendMessage(mHandler.obtainMessage(MIDPOINT, GeoUtils.midPoint(mCarPoint, user)));
mHandler.sendMessage(mHandler.obtainMessage(
MIDPOINT,
GeoUtils.midPoint(mCarPoint, user)));
}
}).start();
@@ -547,9 +541,8 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
// 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
*/
@@ -580,28 +574,33 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
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);
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.
*
* 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) {
markCarDialog();
@@ -613,37 +612,43 @@ 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);
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.
*
* 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
*
* @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 {
/*
@@ -653,18 +658,23 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
mDirections.removePath();
/*
* if there is no location fix then notify user
* else download directions and display them
* 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();
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);
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
* Notifys user about the error that occurred outside of
* the UI thread
*
* @param e
* @author ricky barrette
*/
@@ -673,7 +683,9 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(),
e.getMessage(), Toast.LENGTH_LONG)
.show();
mProgress.dismiss();
}
});
@@ -682,7 +694,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
@Override
public void run() {
try {
mDirections = new DirectionsOverlay(mMapView, mUserOverlay.getUserLocation(), mCarPoint, MapFragment.this);
mDirections = new DirectionsOverlay(mMap.getMap(), mMap.getUserLocation(), mCarPoint, MapFragment.this);
} catch (IllegalStateException e) {
notify(e);
} catch (ClientProtocolException e) {
@@ -704,11 +716,12 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
/**
* 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());
}
}