Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ checkstyle:

test:
cd plugins; ./gradlew :traffic:test
cd plugins; ./gradlew :locationlayer:test

build-release:
cd plugins; ./gradlew :traffic:assembleRelease
cd plugins; ./gradlew :locationlayer:assembleRelease

javadoc:
# Android modules
# Output is ./mapbox/*/build/docs/javadoc/release
cd plugins; ./gradlew :traffic:javadocrelease
cd plugins; ./gradlew :locationlayer:javadocrelease

publish:
cd plugins; export IS_LOCAL_DEVELOPMENT=false; ./gradlew :traffic:uploadArchives
cd plugins; export IS_LOCAL_DEVELOPMENT=false; ./gradlew :locationlayer:uploadArchives

publish-local:
# This publishes to ~/.m2/repository/com/mapbox/mapboxsdk
cd plugins; export IS_LOCAL_DEVELOPMENT=true; ./gradlew :traffic:uploadArchives
cd plugins; export IS_LOCAL_DEVELOPMENT=true; ./gradlew :locationlayer:uploadArchives
1 change: 1 addition & 0 deletions plugins/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {

// Plugin modules
compile project(':traffic')
compile project(':locationlayer')
}

apply from: '../checkstyle.gradle'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.mapbox.mapboxsdk.plugins.locationlayer;

import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.view.View;

import com.mapbox.mapboxsdk.maps.MapboxMap;

import org.hamcrest.Matcher;

import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;

class LocationLayerPluginAction implements ViewAction {

private MapboxMap mapboxMap;
private LocationLayerPlugin locationLayerPlugin;
private onPerformLocationLayerAction onPerformLocationLayerAction;

LocationLayerPluginAction(MapboxMap mapboxMap, LocationLayerPlugin locationLayerPlugin,
onPerformLocationLayerAction onPerformLocationLayerAction) {
this.locationLayerPlugin = locationLayerPlugin;
this.mapboxMap = mapboxMap;
this.onPerformLocationLayerAction = onPerformLocationLayerAction;
}

@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}

@Override
public String getDescription() {
return getClass().getSimpleName();
}

@Override
public void perform(UiController uiController, View view) {
if (onPerformLocationLayerAction != null) {
onPerformLocationLayerAction.onLocationLayerAction(locationLayerPlugin, mapboxMap, uiController);
}
}

interface onPerformLocationLayerAction {
void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package com.mapbox.mapboxsdk.plugins.locationlayer;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.IdlingResourceTimeoutException;
import android.support.test.espresso.UiController;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.plugins.testapp.activity.location.LocationLayerModesActivity;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import timber.log.Timber;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
@SuppressWarnings( {"MissingPermission"})
public class LocationLayerPluginTest {

private static final double DELTA = 1E-10;

@Rule
public ActivityTestRule<LocationLayerModesActivity> rule = new ActivityTestRule<>(LocationLayerModesActivity.class);

private OnMapReadyIdlingResource idlingResource;
private MapboxMap mapboxMap;
private LocationLayerPlugin locationLayerPlugin;

@Before
public void beforeTest() {
try {
Timber.e("@Before: register idle resource");
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
Espresso.registerIdlingResources(idlingResource);
onView(withId(android.R.id.content)).check(matches(isDisplayed()));
mapboxMap = idlingResource.getMapboxMap();
locationLayerPlugin = rule.getActivity().getLocationLayerPlugin();
} catch (IdlingResourceTimeoutException idlingResourceTimeoutException) {
Timber.e("Idling resource timed out. Couldn't not validate if map is ready.");
throw new RuntimeException("Could not start executeLocationLayerTest for "
+ this.getClass().getSimpleName() + ".\n The ViewHierarchy doesn't contain a view with resource id ="
+ "R.id.mapView or \n the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n");
}
}

@Test
public void sanity() throws Exception {
assertTrue(mapboxMap != null);
assertTrue(locationLayerPlugin != null);
}

@Test
public void locationSourceAdded() throws Exception {
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
assertTrue(mapboxMap.getSource(LocationLayerConstants.LOCATION_SOURCE) != null);
}
});
}

