From 8152e487050d39509ea6688ebd627d74304bccd5 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 25 Oct 2018 14:15:18 +0200 Subject: [PATCH] [android] - remove java 8 language features --- .../android/MapboxGLAndroidSDK/build.gradle | 5 --- .../mapboxsdk/http/LocalRequestTask.java | 22 ++++++++++--- .../mapboxsdk/http/NativeHttpRequest.java | 15 +++++---- .../java/com/mapbox/mapboxsdk/log/Logger.java | 20 +++++++++++- .../mapboxsdk/log/LoggerDefinition.java | 32 ------------------- .../com/mapbox/mapboxsdk/maps/MapView.java | 13 +++++--- .../mapboxsdk/offline/OfflineManager.java | 10 +++--- .../style/sources/CustomGeometrySource.java | 2 +- 8 files changed, 60 insertions(+), 59 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index f91df8a8a49..2e413cffd28 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -121,11 +121,6 @@ android { main.res.srcDirs += 'src/main/res-public' } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - lintOptions { disable 'MissingTranslation', 'TypographyQuotes', 'ObsoleteLintCustomCheck', 'MissingPermission', 'WrongThreadInterprocedural' checkAllWarnings true diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/LocalRequestTask.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/LocalRequestTask.java index 7884033de72..1c2ed019456 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/LocalRequestTask.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/LocalRequestTask.java @@ -39,18 +39,32 @@ protected void onPostExecute(byte[] bytes) { private static byte[] loadFile(AssetManager assets, String path) { byte[] buffer = null; - try (InputStream input = assets.open(path)) { + InputStream input = null; + try { + input = assets.open(path); int size = input.available(); buffer = new byte[size]; input.read(buffer); } catch (IOException exception) { - String message = "Load file failed"; - Logger.e(TAG, message, exception); - MapStrictMode.strictModeViolation(message, exception); + logFileError(exception); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException exception) { + logFileError(exception); + } + } } return buffer; } + private static void logFileError(Exception exception) { + String message = "Load file failed"; + Logger.e(TAG, message, exception); + MapStrictMode.strictModeViolation(message, exception); + } + public interface OnLocalRequestResponse { void onResponse(byte[] bytes); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/NativeHttpRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/NativeHttpRequest.java index 5de90b1d67e..14dbfeaee3b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/NativeHttpRequest.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/NativeHttpRequest.java @@ -58,13 +58,16 @@ public void onResponse(int responseCode, String etag, String lastModified, Strin } private void executeLocalRequest(String resourceUrl) { - new LocalRequestTask(bytes -> { - if (bytes != null) { - lock.lock(); - if (nativePtr != 0) { - nativeOnResponse(200, null, null, null, null, null, null, bytes); + new LocalRequestTask(new LocalRequestTask.OnLocalRequestResponse() { + @Override + public void onResponse(byte[] bytes) { + if (bytes != null) { + lock.lock(); + if (nativePtr != 0) { + NativeHttpRequest.this.nativeOnResponse(200, null, null, null, null, null, null, bytes); + } + lock.unlock(); } - lock.unlock(); } }).execute(resourceUrl); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/Logger.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/Logger.java index fe443b81aa4..4a262a85298 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/Logger.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/Logger.java @@ -201,6 +201,24 @@ public static void e(String tag, String msg, Throwable tr) { * @param message The message you would like logged. */ public static void log(int severity, String tag, String message) { - LoggerDefinition.log(severity, tag, message); + switch (severity) { + case Log.VERBOSE: + Logger.v(tag, message); + break; + case Log.DEBUG: + Logger.d(tag, message); + break; + case Log.INFO: + Logger.i(tag, message); + break; + case Log.WARN: + Logger.w(tag, message); + break; + case Log.ERROR: + Logger.e(tag, message); + break; + default: + throw new UnsupportedOperationException(); + } } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/LoggerDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/LoggerDefinition.java index 27de7349f8f..60b6eb00097 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/LoggerDefinition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/log/LoggerDefinition.java @@ -1,7 +1,5 @@ package com.mapbox.mapboxsdk.log; -import android.util.Log; - /** * Definition of a logger for the Mapbox Maps SDK for Android. */ @@ -101,34 +99,4 @@ public interface LoggerDefinition { * @param tr An exception to log */ void e(String tag, String msg, Throwable tr); - - /** - * Send a log message based on severity. - * - * @param severity the log severity - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param message The message you would like logged. - */ - static void log(int severity, String tag, String message) { - switch (severity) { - case Log.VERBOSE: - Logger.v(tag, message); - break; - case Log.DEBUG: - Logger.d(tag, message); - break; - case Log.INFO: - Logger.i(tag, message); - break; - case Log.WARN: - Logger.w(tag, message); - break; - case Log.ERROR: - Logger.e(tag, message); - break; - default: - throw new UnsupportedOperationException(); - } - } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 1c92b3fe0bb..240e8b628fe 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -327,11 +327,14 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) { ); // deprecated API - nativeMapView.addOnMapChangedListener(change -> { - // dispatch events to external listeners - if (!onMapChangedListeners.isEmpty()) { - for (OnMapChangedListener onMapChangedListener : onMapChangedListeners) { - onMapChangedListener.onMapChanged(change); + nativeMapView.addOnMapChangedListener(new OnMapChangedListener() { + @Override + public void onMapChanged(int change) { + // dispatch events to external listeners + if (!onMapChangedListeners.isEmpty()) { + for (OnMapChangedListener onMapChangedListener : onMapChangedListeners) { + onMapChangedListener.onMapChanged(change); + } } } }); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java index c70db4f7171..bfe50b9c61d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java @@ -237,7 +237,7 @@ public void run() { * @param callback completion/error callback */ public void mergeOfflineRegions(@NonNull String path, @NonNull final MergeOfflineRegionsCallback callback) { - File src = new File(path); + final File src = new File(path); new FileUtils.CheckFileReadPermissionTask(new FileUtils.OnCheckFileReadPermissionListener() { @Override public void onReadPermissionGranted() { @@ -329,12 +329,12 @@ private static void copyTempDatabaseFile(File sourceFile, File destFile) throws } } - private void mergeOfflineDatabaseFiles(@NonNull File file, @NonNull final MergeOfflineRegionsCallback callback, - boolean isTemporaryFile) { + private void mergeOfflineDatabaseFiles(@NonNull final File file, @NonNull final MergeOfflineRegionsCallback callback, + final boolean isTemporaryFile) { fileSource.activate(); mergeOfflineRegions(fileSource, file.getAbsolutePath(), new MergeOfflineRegionsCallback() { @Override - public void onMerge(OfflineRegion[] offlineRegions) { + public void onMerge(final OfflineRegion[] offlineRegions) { getHandler().post(new Runnable() { @Override public void run() { @@ -348,7 +348,7 @@ public void run() { } @Override - public void onError(String error) { + public void onError(final String error) { getHandler().post(new Runnable() { @Override public void run() { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java index a44d7cab1a4..8aef5bc2acb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java @@ -230,7 +230,7 @@ private void startThreads() { } executor = new ThreadPoolExecutor(THREAD_POOL_LIMIT, THREAD_POOL_LIMIT, - 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), + 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() { final AtomicInteger threadCount = new AtomicInteger(); final int poolId = poolCount.getAndIncrement();