From 779fc8aeeed7a76022aa4b14e5e72d62745dd2b6 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 19 Sep 2017 10:57:10 +0300 Subject: [android] example custom layer - add context lost callback --- .../testapp/activity/customlayer/CustomLayerActivity.java | 1 + .../mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java | 1 + platform/android/src/example_custom_layer.cpp | 8 ++++++++ 3 files changed, 10 insertions(+) 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 dde22db2db..1b49e9e3d6 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 @@ -69,6 +69,7 @@ public class CustomLayerActivity extends AppCompatActivity { ExampleCustomLayer.createContext(), ExampleCustomLayer.InitializeFunction, ExampleCustomLayer.RenderFunction, + ExampleCustomLayer.ContextLostFunction, // Optional ExampleCustomLayer.DeinitializeFunction); mapboxMap.addLayerBelow(customLayer, "building"); fab.setImageResource(R.drawable.ic_layers_clear); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java index 8c049d7730..aaad2f04ab 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java @@ -11,5 +11,6 @@ public class ExampleCustomLayer { public static long InitializeFunction; public static long RenderFunction; + public static long ContextLostFunction; public static long DeinitializeFunction; } diff --git a/platform/android/src/example_custom_layer.cpp b/platform/android/src/example_custom_layer.cpp index c55c9c3527..1ed68d0835 100644 --- a/platform/android/src/example_custom_layer.cpp +++ b/platform/android/src/example_custom_layer.cpp @@ -92,6 +92,10 @@ void nativeRender(void *context, const mbgl::style::CustomLayerRenderParameters& reinterpret_cast(context)->render(); } +void nativeContextLost(void */*context*/) { + mbgl::Log::Info(mbgl::Event::General, "nativeContextLost"); +} + void nativeDenitialize(void *context) { mbgl::Log::Info(mbgl::Event::General, "nativeDeinitialize"); delete reinterpret_cast(context); @@ -122,6 +126,10 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { env->GetStaticFieldID(customLayerClass, "RenderFunction", "J"), reinterpret_cast(nativeRender)); + env->SetStaticLongField(customLayerClass, + env->GetStaticFieldID(customLayerClass, "ContextLostFunction", "J"), + reinterpret_cast(nativeContextLost)); + env->SetStaticLongField(customLayerClass, env->GetStaticFieldID(customLayerClass, "DeinitializeFunction", "J"), reinterpret_cast(nativeDenitialize)); -- cgit v1.2.1