diff options
author | Antonio Zugaldia <antonio@mapbox.com> | 2016-03-07 13:32:04 -0500 |
---|---|---|
committer | Antonio Zugaldia <antonio@mapbox.com> | 2016-03-07 13:32:24 -0500 |
commit | e920a272e1c24d1e9a15ba950fd8a9702eedf07c (patch) | |
tree | f8ec7a1458b90baf5e39ff685366bce7e3600437 /platform/android | |
parent | b318903ab96f80de4e73dbbffb0f19be028b44ff (diff) | |
download | qtlocation-mapboxgl-e920a272e1c24d1e9a15ba950fd8a9702eedf07c.tar.gz |
[android] Remove GSON From Offline Example TestApp
Fixes #4172
Diffstat (limited to 'platform/android')
2 files changed, 18 insertions, 66 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java index c48bec1a90..69b967f0fa 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/OfflineActivity.java @@ -23,15 +23,15 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.offline.OfflineManager; import com.mapbox.mapboxsdk.offline.OfflineRegion; -import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; import com.mapbox.mapboxsdk.offline.OfflineRegionError; import com.mapbox.mapboxsdk.offline.OfflineRegionStatus; +import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; import com.mapbox.mapboxsdk.testapp.offline.DownloadRegionDialog; -import com.mapbox.mapboxsdk.testapp.offline.CustomMetadata; import com.mapbox.mapboxsdk.testapp.offline.ListRegionsDialog; import com.mapbox.mapboxsdk.utils.ApiAccess; -import java.io.UnsupportedEncodingException; +import org.json.JSONObject; + import java.util.ArrayList; public class OfflineActivity extends AppCompatActivity @@ -39,6 +39,10 @@ public class OfflineActivity extends AppCompatActivity private final static String LOG_TAG = "OfflineActivity"; + // JSON encoding/decoding + public final static String JSON_CHARSET = "UTF-8"; + public final static String JSON_FIELD_REGION_NAME = "FIELD_REGION_NAME"; + /* * UI elements */ @@ -220,9 +224,11 @@ public class OfflineActivity extends AppCompatActivity String regionName; try { - CustomMetadata customMetadata = CustomMetadata.decode(offlineRegion.getMetadata()); - regionName = customMetadata.getRegionName(); - } catch (UnsupportedEncodingException e) { + byte[] metadata = offlineRegion.getMetadata(); + String json = new String(metadata, JSON_CHARSET); + JSONObject jsonObject = new JSONObject(json); + regionName = jsonObject.getString(JSON_FIELD_REGION_NAME); + } catch (Exception e) { Log.e(LOG_TAG, "Failed to decode metadata: " + e.getMessage()); regionName = "Region " + offlineRegion.getID(); } @@ -256,12 +262,14 @@ public class OfflineActivity extends AppCompatActivity OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition( styleURL, bounds, minZoom, maxZoom, pixelRatio); - // Sample way of encoding metadata + // Sample way of encoding metadata from a JSONObject byte[] metadata; try { - CustomMetadata customMetadata = new CustomMetadata(regionName); - metadata = customMetadata.encode(); - } catch (UnsupportedEncodingException e) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(JSON_FIELD_REGION_NAME, regionName); + String json = jsonObject.toString(); + metadata = json.getBytes(JSON_CHARSET); + } catch (Exception e) { Log.e(LOG_TAG, "Failed to encode metadata: " + e.getMessage()); metadata = null; } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java deleted file mode 100644 index 75c5f719f5..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/offline/CustomMetadata.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.offline; - -import com.google.gson.Gson; - -import java.io.UnsupportedEncodingException; - -/** - * A custom metadata class - */ -public class CustomMetadata { - - public final static String CHARSET = "UTF-8"; - - /* - * Fields - */ - - private String regionName; - - /* - * Constructor - */ - - public CustomMetadata(String regionName) { - this.regionName = regionName; - } - - /* - * Getters/setters - */ - - public String getRegionName() { - return regionName; - } - - public void setRegionName(String regionName) { - this.regionName = regionName; - } - - /* - * Helper methods to encode/decode metadata into/from byte[] - */ - - public byte[] encode() throws UnsupportedEncodingException { - return new Gson() - .toJson(this, CustomMetadata.class) - .getBytes(CustomMetadata.CHARSET); - } - - public static CustomMetadata decode(byte[] metadata) throws UnsupportedEncodingException { - String json = new String(metadata, CustomMetadata.CHARSET); - return new Gson() - .fromJson(json, CustomMetadata.class); - } - -} |