use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method getImage.
public Bitmap getImage(int x, int y, int zoom, long[] timeHolder) {
SQLiteConnection db = getDatabase();
if (db == null) {
return null;
}
String[] params = new String[] { x + "", y + "", getFileZoom(zoom) + "" };
byte[] blob;
try {
blob = getBytes(x, y, zoom, null, timeHolder);
} catch (IOException e) {
return null;
}
if (blob != null) {
Bitmap bmp = null;
bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
if (bmp == null) {
// broken image delete it
db.execSQL("DELETE FROM tiles WHERE x = ? AND y = ? AND z = ?", params);
}
return bmp;
}
return null;
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method getRectBoundary.
public QuadRect getRectBoundary(int coordinatesZoom, int minZ) {
SQLiteConnection db = getDatabase();
if (db == null || coordinatesZoom > 25) {
return null;
}
SQLiteCursor q;
if (inversiveZoom) {
int minZoom = (17 - minZ) + 1;
// 17 - z = zoom, x << (25 - zoom) = 25th x tile = 8 + z,
q = db.rawQuery("SELECT max(x << (8+z)), min(x << (8+z)), max(y << (8+z)), min(y << (8+z))" + " from tiles where z < " + minZoom, new String[0]);
} else {
q = db.rawQuery("SELECT max(x << (25-z)), min(x << (25-z)), max(y << (25-z)), min(y << (25-z))" + " from tiles where z > " + minZ, new String[0]);
}
q.moveToFirst();
int right = (int) (q.getInt(0) >> (25 - coordinatesZoom));
int left = (int) (q.getInt(1) >> (25 - coordinatesZoom));
int top = (int) (q.getInt(3) >> (25 - coordinatesZoom));
int bottom = (int) (q.getInt(2) >> (25 - coordinatesZoom));
return new QuadRect(left, top, right, bottom);
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method exists.
public boolean exists(int x, int y, int zoom) {
SQLiteConnection db = getDatabase();
if (db == null) {
return false;
}
try {
int z = getFileZoom(zoom);
SQLiteCursor cursor = db.rawQuery("SELECT 1 FROM tiles WHERE x = ? AND y = ? AND z = ?", // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
new String[] { x + "", y + "", z + "" });
try {
boolean e = cursor.moveToFirst();
cursor.close();
return e;
} catch (SQLiteDiskIOException e) {
return false;
}
} finally {
if (LOG.isDebugEnabled()) {
long time = System.currentTimeMillis();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
LOG.debug("Checking tile existance x = " + x + " y = " + y + " z = " + zoom + " for " + (System.currentTimeMillis() - time));
}
}
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class WikivoyageDbHelper method search.
@NonNull
public List<WikivoyageSearchResult> search(final String searchQuery) {
List<WikivoyageSearchResult> res = new ArrayList<>();
SQLiteConnection conn = openConnection();
if (conn != null) {
try {
SQLiteCursor cursor = conn.rawQuery(SEARCH_QUERY, new String[] { searchQuery + "%" });
if (cursor.moveToFirst()) {
do {
res.add(readSearchResult(cursor));
} while (cursor.moveToNext());
}
} finally {
conn.close();
}
}
List<WikivoyageSearchResult> list = new ArrayList<>(groupSearchResultsByCityId(res));
Collections.sort(list, new Comparator<WikivoyageSearchResult>() {
@Override
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
boolean c1 = CollatorStringMatcher.cmatches(collator, searchQuery, o1.articleTitles.get(0), StringMatcherMode.CHECK_ONLY_STARTS_WITH);
boolean c2 = CollatorStringMatcher.cmatches(collator, searchQuery, o2.articleTitles.get(0), StringMatcherMode.CHECK_ONLY_STARTS_WITH);
if (c1 == c2) {
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
} else if (c1) {
return -1;
} else if (c2) {
return 1;
}
return 0;
}
});
return list;
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class MapMarkersDbHelper method openConnection.
private SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
int version = conn.getVersion();
if (version == 0 || DB_VERSION != version) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
}
version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn);
} else {
onUpgrade(conn, version, DB_VERSION);
}
}
return conn;
}
Aggregations