diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2016-08-08 11:33:31 -0400 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2016-08-08 11:33:31 -0400 |
commit | d9145f504b11217816d27dcfcf9c93aa56f4c239 (patch) | |
tree | 7b07b4ede8ba1337c5da4bfc080f1df932c4133f | |
parent | 66d8c003766b5ad0df2aa00b84c8fe3d3ac3e750 (diff) | |
download | qtlocation-mapboxgl-d9145f504b11217816d27dcfcf9c93aa56f4c239.tar.gz |
[android] #5887 - Custom layer crash fix + updated test case
5 files changed, 43 insertions, 11 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java index 82ecc09cd7..4d578b54f8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java @@ -20,7 +20,7 @@ public class CustomLayer extends Layer { super(nativePtr); } - public void invalidate() { + public void update() { nativeUpdate(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java index 387cedbd6c..9bad3647a3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java @@ -106,7 +106,7 @@ public abstract class Layer { } } - public void invalidate() { + public final void invalidate() { this.invalidated = true; } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java index 4070216537..213b85b6c3 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java @@ -7,14 +7,17 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; +import android.view.Menu; import android.view.MenuItem; import android.view.View; + import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.style.layers.CustomLayer; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.model.customlayer.ExampleCustomLayer; @@ -33,14 +36,7 @@ public class CustomLayerActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_layer); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - final ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayShowHomeEnabled(true); - } + setupActionBar(); mapView = (MapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); @@ -80,13 +76,20 @@ public class CustomLayerActivity extends AppCompatActivity { ExampleCustomLayer.createContext(), ExampleCustomLayer.InitializeFunction, ExampleCustomLayer.RenderFunction, - ExampleCustomLayer.DeinitializeFunction), null); + ExampleCustomLayer.DeinitializeFunction), "building"); fab.setImageResource(R.drawable.ic_layers_clear_24dp); } isShowingCustomLayer = !isShowingCustomLayer; } + private void updateLayer() { + CustomLayer custom = mapboxMap.getLayerAs("custom"); + if (custom != null) { + custom.update(); + } + } + @Override public void onResume() { super.onResume(); @@ -118,13 +121,33 @@ public class CustomLayerActivity extends AppCompatActivity { } @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_custom_layer, menu); + return true; + } + + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; + case R.id.action_update_layer: + updateLayer(); + return true; default: return super.onOptionsItemSelected(item); } } + + private void setupActionBar() { + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + final ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_custom_layer.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_custom_layer.xml new file mode 100644 index 0000000000..43465cce62 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_custom_layer.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:mapbox="http://schemas.android.com/apk/res-auto"> + + <item + android:id="@+id/action_update_layer" + android:title="Update layer (invalidate)" /> +</menu>
\ No newline at end of file diff --git a/platform/android/src/style/layers/custom_layer.cpp b/platform/android/src/style/layers/custom_layer.cpp index 4be6f3800d..aeabb4e19d 100644 --- a/platform/android/src/style/layers/custom_layer.cpp +++ b/platform/android/src/style/layers/custom_layer.cpp @@ -24,6 +24,7 @@ namespace android { CustomLayer::~CustomLayer() = default; void CustomLayer::update(jni::JNIEnv&) { + Log::Debug(mbgl::Event::JNI, "Updating map"); if (map) { map->update(mbgl::Update::Repaint); } else { |