From 2bfafaddb1a824cbc7ec4315aac40995328cbd7c Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 25 Feb 2015 16:48:54 -0600 Subject: [PATCH] #823 - Building request method --- .../mapboxgl/lib/util/JavaFileSource.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java index 91863accfa3..f9b14179762 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java @@ -1,14 +1,22 @@ package com.mapbox.mapboxgl.lib.util; +import com.squareup.okhttp.Callback; +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; + public class JavaFileSource { private static JavaFileSource instance = null; + // Single reference to OkHttp for performance gains + private OkHttpClient client; + /** * Private Constructor to support Singleton pattern */ private JavaFileSource() { super(); + client = new OkHttpClient(); } /** @@ -21,4 +29,18 @@ public static JavaFileSource getInstance() { } return instance; } + + /** + * Make an HTTP Request + * @param resourceUrl URL to resource + * @param callback Callback class + * @return Request created + */ + public Request request(final String resourceUrl, final Callback callback) { + Request request = new Request.Builder().url(resourceUrl).build(); + + client.newCall(request).enqueue(callback); + + return request; + } }