@Test
public void locationAccuracySourceAdded() throws Exception {
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
assertTrue(mapboxMap.getSource(LocationLayerConstants.LOCATION_ACCURACY_SOURCE) != null);
}
});
}

@Test
public void locationTrackingLayersAdded() throws Exception {
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_ACCURACY_LAYER) != null);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_BACKGROUND_LAYER) != null);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null);
}
});
}

@Test
public void locationBearingLayersAdded() throws Exception {
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_ACCURACY_LAYER) != null);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_BACKGROUND_LAYER) != null);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_BEARING_LAYER) != null);
}
});
}

@Test
public void locationNavigationLayersAdded() throws Exception {
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_NAVIGATION_LAYER) != null);
}
});
}

@Test
public void locationLayerModeCorrectlySetToNone() throws Exception {
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null);
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NONE);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER).getVisibility().getValue()
.equals(Property.NONE));
}
});
}

@Test
public void onMapChangeLocationLayerRedrawn() throws Exception {
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null);
mapboxMap.setStyleUrl(Style.SATELLITE);
uiController.loopMainThreadForAtLeast(500);
assertEquals(locationLayerPlugin.getLocationLayerMode(), LocationLayerMode.TRACKING);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null);
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER).getVisibility().getValue()
.equals(Property.VISIBLE));
}
});
}

@After
public void afterTest() {
Timber.e("@After: unregister idle resource");
Espresso.unregisterIdlingResources(idlingResource);
}

public void executeLocationLayerTest(LocationLayerPluginAction.onPerformLocationLayerAction listener) {
onView(withId(android.R.id.content)).perform(new LocationLayerPluginAction(mapboxMap, locationLayerPlugin,
listener));
}
}
38 changes: 38 additions & 0 deletions plugins/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mapbox.mapboxsdk.plugins.testapp">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -27,6 +29,42 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>

<activity
android:name=".activity.location.LocationLayerModesActivity"
android:description="@string/description_location_modes"
android:label="@string/title_location_modes">
<meta-data
android:name="@string/category"
android:value="@string/category_location"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>

<activity
android:name=".activity.location.LocationLayerMapChangeActivity"
android:description="@string/description_location_map_change"
android:label="@string/title_location_map_change">
<meta-data
android:name="@string/category"
android:value="@string/category_location"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>

<activity
android:name=".activity.location.ManualLocationUpdatesActivity"
android:description="@string/description_location_manual_update"
android:label="@string/title_location_manual_update">
<meta-data
android:name="@string/category"
android:value="@string/category_location"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.mapbox.mapboxsdk.plugins.testapp;

import android.location.Location;

import com.mapbox.mapboxsdk.constants.Style;

import java.util.Random;

import timber.log.Timber;

/**
* Useful utilities used throughout the testapp.
*/
public class Utils {

private static final String[] STYLES = new String[] {
Style.MAPBOX_STREETS,
Style.OUTDOORS,
Style.LIGHT,
Style.DARK,
Style.SATELLITE_STREETS
};

private static int index;

/**
* Utility to cycle through map styles. Useful to test if runtime styling source and layers transfer over to new
* style.
*
* @return a string ID representing the map style
*/
public static String getNextStyle() {
index++;
if (index == STYLES.length) {
index = 0;
}
return STYLES[index];
}

/**
* Utility for getting a random coordinate inside a provided bounding box and creates a {@link Location} from it.
*
* @param bbox double array forming the bounding box in the order of {@code [minx, miny, maxx, maxy]}
* @return a {@link Location} object using the random coordinate
*/
public static Location getRandomLocation(double[] bbox) {
Random random = new Random();

double randomLat = bbox[1] + (bbox[3] - bbox[1]) * random.nextDouble();
double randomLon = bbox[0] + (bbox[2] - bbox[0]) * random.nextDouble();

Location location = new Location("random-loc");
location.setLongitude(randomLon);
location.setLatitude(randomLat);
Timber.d("getRandomLatLng: %s", location.toString());
return location;
}
}
Loading