Search in sources :

Example 1 with MapGson

use of com.peterlaurence.trekadvisor.core.map.gson.MapGson in project TrekAdvisor by peterLaurence.

the class MapUpdateTask method doInBackground.

@Override
protected Void doInBackground(File... dirs) {
    /* Search for json files */
    for (File dir : dirs) {
        findMaps(dir, 1);
    }
    /* Now parse the json files found */
    for (File f : mapFilesFoundList) {
        /* Get json file content as String */
        String jsonString;
        try {
            jsonString = FileUtils.getStringFromFile(f);
        } catch (Exception e) {
            // Error while decoding the json file
            Log.e(TAG, e.getMessage(), e);
            continue;
        }
        try {
            /* json deserialization */
            MapGson mapGson = mGson.fromJson(jsonString, MapGson.class);
            /* Map creation */
            Map map = mapGson.thumbnail == null ? new Map(mapGson, f, null) : new Map(mapGson, f, new File(f.getParent(), mapGson.thumbnail));
            /* Calibration */
            map.calibrate();
            /* Set BitMapProvider */
            map.setBitmapProvider(MapLoader.makeBitmapProvider(map));
            mMapList.add(map);
        } catch (JsonSyntaxException | NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    return null;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) MapGson(com.peterlaurence.trekadvisor.core.map.gson.MapGson) File(java.io.File) Map(com.peterlaurence.trekadvisor.core.map.Map) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Map (com.peterlaurence.trekadvisor.core.map.Map)1 MapGson (com.peterlaurence.trekadvisor.core.map.gson.MapGson)1 File (java.io.File)1