From bf738b643f49e15e63a2baedc8de1e933c88a33c Mon Sep 17 00:00:00 2001 From: Chuck Greb Date: Wed, 1 Jul 2015 11:04:36 -0400 Subject: [PATCH 1/4] Replaces OpenScienceMap with Tangram --- app/build.gradle | 7 +- .../com/mapzen/erasermap/AndroidModule.java | 5 - .../mapzen/erasermap/util/HttpCacheFactory.kt | 20 -- .../com/mapzen/erasermap/view/MainActivity.kt | 172 ++++-------------- .../erasermap/view/MarkerSymbolFactory.kt | 19 -- .../com/mapzen/erasermap/view/PoiLayer.kt | 53 ------ app/src/main/res/layout/activity_main.xml | 2 +- 7 files changed, 35 insertions(+), 243 deletions(-) delete mode 100644 app/src/main/kotlin/com/mapzen/erasermap/util/HttpCacheFactory.kt delete mode 100644 app/src/main/kotlin/com/mapzen/erasermap/view/MarkerSymbolFactory.kt delete mode 100644 app/src/main/kotlin/com/mapzen/erasermap/view/PoiLayer.kt diff --git a/app/build.gradle b/app/build.gradle index 038ea2a3..c1f9885e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,18 +65,15 @@ repositories { dependencies { compile 'com.android.support:appcompat-v7:22.2.0' compile 'org.jetbrains.kotlin:kotlin-stdlib:0.12.213' - compile 'org.oscim:vtm:0.5.9-SNAPSHOT' - compile 'org.oscim:vtm-android:0.5.9-SNAPSHOT@aar' - compile 'com.mapzen.android:map-burrito:0.1-SNAPSHOT@aar' + compile 'com.mapzen.tangram:tangram:0.1-SNAPSHOT' compile 'com.mapzen.android:lost:1.0.1' compile ('com.mapzen.android:pelias-android-sdk:0.4-SNAPSHOT') { exclude group: 'javax.annotation:javax', module: 'javax.annotation-api' } - compile 'com.squareup.okhttp:okhttp:1.6.0' compile 'com.google.dagger:dagger:2.0' compile 'com.google.dagger:dagger-compiler:2.0' compile 'javax.annotation:javax.annotation-api:1.2' - compile 'com.android.support:support-v4:22.2.0@aar' + compile 'com.android.support:support-v4:22.2.0' compile 'com.squareup:otto:1.3.7' compile ('com.mapzen:on-the-road:0.8-SNAPSHOT') { exclude group: 'org.apache.commons', module: 'commons-io' diff --git a/app/src/main/java/com/mapzen/erasermap/AndroidModule.java b/app/src/main/java/com/mapzen/erasermap/AndroidModule.java index e985deac..c4e9d793 100644 --- a/app/src/main/java/com/mapzen/erasermap/AndroidModule.java +++ b/app/src/main/java/com/mapzen/erasermap/AndroidModule.java @@ -4,7 +4,6 @@ import com.mapzen.erasermap.model.TileCacheBuilder; import com.mapzen.erasermap.presenter.MainPresenter; import com.mapzen.erasermap.presenter.MainPresenterImpl; -import com.mapzen.erasermap.view.MarkerSymbolFactory; import com.mapzen.pelias.SavedSearch; import com.squareup.okhttp.Cache; @@ -46,10 +45,6 @@ public AndroidModule(PrivateMapsApplication application) { return new MainPresenterImpl(); } - @Provides @Singleton MarkerSymbolFactory provideMarkerSymbolFactory() { - return new MarkerSymbolFactory(application); - } - @Provides @Singleton Bus provideBus() { return new Bus(); } diff --git a/app/src/main/kotlin/com/mapzen/erasermap/util/HttpCacheFactory.kt b/app/src/main/kotlin/com/mapzen/erasermap/util/HttpCacheFactory.kt deleted file mode 100644 index ac319866..00000000 --- a/app/src/main/kotlin/com/mapzen/erasermap/util/HttpCacheFactory.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.mapzen.erasermap.util - -import com.squareup.okhttp.Cache -import com.squareup.okhttp.OkHttpClient -import org.oscim.tiling.source.HttpEngine -import org.oscim.tiling.source.OkHttpEngine -import org.oscim.tiling.source.UrlTileSource - -public class HttpCacheFactory : HttpEngine.Factory { - private val mClient = OkHttpClient() - - public constructor(responseCache: Cache?) { - this.mClient.setCache(responseCache) - } - - override fun create(tileSource: UrlTileSource): OkHttpEngine { - return OkHttpEngine(this.mClient, tileSource) - } -} - diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt index 33039b9c..4f799f77 100644 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt +++ b/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt @@ -21,7 +21,7 @@ import com.mapzen.erasermap.BuildConfig import com.mapzen.erasermap.PrivateMapsApplication import com.mapzen.erasermap.R import com.mapzen.erasermap.presenter.MainPresenter -import com.mapzen.mapburrito.MapController +import com.mapzen.erasermap.util.DouglasPeuckerReducer import com.mapzen.pelias.Pelias import com.mapzen.pelias.PeliasLocationProvider import com.mapzen.pelias.SavedSearch @@ -31,39 +31,21 @@ import com.mapzen.pelias.gson.Result import com.mapzen.pelias.widget.AutoCompleteAdapter import com.mapzen.pelias.widget.AutoCompleteListView import com.mapzen.pelias.widget.PeliasSearchView +import com.mapzen.tangram.Tangram +import com.mapzen.valhalla.Instruction import com.mapzen.valhalla.Route import com.mapzen.valhalla.Router import com.squareup.okhttp.Cache -import com.squareup.okhttp.OkHttpClient import com.squareup.otto.Bus -import org.oscim.android.MapView -import org.oscim.android.canvas.AndroidGraphics -import org.oscim.backend.canvas.Color -import org.oscim.core.BoundingBox -import org.oscim.core.GeoPoint -import org.oscim.core.MapPosition -import org.oscim.layers.PathLayer -import org.oscim.layers.marker.ItemizedLayer -import org.oscim.layers.marker.MarkerItem -import org.oscim.layers.marker.MarkerSymbol -import org.oscim.map.Map -import org.oscim.tiling.source.HttpEngine -import org.oscim.tiling.source.OkHttpEngine -import org.oscim.tiling.source.UrlTileSource import retrofit.Callback import retrofit.RetrofitError import retrofit.client.Response -import com.mapzen.erasermap.util.DouglasPeuckerReducer -import com.mapzen.erasermap.util.HttpCacheFactory -import com.mapzen.valhalla.Instruction import java.util.ArrayList import javax.inject.Inject + public class MainActivity : AppCompatActivity(), ViewController, Router.Callback, - SearchResultsView.OnSearchResultSelectedListener, PoiLayer.OnPoiClickListener { - private val BASE_TILE_URL: String = "http://vector.dev.mapzen.com/osm/all" - private val STYLE_PATH: String = "styles/mapzen.xml" - private val FIND_ME_ICON: Int = android.R.drawable.star_big_on + SearchResultsView.OnSearchResultSelectedListener { private val LOCATION_UPDATE_INTERVAL_IN_MS: Long = 1000L private val LOCATION_UPDATE_SMALLEST_DISPLACEMENT: Float = 0f @@ -78,21 +60,17 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback @Inject set var presenter: MainPresenter? = null @Inject set - var markerSymbolFactory: MarkerSymbolFactory? = null - @Inject set var bus: Bus? = null @Inject set var app: PrivateMapsApplication? = null - var mapController: MapController? = null + var tangram : Tangram? = null var autoCompleteAdapter: AutoCompleteAdapter? = null var optionsMenu: Menu? = null - var poiLayer: PoiLayer? = null var destination: Feature? = null - var path: PathLayer? = null - var markers: ItemizedLayer? = null var type : Router.Type = Router.Type.DRIVING var reverse : Boolean = false; + var currentLocation : Location? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -103,10 +81,9 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback presenter?.bus = bus locationClient?.connect() initMapController() - initPoiLayer() initAutoCompleteAdapter() initFindMeButton() - initreverseButton() + initReverseButton() centerOnCurrentLocation() presenter?.onRestoreViewState() } @@ -142,25 +119,8 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback } private fun initMapController() { - val mapView = findViewById(R.id.map) as MapView - mapController = MapController(mapView.map()) - .setHttpEngine(HttpCacheFactory(tileCache)) - .setApiKey(BuildConfig.VECTOR_TILE_API_KEY) - .setTileSource(BASE_TILE_URL) - .addBuildingLayer() - .addLabelLayer() - .setTheme(STYLE_PATH) - .setCurrentLocationDrawable(getResources().getDrawable(FIND_ME_ICON)) - } - - private fun initPoiLayer() { - val map = mapController?.getMap() - val defaultMarker = markerSymbolFactory?.getDefaultMarker() - val activeMarker = markerSymbolFactory?.getActiveMarker() - if (map is Map && defaultMarker is MarkerSymbol && activeMarker is MarkerSymbol) { - poiLayer = PoiLayer(map, defaultMarker, activeMarker) - poiLayer?.onPoiClickListener = this - } + tangram = findViewById(R.id.map) as Tangram + tangram?.setup(this) } private fun initAutoCompleteAdapter() { @@ -184,14 +144,14 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback .setSmallestDisplacement(LOCATION_UPDATE_SMALLEST_DISPLACEMENT) LocationServices.FusedLocationApi?.requestLocationUpdates(locationRequest) { - location: Location ->mapController?.showCurrentLocation(location)?.update() + location: Location -> currentLocation = location } } private fun centerOnCurrentLocation() { val location = LocationServices.FusedLocationApi?.getLastLocation() if (location != null) { - mapController?.showCurrentLocation(location)?.resetMapAndCenterOn(location) + currentLocation = location } } @@ -209,7 +169,7 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback if (searchView is PeliasSearchView) { listView.setAdapter(autoCompleteAdapter) val pelias = Pelias.getPelias() - pelias.setLocationProvider(MapLocationProvider(mapController)) + pelias.setLocationProvider(LocationProvider()) searchView.setAutoCompleteListView(listView) searchView.setSavedSearch(savedSearch) searchView.setPelias(Pelias.getPelias()) @@ -327,13 +287,13 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback } } - class MapLocationProvider(val mapController: MapController?) : PeliasLocationProvider { + inner class LocationProvider() : PeliasLocationProvider { override fun getLat(): String? { - return mapController?.getMap()?.getMapPosition()?.getLatitude().toString() + return currentLocation?.getLatitude().toString() } override fun getLon(): String? { - return mapController?.getMap()?.getMapPosition()?.getLongitude().toString() + return currentLocation?.getLongitude().toString() } } @@ -350,8 +310,6 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback } private fun addSearchResultsToMap(features: List) { - poiLayer?.removeAllItems() - poiLayer?.addAll(features) centerOnCurrentFeature(features) } @@ -363,27 +321,17 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback val location = Location("map") location.setLatitude(feature.getLat()) location.setLongitude(feature.getLon()) - poiLayer?.resetAllItems() - poiLayer?.setActiveItem(position) - mapController?.resetMapAndCenterOn(location) - mapController?.getMap()?.updateMap(true) }, 100) } override fun hideSearchResults() { hideSearchResultsPager() - removeSearchResultsFromMap() } private fun hideSearchResultsPager() { (findViewById(R.id.search_results) as SearchResultsView).setVisibility(View.GONE) } - private fun removeSearchResultsFromMap() { - poiLayer?.removeAllItems() - mapController?.getMap()?.updateMap(true) - } - override fun showProgress() = findViewById(R.id.progress).setVisibility(View.VISIBLE) override fun hideProgress() = findViewById(R.id.progress).setVisibility(View.GONE) @@ -394,9 +342,6 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback override fun onSearchResultSelected(position: Int) = presenter?.onSearchResultSelected(position) - override fun onPoiClick(position: Int) = - (findViewById(R.id.search_results) as SearchResultsView).setCurrentItem(position) - override fun showActionViewAll() { optionsMenu?.findItem(R.id.action_view_all)?.setVisible(true) } @@ -417,73 +362,22 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback override fun success(route: Route?) { this.route = route; runOnUiThread({ + getSupportActionBar()?.hide() + findViewById(R.id.route_preview).setVisibility(View.VISIBLE) + (findViewById(R.id.route_preview) as RoutePreviewView).destination = + SimpleFeature.fromFeature(destination); + (findViewById(R.id.route_preview) as RoutePreviewView).route = route; + // TODO: Draw route on Tangram map + if( findViewById(R.id.route_mode).getVisibility() != View.VISIBLE) { getSupportActionBar()?.hide() findViewById(R.id.route_preview).setVisibility(View.VISIBLE) (findViewById(R.id.route_preview) as RoutePreviewView).destination = SimpleFeature.fromFeature(destination); (findViewById(R.id.route_preview) as RoutePreviewView).route = route; - displayRoute(route) } }) - updateRoutePreview(destination) - } - - fun displayRoute(route: Route?) { - try { - mapController?.getMap()?.layers()?.remove(path) - mapController?.getMap()?.layers()?.remove(markers) - path = PathLayer(mapController?.getMap(), Color.DKGRAY, 8f) - markers = ItemizedLayer(mapController?.getMap(), ArrayList(), - AndroidGraphics.makeMarker(this.getResources().getDrawable(R.drawable.ic_pin), - MarkerItem.HotspotPlace.BOTTOM_CENTER), null) - - var points: List = route!!.getGeometry() - if (points.size() > 100) { - points = DouglasPeuckerReducer.reduceWithTolerance(points, 100.0) - } - path?.clearPath() - var minlat = Integer.MAX_VALUE.toDouble() - var minlon = Integer.MAX_VALUE.toDouble() - var maxlat = Integer.MIN_VALUE.toDouble() - var maxlon = Integer.MIN_VALUE.toDouble() - for (loc in points) { - maxlat = Math.max(maxlat, loc.getLatitude()) - maxlon = Math.max(maxlon, loc.getLongitude()) - minlat = Math.min(minlat, loc.getLatitude()) - minlon = Math.min(minlon, loc.getLongitude()) - path?.addPoint(GeoPoint(loc.getLatitude(), loc.getLongitude())) - } - - val bbox = BoundingBox(minlat, minlon, maxlat, maxlon) - val w = mapController?.getMap()?.getWidth() as Int - val h = mapController?.getMap()?.getHeight() as Int - val position = MapPosition() - position.setByBoundingBox(bbox, w , h) - - position.setScale(position.getZoomScale() * 0.85) - - mapController!!.getMap().setMapPosition(position) - - if (!((mapController?.getMap()?.layers()?.contains(path)) as Boolean)) { - mapController?.getMap()?.layers()?.add(path) - } - - if (!((mapController?.getMap()?.layers()?.contains(markers)) as Boolean)) { - mapController?.getMap()?.layers()?.add(markers) - } - markers?.removeAllItems() - markers?.addItem(getMarkerItem(R.drawable.ic_a, points.get(0), MarkerItem.HotspotPlace.CENTER)) - markers?.addItem(getMarkerItem(R.drawable.ic_pin_active, points.get(points.size() - 1), MarkerItem.HotspotPlace.BOTTOM_CENTER)) - } catch (e: Exception) { - Toast.makeText(this@MainActivity, "No route found", Toast.LENGTH_LONG).show() - } - } - - private fun getMarkerItem(icon: Int, loc: Location, place: MarkerItem.HotspotPlace): MarkerItem { - val markerItem = MarkerItem("Generic Marker", "Generic Description", GeoPoint(loc.getLatitude(), loc.getLongitude())) - markerItem.setMarker(MarkerSymbol(AndroidGraphics.drawableToBitmap(app!!.getResources().getDrawable(icon)), place)) - return markerItem + updateRoutePreview() } override fun failure(statusCode: Int) { @@ -514,26 +408,29 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback } } - fun updateRoutePreview(destination: Feature?) { + fun updateRoutePreview() { (findViewById(R.id.by_car) as RadioButton).setOnCheckedChangeListener { compoundButton, b -> if (b) { type = Router.Type.DRIVING route() - (findViewById(R.id.routing_circle) as ImageButton).setImageResource(R.drawable.ic_start_car_normal) + (findViewById(R.id.routing_circle) as ImageButton) + .setImageResource(R.drawable.ic_start_car_normal) } } (findViewById(R.id.by_foot) as RadioButton).setOnCheckedChangeListener { compoundButton, b -> if (b) { type = Router.Type.WALKING route() - (findViewById(R.id.routing_circle) as ImageButton).setImageResource(R.drawable.ic_start_walk_normal) + (findViewById(R.id.routing_circle) as ImageButton) + .setImageResource(R.drawable.ic_start_walk_normal) } } (findViewById(R.id.by_bike) as RadioButton).setOnCheckedChangeListener { compoundButton, b -> if (b) { type = Router.Type.BIKING route() - (findViewById(R.id.routing_circle) as ImageButton).setImageResource(R.drawable.ic_start_bike_normal) + (findViewById(R.id.routing_circle) as ImageButton) + .setImageResource(R.drawable.ic_start_bike_normal) } } } @@ -551,7 +448,7 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback route() } - private fun initreverseButton() { + private fun initReverseButton() { (findViewById(R.id.route_reverse) as ImageButton).setOnClickListener({ reverse()}) (findViewById(R.id.routing_circle) as ImageButton).setOnClickListener ( @@ -559,10 +456,6 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback } override fun onBackPressed() { - if ((findViewById(R.id.route_preview)).getVisibility() == View.VISIBLE) { - mapController?.getMap()?.layers()?.remove(path) - mapController?.getMap()?.layers()?.remove(markers) - } presenter?.onBackPressed() centerOnCurrentLocation() } @@ -614,4 +507,3 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback } } } - diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/MarkerSymbolFactory.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/MarkerSymbolFactory.kt deleted file mode 100644 index 568ecc93..00000000 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/MarkerSymbolFactory.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.mapzen.erasermap.view - -import android.content.Context -import com.mapzen.erasermap.R -import org.oscim.android.canvas.AndroidGraphics -import org.oscim.layers.marker.MarkerItem -import org.oscim.layers.marker.MarkerSymbol - -public class MarkerSymbolFactory(val context: Context) { - public fun getDefaultMarker(): MarkerSymbol { - return AndroidGraphics.makeMarker(context.getResources() - .getDrawable(R.drawable.ic_pin), MarkerItem.HotspotPlace.BOTTOM_CENTER) - } - - public fun getActiveMarker(): MarkerSymbol { - return AndroidGraphics.makeMarker(context.getResources() - .getDrawable(R.drawable.ic_pin_active), MarkerItem.HotspotPlace.BOTTOM_CENTER) - } -} diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/PoiLayer.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/PoiLayer.kt deleted file mode 100644 index f6b729c8..00000000 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/PoiLayer.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.mapzen.erasermap.view - -import com.mapzen.pelias.SimpleFeature -import com.mapzen.pelias.gson.Feature -import org.oscim.core.GeoPoint -import org.oscim.layers.marker.ItemizedLayer -import org.oscim.layers.marker.MarkerItem -import org.oscim.layers.marker.MarkerSymbol -import org.oscim.map.Map - -public class PoiLayer(val map: Map, val defaultMarker: MarkerSymbol, val activeMarker: MarkerSymbol) - : ItemizedLayer(map, defaultMarker), ItemizedLayer.OnItemGestureListener { - - public var onPoiClickListener: OnPoiClickListener? = null - - init { - map.layers().add(this) - setOnItemGestureListener(this) - } - - public fun addAll(features: List) { - for (feature in features) { - val simpleFeature = SimpleFeature.fromFeature(feature) - addItem(MarkerItem(simpleFeature.getProperty(SimpleFeature.ID), - simpleFeature.getTitle(), - simpleFeature.getAddress(), - GeoPoint(simpleFeature.getLat(), simpleFeature.getLon()))) - } - } - - public fun resetAllItems() { - for (item in mItemList) { - item.setMarker(defaultMarker) - } - } - - public fun setActiveItem(position: Int) { - mItemList.get(position).setMarker(activeMarker) - } - - override fun onItemSingleTapUp(index: Int, item: MarkerItem?): Boolean { - onPoiClickListener?.onPoiClick(index) - return true; - } - - override fun onItemLongPress(index: Int, item: MarkerItem?): Boolean { - return true; - } - - public trait OnPoiClickListener { - public fun onPoiClick(position: Int) - } -} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2256eba4..defe7a54 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,7 +5,7 @@ android:focusableInTouchMode="true" tools:context=".MainActivity"> - From 8a050c720fa67f442ee670e438e82efc7bfc8f78 Mon Sep 17 00:00:00 2001 From: Chuck Greb Date: Wed, 1 Jul 2015 14:45:31 -0400 Subject: [PATCH 2/4] Remove OpenScienceMap tests. Add Tangram test dummies. --- .../erasermap/PrivateMapsTestRunner.java | 9 +- .../com/mapzen/erasermap/dummy/TestMap.java | 75 --------- .../erasermap/shadows/ShadowGLMatrix.java | 10 -- .../shadows/ShadowGLSurfaceView.java | 14 ++ .../erasermap/shadows/ShadowMapView.java | 33 ---- .../erasermap/shadows/ShadowTangram.java | 18 +++ .../erasermap/view/MainActivityTest.java | 147 +----------------- .../microedition/khronos/egl/EGLConfig.java | 4 + .../microedition/khronos/opengles/GL10.java | 4 + 9 files changed, 45 insertions(+), 269 deletions(-) delete mode 100644 app/src/test/java/com/mapzen/erasermap/dummy/TestMap.java delete mode 100644 app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLMatrix.java create mode 100644 app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLSurfaceView.java delete mode 100644 app/src/test/java/com/mapzen/erasermap/shadows/ShadowMapView.java create mode 100644 app/src/test/java/com/mapzen/erasermap/shadows/ShadowTangram.java create mode 100644 app/src/test/java/javax/microedition/khronos/egl/EGLConfig.java create mode 100644 app/src/test/java/javax/microedition/khronos/opengles/GL10.java diff --git a/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java b/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java index 26d41b5d..8d1a5616 100644 --- a/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java +++ b/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java @@ -1,8 +1,7 @@ package com.mapzen.erasermap; -import com.mapzen.erasermap.shadows.ShadowGLMatrix; -import com.mapzen.erasermap.shadows.ShadowMapView; import com.mapzen.erasermap.shadows.ShadowPorterDuffColorFilter; +import com.mapzen.erasermap.shadows.ShadowTangram; import org.junit.runners.model.InitializationError; import org.robolectric.RobolectricGradleTestRunner; @@ -17,8 +16,7 @@ public class PrivateMapsTestRunner extends RobolectricGradleTestRunner { private static final List CUSTOM_SHADOW_TARGETS = Collections.unmodifiableList(Arrays.asList( - "org.oscim.android.MapView", - "org.oscim.renderer.GLMatrix" + "com.mapzen.tangram.Tangram" )); public PrivateMapsTestRunner(Class klass) throws InitializationError { @@ -29,8 +27,7 @@ public PrivateMapsTestRunner(Class klass) throws InitializationError { protected ShadowMap createShadowMap() { return super.createShadowMap() .newBuilder() - .addShadowClass(ShadowMapView.class) - .addShadowClass(ShadowGLMatrix.class) + .addShadowClass(ShadowTangram.class) .addShadowClass(ShadowPorterDuffColorFilter.class) .build(); } diff --git a/app/src/test/java/com/mapzen/erasermap/dummy/TestMap.java b/app/src/test/java/com/mapzen/erasermap/dummy/TestMap.java deleted file mode 100644 index cad1374f..00000000 --- a/app/src/test/java/com/mapzen/erasermap/dummy/TestMap.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mapzen.erasermap.dummy; - -import org.oscim.core.GeoPoint; -import org.oscim.core.MapPosition; -import org.oscim.map.Animator; -import org.oscim.map.Map; - -public class TestMap extends Map { - private Animator animator = new TestAnimator(this); - private boolean updated = false; - - @Override - public void updateMap(boolean b) { - updated = b; - } - - @Override - public void render() { - } - - @Override - public boolean post(Runnable runnable) { - return false; - } - - @Override - public boolean postDelayed(Runnable runnable, long l) { - return false; - } - - @Override - public int getWidth() { - return 0; - } - - @Override - public int getHeight() { - return 0; - } - - @Override - public Animator animator() { - return animator; - } - - public boolean isUpdated() { - return updated; - } - - public static class TestAnimator extends Animator { - private static GeoPoint geoPoint; - - public TestAnimator(Map map) { - super(map); - } - - @Override - public synchronized void animateTo(GeoPoint geoPoint) { - TestAnimator.geoPoint = geoPoint; - } - - @Override - public synchronized void animateTo(long duration, MapPosition mapPosition) { - TestAnimator.geoPoint = mapPosition.getGeoPoint(); - } - - public static GeoPoint getLastGeoPoint() { - return geoPoint; - } - - public static void clearLastGeoPoint() { - geoPoint = null; - } - } -} diff --git a/app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLMatrix.java b/app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLMatrix.java deleted file mode 100644 index 9bab15b8..00000000 --- a/app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLMatrix.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.mapzen.erasermap.shadows; - -import org.oscim.renderer.GLMatrix; -import org.robolectric.annotation.Implements; - -@Implements(GLMatrix.class) -public class ShadowGLMatrix { - public void __constructor__() { - } -} diff --git a/app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLSurfaceView.java b/app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLSurfaceView.java new file mode 100644 index 00000000..3f2fa00b --- /dev/null +++ b/app/src/test/java/com/mapzen/erasermap/shadows/ShadowGLSurfaceView.java @@ -0,0 +1,14 @@ +package com.mapzen.erasermap.shadows; + +import org.robolectric.annotation.Implements; +import org.robolectric.shadows.ShadowSurfaceView; + +import android.content.Context; +import android.opengl.GLSurfaceView; +import android.util.AttributeSet; + +@Implements(GLSurfaceView.class) +public class ShadowGLSurfaceView extends ShadowSurfaceView { + public void __constructor__(Context context, AttributeSet attributeSet) { + } +} diff --git a/app/src/test/java/com/mapzen/erasermap/shadows/ShadowMapView.java b/app/src/test/java/com/mapzen/erasermap/shadows/ShadowMapView.java deleted file mode 100644 index a3b05307..00000000 --- a/app/src/test/java/com/mapzen/erasermap/shadows/ShadowMapView.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.mapzen.erasermap.shadows; - -import com.mapzen.erasermap.dummy.TestMap; - -import org.oscim.android.AndroidAssets; -import org.oscim.android.MapView; -import org.oscim.android.canvas.AndroidGraphics; -import org.oscim.map.Map; -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowRelativeLayout; - -import android.content.Context; -import android.util.AttributeSet; - -@Implements(MapView.class) -public class ShadowMapView extends ShadowRelativeLayout { - private Map map; - - public void __constructor__(Context context, AttributeSet attributeSet) { - AndroidGraphics.init(); - AndroidAssets.init(context); - } - - @Implementation - public Map map() { - if (map == null) { - map = new TestMap(); - } - - return map; - } -} diff --git a/app/src/test/java/com/mapzen/erasermap/shadows/ShadowTangram.java b/app/src/test/java/com/mapzen/erasermap/shadows/ShadowTangram.java new file mode 100644 index 00000000..b325d692 --- /dev/null +++ b/app/src/test/java/com/mapzen/erasermap/shadows/ShadowTangram.java @@ -0,0 +1,18 @@ +package com.mapzen.erasermap.shadows; + +import com.mapzen.tangram.Tangram; + +import org.robolectric.annotation.Implements; + +import android.app.Activity; +import android.content.Context; +import android.util.AttributeSet; + +@Implements(Tangram.class) +public class ShadowTangram extends ShadowGLSurfaceView { + public void __constructor__(Context context, AttributeSet attributeSet) { + } + + public void setup(Activity mainApp) { + } +} diff --git a/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java b/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java index 23255590..fa03403e 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java @@ -4,10 +4,10 @@ import com.mapzen.erasermap.BuildConfig; import com.mapzen.erasermap.PrivateMapsTestRunner; import com.mapzen.erasermap.R; -import com.mapzen.erasermap.dummy.TestMap; import com.mapzen.pelias.SavedSearch; import com.mapzen.pelias.gson.Feature; import com.mapzen.pelias.widget.PeliasSearchView; +import com.mapzen.tangram.Tangram; import com.mapzen.valhalla.Route; import com.mapzen.valhalla.Router; @@ -15,21 +15,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.oscim.android.MapView; -import org.oscim.layers.marker.ItemizedLayer; -import org.oscim.layers.marker.MarkerItem; -import org.oscim.layers.tile.buildings.BuildingLayer; -import org.oscim.layers.tile.vector.VectorTileLayer; -import org.oscim.layers.tile.vector.labeling.LabelLayer; -import org.oscim.tiling.source.OkHttpEngine; -import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.robolectric.Robolectric; import org.robolectric.annotation.Config; import org.robolectric.fakes.RoboMenu; import org.robolectric.shadows.ShadowActivity; import org.robolectric.shadows.ShadowIntent; import org.robolectric.shadows.ShadowLocationManager; -import org.robolectric.util.ReflectionHelpers; import android.content.Intent; import android.content.SharedPreferences; @@ -46,10 +37,7 @@ import static android.view.View.VISIBLE; import static com.mapzen.erasermap.dummy.TestHelper.getFixture; import static com.mapzen.erasermap.dummy.TestHelper.getTestFeature; -import static com.mapzen.erasermap.dummy.TestMap.TestAnimator.clearLastGeoPoint; -import static com.mapzen.erasermap.dummy.TestMap.TestAnimator.getLastGeoPoint; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.within; import static org.robolectric.Shadows.shadowOf; @RunWith(PrivateMapsTestRunner.class) @@ -58,15 +46,12 @@ public class MainActivityTest { private MainActivity activity; private LocationManager locationManager; private ShadowLocationManager shadowLocationManager; - private MapView mapView; @Before public void setUp() throws Exception { activity = Robolectric.setupActivity(MainActivity.class); locationManager = (LocationManager) activity.getSystemService(LOCATION_SERVICE); shadowLocationManager = shadowOf(locationManager); - mapView = (MapView) activity.findViewById(R.id.map); - clearLastGeoPoint(); } @Test @@ -81,46 +66,7 @@ public void shouldReturnAppName() throws Exception { @Test public void shouldHaveMapView() throws Exception { - assertThat(activity.findViewById(R.id.map)).isInstanceOf(MapView.class); - } - - @Test - public void shouldHaveBaseMap() throws Exception { - assertThat(mapView.map().layers().get(1)).isInstanceOf(VectorTileLayer.class); - } - - @Test - public void shouldHaveBuildingLayer() throws Exception { - assertThat(mapView.map().layers().get(2)).isInstanceOf(BuildingLayer.class); - } - - @Test - public void shouldHaveLabelLayer() throws Exception { - assertThat(mapView.map().layers().get(3)).isInstanceOf(LabelLayer.class); - } - - @Test - public void shouldSetHttpEngine() throws Exception { - VectorTileLayer baseLayer = activity.getMapController().getBaseLayer(); - OSciMap4TileSource tileSource = ReflectionHelpers.getField(baseLayer, "mTileSource"); - assertThat(tileSource.getHttpEngine()).isInstanceOf(OkHttpEngine.class); - } - - @Test - public void shouldCenterOnLocationWhenFindMeButtonIsClicked() throws Exception { - LocationServices.FusedLocationApi.setMockMode(true); - LocationServices.FusedLocationApi.setMockLocation(getTestLocation(1.0, 2.0)); - activity.findViewById(R.id.find_me).performClick(); - assertThat(getLastGeoPoint().getLatitude()).isCloseTo(1.0, within(0.0001)); - assertThat(getLastGeoPoint().getLongitude()).isEqualTo(2.0, within(0.0001)); - } - - @Test - public void shouldDisplayCurrentLocationIconWhenFindMeButtonIsClicked() throws Exception { - LocationServices.FusedLocationApi.setMockMode(true); - LocationServices.FusedLocationApi.setMockLocation(getTestLocation(1.0, 2.0)); - activity.findViewById(R.id.find_me).performClick(); - assertThat(mapView.map().layers().get(4)).isInstanceOf(ItemizedLayer.class); + assertThat(activity.findViewById(R.id.map)).isInstanceOf(Tangram.class); } @Test @@ -128,23 +74,6 @@ public void shouldRequestLocationUpdates() throws Exception { assertThat(shadowLocationManager.getRequestLocationUpdateListeners()).isNotEmpty(); } - @Test - public void shouldSetMarkerPositionOnLocationUpdate() throws Exception { - LocationServices.FusedLocationApi.setMockMode(true); - LocationServices.FusedLocationApi.setMockLocation(getTestLocation(1.0, 2.0)); - ItemizedLayer itemizedLayer = (ItemizedLayer) mapView.map().layers().get(5); - MarkerItem item = itemizedLayer.removeItem(0); - assertThat(item.geoPoint.getLatitude()).isEqualTo(1.0); - assertThat(item.geoPoint.getLongitude()).isEqualTo(2.0); - } - - @Test - public void shouldUpdateMapOnLocationUpdate() throws Exception { - LocationServices.FusedLocationApi.setMockMode(true); - LocationServices.FusedLocationApi.setMockLocation(getTestLocation(1.0, 2.0)); - assertThat(((TestMap) mapView.map()).isUpdated()).isTrue(); - } - @Test public void onPause_shouldDisconnectLocationServices() throws Exception { activity.onPause(); @@ -256,38 +185,6 @@ public void hideProgress_shouldSetProgressViewGone() throws Exception { assertThat(activity.findViewById(R.id.progress).getVisibility()).isEqualTo(GONE); } - @Test - public void showSearchResults_shouldAddFeaturesToPoiLayer() throws Exception { - ArrayList features = new ArrayList<>(); - features.add(getTestFeature()); - features.add(getTestFeature()); - features.add(getTestFeature()); - activity.showSearchResults(features); - assertThat(activity.getPoiLayer().size()).isEqualTo(3); - } - - @Test - public void hideSearchResults_shouldClearPoiLayer() throws Exception { - ArrayList features = new ArrayList<>(); - features.add(getTestFeature()); - features.add(getTestFeature()); - features.add(getTestFeature()); - activity.showSearchResults(features); - activity.hideSearchResults(); - assertThat(activity.getPoiLayer().size()).isEqualTo(0); - } - - @Test - public void showSearchResults_shouldCenterOnCurrentFeature() throws Exception { - Feature feature = getTestFeature(1.0, 2.0); - ArrayList features = new ArrayList<>(); - features.add(feature); - activity.showSearchResults(features); - Robolectric.flushForegroundScheduler(); - assertThat(getLastGeoPoint().getLatitude()).isCloseTo(1.0, within(0.0001)); - assertThat(getLastGeoPoint().getLongitude()).isEqualTo(2.0, within(0.0001)); - } - @Test public void showOverflowMenu_shouldShowOverflowGroup() throws Exception { final RoboMenuWithGroup menu = new RoboMenuWithGroup(0, false); @@ -365,26 +262,6 @@ public void hideRoutePreview_shouldHideRoutePreviewView() throws Exception { assertThat(activity.findViewById(R.id.route_preview).getVisibility()).isEqualTo(GONE); } - @Test - public void onSuccess_shouldShowDrawnRoute() throws Exception { - activity.showRoutePreview(getTestFeature()); - activity.success(new Route(getFixture("valhalla_route"))); - assertThat(activity.getMapController().getMap().layers().contains(activity.getPath())) - .isTrue(); - } - - - @Test - public void onBack_shouldHideDrawnRoute() throws Exception { - activity.showRoutePreview(getTestFeature()); - activity.success(new Route(getFixture("valhalla_route"))); - assertThat(activity.getMapController().getMap().layers().contains(activity.getPath())) - .isTrue(); - activity.onBackPressed(); - assertThat(activity.getMapController().getMap().layers().contains(activity.getPath())) - .isFalse(); - } - @Test public void onRadioClick_shouldChangeType() throws Exception { activity.showRoutePreview(getTestFeature()); @@ -419,26 +296,6 @@ public void onRoutingCircleClick_shouldOpenDirectionListActivity() throws Except assertThat(shadowIntent.getComponent().getClassName()).contains("InstructionListActivity"); } - @Test - public void success_shouldAddMarkerLayer() throws Exception { - activity.showRoutePreview(getTestFeature()); - activity.success(new Route(getFixture("valhalla_route"))); - assertThat(activity.getMapController().getMap().layers().contains(activity.getMarkers())) - .isTrue(); - } - - @Test - public void success_shouldClearMarkerLayer() throws Exception { - activity.showRoutePreview(getTestFeature()); - activity.success(new Route(getFixture("valhalla_route"))); - assertThat(activity.getMapController().getMap().layers().contains(activity.getMarkers())) - .isTrue(); - activity.onBackPressed(); - assertThat(activity.getMapController().getMap().layers().contains(activity.getMarkers())) - .isFalse(); - - } - private Location getTestLocation(double lat, double lng) { Location location = new Location("test"); location.setLatitude(lat); diff --git a/app/src/test/java/javax/microedition/khronos/egl/EGLConfig.java b/app/src/test/java/javax/microedition/khronos/egl/EGLConfig.java new file mode 100644 index 00000000..e685258e --- /dev/null +++ b/app/src/test/java/javax/microedition/khronos/egl/EGLConfig.java @@ -0,0 +1,4 @@ +package javax.microedition.khronos.egl; + +public class EGLConfig { +} diff --git a/app/src/test/java/javax/microedition/khronos/opengles/GL10.java b/app/src/test/java/javax/microedition/khronos/opengles/GL10.java new file mode 100644 index 00000000..dabb6280 --- /dev/null +++ b/app/src/test/java/javax/microedition/khronos/opengles/GL10.java @@ -0,0 +1,4 @@ +package javax.microedition.khronos.opengles; + +public class GL10 { +} From 5c8a90d47c352ca4ae7253a5ecd70ab9ea16b32c Mon Sep 17 00:00:00 2001 From: Chuck Greb Date: Wed, 1 Jul 2015 14:53:51 -0400 Subject: [PATCH 3/4] Update tangram artifact name --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index c1f9885e..628ff5ab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,7 +65,7 @@ repositories { dependencies { compile 'com.android.support:appcompat-v7:22.2.0' compile 'org.jetbrains.kotlin:kotlin-stdlib:0.12.213' - compile 'com.mapzen.tangram:tangram:0.1-SNAPSHOT' + compile 'com.mapzen.tangram:tangram-es:0.1-SNAPSHOT' compile 'com.mapzen.android:lost:1.0.1' compile ('com.mapzen.android:pelias-android-sdk:0.4-SNAPSHOT') { exclude group: 'javax.annotation:javax', module: 'javax.annotation-api' From 8e60632b4224e284e386513394614260c81078ca Mon Sep 17 00:00:00 2001 From: Chuck Greb Date: Wed, 1 Jul 2015 14:57:29 -0400 Subject: [PATCH 4/4] Removes VTM install script --- README.md | 6 ------ circle.yml | 1 - scripts/install-vtm.sh | 17 ----------------- 3 files changed, 24 deletions(-) delete mode 100755 scripts/install-vtm.sh diff --git a/README.md b/README.md index 562a3d43..595b8202 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,6 @@ # Eraser Map Privacy-focused mapping application for Android -## Install VTM dependency -Run the following script to deploy VTM dependencies to your local Maven repository. -```bash -$ scripts/install-vtm.sh -``` - ## Importing project into Android Studio 1. Clone https://github.com/mapzen/eraser-map.git 2. Open Android Studio and choose _File > Import project..._ and select project root folder diff --git a/circle.yml b/circle.yml index 20e3ae49..12584f05 100644 --- a/circle.yml +++ b/circle.yml @@ -14,7 +14,6 @@ machine: dependencies: pre: - echo y | android update sdk --all --no-ui --force --filter "extra-android-m2repository" - - scripts/install-vtm.sh - sudo apt-get update; sudo apt-get install s3cmd - printf "[default]\naccess_key = $S3_ACCESS_KEY\n secret_key = $S3_SECRET_KEY" > ~/.s3cfg - git clone https://github.com/mapzen/apk-s3-lister.git; cd apk-s3-lister; ./upload.sh diff --git a/scripts/install-vtm.sh b/scripts/install-vtm.sh deleted file mode 100755 index 74888a84..00000000 --- a/scripts/install-vtm.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -# -# This script installs the VTM project and native dependencies. -# -# Usage: -# install-vtm.sh - -git clone --recursive https://github.com/mapzen/vtm.git - -echo "Installing vtm" -cd vtm/vtm && ../gradlew clean install - -echo "Installing vtm-android" -cd ../vtm-android && ../gradlew clean install - -echo "Cleaning up vtm project" -cd ../.. && rm -rf vtm