Make pixelRatio constant across a Map object lifetime

also moves framebuffer size out of TransformState into its own object
This commit is contained in:
Konstantin Käfer
2015-07-01 12:39:21 +02:00
parent 3a07cb2f1e
commit 675ddddee7
40 changed files with 308 additions and 214 deletions

View File

@@ -145,7 +145,7 @@ public class MapView extends SurfaceView {
String apkPath = context.getPackageCodePath();
// Create the NativeMapView
mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath);
mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath, mScreenDensity);
// Load the attributes
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0);
@@ -477,6 +477,10 @@ public class MapView extends SurfaceView {
mNativeMapView.resume();
}
public void onSizeChanged(int width, int height, int oldw, int oldh) {
mNativeMapView.resizeView((int)(width / mScreenDensity), (int)(height / mScreenDensity));
}
// This class handles SurfaceHolder callbacks
private class Callbacks implements SurfaceHolder.Callback {
@@ -498,9 +502,8 @@ public class MapView extends SurfaceView {
// changed
// Must handle window resizing here.
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
mNativeMapView.resize((int) (width / mScreenDensity), (int) (height / mScreenDensity), mScreenDensity, width, height);
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mNativeMapView.resizeFramebuffer(width, height);
}
}

View File

@@ -39,11 +39,11 @@ class NativeMapView {
// Constructors
//
public NativeMapView(MapView mapView, String cachePath, String dataPath, String apkPath) {
public NativeMapView(MapView mapView, String cachePath, String dataPath, String apkPath, float pixelRatio) {
mMapView = mapView;
// Create the NativeMapView
mNativeMapViewPtr = nativeCreate(cachePath, dataPath, apkPath);
mNativeMapViewPtr = nativeCreate(cachePath, dataPath, apkPath, pixelRatio);
}
//
@@ -90,8 +90,7 @@ class NativeMapView {
nativeOnInvalidate(mNativeMapViewPtr);
}
public void resize(int width, int height, float ratio, int fbWidth,
int fbHeight) {
public void resizeView(int width, int height) {
if (width < 0) {
throw new IllegalArgumentException("width cannot be negative.");
}
@@ -100,6 +99,19 @@ class NativeMapView {
throw new IllegalArgumentException("height cannot be negative.");
}
if (width > 65535) {
throw new IllegalArgumentException(
"width cannot be greater than 65535.");
}
if (height > 65535) {
throw new IllegalArgumentException(
"height cannot be greater than 65535.");
}
nativeViewResize(mNativeMapViewPtr, width, height);
}
public void resizeFramebuffer(int fbWidth, int fbHeight) {
if (fbWidth < 0) {
throw new IllegalArgumentException("fbWidth cannot be negative.");
}
@@ -117,7 +129,7 @@ class NativeMapView {
throw new IllegalArgumentException(
"fbHeight cannot be greater than 65535.");
}
nativeResize(mNativeMapViewPtr, width, height, ratio, fbWidth, fbHeight);
nativeFramebufferResize(mNativeMapViewPtr, fbWidth, fbHeight);
}
public void addClass(String clazz) {
@@ -370,7 +382,7 @@ class NativeMapView {
super.finalize();
}
private native long nativeCreate(String cachePath, String dataPath, String apkPath);
private native long nativeCreate(String cachePath, String dataPath, String apkPath, float pixelRatio);
private native void nativeDestroy(long nativeMapViewPtr);
@@ -395,8 +407,9 @@ class NativeMapView {
private native void nativeOnInvalidate(long nativeMapViewPtr);
private native void nativeResize(long nativeMapViewPtr, int width,
int height, float ratio, int fbWidth, int fbHeight);
private native void nativeViewResize(long nativeMapViewPtr, int width, int height);
private native void nativeFramebufferResize(long nativeMapViewPtr, int fbWidth, int fbHeight);
private native void nativeAddClass(long nativeMapViewPtr, String clazz);