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:
2012-01-08 14:32:53 +00:00
parent 4a0469abf7
commit 703a6ca059
65 changed files with 519 additions and 189 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -12,17 +12,23 @@ public final class R {
}
public static final class drawable {
public static int compass=0x7f020000;
public static int logoidea3=0x7f020001;
public static int needle=0x7f020002;
public static int skyhook_logo=0x7f020003;
public static int skyhook_logo_alpha=0x7f020004;
public static int skyhook_logo_alpha_small=0x7f020005;
public static int tc_logo_complete=0x7f020006;
public static int user=0x7f020007;
public static int user_arrow_animation_1=0x7f020008;
public static int user_arrow_animation_2=0x7f020009;
public static int user_arrow_animation_3=0x7f02000a;
public static int userarrow=0x7f02000b;
public static int compass_lrg=0x7f020001;
public static int compass_med=0x7f020002;
public static int compass_sm=0x7f020003;
public static int logoidea3=0x7f020004;
public static int needle=0x7f020005;
public static int needle_lrg=0x7f020006;
public static int needle_med=0x7f020007;
public static int needle_sm=0x7f020008;
public static int skyhook_logo=0x7f020009;
public static int skyhook_logo_alpha=0x7f02000a;
public static int skyhook_logo_alpha_small=0x7f02000b;
public static int tc_logo_complete=0x7f02000c;
public static int user=0x7f02000d;
public static int user_arrow_animation_1=0x7f02000e;
public static int user_arrow_animation_2=0x7f02000f;
public static int user_arrow_animation_3=0x7f020010;
public static int userarrow=0x7f020011;
}
public static final class id {
public static int skyhook_img=0x7f050000;

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -7,11 +7,13 @@
package com.TwentyCodes.android.location;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Point;
import android.util.TypedValue;
import com.TwentyCodes.android.SkyHook.R;
import com.google.android.maps.GeoPoint;
@@ -30,10 +32,10 @@ public class CompasOverlay extends Overlay implements CompassListener {
private GeoPoint mLocation;
private boolean isEnabled;
private CompassSensor mCompassSensor;
private int mNeedleResId = R.drawable.needle;
private int mBackgroundResId = R.drawable.compass;
private int mX = 100;
private int mY = 100;
private int mNeedleResId = R.drawable.needle_sm;
private int mBackgroundResId = R.drawable.compass_sm;
private int mX;
private int mY;
private CompassListener mListener;
/**
@@ -43,6 +45,8 @@ public class CompasOverlay extends Overlay implements CompassListener {
public CompasOverlay(Context context) {
mContext = context;
mCompassSensor = new CompassSensor(context);
mX = convertDipToPx(40);
mY = mX;
}
/**
@@ -56,6 +60,24 @@ public class CompasOverlay extends Overlay implements CompassListener {
mDestination = destination;
}
/**
* Creates a new CompasOverlay
* @param context
* @param destination
* @param needleResId
* @param backgroundResId
* @param x dip
* @param y dip
* @author ricky barrette
*/
public CompasOverlay(Context context, GeoPoint destination, int needleResId, int backgroundResId, int x, int y){
this(context, destination);
mX = convertDipToPx(x);
mY = convertDipToPx(y);
mNeedleResId = needleResId;
mBackgroundResId = backgroundResId;
}
/**
* Creates a new CompasOverlay
* @param context
@@ -69,24 +91,6 @@ public class CompasOverlay extends Overlay implements CompassListener {
this(context, null, needleResId, backgroundResId, x, y);
}
/**
* Creates a new CompasOverlay
* @param context
* @param destination
* @param needleResId
* @param backgroundResId
* @param x
* @param y
* @author ricky barrette
*/
public CompasOverlay(Context context, GeoPoint destination, int needleResId, int backgroundResId, int x, int y){
this(context, destination);
mX = x;
mY = y;
mNeedleResId = needleResId;
mBackgroundResId = backgroundResId;
}
/**
* Calculated the bearing from the current location to the current destination, or returns the bearing for north if there is no destination
* @return bearing
@@ -103,6 +107,17 @@ public class CompasOverlay extends Overlay implements CompassListener {
return bearing;
}
/**
* Converts dip to px
* @param dip
* @return px
* @author ricky barrette
*/
private int convertDipToPx(int i) {
Resources r = mContext.getResources();
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, i, r.getDisplayMetrics());
}
/**
* Disables the compass overlay
* @author ricky barrette
@@ -214,11 +229,13 @@ public class CompasOverlay extends Overlay implements CompassListener {
/**
* @param needleResId
* @param backgroundResId
* @param x dip
* @param y dip
* @author ricky barrette
*/
public void setDrawables(int needleResId, int backgroundResId, int x, int y){
mX = x;
mY = y;
mX = convertDipToPx(x);
mY = convertDipToPx(y);
mNeedleResId = needleResId;
mBackgroundResId = backgroundResId;
}

View File

@@ -0,0 +1,12 @@
package com.TwentyCodes.android.location;
import com.google.android.maps.GeoPoint;
/**
* This interface will be used to pass the selected location from the dialogs to the listening instance
* @author ricky barrette
*/
public interface LocationSelectedListener {
public void onLocationSelected(GeoPoint point);
}

View File

@@ -0,0 +1,156 @@
/**
* @author Twenty Codes
* @author ricky barrette
*/
package com.TwentyCodes.android.location;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.RectF;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
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
* @author ricky barrette
*/
public class RadiusOverlay extends Overlay{
public OverlayItem mOverlayItem;
private GeoPoint mPoint;
private float mRadius = 0;
private int mColor = Color.GREEN;
private GeoPoint mRadiusPoint;
private LocationSelectedListener mListener;
/**
* Creates a new RadiusOverlay
* @author ricky barrette
*/
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
* @author ricky barrette
*/
public RadiusOverlay(GeoPoint point, float radius, int color) {
mPoint = point;
mRadius = radius;
mColor = color;
}
/**
* draws a specific radius on the mapview that is handed to it
* @param canvas canvas to be drawn on
* @param mapView
* @param shadow
* @param when
*/
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow){
if(mPoint != null){
Paint paint = new Paint();
Point center = new Point();
Point left = new Point();
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.
*/
mRadiusPoint = GeoUtils.distanceFrom(mPoint , mRadius);
projection.toPixels(mRadiusPoint, left);
projection.toPixels(mPoint, center);
/*
* get radius of the circle being drawn by
*/
int circleRadius = center.x - left.x;
if(circleRadius <= 0){
circleRadius = left.x - center.x;
}
/*
* paint a circle on the map
*/
paint.setAntiAlias(true);
paint.setStrokeWidth(2.0f);
paint.setColor(mColor);
paint.setStyle(Style.STROKE);
canvas.drawCircle(center.x, center.y, circleRadius, paint);
//draw a dot over the geopoint
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
paint.setAlpha(25);
paint.setStyle(Style.FILL);
canvas.drawCircle(center.x, center.y, circleRadius, paint);
}
}
/**
* @return the selected location
* @author ricky barrette
*/
public GeoPoint getLocation(){
return mPoint;
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
mPoint = p;
if(this.mListener != null)
this.mListener.onLocationSelected(p);
return super.onTap(p, mapView);
}
/**
* @param color
* @author ricky barrette
*/
public void setColor(int color){
mColor = color;
}
/**
* @param location
* @author ricky barrette
*/
public void setLocation(GeoPoint location){
mPoint = location;
}
/**
* @param radius in meters
* @author ricky barrette
* @param radius
*/
public void setRadius(int radius){
mRadius = radius;
}
public int getZoomLevel() {
// GeoUtils.GeoUtils.distanceFrom(mPoint , mRadius)
return 0;
}
public void setLocationSelectedListener(LocationSelectedListener listener) {
this.mListener = listener;
}
}

