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;
}
AppLogger.log( "dev/target=" + deviceLevel + "/" + targetSdkVersion + " canAccessSdCard=" + canAccessSdCard );
if ( canAccessSdCard )
{
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir, true );
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir, canAccessSdCard, true );
worker.nogoList = new ArrayList<OsmNodeNamed>( cor.nogopoints );
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

View file

@ -232,13 +232,7 @@ public class BRouterView extends View
canAccessSdCard = false;
}
if (canAccessSdCard) {
cor = CoordinateReader.obtainValidReader(basedir, segmentDir);
}
else {
cor = new CoordinateReaderInternal(basedir);
cor.readFromTo();
}
cor = CoordinateReader.obtainValidReader(basedir, segmentDir, canAccessSdCard);
wpList = cor.waypoints;
nogoList = cor.nogopoints;
@ -586,7 +580,7 @@ public class BRouterView extends View
for ( int i = 0; i < wpList.size(); i++ )
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;
}

View file

@ -149,16 +149,17 @@ public abstract class CoordinateReader
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;
ArrayList<CoordinateReader> rl = new ArrayList<CoordinateReader>();
if (canAccessSdCard) {
AppLogger.log("adding standard maptool-base: " + basedir);
rl.add(new CoordinateReaderOsmAnd(basedir));
rl.add(new CoordinateReaderLocus(basedir));
@ -166,11 +167,9 @@ public abstract class CoordinateReader
// eventually add standard-sd
File standardbase = Environment.getExternalStorageDirectory();
if ( standardbase != null )
{
if (standardbase != null) {
String base2 = standardbase.getAbsolutePath();
if ( !base2.equals( basedir ) )
{
if (!base2.equals(basedir)) {
AppLogger.log("adding internal sd maptool-base: " + base2);
rl.add(new CoordinateReaderOsmAnd(base2));
rl.add(new CoordinateReaderLocus(base2));
@ -180,8 +179,7 @@ public abstract class CoordinateReader
// eventually add explicit directory
File additional = RoutingHelper.getAdditionalMaptoolDir(segmentDir);
if ( additional != null )
{
if (additional != null) {
String base3 = additional.getAbsolutePath();
AppLogger.log("adding maptool-base from storage-config: " + base3);
@ -193,32 +191,28 @@ public abstract class CoordinateReader
}
long tmax = 0;
for ( CoordinateReader r : rl )
{
if ( AppLogger.isLogging() )
{
for (CoordinateReader r : rl) {
if (AppLogger.isLogging()) {
AppLogger.log("reading timestamp at systime " + new Date());
}
long t = r.getTimeStamp();
if ( t != 0 )
{
if ( AppLogger.isLogging() )
{
if (t != 0) {
if (AppLogger.isLogging()) {
AppLogger.log("found coordinate source at " + r.basedir + r.rootdir + " with timestamp " + new Date(t));
}
}
if ( t > tmax )
{
if (t > tmax) {
tmax = t;
cor = r;
}
}
}
if ( cor == null )
{
cor = new CoordinateReaderNone();
cor = new CoordinateReaderInternal(basedir);
}
cor.nogosOnly = nogosOnly;
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
{
}
}