Search in sources :

Example 16 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class FormMapActivityTest method tappingOnEditableInstance_showsSubmissionSummaryWithAppropriateMessage.

@Test
public void tappingOnEditableInstance_showsSubmissionSummaryWithAppropriateMessage() {
    Pair<Instance, MapPoint> editableAndFinalized = new Pair<>(testInstances[1], new MapPoint(10.1, 125.6));
    Pair<Instance, MapPoint> unfinalized = new Pair<>(testInstances[2], new MapPoint(10.1, 126.6));
    Pair<Instance, MapPoint> failedToSend = new Pair<>(testInstances[4], new MapPoint(10.3, 125.6));
    activity.onFeatureClicked(map.getFeatureIdFor(editableAndFinalized.second));
    assertSubmissionSummaryContent(editableAndFinalized.first.getDisplayName(), editableAndFinalized.first.getStatus(), new Date(editableAndFinalized.first.getLastStatusChangeDate()), OPEN_EDIT);
    activity.onFeatureClicked(map.getFeatureIdFor(unfinalized.second));
    assertSubmissionSummaryContent(unfinalized.first.getDisplayName(), unfinalized.first.getStatus(), new Date(unfinalized.first.getLastStatusChangeDate()), OPEN_EDIT);
    activity.onFeatureClicked(map.getFeatureIdFor(failedToSend.second));
    assertSubmissionSummaryContent(failedToSend.first.getDisplayName(), failedToSend.first.getStatus(), new Date(failedToSend.first.getLastStatusChangeDate()), OPEN_READ_ONLY);
}
Also used : Instance(org.odk.collect.forms.instances.Instance) MapPoint(org.odk.collect.geo.maps.MapPoint) Date(java.util.Date) Pair(android.util.Pair) Test(org.junit.Test)

Example 17 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class FormMapActivityTest method tappingOnFailedSubmission_showsSubmissionSummaryWithAppropriateMessage.

@Test
public void tappingOnFailedSubmission_showsSubmissionSummaryWithAppropriateMessage() {
    Pair<Instance, MapPoint> submissionFailedCantEditWhenFinalized = new Pair<>(testInstances[6], new MapPoint(10.4, 125.6));
    int featureId = map.getFeatureIdFor(submissionFailedCantEditWhenFinalized.second);
    activity.onFeatureClicked(featureId);
    assertSubmissionSummaryContent(submissionFailedCantEditWhenFinalized.first.getDisplayName(), submissionFailedCantEditWhenFinalized.first.getStatus(), new Date(submissionFailedCantEditWhenFinalized.first.getLastStatusChangeDate()), NOT_VIEWABLE_TOAST);
}
Also used : Instance(org.odk.collect.forms.instances.Instance) MapPoint(org.odk.collect.geo.maps.MapPoint) MapPoint(org.odk.collect.geo.maps.MapPoint) Date(java.util.Date) Pair(android.util.Pair) Test(org.junit.Test)

Example 18 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class GeoPointMapActivity method restoreFromInstanceState.

