diff options
author | Tobrun <tobrun@mapbox.com> | 2016-01-14 13:49:06 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-01-14 14:21:46 +0100 |
commit | 35855889df4ba4a65f8ed19940043fdf24466acb (patch) | |
tree | 61a165ebdbc402621839a961af60d59c98cd9f8a /platform | |
parent | 1f31de288faf933d8bc9fa35588a3bac712b245d (diff) | |
download | qtlocation-mapboxgl-35855889df4ba4a65f8ed19940043fdf24466acb.tar.gz |
[android] #3461 - upgrade to okhttp3 for faster tile loading! :rocket:
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/build.gradle | 2 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java | 49 |
2 files changed, 26 insertions, 25 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index 3fed32766f..55beb8dea8 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -25,7 +25,7 @@ dependencies { compile "com.android.support:support-annotations:${supportLibVersion}" compile "com.android.support:support-v4:${supportLibVersion}" compile "com.android.support:design:${supportLibVersion}" - compile 'com.squareup.okhttp:okhttp:2.5.0' + compile 'com.squareup.okhttp3:okhttp:3.0.0' compile 'com.mapzen.android:lost:1.0.1' } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java index ee486cb65c..776a3e467a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPContext.java @@ -4,12 +4,6 @@ import android.text.TextUtils; import android.util.Log; import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.squareup.okhttp.Call; -import com.squareup.okhttp.Callback; -import com.squareup.okhttp.Interceptor; -import com.squareup.okhttp.OkHttpClient; -import com.squareup.okhttp.Request; -import com.squareup.okhttp.Response; import java.io.IOException; import java.io.InterruptedIOException; @@ -19,6 +13,13 @@ import java.net.UnknownHostException; import javax.net.ssl.SSLException; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + class HTTPContext { private static final int CONNECTION_ERROR = 0; @@ -80,23 +81,7 @@ class HTTPContext { } @Override - public void onFailure(Request request, IOException e) { - Log.w(LOG_TAG, String.format("[HTTP] Request could not be executed: %s", e.getMessage())); - - int type = PERMANENT_ERROR; - if ((e instanceof UnknownHostException) || (e instanceof SocketException) || (e instanceof ProtocolException) || (e instanceof SSLException)) { - type = CONNECTION_ERROR; - } else if ((e instanceof InterruptedIOException)) { - type = TEMPORARY_ERROR; - } else if (mCall.isCanceled()) { - type = CANCELED_ERROR; - } - - nativeOnFailure(mNativePtr, type, e.getMessage()); - } - - @Override - public void onResponse(Response response) throws IOException { + public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()) { Log.d(LOG_TAG, String.format("[HTTP] Request was successful (code = %d).", response.code())); } else { @@ -117,9 +102,25 @@ class HTTPContext { } finally { response.body().close(); } - + nativeOnResponse(mNativePtr, response.code(), response.message(), response.header("ETag"), response.header("Last-Modified"), response.header("Cache-Control"), response.header("Expires"), body); } + + @Override + public void onFailure(Call call, IOException e) { + Log.w(LOG_TAG, String.format("[HTTP] Request could not be executed: %s", e.getMessage())); + + int type = PERMANENT_ERROR; + if ((e instanceof UnknownHostException) || (e instanceof SocketException) || (e instanceof ProtocolException) || (e instanceof SSLException)) { + type = CONNECTION_ERROR; + } else if ((e instanceof InterruptedIOException)) { + type = TEMPORARY_ERROR; + } else if (mCall.isCanceled()) { + type = CANCELED_ERROR; + } + + nativeOnFailure(mNativePtr, type, e.getMessage()); + } } /* |