Skip to content

Commit

Permalink
Merge pull request #190 from mapzen/108-clear-location-markers
Browse files Browse the repository at this point in the history
Clear location markers on rotation
  • Loading branch information
msmollin committed Dec 10, 2015
2 parents a72050f + dd724a2 commit b024c42
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public open class MainPresenterImpl(val mapzenLocation: MapzenLocation, val bus:
private fun onBackPressedStateRoutePreview() {
vsm.viewState = ViewStateManager.ViewState.SEARCH_RESULTS
mainViewController?.hideRoutePreview()
mainViewController?.clearRouteLine()
mainViewController?.clearRoute()
}

private fun onBackPressedStateRouting() {
Expand Down Expand Up @@ -197,12 +197,16 @@ public open class MainPresenterImpl(val mapzenLocation: MapzenLocation, val bus:
}

override fun onCreate() {
if (!initialized) {
val currentLocation = mapzenLocation.getLastLocation()
if (currentLocation is Location) {
val currentLocation = mapzenLocation.getLastLocation()
if (currentLocation is Location) {
if (!initialized) {
// Show location puck and center map
mainViewController?.centerMapOnLocation(currentLocation, MainPresenter.DEFAULT_ZOOM)
initialized = true
} else {
// Just show location puck. Do not recenter map.
mainViewController?.showCurrentLocation(currentLocation)
}
initialized = true
}
}

Expand Down Expand Up @@ -269,7 +273,7 @@ public open class MainPresenterImpl(val mapzenLocation: MapzenLocation, val bus:
mainViewController?.hideProgress()
routeManager.route = route
generateRoutingMode()
mainViewController?.drawRouteLine(route)
mainViewController?.drawRoute(route)
}

private fun generateRoutePreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface RoutePresenter {
public fun onInstructionPagerTouch()
public fun onInstructionSelected(instruction: Instruction)
public fun onUpdateSnapLocation(location: Location)
public fun onRouteClear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public class RoutePresenterImpl(private val routeEngine: RouteEngine,
routeController?.centerMapOnLocation(location)
}
}

override fun onRouteClear() {
routeController?.hideRouteIcon()
routeController?.hideRouteLine()
}
}
37 changes: 10 additions & 27 deletions app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public class MainActivity : AppCompatActivity(), MainViewController, RouteCallba
var mapController : MapController? = null
var autoCompleteAdapter: AutoCompleteAdapter? = null
var optionsMenu: Menu? = null
var routeLine: MapData? = null
var findMe: MapData? = null
var searchResults: MapData? = null

Expand Down Expand Up @@ -149,7 +148,8 @@ public class MainActivity : AppCompatActivity(), MainViewController, RouteCallba
override public fun onDestroy() {
super.onDestroy()
saveCurrentSearchTerm()
clearRouteLine()
routeModeView.clearRoute()
findMe?.clear()
}

private fun initMapController() {
Expand Down Expand Up @@ -470,8 +470,12 @@ public class MainActivity : AppCompatActivity(), MainViewController, RouteCallba
route()
}

override fun clearRouteLine() {
routeLine?.clear()
override fun drawRoute(route: Route) {
routeModeView.drawRoute(route)
}

override fun clearRoute() {
routeModeView.clearRoute()
}

override fun success(route: Route) {
Expand All @@ -484,31 +488,10 @@ public class MainActivity : AppCompatActivity(), MainViewController, RouteCallba
}
})
updateRoutePreview()
drawRouteLine(route)
routeModeView.drawRoute(route)
hideProgress()
}

override fun drawRouteLine(route: Route) {
val properties = com.mapzen.tangram.Properties()
properties.add("type", "line");
val geometry: ArrayList<Location>? = route.getGeometry()
val mapGeometry: ArrayList<LngLat> = ArrayList()
if (geometry is ArrayList<Location>) {
for (location in geometry) {
mapGeometry.add(LngLat(location.longitude, location.latitude))
}
}

if (routeLine == null) {
routeLine = MapData("route")
Tangram.addDataSource(routeLine);
}

routeLine?.clear()
routeLine?.addLine(properties, mapGeometry)
routeLine?.update();
}

override fun failure(statusCode: Int) {
hideProgress()
Toast.makeText(this@MainActivity, "No route found", Toast.LENGTH_LONG).show()
Expand Down Expand Up @@ -605,7 +588,7 @@ public class MainActivity : AppCompatActivity(), MainViewController, RouteCallba
showRoutingMode(feature)
val route = routeManager?.route
if (route is Route) {
drawRouteLine(route)
drawRoute(route)
}
routeModeView.resumeRoute(feature, routeManager?.route)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface MainViewController {
public fun showCurrentLocation(location: Location)
public fun setMapTilt(radians: Float)
public fun setMapRotation(radians: Float)
public fun drawRouteLine(route: Route)
public fun clearRouteLine()
public fun drawRoute(route: Route)
public fun clearRoute()
public fun rotateCompass()
}
33 changes: 32 additions & 1 deletion app/src/main/kotlin/com/mapzen/erasermap/view/RouteModeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class RouteModeView : LinearLayout, RouteViewController, ViewPager.OnPage

private var currentSnapLocation: Location? = null
private var routeIcon: MapData? = null
private var routeLine: MapData? = null


public constructor(context: Context) : super(context) {
init(context)
Expand Down Expand Up @@ -380,7 +382,7 @@ public class RouteModeView : LinearLayout, RouteViewController, ViewPager.OnPage
return Math.toRadians(360 - location.bearing.toDouble()).toFloat()
}

fun hideRouteIcon() {
override fun hideRouteIcon() {
routeIcon?.clear()
}

Expand Down Expand Up @@ -420,4 +422,33 @@ public class RouteModeView : LinearLayout, RouteViewController, ViewPager.OnPage
setAdapter(adapter)
}
}

public fun drawRoute(route: Route) {
val properties = com.mapzen.tangram.Properties()
properties.add("type", "line");
val geometry: ArrayList<Location>? = route.getGeometry()
val mapGeometry: ArrayList<LngLat> = ArrayList()
if (geometry is ArrayList<Location>) {
for (location in geometry) {
mapGeometry.add(LngLat(location.longitude, location.latitude))
}
}

if (routeLine == null) {
routeLine = MapData("route")
Tangram.addDataSource(routeLine);
}

routeLine?.clear()
routeLine?.addLine(properties, mapGeometry)
routeLine?.update();
}

override fun hideRouteLine() {
routeLine?.clear()
}

public fun clearRoute() {
routePresenter?.onRouteClear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface RouteViewController {
public fun updateDistanceToDestination(meters: Int)
public fun showRouteComplete()
public fun showReroute(location: Location)
public fun hideRouteIcon()
public fun hideRouteLine()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mapzen.erasermap.shadows.ShadowMapData;
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;
Expand All @@ -26,6 +27,7 @@ protected ShadowMap createShadowMap() {
.addShadowClass(ShadowGLSurfaceView.class)
.addShadowClass(ShadowPorterDuffColorFilter.class)
.addShadowClass(ShadowMapData.class)
.addShadowClass(ShadowTangram.class)
.build();
}

Expand Down
25 changes: 25 additions & 0 deletions app/src/test/java/com/mapzen/erasermap/shadows/ShadowTangram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mapzen.erasermap.shadows;

import com.mapzen.tangram.DataSource;
import com.mapzen.tangram.Tangram;

import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowSurfaceView;

import java.util.ArrayList;

@Implements(Tangram.class)
public class ShadowTangram extends ShadowSurfaceView {
public static ArrayList<DataSource> dataSources = new ArrayList<>();

@Implementation
public static void addDataSource(DataSource source) {
dataSources.add(source);
}

@Implementation
public static void clearDataSource(DataSource source, boolean data, boolean tiles) {
dataSources.remove(source);
}
}
27 changes: 18 additions & 9 deletions app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import com.mapzen.erasermap.dummy.TestHelper.getTestFeature
import com.mapzen.erasermap.dummy.TestHelper.getTestLocation
import com.mapzen.erasermap.presenter.MainPresenter
import com.mapzen.erasermap.shadows.ShadowMapData
import com.mapzen.erasermap.shadows.ShadowTangram
import com.mapzen.pelias.SavedSearch
import com.mapzen.pelias.gson.Feature
import com.mapzen.pelias.widget.PeliasSearchView
import com.mapzen.tangram.LngLat
import com.mapzen.tangram.MapData
import com.mapzen.tangram.MapView
import com.mapzen.valhalla.Route
import com.mapzen.valhalla.Router
Expand Down Expand Up @@ -231,22 +231,22 @@ public class MainActivityTest {
activity.showRoutePreview(getTestLocation(), getTestFeature())
activity.success(TestRoute())
Robolectric.flushForegroundThreadScheduler()
assertThat((ShadowExtractor.extract(activity.routeLine) as ShadowMapData).line).isNotNull()
val routeLine = ShadowTangram.dataSources[0]
assertThat((ShadowExtractor.extract(routeLine) as ShadowMapData).line).isNotNull()
}

@Test
public fun showRoutePreview_shouldClearPreviousRouteLine() {
val properties = com.mapzen.tangram.Properties()
properties.add("type", "line");
val routeLine = ArrayList<LngLat>()
routeLine.add(LngLat())
activity.routeLine = MapData("route")
activity.routeLine?.addLine(properties, routeLine)
val old = ArrayList<LngLat>()
old.add(LngLat())
activity.routeModeView.drawRoute(TestRoute())
activity.showRoutePreview(getTestLocation(), getTestFeature())
activity.success(TestRoute())
Robolectric.flushForegroundThreadScheduler()
assertThat((ShadowExtractor.extract(activity.routeLine) as ShadowMapData).line)
.isNotSameAs(routeLine)
val new = ShadowTangram.dataSources[0]
assertThat(old).isNotSameAs(new)
}

@Test
Expand Down Expand Up @@ -435,11 +435,20 @@ public class MainActivityTest {
assertThat(shadowMapData.points).isNullOrEmpty()
}

@Test
public fun onDestroy_shouldClearFindMeIcon() {
activity.showCurrentLocation(getTestLocation())
val shadowMapData = ShadowExtractor.extract(activity.findMe) as ShadowMapData
activity.onDestroy()
assertThat(shadowMapData.points).isNullOrEmpty()
}

@Test
public fun resumeRoutingMode_shouldDrawRouteLine() {
activity.routeManager?.route = TestRoute()
activity.resumeRoutingMode(getTestFeature())
val shadowMapData = ShadowExtractor.extract(activity.routeLine) as ShadowMapData
val routeLine = ShadowTangram.dataSources[0]
val shadowMapData = ShadowExtractor.extract(routeLine) as ShadowMapData
assertThat(shadowMapData.line).isNotNull()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ public class MainPresenterTest {
assertThat(mainController.location).isNull()
}

@Test fun onCreate_shouldShowCurrentLocationSecondTimeInvoked() {
presenter.onCreate()
mainController.puckPosition = null
presenter.onCreate()
assertThat(mainController.puckPosition).isNotNull()
}

@Test fun onReroute_shouldShowProgress() {
routeManager.reset()
presenter.onRoutePreviewEvent(RoutePreviewEvent(getTestFeature()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,16 @@ public class RoutePresenterTest {
routePresenter.onInstructionSelected(instruction)
assertThat(routeController.mapLocation).isEqualTo(location)
}

@Test fun onClearRoute_shouldHideRouteIcon() {
routeController.isRouteIconVisible = true
routePresenter.onRouteClear()
assertThat(routeController.isRouteIconVisible).isFalse()
}

@Test fun onClearRoute_shouldHideRouteLine() {
routeController.isRouteLineVisible = true
routePresenter.onRouteClear()
assertThat(routeController.isRouteLineVisible).isFalse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class TestMainController : MainViewController {
public var rotation: Float = 0f
public var routeLine: Route? = null
public var queryText: String = ""
public var puckPosition: Location? = null

public var isProgressVisible: Boolean = false
public var isOverflowVisible: Boolean = false
Expand Down Expand Up @@ -103,6 +104,7 @@ public class TestMainController : MainViewController {
}

override fun showCurrentLocation(location: Location) {
puckPosition = location
}

override fun setMapTilt(radians: Float) {
Expand All @@ -117,11 +119,11 @@ public class TestMainController : MainViewController {
isReverseGeocodeVisible = true
}

override fun drawRouteLine(route: Route) {
override fun drawRoute(route: Route) {
routeLine = route
}

override fun clearRouteLine() {
override fun clearRoute() {
routeLine = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class TestRouteController : RouteViewController {
public var mapLocation: Location? = null
public var isDirectionListVisible: Boolean = false
public var isResumeButtonVisible: Boolean = false
public var isRouteIconVisible: Boolean = false
public var isRouteLineVisible: Boolean = false

override fun onLocationChanged(location: Location) {
this.location = location
Expand Down Expand Up @@ -68,4 +70,12 @@ public class TestRouteController : RouteViewController {

override fun updateSnapLocation(location: Location) {
}

override fun hideRouteIcon() {
isRouteIconVisible = false
}

override fun hideRouteLine() {
isRouteLineVisible = false
}
}
1 change: 1 addition & 0 deletions config/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<suppress checks="MemberName" files=".*src/test/java/*" />
<suppress checks="MagicNumberCheck" files=".*src/test/java/*" />
<suppress checks="[a-zA-Z0-9]*" files="MapzenAndroidManifest\.java" />
<suppress checks="VisibilityModifier" files="ShadowTangram\.java" />
</suppressions>

0 comments on commit b024c42

Please sign in to comment.