diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils')
3 files changed, 20 insertions, 43 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java index 10ecf43bd3..a4352d0b1c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java @@ -3,10 +3,10 @@ package com.mapbox.mapboxsdk.testapp.utils; import android.content.Context; import android.graphics.Typeface; -import timber.log.Timber; - import java.util.Hashtable; +import timber.log.Timber; + public class FontCache { private static Hashtable<String, Typeface> fontCache = new Hashtable<>(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java index 0d21fd2c71..c21e479659 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java @@ -3,12 +3,11 @@ package com.mapbox.mapboxsdk.testapp.utils; import android.content.Context; import android.text.TextUtils; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.geometry.LatLng; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -29,34 +28,13 @@ public class GeoParseUtil { return readAll(rd); } - public static List<LatLng> parseGeoJsonCoordinates(String geojsonStr) throws JSONException { + public static List<LatLng> parseGeoJsonCoordinates(String geojsonStr) { List<LatLng> latLngs = new ArrayList<>(); - JSONObject jsonObject = new JSONObject(geojsonStr); - JSONArray features = jsonObject.getJSONArray("features"); - int featureLength = features.length(); - for (int j = 0; j < featureLength; ++j) { - JSONObject feature = features.getJSONObject(j); - JSONObject geometry = feature.getJSONObject("geometry"); - String type = geometry.getString("type"); - JSONArray coordinates; - if (type.equals("Polygon")) { - coordinates = geometry.getJSONArray("coordinates").getJSONArray(0); - } else { - coordinates = geometry.getJSONArray("coordinates"); - } - int len = coordinates.length(); - for (int i = 0; i < len; ++i) { - if (coordinates.get(i) instanceof JSONArray) { - JSONArray coord = coordinates.getJSONArray(i); - double lng = coord.getDouble(0); - double lat = coord.getDouble(1); - latLngs.add(new LatLng(lat, lng)); - } else { - double lng = coordinates.getDouble(0); - double lat = coordinates.getDouble(1); - latLngs.add(new LatLng(lat, lng)); - break; - } + FeatureCollection featureCollection = FeatureCollection.fromJson(geojsonStr); + for (Feature feature : featureCollection.features()) { + if (feature.geometry() instanceof Point) { + Point point = (Point) feature.geometry(); + latLngs.add(new LatLng(point.latitude(), point.longitude())); } } return latLngs; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/OfflineUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/OfflineUtils.java index 6220dc7e69..d4ec95ce5c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/OfflineUtils.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/OfflineUtils.java @@ -2,9 +2,10 @@ package com.mapbox.mapboxsdk.testapp.utils; import android.support.annotation.NonNull; -import timber.log.Timber; +import com.google.gson.Gson; +import com.google.gson.JsonObject; -import org.json.JSONObject; +import timber.log.Timber; import static com.mapbox.mapboxsdk.testapp.activity.offline.OfflineActivity.JSON_CHARSET; import static com.mapbox.mapboxsdk.testapp.activity.offline.OfflineActivity.JSON_FIELD_REGION_NAME; @@ -14,24 +15,22 @@ public class OfflineUtils { public static String convertRegionName(@NonNull byte[] metadata) { try { String json = new String(metadata, JSON_CHARSET); - JSONObject jsonObject = new JSONObject(json); - return jsonObject.getString(JSON_FIELD_REGION_NAME); + JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class); + return jsonObject.get(JSON_FIELD_REGION_NAME).getAsString(); } catch (Exception exception) { return null; } } public static byte[] convertRegionName(String regionName) { - byte[] metadata = null; try { - JSONObject jsonObject = new JSONObject(); - jsonObject.put(JSON_FIELD_REGION_NAME, regionName); - String json = jsonObject.toString(); - metadata = json.getBytes(JSON_CHARSET); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty(JSON_FIELD_REGION_NAME, regionName); + return jsonObject.toString().getBytes(JSON_CHARSET); } catch (Exception exception) { Timber.e(exception, "Failed to encode metadata: "); } - return metadata; + return null; } } |