protected void restoreFromInstanceState(Bundle state) {
    isDragged = state.getBoolean(IS_DRAGGED_KEY, false);
    captureLocation = state.getBoolean(CAPTURE_LOCATION_KEY, false);
    foundFirstLocation = state.getBoolean(FOUND_FIRST_LOCATION_KEY, false);
    setClear = state.getBoolean(SET_CLEAR_KEY, false);
    pointFromIntent = state.getBoolean(POINT_FROM_INTENT_KEY, false);
    intentReadOnly = state.getBoolean(INTENT_READ_ONLY_KEY, false);
    intentDraggable = state.getBoolean(INTENT_DRAGGABLE_KEY, false);
    isPointLocked = state.getBoolean(IS_POINT_LOCKED_KEY, false);
    // Restore the marker and dialog after the flags, because they use some of them.
    MapPoint point = state.getParcelable(POINT_KEY);
    if (point != null) {
        placeMarker(point);
    } else {
        clear();
    }
    // Restore the flags again, because placeMarker() and clear() modify some of them.
    isDragged = state.getBoolean(IS_DRAGGED_KEY, false);
    captureLocation = state.getBoolean(CAPTURE_LOCATION_KEY, false);
    foundFirstLocation = state.getBoolean(FOUND_FIRST_LOCATION_KEY, false);
    setClear = state.getBoolean(SET_CLEAR_KEY, false);
    pointFromIntent = state.getBoolean(POINT_FROM_INTENT_KEY, false);
    intentReadOnly = state.getBoolean(INTENT_READ_ONLY_KEY, false);
    intentDraggable = state.getBoolean(INTENT_DRAGGABLE_KEY, false);
    isPointLocked = state.getBoolean(IS_POINT_LOCKED_KEY, false);
    // Restore the rest of the UI state.
    MapPoint mapCenter = state.getParcelable(MAP_CENTER_KEY);
    Double mapZoom = state.getDouble(MAP_ZOOM_KEY);
    if (mapCenter != null) {
        map.zoomToPoint(mapCenter, mapZoom, false);
    }
    placeMarkerButton.setEnabled(state.getBoolean(PLACE_MARKER_BUTTON_ENABLED_KEY, false));
    zoomButton.setEnabled(state.getBoolean(ZOOM_BUTTON_ENABLED_KEY, false));
    clearButton.setEnabled(state.getBoolean(CLEAR_BUTTON_ENABLED_KEY, false));
    locationInfo.setVisibility(state.getInt(LOCATION_INFO_VISIBILITY_KEY, View.GONE));
    locationStatus.setVisibility(state.getInt(LOCATION_STATUS_VISIBILITY_KEY, View.GONE));
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint)

Example 19 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class GeoPointMapActivity method onLocationChanged.

public void onLocationChanged(MapPoint point) {
    if (setClear) {
        placeMarkerButton.setEnabled(true);
    }
    MapPoint previousLocation = this.location;
    this.location = point;
    if (point != null) {
        if (previousLocation != null) {
            enableZoomButton(true);
            if (!captureLocation && !setClear) {
                placeMarker(point);
                placeMarkerButton.setEnabled(true);
            }
            if (!foundFirstLocation) {
                map.zoomToPoint(map.getGpsLocation(), true);
                foundFirstLocation = true;
            }
            locationStatus.setText(formatLocationStatus(map.getLocationProvider(), point.sd));
        }
    }
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint)

Example 20 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class GeoPointMapActivityTest method shouldReturnPointFromSecondLocationFix.

@Test
public void shouldReturnPointFromSecondLocationFix() {
    ActivityScenario<GeoPointMapActivity> scenario = launcherRule.launch(GeoPointMapActivity.class);
    // The very first fix is ignored.
    mapFragment.setLocationProvider("GPS");
    mapFragment.setLocation(new MapPoint(1, 2, 3, 4f));
    scenario.onActivity(activity -> {
        assertEquals(activity.getString(R.string.please_wait_long), activity.getLocationStatus());
    });
    // The second fix changes the status message.
    mapFragment.setLocation(new MapPoint(5, 6, 7, 8f));
    scenario.onActivity(activity -> {
        assertEquals(activity.formatLocationStatus("gps", 8f), activity.getLocationStatus());
    });
    // When the user clicks the "Save" button, the fix location should be returned.
    scenario.onActivity(activity -> {
        activity.findViewById(R.id.accept_location).performClick();
    });
    assertThat(scenario.getResult().getResultCode(), is(RESULT_OK));
    scenario.onActivity(activity -> {
        Intent resultData = scenario.getResult().getResultData();
        assertThat(ExternalAppUtils.getReturnedSingleValue(resultData), is(activity.formatResult(new MapPoint(5, 6, 7, 8))));
    });
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

MapPoint (org.odk.collect.geo.maps.MapPoint)28 Test (org.junit.Test)8 SuppressLint (android.annotation.SuppressLint)7 IGeoPoint (org.osmdroid.api.IGeoPoint)5 GeoPoint (org.osmdroid.util.GeoPoint)5 Paint (android.graphics.Paint)4 Pair (android.util.Pair)4 Date (java.util.Date)4 Instance (org.odk.collect.forms.instances.Instance)4 Intent (android.content.Intent)3 Handler (android.os.Handler)3 ArrayList (java.util.ArrayList)3 ImageButton (android.widget.ImageButton)2 NonNull (androidx.annotation.NonNull)2 LatLng (com.google.android.gms.maps.model.LatLng)1 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 Ignore (org.junit.Ignore)1 Location (org.odk.collect.location.Location)1