First pass at updating JNI bindings
Hook up collisionDebug, isFullyLoaded, onLowMemory in Android Rename class to styleClass in Java to match iOS Fixed some formatting Fixes #1905 Fixes #1946 Fixes #1263
This commit is contained in:
@@ -272,6 +272,7 @@ jlongArray std_vector_uint_to_jobject(JNIEnv *env, std::vector<uint32_t> 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<jlong>(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<NativeMapView *>(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<NativeMapView *>(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<NativeMapView *>(nativeMapViewPtr);
|
||||
@@ -691,7 +688,6 @@ std::pair<mbgl::AnnotationSegment, mbgl::StyleProperties> 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<NativeMapView *>(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<NativeMapView *>(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<NativeMapView *>(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<NativeMapView *>(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<NativeMapView *>(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<NativeMapView *>(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<JNINativeMethod> 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<void *>(&nativeCreate)},
|
||||
{"nativeDestroy", "(J)V", reinterpret_cast<void *>(&nativeDestroy)},
|
||||
{"nativeInitializeDisplay", "(J)V", reinterpret_cast<void *>(&nativeInitializeDisplay)},
|
||||
@@ -1500,9 +1529,14 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
&nativeSetBearing))},
|
||||
{"nativeGetBearing", "(J)D", reinterpret_cast<void *>(&nativeGetBearing)},
|
||||
{"nativeResetNorth", "(J)V", reinterpret_cast<void *>(&nativeResetNorth)},
|
||||
{"nativeOnLowMemory", "(J)V", reinterpret_cast<void *>(&nativeOnLowMemory)},
|
||||
{"nativeSetDebug", "(JZ)V", reinterpret_cast<void *>(&nativeSetDebug)},
|
||||
{"nativeToggleDebug", "(J)V", reinterpret_cast<void *>(&nativeToggleDebug)},
|
||||
{"nativeGetDebug", "(J)Z", reinterpret_cast<void *>(&nativeGetDebug)},
|
||||
{"nativeSetCollisionDebug", "(JZ)V", reinterpret_cast<void *>(&nativeSetCollisionDebug)},
|
||||
{"nativeToggleCollisionDebug", "(J)V", reinterpret_cast<void *>(&nativeToggleCollisionDebug)},
|
||||
{"nativeGetCollisionDebug", "(J)Z", reinterpret_cast<void *>(&nativeGetCollisionDebug)},
|
||||
{"nativeIsFullyLoaded", "(J)Z", reinterpret_cast<void *>(&nativeIsFullyLoaded)},
|
||||
{"nativeSetReachability", "(JZ)V", reinterpret_cast<void *>(&nativeSetReachability)},
|
||||
//{"nativeGetWorldBoundsMeters", "(J)V", reinterpret_cast<void *>(&nativeGetWorldBoundsMeters)},
|
||||
//{"nativeGetWorldBoundsLatLng", "(J)V", reinterpret_cast<void *>(&nativeGetWorldBoundsLatLng)},
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <mbgl/platform/event.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/platform/gl.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
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<float>(totalMemory) / 1000.0f / 1000.0f / 1000.0f;
|
||||
float sizeFactor = (static_cast<float>(map.getWidth()) / mbgl::util::tileSize) *
|
||||
(static_cast<float>(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);
|
||||
|
||||
@@ -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 @@ public class MapView extends SurfaceView {
|
||||
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 class MapView extends SurfaceView {
|
||||
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 class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
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 class MapView extends SurfaceView {
|
||||
return mNativeMapView.getAccessToken();
|
||||
}
|
||||
|
||||
public List<String> getClasses() {
|
||||
public List<String> getStyleClasses() {
|
||||
return mNativeMapView.getClasses();
|
||||
}
|
||||
|
||||
public void setClasses(List<String> classes) {
|
||||
setClasses(classes, 0);
|
||||
public void setStyleClasses(List<String> styleClasses) {
|
||||
setStyleClasses(styleClasses, 0);
|
||||
}
|
||||
|
||||
public void setClasses(List<String> classes, long transitionDuration) {
|
||||
public void setStyleClasses(List<String> 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<String> classes = new ArrayList<>(0);
|
||||
setClasses(classes);
|
||||
ArrayList<String> styleClasses = new ArrayList<>(0);
|
||||
setStyleClasses(styleClasses);
|
||||
}
|
||||
|
||||
public LatLng fromScreenLocation(PointF point) {
|
||||
@@ -503,9 +515,9 @@ public class MapView extends SurfaceView {
|
||||
setDebugActive(savedInstanceState.getBoolean(STATE_DEBUG_ACTIVE));
|
||||
setStyleUrl(savedInstanceState.getString(STATE_STYLE_URL));
|
||||
setAccessToken(savedInstanceState.getString(STATE_ACCESS_TOKEN));
|
||||
List<String> appliedClasses = savedInstanceState.getStringArrayList(STATE_CLASSES);
|
||||
if (!appliedClasses.isEmpty()) {
|
||||
setClasses(appliedClasses);
|
||||
List<String> appliedStyleClasses = savedInstanceState.getStringArrayList(STATE_STYLE_CLASSES);
|
||||
if (!appliedStyleClasses.isEmpty()) {
|
||||
setStyleClasses(appliedStyleClasses);
|
||||
}
|
||||
mNativeMapView.setDefaultTransitionDuration(savedInstanceState.getLong(STATE_DEFAULT_TRANSITION_DURATION));
|
||||
}
|
||||
@@ -526,7 +538,7 @@ public class MapView extends SurfaceView {
|
||||
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 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the system is running low on memory
|
||||
// Must be called from Activity onLowMemory
|
||||
public void onLowMemory() {
|
||||
mNativeMapView.onLowMemory();
|
||||
}
|
||||
|
||||
//
|
||||
// Draw events
|
||||
//
|
||||
|
||||
@@ -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 @@ class NativeMapView {
|
||||
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 @@ class NativeMapView {
|
||||
nativeResetNorth(mNativeMapViewPtr);
|
||||
}
|
||||
|
||||
public void onLowMemory() {
|
||||
nativeOnLowMemory(mNativeMapViewPtr);
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
nativeSetDebug(mNativeMapViewPtr, debug);
|
||||
}
|
||||
@@ -360,6 +372,22 @@ class NativeMapView {
|
||||
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 @@ class NativeMapView {
|
||||
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 @@ class NativeMapView {
|
||||
|
||||
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);
|
||||
|
||||
@@ -226,6 +226,14 @@ public class MainActivity extends ActionBarActivity {
|
||||
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 class MainActivity extends ActionBarActivity {
|
||||
// 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 class MainActivity extends ActionBarActivity {
|
||||
// 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 class MainActivity extends ActionBarActivity {
|
||||
// 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 class MainActivity extends ActionBarActivity {
|
||||
// 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 class MainActivity extends ActionBarActivity {
|
||||
// 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 @@ public class MainActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
ArrayList<String> classes = new ArrayList<>(1);
|
||||
ArrayList<String> 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 class MainActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
mapView.removeAllClasses();
|
||||
mapView.removeAllStyleClasses();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,25 +556,25 @@ public class MainActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
ArrayList<String> classes = new ArrayList<>(2);
|
||||
ArrayList<String> 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 class MainActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
mapView.removeAllClasses();
|
||||
mapView.removeAllStyleClasses();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 @@ private:
|
||||
int fbHeight = 0;
|
||||
const float pixelRatio;
|
||||
|
||||
int availableProcessors = 0;
|
||||
size_t totalMemory = 0;
|
||||
|
||||
// Ensure these are initialised last
|
||||
mbgl::SQLiteCache fileCache;
|
||||
mbgl::DefaultFileSource fileSource;
|
||||
|
||||
Reference in New Issue
Block a user