Always fallback to CoordinateReaderInternal

This commit is contained in:
Manuel Fuhr 2021-11-07 11:12:48 +01:00
parent dc95984199
commit db77728d4c
4 changed files with 54 additions and 108 deletions

View file

@ -218,21 +218,11 @@ public class BRouterService extends Service
canAccessSdCard = false; canAccessSdCard = false;
} }
AppLogger.log( "dev/target=" + deviceLevel + "/" + targetSdkVersion + " canAccessSdCard=" + canAccessSdCard ); AppLogger.log( "dev/target=" + deviceLevel + "/" + targetSdkVersion + " canAccessSdCard=" + canAccessSdCard );
if ( canAccessSdCard )
{ CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir, canAccessSdCard, true );
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir, true );
worker.nogoList = new ArrayList<OsmNodeNamed>( cor.nogopoints ); worker.nogoList = new ArrayList<OsmNodeNamed>( cor.nogopoints );
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>(); worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
} }
else {
CoordinateReader cor = new CoordinateReaderInternal( baseDir );
cor.readFromTo();
worker.nogoList = new ArrayList<OsmNodeNamed>( cor.nogopoints );
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
}
}
private boolean fileEqual( byte[] fileBytes, File file ) throws Exception private boolean fileEqual( byte[] fileBytes, File file ) throws Exception

View file

@ -232,13 +232,7 @@ public class BRouterView extends View
canAccessSdCard = false; canAccessSdCard = false;
} }
if (canAccessSdCard) { cor = CoordinateReader.obtainValidReader(basedir, segmentDir, canAccessSdCard);
cor = CoordinateReader.obtainValidReader(basedir, segmentDir);
}
else {
cor = new CoordinateReaderInternal(basedir);
cor.readFromTo();
}
wpList = cor.waypoints; wpList = cor.waypoints;
nogoList = cor.nogopoints; nogoList = cor.nogopoints;
@ -586,7 +580,7 @@ public class BRouterView extends View
for ( int i = 0; i < wpList.size(); i++ ) for ( int i = 0; i < wpList.size(); i++ )
msg += ( i > 0 ? "->" : "" ) + wpList.get( i ).name; msg += ( i > 0 ? "->" : "" ) + wpList.get( i ).name;
} }
( (BRouterActivity) getContext() ).showResultMessage( "Select Action", msg, cor instanceof CoordinateReaderNone ? -2 : wpList.size() ); ( (BRouterActivity) getContext() ).showResultMessage( "Select Action", msg, wpList.size() );
return; return;
} }

View file

@ -149,76 +149,70 @@ public abstract class CoordinateReader
protected abstract void readPointmap() throws Exception; protected abstract void readPointmap() throws Exception;
public static CoordinateReader obtainValidReader( String basedir, File segmentDir ) throws Exception public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean canAccessSdCard ) throws Exception
{ {
return obtainValidReader( basedir, segmentDir, false ); return obtainValidReader( basedir, segmentDir, canAccessSdCard, false );
} }
public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean nogosOnly ) throws Exception public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean canAccessSdCard, boolean nogosOnly ) throws Exception
{ {
CoordinateReader cor = null; CoordinateReader cor = null;
ArrayList<CoordinateReader> rl = new ArrayList<CoordinateReader>(); ArrayList<CoordinateReader> rl = new ArrayList<CoordinateReader>();
AppLogger.log( "adding standard maptool-base: " + basedir ); if (canAccessSdCard) {
rl.add( new CoordinateReaderOsmAnd( basedir ) ); AppLogger.log("adding standard maptool-base: " + basedir);
rl.add( new CoordinateReaderLocus( basedir ) ); rl.add(new CoordinateReaderOsmAnd(basedir));
rl.add( new CoordinateReaderOrux( basedir ) ); rl.add(new CoordinateReaderLocus(basedir));
rl.add(new CoordinateReaderOrux(basedir));
// eventually add standard-sd // eventually add standard-sd
File standardbase = Environment.getExternalStorageDirectory(); File standardbase = Environment.getExternalStorageDirectory();
if ( standardbase != null ) if (standardbase != null) {
{
String base2 = standardbase.getAbsolutePath(); String base2 = standardbase.getAbsolutePath();
if ( !base2.equals( basedir ) ) if (!base2.equals(basedir)) {
{ AppLogger.log("adding internal sd maptool-base: " + base2);
AppLogger.log( "adding internal sd maptool-base: " + base2 ); rl.add(new CoordinateReaderOsmAnd(base2));
rl.add( new CoordinateReaderOsmAnd( base2 ) ); rl.add(new CoordinateReaderLocus(base2));
rl.add( new CoordinateReaderLocus( base2 ) ); rl.add(new CoordinateReaderOrux(base2));
rl.add( new CoordinateReaderOrux( base2 ) );
} }
} }
// eventually add explicit directory // eventually add explicit directory
File additional = RoutingHelper.getAdditionalMaptoolDir( segmentDir ); File additional = RoutingHelper.getAdditionalMaptoolDir(segmentDir);
if ( additional != null ) if (additional != null) {
{
String base3 = additional.getAbsolutePath(); String base3 = additional.getAbsolutePath();
AppLogger.log( "adding maptool-base from storage-config: " + base3 ); AppLogger.log("adding maptool-base from storage-config: " + base3);
rl.add( new CoordinateReaderOsmAnd( base3 ) ); rl.add(new CoordinateReaderOsmAnd(base3));
rl.add( new CoordinateReaderOsmAnd( base3, true ) ); rl.add(new CoordinateReaderOsmAnd(base3, true));
rl.add( new CoordinateReaderLocus( base3 ) ); rl.add(new CoordinateReaderLocus(base3));
rl.add( new CoordinateReaderOrux( base3 ) ); rl.add(new CoordinateReaderOrux(base3));
} }
long tmax = 0; long tmax = 0;
for ( CoordinateReader r : rl ) for (CoordinateReader r : rl) {
{ if (AppLogger.isLogging()) {
if ( AppLogger.isLogging() ) AppLogger.log("reading timestamp at systime " + new Date());
{
AppLogger.log( "reading timestamp at systime " + new Date() );
} }
long t = r.getTimeStamp(); long t = r.getTimeStamp();
if ( t != 0 ) if (t != 0) {
{ if (AppLogger.isLogging()) {
if ( AppLogger.isLogging() ) AppLogger.log("found coordinate source at " + r.basedir + r.rootdir + " with timestamp " + new Date(t));
{
AppLogger.log( "found coordinate source at " + r.basedir + r.rootdir + " with timestamp " + new Date( t ) );
} }
} }
if ( t > tmax ) if (t > tmax) {
{
tmax = t; tmax = t;
cor = r; cor = r;
} }
} }
}
if ( cor == null ) if ( cor == null )
{ {
cor = new CoordinateReaderNone(); cor = new CoordinateReaderInternal(basedir);
} }
cor.nogosOnly = nogosOnly; cor.nogosOnly = nogosOnly;
cor.readFromTo(); cor.readFromTo();

View file

@ -1,32 +0,0 @@
package btools.routingapp;
/**
* Dummy coordinate reader if none found
*/
public class CoordinateReaderNone extends CoordinateReader
{
public CoordinateReaderNone()
{
super( "" );
rootdir = "none";
}
@Override
public long getTimeStamp() throws Exception
{
return 0L;
}
@Override
public int getTurnInstructionMode()
{
return 0; // none
}
@Override
public void readPointmap() throws Exception
{
}
}