Skip to content

Commit

Permalink
Merge pull request #250 from onaio/40-make-location-blue-circle-radiu…
Browse files Browse the repository at this point in the history
…s-configurable

Make location blue circle radius configurable
  • Loading branch information
vincent-karuri authored Feb 25, 2019
2 parents b867e77 + 7336065 commit c32ef0b
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import io.ona.kujaku.exceptions.WmtsCapabilitiesException;
import io.ona.kujaku.listeners.BoundsChangeListener;
import io.ona.kujaku.listeners.OnLocationChanged;
import io.ona.kujaku.wmts.serializer.WmtsCapabilitiesSerializer;
import io.ona.kujaku.wmts.model.WmtsCapabilities;
import io.ona.kujaku.wmts.model.WmtsLayer;
import io.ona.kujaku.wmts.serializer.WmtsCapabilitiesSerializer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -67,6 +67,11 @@ public void run() {
});
}

@Test
public void testLocationComponentWrapperIsInitaliazed() {
assertNotNull(kujakuMapView.getMapboxLocationComponentWrapper());
}

@Test
public void enableAddPointShouldShowMarkerLayoutWhenPassedTrue() throws NoSuchFieldException, IllegalAccessException {
assertEquals(View.GONE, kujakuMapView.findViewById(R.id.iv_mapview_locationSelectionMarker).getVisibility());
Expand Down Expand Up @@ -125,21 +130,13 @@ public void onLocationChanged(Location location) {
};

LatLng latLng = new LatLng(14d, 23d);

insertValueInPrivateField(KujakuMapView.class, kujakuMapView, "latestLocation", latLng);
insertValueInPrivateField(KujakuMapView.class, kujakuMapView, "latestLocationCoordinates", latLng);
uiThreadTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
kujakuMapView.enableAddPoint(true, onLocationChanged);
}
});

// Check if the two circle layers were added
// Check if geojson for current user position was added
// Todo: this can use a drawable icon instead of having two extra layers

assertNotNull(getValueInPrivateField(KujakuMapView.class, kujakuMapView, "pointsSource"));

//Make sure the map centers on the location
assertTrue(kujakuMapView.isMapCentered);
}
Expand Down Expand Up @@ -227,6 +224,7 @@ public void showCurrentLocationBtnShouldChangeVisibleWhenCalled() {
assertEquals(View.GONE, currentLocationBtn.getVisibility());
}


@Test
public void focusOnUserLocationShouldChangeTargetIconWhenCalled() throws NoSuchFieldException, IllegalAccessException {
String updateUserLocationOnMap = "updateUserLocationOnMap";
Expand All @@ -246,6 +244,25 @@ public void focusOnUserLocationShouldChangeTargetIconWhenCalled() throws NoSuchF
assertEquals(R.drawable.ic_cross_hair, drawableResId);
}

@Test
public void focusOnUserLocationWithRadiusShouldChangeTargetIconWhenCalled() throws NoSuchFieldException, IllegalAccessException {
String updateUserLocationOnMap = "updateUserLocationOnMap";

kujakuMapView.focusOnUserLocation(true, 25f);
assertTrue((boolean) getValueInPrivateField(KujakuMapView.class, kujakuMapView, updateUserLocationOnMap));
ImageButton imageButton = kujakuMapView.findViewById(R.id.ib_mapview_focusOnMyLocationIcon);

int drawableResId = (int) getValueInPrivateField(ImageView.class, imageButton, "mResource");
assertEquals(R.drawable.ic_cross_hair_blue, drawableResId);


kujakuMapView.focusOnUserLocation(false);
assertFalse((boolean) getValueInPrivateField(KujakuMapView.class, kujakuMapView, updateUserLocationOnMap));

drawableResId = (int) getValueInPrivateField(ImageView.class, imageButton, "mResource");
assertEquals(R.drawable.ic_cross_hair, drawableResId);
}

@Test
public void addNullWmtsLayers() {
assertEquals(0, kujakuMapView.getWmtsLayers().size());
Expand Down Expand Up @@ -344,4 +361,4 @@ public void onBoundsChanged(LatLng topLeft, LatLng topRight, LatLng bottomRight,
countDownLatch.await(3, TimeUnit.SECONDS);
assertEquals(1, results.size());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.ona.kujaku.callbacks;

/**
* @author Vincent Karuri
*/
public interface OnLocationServicesEnabledCallBack {
void onSuccess();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.ona.kujaku.helpers;

import android.content.Context;
import android.support.annotation.NonNull;

import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapboxMap;

/**
* @author Vincent Karuri
*/
public class MapboxLocationComponentWrapper {

private LocationComponent locationComponent;

@SuppressWarnings( {"MissingPermission"})
public void init(@NonNull MapboxMap mapboxMap, @NonNull Context context) {
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(context, (LocationEngine) null);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setCameraMode(CameraMode.NONE);
locationComponent.setRenderMode(RenderMode.NORMAL);
}

public LocationComponent getLocationComponent() {
return locationComponent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ public interface IKujakuMapView extends IKujakuMapViewLowLevel {
* intervention. If the MY LOCATION BUTTON is visible, it will turn blue as long as this mode is on.
* This can be turned off by the user if s/he touches the map to scroll it to a specific location.
*
* @param focusOnMyLocation
* @param focusOnMyLocation Whether to focus on the user's current location or not
*/
void focusOnUserLocation(boolean focusOnMyLocation);


/**
* Enables/disables location on the map to show the user location on the map without the user
* intervention. If the MY LOCATION BUTTON is visible, it will turn blue as long as this mode is on.
* This can be turned off by the user if s/he touches the map to scroll it to a specific location.
*
* @param focusOnMyLocation Whether to focus on the user's current location or not
* @param radius Radius of the outer circle that marks the user's current location
*/
void focusOnUserLocation(boolean focusOnMyLocation, @Nullable Float radius);


/**
* Add new {@link com.mapbox.geojson.Feature Feature} points to the {@link io.ona.kujaku.views.KujakuMapView map}
*
Expand Down
Loading

0 comments on commit c32ef0b

Please sign in to comment.