package atila.android.friendtracker.app;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.RectF;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
public class Utils
{
/**
* \brief Make hit testing to know if the user taps on the overlay passed by arg
*/
public static boolean HitTest( Bitmap icon, Position iconPos, GeoPoint geopoint, MapView mapview )
{
boolean bRet = false;
Point screenCoords = new Point();
Point tapScreenCoords = new Point();
RectF hitTestRect = new RectF();
mapview.getProjection().toPixels(iconPos.GetMapPoint(), screenCoords);
mapview.getProjection().toPixels(geopoint, tapScreenCoords);
hitTestRect.set( 0, 0, icon.getWidth(), icon.getHeight());
hitTestRect.offset(screenCoords.x - (icon.getWidth() >> 1), screenCoords.y - (icon.getHeight() >> 1));
if(hitTestRect.contains( tapScreenCoords.x, tapScreenCoords.y) )
{
bRet = true;
}
return bRet;
}
}
|