[android] #5887 - Custom layer crash fix + updated test case
This commit is contained in:
@@ -20,7 +20,7 @@ public class CustomLayer extends Layer {
|
||||
super(nativePtr);
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
public void update() {
|
||||
nativeUpdate();
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public abstract class Layer {
|
||||
}
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
public final void invalidate() {
|
||||
this.invalidated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -117,14 +120,34 @@ public class CustomLayerActivity extends AppCompatActivity {
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user