[android] - introduce StyleCallback, make parent class for StateCallback

This commit is contained in:
Tobrun
2018-12-05 15:11:27 +02:00
committed by Tobrun
parent 075443e18b
commit 3ffb62b419
2 changed files with 21 additions and 17 deletions

View File

@@ -48,7 +48,7 @@ final class NativeMapView {
private static final String TAG = "Mbgl-NativeMapView";
//Hold a reference to prevent it from being GC'd as long as it's used on the native side
// Hold a reference to prevent it from being GC'd as long as it's used on the native side
private final FileSource fileSource;
// Used to schedule work on the MapRenderer Thread
@@ -71,7 +71,8 @@ final class NativeMapView {
// Flag to indicating destroy was called
private boolean destroyed = false;
private Style style;
// Used for style load callbacks
private StyleCallback styleCallback;
// Holds the pointer to JNI NativeMapView
@Keep
@@ -939,8 +940,8 @@ final class NativeMapView {
@Keep
private void onWillStartLoadingMap() {
stateCallback.onWillStartLoadingMap();
if (style != null) {
style.onWillStartLoadingStyle();
if (styleCallback != null) {
styleCallback.onWillStartLoadingMap();
}
}
@@ -976,7 +977,7 @@ final class NativeMapView {
@Keep
private void onDidFinishLoadingStyle() {
style.onDidFinishLoadingStyle();
styleCallback.onDidFinishLoadingStyle();
stateCallback.onDidFinishLoadingStyle();
}
@@ -1341,9 +1342,8 @@ final class NativeMapView {
});
}
// TODO remove dependency of Style on NativeMapView
public void setStyle(Style style) {
this.style = style;
void setStyleCallback(@NonNull StyleCallback callback) {
this.styleCallback = callback;
}
//
@@ -1407,15 +1407,19 @@ final class NativeMapView {
Bitmap getViewContent();
}
public interface StateCallback {
interface StyleCallback {
void onWillStartLoadingMap();
void onDidFinishLoadingStyle();
}
interface StateCallback extends StyleCallback {
void onCameraWillChange(boolean animated);
void onCameraIsChanging();
void onCameraDidChange(boolean animated);
void onWillStartLoadingMap();
void onDidFinishLoadingMap();
void onDidFailLoadingMap(String error);
@@ -1428,8 +1432,6 @@ final class NativeMapView {
void onDidFinishRenderingMap(boolean fully);
void onDidFinishLoadingStyle();
void onSourceChanged(String sourceId);
}
}

View File

@@ -25,7 +25,7 @@ import java.util.List;
* has been loaded by underlying map.
* </p>
*/
public class Style {
public class Style implements NativeMapView.StyleCallback {
private final NativeMapView nativeMapView;
private final HashMap<String, Source> sources = new HashMap<>();
@@ -365,7 +365,8 @@ public class Style {
* Called when the underlying map will start loading a new style. This method will clean up this style
* by setting the java sources and layers in a detached state and removing them from core.
*/
void onWillStartLoadingStyle() {
@Override
public void onWillStartLoadingMap() {
for (Source source : sources.values()) {
if (source != null) {
source.setDetached();
@@ -388,7 +389,8 @@ public class Style {
* Called when the underlying map has finished loading this style.
* This method will add all components added to the builder that were defined with the 'with' prefix.
*/
void onDidFinishLoadingStyle() {
@Override
public void onDidFinishLoadingStyle() {
if (!styleLoaded) {
styleLoaded = true;
for (Source source : builder.sources) {
@@ -597,7 +599,7 @@ public class Style {
*/
void build(@NonNull NativeMapView nativeMapView, @Nullable OnStyleLoaded styleLoaded) {
Style style = new Style(this, nativeMapView, styleLoaded);
nativeMapView.setStyle(style);
nativeMapView.setStyleCallback(style);
if (styleUrl != null) {
nativeMapView.setStyleUrl(styleUrl);