brouter/brouter-routing-app/src/main/java/btools/routingapp/CoordinateReaderLocus.java
Manuel Fuhr 54d5c5e943 Reformat files using Android Studio
android-studio/bin/format.sh -m '*.java' -r brouter-routing-app

To rebase active branches on top of the new master just rebase your
branch onto the commit prior to the reformatting and format every commit
of your branch using (<commit> should be replaced by this commit)

git rebase \
        --strategy-option=theirs \
        --onto <commit> \
        --exec 'format.sh -m "*.java" -r brouter-routing-app' \
        --exec 'git commit --all --no-edit --amend' \
        <commit>~

To ignore this mass edit during git blame see `.git-blame-ignore-revs`
2021-11-20 16:50:23 +01:00

68 lines
2 KiB
Java

package btools.routingapp;
import java.io.File;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import btools.router.OsmNodeNamed;
/**
* Read coordinates from a gpx-file
*/
public class CoordinateReaderLocus extends CoordinateReader {
public CoordinateReaderLocus(String basedir) {
super(basedir);
tracksdir = "/Locus/mapItems";
rootdir = "/Locus";
}
@Override
public long getTimeStamp() throws Exception {
File f = new File(basedir + "/Locus/data/database/waypoints.db");
long t1 = f.lastModified();
// Android 10 delivers file size but can't read it
boolean canRead = f.canRead();
return canRead ? t1 : 0L;
}
@Override
public int getTurnInstructionMode() {
return 2; // locus style
}
/*
* read the from and to position from a ggx-file
* (with hardcoded name for now)
*/
@Override
public void readPointmap() throws Exception {
_readPointmap(basedir + "/Locus/data/database/waypoints.db");
}
private void _readPointmap(String filename) throws Exception {
SQLiteDatabase myDataBase = null;
try {
myDataBase = SQLiteDatabase.openDatabase(filename, null, SQLiteDatabase.OPEN_READONLY);
} catch (Exception e) {
// not open, do not produce an error
return;
}
Cursor c = myDataBase.rawQuery("SELECT c.name, w.name, w.longitude, w.latitude FROM waypoints w, categories c where w.parent_id = c._id", null);
if (c.getCount() == 0) {
c.close();
c = myDataBase.rawQuery("SELECT c.name, w.name, w.longitude, w.latitude FROM waypoints w, groups c where w.parent_id = c._id;", null);
}
while (c.moveToNext()) {
OsmNodeNamed n = new OsmNodeNamed();
String category = c.getString(0);
n.name = c.getString(1);
n.ilon = (int) ((c.getDouble(2) + 180.) * 1000000. + 0.5);
n.ilat = (int) ((c.getDouble(3) + 90.) * 1000000. + 0.5);
checkAddPoint(category, n);
}
c.close();
myDataBase.close();
}
}