added compass drawables to the lib
CompasOverlay.java updated all methods that set mX and mY to use dip instead of px updated default drawables to compass_sm.png and needle_sm.png added RadiusOverlay.java and LocationSelectedListener.java to the library
This commit is contained in:
@@ -91,22 +91,6 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
this(context, null, needleResId, backgroundResId, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculated the bearing from the current location to the current destination, or returns the bearing for north if there is no destination
|
||||
* @return bearing
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private float calculateBearing() {
|
||||
if( (mLocation == null) || (mDestination == null) )
|
||||
return mBearing;
|
||||
|
||||
float bearing = mBearing - GeoUtils.bearing(mLocation, mDestination).floatValue();
|
||||
if (bearing != 0)
|
||||
bearing = 360 - bearing;
|
||||
|
||||
return bearing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts dip to px
|
||||
* @param dip
|
||||
@@ -152,7 +136,7 @@ public class CompasOverlay extends Overlay implements CompassListener {
|
||||
//draw the compass needle
|
||||
Bitmap arrowBitmap = BitmapFactory.decodeResource( mContext.getResources(), mNeedleResId);
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(calculateBearing());
|
||||
matrix.postRotate(GeoUtils.calculateBearing(mLocation, mDestination, mBearing));
|
||||
Bitmap rotatedBmp = Bitmap.createBitmap(
|
||||
arrowBitmap,
|
||||
0, 0,
|
||||
|
||||
@@ -37,6 +37,30 @@ public class GeoUtils {
|
||||
|
||||
public static final int EARTH_RADIUS_KM = 6371;
|
||||
public static final double MILLION = 1000000;
|
||||
|
||||
/**
|
||||
* Calculates the bearing from the user location to the destination location, or returns the bearing for north if there is no destination.
|
||||
* This method is awesome for make a compass point toward the destination rather than North.
|
||||
* @param user location
|
||||
* @param dest location
|
||||
* @param bearing Degrees East from compass
|
||||
* @return Degrees East of dest location
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static float calculateBearing(GeoPoint user, GeoPoint dest, float bearing) {
|
||||
|
||||
if( (user == null) || (dest == null) )
|
||||
return bearing;
|
||||
|
||||
float heading = bearing(user, dest).floatValue();
|
||||
|
||||
bearing = (360 - heading) + bearing;
|
||||
|
||||
if (bearing > 360)
|
||||
return bearing - 360;
|
||||
|
||||
return bearing;
|
||||
}
|
||||
|
||||
/**
|
||||
* computes the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East
|
||||
@@ -44,7 +68,7 @@ public class GeoUtils {
|
||||
* @param lon1 source lon
|
||||
* @param lat2 destination lat
|
||||
* @param lon2 destination lon
|
||||
* @return the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East
|
||||
* @return the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East of true north
|
||||
* @author Google Inc.
|
||||
*/
|
||||
public static double bearing(double lat1, double lon1, double lat2, double lon2) {
|
||||
@@ -57,7 +81,7 @@ public class GeoUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* computes the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East
|
||||
* computes the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East of true north
|
||||
* @param p1 source geopoint
|
||||
* @param p2 destination geopoint
|
||||
* @return the bearing of p2 in relationship from p1 in degrees East
|
||||
|
||||
@@ -52,6 +52,7 @@ public class UserOverlay extends Overlay implements GeoPointLocationListener, Co
|
||||
private CompasOverlay mCompass;
|
||||
private boolean isCompassEnabled;
|
||||
private boolean isGPSDialogEnabled;
|
||||
private CompassListener mCompassListener;
|
||||
|
||||
/**
|
||||
* Construct a new SkyHookUserOverlaymFollowUser
|
||||
@@ -262,20 +263,21 @@ public class UserOverlay extends Overlay implements GeoPointLocationListener, Co
|
||||
new Handler().postAtTime(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mGPSprogress.isShowing()) {
|
||||
mGPSprogress.cancel();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
builder.setMessage(
|
||||
mContext.getText(R.string.sorry_theres_trouble))
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(mContext.getText(android.R.string.ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
if(mGPSprogress != null)
|
||||
if (mGPSprogress.isShowing()) {
|
||||
mGPSprogress.cancel();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
builder.setMessage(
|
||||
mContext.getText(R.string.sorry_theres_trouble))
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(mContext.getText(android.R.string.ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
}, SystemClock.uptimeMillis()+90000L);
|
||||
}
|
||||
@@ -313,6 +315,8 @@ public class UserOverlay extends Overlay implements GeoPointLocationListener, Co
|
||||
public void onCompassUpdate(float bearing) {
|
||||
if(Debug.DEBUG)
|
||||
Log.v(TAG, "onCompassUpdate()");
|
||||
if(mCompassListener != null)
|
||||
mCompassListener.onCompassUpdate(bearing);
|
||||
mBearing = bearing;
|
||||
mMapView.invalidate();
|
||||
}
|
||||
@@ -420,6 +424,14 @@ public class UserOverlay extends Overlay implements GeoPointLocationListener, Co
|
||||
mCompass.setDrawables(needleResId, backgroundResId, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the CompassListener
|
||||
* @param listener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setCompassListener(CompassListener listener){
|
||||
mCompassListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* This thread is responsible for animating the user icon
|
||||
|
||||
Reference in New Issue
Block a user