Search in sources :

Example 1 with SQLiteCursor

use of net.osmand.plus.api.SQLiteAPI.SQLiteCursor in project Osmand by osmandapp.

the class SQLiteTileSource method hasTimeColumn.

private boolean hasTimeColumn() {
    SQLiteCursor cursor;
    cursor = db.rawQuery("SELECT * FROM tiles", null);
    cursor.moveToFirst();
    List<String> cols = Arrays.asList(cursor.getColumnNames());
    boolean timeSupported = cols.contains("time");
    cursor.close();
    return timeSupported;
}
Also used : SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 2 with SQLiteCursor

use of net.osmand.plus.api.SQLiteAPI.SQLiteCursor in project Osmand by osmandapp.

the class SQLiteTileSource method getDatabase.

protected SQLiteConnection getDatabase() {
    if ((db == null || db.isClosed()) && file.exists()) {
        LOG.debug("Open " + file.getAbsolutePath());
        try {
            onlyReadonlyAvailable = false;
            db = ctx.getSQLiteAPI().openByAbsolutePath(file.getAbsolutePath(), false);
        } catch (RuntimeException e) {
            onlyReadonlyAvailable = true;
            db = ctx.getSQLiteAPI().openByAbsolutePath(file.getAbsolutePath(), true);
        }
        try {
            SQLiteCursor cursor = db.rawQuery("SELECT * FROM info", null);
            if (cursor.moveToFirst()) {
                String[] columnNames = cursor.getColumnNames();
                List<String> list = Arrays.asList(columnNames);
                int url = list.indexOf("url");
                if (url != -1) {
                    String template = cursor.getString(url);
                    if (!Algorithms.isEmpty(template)) {
                        // urlTemplate = template;
                        urlTemplate = TileSourceTemplate.normalizeUrl(template);
                    }
                }
                int ruleId = list.indexOf("rule");
                if (ruleId != -1) {
                    rule = cursor.getString(ruleId);
                }
                int refererId = list.indexOf("referer");
                if (refererId != -1) {
                    referer = cursor.getString(refererId);
                }
                int tnumbering = list.indexOf("tilenumbering");
                if (tnumbering != -1) {
                    inversiveZoom = "BigPlanet".equalsIgnoreCase(cursor.getString(tnumbering));
                } else {
                    inversiveZoom = true;
                    addInfoColumn("tilenumbering", "BigPlanet");
                }
                int timecolumn = list.indexOf("timecolumn");
                if (timecolumn != -1) {
                    timeSupported = "yes".equalsIgnoreCase(cursor.getString(timecolumn));
                } else {
                    timeSupported = hasTimeColumn();
                    addInfoColumn("timecolumn", timeSupported ? "yes" : "no");
                }
                int expireminutes = list.indexOf("expireminutes");
                this.expirationTimeMillis = -1;
                if (expireminutes != -1) {
                    int minutes = (int) cursor.getInt(expireminutes);
                    if (minutes > 0) {
                        this.expirationTimeMillis = minutes * 60 * 1000;
                    }
                } else {
                    addInfoColumn("expireminutes", "0");
                }
                int ellipsoid = list.indexOf("ellipsoid");
                if (ellipsoid != -1) {
                    int set = (int) cursor.getInt(ellipsoid);
                    if (set == 1) {
                        this.isEllipsoid = true;
                    }
                }
                // boolean inversiveInfoZoom = tnumbering != -1 && "BigPlanet".equals(cursor.getString(tnumbering));
                boolean inversiveInfoZoom = inversiveZoom;
                int mnz = list.indexOf("minzoom");
                if (mnz != -1) {
                    minZoom = (int) cursor.getInt(mnz);
                }
                int mxz = list.indexOf("maxzoom");
                if (mxz != -1) {
                    maxZoom = (int) cursor.getInt(mxz);
                }
                if (inversiveInfoZoom) {
                    mnz = minZoom;
                    minZoom = 17 - maxZoom;
                    maxZoom = 17 - mnz;
                }
            }
            cursor.close();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }
    return db;
}
Also used : SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 3 with SQLiteCursor

use of net.osmand.plus.api.SQLiteAPI.SQLiteCursor 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);
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) QuadRect(net.osmand.data.QuadRect) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 4 with SQLiteCursor

use of net.osmand.plus.api.SQLiteAPI.SQLiteCursor 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));
        }
    }
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 5 with SQLiteCursor

use of net.osmand.plus.api.SQLiteAPI.SQLiteCursor 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;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) ArrayList(java.util.ArrayList) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) NonNull(android.support.annotation.NonNull)

Aggregations

SQLiteCursor (net.osmand.plus.api.SQLiteAPI.SQLiteCursor)15 SQLiteConnection (net.osmand.plus.api.SQLiteAPI.SQLiteConnection)12 Nullable (android.support.annotation.Nullable)3 ArrayList (java.util.ArrayList)3 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)3 LinkedHashMap (java.util.LinkedHashMap)2 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)1 NonNull (android.support.annotation.NonNull)1 HashSet (java.util.HashSet)1 FavouritePoint (net.osmand.data.FavouritePoint)1 QuadRect (net.osmand.data.QuadRect)1 MapMarkersGroup (net.osmand.plus.MapMarkersHelper.MapMarkersGroup)1