Finished converting FMC over to the new SkyHookUserOverlayMapFragment
Change-Id: I9059afeec89b5e5fea735c3800b7465bb9ff6e72 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -12,23 +12,18 @@
|
|||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
layout="@layout/distancebar" />
|
layout="@layout/distancebar" />
|
||||||
|
|
||||||
<!-- ricky beta release 0rKmsWMM0D-IRAEgcSZEqwZCs_8AUwxjYjj0bnA -->
|
<fragment
|
||||||
<!-- ricky 0rKmsWMM0D-KC9KXr1WbA5aEb-2ozQ0SHTvV46g -->
|
android:id="@+id/map_fragment"
|
||||||
<!-- TWENTYCODES 0rKmsWMM0D-K15bEM_kwabPbNhsn4dp4rcq2q5Q -->
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
class="com.TwentyCodes.android.SkyHook.SkyHoookUserOverlayMapFragment" >
|
||||||
|
|
||||||
<com.TwentyCodes.android.location.MapView
|
<!-- Preview: layout=@layout/map_fragment -->
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
</fragment>
|
||||||
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" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_below="@id/table" />
|
android:layout_below="@id/table" />
|
||||||
@@ -47,7 +42,7 @@
|
|||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@id/buttons"
|
android:id="@+id/buttons"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
|
|||||||
@@ -128,9 +128,9 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
|
|||||||
*/
|
*/
|
||||||
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
|
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
|
||||||
enableGPSdialog(Main.this);
|
enableGPSdialog(Main.this);
|
||||||
else
|
// else
|
||||||
if(mMap != null)
|
// if(mMap != null)
|
||||||
mMap.setGPSDialogEnabled(true);
|
// mMap.setGPSDialogEnabled(true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the map is no longer needed, clear it from memory
|
* 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
|
* Shows the splash screen over the full Activity
|
||||||
*/
|
*/
|
||||||
protected void showSplashScreen() {
|
protected void showSplashScreen() {
|
||||||
mMap.setGPSDialogEnabled(false);
|
// mMap.setGPSDialogEnabled(false);
|
||||||
mSplashDialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
|
mSplashDialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
|
||||||
mSplashDialog.setContentView(R.layout.powered_by_skyhook);
|
mSplashDialog.setContentView(R.layout.powered_by_skyhook);
|
||||||
mSplashDialog.setCancelable(false);
|
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){
|
if(mSettings.getInt(Settings.BUILD_NUMBER, 0) < build_number || Debug.FORCE_FIRSTBOOT_DIALOG){
|
||||||
displayWelcomeDialog();
|
displayWelcomeDialog();
|
||||||
} else {
|
|
||||||
mMap.setGPSDialogEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// mMap.setGPSDialogEnabled(true);
|
||||||
|
// }
|
||||||
|
|
||||||
mSettings.edit().putInt(Settings.BUILD_NUMBER, build_number).commit();
|
mSettings.edit().putInt(Settings.BUILD_NUMBER, build_number).commit();
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
|
|||||||
@@ -18,14 +18,12 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
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;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay.OnDirectionsCompleteListener;
|
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay.OnDirectionsCompleteListener;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.FindMyCarOverlay;
|
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.GeoPointLocationListener;
|
||||||
import com.TwentyCodes.android.location.GeoUtils;
|
import com.TwentyCodes.android.location.GeoUtils;
|
||||||
import com.TwentyCodes.android.location.MapView;
|
import com.TwentyCodes.android.location.MapView;
|
||||||
@@ -52,6 +50,7 @@ import com.google.android.maps.GeoPoint;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* this is the main class FindMyCar Full
|
* this is the main class FindMyCar Full
|
||||||
|
*
|
||||||
* @author WWPowers
|
* @author WWPowers
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -59,7 +58,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
|
|
||||||
public boolean hasLeftCar;
|
public boolean hasLeftCar;
|
||||||
public boolean isCarFound;
|
public boolean isCarFound;
|
||||||
// private boolean isShowingBoth = false;
|
// private boolean isShowingBoth = false;
|
||||||
private static final int ACCURACY = 0;
|
private static final int ACCURACY = 0;
|
||||||
private static final int DISTANCE = 1;
|
private static final int DISTANCE = 1;
|
||||||
private static final int FOUND_CAR = 2;
|
private static final int FOUND_CAR = 2;
|
||||||
@@ -71,23 +70,25 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
public static TextView mDistance;
|
public static TextView mDistance;
|
||||||
public static boolean isMetric = true;
|
public static boolean isMetric = true;
|
||||||
public static TextView mAccuracy;
|
public static TextView mAccuracy;
|
||||||
public static SkyHookUserOverlay mUserOverlay;
|
|
||||||
public static MapView mMapView;
|
|
||||||
private SharedPreferences mSettings;
|
private SharedPreferences mSettings;
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private ProgressDialog mProgress;
|
private ProgressDialog mProgress;
|
||||||
private boolean isGPSDialogEnabled = true;
|
|
||||||
protected DirectionsOverlay mDirections;
|
protected DirectionsOverlay mDirections;
|
||||||
private MapFragmentListener mListener;
|
private MapFragmentListener mListener;
|
||||||
|
private SkyHoookUserOverlayMapFragment mMap;
|
||||||
|
|
||||||
public interface MapFragmentListener{
|
public interface MapFragmentListener {
|
||||||
public void onCarDeleted();
|
public void onCarDeleted();
|
||||||
|
|
||||||
public void onDirectionsDisplayed(DirectionsOverlay directions);
|
public void onDirectionsDisplayed(DirectionsOverlay directions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a string distance that is based on the users measurement unit preference
|
* returns a string distance that is based on the users measurement unit
|
||||||
* @param distance in kilometers
|
* preference
|
||||||
|
*
|
||||||
|
* @param distance
|
||||||
|
* in kilometers
|
||||||
* @return string distance
|
* @return string distance
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -97,43 +98,46 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* if blnUnit is true, the distance computed will be in metric units,
|
* if blnUnit is true, the distance computed will be in metric units,
|
||||||
* else, standard units are used
|
* else, standard units are used meters are used until 1 kilometer is
|
||||||
* meters are used until 1 kilometer is reached, then kilometers are used
|
* reached, then kilometers are used feet are used until 1 mile is
|
||||||
* feet are used until 1 mile is reached, then miles are used
|
* reached, then miles are used
|
||||||
*/
|
*/
|
||||||
if(isMetric){
|
if (isMetric) {
|
||||||
if (distance < 1){
|
if (distance < 1) {
|
||||||
distance = distance * 1000;
|
distance = distance * 1000;
|
||||||
return twoDForm.format(distance) +" m";
|
return twoDForm.format(distance) + " m";
|
||||||
}
|
}
|
||||||
return threeDForm.format(distance) +" Km";
|
return threeDForm.format(distance) + " Km";
|
||||||
}
|
}
|
||||||
distance = distance / 1.609344;
|
distance = distance / 1.609344;
|
||||||
if (distance < 1){
|
if (distance < 1) {
|
||||||
distance = distance * 5280;
|
distance = distance * 5280;
|
||||||
return twoDForm.format(distance) +" ft";
|
return twoDForm.format(distance) + " ft";
|
||||||
}
|
}
|
||||||
return twoDForm.format(distance) +" mi";
|
return twoDForm.format(distance) + " mi";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pans maps to where the a geopoint is, and if zoomIn is true, zooms in to level 20
|
* pans maps to where the a geopoint is, and if zoomIn is true, zooms in to
|
||||||
* @param GeoPoint point - lat and lon of point to pan 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
|
* @param boolean zoomIn - true if map needs to be zoomed in
|
||||||
* @return boolean false it geopoint is null
|
* @return boolean false it geopoint is null
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public boolean panToGeoPoint(GeoPoint point, boolean zoomIn) {
|
public boolean panToGeoPoint(GeoPoint point, boolean zoomIn) {
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
if (mMapView != null) {
|
if (mMap != null) {
|
||||||
try {
|
try {
|
||||||
mMapView.getController().stopAnimation(false);
|
mMap.getMap().getController().setCenter(point);
|
||||||
mMapView.getController().setCenter(point);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (zoomIn) {
|
if (zoomIn) {
|
||||||
mMapView.getController().setZoom((mMapView.getMaxZoomLevel() - 2));
|
mMap.getMap().getController()
|
||||||
|
.setZoom((mMap.getMap().getMaxZoomLevel() - 2));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "panToGeoPoint call. mapcontroller was null");
|
Log.e(TAG, "panToGeoPoint call. mapcontroller was null");
|
||||||
@@ -147,157 +151,164 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* removes the car overlay from the mapview.
|
* removes the car overlay from the mapview.
|
||||||
|
*
|
||||||
* @return true if successful
|
* @return true if successful
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public boolean removeCar(){
|
public boolean removeCar() {
|
||||||
|
|
||||||
mCarPoint = null;
|
mCarPoint = null;
|
||||||
mDistance.setText("0");
|
mDistance.setText("0");
|
||||||
mSettings.edit().remove(Settings.LAT).remove(Settings.LON).commit();
|
mSettings.edit().remove(Settings.LAT).remove(Settings.LON).commit();
|
||||||
if(mListener != null)
|
if (mListener != null)
|
||||||
mListener.onCarDeleted();
|
mListener.onCarDeleted();
|
||||||
if(mDirections != null) {
|
if (mDirections != null) {
|
||||||
mDirections.removePath();
|
mDirections.removePath();
|
||||||
mDirections = null;
|
mDirections = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mMapView.getOverlays().remove(mCarOverlay);
|
mMap.getMap().getOverlays().remove(mCarOverlay);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapView getMap(){
|
public MapView getMap() {
|
||||||
return mMapView;
|
return mMap.getMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loads saved settings from files
|
* loads saved settings from files
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void loadSettings(){
|
private void loadSettings() {
|
||||||
|
|
||||||
int lat = mSettings.getInt(Settings.LAT, 0);//mFileStream.readInteger(getString(R.string.lat));
|
int lat = mSettings.getInt(Settings.LAT, 0);// mFileStream.readInteger(getString(R.string.lat));
|
||||||
int lon = mSettings.getInt(Settings.LON, 0);//mFileStream.readInteger(getString(R.string.lon));
|
int lon = mSettings.getInt(Settings.LON, 0);// mFileStream.readInteger(getString(R.string.lon));
|
||||||
|
|
||||||
//sets car geopoint up if lat and lon != 0
|
// sets car geopoint up if lat and lon != 0
|
||||||
if (lat != 0 && lon != 0) {
|
if (lat != 0 && lon != 0) {
|
||||||
setCar(new GeoPoint(lat, lon));
|
setCar(new GeoPoint(lat, lon));
|
||||||
}
|
}
|
||||||
|
|
||||||
//sets measurement unit preference
|
// sets measurement unit preference
|
||||||
String mu = mSettings.getString(Settings.MEASUREMENT_UNIT, null);
|
String mu = mSettings.getString(Settings.MEASUREMENT_UNIT, null);
|
||||||
if(mu != null){
|
if (mu != null) {
|
||||||
if(mu.equalsIgnoreCase("Standard")){
|
if (mu.equalsIgnoreCase("Standard")) {
|
||||||
isMetric = false;
|
isMetric = false;
|
||||||
}
|
}
|
||||||
if(mu.equalsIgnoreCase("Metric")){
|
if (mu.equalsIgnoreCase("Metric")) {
|
||||||
isMetric = true;
|
isMetric = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//load compass options
|
// load compass options
|
||||||
String compass_option = mSettings.getString(Settings.COMPASS_OPTION, "Small");
|
String compass_option = mSettings.getString(Settings.COMPASS_OPTION, "Small");
|
||||||
int px;
|
if (compass_option.equalsIgnoreCase("Large")) {
|
||||||
Resources r = getResources();
|
mMap.setCompassDrawables(R.drawable.needle_lrg, R.drawable.compass_lrg, 110, 110);
|
||||||
if(compass_option.equalsIgnoreCase("Large")){
|
} else if (compass_option.equalsIgnoreCase("Small")) {
|
||||||
px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 110, r.getDisplayMetrics());
|
mMap.setCompassDrawables(R.drawable.needle_sm, R.drawable.compass_sm, 40, 40);
|
||||||
mUserOverlay.setCompassDrawables(R.drawable.needle_lrg, R.drawable.compass_lrg, px, px);
|
|
||||||
} 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);
|
|
||||||
} else {
|
} else {
|
||||||
px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, r.getDisplayMetrics());
|
mMap.setCompassDrawables(R.drawable.needle_med, R.drawable.compass_med, 70, 70);
|
||||||
mUserOverlay.setCompassDrawables(R.drawable.needle_med, R.drawable.compass_med, px, px);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* using the users lat/lon saves car location to lat/lon files and passes that geopoint info to setCar
|
* using the users lat/lon saves car location to lat/lon files and passes
|
||||||
* also writes address to notes
|
* that geopoint info to setCar also writes address to notes
|
||||||
|
*
|
||||||
* @author ricky barrette 3-31-2010
|
* @author ricky barrette 3-31-2010
|
||||||
* @author WWPowers 3-31-2010
|
* @author WWPowers 3-31-2010
|
||||||
*/
|
*/
|
||||||
private void markCar() {
|
private void markCar() {
|
||||||
//removed old parking timer
|
// removed old parking timer
|
||||||
// ParkingTimerDialog.stopTimer(this);
|
// ParkingTimerDialog.stopTimer(this);
|
||||||
|
|
||||||
GeoPoint user = mUserOverlay.getUserLocation();
|
GeoPoint user = mMap.getUserLocation();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if the user location is not null then
|
* if the user location is not null then save car lat and lon to files
|
||||||
* save car lat and lon to files
|
* pass geopoint info to set car, which will setup and show the car
|
||||||
* pass geopoint info to set car, which will setup and show the car overlay
|
* overlay get address info and add it to the notes file
|
||||||
* get address info and add it to the notes file
|
|
||||||
*
|
*
|
||||||
* else inform user that they dont have a gps signal
|
* else inform user that they dont have a gps signal
|
||||||
*/
|
*/
|
||||||
if (user != null){
|
if (user != null) {
|
||||||
mSettings.edit()
|
mSettings.edit().putInt(Settings.LAT, user.getLatitudeE6())
|
||||||
.putInt(Settings.LAT, user.getLatitudeE6())
|
.putInt(Settings.LON, user.getLongitudeE6()).commit();
|
||||||
.putInt(Settings.LON, user.getLongitudeE6())
|
|
||||||
.commit();
|
|
||||||
|
|
||||||
setCar(user);
|
setCar(user);
|
||||||
|
|
||||||
//TODO get address
|
// TODO get address
|
||||||
|
|
||||||
} else {
|
} 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
|
* ask user if they want to replace current car marker with a new one
|
||||||
|
*
|
||||||
* @since 0.1.1
|
* @since 0.1.1
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void markCarDialog(){
|
public void markCarDialog() {
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(getActivity())
|
||||||
.setMessage(R.string.mark_car_warning).setCancelable(false)
|
.setMessage(R.string.mark_car_warning)
|
||||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
.setCancelable(false)
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
.setPositiveButton(R.string.yes,
|
||||||
removeCar();
|
new DialogInterface.OnClickListener() {
|
||||||
markCar();
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dialog.cancel();
|
removeCar();
|
||||||
}
|
markCar();
|
||||||
})
|
dialog.cancel();
|
||||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
}
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
})
|
||||||
dialog.cancel();
|
.setNegativeButton(R.string.no,
|
||||||
}
|
new DialogInterface.OnClickListener() {
|
||||||
})
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
.show();
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (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
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.map_action_bar, menu);
|
inflater.inflate(R.menu.map_action_bar, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see com.google.android.maps.MapActivity#onCreate(android.os.Bundle)
|
* @see com.google.android.maps.MapActivity#onCreate(android.os.Bundle)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
container.removeAllViews();
|
container.removeAllViews();
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.map, container, false);
|
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();
|
setUiHandler();
|
||||||
|
|
||||||
mAccuracy = (TextView) view.findViewById(R.id.tvAccuracy2);
|
mAccuracy = (TextView) view.findViewById(R.id.tvAccuracy2);
|
||||||
mDistance = (TextView) view.findViewById(R.id.tvDistance2);
|
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.my_location).setOnClickListener(this);
|
||||||
view.findViewById(R.id.mark_my_location).setOnClickListener(this);
|
view.findViewById(R.id.mark_my_location).setOnClickListener(this);
|
||||||
@@ -309,46 +320,56 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDirectionsComplete(final DirectionsOverlay directionsOverlay) {
|
public void onDirectionsComplete(final DirectionsOverlay directionsOverlay) {
|
||||||
if(mProgress != null){
|
if (mProgress != null) {
|
||||||
mProgress.dismiss();
|
mProgress.dismiss();
|
||||||
mProgress = null;
|
mProgress = null;
|
||||||
}
|
}
|
||||||
if(mListener != null)
|
if (mListener != null)
|
||||||
mListener.onDirectionsDisplayed(directionsOverlay);
|
mListener.onDirectionsDisplayed(directionsOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* here we will overrride onLocationChanged() so we can update the FindMyCarUI
|
* here we will overrride onLocationChanged() so we can update the
|
||||||
* (non-Javadoc)
|
* FindMyCarUI (non-Javadoc)
|
||||||
* @see com.TwentyCodes.android.SkyHook.map.SkyHookUserOverlay#onLocationChanged(com.google.android.maps.GeoPoint, int)
|
*
|
||||||
|
* @see com.TwentyCodes.android.SkyHook.map.SkyHookUserOverlay#onLocationChanged(com.google.android.maps.GeoPoint,
|
||||||
|
* int)
|
||||||
* @param point
|
* @param point
|
||||||
* @param accuracy
|
* @param accuracy
|
||||||
* @author Ricky Barrette
|
* @author Ricky Barrette
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final GeoPoint point, final int accuracy){
|
public void onLocationChanged(final GeoPoint point, final int accuracy) {
|
||||||
|
|
||||||
Log.d(TAG, "FMC onLocationChanged()");
|
Log.d(TAG, "FMC onLocationChanged()");
|
||||||
|
|
||||||
new Thread(new Runnable(){
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(ACCURACY, distance(accuracy/1E3)));
|
mHandler.sendMessage(mHandler.obtainMessage(ACCURACY,
|
||||||
|
distance(accuracy / 1E3)));
|
||||||
|
|
||||||
// if (point != null)
|
// if (point != null)
|
||||||
// if(isShowingBoth)
|
// if(isShowingBoth)
|
||||||
// if(GeoUtils.isPointOffMap(mMapView,point) || GeoUtils.isPointOffMap(mMapView, mCarPoint))
|
// if(GeoUtils.isPointOffMap(mMap.getMap(),point) ||
|
||||||
// mHandler.sendEmptyMessage(SHOWBOTH);
|
// GeoUtils.isPointOffMap(mMap.getMap(), mCarPoint))
|
||||||
//
|
// mHandler.sendEmptyMessage(SHOWBOTH);
|
||||||
if (mCarPoint != null && point != null){
|
//
|
||||||
|
if (mCarPoint != null && point != null) {
|
||||||
double distance = GeoUtils.distanceKm(point, mCarPoint);
|
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
|
||||||
if (distance > 0.009144){
|
// is set to check for arrival
|
||||||
|
if (distance > 0.009144) {
|
||||||
hasLeftCar = true;
|
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 user has gone back into 30 foot radius and has not
|
||||||
if (distance <= 0.009144 && isCarFound == false && hasLeftCar == true){
|
// 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;
|
isCarFound = true;
|
||||||
|
|
||||||
mHandler.sendEmptyMessage(FOUND_CAR);
|
mHandler.sendEmptyMessage(FOUND_CAR);
|
||||||
@@ -361,12 +382,13 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* handles menu selection
|
* handles menu selection
|
||||||
|
*
|
||||||
* @since 0.0.2
|
* @since 0.0.2
|
||||||
* @author ricky barrette 3-30-2010
|
* @author ricky barrette 3-30-2010
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected (MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if(item.getItemId() == R.id.delete_car)
|
if (item.getItemId() == R.id.delete_car)
|
||||||
removeCar();
|
removeCar();
|
||||||
else if (item.getItemId() == R.id.settings) {
|
else if (item.getItemId() == R.id.settings) {
|
||||||
startActivity(new Intent().setClass(getActivity(), Settings.class));
|
startActivity(new Intent().setClass(getActivity(), Settings.class));
|
||||||
@@ -377,136 +399,102 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
return false;
|
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)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.support.v4.app.Fragment#onResume()
|
* @see android.support.v4.app.Fragment#onResume()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
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();
|
loadSettings();
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reorders the overlays to the UserOverlay always on top
|
* removes the previous car overlay and replaces it with a new car overlay
|
||||||
* @author ricky barrette
|
* that represents the users car at a specific geopoint
|
||||||
*/
|
|
||||||
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
|
|
||||||
*
|
*
|
||||||
* @param point for geopoint of car
|
* @param point
|
||||||
|
* for geopoint of car
|
||||||
* @author WWPowers 3-31-2010
|
* @author WWPowers 3-31-2010
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setCar(GeoPoint point) {
|
public void setCar(GeoPoint point) {
|
||||||
isCarFound = false;
|
isCarFound = false;
|
||||||
hasLeftCar = false;
|
hasLeftCar = false;
|
||||||
mCarPoint = point;
|
mCarPoint = point;
|
||||||
mCarOverlay = new FindMyCarOverlay(getActivity(), point);
|
mCarOverlay = new FindMyCarOverlay(getActivity(), point);
|
||||||
mMapView.getOverlays().add(mCarOverlay);
|
mMap.getMap().getOverlays().add(mCarOverlay);
|
||||||
mUserOverlay.setDestination(mCarPoint);
|
mMap.setDestination(mCarPoint);
|
||||||
reorderOverlays();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* enables the GPS dialog
|
// * enables the GPS dialog
|
||||||
* @param b
|
// *
|
||||||
* @author ricky barrette
|
// * @param b
|
||||||
*/
|
// * @author ricky barrette
|
||||||
public void setGPSDialogEnabled(boolean b) {
|
// */
|
||||||
isGPSDialogEnabled = b;
|
// public void setGPSDialogEnabled(boolean b) {
|
||||||
if(mUserOverlay != null)
|
// if (mMap != null)
|
||||||
if(b)
|
// if (b)
|
||||||
mUserOverlay.enableGPSDialog();
|
// mMap.enableGPSDialog();
|
||||||
else
|
// else
|
||||||
mUserOverlay.disableGPSDialog();
|
// mMap.disableGPSDialog();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the UI handler.
|
* Sets up the UI handler. The UI handler will process messages from
|
||||||
* The UI handler will process messages from processing threads
|
* processing threads
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void setUiHandler() {
|
private void setUiHandler() {
|
||||||
mHandler = new Handler(){
|
mHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg){
|
public void handleMessage(Message msg) {
|
||||||
switch(msg.what){
|
switch (msg.what) {
|
||||||
case ACCURACY:
|
case ACCURACY:
|
||||||
mAccuracy.setText( (String) msg.obj );
|
mAccuracy.setText((String) msg.obj);
|
||||||
break;
|
break;
|
||||||
case DISTANCE:
|
case DISTANCE:
|
||||||
mDistance.setText((String) msg.obj);
|
mDistance.setText((String) msg.obj);
|
||||||
break;
|
break;
|
||||||
case FOUND_CAR:
|
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) {
|
if (mDirections != null) {
|
||||||
mDirections.removePath();
|
mDirections.removePath();
|
||||||
mDirections = null;
|
mDirections = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vibrator vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
Vibrator vib = (Vibrator) getActivity().getSystemService(
|
||||||
new AlertDialog.Builder(getActivity())
|
Context.VIBRATOR_SERVICE);
|
||||||
|
new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(R.string.yay)
|
.setTitle(R.string.yay)
|
||||||
.setMessage(R.string.found_car).setCancelable(false)
|
.setMessage(R.string.found_car)
|
||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
.setCancelable(false)
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
.setPositiveButton(R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(
|
||||||
|
DialogInterface dialog, int id) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
vib.vibrate(100);
|
vib.vibrate(100);
|
||||||
mDistance.setText("0");
|
mDistance.setText("0");
|
||||||
break;
|
break;
|
||||||
case SHOWBOTH:
|
case SHOWBOTH:
|
||||||
showBoth();
|
showBoth();
|
||||||
break;
|
break;
|
||||||
case MIDPOINT:
|
case MIDPOINT:
|
||||||
MidPoint mp = (MidPoint) msg.obj;
|
MidPoint mp = (MidPoint) msg.obj;
|
||||||
panToGeoPoint(mp.getMidPoint(), false);
|
panToGeoPoint(mp.getMidPoint(), false);
|
||||||
mp.zoomToSpan(mMapView);
|
mp.zoomToSpan(mMap.getMap());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -514,42 +502,47 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* computes a geopoint the is the central geopoint between the user and the car.
|
* computes a geopoint the is the central geopoint between the user and the
|
||||||
* also it zooms so both marks are visible on the map
|
* car. also it zooms so both marks are visible on the map
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
protected void showBoth(){
|
protected void showBoth() {
|
||||||
if(mUserOverlay != null) {
|
if (mMap != null) {
|
||||||
if (mCarPoint == null){
|
if (mCarPoint == null) {
|
||||||
Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), R.string.mark_car_first,
|
||||||
} else if (mUserOverlay.getUserLocation() == null){
|
Toast.LENGTH_LONG).show();
|
||||||
Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
|
} else if (mMap.getUserLocation() == null) {
|
||||||
|
Toast.makeText(getActivity(), R.string.no_gps_signal,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
if (mMapView != null) {
|
if (mMap.getMap() != null) {
|
||||||
mMapView.getController().stopAnimation(false);
|
mMap.getMap().getController().stopAnimation(false);
|
||||||
mUserOverlay.followUser(false);
|
mMap.followUser(false);
|
||||||
// isShowingBoth = true;
|
// 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
|
* here we null check our next set of value before we send
|
||||||
* if they have became null for some reason we disable show both mode
|
* them off to geoutils if they have became null for some
|
||||||
|
* reason we disable show both mode
|
||||||
*/
|
*/
|
||||||
if(mCarPoint!= null && user != null){
|
if (mCarPoint != null && user != null) {
|
||||||
new Thread(new Runnable(){
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(MIDPOINT, GeoUtils.midPoint(mCarPoint, user)));
|
mHandler.sendMessage(mHandler.obtainMessage(
|
||||||
|
MIDPOINT,
|
||||||
|
GeoUtils.midPoint(mCarPoint, user)));
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
}
|
}
|
||||||
// else
|
// else
|
||||||
// isShowingBoth = false;
|
// isShowingBoth = false;
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} 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
|
* Sets the listener for this map fragment
|
||||||
|
*
|
||||||
* @param listener
|
* @param listener
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -568,7 +562,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (v.getId() == R.id.show_both)
|
if (v.getId() == R.id.show_both)
|
||||||
showBoth();
|
showBoth();
|
||||||
else if(v.getId() == R.id.mark_my_location)
|
else if (v.getId() == R.id.mark_my_location)
|
||||||
markMyLocation();
|
markMyLocation();
|
||||||
else if (v.getId() == R.id.my_location)
|
else if (v.getId() == R.id.my_location)
|
||||||
myLocation();
|
myLocation();
|
||||||
@@ -577,33 +571,38 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
else if (v.getId() == R.id.map_mode)
|
else if (v.getId() == R.id.map_mode)
|
||||||
changeMapMode();
|
changeMapMode();
|
||||||
else if (v.getId() == R.id.parking_timer)
|
else if (v.getId() == R.id.parking_timer)
|
||||||
if (! Main.isFull)
|
if (!Main.isFull)
|
||||||
Main.featureInFullDialog(getActivity());
|
Main.featureInFullDialog(getActivity());
|
||||||
else
|
else
|
||||||
getActivity().startActivity(new Intent(getActivity(), ParkignTimerActivity.class));
|
getActivity().startActivity(
|
||||||
|
new Intent(getActivity(), ParkignTimerActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the user's location
|
* Marks the user's location
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void markMyLocation() {
|
private void markMyLocation() {
|
||||||
mUserOverlay.followUser(true);
|
mMap.followUser(true);
|
||||||
// isShowingBoth = false;
|
// isShowingBoth = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if we have a gps signal, then pan to user location and then
|
* if we have a gps signal, then pan to user location and then if there
|
||||||
* if there is no car, mark the car location as the users location
|
* is no car, mark the car location as the users location else show mark
|
||||||
* else show mark car dialog
|
* 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
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
if (! panToGeoPoint(mUserOverlay.getUserLocation(), true)){
|
if (!panToGeoPoint(mMap.getUserLocation(), true)) {
|
||||||
Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), R.string.no_gps_signal,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
if (mCarPoint != null){
|
if (mCarPoint != null) {
|
||||||
markCarDialog();
|
markCarDialog();
|
||||||
} else {
|
} else {
|
||||||
markCar();
|
markCar();
|
||||||
@@ -613,89 +612,102 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* pans the map to the user's location
|
* pans the map to the user's location
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void myLocation() {
|
private void myLocation() {
|
||||||
mUserOverlay.followUser(true);
|
mMap.followUser(true);
|
||||||
// isShowingBoth = false;
|
// isShowingBoth = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if we have a gps signal, then pan to user location
|
* if we have a gps signal, then pan to user location else notify user
|
||||||
* else notify user that there is no GPS signal
|
* 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
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
if (! panToGeoPoint(mUserOverlay.getUserLocation(), true)){
|
if (!panToGeoPoint(mMap.getUserLocation(), true)) {
|
||||||
Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
|
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
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void directions() {
|
private void directions() {
|
||||||
if (Main.isFull) {
|
if (Main.isFull) {
|
||||||
/*
|
/*
|
||||||
* if there is no car marked, then notify user
|
* if there is no car marked, then notify user else check to see if
|
||||||
* else check to see if there is directions
|
* there is directions
|
||||||
*/
|
*/
|
||||||
if (mCarPoint == null) {
|
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 {
|
} else {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove old directions if the exist
|
* Remove old directions if the exist
|
||||||
*/
|
*/
|
||||||
if(mDirections != null)
|
if (mDirections != null)
|
||||||
mDirections.removePath();
|
mDirections.removePath();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if there is no location fix then notify user
|
* if there is no location fix then notify user else download
|
||||||
* else download directions and display them
|
* directions and display them
|
||||||
*/
|
*/
|
||||||
if (mUserOverlay.getUserLocation() == null) {
|
if (mMap.getUserLocation() == null) {
|
||||||
Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), R.string.no_gps_signal,
|
||||||
} else {
|
Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
|
||||||
mProgress = ProgressDialog.show(getActivity(), getText(R.string.directions), getText(R.string.calculating), true);
|
mProgress = ProgressDialog.show(getActivity(),
|
||||||
new Thread(new Runnable(){
|
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
|
||||||
* @param e
|
* the UI thread
|
||||||
* @author ricky barrette
|
*
|
||||||
*/
|
* @param e
|
||||||
public void notify(final Exception e){
|
* @author ricky barrette
|
||||||
e.printStackTrace();
|
*/
|
||||||
getActivity().runOnUiThread(new Runnable(){
|
public void notify(final Exception e) {
|
||||||
@Override
|
e.printStackTrace();
|
||||||
public void run(){
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
|
@Override
|
||||||
mProgress.dismiss();
|
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();
|
}
|
||||||
|
|
||||||
}
|
@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
|
} else
|
||||||
@@ -704,11 +716,12 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* changes the map mode
|
* changes the map mode
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void changeMapMode() {
|
private void changeMapMode() {
|
||||||
if(mMapView != null)
|
if (mMap.getMap() != null)
|
||||||
mMapView.setSatellite(!mMapView.isSatellite());
|
mMap.getMap().setSatellite(!mMap.getMap().isSatellite());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user