From 7325000edb13526e7ab694aef573a6717ef26884 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Aug 2015 09:44:49 +1000 Subject: [PATCH] Check API level for totalMemory --- .../main/java/com/mapbox/mapboxgl/views/MapView.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 cd7e84cee..3b34fcca0 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 @@ -192,6 +192,7 @@ public class MapView extends FrameLayout implements LocationListener { // // Common initialization code goes here + @TargetApi(16) private void initialize(Context context, AttributeSet attrs) { // Save the context @@ -218,9 +219,12 @@ public class MapView extends FrameLayout implements LocationListener { 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); - + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + long totalMemory = memoryInfo.totalMem; + mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath, mScreenDensity, availableProcessors, totalMemory); + } else { + throw new RuntimeException("Need to implement totalMemory on pre-Jelly Bean devices."); + } // Load the attributes TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0); try { @@ -685,7 +689,7 @@ public class MapView extends FrameLayout implements LocationListener { } public void onSizeChanged(int width, int height, int oldw, int oldh) { - mNativeMapView.resizeView((int)(width / mScreenDensity), (int)(height / mScreenDensity)); + mNativeMapView.resizeView((int) (width / mScreenDensity), (int) (height / mScreenDensity)); } // This class handles SurfaceHolder callbacks