From 0ae9950fcca86ab7c762f00191a54fd60ad753d3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 11 Aug 2013 22:38:56 +0200 Subject: [PATCH] Support different sqlite files --- .../src/net/osmand/plus/SQLiteTileSource.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java index bea830b416..0c40419cb1 100644 --- a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java +++ b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java @@ -44,6 +44,7 @@ public class SQLiteTileSource implements ITileSource { private int maxZoom = 17; private int baseZoom = 17; //Default base zoom private boolean inversiveZoom = true; // BigPlanet + private boolean timeSupported = false; static final int margin = 1; static final int tileSize = 256; @@ -161,9 +162,9 @@ public class SQLiteTileSource implements ITileSource { } } int tnumbering = list.indexOf("tilenumbering"); - boolean inversiveInfoZoom = tnumbering != -1 && "BigPlanet".equals(list.get(tnumbering)); + boolean inversiveInfoZoom = tnumbering != -1 && "BigPlanet".equals(cursor.getString(tnumbering)); if(tnumbering != -1) { - inversiveZoom = "BigPlanet".equals(list.get(tnumbering)); + inversiveZoom = "BigPlanet".equalsIgnoreCase(cursor.getString(tnumbering)); } int mnz = list.indexOf("minzoom"); if(mnz != -1) { @@ -179,10 +180,18 @@ public class SQLiteTileSource implements ITileSource { baseZoom = 17 - mnz; } } + cursor.close(); maxZoom = 24; // Cheat to have tiles request even if zoom level not in sqlite // decrease maxZoom if too much scaling would be required while ((tileSize >> (maxZoom - baseZoom)) < minScaledSize) maxZoom--; + + cursor = db.rawQuery("SELECT * FROM tiles", null); + cursor.moveToFirst(); + List cols = Arrays.asList(cursor.getColumnNames()); + timeSupported = cols.contains("time"); + cursor.close(); + } catch (RuntimeException e) { e.printStackTrace(); } @@ -407,12 +416,18 @@ public class SQLiteTileSource implements ITileSource { buf.put(b, 0, i); } - net.osmand.plus.api.SQLiteAPI.SQLiteStatement statement = db.compileStatement("INSERT INTO tiles VALUES(?, ?, ?, ?, ?)"); //$NON-NLS-1$ + + String query = timeSupported? "INSERT INTO tiles(x,y,z,s,image,time) VALUES(?, ?, ?, ?, ?, ?)" : + "INSERT INTO tiles(x,y,z,s,image) VALUES(?, ?, ?, ?, ?)"; + net.osmand.plus.api.SQLiteAPI.SQLiteStatement statement = db.compileStatement(query); //$NON-NLS-1$ statement.bindLong(1, x); statement.bindLong(2, y); statement.bindLong(3, getFileZoom(zoom)); statement.bindLong(4, 0); statement.bindBlob(5, buf.array()); + if(timeSupported) { + statement.bindLong(6, System.currentTimeMillis()); + } statement.execute(); statement.close(); is.close();