Cleaned up code
This commit is contained in:
@@ -30,29 +30,31 @@ import com.google.android.maps.Projection;
|
||||
|
||||
/**
|
||||
* This class will be used to build user overlays
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public abstract class BaseUserOverlay extends Overlay implements GeoPointLocationListener, CompassListener {
|
||||
|
||||
/**
|
||||
* This thread is responsible for animating the user icon
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class AnimationThread extends Thread {
|
||||
|
||||
private boolean isAborted;
|
||||
|
||||
public void abort(){
|
||||
public void abort() {
|
||||
isAborted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method of this animation thread
|
||||
* (non-Javadoc)
|
||||
* Main method of this animation thread (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Thread#run()
|
||||
*/
|
||||
@Override
|
||||
public void run(){
|
||||
public void run() {
|
||||
super.run();
|
||||
int index = 0;
|
||||
boolean isCountingDown = false;
|
||||
@@ -61,41 +63,41 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
if (isAborted)
|
||||
break;
|
||||
|
||||
switch(index){
|
||||
case 1:
|
||||
mUserArrow = R.drawable.user_arrow_animation_2;
|
||||
if(isCountingDown)
|
||||
index--;
|
||||
else
|
||||
index++;
|
||||
|
||||
try {
|
||||
sleep(100l);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
mUserArrow = R.drawable.user_arrow_animation_3;
|
||||
switch (index) {
|
||||
case 1:
|
||||
mUserArrow = R.drawable.user_arrow_animation_2;
|
||||
if (isCountingDown)
|
||||
index--;
|
||||
isCountingDown = true;
|
||||
try {
|
||||
sleep(200l);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
mUserArrow = R.drawable.user_arrow_animation_1;
|
||||
else
|
||||
index++;
|
||||
isCountingDown = false;
|
||||
try {
|
||||
sleep(2000l);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
try {
|
||||
sleep(100l);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
mUserArrow = R.drawable.user_arrow_animation_3;
|
||||
index--;
|
||||
isCountingDown = true;
|
||||
try {
|
||||
sleep(200l);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
mUserArrow = R.drawable.user_arrow_animation_1;
|
||||
index++;
|
||||
isCountingDown = false;
|
||||
try {
|
||||
sleep(2000l);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +123,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
|
||||
/**
|
||||
* Construct a new UserOverlay
|
||||
*
|
||||
* @param mapView
|
||||
* @param context
|
||||
* @author ricky barrette
|
||||
@@ -135,6 +138,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
|
||||
/**
|
||||
* Construct a new UserOverlayTODO Auto-generated method stub
|
||||
*
|
||||
* @param mapView
|
||||
* @param context
|
||||
* @param followUser
|
||||
@@ -147,38 +151,42 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
|
||||
/**
|
||||
* Disables the compass
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public final void disableCompass(){
|
||||
public final void disableCompass() {
|
||||
isCompassEnabled = false;
|
||||
mMapView.getOverlays().remove(mCompass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops location updates and removes the overlay from view
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public final void disableMyLocation(){
|
||||
Log.d(TAG,"disableMyLocation()");
|
||||
public final void disableMyLocation() {
|
||||
Log.d(TAG, "disableMyLocation()");
|
||||
onMyLocationDisabled();
|
||||
isEnabled = false;
|
||||
mCompass.disable();
|
||||
if(mListener != null)
|
||||
if (mListener != null)
|
||||
mListener.onFirstFix(false);
|
||||
mAnimationThread.abort();
|
||||
}
|
||||
|
||||
/**
|
||||
* we override this methods so we can provide a drawable and a location to draw on the canvas.
|
||||
* (non-Javadoc)
|
||||
* @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean)
|
||||
* we override this methods so we can provide a drawable and a location to
|
||||
* draw on the canvas. (non-Javadoc)
|
||||
*
|
||||
* @see com.google.android.maps.Overlay#draw(android.graphics.Canvas,
|
||||
* com.google.android.maps.MapView, boolean)
|
||||
* @param canvas
|
||||
* @param mapView
|
||||
* @param shadow
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void draw(Canvas canvas, final MapView mapView, final boolean shadow){
|
||||
public void draw(Canvas canvas, final MapView mapView, final boolean shadow) {
|
||||
if (isEnabled && mPoint != null) {
|
||||
final Point center = new Point();
|
||||
final Point left = new Point();
|
||||
@@ -189,19 +197,24 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
canvas = drawAccuracyCircle(center, left, canvas);
|
||||
canvas = drawUser(center, mBearing, canvas);
|
||||
/*
|
||||
* the following log is used to demonstrate if the leftGeo point is the correct
|
||||
* the following log is used to demonstrate if the leftGeo point is
|
||||
* the correct
|
||||
*/
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG, GeoUtils.distanceKm(mPoint, leftGeo) * 1000+"m");
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, GeoUtils.distanceKm(mPoint, leftGeo) * 1000 + "m");
|
||||
}
|
||||
super.draw(canvas, mapView, shadow);
|
||||
}
|
||||
|
||||
/**
|
||||
* draws an accuracy circle onto the canvas supplied
|
||||
* @param center point of the circle
|
||||
* @param left point of the circle
|
||||
* @param canvas to be drawn on
|
||||
*
|
||||
* @param center
|
||||
* point of the circle
|
||||
* @param left
|
||||
* point of the circle
|
||||
* @param canvas
|
||||
* to be drawn on
|
||||
* @return modified canvas
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@@ -212,7 +225,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
* get radius of the circle being drawn by
|
||||
*/
|
||||
int circleRadius = center.x - left.x;
|
||||
if(circleRadius <= 0)
|
||||
if (circleRadius <= 0)
|
||||
circleRadius = left.x - center.x;
|
||||
/*
|
||||
* paint a blue circle on the map
|
||||
@@ -230,10 +243,9 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
canvas.drawCircle(center.x, center.y, circleRadius, paint);
|
||||
|
||||
/*
|
||||
* for testing
|
||||
* draw a dot over the left geopoint
|
||||
* for testing draw a dot over the left geopoint
|
||||
*/
|
||||
if(Debug.DEBUG){
|
||||
if (Debug.DEBUG) {
|
||||
paint.setColor(Color.RED);
|
||||
final RectF oval = new RectF(left.x - 1, left.y - 1, left.x + 1, left.y + 1);
|
||||
canvas.drawOval(oval, paint);
|
||||
@@ -243,40 +255,34 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
}
|
||||
|
||||
/**
|
||||
* draws user arrow that points north based on bearing onto the supplied canvas
|
||||
* @param point to draw user arrow on
|
||||
* @param bearing of the device
|
||||
* @param canvas to draw on
|
||||
* draws user arrow that points north based on bearing onto the supplied
|
||||
* canvas
|
||||
*
|
||||
* @param point
|
||||
* to draw user arrow on
|
||||
* @param bearing
|
||||
* of the device
|
||||
* @param canvas
|
||||
* to draw on
|
||||
* @return modified canvas
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private Canvas drawUser(final Point point, final float bearing, final Canvas canvas){
|
||||
private Canvas drawUser(final Point point, final float bearing, final Canvas canvas) {
|
||||
final Bitmap user = BitmapFactory.decodeResource(mContext.getResources(), mUserArrow);
|
||||
final Matrix matrix = new Matrix();
|
||||
matrix.postRotate(bearing);
|
||||
final Bitmap rotatedBmp = Bitmap.createBitmap(
|
||||
user,
|
||||
0, 0,
|
||||
user.getWidth(),
|
||||
user.getHeight(),
|
||||
matrix,
|
||||
true
|
||||
);
|
||||
canvas.drawBitmap(
|
||||
rotatedBmp,
|
||||
point.x - rotatedBmp.getWidth() / 2,
|
||||
point.y - rotatedBmp.getHeight() / 2,
|
||||
null
|
||||
);
|
||||
final Bitmap rotatedBmp = Bitmap.createBitmap(user, 0, 0, user.getWidth(), user.getHeight(), matrix, true);
|
||||
canvas.drawBitmap(rotatedBmp, point.x - rotatedBmp.getWidth() / 2, point.y - rotatedBmp.getHeight() / 2, null);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the compass
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void enableCompass(){
|
||||
if(! isCompassEnabled){
|
||||
public void enableCompass() {
|
||||
if (!isCompassEnabled) {
|
||||
mMapView.getOverlays().add(mCompass);
|
||||
isCompassEnabled = true;
|
||||
}
|
||||
@@ -284,12 +290,13 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
|
||||
/**
|
||||
* Attempts to enable MyLocation, registering for updates from provider
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void enableMyLocation(){
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG,"enableMyLocation()");
|
||||
if (! isEnabled) {
|
||||
public void enableMyLocation() {
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, "enableMyLocation()");
|
||||
if (!isEnabled) {
|
||||
|
||||
mAnimationThread = new AnimationThread();
|
||||
mAnimationThread.start();
|
||||
@@ -298,19 +305,20 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
isEnabled = true;
|
||||
mCompass.enable(this);
|
||||
isFistFix = true;
|
||||
if(mListener != null)
|
||||
if (mListener != null)
|
||||
mListener.onFirstFix(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the map to follow the user
|
||||
*
|
||||
* @param followUser
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void followUser(final boolean followUser){
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG,"followUser()");
|
||||
public void followUser(final boolean followUser) {
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, "followUser()");
|
||||
isFollowingUser = followUser;
|
||||
}
|
||||
|
||||
@@ -318,40 +326,44 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
* @return return the current destination
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getDestination(){
|
||||
public GeoPoint getDestination() {
|
||||
return mCompass.getDestination();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the users current bearing
|
||||
*
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public float getUserBearing(){
|
||||
public float getUserBearing() {
|
||||
return mBearing;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the users current location
|
||||
*
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getUserLocation(){
|
||||
public GeoPoint getUserLocation() {
|
||||
return mPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompassUpdate(final float bearing) {
|
||||
if(mCompassListener != null)
|
||||
if (mCompassListener != null)
|
||||
mCompassListener.onCompassUpdate(bearing);
|
||||
mBearing = bearing;
|
||||
mMapView.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* called when the SkyHook location changes, this mthod is resposiable for updating the overlay location and accuracy circle.
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.SkyHook.GeoPointLocationListener.location.LocationListener#onLocationChanged(com.google.android.maps.GeoPoint, float)
|
||||
* called when the SkyHook location changes, this mthod is resposiable for
|
||||
* updating the overlay location and accuracy circle. (non-Javadoc)
|
||||
*
|
||||
* @see com.TwentyCodes.android.SkyHook.GeoPointLocationListener.location.LocationListener#onLocationChanged(com.google.android.maps.GeoPoint,
|
||||
* float)
|
||||
* @param point
|
||||
* @param accuracy
|
||||
* @author ricky barrette
|
||||
@@ -359,26 +371,26 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
@Override
|
||||
public void onLocationChanged(final GeoPoint point, final int accuracy) {
|
||||
|
||||
if(mCompass != null)
|
||||
if (mCompass != null)
|
||||
mCompass.setLocation(point);
|
||||
|
||||
/*
|
||||
* if this is the first fix
|
||||
* set map center the users location, and zoom to the max zoom level
|
||||
* if this is the first fix set map center the users location, and zoom
|
||||
* to the max zoom level
|
||||
*/
|
||||
if(point != null && isFistFix){
|
||||
if (point != null && isFistFix) {
|
||||
mMapView.getController().setCenter(point);
|
||||
mMapView.getController().setZoom( mMapView.getMaxZoomLevel() - 2 );
|
||||
if(mListener != null)
|
||||
mMapView.getController().setZoom(mMapView.getMaxZoomLevel() - 2);
|
||||
if (mListener != null)
|
||||
mListener.onFirstFix(true);
|
||||
isFistFix = false;
|
||||
}
|
||||
|
||||
//update the users point, and accuracy for the UI
|
||||
// update the users point, and accuracy for the UI
|
||||
mPoint = point;
|
||||
mAccuracy = accuracy;
|
||||
mMapView.invalidate();
|
||||
if(mListener != null)
|
||||
if (mListener != null)
|
||||
mListener.onLocationChanged(point, accuracy);
|
||||
|
||||
if (isFollowingUser)
|
||||
@@ -386,19 +398,24 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when disableMyLocation is called. This is where you want to disable any location updates from your provider
|
||||
* Called when disableMyLocation is called. This is where you want to
|
||||
* disable any location updates from your provider
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public abstract void onMyLocationDisabled();
|
||||
|
||||
/**
|
||||
* Called when the enableMyLocation() is called. This is where you want to ask your location provider for updates
|
||||
* Called when the enableMyLocation() is called. This is where you want to
|
||||
* ask your location provider for updates
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public abstract void onMyLocationEnabled();
|
||||
|
||||
/**
|
||||
* pans the map view if the user is off screen.
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void panToUserIfOffMap(final GeoPoint user) {
|
||||
@@ -410,27 +427,29 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
final double whichIsGreater = distanceLat > distanceLon ? distanceLat : distanceLon;
|
||||
|
||||
/**
|
||||
* if the user is one the map, keep them their
|
||||
* else don't pan to user unless they pan pack to them
|
||||
* if the user is one the map, keep them their else don't pan to user
|
||||
* unless they pan pack to them
|
||||
*/
|
||||
if( ! (distance > whichIsGreater) )
|
||||
if (distance > distanceLat || distance > distanceLon)
|
||||
if (!(distance > whichIsGreater))
|
||||
if (distance > distanceLat || distance > distanceLon)
|
||||
mMapView.getController().animateTo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to register the listener for location updates
|
||||
*
|
||||
* @param listener
|
||||
* @author Ricky Barrette
|
||||
*/
|
||||
public void registerListener(final GeoPointLocationListener listener){
|
||||
Log.d(TAG,"registerListener()");
|
||||
public void registerListener(final GeoPointLocationListener listener) {
|
||||
Log.d(TAG, "registerListener()");
|
||||
if (mListener == null)
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the compass drawables and location
|
||||
*
|
||||
* @param needleResId
|
||||
* @param backgroundResId
|
||||
* @param x
|
||||
@@ -443,27 +462,31 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
||||
|
||||
/**
|
||||
* Sets the CompassListener
|
||||
*
|
||||
* @param listener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setCompassListener(final CompassListener listener){
|
||||
public void setCompassListener(final CompassListener listener) {
|
||||
mCompassListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the destination for the compass
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setDestination(final GeoPoint destination){
|
||||
if(mCompass != null)
|
||||
public void setDestination(final GeoPoint destination) {
|
||||
if (mCompass != null)
|
||||
mCompass.setDestination(destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* UnResgisters the listener. after this call you will no longer get location updates
|
||||
* UnResgisters the listener. after this call you will no longer get
|
||||
* location updates
|
||||
*
|
||||
* @author Ricky Barrette
|
||||
*/
|
||||
public void unRegisterListener(){
|
||||
public void unRegisterListener() {
|
||||
mListener = null;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,9 @@ import com.google.android.maps.MapView;
|
||||
import com.google.android.maps.Overlay;
|
||||
|
||||
/**
|
||||
* A Simple compass overlay that will be used to point towards a destination or north
|
||||
* A Simple compass overlay that will be used to point towards a destination or
|
||||
* north
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class CompasOverlay extends Overlay implements CompassListener {
|
||||
@@ -43,6 +45,7 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
|
||||
/**
|
||||
* Creates a new CompasOverlay
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public CompasOverlay(final Context context) {
|
||||
@@ -54,26 +57,30 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
|
||||
/**
|
||||
* Creates a new CompasOverlay
|
||||
*
|
||||
* @param context
|
||||
* @param destination
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public CompasOverlay(final Context context, final GeoPoint destination){
|
||||
public CompasOverlay(final Context context, final GeoPoint destination) {
|
||||
this(context);
|
||||
mDestination = destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CompasOverlay
|
||||
*
|
||||
* @param context
|
||||
* @param destination
|
||||
* @param needleResId
|
||||
* @param backgroundResId
|
||||
* @param x dip
|
||||
* @param y dip
|
||||
* @param x
|
||||
* dip
|
||||
* @param y
|
||||
* dip
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public CompasOverlay(final Context context, final GeoPoint destination, final int needleResId, final int backgroundResId, final int x, final int y){
|
||||
public CompasOverlay(final Context context, final GeoPoint destination, final int needleResId, final int backgroundResId, final int x, final int y) {
|
||||
this(context, destination);
|
||||
mX = convertDipToPx(x);
|
||||
mY = convertDipToPx(y);
|
||||
@@ -83,6 +90,7 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
|
||||
/**
|
||||
* Creates a new CompasOverlay
|
||||
*
|
||||
* @param context
|
||||
* @param needleResId
|
||||
* @param backgroundResId
|
||||
@@ -90,12 +98,13 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
* @param y
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public CompasOverlay(final Context context, final int needleResId, final int backgroundResId, final int x, final int y){
|
||||
public CompasOverlay(final Context context, final int needleResId, final int backgroundResId, final int x, final int y) {
|
||||
this(context, null, needleResId, backgroundResId, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts dip to px
|
||||
*
|
||||
* @param dip
|
||||
* @return px
|
||||
* @author ricky barrette
|
||||
@@ -107,9 +116,10 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
|
||||
/**
|
||||
* Disables the compass overlay
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void disable(){
|
||||
public void disable() {
|
||||
isEnabled = false;
|
||||
mCompassSensor.disable();
|
||||
mListener = null;
|
||||
@@ -117,43 +127,30 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean)
|
||||
*
|
||||
* @see com.google.android.maps.Overlay#draw(android.graphics.Canvas,
|
||||
* com.google.android.maps.MapView, boolean)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
|
||||
|
||||
if(isEnabled){
|
||||
//set the center of the compass in the top left corner of the screen
|
||||
if (isEnabled) {
|
||||
// set the center of the compass in the top left corner of the
|
||||
// screen
|
||||
final Point point = new Point();
|
||||
point.set(mX, mY);
|
||||
|
||||
//draw compass background
|
||||
final Bitmap compass = BitmapFactory.decodeResource( mContext.getResources(), mBackgroundResId);
|
||||
canvas.drawBitmap(compass,
|
||||
point.x - compass.getWidth() / 2,
|
||||
point.y - compass.getHeight() / 2,
|
||||
null
|
||||
);
|
||||
// draw compass background
|
||||
final Bitmap compass = BitmapFactory.decodeResource(mContext.getResources(), mBackgroundResId);
|
||||
canvas.drawBitmap(compass, point.x - compass.getWidth() / 2, point.y - compass.getHeight() / 2, null);
|
||||
|
||||
//draw the compass needle
|
||||
final Bitmap arrowBitmap = BitmapFactory.decodeResource( mContext.getResources(), mNeedleResId);
|
||||
// draw the compass needle
|
||||
final Bitmap arrowBitmap = BitmapFactory.decodeResource(mContext.getResources(), mNeedleResId);
|
||||
final Matrix matrix = new Matrix();
|
||||
matrix.postRotate(GeoUtils.calculateBearing(mLocation, mDestination, mBearing));
|
||||
final Bitmap rotatedBmp = Bitmap.createBitmap(
|
||||
arrowBitmap,
|
||||
0, 0,
|
||||
arrowBitmap.getWidth(),
|
||||
arrowBitmap.getHeight(),
|
||||
matrix,
|
||||
true
|
||||
);
|
||||
canvas.drawBitmap(
|
||||
rotatedBmp,
|
||||
point.x - rotatedBmp.getWidth() / 2,
|
||||
point.y - rotatedBmp.getHeight() / 2,
|
||||
null
|
||||
);
|
||||
final Bitmap rotatedBmp = Bitmap.createBitmap(arrowBitmap, 0, 0, arrowBitmap.getWidth(), arrowBitmap.getHeight(), matrix, true);
|
||||
canvas.drawBitmap(rotatedBmp, point.x - rotatedBmp.getWidth() / 2, point.y - rotatedBmp.getHeight() / 2, null);
|
||||
mapView.invalidate();
|
||||
}
|
||||
super.draw(canvas, mapView, shadow);
|
||||
@@ -161,10 +158,11 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
|
||||
/**
|
||||
* Enables the compass overlay
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void enable(){
|
||||
if(! isEnabled){
|
||||
public void enable() {
|
||||
if (!isEnabled) {
|
||||
isEnabled = true;
|
||||
mCompassSensor.enable(this);
|
||||
}
|
||||
@@ -172,10 +170,11 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
|
||||
/**
|
||||
* Enables the compass overlay
|
||||
*
|
||||
* @param listener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void enable(final CompassListener listener){
|
||||
public void enable(final CompassListener listener) {
|
||||
mListener = listener;
|
||||
enable();
|
||||
}
|
||||
@@ -184,7 +183,7 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
* @return the current bearing
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public float getBearing(){
|
||||
public float getBearing() {
|
||||
return mBearing;
|
||||
}
|
||||
|
||||
@@ -192,13 +191,14 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
* @return return the current destination
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getDestination(){
|
||||
public GeoPoint getDestination() {
|
||||
return mDestination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the compass Sensor to update the current bearing
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@@ -209,7 +209,7 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
/*
|
||||
* pass it down the chain
|
||||
*/
|
||||
if(mListener != null)
|
||||
if (mListener != null)
|
||||
mListener.onCompassUpdate(bearing);
|
||||
}
|
||||
|
||||
@@ -217,18 +217,20 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
* @param destination
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setDestination(final GeoPoint destination){
|
||||
public void setDestination(final GeoPoint destination) {
|
||||
mDestination = destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param needleResId
|
||||
* @param backgroundResId
|
||||
* @param x dip
|
||||
* @param y dip
|
||||
* @param x
|
||||
* dip
|
||||
* @param y
|
||||
* dip
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setDrawables(final int needleResId, final int backgroundResId, final int x, final int y){
|
||||
public void setDrawables(final int needleResId, final int backgroundResId, final int x, final int y) {
|
||||
mX = convertDipToPx(x);
|
||||
mY = convertDipToPx(y);
|
||||
mNeedleResId = needleResId;
|
||||
@@ -239,7 +241,7 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
* @param location
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setLocation(final GeoPoint location){
|
||||
public void setLocation(final GeoPoint location) {
|
||||
mLocation = location;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ import com.TwentyCodes.android.location.MapView;
|
||||
import com.google.android.maps.GeoPoint;
|
||||
|
||||
/**
|
||||
* This Overlay class will be used to display provided by the Google Directions API on a map
|
||||
* This Overlay class will be used to display provided by the Google Directions
|
||||
* API on a map
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class DirectionsOverlay {
|
||||
@@ -34,7 +36,7 @@ public class DirectionsOverlay {
|
||||
/**
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public interface OnDirectionsCompleteListener{
|
||||
public interface OnDirectionsCompleteListener {
|
||||
public void onDirectionsComplete(DirectionsOverlay directionsOverlay);
|
||||
}
|
||||
|
||||
@@ -51,15 +53,19 @@ public class DirectionsOverlay {
|
||||
|
||||
/**
|
||||
* Downloads and Creates a new DirectionsOverlay from the provided points
|
||||
* @param origin point
|
||||
* @param destination point
|
||||
*
|
||||
* @param origin
|
||||
* point
|
||||
* @param destination
|
||||
* point
|
||||
* @author ricky barrette
|
||||
* @throws IOException
|
||||
* @throws ClientProtocolException
|
||||
* @throws IllegalStateException
|
||||
* @throws JSONException
|
||||
*/
|
||||
public DirectionsOverlay(final MapView map, final GeoPoint origin, final GeoPoint destination, final OnDirectionsCompleteListener listener) throws IllegalStateException, ClientProtocolException, IOException, JSONException {
|
||||
public DirectionsOverlay(final MapView map, final GeoPoint origin, final GeoPoint destination, final OnDirectionsCompleteListener listener)
|
||||
throws IllegalStateException, ClientProtocolException, IOException, JSONException {
|
||||
mMapView = map;
|
||||
mListener = listener;
|
||||
final String json = downloadJSON(generateUrl(origin, destination));
|
||||
@@ -68,11 +74,12 @@ public class DirectionsOverlay {
|
||||
|
||||
/**
|
||||
* Creates a new DirectionsOverlay from the provided String JSON
|
||||
*
|
||||
* @param json
|
||||
* @throws JSONException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public DirectionsOverlay(final MapView map, final String json, final OnDirectionsCompleteListener listener) throws JSONException{
|
||||
public DirectionsOverlay(final MapView map, final String json, final OnDirectionsCompleteListener listener) throws JSONException {
|
||||
mListener = listener;
|
||||
mMapView = map;
|
||||
drawPath(json);
|
||||
@@ -80,14 +87,16 @@ public class DirectionsOverlay {
|
||||
|
||||
/**
|
||||
* Deocodes googles polyline
|
||||
*
|
||||
* @param encoded
|
||||
* @return a list of geopoints representing the path
|
||||
* @author Mark McClure http://facstaff.unca.edu/mcmcclur/googlemaps/encodepolyline/
|
||||
* @author Mark McClure
|
||||
* http://facstaff.unca.edu/mcmcclur/googlemaps/encodepolyline/
|
||||
* @author ricky barrette
|
||||
* @throws JSONException
|
||||
*/
|
||||
private void decodePoly(final JSONObject step) throws JSONException {
|
||||
if(Debug.DEBUG)
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, "decodePoly");
|
||||
|
||||
final String encoded = step.getJSONObject("polyline").getString("points");
|
||||
@@ -118,17 +127,16 @@ public class DirectionsOverlay {
|
||||
|
||||
final GeoPoint p = new GeoPoint((int) (lat / 1E5 * 1E6), (int) (lng / 1E5 * 1E6));
|
||||
|
||||
if(Debug.DEBUG){
|
||||
Log.d(TAG, "current = "+ p.toString());
|
||||
if(last != null)
|
||||
Log.d(TAG, "last = "+ last.toString());
|
||||
if (Debug.DEBUG) {
|
||||
Log.d(TAG, "current = " + p.toString());
|
||||
if (last != null)
|
||||
Log.d(TAG, "last = " + last.toString());
|
||||
}
|
||||
|
||||
|
||||
if(last != null)
|
||||
if (last != null)
|
||||
mPath.add(new PathOverlay(last, p, Color.RED));
|
||||
// else
|
||||
// mPath.add(new PathOverlay(p, 5, Color.GREEN));
|
||||
// else
|
||||
// mPath.add(new PathOverlay(p, 5, Color.GREEN));
|
||||
|
||||
last = p;
|
||||
}
|
||||
@@ -137,6 +145,7 @@ public class DirectionsOverlay {
|
||||
|
||||
/**
|
||||
* Downloads Google Directions JSON from the Internet
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
* @throws IllegalStateException
|
||||
@@ -145,9 +154,9 @@ public class DirectionsOverlay {
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private String downloadJSON(final String url) throws IllegalStateException, ClientProtocolException, IOException {
|
||||
if(Debug.DEBUG)
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, url);
|
||||
if(url == null)
|
||||
if (url == null)
|
||||
throw new NullPointerException();
|
||||
final StringBuffer response = new StringBuffer();
|
||||
final BufferedReader br = new BufferedReader(new InputStreamReader(new DefaultHttpClient().execute(new HttpGet(url)).getEntity().getContent()));
|
||||
@@ -157,16 +166,17 @@ public class DirectionsOverlay {
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new DirectionsOverlay from the json provided
|
||||
* @param json of Google Directions API
|
||||
*
|
||||
* @param json
|
||||
* of Google Directions API
|
||||
* @author ricky barrette
|
||||
* @return
|
||||
* @throws JSONException
|
||||
*/
|
||||
public void drawPath(final String json) throws JSONException{
|
||||
if(Debug.DEBUG){
|
||||
public void drawPath(final String json) throws JSONException {
|
||||
if (Debug.DEBUG) {
|
||||
Log.d(TAG, "drawPath");
|
||||
Log.d(TAG, json);
|
||||
}
|
||||
@@ -176,46 +186,52 @@ public class DirectionsOverlay {
|
||||
mDistance = new ArrayList<String>();
|
||||
mDuration = new ArrayList<String>();
|
||||
|
||||
//get first route
|
||||
// get first route
|
||||
final JSONObject route = new JSONObject(json).getJSONArray("routes").getJSONObject(0);
|
||||
|
||||
mCopyRights = route.getString("copyrights");
|
||||
//route.getString("status");
|
||||
// route.getString("status");
|
||||
|
||||
final JSONObject leg = route.getJSONArray("legs").getJSONObject(0);
|
||||
getDistance(leg);
|
||||
getDuration(leg);
|
||||
// mMapView.getOverlays().add(new PathOverlay(getGeoPoint(leg.getJSONObject("start_location")), 12, Color.GREEN));
|
||||
// mMapView.getOverlays().add(new PathOverlay(getGeoPoint(leg.getJSONObject("end_location")), 12, Color.RED));
|
||||
// mMapView.getOverlays().add(new
|
||||
// PathOverlay(getGeoPoint(leg.getJSONObject("start_location")), 12,
|
||||
// Color.GREEN));
|
||||
// mMapView.getOverlays().add(new
|
||||
// PathOverlay(getGeoPoint(leg.getJSONObject("end_location")), 12,
|
||||
// Color.RED));
|
||||
|
||||
leg.getString("start_address");
|
||||
leg.getString("end_address");
|
||||
|
||||
// JSONArray warnings = leg.getJSONArray("warnings");
|
||||
// for(int i = 0; i < warnings.length(); i++){
|
||||
// mWarnings.add(warnings.get)w
|
||||
// }w
|
||||
// JSONArray warnings = leg.getJSONArray("warnings");
|
||||
// for(int i = 0; i < warnings.length(); i++){
|
||||
// mWarnings.add(warnings.get)w
|
||||
// }w
|
||||
|
||||
/*
|
||||
* here we will parse the steps of the directions
|
||||
*/
|
||||
if(Debug.DEBUG)
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, "processing steps");
|
||||
final JSONArray steps = leg.getJSONArray("steps");
|
||||
JSONObject step = null;
|
||||
for(int i = 0; i < steps.length(); i++){
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG, "step "+i);
|
||||
for (int i = 0; i < steps.length(); i++) {
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, "step " + i);
|
||||
|
||||
step = steps.getJSONObject(i);
|
||||
|
||||
if(Debug.DEBUG){
|
||||
Log.d(TAG, "start "+getGeoPoint(step.getJSONObject("start_location")).toString());
|
||||
Log.d(TAG, "end "+getGeoPoint(step.getJSONObject("end_location")).toString());
|
||||
if (Debug.DEBUG) {
|
||||
Log.d(TAG, "start " + getGeoPoint(step.getJSONObject("start_location")).toString());
|
||||
Log.d(TAG, "end " + getGeoPoint(step.getJSONObject("end_location")).toString());
|
||||
}
|
||||
|
||||
// if(Debug.DEBUG)
|
||||
// mMapView.getOverlays().add(new PathOverlay(getGeoPoint(step.getJSONObject("start_location")), getGeoPoint(step.getJSONObject("end_location")), Color.MAGENTA));
|
||||
// if(Debug.DEBUG)
|
||||
// mMapView.getOverlays().add(new
|
||||
// PathOverlay(getGeoPoint(step.getJSONObject("start_location")),
|
||||
// getGeoPoint(step.getJSONObject("end_location")), Color.MAGENTA));
|
||||
|
||||
decodePoly(step);
|
||||
|
||||
@@ -224,19 +240,19 @@ public class DirectionsOverlay {
|
||||
mDistance.add(getDistance(step));
|
||||
|
||||
mDirections.add(step.getString("html_instructions"));
|
||||
// Log.d("TEST", step.getString("html_instructions"));
|
||||
// Log.d("TEST", step.getString("html_instructions"));
|
||||
mPoints.add(getGeoPoint(step.getJSONObject("start_location")));
|
||||
|
||||
}
|
||||
if(Debug.DEBUG)
|
||||
if (Debug.DEBUG)
|
||||
Log.d(TAG, "finished parsing");
|
||||
|
||||
if(mMapView != null){
|
||||
if (mMapView != null) {
|
||||
mMapView.getOverlays().addAll(mPath);
|
||||
mMapView.postInvalidate();
|
||||
}
|
||||
|
||||
if(mListener != null)
|
||||
if (mListener != null)
|
||||
mListener.onDirectionsComplete(DirectionsOverlay.this);
|
||||
}
|
||||
|
||||
@@ -246,23 +262,17 @@ public class DirectionsOverlay {
|
||||
* @return The Google API url for our directions
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private String generateUrl(final GeoPoint origin, final GeoPoint destination){
|
||||
return "http://maps.googleapis.com/maps/api/directions/json?&origin="+
|
||||
Double.toString(origin.getLatitudeE6() / 1.0E6)+
|
||||
","+
|
||||
Double.toString(origin.getLongitudeE6() / 1.0E6)+
|
||||
"&destination="+
|
||||
Double.toString(destination.getLatitudeE6() / 1.0E6)+
|
||||
","+
|
||||
Double.toString(destination.getLongitudeE6() / 1.0E6)+
|
||||
"&sensor=true&mode=walking";
|
||||
private String generateUrl(final GeoPoint origin, final GeoPoint destination) {
|
||||
return "http://maps.googleapis.com/maps/api/directions/json?&origin=" + Double.toString(origin.getLatitudeE6() / 1.0E6) + ","
|
||||
+ Double.toString(origin.getLongitudeE6() / 1.0E6) + "&destination=" + Double.toString(destination.getLatitudeE6() / 1.0E6) + ","
|
||||
+ Double.toString(destination.getLongitudeE6() / 1.0E6) + "&sensor=true&mode=walking";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public String getCopyrights(){
|
||||
public String getCopyrights() {
|
||||
return mCopyRights;
|
||||
}
|
||||
|
||||
@@ -280,7 +290,7 @@ public class DirectionsOverlay {
|
||||
* @throws JSONException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private String getDistance(final JSONObject step) throws JSONException{
|
||||
private String getDistance(final JSONObject step) throws JSONException {
|
||||
return step.getJSONObject("distance").getString("text");
|
||||
}
|
||||
|
||||
@@ -288,7 +298,7 @@ public class DirectionsOverlay {
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public ArrayList<String> getDistances(){
|
||||
public ArrayList<String> getDistances() {
|
||||
return mDistance;
|
||||
}
|
||||
|
||||
@@ -298,7 +308,7 @@ public class DirectionsOverlay {
|
||||
* @throws JSONException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private String getDuration(final JSONObject step) throws JSONException{
|
||||
private String getDuration(final JSONObject step) throws JSONException {
|
||||
return step.getJSONObject("duration").getString("text");
|
||||
}
|
||||
|
||||
@@ -306,26 +316,27 @@ public class DirectionsOverlay {
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public ArrayList<String> getDurations(){
|
||||
public ArrayList<String> getDurations() {
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a JSON location object into a GeoPoint
|
||||
*
|
||||
* @param point
|
||||
* @return Geopoint parsed from the provided JSON Object
|
||||
* @throws JSONException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private GeoPoint getGeoPoint(final JSONObject point) throws JSONException{
|
||||
return new GeoPoint((int) (point.getDouble("lat")*1E6), (int) (point.getDouble("lng")*1E6));
|
||||
private GeoPoint getGeoPoint(final JSONObject point) throws JSONException {
|
||||
return new GeoPoint((int) (point.getDouble("lat") * 1E6), (int) (point.getDouble("lng") * 1E6));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the array of PathOverlays
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public ArrayList<PathOverlay> getPath(){
|
||||
public ArrayList<PathOverlay> getPath() {
|
||||
return mPath;
|
||||
}
|
||||
|
||||
@@ -347,9 +358,11 @@ public class DirectionsOverlay {
|
||||
|
||||
/**
|
||||
* Removes the directions overlay from the map view
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void removePath() {
|
||||
if(mMapView.getOverlays().removeAll(mPath));
|
||||
if (mMapView.getOverlays().removeAll(mPath))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import com.google.android.maps.Projection;
|
||||
|
||||
/**
|
||||
* This imutable overlay class is used to draw a path and points on a map
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public final class PathOverlay extends Overlay {
|
||||
@@ -32,6 +33,7 @@ public final class PathOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
* Creates a new PathOverlay in path mode
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public PathOverlay(final GeoPoint start, final GeoPoint end, final int color) {
|
||||
@@ -44,12 +46,13 @@ public final class PathOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
* Creates a new PathOverlay in point mode. This is used to draw end points.
|
||||
*
|
||||
* @param point
|
||||
* @param radius
|
||||
* @param color
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public PathOverlay(final GeoPoint point, final int radius, final int color){
|
||||
public PathOverlay(final GeoPoint point, final int radius, final int color) {
|
||||
mMode = POINT;
|
||||
mRadius = radius;
|
||||
mStart = point;
|
||||
@@ -59,7 +62,8 @@ public final class PathOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param canvas canvas to be drawn on
|
||||
* @param canvas
|
||||
* canvas to be drawn on
|
||||
* @param mapView
|
||||
* @param shadow
|
||||
* @param when
|
||||
@@ -73,16 +77,16 @@ public final class PathOverlay extends Overlay {
|
||||
final Point point = new Point();
|
||||
projection.toPixels(mStart, point);
|
||||
|
||||
switch (mMode){
|
||||
case POINT:
|
||||
final RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);
|
||||
canvas.drawOval(oval, paint);
|
||||
case PATH:
|
||||
final Point point2 = new Point();
|
||||
projection.toPixels(mEnd, point2);
|
||||
paint.setStrokeWidth(5);
|
||||
paint.setAlpha(120);
|
||||
canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
|
||||
switch (mMode) {
|
||||
case POINT:
|
||||
final RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);
|
||||
canvas.drawOval(oval, paint);
|
||||
case PATH:
|
||||
final Point point2 = new Point();
|
||||
projection.toPixels(mEnd, point2);
|
||||
paint.setStrokeWidth(5);
|
||||
paint.setAlpha(120);
|
||||
canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
|
||||
}
|
||||
super.draw(canvas, mapView, shadow);
|
||||
}
|
||||
@@ -91,7 +95,7 @@ public final class PathOverlay extends Overlay {
|
||||
* @return the end point of this path
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getEndPoint(){
|
||||
public GeoPoint getEndPoint() {
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
@@ -99,7 +103,7 @@ public final class PathOverlay extends Overlay {
|
||||
* @return the start point of this path
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getStartPoint(){
|
||||
public GeoPoint getStartPoint() {
|
||||
return mStart;
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,12 @@ import com.google.android.maps.OverlayItem;
|
||||
import com.google.android.maps.Projection;
|
||||
|
||||
/**
|
||||
* This class will used to draw a radius of a specified size in a specified location, then inserted into
|
||||
* an overlay list to be displayed a map
|
||||
* This class will used to draw a radius of a specified size in a specified
|
||||
* location, then inserted into an overlay list to be displayed a map
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class RadiusOverlay extends Overlay{
|
||||
public class RadiusOverlay extends Overlay {
|
||||
|
||||
public OverlayItem mOverlayItem;
|
||||
private GeoPoint mPoint;
|
||||
@@ -36,16 +37,22 @@ public class RadiusOverlay extends Overlay{
|
||||
|
||||
/**
|
||||
* Creates a new RadiusOverlay
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public RadiusOverlay(){
|
||||
public RadiusOverlay() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new RadiusOverlay object that can be inserted into an overlay list.
|
||||
* @param point center of radius geopoint
|
||||
* @param radius radius in meters
|
||||
* @param color desired color of the radius from Color API
|
||||
* Creates a new RadiusOverlay object that can be inserted into an overlay
|
||||
* list.
|
||||
*
|
||||
* @param point
|
||||
* center of radius geopoint
|
||||
* @param radius
|
||||
* radius in meters
|
||||
* @param color
|
||||
* desired color of the radius from Color API
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public RadiusOverlay(final GeoPoint point, final float radius, final int color) {
|
||||
@@ -56,25 +63,28 @@ public class RadiusOverlay extends Overlay{
|
||||
|
||||
/**
|
||||
* draws a specific radius on the mapview that is handed to it
|
||||
* @param canvas canvas to be drawn on
|
||||
*
|
||||
* @param canvas
|
||||
* canvas to be drawn on
|
||||
* @param mapView
|
||||
* @param shadow
|
||||
* @param when
|
||||
*/
|
||||
@Override
|
||||
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow){
|
||||
if(mPoint != null){
|
||||
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
|
||||
if (mPoint != null) {
|
||||
final Paint paint = new Paint();
|
||||
final Point center = new Point();
|
||||
final Point left = new Point();
|
||||
final Projection projection = mapView.getProjection();
|
||||
|
||||
/*
|
||||
* Calculate a geopoint that is "radius" meters away from geopoint point and
|
||||
* convert the given GeoPoint and leftGeo to onscreen pixel coordinates,
|
||||
* relative to the top-left of the MapView that provided this Projection.
|
||||
* Calculate a geopoint that is "radius" meters away from geopoint
|
||||
* point and convert the given GeoPoint and leftGeo to onscreen
|
||||
* pixel coordinates, relative to the top-left of the MapView that
|
||||
* provided this Projection.
|
||||
*/
|
||||
mRadiusPoint = GeoUtils.distanceFrom(mPoint , mRadius);
|
||||
mRadiusPoint = GeoUtils.distanceFrom(mPoint, mRadius);
|
||||
projection.toPixels(mRadiusPoint, left);
|
||||
projection.toPixels(mPoint, center);
|
||||
|
||||
@@ -82,7 +92,7 @@ public class RadiusOverlay extends Overlay{
|
||||
* get radius of the circle being drawn by
|
||||
*/
|
||||
int circleRadius = center.x - left.x;
|
||||
if(circleRadius <= 0)
|
||||
if (circleRadius <= 0)
|
||||
circleRadius = left.x - center.x;
|
||||
|
||||
/*
|
||||
@@ -94,11 +104,11 @@ public class RadiusOverlay extends Overlay{
|
||||
paint.setStyle(Style.STROKE);
|
||||
canvas.drawCircle(center.x, center.y, circleRadius, paint);
|
||||
|
||||
//draw a dot over the geopoint
|
||||
// draw a dot over the geopoint
|
||||
final RectF oval = new RectF(center.x - 2, center.y - 2, center.x + 2, center.y + 2);
|
||||
canvas.drawOval(oval, paint);
|
||||
|
||||
//fill the radius with a nice green
|
||||
// fill the radius with a nice green
|
||||
paint.setAlpha(25);
|
||||
paint.setStyle(Style.FILL);
|
||||
canvas.drawCircle(center.x, center.y, circleRadius, paint);
|
||||
@@ -109,19 +119,19 @@ public class RadiusOverlay extends Overlay{
|
||||
* @return the selected location
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getLocation(){
|
||||
public GeoPoint getLocation() {
|
||||
return mPoint;
|
||||
}
|
||||
|
||||
public int getZoomLevel() {
|
||||
// GeoUtils.GeoUtils.distanceFrom(mPoint , mRadius)
|
||||
// GeoUtils.GeoUtils.distanceFrom(mPoint , mRadius)
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTap(final GeoPoint p, final MapView mapView) {
|
||||
mPoint = p;
|
||||
if(mListener != null)
|
||||
if (mListener != null)
|
||||
mListener.onLocationSelected(p);
|
||||
return super.onTap(p, mapView);
|
||||
}
|
||||
@@ -130,7 +140,7 @@ public class RadiusOverlay extends Overlay{
|
||||
* @param color
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setColor(final int color){
|
||||
public void setColor(final int color) {
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
@@ -138,7 +148,7 @@ public class RadiusOverlay extends Overlay{
|
||||
* @param location
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setLocation(final GeoPoint location){
|
||||
public void setLocation(final GeoPoint location) {
|
||||
mPoint = location;
|
||||
}
|
||||
|
||||
@@ -147,11 +157,12 @@ public class RadiusOverlay extends Overlay{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param radius in meters
|
||||
* @param radius
|
||||
* in meters
|
||||
* @author ricky barrette
|
||||
* @param radius
|
||||
*/
|
||||
public void setRadius(final int radius){
|
||||
public void setRadius(final int radius) {
|
||||
mRadius = radius;
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,12 @@ import com.TwentyCodes.android.SkyHook.SkyHook;
|
||||
import com.google.android.maps.MapView;
|
||||
|
||||
/**
|
||||
* this class will be used to display the users location on the map using skyhook's call back methods
|
||||
* this class will be used to display the users location on the map using
|
||||
* skyhook's call back methods
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class SkyHookUserOverlay extends BaseUserOverlay{
|
||||
public class SkyHookUserOverlay extends BaseUserOverlay {
|
||||
|
||||
private final SkyHook mSkyHook;
|
||||
|
||||
@@ -25,6 +27,7 @@ public class SkyHookUserOverlay extends BaseUserOverlay{
|
||||
|
||||
/**
|
||||
* Construct a new SkyHookUserOverlay
|
||||
*
|
||||
* @param mapView
|
||||
* @param context
|
||||
* @param followUser
|
||||
@@ -41,8 +44,8 @@ public class SkyHookUserOverlay extends BaseUserOverlay{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the location provider needs to be disabled
|
||||
* (non-Javadoc)
|
||||
* Called when the location provider needs to be disabled (non-Javadoc)
|
||||
*
|
||||
* @see com.TwentyCodes.android.overlays.BaseUserOverlay#onMyLocationDisabled()
|
||||
*/
|
||||
@Override
|
||||
@@ -51,8 +54,8 @@ public class SkyHookUserOverlay extends BaseUserOverlay{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the location provider needs to be enabled
|
||||
* (non-Javadoc)
|
||||
* Called when the location provider needs to be enabled (non-Javadoc)
|
||||
*
|
||||
* @see com.TwentyCodes.android.overlays.BaseUserOverlay#onMyLocationEnabled()
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -12,9 +12,10 @@ import com.google.android.maps.MapView;
|
||||
|
||||
/**
|
||||
* This is the standard version of the UserOverlay.
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class UserOverlay extends BaseUserOverlay{
|
||||
public class UserOverlay extends BaseUserOverlay {
|
||||
|
||||
private final AndroidGPS mAndroidGPS;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user