Search in sources :

Example 6 with GeoPoint

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)));
}
Also used : GeoPoint(com.google.android.maps.GeoPoint) Test(org.junit.Test)

Example 7 with GeoPoint

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);
}
Also used : GeoPoint(com.google.android.maps.GeoPoint) Point(android.graphics.Point) GeoPoint(com.google.android.maps.GeoPoint) Overlay(com.google.android.maps.Overlay) Point(android.graphics.Point) GeoPoint(com.google.android.maps.GeoPoint) Implementation(org.robolectric.annotation.Implementation)

Example 8 with GeoPoint

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)));
}
Also used : GeoPoint(com.google.android.maps.GeoPoint) Point(android.graphics.Point) GeoPoint(com.google.android.maps.GeoPoint) Test(org.junit.Test)

Example 9 with GeoPoint

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)));
}
Also used : GeoPoint(com.google.android.maps.GeoPoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with GeoPoint

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);
}
Also used : Projection(com.google.android.maps.Projection) Point(android.graphics.Point) GeoPoint(com.google.android.maps.GeoPoint) Paint(android.graphics.Paint)

Aggregations

GeoPoint (com.google.android.maps.GeoPoint)11 Test (org.junit.Test)5 Point (android.graphics.Point)4 Ignore (org.junit.Ignore)2 Implementation (org.robolectric.annotation.Implementation)2 Paint (android.graphics.Paint)1 Drawable (android.graphics.drawable.Drawable)1 AccuracyCircleOverlay (com.github.ignition.samples.location.overlays.AccuracyCircleOverlay)1 MapView (com.google.android.maps.MapView)1 Overlay (com.google.android.maps.Overlay)1 Projection (com.google.android.maps.Projection)1