use of com.google.android.maps.GeoPoint in project robolectric by robolectric.
the class ShadowMapViewTest method dispatchTouchEvents_shouldMoveBackToCenterOnCancel.
@Test
public void dispatchTouchEvents_shouldMoveBackToCenterOnCancel() throws Exception {
initMapForDrag();
dispatchTouchEvent(MotionEvent.ACTION_DOWN, 10, 10);
dispatchTouchEvent(MotionEvent.ACTION_MOVE, 11, 11);
dispatchTouchEvent(MotionEvent.ACTION_MOVE, 12, 12);
dispatchTouchEvent(MotionEvent.ACTION_CANCEL, 11, 11);
assertThat(mapView.getMapCenter()).isEqualTo(new GeoPoint(toE6(25), toE6(25)));
}
use of com.google.android.maps.GeoPoint in project robolectric by robolectric.
the class ShadowMapView method dispatchTouchEvent.
@Implementation
public boolean dispatchTouchEvent(MotionEvent event) {
for (Overlay overlay : overlays) {
if (overlay.onTouchEvent(event, realMapView)) {
return true;
}
}
GeoPoint mouseGeoPoint = getProjection().fromPixels((int) event.getX(), (int) event.getY());
int diffX = 0;
int diffY = 0;
if (mouseDownOnMe) {
diffX = (int) event.getX() - lastTouchEventPoint.x;
diffY = (int) event.getY() - lastTouchEventPoint.y;
}
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
mouseDownOnMe = true;
mouseDownCenter = getMapCenter();
break;
case MotionEvent.ACTION_MOVE:
if (mouseDownOnMe) {
moveByPixels(-diffX, -diffY);
}
break;
case MotionEvent.ACTION_UP:
if (mouseDownOnMe) {
moveByPixels(-diffX, -diffY);
mouseDownOnMe = false;
}
break;
case MotionEvent.ACTION_CANCEL:
getController().setCenter(mouseDownCenter);
mouseDownOnMe = false;
break;
}
lastTouchEventPoint = new Point((int) event.getX(), (int) event.getY());
return realView.dispatchTouchEvent(event);
}
use of com.google.android.maps.GeoPoint in project robolectric by robolectric.
the class ShadowMapViewTest method getProjection_fromPixels_shouldPerformCorrectTranslations.
@Test
public void getProjection_fromPixels_shouldPerformCorrectTranslations() throws Exception {
int centerLat = 11;
int centerLng = 16;
int spanLat = 20;
int spanLng = 30;
mapView.getController().setCenter(new GeoPoint(toE6(centerLat), toE6(centerLng)));
mapView.getController().zoomToSpan(toE6(spanLat), toE6(spanLng));
mapView.layout(50, 60, 650, 460);
assertThat(mapView.getProjection().fromPixels(50, 60)).isEqualTo(new GeoPoint(toE6(21), toE6(1)));
assertThat(mapView.getProjection().fromPixels(350, 260)).isEqualTo(new GeoPoint(toE6(11), toE6(16)));
assertThat(mapView.getProjection().fromPixels(650, 460)).isEqualTo(new GeoPoint(toE6(1), toE6(31)));
}
use of com.google.android.maps.GeoPoint in project robolectric by robolectric.
the class ShadowMapViewTest method dispatchTouchEvents_shouldDragMapByCorrectAmount.
// todo 2.0-cleanup
@Ignore("not yet working in 2.0, sorry :-(")
@Test
public void dispatchTouchEvents_shouldDragMapByCorrectAmount() throws Exception {
initMapForDrag();
dispatchTouchEvent(MotionEvent.ACTION_DOWN, 10, 10);
dispatchTouchEvent(MotionEvent.ACTION_UP, 11, 11);
assertThat(mapView.getMapCenter()).isEqualTo(new GeoPoint(toE6(26), toE6(24)));
}
use of com.google.android.maps.GeoPoint in project ignition by mttkay.
the class AccuracyCircleOverlay method draw.
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection projection = mapView.getProjection();
if (shadow && projection == null) {
Log.v(LOG_TAG, "drawing not done because shadow and projection are null");
return;
}
Point pt = new Point();
projection.toPixels(geoPoint, pt);
float circleRadius = metersToRadius(accuracy, projection, geoPoint.getLatitudeE6());
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(0x186666ff);
paint.setStyle(Style.FILL_AND_STROKE);
canvas.drawCircle(pt.x, pt.y, circleRadius, paint);
paint.setColor(0xff6666ff);
paint.setStyle(Style.STROKE);
canvas.drawCircle(pt.x, pt.y, circleRadius, paint);
paint.setColor(Color.RED);
paint.setStyle(Style.FILL_AND_STROKE);
canvas.drawCircle(pt.x, pt.y, 3, paint);
super.draw(canvas, mapView, shadow);
}
Aggregations