View File

@@ -10,81 +10,136 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import com.TwentyCodes.android.SkyHook.R;
import com.TwentyCodes.android.debug.Debug;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
/**
* This is the standard version of the UserOverlay.
* @author ricky barrette
*/
public class UserOverlay extends MyLocationOverlay {
public class UserOverlay extends Overlay implements GeoPointLocationListener, CompassListener {
private boolean isEnabled;
private int mUserArrow = R.drawable.user_arrow_animation_1;
private Thread mAnimationThread;
private float mBearing = 0;
private int mAccuracy;
private GeoPoint mPoint;
private Context mContext;
private AndroidGPS mAndroidGPS;
private MapView mMapView;
private ProgressDialog mGPSprogress;
private boolean isFirstFix = true;
private boolean isFistFix = true;
private GeoPointLocationListener mListener;
private boolean isFollowingUser = true;
private float myAzimuth;
private GeoPoint mUser;
private GeoPoint mDest;
private boolean isShowingCompass;
private AnimationDrawable mUserArrow;
public boolean isFollowingUser = true;
private final String TAG = "SkyHookUserOverlay";
private CompasOverlay mCompass;
private boolean isCompassEnabled;
private boolean isGPSDialogEnabled;
/**
* Creates a new UserOverlay
* @param context
* Construct a new SkyHookUserOverlaymFollowUser
* @param mapView
* @param context
* @author ricky barrette
*/
public UserOverlay(Context context, MapView mapView) {
super(context, mapView);
mMapView = mapView;
public UserOverlay(MapView mapView, Context context) {
mContext = context;
mUserArrow = (AnimationDrawable) mContext.getResources().getAnimation(R.drawable.userarrow);
mUserArrow.start();
mMapView = mapView;
mAndroidGPS = new AndroidGPS(context);
mCompass = new CompasOverlay(context);
mUserArrow = R.drawable.user_arrow_animation_1;
}
/**
* disables the compass view
* (non-Javadoc)
* @see com.google.android.maps.MyLocationOverlay#disableCompass()
* Construct a new SkyHookUserOverlay
* @param mapView
* @param context
* @param followUser
* @author ricky barrette
*/
public UserOverlay(MapView mapView, Context context, boolean followUser) {
this(mapView, context);
isFollowingUser = followUser;
}
/**
* Disables the compass
* @author ricky barrette
*/
@Override
public void disableCompass(){
isShowingCompass = false;
isCompassEnabled = false;
mMapView.getOverlays().remove(mCompass);
}
/**
* called when the overlay is disabled. this will disable all progress dialogs, and location based servicess
* Stops location updates and removes the overlay from view
* @author ricky barrette
*/
public void disableMyLocation(){
Log.d(TAG,"disableMyLocation()");
mAndroidGPS.disableLocationUpdates();
isEnabled = false;
mCompass.disable();
if(mGPSprogress != null)
mGPSprogress.cancel();
}
/**
* Disables the Acquiring GPS dialog
* @author ricky barrette
*/
public void disableGPSDialog(){
isGPSDialogEnabled = false;
if(mGPSprogress != null)
mGPSprogress.dismiss();
}
/**
* 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.MyLocationOverlay#disableMyLocation()
* @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 disableMyLocation(){
super.disableCompass();
super.disableMyLocation();
mGPSprogress.dismiss();
public void draw(Canvas canvas, MapView mapView, boolean shadow){
if (isEnabled && mPoint != null) {
Point center = new Point();
Point left = new Point();
Projection projection = mapView.getProjection();
GeoPoint leftGeo = GeoUtils.distanceFrom(mPoint, mAccuracy);
projection.toPixels(leftGeo, left);
projection.toPixels(mPoint, center);
canvas = drawAccuracyCircle(center, left, canvas);
canvas = drawUser(center, mBearing, canvas);
/*
* the following log is used to demonstrate if the leftGeo point is the correct
*/
// Log.d(SkyHook.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
@@ -129,64 +184,7 @@ public class UserOverlay extends MyLocationOverlay {
return canvas;
}
/**
* computes bearing to geopoint based on device oriantaion and draws the compass of what you want really really badly on screen
* @param - canvas - the canvas to draw on
* @param - bearing - bearing of user based on magnetic compass
* @author ricky barrette
*/
@Override
protected void drawCompass(Canvas canvas, float bearing){
myAzimuth = bearing;
mMapView.invalidate();
if (isShowingCompass) {
/*
* if the dest and user geopoint are not null, then draw the compass point to the dest geopoint
*
* else draw the compass to point north
*/
if (mUser != null && mDest != null){
Double d = GeoUtils.bearing(mUser, mDest);
bearing = bearing - d.floatValue();
} else if (bearing != 0){
bearing = 360 - bearing;
}
super.drawCompass(canvas, bearing);
}
}
/**
* 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
protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint point, long when){
if (point != null) {
Point center = new Point();
Point left = new Point();
Projection projection = mapView.getProjection();
GeoPoint leftGeo = GeoUtils.distanceFrom(point, lastFix.getAccuracy());
projection.toPixels(leftGeo, left);
projection.toPixels(point, center);
canvas = drawAccuracyCircle(center, left, canvas);
canvas = drawUser(center, myAzimuth, canvas);
/*
* the following log is used to demonstrate if the leftGeo point is the correct
*/
// Log.d(SkyHook.TAG, (GeoUtils.distanceKm(mPoint, leftGeo) * 1000)+"m");
}
}
/**
/**
* 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
@@ -195,14 +193,14 @@ public class UserOverlay extends MyLocationOverlay {
* @author ricky barrette
*/
private Canvas drawUser(Point point, float bearing, Canvas canvas){
Bitmap arrowBitmap = ((BitmapDrawable)mUserArrow.getCurrent()).getBitmap();
Bitmap user = BitmapFactory.decodeResource(mContext.getResources(), mUserArrow);
Matrix matrix = new Matrix();
matrix.postRotate(bearing);
Bitmap rotatedBmp = Bitmap.createBitmap(
arrowBitmap,
user,
0, 0,
arrowBitmap.getWidth(),
arrowBitmap.getHeight(),
user.getWidth(),
user.getHeight(),
matrix,
true
);
@@ -215,55 +213,73 @@ public class UserOverlay extends MyLocationOverlay {
return canvas;
}
/**
* enables the compass view
* (non-Javadoc)
* @see com.google.android.maps.MyLocationOverlay#enableCompass()
* @author ricky barrette
*/
@Override
public boolean enableCompass(){
isShowingCompass = true;
return isShowingCompass;
}
/**
* Enables the compass
* @author ricky barrette
*/
public synchronized void enableCompass(){
if(! this.isCompassEnabled){
this.mMapView.getOverlays().add(this.mCompass);
this.isCompassEnabled = true;
}
}
/**
* called when the user overlay is enabled, this will display the progress dialog
* (non-Javadoc)
* @see com.google.android.maps.MyLocationOverlay#enableMyLocation()
* @author ricky barrette
*/
@Override
public boolean enableMyLocation(){
mGPSprogress = ProgressDialog.show(mContext, "", mContext.getText(R.string.gps_fix), true, true);
isFirstFix = true;
super.enableCompass();
* Enables the Acquiring GPS dialog if the location has not been acquired
* @author ricky barrette
*/
public void enableGPSDialog(){
isGPSDialogEnabled = true;
if(isFistFix)
if(mGPSprogress != null){
if(! mGPSprogress.isShowing())
mGPSprogress = ProgressDialog.show(mContext, "", mContext.getText(R.string.gps_fix), true, true);
} else
mGPSprogress = ProgressDialog.show(mContext, "", mContext.getText(R.string.gps_fix), true, true);
}
/**
* this is a message that tells the user that we are having trouble getting an GPS signal
*/
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();
/**
* Attempts to enable MyLocation, registering for updates from sky hook
* @author ricky barrette
*/
public void enableMyLocation(){
Log.d(TAG,"enableMyLocation()");
if (! isEnabled) {
mAnimationThread = new AnimationThread();
mAnimationThread.start();
mAndroidGPS.enableLocationUpdates(this);
isEnabled = true;
mCompass.enable(this);
isFistFix = true;
if(isGPSDialogEnabled)
enableGPSDialog();
/**
* this is a message that tells the user that we are having trouble getting an GPS signal
*/
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();
}
}
}
}, SystemClock.uptimeMillis()+90000L);
return super.enableMyLocation();
}
}, SystemClock.uptimeMillis()+90000L);
}
}
/**
* Allows the map to follow the user
@@ -271,11 +287,38 @@ public class UserOverlay extends MyLocationOverlay {
* @author ricky barrette
*/
public void followUser(boolean followUser){
Log.d(TAG,"followUser()");
isFollowingUser = followUser;
}
/**
* returns the users current bearing
* @return
* @author ricky barrette
*/
public float getUserBearing(){
return mBearing;
}
/**
* called when the SkyHook location changes, this method is resposiable for updating the overlay location and accuracy circle.
* returns the users current location
* @return
* @author ricky barrette
*/
public GeoPoint getUserLocation(){
return mPoint;
}
@Override
public void onCompassUpdate(float bearing) {
if(Debug.DEBUG)
Log.v(TAG, "onCompassUpdate()");
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)
* @param point
@@ -283,28 +326,34 @@ public class UserOverlay extends MyLocationOverlay {
* @author ricky barrette
*/
@Override
public void onLocationChanged(Location location) {
public void onLocationChanged(GeoPoint point, int accuracy) {
GeoPoint point = new GeoPoint((int) (location.getLatitude() *1e6), (int) (location.getLongitude() *1e6));
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(point != null && isFirstFix){
if(point != null && isFistFix){
mMapView.getController().setCenter(point);
mMapView.getController().setZoom(mMapView.getMaxZoomLevel()+3);
mGPSprogress.dismiss();
isFirstFix = false;
mMapView.getController().setZoom( (mMapView.getMaxZoomLevel() - 2) );
if(mGPSprogress != null)
mGPSprogress.dismiss();
isFistFix = false;
}
//update the users point, and accuracy for the UI
mPoint = point;
mAccuracy = accuracy;
mMapView.invalidate();
if(mListener != null){
mListener.onLocationChanged(point, accuracy);
}
//pan to user if off map
if (isFollowingUser) {
panToUserIfOffMap(point);
}
mListener.onLocationChanged(point, (int) location.getAccuracy());
super.onLocationChanged(location);
}
/**
@@ -335,17 +384,107 @@ public class UserOverlay extends MyLocationOverlay {
* @author Ricky Barrette
*/
public void registerListener(GeoPointLocationListener listener){
Log.d(TAG,"registerListener()");
if (mListener == null){
mListener = listener;
}
}
/**
* Sets the destination for the compass
* @author ricky barrette
*/
public void setDestination(GeoPoint destination){
if(mCompass != null)
mCompass.setDestination(destination);
}
/**
* UnResgisters the listener. after this call you will no longer get location updates
* @author Ricky Barrette
*/
public void unRegisterListener(){
Log.d(TAG,"unRegisterListener()");
mListener = null;
}
/**
* Set the compass drawables and location
* @param needleResId
* @param backgroundResId
* @param x
* @param y
* @author ricky barrette
*/
public void setCompassDrawables(int needleResId, int backgroundResId, int x, int y) {
mCompass.setDrawables(needleResId, backgroundResId, x, y);
}
/**
* This thread is responsible for animating the user icon
* @author ricky barrette
*/
private class AnimationThread extends Thread {
/**
* Main method of this animation thread
* (non-Javadoc)
* @see java.lang.Thread#run()
*/
@Override
public void run(){
super.run();
int index = 0;
boolean isCountingUp = true;
while (true) {
synchronized (this) {
if (! isEnabled) {
break;
}
switch(index){
case 1:
setDrawable(R.drawable.user_arrow_animation_2);
break;
case 2:
setDrawable(R.drawable.user_arrow_animation_3);
break;
default:
setDrawable(R.drawable.user_arrow_animation_1);
try {
sleep(300l);
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
break;
}
try {
sleep(200l);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(isCountingUp){
if(index++ == 2)
isCountingUp = false;
} else if(index-- == 0)
isCountingUp = true;
}
}
}
/**
* Sets the id of the user drawable
* @param id
* @author ricky barrette
*/
private synchronized void setDrawable(int id){
mUserArrow = id;
}
}
}