updated the manifest to reflect com.TwentyCodes.android.location as the main package

Created the abstract class MapFragmentBase.java to be used as a template for creating new mapfragments.

Created UserOverlayMapFragment.java & SkyHookUserOverlayMapFragment.java. these two mapfragments each maintain the mapview and its respected user overlay, allowing for simpler implmention
This commit is contained in:
2012-01-12 15:20:42 +00:00
parent 1a858f1335
commit 51e03d9d9d
48 changed files with 381 additions and 70 deletions

View File

@@ -0,0 +1,127 @@
/**
* UserOverlayMapFragmentBase.java
* @date Jan 12, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.SkyHook;
import com.TwentyCodes.android.location.CompassListener;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.MapFragmentBase;
import com.TwentyCodes.android.location.MapView;
import com.google.android.maps.GeoPoint;
/**
* This is a MapFragment that maintains the SkyHookUserOverlay
*
* TODO acquiring gps dialog
* @author ricky barrette
*/
public class SkyHoookUserOverlayMapFragment extends MapFragmentBase implements GeoPointLocationListener, CompassListener{
private SkyHookUserOverlay mUserOverlay;
private GeoPointLocationListener mGeoPointLocationListener;
private CompassListener mCompassListener;
/**
* Creates a new UserOverlayMapFragment
* @author ricky barrette
*/
public SkyHoookUserOverlayMapFragment() {
super();
}
/**
* @return the users current location
* @author ricky barrette
*/
public GeoPoint getUserLocation() {
return mUserOverlay.getUserLocation();
}
/**
* Called when the compass is updated
* (non-Javadoc)
* @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float)
*/
@Override
public void onCompassUpdate(float bearing) {
if(mCompassListener != null)
mCompassListener.onCompassUpdate(bearing);
}
/**
* Called when has a location to report
* @author ricky barrette
*/
@Override
public void onLocationChanged(GeoPoint point, int accuracy) {
if(mGeoPointLocationListener != null)
mGeoPointLocationListener.onLocationChanged(point, accuracy);
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.location.MapFragmentBase#onMapViewCreate(com.TwentyCodes.android.location.MapView)
*/
@Override
public void onMapViewCreate(MapView map) {
mUserOverlay = new SkyHookUserOverlay(map, this.getActivity().getApplicationContext());
mUserOverlay.registerListener(this);
mUserOverlay.setCompassListener(this);
mUserOverlay.enableCompass();
mUserOverlay.disableGPSDialog();
mUserOverlay.followUser(true);
map.getOverlays().add(mUserOverlay);
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.location.MapFragmentBase#onPause()
*/
@Override
public void onPause() {
mUserOverlay.disableMyLocation();
removeOverlay(mUserOverlay);
super.onPause();
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.location.MapFragmentBase#onResume()
*/
@Override
public void onResume() {
if(mUserOverlay != null)
mUserOverlay.enableMyLocation();
super.onResume();
}
/**
* @param listener
* @author ricky barrette
*/
public void setCompassListener(CompassListener listener){
mCompassListener = listener;
}
/**
* Sets the destination for the compass to point to
* @param destination
* @author ricky barrette
*/
public void setDestination(GeoPoint destination){
mUserOverlay.setDestination(destination);
}
/**
* @param listener
* @author ricky barrette
*/
public void setGeoPointLocationListener(GeoPointLocationListener listener){
mGeoPointLocationListener = listener;
}
}

View File

@@ -5,6 +5,8 @@
*/
package com.TwentyCodes.android.SkyHook;
import com.TwentyCodes.android.location.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;

View File

@@ -15,7 +15,7 @@ import android.graphics.Matrix;
import android.graphics.Point;
import android.util.TypedValue;
import com.TwentyCodes.android.SkyHook.R;
import com.TwentyCodes.android.location.R;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

View File

@@ -0,0 +1,75 @@
/**
* MapFragment.java
* @date Jan 7, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.location;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.maps.GeoPoint;
/**
* This map fragment will maintain a map view and all its functions
*
* @author ricky barrette
*/
public abstract class MapFragmentBase extends Fragment {
private MapView mMapView;
/**
* Creates a new MapFragment
* @author ricky barrette
*/
public MapFragmentBase() {
super();
}
/**
* Called when the fragment view is first created
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map_fragment, container, false);
mMapView = (MapView) view.findViewById(R.id.mapview);
mMapView.setClickable(true);
onMapViewCreate(mMapView);
return view;
}
/**
* Called when the mapview has been initialized. here you want to init and add your custom overlays
* @param map
* @author ricky barrette
*/
public abstract void onMapViewCreate(MapView map);
/**
* Removes an overlay from the mapview
* @param overlay
* @author ricky barrette
*/
protected void removeOverlay(Object overlay){
mMapView.getOverlays().remove(overlay);
}
/**
* Sets the center of the map to the provided point
* @param point
* @author ricky barrette
*/
public void setMapCenter(GeoPoint point){
mMapView.getController().setCenter(point);
}
}

View File

@@ -22,7 +22,7 @@ import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import com.TwentyCodes.android.SkyHook.R;
import com.TwentyCodes.android.location.R;
import com.TwentyCodes.android.debug.Debug;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;

View File

@@ -0,0 +1,123 @@
/**
* UserOverlayMapFragment.java
* @date Jan 12, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.location;
import com.google.android.maps.GeoPoint;
/**
* This is a MapFragment that maintains the UserOverlay
*
* TODO acquiring gps dialog
* @author ricky barrette
*/
public class UserOverlayMapFragment extends MapFragmentBase implements GeoPointLocationListener, CompassListener{
private UserOverlay mUserOverlay;
private GeoPointLocationListener mGeoPointLocationListener;
private CompassListener mCompassListener;
/**
* Creates a new UserOverlayMapFragment
* @author ricky barrette
*/
public UserOverlayMapFragment() {
super();
}
/**
* @return the users current location
* @author ricky barrette
*/
public GeoPoint getUserLocation() {
return mUserOverlay.getUserLocation();
}
/**
* Called when the compass is updated
* (non-Javadoc)
* @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float)
*/
@Override
public void onCompassUpdate(float bearing) {
if(mCompassListener != null)
mCompassListener.onCompassUpdate(bearing);
}
/**
* Called when skyhook has a location to report
* @author ricky barrette
*/
@Override
public void onLocationChanged(GeoPoint point, int accuracy) {
if(mGeoPointLocationListener != null)
mGeoPointLocationListener.onLocationChanged(point, accuracy);
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.location.MapFragmentBase#onMapViewCreate(com.TwentyCodes.android.location.MapView)
*/
@Override
public void onMapViewCreate(MapView map) {
mUserOverlay = new UserOverlay(map, this.getActivity().getApplicationContext());
mUserOverlay.registerListener(this);
mUserOverlay.setCompassListener(this);
mUserOverlay.enableCompass();
mUserOverlay.disableGPSDialog();
mUserOverlay.followUser(true);
map.getOverlays().add(mUserOverlay);
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.location.MapFragmentBase#onPause()
*/
@Override
public void onPause() {
mUserOverlay.disableMyLocation();
removeOverlay(mUserOverlay);
super.onPause();
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.location.MapFragmentBase#onResume()
*/
@Override
public void onResume() {
if(mUserOverlay != null)
mUserOverlay.enableMyLocation();
super.onResume();
}
/**
* @param listener
* @author ricky barrette
*/
public void setCompassListener(CompassListener listener){
mCompassListener = listener;
}
/**
* Sets the destination for the compass to point to
* @param destination
* @author ricky barrette
*/
public void setDestination(GeoPoint destination){
mUserOverlay.setDestination(destination);
}
/**
* @param listener
* @author ricky barrette
*/
public void setGeoPointLocationListener(GeoPointLocationListener listener){
mGeoPointLocationListener = listener;
}
}