Refactored the entire library
I also moved the directions listfragment, overlay, and other required classes from FMC into the library Change-Id: Iba27e29d89e864dbeca3a2670aed552a8be4f2b8 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* @author Twenty Codes, LLC
|
||||
* @author ricky barrette
|
||||
* @date Sep 22, 2010
|
||||
*/
|
||||
package com.TwentyCodes.android.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.TwentyCodes.android.location.R;
|
||||
import com.TwentyCodes.android.overlays.DirectionsOverlay;
|
||||
|
||||
/**
|
||||
* this is a custom listview adaptor that wills a listview that has 2 textviews in each row.
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class DirectionsAdapter extends BaseAdapter {
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
private DirectionsOverlay mDirections;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new DirectionsAdapter
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public DirectionsAdapter(Context context, DirectionsOverlay directions) {
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mDirections = directions;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the size of the main list
|
||||
* @see android.widget.Adapter#getCount()
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mDirections.getDirections().size() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see android.widget.Adapter#getItem(int)
|
||||
* @param position
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current position in the list
|
||||
* @see android.widget.Adapter#getItemId(int)
|
||||
* @param position
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* inflates the row from xml, and sets the textviews to their intended vales
|
||||
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
|
||||
* @param position
|
||||
* @param convertView
|
||||
* @param parent
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
if (convertView == null) {
|
||||
convertView = mInflater.inflate(R.layout.list_row, null);
|
||||
holder = new ViewHolder();
|
||||
holder.text = (TextView) convertView.findViewById(R.id.TextView01);
|
||||
holder.text2 = (TextView) convertView.findViewById(R.id.TextView02);
|
||||
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the copyrights on the bottom of the directions list
|
||||
*/
|
||||
if (position == mDirections.getDirections().size()){
|
||||
holder.text.setText(mDirections.getCopyrights());
|
||||
holder.text2.setText("");
|
||||
} else {
|
||||
holder.text.setText(Html.fromHtml(mDirections.getDirections().get(position)));
|
||||
holder.text2.setText(mDirections.getDurations().get(position) +" : "+ mDirections.getDistances().get(position));
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
/**
|
||||
* this class will hold the TextViews
|
||||
* @author ricky barrette
|
||||
*/
|
||||
class ViewHolder {
|
||||
TextView text;
|
||||
TextView text2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* DirectionsListFragment.java
|
||||
* @date Nov 25, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.fragments;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.TwentyCodes.android.location.OnDirectionSelectedListener;
|
||||
import com.TwentyCodes.android.overlays.DirectionsOverlay;
|
||||
import com.google.android.maps.GeoPoint;
|
||||
|
||||
/**
|
||||
* This fragment will be used to display directions to the user.
|
||||
* When a specific direction is clicked, the corrispoding geopoint is returned via listener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class DirectionsListFragment extends ListFragment {
|
||||
|
||||
private OnDirectionSelectedListener mListener;
|
||||
private ArrayList<GeoPoint> mPoints;
|
||||
|
||||
/**
|
||||
* Creates a new Directions List Fragment
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public DirectionsListFragment() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Directions List Fragment
|
||||
* @param listener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public DirectionsListFragment(OnDirectionSelectedListener listener) {
|
||||
this();
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all content in the listview
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void clear() {
|
||||
this.setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, new ArrayList<String>()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a list item is clicked.
|
||||
* Checks to see if the list item is a direction, if to it reports the selected direction's geopoint to the listener
|
||||
* (non-Javadoc)
|
||||
* @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
|
||||
*/
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View w, int position, long id) {
|
||||
if(position < mPoints.size())
|
||||
if(mListener != null)
|
||||
mListener.onDirectionSelected(mPoints.get(position));
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see android.support.v4.app.Fragment#onStart()
|
||||
*/
|
||||
@Override
|
||||
public void onStart() {
|
||||
this.setListShown(true);
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the directions from the provided DirectionsOverlay object
|
||||
* @param directions
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setDirections(final DirectionsOverlay directions) {
|
||||
mPoints = directions.getPoints();
|
||||
this.setListAdapter(new DirectionsAdapter(getActivity(), directions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text to be displayed while the list is empty
|
||||
* @param text
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void SetEmptyText(String text){
|
||||
this.setEmptyText(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* MapFragment.java
|
||||
* @date Jan 7, 2012
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.TwentyCodes.android.location.MapView;
|
||||
import com.TwentyCodes.android.location.R;
|
||||
import com.TwentyCodes.android.location.R.id;
|
||||
import com.TwentyCodes.android.location.R.layout;
|
||||
import com.google.android.maps.GeoPoint;
|
||||
import com.google.android.maps.Overlay;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
public void addOverlay(Overlay overlay){
|
||||
mMapView.getOverlays().add(overlay);
|
||||
}
|
||||
|
||||
/**
|
||||
* changes the map mode
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void changeMapMode() {
|
||||
mMapView.setSatellite(!mMapView.isSatellite());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mapview
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public MapView getMap(){
|
||||
return mMapView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void removeOverlay(Object overlay){
|
||||
mMapView.getOverlays().remove(overlay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the center of the map to the provided point
|
||||
* @param point
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public boolean setMapCenter(GeoPoint point){
|
||||
if(point == null)
|
||||
return false;
|
||||
mMapView.getController().setCenter(point);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* UserOverlayMapFragmentBase.java
|
||||
* @date Jan 12, 2012
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.fragments;
|
||||
|
||||
import com.TwentyCodes.android.location.CompassListener;
|
||||
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
||||
import com.TwentyCodes.android.location.MapView;
|
||||
import com.TwentyCodes.android.overlays.SkyHookUserOverlay;
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* disables the GPS dialog
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void disableGPSDialog(){
|
||||
mUserOverlay.disableGPSDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* enables the GPS dialog
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void enableGPSDialog(){
|
||||
mUserOverlay.enableGPSDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the useroverlay to pan the map to follow the user
|
||||
* @param followUser
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void followUser(boolean followUser){
|
||||
mUserOverlay.followUser(followUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.fragments.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.fragments.MapFragmentBase#onPause()
|
||||
*/
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mUserOverlay.disableMyLocation();
|
||||
removeOverlay(mUserOverlay);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.fragments.MapFragmentBase#onResume()
|
||||
*/
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if(mUserOverlay != null)
|
||||
mUserOverlay.enableMyLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* reorders the overlays to the UserOverlay always on top
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void reorderOverlays() {
|
||||
getMap().getOverlays().remove(mUserOverlay);
|
||||
getMap().getOverlays().add(mUserOverlay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param needleResId
|
||||
* @param backgroundResId
|
||||
* @param x
|
||||
* @param y
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setCompassDrawables(int needleResId, int backgroundResId, int x, int y){
|
||||
mUserOverlay.setCompassDrawables(needleResId, backgroundResId, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* UserOverlayMapFragment.java
|
||||
* @date Jan 12, 2012
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.fragments;
|
||||
|
||||
import com.TwentyCodes.android.location.CompassListener;
|
||||
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
||||
import com.TwentyCodes.android.location.MapView;
|
||||
import com.TwentyCodes.android.overlays.UserOverlay;
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* disables the GPS dialog
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void disableGPSDialog(){
|
||||
mUserOverlay.disableGPSDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* enables the GPS dialog
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void enableGPSDialog(){
|
||||
mUserOverlay.enableGPSDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the useroverlay to pan the map to follow the user
|
||||
* @param followUser
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void followUser(boolean followUser){
|
||||
mUserOverlay.followUser(followUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.fragments.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.fragments.MapFragmentBase#onPause()
|
||||
*/
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mUserOverlay.disableMyLocation();
|
||||
removeOverlay(mUserOverlay);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.fragments.MapFragmentBase#onResume()
|
||||
*/
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if(mUserOverlay != null)
|
||||
mUserOverlay.enableMyLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* reorders the overlays to the UserOverlay always on top
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void reorderOverlays() {
|
||||
getMap().getOverlays().remove(mUserOverlay);
|
||||
getMap().getOverlays().add(mUserOverlay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param needleResId
|
||||
* @param backgroundResId
|
||||
* @param x
|
||||
* @param y
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setCompassDrawables(int needleResId, int backgroundResId, int x, int y){
|
||||
mUserOverlay.setCompassDrawables(needleResId, backgroundResId, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user