diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 0521e07ad0d..85022dbc0dc 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -272,6 +272,7 @@ jlongArray std_vector_uint_to_jobject(JNIEnv *env, std::vector vector) return jarray; } + } } @@ -279,13 +280,12 @@ namespace { using namespace mbgl::android; -jlong JNICALL -nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_, jfloat pixelRatio) { +jlong JNICALL nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_, jfloat pixelRatio, jint availableProcessors, jlong totalMemory) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreate"); cachePath = std_string_from_jstring(env, cachePath_); dataPath = std_string_from_jstring(env, dataPath_); apkPath = std_string_from_jstring(env, apkPath_); - NativeMapView *nativeMapView = new NativeMapView(env, obj, pixelRatio); + NativeMapView *nativeMapView = new NativeMapView(env, obj, pixelRatio, availableProcessors, totalMemory); jlong mapViewPtr = reinterpret_cast(nativeMapView); return mapViewPtr; } @@ -337,8 +337,7 @@ void JNICALL nativeTerminateContext(JNIEnv *env, jobject obj, jlong nativeMapVie nativeMapView->terminateContext(); } -void JNICALL -nativeCreateSurface(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject surface) { +void JNICALL nativeCreateSurface(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject surface) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreateSurface"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); @@ -428,8 +427,7 @@ void JNICALL nativeAddClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, js nativeMapView->getMap().addClass(std_string_from_jstring(env, clazz)); } -void JNICALL -nativeSetClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject classes) { +void JNICALL nativeSetClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject classes) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetClasses"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); @@ -482,8 +480,7 @@ jstring JNICALL nativeGetStyleJSON(JNIEnv *env, jobject obj, jlong nativeMapView return std_string_to_jstring(env, nativeMapView->getMap().getStyleJSON()); } -void JNICALL -nativeSetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring accessToken) { +void JNICALL nativeSetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring accessToken) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetAccessToken"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); @@ -691,7 +688,6 @@ std::pair readPolygon(JNIEnv *en return std::make_pair(segment, shapeProperties); } - jlong JNICALL nativeAddPolygon(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polygon) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolygon"); assert(nativeMapViewPtr != 0); @@ -760,7 +756,6 @@ jlongArray JNICALL nativeAddPolygons(JNIEnv *env, jobject obj, jlong nativeMapVi return std_vector_uint_to_jobject(env, shapeAnnotationIDs); } - void JNICALL nativeRemoveAnnotation(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlong annotationId) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotation"); assert(nativeMapViewPtr != 0); @@ -845,8 +840,7 @@ jdouble JNICALL nativeGetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) return nativeMapView->getMap().getScale(); } -void JNICALL -nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jlong duration) { +void JNICALL nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jlong duration) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetZoom"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); @@ -962,6 +956,13 @@ void JNICALL nativeResetNorth(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) nativeMapView->getMap().resetNorth(); } +void JNICALL nativeOnLowMemory(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeOnLowMemory"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + nativeMapView->getMap().onLowMemory(); +} + void JNICALL nativeSetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean debug) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetDebug"); assert(nativeMapViewPtr != 0); @@ -985,8 +986,35 @@ jboolean JNICALL nativeGetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr return nativeMapView->getMap().getDebug(); } -void JNICALL -nativeSetReachability(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean status) { +void JNICALL nativeSetCollisionDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean debug) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetCollisionDebug"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + nativeMapView->getMap().setCollisionDebug(debug); +} + +void JNICALL nativeToggleCollisionDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeToggleCollisionDebug"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + nativeMapView->getMap().toggleCollisionDebug(); +} + +jboolean JNICALL nativeGetCollisionDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetCollisionDebug"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + return nativeMapView->getMap().getCollisionDebug(); +} + +jboolean JNICALL nativeIsFullyLoaded(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeIsFullyLoaded"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + return nativeMapView->getMap().isFullyLoaded(); +} + +void JNICALL nativeSetReachability(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean status) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetReachability"); assert(nativeMapViewPtr != 0); if (status) { @@ -1112,6 +1140,7 @@ jobject JNICALL nativeLatLngForPixel(JNIEnv *env, jobject obj, jlong nativeMapVi return ret; } + } extern "C" { @@ -1167,7 +1196,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { env->ExceptionDescribe(); return JNI_ERR; } - + markerSpriteId = env->GetFieldID(markerClass, "sprite", "Ljava/lang/String;"); if (markerSpriteId == nullptr) { env->ExceptionDescribe(); @@ -1415,7 +1444,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { } const std::vector methods = { - {"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;F)J", + {"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;FIJ)J", reinterpret_cast(&nativeCreate)}, {"nativeDestroy", "(J)V", reinterpret_cast(&nativeDestroy)}, {"nativeInitializeDisplay", "(J)V", reinterpret_cast(&nativeInitializeDisplay)}, @@ -1500,9 +1529,14 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { &nativeSetBearing))}, {"nativeGetBearing", "(J)D", reinterpret_cast(&nativeGetBearing)}, {"nativeResetNorth", "(J)V", reinterpret_cast(&nativeResetNorth)}, + {"nativeOnLowMemory", "(J)V", reinterpret_cast(&nativeOnLowMemory)}, {"nativeSetDebug", "(JZ)V", reinterpret_cast(&nativeSetDebug)}, {"nativeToggleDebug", "(J)V", reinterpret_cast(&nativeToggleDebug)}, {"nativeGetDebug", "(J)Z", reinterpret_cast(&nativeGetDebug)}, + {"nativeSetCollisionDebug", "(JZ)V", reinterpret_cast(&nativeSetCollisionDebug)}, + {"nativeToggleCollisionDebug", "(J)V", reinterpret_cast(&nativeToggleCollisionDebug)}, + {"nativeGetCollisionDebug", "(J)Z", reinterpret_cast(&nativeGetCollisionDebug)}, + {"nativeIsFullyLoaded", "(J)Z", reinterpret_cast(&nativeIsFullyLoaded)}, {"nativeSetReachability", "(JZ)V", reinterpret_cast(&nativeSetReachability)}, //{"nativeGetWorldBoundsMeters", "(J)V", reinterpret_cast(&nativeGetWorldBoundsMeters)}, //{"nativeGetWorldBoundsLatLng", "(J)V", reinterpret_cast(&nativeGetWorldBoundsLatLng)}, diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 9c7a3efde71..351833a07d6 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace mbgl { namespace android { @@ -52,9 +53,11 @@ void log_gl_string(GLenum name, const char *label) { } } -NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_) +NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int availableProcessors_, size_t totalMemory_) : mbgl::View(*this), pixelRatio(pixelRatio_), + availableProcessors(availableProcessors_), + totalMemory(totalMemory_), fileCache(mbgl::android::cachePath + "/mbgl-cache.db"), fileSource(&fileCache), map(*this, fileSource, MapMode::Continuous) { @@ -763,6 +766,16 @@ void NativeMapView::onInvalidate(bool inProgress) { const bool dirty = !clean.test_and_set(); if (dirty) { + float zoomFactor = map.getMaxZoom() - map.getMinZoom() + 1; + float cpuFactor = availableProcessors; + float memoryFactor = static_cast(totalMemory) / 1000.0f / 1000.0f / 1000.0f; + float sizeFactor = (static_cast(map.getWidth()) / mbgl::util::tileSize) * + (static_cast(map.getHeight()) / mbgl::util::tileSize); + + size_t cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5f; + + map.setSourceTileCacheSize(cacheSize); + const bool needsRerender = map.renderSync(); if (!inProgress) { map.nudgeTransitions(needsRerender); diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java index 8c16652ba9d..15b1d32fe3c 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java @@ -1,6 +1,7 @@ package com.mapbox.mapboxgl.views; import android.annotation.TargetApi; +import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -66,7 +67,7 @@ public class MapView extends SurfaceView { private static final String STATE_DEBUG_ACTIVE = "debugActive"; private static final String STATE_STYLE_URL = "styleUrl"; private static final String STATE_ACCESS_TOKEN = "accessToken"; - private static final String STATE_CLASSES = "classes"; + private static final String STATE_STYLE_CLASSES = "styleClasses"; private static final String STATE_DEFAULT_TRANSITION_DURATION = "defaultTransitionDuration"; /** @@ -156,7 +157,12 @@ private void initialize(Context context, AttributeSet attrs) { String apkPath = context.getPackageCodePath(); // Create the NativeMapView - mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath, mScreenDensity); + int availableProcessors = Runtime.getRuntime().availableProcessors(); + ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); + ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + activityManager.getMemoryInfo(memoryInfo); + long totalMemory = memoryInfo.totalMem; + mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath, mScreenDensity,availableProcessors, totalMemory); // Load the attributes TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0); @@ -227,7 +233,7 @@ public void setSprite(String symbol, float scale, Bitmap bitmap) { if(bitmap.getConfig() != Bitmap.Config.ARGB_8888) { bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false); } - ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount()); + ByteBuffer buffer = ByteBuffer.allocate(bitmap.getRowBytes() * bitmap.getHeight()); bitmap.copyPixelsToBuffer(buffer); mNativeMapView.setSprite(symbol, bitmap.getWidth(), bitmap.getHeight(), scale, buffer.array()); @@ -398,15 +404,21 @@ public void setRotateEnabled(boolean rotateEnabled) { } public boolean isDebugActive() { - return mNativeMapView.getDebug(); + return mNativeMapView.getDebug() || mNativeMapView.getCollisionDebug(); } public void setDebugActive(boolean debugActive) { mNativeMapView.setDebug(debugActive); + mNativeMapView.setCollisionDebug(debugActive); } public void toggleDebug() { mNativeMapView.toggleDebug(); + mNativeMapView.toggleCollisionDebug(); + } + + public boolean isFullyLoaded() { + return mNativeMapView.isFullyLoaded(); } private void validateStyleUrl(String url) { @@ -442,39 +454,39 @@ public String getAccessToken() { return mNativeMapView.getAccessToken(); } - public List getClasses() { + public List getStyleClasses() { return mNativeMapView.getClasses(); } - public void setClasses(List classes) { - setClasses(classes, 0); + public void setStyleClasses(List styleClasses) { + setStyleClasses(styleClasses, 0); } - public void setClasses(List classes, long transitionDuration) { + public void setStyleClasses(List styleClasses, long transitionDuration) { mNativeMapView.setDefaultTransitionDuration(transitionDuration); - mNativeMapView.setClasses(classes); + mNativeMapView.setClasses(styleClasses); } - public void addClass(String clazz) { - mNativeMapView.addClass(clazz); + public void addStyleClass(String styleClass) { + mNativeMapView.addClass(styleClass); } - public void removeClass(String clazz) { - mNativeMapView.removeClass(clazz); + public void removeStyleClass(String styleClass) { + mNativeMapView.removeClass(styleClass); } - public boolean hasClass(String clazz) { - return mNativeMapView.hasClass(clazz); + public boolean hasStyleClass(String styleClass) { + return mNativeMapView.hasClass(styleClass); } - public void removeAllClasses() { - removeAllClasses(0); + public void removeAllStyleClasses() { + removeAllStyleClasses(0); } - public void removeAllClasses(long transitionDuration) { + public void removeAllStyleClasses(long transitionDuration) { mNativeMapView.setDefaultTransitionDuration(transitionDuration); - ArrayList classes = new ArrayList<>(0); - setClasses(classes); + ArrayList styleClasses = new ArrayList<>(0); + setStyleClasses(styleClasses); } public LatLng fromScreenLocation(PointF point) { @@ -503,9 +515,9 @@ public void onCreate(Bundle savedInstanceState) { setDebugActive(savedInstanceState.getBoolean(STATE_DEBUG_ACTIVE)); setStyleUrl(savedInstanceState.getString(STATE_STYLE_URL)); setAccessToken(savedInstanceState.getString(STATE_ACCESS_TOKEN)); - List appliedClasses = savedInstanceState.getStringArrayList(STATE_CLASSES); - if (!appliedClasses.isEmpty()) { - setClasses(appliedClasses); + List appliedStyleClasses = savedInstanceState.getStringArrayList(STATE_STYLE_CLASSES); + if (!appliedStyleClasses.isEmpty()) { + setStyleClasses(appliedStyleClasses); } mNativeMapView.setDefaultTransitionDuration(savedInstanceState.getLong(STATE_DEFAULT_TRANSITION_DURATION)); } @@ -526,7 +538,7 @@ public void onSaveInstanceState(Bundle outState) { outState.putBoolean(STATE_DEBUG_ACTIVE, isDebugActive()); outState.putString(STATE_STYLE_URL, mStyleUrl); outState.putString(STATE_ACCESS_TOKEN, getAccessToken()); - outState.putStringArrayList(STATE_CLASSES, new ArrayList<>(getClasses())); + outState.putStringArrayList(STATE_STYLE_CLASSES, new ArrayList<>(getStyleClasses())); outState.putLong(STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration()); } @@ -634,6 +646,12 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) { } } + // Called when the system is running low on memory + // Must be called from Activity onLowMemory + public void onLowMemory() { + mNativeMapView.onLowMemory(); + } + // // Draw events // diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java index 8a78515da3a..3bf123f88e9 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/NativeMapView.java @@ -41,11 +41,19 @@ class NativeMapView { // Constructors // - public NativeMapView(MapView mapView, String cachePath, String dataPath, String apkPath, float pixelRatio) { + public NativeMapView(MapView mapView, String cachePath, String dataPath, String apkPath, float pixelRatio, int availableProcessors, long totalMemory) { + if (availableProcessors < 0) { + throw new IllegalArgumentException("availableProcessors cannot be negative."); + } + + if (totalMemory < 0) { + throw new IllegalArgumentException("totalMemory cannot be negative."); + } + mMapView = mapView; // Create the NativeMapView - mNativeMapViewPtr = nativeCreate(cachePath, dataPath, apkPath, pixelRatio); + mNativeMapViewPtr = nativeCreate(cachePath, dataPath, apkPath, pixelRatio, availableProcessors, totalMemory); } // @@ -165,7 +173,7 @@ public long getDefaultTransitionDuration() { public void setDefaultTransitionDuration(long milliseconds) { if (milliseconds < 0) { throw new IllegalArgumentException( - "durationMilliseconds cannot be negative."); + "milliseconds cannot be negative."); } nativeSetDefaultTransitionDuration(mNativeMapViewPtr, @@ -348,6 +356,10 @@ public void resetNorth() { nativeResetNorth(mNativeMapViewPtr); } + public void onLowMemory() { + nativeOnLowMemory(mNativeMapViewPtr); + } + public void setDebug(boolean debug) { nativeSetDebug(mNativeMapViewPtr, debug); } @@ -360,6 +372,22 @@ public boolean getDebug() { return nativeGetDebug(mNativeMapViewPtr); } + public void setCollisionDebug(boolean debug) { + nativeSetCollisionDebug(mNativeMapViewPtr, debug); + } + + public void toggleCollisionDebug() { + nativeToggleCollisionDebug(mNativeMapViewPtr); + } + + public boolean getCollisionDebug() { + return nativeGetCollisionDebug(mNativeMapViewPtr); + } + + public boolean isFullyLoaded() { + return nativeIsFullyLoaded(mNativeMapViewPtr); + } + public void setReachability(boolean status) { nativeSetReachability(mNativeMapViewPtr, status); } @@ -415,7 +443,7 @@ protected void finalize() throws Throwable { super.finalize(); } - private native long nativeCreate(String cachePath, String dataPath, String apkPath, float pixelRatio); + private native long nativeCreate(String cachePath, String dataPath, String apkPath, float pixelRatio, int availableProcessors, long totalMemory); private native void nativeDestroy(long nativeMapViewPtr); @@ -535,12 +563,22 @@ private native void nativeSetBearing(long nativeMapViewPtr, double degrees, private native void nativeResetNorth(long nativeMapViewPtr); + private native void nativeOnLowMemory(long nativeMapViewPtr); + private native void nativeSetDebug(long nativeMapViewPtr, boolean debug); private native void nativeToggleDebug(long nativeMapViewPtr); private native boolean nativeGetDebug(long nativeMapViewPtr); + private native void nativeSetCollisionDebug(long nativeMapViewPtr, boolean debug); + + private native void nativeToggleCollisionDebug(long nativeMapViewPtr); + + private native boolean nativeGetCollisionDebug(long nativeMapViewPtr); + + private native boolean nativeIsFullyLoaded(long nativeMapViewPtr); + private native void nativeSetReachability(long nativeMapViewPtr, boolean status); //private native void nativeGetWorldBoundsMeters(long nativeMapViewPtr); diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java index 3735cc0445d..988ba9878ce 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java @@ -226,6 +226,14 @@ protected void onSaveInstanceState(Bundle outState) { outState.putBoolean(STATE_IS_GPS_ON, mIsGpsOn); } + // Called when the system is running low on memory + @Override + public void onLowMemory() { + super.onLowMemory(); + + mapView.onLowMemory(); + } + // // Other events // @@ -457,7 +465,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long // Mapbox Streets case 0: mapView.setStyleUrl("asset://styles/mapbox-streets-v7.json"); - mapView.removeAllClasses(); + mapView.removeAllStyleClasses(); mClassSpinner.setVisibility(View.INVISIBLE); mClassSpinner.setAdapter(null); mClassSpinner.setOnItemSelectedListener(null); @@ -466,7 +474,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long // Emerald case 1: mapView.setStyleUrl("asset://styles/emerald-v7.json"); - mapView.removeAllClasses(); + mapView.removeAllStyleClasses(); mClassSpinner.setVisibility(View.INVISIBLE); mClassSpinner.setAdapter(null); mClassSpinner.setOnItemSelectedListener(null); @@ -475,7 +483,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long // Light case 2: mapView.setStyleUrl("asset://styles/light-v7.json"); - mapView.removeAllClasses(); + mapView.removeAllStyleClasses(); mClassSpinner.setVisibility(View.INVISIBLE); mClassSpinner.setAdapter(null); mClassSpinner.setOnItemSelectedListener(null); @@ -484,7 +492,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long // Dark case 3: mapView.setStyleUrl("asset://styles/dark-v7.json"); - mapView.removeAllClasses(); + mapView.removeAllStyleClasses(); mClassSpinner.setVisibility(View.INVISIBLE); mClassSpinner.setAdapter(null); mClassSpinner.setOnItemSelectedListener(null); @@ -493,7 +501,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long // Outdoors case 4: mapView.setStyleUrl("asset://styles/outdoors-v7.json"); - mapView.removeAllClasses(); + mapView.removeAllStyleClasses(); mClassSpinner.setVisibility(View.VISIBLE); mClassSpinner.setAdapter(mOutdoorsClassAdapter); mClassSpinner.setOnItemSelectedListener(new OutdoorClassSpinnerListener()); @@ -516,19 +524,19 @@ private class OutdoorClassSpinnerListener implements AdapterView.OnItemSelectedL @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - ArrayList classes = new ArrayList<>(1); + ArrayList styleClasses = new ArrayList<>(1); switch (position) { // Day case 0: - classes.add("day"); - mapView.setClasses(classes); + styleClasses.add("day"); + mapView.setStyleClasses(styleClasses); break; // Night case 1: - classes.add("night"); - mapView.setClasses(classes); + styleClasses.add("night"); + mapView.setStyleClasses(styleClasses); break; default: @@ -539,7 +547,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long @Override public void onNothingSelected(AdapterView parent) { - mapView.removeAllClasses(); + mapView.removeAllStyleClasses(); } } @@ -548,25 +556,25 @@ private class SatelliteClassSpinnerListener implements AdapterView.OnItemSelecte @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - ArrayList classes = new ArrayList<>(2); + ArrayList styleClasses = new ArrayList<>(2); switch (position) { // Labels + Contours case 0: - classes.add("labels"); - classes.add("contours"); - mapView.setClasses(classes); + styleClasses.add("labels"); + styleClasses.add("contours"); + mapView.setStyleClasses(styleClasses); break; // Labels Only case 1: - classes.add("labels"); - mapView.setClasses(classes); + styleClasses.add("labels"); + mapView.setStyleClasses(styleClasses); break; // No Labels case 2: - mapView.setClasses(classes); + mapView.setStyleClasses(styleClasses); break; default: @@ -577,7 +585,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long @Override public void onNothingSelected(AdapterView parent) { - mapView.removeAllClasses(); + mapView.removeAllStyleClasses(); } } diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp index e65c16869c9..1ea67a0da8f 100644 --- a/include/mbgl/android/native_map_view.hpp +++ b/include/mbgl/android/native_map_view.hpp @@ -17,7 +17,7 @@ namespace android { class NativeMapView : public mbgl::View, private mbgl::util::noncopyable { public: - NativeMapView(JNIEnv *env, jobject obj, float pixelRatio); + NativeMapView(JNIEnv *env, jobject obj, float pixelRatio, int availableProcessors, size_t totalMemory); virtual ~NativeMapView(); float getPixelRatio() const override; @@ -85,6 +85,9 @@ class NativeMapView : public mbgl::View, private mbgl::util::noncopyable { int fbHeight = 0; const float pixelRatio; + int availableProcessors = 0; + size_t totalMemory = 0; + // Ensure these are initialised last mbgl::SQLiteCache fileCache; mbgl::DefaultFileSource fileSource;