[android] example custom layer - add context lost callback

This commit is contained in:
Ivo van Dongen
2017-09-19 10:57:10 +03:00
committed by Ivo van Dongen
parent d1e69c8baf
commit 779fc8aeee
3 changed files with 10 additions and 0 deletions

View File

@@ -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);

View File

@@ -11,5 +11,6 @@ public class ExampleCustomLayer {
public static long InitializeFunction;
public static long RenderFunction;
public static long ContextLostFunction;
public static long DeinitializeFunction;
}

View File

@@ -92,6 +92,10 @@ void nativeRender(void *context, const mbgl::style::CustomLayerRenderParameters&
reinterpret_cast<ExampleCustomLayer*>(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<ExampleCustomLayer*>(context);
@@ -122,6 +126,10 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
env->GetStaticFieldID(customLayerClass, "RenderFunction", "J"),
reinterpret_cast<jlong>(nativeRender));
env->SetStaticLongField(customLayerClass,
env->GetStaticFieldID(customLayerClass, "ContextLostFunction", "J"),
reinterpret_cast<jlong>(nativeContextLost));
env->SetStaticLongField(customLayerClass,
env->GetStaticFieldID(customLayerClass, "DeinitializeFunction", "J"),
reinterpret_cast<jlong>(nativeDenitialize));