Merge pull request #368 from zod/reformat
Reformat using Android Studio
This commit is contained in:
commit
a37ee5b3d9
19 changed files with 3034 additions and 3662 deletions
9
.git-blame-ignore-revs
Normal file
9
.git-blame-ignore-revs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Commits which should be ignored by git blame
|
||||||
|
|
||||||
|
# You have to instruct git to use this file using either
|
||||||
|
# `git blame --ignore-revs-file .git-blame-ignore-revs`
|
||||||
|
# or update you git config to always include those commits
|
||||||
|
# `git config blame.ignoreRevsFile .git-blame-ignore-revs`
|
||||||
|
|
||||||
|
# Reformat brouter-routing-app using Android Studio
|
||||||
|
54d5c5e9439be2c3df4c95b6fc12d33fdcc9b389
|
|
@ -13,37 +13,31 @@ import android.os.Environment;
|
||||||
/**
|
/**
|
||||||
* static logger interface to be used in the android app
|
* static logger interface to be used in the android app
|
||||||
*/
|
*/
|
||||||
public class AppLogger
|
public class AppLogger {
|
||||||
{
|
|
||||||
private static FileWriter debugLogWriter = null;
|
private static FileWriter debugLogWriter = null;
|
||||||
private static boolean initDone = false;
|
private static boolean initDone = false;
|
||||||
|
|
||||||
private static void init()
|
private static void init() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
// open logfile if existing
|
// open logfile if existing
|
||||||
File sd = Environment.getExternalStorageDirectory();
|
File sd = Environment.getExternalStorageDirectory();
|
||||||
if ( sd == null ) return;
|
if (sd == null) return;
|
||||||
File debugLog = new File( sd, "Android/media/btools.routingapp/brouter/brouterapp.txt" );
|
File debugLog = new File(sd, "Android/media/btools.routingapp/brouter/brouterapp.txt");
|
||||||
if ( debugLog.exists() )
|
if (debugLog.exists()) {
|
||||||
{
|
debugLogWriter = new FileWriter(debugLog, true);
|
||||||
debugLogWriter = new FileWriter( debugLog, true );
|
|
||||||
}
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
}
|
}
|
||||||
catch( IOException ioe ) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* log an info trace to the app log file, if any
|
* log an info trace to the app log file, if any
|
||||||
*/
|
*/
|
||||||
public static boolean isLogging()
|
public static boolean isLogging() {
|
||||||
{
|
if (!initDone) {
|
||||||
if ( !initDone )
|
|
||||||
{
|
|
||||||
initDone = true;
|
initDone = true;
|
||||||
init();
|
init();
|
||||||
log( "logging started at " + new Date() );
|
log("logging started at " + new Date());
|
||||||
}
|
}
|
||||||
return debugLogWriter != null;
|
return debugLogWriter != null;
|
||||||
}
|
}
|
||||||
|
@ -51,19 +45,14 @@ public class AppLogger
|
||||||
/**
|
/**
|
||||||
* log an info trace to the app log file, if any
|
* log an info trace to the app log file, if any
|
||||||
*/
|
*/
|
||||||
public static void log( String msg )
|
public static void log(String msg) {
|
||||||
{
|
if (isLogging()) {
|
||||||
if ( isLogging() )
|
try {
|
||||||
{
|
debugLogWriter.write(msg);
|
||||||
try
|
debugLogWriter.write('\n');
|
||||||
{
|
|
||||||
debugLogWriter.write( msg );
|
|
||||||
debugLogWriter.write( '\n' );
|
|
||||||
debugLogWriter.flush();
|
debugLogWriter.flush();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch( IOException e )
|
throw new RuntimeException("cannot write brouterapp.txt: " + e);
|
||||||
{
|
|
||||||
throw new RuntimeException( "cannot write brouterapp.txt: " + e );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,11 +60,10 @@ public class AppLogger
|
||||||
/**
|
/**
|
||||||
* Format an exception using
|
* Format an exception using
|
||||||
*/
|
*/
|
||||||
public static String formatThrowable( Throwable t )
|
public static String formatThrowable(Throwable t) {
|
||||||
{
|
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter( sw );
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
t.printStackTrace( pw );
|
t.printStackTrace(pw);
|
||||||
return sw.toString();
|
return sw.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,9 @@ public class BInstallerActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/**
|
||||||
|
* Called when the activity is first created.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -105,27 +107,21 @@ public class BInstallerActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
protected Dialog onCreateDialog( int id )
|
protected Dialog onCreateDialog(int id) {
|
||||||
{
|
|
||||||
AlertDialog.Builder builder;
|
AlertDialog.Builder builder;
|
||||||
switch ( id )
|
switch (id) {
|
||||||
{
|
|
||||||
case DIALOG_CONFIRM_DELETE_ID:
|
case DIALOG_CONFIRM_DELETE_ID:
|
||||||
builder = new AlertDialog.Builder( this );
|
builder = new AlertDialog.Builder(this);
|
||||||
builder
|
builder
|
||||||
.setTitle( "Confirm Delete" )
|
.setTitle("Confirm Delete")
|
||||||
.setMessage( "Really delete?" ).setPositiveButton( "Yes", new DialogInterface.OnClickListener()
|
.setMessage("Really delete?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
mBInstallerView.deleteSelectedTiles();
|
mBInstallerView.deleteSelectedTiles();
|
||||||
}
|
}
|
||||||
} ).setNegativeButton( "No", new DialogInterface.OnClickListener()
|
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -134,32 +130,28 @@ public class BInstallerActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void showConfirmDelete()
|
public void showConfirmDelete() {
|
||||||
{
|
showDialog(DIALOG_CONFIRM_DELETE_ID);
|
||||||
showDialog( DIALOG_CONFIRM_DELETE_ID );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Integer> dialogIds = new HashSet<Integer>();
|
private Set<Integer> dialogIds = new HashSet<Integer>();
|
||||||
|
|
||||||
private void showNewDialog( int id )
|
private void showNewDialog(int id) {
|
||||||
{
|
if (dialogIds.contains(Integer.valueOf(id))) {
|
||||||
if ( dialogIds.contains( Integer.valueOf( id ) ) )
|
removeDialog(id);
|
||||||
{
|
|
||||||
removeDialog( id );
|
|
||||||
}
|
}
|
||||||
dialogIds.add( Integer.valueOf( id ) );
|
dialogIds.add(Integer.valueOf(id));
|
||||||
showDialog( id );
|
showDialog(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static public long getAvailableSpace (String baseDir) {
|
static public long getAvailableSpace(String baseDir) {
|
||||||
StatFs stat = new StatFs(baseDir);
|
StatFs stat = new StatFs(baseDir);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
return stat.getAvailableBlocksLong()*stat.getBlockSizeLong();
|
return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
|
||||||
}
|
} else {
|
||||||
else {
|
return stat.getAvailableBlocks() * stat.getBlockSize();
|
||||||
return stat.getAvailableBlocks()*stat.getBlockSize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,14 +29,14 @@ import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import btools.mapaccess.PhysicalFile;
|
import btools.mapaccess.PhysicalFile;
|
||||||
import btools.mapaccess.Rd5DiffManager;
|
import btools.mapaccess.Rd5DiffManager;
|
||||||
import btools.mapaccess.Rd5DiffTool;
|
import btools.mapaccess.Rd5DiffTool;
|
||||||
import btools.router.RoutingHelper;
|
import btools.router.RoutingHelper;
|
||||||
import btools.util.ProgressListener;
|
import btools.util.ProgressListener;
|
||||||
|
|
||||||
public class BInstallerView extends View
|
public class BInstallerView extends View {
|
||||||
{
|
|
||||||
private static final int MASK_SELECTED_RD5 = 1;
|
private static final int MASK_SELECTED_RD5 = 1;
|
||||||
private static final int MASK_DELETED_RD5 = 2;
|
private static final int MASK_DELETED_RD5 = 2;
|
||||||
private static final int MASK_INSTALLED_RD5 = 4;
|
private static final int MASK_INSTALLED_RD5 = 4;
|
||||||
|
@ -86,54 +86,47 @@ public class BInstallerView extends View
|
||||||
Activity mActivity;
|
Activity mActivity;
|
||||||
|
|
||||||
|
|
||||||
protected String baseNameForTile( int tileIndex )
|
protected String baseNameForTile(int tileIndex) {
|
||||||
{
|
int lon = (tileIndex % 72) * 5 - 180;
|
||||||
int lon = (tileIndex % 72 ) * 5 - 180;
|
int lat = (tileIndex / 72) * 5 - 90;
|
||||||
int lat = (tileIndex / 72 ) * 5 - 90;
|
|
||||||
String slon = lon < 0 ? "W" + (-lon) : "E" + lon;
|
String slon = lon < 0 ? "W" + (-lon) : "E" + lon;
|
||||||
String slat = lat < 0 ? "S" + (-lat) : "N" + lat;
|
String slat = lat < 0 ? "S" + (-lat) : "N" + lat;
|
||||||
return slon + "_" + slat;
|
return slon + "_" + slat;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int gridPos2Tileindex( int ix, int iy )
|
private int gridPos2Tileindex(int ix, int iy) {
|
||||||
{
|
return (35 - iy) * 72 + (ix >= 70 ? ix - 70 : ix + 2);
|
||||||
return (35-iy)*72 + ( ix >= 70 ? ix-70: ix+2 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int tileForBaseName( String basename )
|
private int tileForBaseName(String basename) {
|
||||||
{
|
|
||||||
String uname = basename.toUpperCase(Locale.ROOT);
|
String uname = basename.toUpperCase(Locale.ROOT);
|
||||||
int idx = uname.indexOf( "_" );
|
int idx = uname.indexOf("_");
|
||||||
if ( idx < 0 ) return -1;
|
if (idx < 0) return -1;
|
||||||
String slon = uname.substring( 0, idx );
|
String slon = uname.substring(0, idx);
|
||||||
String slat = uname.substring( idx+1 );
|
String slat = uname.substring(idx + 1);
|
||||||
int ilon = slon.charAt(0) == 'W' ? -Integer.parseInt( slon.substring(1) ) :
|
int ilon = slon.charAt(0) == 'W' ? -Integer.parseInt(slon.substring(1)) :
|
||||||
( slon.charAt(0) == 'E' ? Integer.parseInt( slon.substring(1) ) : -1 );
|
(slon.charAt(0) == 'E' ? Integer.parseInt(slon.substring(1)) : -1);
|
||||||
int ilat = slat.charAt(0) == 'S' ? -Integer.parseInt( slat.substring(1) ) :
|
int ilat = slat.charAt(0) == 'S' ? -Integer.parseInt(slat.substring(1)) :
|
||||||
( slat.charAt(0) == 'N' ? Integer.parseInt( slat.substring(1) ) : -1 );
|
(slat.charAt(0) == 'N' ? Integer.parseInt(slat.substring(1)) : -1);
|
||||||
if ( ilon < -180 || ilon >= 180 || ilon % 5 != 0 ) return -1;
|
if (ilon < -180 || ilon >= 180 || ilon % 5 != 0) return -1;
|
||||||
if ( ilat < - 90 || ilat >= 90 || ilat % 5 != 0 ) return -1;
|
if (ilat < -90 || ilat >= 90 || ilat % 5 != 0) return -1;
|
||||||
return (ilon+180) / 5 + 72*((ilat+90)/5);
|
return (ilon + 180) / 5 + 72 * ((ilat + 90) / 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isDownloadCanceled()
|
public boolean isDownloadCanceled() {
|
||||||
{
|
|
||||||
return downloadCanceled;
|
return downloadCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleDownload()
|
private void toggleDownload() {
|
||||||
{
|
if (isDownloading) {
|
||||||
if ( isDownloading )
|
|
||||||
{
|
|
||||||
downloadCanceled = true;
|
downloadCanceled = true;
|
||||||
downloadAction = "Canceling...";
|
downloadAction = "Canceling...";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( delTiles > 0 )
|
if (delTiles > 0) {
|
||||||
{
|
((BInstallerActivity) getContext()).showConfirmDelete();
|
||||||
( (BInstallerActivity) getContext() ).showConfirmDelete();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,17 +135,13 @@ public class BInstallerView extends View
|
||||||
|
|
||||||
ArrayList<Integer> downloadList = new ArrayList<>();
|
ArrayList<Integer> downloadList = new ArrayList<>();
|
||||||
// prepare download list
|
// prepare download list
|
||||||
for( int ix=0; ix<72; ix++ )
|
for (int ix = 0; ix < 72; ix++) {
|
||||||
{
|
for (int iy = 0; iy < 36; iy++) {
|
||||||
for( int iy=0; iy<36; iy++ )
|
int tidx = gridPos2Tileindex(ix, iy);
|
||||||
{
|
if ((tileStatus[tidx] & MASK_SELECTED_RD5) != 0) {
|
||||||
int tidx = gridPos2Tileindex( ix, iy );
|
|
||||||
if ( ( tileStatus[tidx] & MASK_SELECTED_RD5 ) != 0 )
|
|
||||||
{
|
|
||||||
int tilesize = BInstallerSizes.getRd5Size(tidx);
|
int tilesize = BInstallerSizes.getRd5Size(tidx);
|
||||||
downloadList.add(tidx);
|
downloadList.add(tidx);
|
||||||
if ( tilesize > 0 && tilesize < min_size )
|
if (tilesize > 0 && tilesize < min_size) {
|
||||||
{
|
|
||||||
tidx_min = tidx;
|
tidx_min = tidx;
|
||||||
min_size = tilesize;
|
min_size = tilesize;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +149,7 @@ public class BInstallerView extends View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadList.size()>0) {
|
if (downloadList.size() > 0) {
|
||||||
isDownloading = true;
|
isDownloading = true;
|
||||||
downloadAll(downloadList);
|
downloadAll(downloadList);
|
||||||
for (Integer i : downloadList) {
|
for (Integer i : downloadList) {
|
||||||
|
@ -172,8 +161,8 @@ public class BInstallerView extends View
|
||||||
|
|
||||||
private void downloadAll(ArrayList<Integer> downloadList) {
|
private void downloadAll(ArrayList<Integer> downloadList) {
|
||||||
ArrayList<String> urlparts = new ArrayList<>();
|
ArrayList<String> urlparts = new ArrayList<>();
|
||||||
for (Integer i: downloadList) {
|
for (Integer i : downloadList) {
|
||||||
urlparts.add(baseNameForTile( i.intValue() ));
|
urlparts.add(baseNameForTile(i.intValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
currentDownloadOperation = "Start download ...";
|
currentDownloadOperation = "Start download ...";
|
||||||
|
@ -184,7 +173,7 @@ public class BInstallerView extends View
|
||||||
//final DownloadBackground downloadTask = new DownloadBackground(getContext(), urlparts, baseDir);
|
//final DownloadBackground downloadTask = new DownloadBackground(getContext(), urlparts, baseDir);
|
||||||
//downloadTask.execute( );
|
//downloadTask.execute( );
|
||||||
Intent intent = new Intent(mActivity, DownloadService.class);
|
Intent intent = new Intent(mActivity, DownloadService.class);
|
||||||
intent.putExtra("dir", baseDir.getAbsolutePath()+"/brouter/");
|
intent.putExtra("dir", baseDir.getAbsolutePath() + "/brouter/");
|
||||||
intent.putExtra("urlparts", urlparts);
|
intent.putExtra("urlparts", urlparts);
|
||||||
mActivity.startService(intent);
|
mActivity.startService(intent);
|
||||||
|
|
||||||
|
@ -192,11 +181,9 @@ public class BInstallerView extends View
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void downloadDone( boolean success )
|
public void downloadDone(boolean success) {
|
||||||
{
|
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
if ( success )
|
if (success) {
|
||||||
{
|
|
||||||
scanExistingFiles();
|
scanExistingFiles();
|
||||||
toggleDownload(); // keep on if no error
|
toggleDownload(); // keep on if no error
|
||||||
}
|
}
|
||||||
|
@ -213,85 +200,71 @@ public class BInstallerView extends View
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int tileIndex( float x, float y )
|
private int tileIndex(float x, float y) {
|
||||||
{
|
int ix = (int) (72.f * x / bmp.getWidth());
|
||||||
int ix = (int)(72.f * x / bmp.getWidth());
|
int iy = (int) (36.f * y / bmp.getHeight());
|
||||||
int iy = (int)(36.f * y / bmp.getHeight());
|
if (ix >= 0 && ix < 72 && iy >= 0 && iy < 36) return gridPos2Tileindex(ix, iy);
|
||||||
if ( ix >= 0 && ix < 72 && iy >= 0 && iy < 36 ) return gridPos2Tileindex(ix, iy);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearTileSelection( int mask )
|
private void clearTileSelection(int mask) {
|
||||||
{
|
|
||||||
// clear selection if zooming out
|
// clear selection if zooming out
|
||||||
for( int ix=0; ix<72; ix++ )
|
for (int ix = 0; ix < 72; ix++)
|
||||||
for( int iy=0; iy<36; iy++ )
|
for (int iy = 0; iy < 36; iy++) {
|
||||||
{
|
int tidx = gridPos2Tileindex(ix, iy);
|
||||||
int tidx = gridPos2Tileindex( ix, iy );
|
|
||||||
tileStatus[tidx] ^= tileStatus[tidx] & mask;
|
tileStatus[tidx] ^= tileStatus[tidx] & mask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get back the current image scale
|
// get back the current image scale
|
||||||
private float currentScale()
|
private float currentScale() {
|
||||||
{
|
|
||||||
testVector[1] = 1.f;
|
testVector[1] = 1.f;
|
||||||
mat.mapVectors(testVector);
|
mat.mapVectors(testVector);
|
||||||
return testVector[1] / viewscale;
|
return testVector[1] / viewscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteRawTracks()
|
private void deleteRawTracks() {
|
||||||
{
|
File modeDir = new File(baseDir, "brouter/modes");
|
||||||
File modeDir = new File( baseDir, "brouter/modes" );
|
|
||||||
String[] fileNames = modeDir.list();
|
String[] fileNames = modeDir.list();
|
||||||
if ( fileNames == null ) return;
|
if (fileNames == null) return;
|
||||||
for( String fileName : fileNames )
|
for (String fileName : fileNames) {
|
||||||
{
|
if (fileName.endsWith("_rawtrack.dat")) {
|
||||||
if ( fileName.endsWith( "_rawtrack.dat" ) )
|
File f = new File(modeDir, fileName);
|
||||||
{
|
|
||||||
File f = new File( modeDir, fileName );
|
|
||||||
f.delete();
|
f.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanExistingFiles()
|
private void scanExistingFiles() {
|
||||||
{
|
clearTileSelection(MASK_INSTALLED_RD5 | MASK_CURRENT_RD5);
|
||||||
clearTileSelection( MASK_INSTALLED_RD5 | MASK_CURRENT_RD5 );
|
|
||||||
|
|
||||||
scanExistingFiles( new File( baseDir, "brouter/segments4" ) );
|
scanExistingFiles(new File(baseDir, "brouter/segments4"));
|
||||||
|
|
||||||
File secondary = RoutingHelper.getSecondarySegmentDir( new File ( baseDir, "brouter/segments4" ) );
|
File secondary = RoutingHelper.getSecondarySegmentDir(new File(baseDir, "brouter/segments4"));
|
||||||
if ( secondary != null )
|
if (secondary != null) {
|
||||||
{
|
scanExistingFiles(secondary);
|
||||||
scanExistingFiles( secondary );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
availableSize = -1;
|
availableSize = -1;
|
||||||
try
|
try {
|
||||||
{
|
availableSize = (long) ((BInstallerActivity) getContext()).getAvailableSpace(baseDir.getAbsolutePath());
|
||||||
availableSize = (long)((BInstallerActivity)getContext()).getAvailableSpace(baseDir.getAbsolutePath ());
|
|
||||||
//StatFs stat = new StatFs(baseDir.getAbsolutePath ());
|
//StatFs stat = new StatFs(baseDir.getAbsolutePath ());
|
||||||
//availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong();
|
//availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong();
|
||||||
}
|
} catch (Exception e) { /* ignore */ }
|
||||||
catch (Exception e) { /* ignore */ }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanExistingFiles( File dir )
|
private void scanExistingFiles(File dir) {
|
||||||
{
|
|
||||||
String[] fileNames = dir.list();
|
String[] fileNames = dir.list();
|
||||||
if ( fileNames == null ) return;
|
if (fileNames == null) return;
|
||||||
String suffix = ".rd5";
|
String suffix = ".rd5";
|
||||||
for( String fileName : fileNames )
|
for (String fileName : fileNames) {
|
||||||
{
|
if (fileName.endsWith(suffix)) {
|
||||||
if ( fileName.endsWith( suffix ) )
|
String basename = fileName.substring(0, fileName.length() - suffix.length());
|
||||||
{
|
int tidx = tileForBaseName(basename);
|
||||||
String basename = fileName.substring( 0, fileName.length() - suffix.length() );
|
|
||||||
int tidx = tileForBaseName( basename );
|
|
||||||
tileStatus[tidx] |= MASK_INSTALLED_RD5;
|
tileStatus[tidx] |= MASK_INSTALLED_RD5;
|
||||||
|
|
||||||
long age = System.currentTimeMillis() - new File( dir, fileName ).lastModified();
|
long age = System.currentTimeMillis() - new File(dir, fileName).lastModified();
|
||||||
if ( age < 10800000 ) tileStatus[tidx] |= MASK_CURRENT_RD5; // 3 hours
|
if (age < 10800000) tileStatus[tidx] |= MASK_CURRENT_RD5; // 3 hours
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,30 +274,27 @@ public class BInstallerView extends View
|
||||||
|
|
||||||
public void startInstaller() {
|
public void startInstaller() {
|
||||||
|
|
||||||
baseDir = ConfigHelper.getBaseDir( getContext() );
|
baseDir = ConfigHelper.getBaseDir(getContext());
|
||||||
segmentDir = new File( baseDir, "brouter/segments4");
|
segmentDir = new File(baseDir, "brouter/segments4");
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
AssetManager assetManager = getContext().getAssets();
|
AssetManager assetManager = getContext().getAssets();
|
||||||
InputStream istr = assetManager.open("world.png");
|
InputStream istr = assetManager.open("world.png");
|
||||||
bmp = BitmapFactory.decodeStream(istr);
|
bmp = BitmapFactory.decodeStream(istr);
|
||||||
istr.close();
|
istr.close();
|
||||||
}
|
} catch (IOException io) {
|
||||||
catch( IOException io )
|
throw new RuntimeException("cannot read world.png from assets");
|
||||||
{
|
|
||||||
throw new RuntimeException( "cannot read world.png from assets" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tileStatus = new int[72*36];
|
tileStatus = new int[72 * 36];
|
||||||
scanExistingFiles();
|
scanExistingFiles();
|
||||||
|
|
||||||
float scaleX = imgwOrig / ((float)bmp.getWidth());
|
float scaleX = imgwOrig / ((float) bmp.getWidth());
|
||||||
float scaley = imghOrig / ((float)bmp.getHeight());
|
float scaley = imghOrig / ((float) bmp.getHeight());
|
||||||
|
|
||||||
viewscale = scaleX < scaley ? scaleX : scaley;
|
viewscale = scaleX < scaley ? scaleX : scaley;
|
||||||
|
|
||||||
mat = new Matrix();
|
mat = new Matrix();
|
||||||
mat.postScale( viewscale, viewscale );
|
mat.postScale(viewscale, viewscale);
|
||||||
tilesVisible = false;
|
tilesVisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +303,7 @@ public class BInstallerView extends View
|
||||||
mActivity = (Activity) context;
|
mActivity = (Activity) context;
|
||||||
|
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
imgwOrig = metrics.widthPixels;
|
imgwOrig = metrics.widthPixels;
|
||||||
imghOrig = metrics.heightPixels;
|
imghOrig = metrics.heightPixels;
|
||||||
int im = imgwOrig > imghOrig ? imgwOrig : imghOrig;
|
int im = imgwOrig > imghOrig ? imgwOrig : imghOrig;
|
||||||
|
@ -341,10 +311,10 @@ public class BInstallerView extends View
|
||||||
scaleOrig = im / 480.f;
|
scaleOrig = im / 480.f;
|
||||||
|
|
||||||
matText = new Matrix();
|
matText = new Matrix();
|
||||||
matText.preScale( scaleOrig, scaleOrig );
|
matText.preScale(scaleOrig, scaleOrig);
|
||||||
|
|
||||||
imgw = (int)(imgwOrig / scaleOrig);
|
imgw = (int) (imgwOrig / scaleOrig);
|
||||||
imgh = (int)(imghOrig / scaleOrig);
|
imgh = (int) (imghOrig / scaleOrig);
|
||||||
|
|
||||||
totalSize = 0;
|
totalSize = 0;
|
||||||
rd5Tiles = 0;
|
rd5Tiles = 0;
|
||||||
|
@ -353,21 +323,18 @@ public class BInstallerView extends View
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
super.onSizeChanged(w,h,oldw,oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toast( String msg )
|
private void toast(String msg) {
|
||||||
{
|
Toast.makeText(getContext(), msg, Toast.LENGTH_LONG).show();
|
||||||
Toast.makeText(getContext(), msg, Toast.LENGTH_LONG ).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas)
|
protected void onDraw(Canvas canvas) {
|
||||||
{
|
if (!isDownloading) {
|
||||||
if ( !isDownloading )
|
canvas.setMatrix(mat);
|
||||||
{
|
canvas.drawBitmap(bmp, 0, 0, null);
|
||||||
canvas.setMatrix( mat );
|
|
||||||
canvas.drawBitmap(bmp, 0,0, null);
|
|
||||||
}
|
}
|
||||||
// draw 5*5 lattice starting at scale=3
|
// draw 5*5 lattice starting at scale=3
|
||||||
|
|
||||||
|
@ -378,20 +345,17 @@ public class BInstallerView extends View
|
||||||
|
|
||||||
boolean drawGrid = tilesVisible && !isDownloading;
|
boolean drawGrid = tilesVisible && !isDownloading;
|
||||||
|
|
||||||
if ( drawGrid )
|
if (drawGrid) {
|
||||||
{
|
|
||||||
|
|
||||||
pnt_1.setColor(Color.GREEN);
|
pnt_1.setColor(Color.GREEN);
|
||||||
|
|
||||||
for( int ix=1; ix<72; ix++ )
|
for (int ix = 1; ix < 72; ix++) {
|
||||||
{
|
float fx = fw * ix;
|
||||||
float fx = fw*ix;
|
canvas.drawLine(fx, 0, fx, ih, pnt_1);
|
||||||
canvas.drawLine( fx, 0, fx, ih, pnt_1);
|
|
||||||
}
|
}
|
||||||
for( int iy=1; iy<36; iy++ )
|
for (int iy = 1; iy < 36; iy++) {
|
||||||
{
|
float fy = fh * iy;
|
||||||
float fy = fh*iy;
|
canvas.drawLine(0, fy, iw, fy, pnt_1);
|
||||||
canvas.drawLine( 0, fy, iw, fy, pnt_1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rd5Tiles = 0;
|
rd5Tiles = 0;
|
||||||
|
@ -402,65 +366,61 @@ public class BInstallerView extends View
|
||||||
|
|
||||||
pnt_2.setColor(Color.GRAY);
|
pnt_2.setColor(Color.GRAY);
|
||||||
pnt_2.setStrokeWidth(1);
|
pnt_2.setStrokeWidth(1);
|
||||||
drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5, mask3, false, false, drawGrid );
|
drawSelectedTiles(canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5, mask3, false, false, drawGrid);
|
||||||
pnt_2.setColor(Color.BLUE);
|
pnt_2.setColor(Color.BLUE);
|
||||||
pnt_2.setStrokeWidth(1);
|
pnt_2.setStrokeWidth(1);
|
||||||
drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5 | MASK_CURRENT_RD5, mask3, false, false, drawGrid );
|
drawSelectedTiles(canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5 | MASK_CURRENT_RD5, mask3, false, false, drawGrid);
|
||||||
pnt_2.setColor(Color.GREEN);
|
pnt_2.setColor(Color.GREEN);
|
||||||
pnt_2.setStrokeWidth(2);
|
pnt_2.setStrokeWidth(2);
|
||||||
drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5, mask2, true, false, drawGrid );
|
drawSelectedTiles(canvas, pnt_2, fw, fh, MASK_SELECTED_RD5, mask2, true, false, drawGrid);
|
||||||
pnt_2.setColor(Color.YELLOW);
|
pnt_2.setColor(Color.YELLOW);
|
||||||
pnt_2.setStrokeWidth(2);
|
pnt_2.setStrokeWidth(2);
|
||||||
drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5 | MASK_INSTALLED_RD5, mask2, true, false, drawGrid );
|
drawSelectedTiles(canvas, pnt_2, fw, fh, MASK_SELECTED_RD5 | MASK_INSTALLED_RD5, mask2, true, false, drawGrid);
|
||||||
pnt_2.setColor(Color.RED);
|
pnt_2.setColor(Color.RED);
|
||||||
pnt_2.setStrokeWidth(2);
|
pnt_2.setStrokeWidth(2);
|
||||||
drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_DELETED_RD5 | MASK_INSTALLED_RD5, mask2, false, true, drawGrid );
|
drawSelectedTiles(canvas, pnt_2, fw, fh, MASK_DELETED_RD5 | MASK_INSTALLED_RD5, mask2, false, true, drawGrid);
|
||||||
|
|
||||||
canvas.setMatrix( matText );
|
canvas.setMatrix(matText);
|
||||||
|
|
||||||
paint.setColor(Color.RED);
|
paint.setColor(Color.RED);
|
||||||
|
|
||||||
long mb = 1024*1024;
|
long mb = 1024 * 1024;
|
||||||
|
|
||||||
if ( isDownloading )
|
if (isDownloading) {
|
||||||
{
|
String sizeHint = currentDownloadSize > 0 ? " (" + ((currentDownloadSize + mb - 1) / mb) + " MB)" : "";
|
||||||
String sizeHint = currentDownloadSize > 0 ? " (" + ((currentDownloadSize + mb-1)/mb) + " MB)" : "";
|
|
||||||
paint.setTextSize(30);
|
paint.setTextSize(30);
|
||||||
canvas.drawText( currentDownloadOperation, 30, (imgh/3)*2-30, paint);
|
canvas.drawText(currentDownloadOperation, 30, (imgh / 3) * 2 - 30, paint);
|
||||||
// canvas.drawText( currentDownloadOperation + " " + currentDownloadFile + sizeHint, 30, (imgh/3)*2-30, paint);
|
// canvas.drawText( currentDownloadOperation + " " + currentDownloadFile + sizeHint, 30, (imgh/3)*2-30, paint);
|
||||||
canvas.drawText( downloadAction, 30, (imgh/3)*2, paint);
|
canvas.drawText(downloadAction, 30, (imgh / 3) * 2, paint);
|
||||||
}
|
}
|
||||||
if ( !tilesVisible && !isDownloading)
|
if (!tilesVisible && !isDownloading) {
|
||||||
{
|
|
||||||
paint.setTextSize(35);
|
paint.setTextSize(35);
|
||||||
canvas.drawText( "Touch region to zoom in!", 30, (imgh/3)*2, paint);
|
canvas.drawText("Touch region to zoom in!", 30, (imgh / 3) * 2, paint);
|
||||||
}
|
}
|
||||||
paint.setTextSize(20);
|
paint.setTextSize(20);
|
||||||
|
|
||||||
|
|
||||||
|
String totmb = ((totalSize + mb - 1) / mb) + " MB";
|
||||||
String totmb = ((totalSize + mb-1)/mb) + " MB";
|
String freemb = availableSize >= 0 ? ((availableSize + mb - 1) / mb) + " MB" : "?";
|
||||||
String freemb = availableSize >= 0 ? ((availableSize + mb-1)/mb) + " MB" : "?";
|
canvas.drawText("Selected segments=" + rd5Tiles, 10, 25, paint);
|
||||||
canvas.drawText( "Selected segments=" + rd5Tiles, 10, 25, paint );
|
canvas.drawText("Size=" + totmb + " Free=" + freemb, 10, 45, paint);
|
||||||
canvas.drawText( "Size=" + totmb + " Free=" + freemb , 10, 45, paint );
|
|
||||||
|
|
||||||
|
|
||||||
String btnText = null;
|
String btnText = null;
|
||||||
if ( isDownloading ) btnText = "Cancel Download";
|
if (isDownloading) btnText = "Cancel Download";
|
||||||
else if ( delTiles > 0 ) btnText = "Delete " + delTiles + " tiles";
|
else if (delTiles > 0) btnText = "Delete " + delTiles + " tiles";
|
||||||
else if ( rd5Tiles > 0 ) btnText = "Start Download";
|
else if (rd5Tiles > 0) btnText = "Start Download";
|
||||||
else if ( tilesVisible &&
|
else if (tilesVisible &&
|
||||||
rd5Tiles == 0 &&
|
rd5Tiles == 0 &&
|
||||||
RoutingHelper.hasDirectoryAnyDatafiles( segmentDir )) btnText = "Update all";
|
RoutingHelper.hasDirectoryAnyDatafiles(segmentDir)) btnText = "Update all";
|
||||||
|
|
||||||
if ( btnText != null )
|
if (btnText != null) {
|
||||||
{
|
canvas.drawLine(imgw - btnw, imgh - btnh, imgw - btnw, imgh - 2, paint);
|
||||||
canvas.drawLine( imgw-btnw, imgh-btnh, imgw-btnw, imgh-2, paint);
|
canvas.drawLine(imgw - btnw, imgh - btnh, imgw - 2, imgh - btnh, paint);
|
||||||
canvas.drawLine( imgw-btnw, imgh-btnh, imgw-2, imgh-btnh, paint);
|
canvas.drawLine(imgw - btnw, imgh - btnh, imgw - btnw, imgh - 2, paint);
|
||||||
canvas.drawLine( imgw-btnw, imgh-btnh, imgw-btnw, imgh-2, paint);
|
canvas.drawLine(imgw - 2, imgh - btnh, imgw - 2, imgh - 2, paint);
|
||||||
canvas.drawLine( imgw-2, imgh-btnh, imgw-2, imgh-2, paint);
|
canvas.drawLine(imgw - btnw, imgh - 2, imgw - 2, imgh - 2, paint);
|
||||||
canvas.drawLine( imgw-btnw, imgh-2, imgw-2, imgh-2, paint);
|
canvas.drawText(btnText, imgw - btnw + 5, imgh - 10, paint);
|
||||||
canvas.drawText( btnText , imgw-btnw+5, imgh-10, paint );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,55 +428,45 @@ public class BInstallerView extends View
|
||||||
int btnw = 160;
|
int btnw = 160;
|
||||||
|
|
||||||
|
|
||||||
float tx, ty;
|
float tx, ty;
|
||||||
|
|
||||||
private void drawSelectedTiles( Canvas canvas, Paint pnt, float fw, float fh, int status, int mask, boolean doCount, boolean cntDel, boolean doDraw )
|
private void drawSelectedTiles(Canvas canvas, Paint pnt, float fw, float fh, int status, int mask, boolean doCount, boolean cntDel, boolean doDraw) {
|
||||||
{
|
for (int ix = 0; ix < 72; ix++)
|
||||||
for ( int ix = 0; ix < 72; ix++ )
|
for (int iy = 0; iy < 36; iy++) {
|
||||||
for ( int iy = 0; iy < 36; iy++ )
|
int tidx = gridPos2Tileindex(ix, iy);
|
||||||
{
|
if ((tileStatus[tidx] & mask) == status) {
|
||||||
int tidx = gridPos2Tileindex( ix, iy );
|
int tilesize = BInstallerSizes.getRd5Size(tidx);
|
||||||
if ( ( tileStatus[tidx] & mask ) == status )
|
if (tilesize > 0) {
|
||||||
{
|
if (doCount) {
|
||||||
int tilesize = BInstallerSizes.getRd5Size( tidx );
|
|
||||||
if ( tilesize > 0 )
|
|
||||||
{
|
|
||||||
if ( doCount )
|
|
||||||
{
|
|
||||||
rd5Tiles++;
|
rd5Tiles++;
|
||||||
totalSize += BInstallerSizes.getRd5Size( tidx );
|
totalSize += BInstallerSizes.getRd5Size(tidx);
|
||||||
}
|
}
|
||||||
if ( cntDel )
|
if (cntDel) {
|
||||||
{
|
|
||||||
delTiles++;
|
delTiles++;
|
||||||
totalSize += BInstallerSizes.getRd5Size( tidx );
|
totalSize += BInstallerSizes.getRd5Size(tidx);
|
||||||
}
|
}
|
||||||
if ( !doDraw )
|
if (!doDraw)
|
||||||
continue;
|
continue;
|
||||||
// draw cross
|
// draw cross
|
||||||
canvas.drawLine( fw * ix, fh * iy, fw * ( ix + 1 ), fh * ( iy + 1 ), pnt );
|
canvas.drawLine(fw * ix, fh * iy, fw * (ix + 1), fh * (iy + 1), pnt);
|
||||||
canvas.drawLine( fw * ix, fh * ( iy + 1 ), fw * ( ix + 1 ), fh * iy, pnt );
|
canvas.drawLine(fw * ix, fh * (iy + 1), fw * (ix + 1), fh * iy, pnt);
|
||||||
|
|
||||||
// draw frame
|
// draw frame
|
||||||
canvas.drawLine( fw * ix, fh * iy, fw * ( ix + 1 ), fh * iy, pnt );
|
canvas.drawLine(fw * ix, fh * iy, fw * (ix + 1), fh * iy, pnt);
|
||||||
canvas.drawLine( fw * ix, fh * ( iy + 1 ), fw * ( ix + 1 ), fh * ( iy + 1 ), pnt );
|
canvas.drawLine(fw * ix, fh * (iy + 1), fw * (ix + 1), fh * (iy + 1), pnt);
|
||||||
canvas.drawLine( fw * ix, fh * iy, fw * ix, fh * ( iy + 1 ), pnt );
|
canvas.drawLine(fw * ix, fh * iy, fw * ix, fh * (iy + 1), pnt);
|
||||||
canvas.drawLine( fw * ( ix + 1 ), fh * iy, fw * ( ix + 1 ), fh * ( iy + 1 ), pnt );
|
canvas.drawLine(fw * (ix + 1), fh * iy, fw * (ix + 1), fh * (iy + 1), pnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteSelectedTiles()
|
public void deleteSelectedTiles() {
|
||||||
{
|
for (int ix = 0; ix < 72; ix++) {
|
||||||
for ( int ix = 0; ix < 72; ix++ )
|
for (int iy = 0; iy < 36; iy++) {
|
||||||
{
|
int tidx = gridPos2Tileindex(ix, iy);
|
||||||
for ( int iy = 0; iy < 36; iy++ )
|
if ((tileStatus[tidx] & MASK_DELETED_RD5) != 0) {
|
||||||
{
|
new File(baseDir, "brouter/segments4/" + baseNameForTile(tidx) + ".rd5").delete();
|
||||||
int tidx = gridPos2Tileindex( ix, iy );
|
|
||||||
if ( ( tileStatus[tidx] & MASK_DELETED_RD5 ) != 0 )
|
|
||||||
{
|
|
||||||
new File( baseDir, "brouter/segments4/" + baseNameForTile( tidx ) + ".rd5").delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -547,54 +497,52 @@ float tx, ty;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_MOVE: { // a pointer was moved
|
case MotionEvent.ACTION_MOVE: { // a pointer was moved
|
||||||
|
|
||||||
if ( isDownloading ) break;
|
if (isDownloading) break;
|
||||||
int np = event.getPointerCount();
|
int np = event.getPointerCount();
|
||||||
int nh = event.getHistorySize();
|
int nh = event.getHistorySize();
|
||||||
if ( nh == 0 ) break;
|
if (nh == 0) break;
|
||||||
|
|
||||||
float x0 = event.getX( 0 );
|
float x0 = event.getX(0);
|
||||||
float y0 = event.getY( 0 );
|
float y0 = event.getY(0);
|
||||||
float hx0 = event.getHistoricalX(0,0);
|
float hx0 = event.getHistoricalX(0, 0);
|
||||||
float hy0 = event.getHistoricalY(0,0);
|
float hy0 = event.getHistoricalY(0, 0);
|
||||||
|
|
||||||
if ( np > 1 ) // multi-touch
|
if (np > 1) // multi-touch
|
||||||
{
|
{
|
||||||
float x1 = event.getX( 1 );
|
float x1 = event.getX(1);
|
||||||
float y1 = event.getY( 1 );
|
float y1 = event.getY(1);
|
||||||
float hx1 = event.getHistoricalX(1,0);
|
float hx1 = event.getHistoricalX(1, 0);
|
||||||
float hy1 = event.getHistoricalY(1,0);
|
float hy1 = event.getHistoricalY(1, 0);
|
||||||
|
|
||||||
float r = (float)Math.sqrt( (x1-x0)*(x1-x0) + (y1-y0)*(y1-y0) );
|
float r = (float) Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
|
||||||
float hr = (float)Math.sqrt( (hx1-hx0)*(hx1-hx0) + (hy1-hy0)*(hy1-hy0) );
|
float hr = (float) Math.sqrt((hx1 - hx0) * (hx1 - hx0) + (hy1 - hy0) * (hy1 - hy0));
|
||||||
|
|
||||||
if ( hr > 0. )
|
if (hr > 0.) {
|
||||||
{
|
float ratio = r / hr;
|
||||||
float ratio = r/hr;
|
|
||||||
|
|
||||||
float mx = (x1+x0)/2.f;
|
float mx = (x1 + x0) / 2.f;
|
||||||
float my = (y1+y0)/2.f;
|
float my = (y1 + y0) / 2.f;
|
||||||
|
|
||||||
float scale = currentScale();
|
float scale = currentScale();
|
||||||
float newscale = scale*ratio;
|
float newscale = scale * ratio;
|
||||||
|
|
||||||
if ( newscale > 10.f ) ratio *= (10.f / newscale );
|
if (newscale > 10.f) ratio *= (10.f / newscale);
|
||||||
if ( newscale < 0.5f ) ratio *= (0.5f / newscale );
|
if (newscale < 0.5f) ratio *= (0.5f / newscale);
|
||||||
|
|
||||||
mat.postScale( ratio, ratio, mx, my );
|
mat.postScale(ratio, ratio, mx, my);
|
||||||
|
|
||||||
mat.postScale( ratio, ratio, mx, my );
|
mat.postScale(ratio, ratio, mx, my);
|
||||||
|
|
||||||
boolean tilesv = currentScale() >= 3.f;
|
boolean tilesv = currentScale() >= 3.f;
|
||||||
if ( tilesVisible && !tilesv )
|
if (tilesVisible && !tilesv) {
|
||||||
{
|
clearTileSelection(MASK_SELECTED_RD5 | MASK_DELETED_RD5);
|
||||||
clearTileSelection( MASK_SELECTED_RD5 | MASK_DELETED_RD5 );
|
|
||||||
}
|
}
|
||||||
tilesVisible = tilesv;
|
tilesVisible = tilesv;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mat.postTranslate( x0-hx0, y0-hy0 );
|
mat.postTranslate(x0 - hx0, y0 - hy0);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -602,27 +550,22 @@ float tx, ty;
|
||||||
|
|
||||||
long downTime = event.getEventTime() - event.getDownTime();
|
long downTime = event.getEventTime() - event.getDownTime();
|
||||||
|
|
||||||
if ( downTime < 5 || downTime > 500 )
|
if (downTime < 5 || downTime > 500) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Math.abs(lastDownX - event.getX() ) > 10 || Math.abs(lastDownY - event.getY() ) > 10 )
|
if (Math.abs(lastDownX - event.getX()) > 10 || Math.abs(lastDownY - event.getY()) > 10) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// download button?
|
// download button?
|
||||||
if ( ( delTiles > 0 || rd5Tiles >= 0 || isDownloading ) && event.getX() > imgwOrig - btnw*scaleOrig && event.getY() > imghOrig-btnh*scaleOrig )
|
if ((delTiles > 0 || rd5Tiles >= 0 || isDownloading) && event.getX() > imgwOrig - btnw * scaleOrig && event.getY() > imghOrig - btnh * scaleOrig) {
|
||||||
{
|
|
||||||
if (rd5Tiles == 0) {
|
if (rd5Tiles == 0) {
|
||||||
for ( int ix = 0; ix < 72; ix++ )
|
for (int ix = 0; ix < 72; ix++) {
|
||||||
{
|
for (int iy = 0; iy < 36; iy++) {
|
||||||
for ( int iy = 0; iy < 36; iy++ )
|
int tidx = gridPos2Tileindex(ix, iy);
|
||||||
{
|
|
||||||
int tidx = gridPos2Tileindex( ix, iy );
|
|
||||||
if (tidx != -1) {
|
if (tidx != -1) {
|
||||||
if ( ( tileStatus[tidx] & MASK_INSTALLED_RD5 ) != 0 ) {
|
if ((tileStatus[tidx] & MASK_INSTALLED_RD5) != 0) {
|
||||||
tileStatus[tidx] |= MASK_SELECTED_RD5;
|
tileStatus[tidx] |= MASK_SELECTED_RD5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,45 +578,35 @@ float tx, ty;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !tilesVisible )
|
if (!tilesVisible) {
|
||||||
{
|
|
||||||
float scale = currentScale();
|
float scale = currentScale();
|
||||||
if ( scale > 0f && scale < 5f )
|
if (scale > 0f && scale < 5f) {
|
||||||
{
|
|
||||||
float ratio = 5f / scale;
|
float ratio = 5f / scale;
|
||||||
mat.postScale( ratio, ratio, event.getX(), event.getY() );
|
mat.postScale(ratio, ratio, event.getX(), event.getY());
|
||||||
tilesVisible = true;
|
tilesVisible = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isDownloading ) break;
|
if (isDownloading) break;
|
||||||
|
|
||||||
Matrix imat = new Matrix();
|
Matrix imat = new Matrix();
|
||||||
if ( mat.invert(imat) )
|
if (mat.invert(imat)) {
|
||||||
{
|
|
||||||
float[] touchpoint = new float[2];
|
float[] touchpoint = new float[2];
|
||||||
touchpoint[0] = event.getX();
|
touchpoint[0] = event.getX();
|
||||||
touchpoint[1] = event.getY();
|
touchpoint[1] = event.getY();
|
||||||
imat.mapPoints(touchpoint);
|
imat.mapPoints(touchpoint);
|
||||||
|
|
||||||
int tidx = tileIndex( touchpoint[0], touchpoint[1] );
|
int tidx = tileIndex(touchpoint[0], touchpoint[1]);
|
||||||
if ( tidx != -1 )
|
if (tidx != -1) {
|
||||||
{
|
if ((tileStatus[tidx] & MASK_SELECTED_RD5) != 0) {
|
||||||
if ( ( tileStatus[tidx] & MASK_SELECTED_RD5 ) != 0 )
|
|
||||||
{
|
|
||||||
tileStatus[tidx] ^= MASK_SELECTED_RD5;
|
tileStatus[tidx] ^= MASK_SELECTED_RD5;
|
||||||
if ( ( tileStatus[tidx] & MASK_INSTALLED_RD5 ) != 0 )
|
if ((tileStatus[tidx] & MASK_INSTALLED_RD5) != 0) {
|
||||||
{
|
|
||||||
tileStatus[tidx] |= MASK_DELETED_RD5;
|
tileStatus[tidx] |= MASK_DELETED_RD5;
|
||||||
}
|
}
|
||||||
}
|
} else if ((tileStatus[tidx] & MASK_DELETED_RD5) != 0) {
|
||||||
else if ( ( tileStatus[tidx] & MASK_DELETED_RD5 ) != 0 )
|
|
||||||
{
|
|
||||||
tileStatus[tidx] ^= MASK_DELETED_RD5;
|
tileStatus[tidx] ^= MASK_DELETED_RD5;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
tileStatus[tidx] ^= MASK_SELECTED_RD5;
|
tileStatus[tidx] ^= MASK_SELECTED_RD5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -696,5 +629,4 @@ float tx, ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,68 +63,61 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
private PowerManager mPowerManager;
|
private PowerManager mPowerManager;
|
||||||
private WakeLock mWakeLock;
|
private WakeLock mWakeLock;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/**
|
||||||
|
* Called when the activity is first created.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void onCreate( Bundle savedInstanceState )
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
{
|
super.onCreate(savedInstanceState);
|
||||||
super.onCreate( savedInstanceState );
|
|
||||||
|
|
||||||
// Get an instance of the PowerManager
|
// Get an instance of the PowerManager
|
||||||
mPowerManager = (PowerManager) getSystemService( POWER_SERVICE );
|
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
|
|
||||||
// Create a bright wake lock
|
// Create a bright wake lock
|
||||||
mWakeLock = mPowerManager.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName() );
|
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());
|
||||||
|
|
||||||
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
||||||
int memoryClass = am.getMemoryClass();
|
int memoryClass = am.getMemoryClass();
|
||||||
|
|
||||||
// instantiate our simulation view and set it as the activity's content
|
// instantiate our simulation view and set it as the activity's content
|
||||||
mBRouterView = new BRouterView( this, memoryClass );
|
mBRouterView = new BRouterView(this, memoryClass);
|
||||||
mBRouterView.init();
|
mBRouterView.init();
|
||||||
setContentView( mBRouterView );
|
setContentView(mBRouterView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
protected Dialog onCreateDialog( int id )
|
protected Dialog onCreateDialog(int id) {
|
||||||
{
|
|
||||||
AlertDialog.Builder builder;
|
AlertDialog.Builder builder;
|
||||||
builder = new AlertDialog.Builder( this );
|
builder = new AlertDialog.Builder(this);
|
||||||
builder.setCancelable(false);
|
builder.setCancelable(false);
|
||||||
|
|
||||||
switch ( id )
|
switch (id) {
|
||||||
{
|
|
||||||
case DIALOG_SELECTPROFILE_ID:
|
case DIALOG_SELECTPROFILE_ID:
|
||||||
builder.setTitle( "Select a routing profile" );
|
builder.setTitle("Select a routing profile");
|
||||||
builder.setItems( availableProfiles, new DialogInterface.OnClickListener()
|
builder.setItems(availableProfiles, new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
public void onClick( DialogInterface dialog, int item )
|
|
||||||
{
|
|
||||||
selectedProfile = availableProfiles[item];
|
selectedProfile = availableProfiles[item];
|
||||||
mBRouterView.startProcessing( selectedProfile );
|
mBRouterView.startProcessing(selectedProfile);
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_MAINACTION_ID:
|
case DIALOG_MAINACTION_ID:
|
||||||
builder.setTitle( "Select Main Action" );
|
builder.setTitle("Select Main Action");
|
||||||
builder
|
builder
|
||||||
.setItems( new String[]
|
.setItems(new String[]
|
||||||
{ "Download Manager", "BRouter App" }, new DialogInterface.OnClickListener()
|
{"Download Manager", "BRouter App"}, new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
public void onClick( DialogInterface dialog, int item )
|
if (item == 0)
|
||||||
{
|
|
||||||
if ( item == 0 )
|
|
||||||
startDownloadManager();
|
startDownloadManager();
|
||||||
else
|
else
|
||||||
showDialog( DIALOG_SELECTPROFILE_ID );
|
showDialog(DIALOG_SELECTPROFILE_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.setNegativeButton( "Close", new DialogInterface.OnClickListener()
|
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,29 +125,25 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SHOW_DM_INFO_ID:
|
case DIALOG_SHOW_DM_INFO_ID:
|
||||||
builder
|
builder
|
||||||
.setTitle( "BRouter Download Manager" )
|
.setTitle("BRouter Download Manager")
|
||||||
.setMessage(
|
.setMessage(
|
||||||
"*** Attention: ***\n\n" + "The Download Manager is used to download routing-data "
|
"*** Attention: ***\n\n" + "The Download Manager is used to download routing-data "
|
||||||
+ "files which can be up to 170MB each. Do not start the Download Manager " + "on a cellular data connection without a data plan! "
|
+ "files which can be up to 170MB each. Do not start the Download Manager " + "on a cellular data connection without a data plan! "
|
||||||
+ "Download speed is restricted to 4 MBit/s." ).setPositiveButton( "I know", new DialogInterface.OnClickListener()
|
+ "Download speed is restricted to 4 MBit/s.").setPositiveButton("I know", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
Intent intent = new Intent(BRouterActivity.this, BInstallerActivity.class);
|
||||||
{
|
startActivity(intent);
|
||||||
Intent intent = new Intent( BRouterActivity.this, BInstallerActivity.class );
|
|
||||||
startActivity( intent );
|
|
||||||
// finish();
|
// finish();
|
||||||
}
|
}
|
||||||
} ).setNegativeButton( "Cancel", new DialogInterface.OnClickListener()
|
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SHOW_WP_HELP_ID:
|
case DIALOG_SHOW_WP_HELP_ID:
|
||||||
builder
|
builder
|
||||||
.setTitle( "No Waypoint Database found" )
|
.setTitle("No Waypoint Database found")
|
||||||
.setMessage(
|
.setMessage(
|
||||||
"The simple scan did not find any map-tool directory including a waypoint database. "
|
"The simple scan did not find any map-tool directory including a waypoint database. "
|
||||||
+ "Reason could be there is no map-tool installed (osmand, locus or oruxmaps), or at an "
|
+ "Reason could be there is no map-tool installed (osmand, locus or oruxmaps), or at an "
|
||||||
|
@ -163,23 +152,19 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
+ "configure the profile mapping. But you will not be able to use nogo-points or do "
|
+ "configure the profile mapping. But you will not be able to use nogo-points or do "
|
||||||
+ "long distance calculations. If you know the path to your map-tool, you can manually "
|
+ "long distance calculations. If you know the path to your map-tool, you can manually "
|
||||||
+ "configure it in 'storageconfig.txt'. Or I can do an extended scan searching "
|
+ "configure it in 'storageconfig.txt'. Or I can do an extended scan searching "
|
||||||
+ "your sd-card for a valid waypoint database" ).setPositiveButton( "Scan", new DialogInterface.OnClickListener()
|
+ "your sd-card for a valid waypoint database").setPositiveButton("Scan", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
mBRouterView.startWpDatabaseScan();
|
mBRouterView.startWpDatabaseScan();
|
||||||
}
|
}
|
||||||
} ).setNegativeButton( "Exit", new DialogInterface.OnClickListener()
|
}).setNegativeButton("Exit", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SHOW_API23_HELP_ID:
|
case DIALOG_SHOW_API23_HELP_ID:
|
||||||
builder
|
builder
|
||||||
.setTitle( "Android >=6 limitations" )
|
.setTitle("Android >=6 limitations")
|
||||||
.setMessage(
|
.setMessage(
|
||||||
"You are using the BRouter APP on Android >= 6, where classic mode is no longer supported. "
|
"You are using the BRouter APP on Android >= 6, where classic mode is no longer supported. "
|
||||||
+ "Reason is that security policy does not permit any longer to read the waypoint databases of other apps. "
|
+ "Reason is that security policy does not permit any longer to read the waypoint databases of other apps. "
|
||||||
|
@ -191,240 +176,186 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
+ "very long distance calculations. If you want to get classic mode back, you can manually install "
|
+ "very long distance calculations. If you want to get classic mode back, you can manually install "
|
||||||
+ "the APK of the BRouter App from the release page ( http://brouter.de/brouter/revisions.html ), which "
|
+ "the APK of the BRouter App from the release page ( http://brouter.de/brouter/revisions.html ), which "
|
||||||
+ "is still built against Android API 10, and does not have these limitations. "
|
+ "is still built against Android API 10, and does not have these limitations. "
|
||||||
).setNegativeButton( "Exit", new DialogInterface.OnClickListener()
|
).setNegativeButton("Exit", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID:
|
case DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID:
|
||||||
builder
|
builder
|
||||||
.setTitle( "Successfully prepared a timeout-free calculation" )
|
.setTitle("Successfully prepared a timeout-free calculation")
|
||||||
.setMessage(
|
.setMessage(
|
||||||
"You successfully repeated a calculation that previously run into a timeout "
|
"You successfully repeated a calculation that previously run into a timeout "
|
||||||
+ "when started from your map-tool. If you repeat the same request from your "
|
+ "when started from your map-tool. If you repeat the same request from your "
|
||||||
+ "maptool, with the exact same destination point and a close-by starting point, "
|
+ "maptool, with the exact same destination point and a close-by starting point, "
|
||||||
+ "this request is guaranteed not to time out." ).setNegativeButton( "Exit", new DialogInterface.OnClickListener()
|
+ "this request is guaranteed not to time out.").setNegativeButton("Exit", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SHOW_WP_SCANRESULT_ID:
|
case DIALOG_SHOW_WP_SCANRESULT_ID:
|
||||||
builder
|
builder
|
||||||
.setTitle( "Waypoint Database " )
|
.setTitle("Waypoint Database ")
|
||||||
.setMessage( "Found Waypoint-Database(s) for maptool-dir: " + maptoolDirCandidate
|
.setMessage("Found Waypoint-Database(s) for maptool-dir: " + maptoolDirCandidate
|
||||||
+ " Configure that?" ).setPositiveButton( "Yes", new DialogInterface.OnClickListener()
|
+ " Configure that?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
mBRouterView.saveMaptoolDir(maptoolDirCandidate);
|
||||||
{
|
|
||||||
mBRouterView.saveMaptoolDir( maptoolDirCandidate );
|
|
||||||
}
|
}
|
||||||
} ).setNegativeButton( "No", new DialogInterface.OnClickListener()
|
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_OLDDATAHINT_ID:
|
case DIALOG_OLDDATAHINT_ID:
|
||||||
builder
|
builder
|
||||||
.setTitle( "Local setup needs reset" )
|
.setTitle("Local setup needs reset")
|
||||||
.setMessage(
|
.setMessage(
|
||||||
"You are currently using an old version of the lookup-table " + "together with routing data made for this old table. "
|
"You are currently using an old version of the lookup-table " + "together with routing data made for this old table. "
|
||||||
+ "Before downloading new datafiles made for the new table, "
|
+ "Before downloading new datafiles made for the new table, "
|
||||||
+ "you have to reset your local setup by 'moving away' (or deleting) "
|
+ "you have to reset your local setup by 'moving away' (or deleting) "
|
||||||
+ "your <basedir>/brouter directory and start a new setup by calling the " + "BRouter App again." )
|
+ "your <basedir>/brouter directory and start a new setup by calling the " + "BRouter App again.")
|
||||||
.setPositiveButton( "OK", new DialogInterface.OnClickListener()
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_ROUTINGMODES_ID:
|
case DIALOG_ROUTINGMODES_ID:
|
||||||
builder.setTitle( message );
|
builder.setTitle(message);
|
||||||
builder.setMultiChoiceItems( routingModes, routingModesChecked, new DialogInterface.OnMultiChoiceClickListener()
|
builder.setMultiChoiceItems(routingModes, routingModesChecked, new DialogInterface.OnMultiChoiceClickListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick( DialogInterface dialog, int which, boolean isChecked )
|
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||||
{
|
|
||||||
routingModesChecked[which] = isChecked;
|
routingModesChecked[which] = isChecked;
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
builder.setPositiveButton( "Ok", new DialogInterface.OnClickListener()
|
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
public void onClick( DialogInterface dialog, int whichButton )
|
mBRouterView.configureService(routingModes, routingModesChecked);
|
||||||
{
|
|
||||||
mBRouterView.configureService( routingModes, routingModesChecked );
|
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_EXCEPTION_ID:
|
case DIALOG_EXCEPTION_ID:
|
||||||
builder.setTitle( "An Error occured" ).setMessage( errorMessage ).setPositiveButton( "OK", new DialogInterface.OnClickListener()
|
builder.setTitle("An Error occured").setMessage(errorMessage).setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
mBRouterView.continueProcessing();
|
mBRouterView.continueProcessing();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_TEXTENTRY_ID:
|
case DIALOG_TEXTENTRY_ID:
|
||||||
builder.setTitle( "Enter SDCARD base dir:" );
|
builder.setTitle("Enter SDCARD base dir:");
|
||||||
builder.setMessage( message );
|
builder.setMessage(message);
|
||||||
final EditText input = new EditText( this );
|
final EditText input = new EditText(this);
|
||||||
input.setText( defaultbasedir );
|
input.setText(defaultbasedir);
|
||||||
builder.setView( input );
|
builder.setView(input);
|
||||||
builder.setPositiveButton( "Ok", new DialogInterface.OnClickListener()
|
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
public void onClick( DialogInterface dialog, int whichButton )
|
|
||||||
{
|
|
||||||
String basedir = input.getText().toString();
|
String basedir = input.getText().toString();
|
||||||
mBRouterView.startSetup( new File(basedir), true );
|
mBRouterView.startSetup(new File(basedir), true);
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SELECTBASEDIR_ID:
|
case DIALOG_SELECTBASEDIR_ID:
|
||||||
builder.setTitle( "Choose brouter data base dir:" );
|
builder.setTitle("Choose brouter data base dir:");
|
||||||
// builder.setMessage( message );
|
// builder.setMessage( message );
|
||||||
builder.setSingleChoiceItems( basedirOptions, 0, new DialogInterface.OnClickListener()
|
builder.setSingleChoiceItems(basedirOptions, 0, new DialogInterface.OnClickListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick( DialogInterface dialog, int item )
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
{
|
|
||||||
selectedBasedir = item;
|
selectedBasedir = item;
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
builder.setPositiveButton( "Ok", new DialogInterface.OnClickListener()
|
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
public void onClick( DialogInterface dialog, int whichButton )
|
if (selectedBasedir < availableBasedirs.size()) {
|
||||||
{
|
mBRouterView.startSetup(availableBasedirs.get(selectedBasedir), true);
|
||||||
if ( selectedBasedir < availableBasedirs.size() )
|
} else {
|
||||||
{
|
showDialog(DIALOG_TEXTENTRY_ID);
|
||||||
mBRouterView.startSetup( availableBasedirs.get( selectedBasedir ), true );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
showDialog( DIALOG_TEXTENTRY_ID );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_VIASELECT_ID:
|
case DIALOG_VIASELECT_ID:
|
||||||
builder.setTitle( "Check VIA Selection:" );
|
builder.setTitle("Check VIA Selection:");
|
||||||
builder.setMultiChoiceItems( availableVias, getCheckedBooleanArray( availableVias.length ), new DialogInterface.OnMultiChoiceClickListener()
|
builder.setMultiChoiceItems(availableVias, getCheckedBooleanArray(availableVias.length), new DialogInterface.OnMultiChoiceClickListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick( DialogInterface dialog, int which, boolean isChecked )
|
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||||
{
|
if (isChecked) {
|
||||||
if ( isChecked )
|
selectedVias.add(availableVias[which]);
|
||||||
{
|
} else {
|
||||||
selectedVias.add( availableVias[which] );
|
selectedVias.remove(availableVias[which]);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selectedVias.remove( availableVias[which] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
builder.setPositiveButton( "Ok", new DialogInterface.OnClickListener()
|
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
public void onClick( DialogInterface dialog, int whichButton )
|
mBRouterView.updateViaList(selectedVias);
|
||||||
{
|
mBRouterView.startProcessing(selectedProfile);
|
||||||
mBRouterView.updateViaList( selectedVias );
|
|
||||||
mBRouterView.startProcessing( selectedProfile );
|
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_NOGOSELECT_ID:
|
case DIALOG_NOGOSELECT_ID:
|
||||||
builder.setTitle( "Check NoGo Selection:" );
|
builder.setTitle("Check NoGo Selection:");
|
||||||
String[] nogoNames = new String[nogoList.size()];
|
String[] nogoNames = new String[nogoList.size()];
|
||||||
for ( int i = 0; i < nogoList.size(); i++ )
|
for (int i = 0; i < nogoList.size(); i++)
|
||||||
nogoNames[i] = nogoList.get( i ).name;
|
nogoNames[i] = nogoList.get(i).name;
|
||||||
final boolean[] nogoEnabled = getCheckedBooleanArray( nogoList.size() );
|
final boolean[] nogoEnabled = getCheckedBooleanArray(nogoList.size());
|
||||||
builder.setMultiChoiceItems( nogoNames, getCheckedBooleanArray( nogoNames.length ), new DialogInterface.OnMultiChoiceClickListener()
|
builder.setMultiChoiceItems(nogoNames, getCheckedBooleanArray(nogoNames.length), new DialogInterface.OnMultiChoiceClickListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick( DialogInterface dialog, int which, boolean isChecked )
|
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||||
{
|
|
||||||
nogoEnabled[which] = isChecked;
|
nogoEnabled[which] = isChecked;
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
builder.setPositiveButton( "Ok", new DialogInterface.OnClickListener()
|
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
public void onClick( DialogInterface dialog, int whichButton )
|
mBRouterView.updateNogoList(nogoEnabled);
|
||||||
{
|
mBRouterView.startProcessing(selectedProfile);
|
||||||
mBRouterView.updateNogoList( nogoEnabled );
|
|
||||||
mBRouterView.startProcessing( selectedProfile );
|
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SHOWRESULT_ID:
|
case DIALOG_SHOWRESULT_ID:
|
||||||
String leftLabel = wpCount < 0 ? ( wpCount != -2 ? "Exit" : "Help") : ( wpCount == 0 ? "Select from" : "Select to/via" );
|
String leftLabel = wpCount < 0 ? (wpCount != -2 ? "Exit" : "Help") : (wpCount == 0 ? "Select from" : "Select to/via");
|
||||||
String rightLabel = wpCount < 2 ? ( wpCount == -3 ? "Help" : "Server-Mode" ) : "Calc Route";
|
String rightLabel = wpCount < 2 ? (wpCount == -3 ? "Help" : "Server-Mode") : "Calc Route";
|
||||||
|
|
||||||
builder.setTitle( title ).setMessage( errorMessage ).setPositiveButton( leftLabel, new DialogInterface.OnClickListener()
|
builder.setTitle(title).setMessage(errorMessage).setPositiveButton(leftLabel, new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
if (wpCount == -2) {
|
||||||
{
|
|
||||||
if ( wpCount == -2 )
|
|
||||||
{
|
|
||||||
showWaypointDatabaseHelp();
|
showWaypointDatabaseHelp();
|
||||||
}
|
} else if (wpCount == -1 || wpCount == -3) {
|
||||||
else if ( wpCount == -1 || wpCount == -3 )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mBRouterView.pickWaypoints();
|
mBRouterView.pickWaypoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ).setNegativeButton( rightLabel, new DialogInterface.OnClickListener()
|
}).setNegativeButton(rightLabel, new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
if (wpCount == -3) {
|
||||||
{
|
|
||||||
if ( wpCount == -3 )
|
|
||||||
{
|
|
||||||
showRepeatTimeoutHelp();
|
showRepeatTimeoutHelp();
|
||||||
}
|
} else if (wpCount < 2) {
|
||||||
else if ( wpCount < 2 )
|
|
||||||
{
|
|
||||||
mBRouterView.startConfigureService();
|
mBRouterView.startConfigureService();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mBRouterView.finishWaypointSelection();
|
mBRouterView.finishWaypointSelection();
|
||||||
mBRouterView.startProcessing( selectedProfile );
|
mBRouterView.startProcessing(selectedProfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_MODECONFIGOVERVIEW_ID:
|
case DIALOG_MODECONFIGOVERVIEW_ID:
|
||||||
builder.setTitle( "Success" ).setMessage( message ).setPositiveButton( "Exit", new DialogInterface.OnClickListener()
|
builder.setTitle("Success").setMessage(message).setPositiveButton("Exit", new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick( DialogInterface dialog, int id )
|
|
||||||
{
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_PICKWAYPOINT_ID:
|
case DIALOG_PICKWAYPOINT_ID:
|
||||||
builder.setTitle( wpCount > 0 ? "Select to/via" : "Select from" );
|
builder.setTitle(wpCount > 0 ? "Select to/via" : "Select from");
|
||||||
builder.setItems( availableWaypoints, new DialogInterface.OnClickListener()
|
builder.setItems(availableWaypoints, new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
public void onClick( DialogInterface dialog, int item )
|
mBRouterView.updateWaypointList(availableWaypoints[item]);
|
||||||
{
|
mBRouterView.startProcessing(selectedProfile);
|
||||||
mBRouterView.updateWaypointList( availableWaypoints[item] );
|
|
||||||
mBRouterView.startProcessing( selectedProfile );
|
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -432,10 +363,9 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean[] getCheckedBooleanArray( int size )
|
private boolean[] getCheckedBooleanArray(int size) {
|
||||||
{
|
|
||||||
boolean[] checked = new boolean[size];
|
boolean[] checked = new boolean[size];
|
||||||
for ( int i = 0; i < checked.length; i++ ) checked[i] = true;
|
for (int i = 0; i < checked.length; i++) checked[i] = true;
|
||||||
return checked;
|
return checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,18 +391,17 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
|
|
||||||
private String maptoolDirCandidate;
|
private String maptoolDirCandidate;
|
||||||
|
|
||||||
public boolean isOnline(Context context)
|
public boolean isOnline(Context context) {
|
||||||
{
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
Network nw = connectivityManager.getActiveNetwork();
|
Network nw = connectivityManager.getActiveNetwork();
|
||||||
if (nw == null) return false;
|
if (nw == null) return false;
|
||||||
NetworkCapabilities nwc = connectivityManager.getNetworkCapabilities(nw);
|
NetworkCapabilities nwc = connectivityManager.getNetworkCapabilities(nw);
|
||||||
if (nwc == null)return false;
|
if (nwc == null) return false;
|
||||||
result = nwc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) |
|
result = nwc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) |
|
||||||
nwc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) |
|
nwc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) |
|
||||||
nwc.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) ;
|
nwc.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
|
NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
|
||||||
|
@ -486,51 +415,39 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void selectProfile( String[] items )
|
public void selectProfile(String[] items) {
|
||||||
{
|
|
||||||
availableProfiles = items;
|
availableProfiles = items;
|
||||||
|
|
||||||
// if we have internet access, first show the main action dialog
|
// if we have internet access, first show the main action dialog
|
||||||
if ( isOnline(this) )
|
if (isOnline(this)) {
|
||||||
{
|
showDialog(DIALOG_MAINACTION_ID);
|
||||||
showDialog( DIALOG_MAINACTION_ID );
|
} else {
|
||||||
}
|
showDialog(DIALOG_SELECTPROFILE_ID);
|
||||||
else
|
|
||||||
{
|
|
||||||
showDialog( DIALOG_SELECTPROFILE_ID );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void startDownloadManager()
|
public void startDownloadManager() {
|
||||||
{
|
if (!mBRouterView.hasUpToDateLookups()) {
|
||||||
if ( !mBRouterView.hasUpToDateLookups() )
|
showDialog(DIALOG_OLDDATAHINT_ID);
|
||||||
{
|
} else {
|
||||||
showDialog( DIALOG_OLDDATAHINT_ID );
|
showDialog(DIALOG_SHOW_DM_INFO_ID);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
showDialog( DIALOG_SHOW_DM_INFO_ID );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void selectBasedir( ArrayList<File> items, String defaultBasedir, String message )
|
public void selectBasedir(ArrayList<File> items, String defaultBasedir, String message) {
|
||||||
{
|
|
||||||
this.defaultbasedir = defaultBasedir;
|
this.defaultbasedir = defaultBasedir;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
availableBasedirs = items;
|
availableBasedirs = items;
|
||||||
ArrayList<Long> dirFreeSizes = new ArrayList<Long>();
|
ArrayList<Long> dirFreeSizes = new ArrayList<Long>();
|
||||||
for ( File f : items )
|
for (File f : items) {
|
||||||
{
|
|
||||||
long size = 0L;
|
long size = 0L;
|
||||||
try
|
try {
|
||||||
{
|
StatFs stat = new StatFs(f.getAbsolutePath());
|
||||||
StatFs stat = new StatFs( f.getAbsolutePath() );
|
|
||||||
size = (long) stat.getAvailableBlocks() * stat.getBlockSize();
|
size = (long) stat.getAvailableBlocks() * stat.getBlockSize();
|
||||||
}
|
} catch (Exception e) { /* ignore */ }
|
||||||
catch (Exception e) { /* ignore */ }
|
dirFreeSizes.add(Long.valueOf(size));
|
||||||
dirFreeSizes.add( Long.valueOf( size ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
@ -540,94 +457,80 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdidx = 0;
|
int bdidx = 0;
|
||||||
DecimalFormat df = new DecimalFormat( "###0.00" );
|
DecimalFormat df = new DecimalFormat("###0.00");
|
||||||
for ( int idx = 0; idx < availableBasedirs.size(); idx++ )
|
for (int idx = 0; idx < availableBasedirs.size(); idx++) {
|
||||||
{
|
basedirOptions[bdidx++] = availableBasedirs.get(idx) + " (" + df.format(dirFreeSizes.get(idx) / 1024. / 1024. / 1024.) + " GB free)";
|
||||||
basedirOptions[bdidx++] = availableBasedirs.get( idx ) + " (" + df.format( dirFreeSizes.get( idx ) / 1024. / 1024. / 1024. ) + " GB free)";
|
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
basedirOptions[bdidx] = "Enter path manually";
|
basedirOptions[bdidx] = "Enter path manually";
|
||||||
}
|
}
|
||||||
|
|
||||||
showDialog( DIALOG_SELECTBASEDIR_ID );
|
showDialog(DIALOG_SELECTBASEDIR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void selectRoutingModes( String[] modes, boolean[] modesChecked, String message )
|
public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message) {
|
||||||
{
|
|
||||||
routingModes = modes;
|
routingModes = modes;
|
||||||
routingModesChecked = modesChecked;
|
routingModesChecked = modesChecked;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
showDialog( DIALOG_ROUTINGMODES_ID );
|
showDialog(DIALOG_ROUTINGMODES_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void showModeConfigOverview( String message )
|
public void showModeConfigOverview(String message) {
|
||||||
{
|
|
||||||
this.message = message;
|
this.message = message;
|
||||||
showDialog( DIALOG_MODECONFIGOVERVIEW_ID );
|
showDialog(DIALOG_MODECONFIGOVERVIEW_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void selectVias( String[] items )
|
public void selectVias(String[] items) {
|
||||||
{
|
|
||||||
availableVias = items;
|
availableVias = items;
|
||||||
selectedVias = new HashSet<String>( availableVias.length );
|
selectedVias = new HashSet<String>(availableVias.length);
|
||||||
for ( String via : items )
|
for (String via : items)
|
||||||
selectedVias.add( via );
|
selectedVias.add(via);
|
||||||
showDialog( DIALOG_VIASELECT_ID );
|
showDialog(DIALOG_VIASELECT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void selectWaypoint( String[] items )
|
public void selectWaypoint(String[] items) {
|
||||||
{
|
|
||||||
availableWaypoints = items;
|
availableWaypoints = items;
|
||||||
showNewDialog( DIALOG_PICKWAYPOINT_ID );
|
showNewDialog(DIALOG_PICKWAYPOINT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void showWaypointDatabaseHelp()
|
public void showWaypointDatabaseHelp() {
|
||||||
{
|
if (mBRouterView.canAccessSdCard) {
|
||||||
if ( mBRouterView.canAccessSdCard )
|
showNewDialog(DIALOG_SHOW_WP_HELP_ID);
|
||||||
{
|
} else {
|
||||||
showNewDialog( DIALOG_SHOW_WP_HELP_ID );
|
showNewDialog(DIALOG_SHOW_API23_HELP_ID);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
showNewDialog( DIALOG_SHOW_API23_HELP_ID );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void showRepeatTimeoutHelp()
|
public void showRepeatTimeoutHelp() {
|
||||||
{
|
showNewDialog(DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID);
|
||||||
showNewDialog( DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void showWpDatabaseScanSuccess( String bestGuess )
|
public void showWpDatabaseScanSuccess(String bestGuess) {
|
||||||
{
|
|
||||||
maptoolDirCandidate = bestGuess;
|
maptoolDirCandidate = bestGuess;
|
||||||
showNewDialog( DIALOG_SHOW_WP_SCANRESULT_ID );
|
showNewDialog(DIALOG_SHOW_WP_SCANRESULT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void selectNogos( List<OsmNodeNamed> nogoList )
|
public void selectNogos(List<OsmNodeNamed> nogoList) {
|
||||||
{
|
|
||||||
this.nogoList = nogoList;
|
this.nogoList = nogoList;
|
||||||
showDialog( DIALOG_NOGOSELECT_ID );
|
showDialog(DIALOG_NOGOSELECT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Integer> dialogIds = new HashSet<Integer>();
|
private Set<Integer> dialogIds = new HashSet<Integer>();
|
||||||
|
|
||||||
private void showNewDialog( int id )
|
private void showNewDialog(int id) {
|
||||||
{
|
if (dialogIds.contains(Integer.valueOf(id))) {
|
||||||
if ( dialogIds.contains( Integer.valueOf( id ) ) )
|
removeDialog(id);
|
||||||
{
|
|
||||||
removeDialog( id );
|
|
||||||
}
|
}
|
||||||
dialogIds.add( Integer.valueOf( id ) );
|
dialogIds.add(Integer.valueOf(id));
|
||||||
showDialog( id );
|
showDialog(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
|
@ -635,24 +538,21 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
private int wpCount;
|
private int wpCount;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void showErrorMessage( String msg )
|
public void showErrorMessage(String msg) {
|
||||||
{
|
|
||||||
errorMessage = msg;
|
errorMessage = msg;
|
||||||
showNewDialog( DIALOG_EXCEPTION_ID );
|
showNewDialog(DIALOG_EXCEPTION_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void showResultMessage( String title, String msg, int wpCount )
|
public void showResultMessage(String title, String msg, int wpCount) {
|
||||||
{
|
|
||||||
errorMessage = msg;
|
errorMessage = msg;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.wpCount = wpCount;
|
this.wpCount = wpCount;
|
||||||
showNewDialog( DIALOG_SHOWRESULT_ID );
|
showNewDialog(DIALOG_SHOWRESULT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume()
|
protected void onResume() {
|
||||||
{
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
/*
|
/*
|
||||||
* when the activity is resumed, we acquire a wake-lock so that the screen
|
* when the activity is resumed, we acquire a wake-lock so that the screen
|
||||||
|
@ -663,8 +563,7 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause()
|
protected void onPause() {
|
||||||
{
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
/*
|
/*
|
||||||
* When the activity is paused, we make sure to stop the router
|
* When the activity is paused, we make sure to stop the router
|
||||||
|
@ -681,7 +580,7 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
return EnvironmentCompat.getStorageState(f); //Environment.MEDIA_MOUNTED
|
return EnvironmentCompat.getStorageState(f); //Environment.MEDIA_MOUNTED
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<File> getStorageDirectories () {
|
public ArrayList<File> getStorageDirectories() {
|
||||||
ArrayList<File> list = null;
|
ArrayList<File> list = null;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
list = new ArrayList<File>(Arrays.asList(getExternalMediaDirs()));
|
list = new ArrayList<File>(Arrays.asList(getExternalMediaDirs()));
|
||||||
|
@ -693,7 +592,7 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
for (File f : list) {
|
for (File f : list) {
|
||||||
if (f != null) {
|
if (f != null) {
|
||||||
if (getStorageState(f).equals(Environment.MEDIA_MOUNTED))
|
if (getStorageState(f).equals(Environment.MEDIA_MOUNTED))
|
||||||
res.add (f);
|
res.add(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,27 +607,25 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques
|
||||||
boolean isWritable = false;
|
boolean isWritable = false;
|
||||||
try {
|
try {
|
||||||
File sd = Environment.getExternalStorageDirectory();
|
File sd = Environment.getExternalStorageDirectory();
|
||||||
File testDir = new File( sd, "brouter" );
|
File testDir = new File(sd, "brouter");
|
||||||
boolean didExist = testDir.isDirectory();
|
boolean didExist = testDir.isDirectory();
|
||||||
if ( !didExist )
|
if (!didExist) {
|
||||||
{
|
|
||||||
testDir.mkdir();
|
testDir.mkdir();
|
||||||
}
|
}
|
||||||
File testFile = new File( testDir, "test" + System.currentTimeMillis() );
|
File testFile = new File(testDir, "test" + System.currentTimeMillis());
|
||||||
testFile.createNewFile();
|
testFile.createNewFile();
|
||||||
if ( testFile.exists() ) {
|
if (testFile.exists()) {
|
||||||
testFile.delete();
|
testFile.delete();
|
||||||
isWritable = true;
|
isWritable = true;
|
||||||
}
|
}
|
||||||
}
|
} catch (Throwable t) {
|
||||||
catch (Throwable t) {
|
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
return isWritable;
|
return isWritable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
if (requestCode == 0) {
|
if (requestCode == 0) {
|
||||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
mBRouterView.startSetup(null, true);
|
mBRouterView.startSetup(null, true);
|
||||||
|
|
|
@ -33,8 +33,7 @@ import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import btools.router.OsmNodeNamed;
|
import btools.router.OsmNodeNamed;
|
||||||
|
|
||||||
public class BRouterService extends Service
|
public class BRouterService extends Service {
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent arg0) {
|
public IBinder onBind(Intent arg0) {
|
||||||
|
@ -42,114 +41,98 @@ public class BRouterService extends Service
|
||||||
return myBRouterServiceStub;
|
return myBRouterServiceStub;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBRouterService.Stub myBRouterServiceStub = new IBRouterService.Stub()
|
private IBRouterService.Stub myBRouterServiceStub = new IBRouterService.Stub() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public String getTrackFromParams( Bundle params ) throws RemoteException
|
public String getTrackFromParams(Bundle params) throws RemoteException {
|
||||||
{
|
logBundle(params);
|
||||||
logBundle( params );
|
|
||||||
|
|
||||||
BRouterWorker worker = new BRouterWorker();
|
BRouterWorker worker = new BRouterWorker();
|
||||||
|
|
||||||
// get base dir from private file
|
// get base dir from private file
|
||||||
String baseDir = null;
|
String baseDir = null;
|
||||||
InputStream configInput = null;
|
InputStream configInput = null;
|
||||||
try
|
try {
|
||||||
{
|
configInput = openFileInput("config15.dat");
|
||||||
configInput = openFileInput( "config15.dat" );
|
BufferedReader br = new BufferedReader(new InputStreamReader(configInput));
|
||||||
BufferedReader br = new BufferedReader( new InputStreamReader( configInput ) );
|
|
||||||
baseDir = br.readLine();
|
baseDir = br.readLine();
|
||||||
|
} catch (Exception e) {
|
||||||
|
} finally {
|
||||||
|
if (configInput != null) try {
|
||||||
|
configInput.close();
|
||||||
|
} catch (Exception ee) {
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if ( configInput != null ) try { configInput.close(); } catch (Exception ee) {}
|
|
||||||
}
|
}
|
||||||
worker.baseDir = baseDir;
|
worker.baseDir = baseDir;
|
||||||
worker.segmentDir = new File (baseDir, "brouter/segments4" );
|
worker.segmentDir = new File(baseDir, "brouter/segments4");
|
||||||
|
|
||||||
String remoteProfile = params.getString( "remoteProfile" );
|
String remoteProfile = params.getString("remoteProfile");
|
||||||
|
|
||||||
if ( remoteProfile == null )
|
if (remoteProfile == null) {
|
||||||
{
|
remoteProfile = checkForTestDummy(baseDir);
|
||||||
remoteProfile = checkForTestDummy( baseDir );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String errMsg = null;
|
String errMsg = null;
|
||||||
if (remoteProfile != null ) {
|
if (remoteProfile != null) {
|
||||||
errMsg = getConfigForRemoteProfile(worker, baseDir, remoteProfile);
|
errMsg = getConfigForRemoteProfile(worker, baseDir, remoteProfile);
|
||||||
} else if (params.containsKey("profile")) {
|
} else if (params.containsKey("profile")) {
|
||||||
String profile = params.getString( "profile" );
|
String profile = params.getString("profile");
|
||||||
worker.profileName = profile;
|
worker.profileName = profile;
|
||||||
worker.profilePath = baseDir + "/brouter/profiles2/" + profile + ".brf";
|
worker.profilePath = baseDir + "/brouter/profiles2/" + profile + ".brf";
|
||||||
worker.rawTrackPath = baseDir + "/brouter/modes/" + profile + "_rawtrack.dat";
|
worker.rawTrackPath = baseDir + "/brouter/modes/" + profile + "_rawtrack.dat";
|
||||||
if (!new File(worker.profilePath).exists()) errMsg = "Profile " + profile + " does not exists";
|
if (!new File(worker.profilePath).exists())
|
||||||
|
errMsg = "Profile " + profile + " does not exists";
|
||||||
try {
|
try {
|
||||||
readNogos(worker, baseDir);
|
readNogos(worker, baseDir);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errMsg = e.getLocalizedMessage();
|
errMsg = e.getLocalizedMessage();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
errMsg = getConfigFromMode(worker, baseDir, params.getString("v"), params.getString("fast"));
|
errMsg = getConfigFromMode(worker, baseDir, params.getString("v"), params.getString("fast"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( errMsg != null )
|
if (errMsg != null) {
|
||||||
{
|
|
||||||
return errMsg;
|
return errMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean canCompress = "true".equals( params.getString( "acceptCompressedResult" ) );
|
boolean canCompress = "true".equals(params.getString("acceptCompressedResult"));
|
||||||
try
|
try {
|
||||||
{
|
String gpxMessage = worker.getTrackFromParams(params);
|
||||||
String gpxMessage = worker.getTrackFromParams( params );
|
if (canCompress && gpxMessage.startsWith("<")) {
|
||||||
if ( canCompress && gpxMessage.startsWith( "<" ) )
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
baos.write( "z64".getBytes(Charset.forName("UTF-8")) ); // marker prefix
|
baos.write("z64".getBytes(Charset.forName("UTF-8"))); // marker prefix
|
||||||
OutputStream os = new GZIPOutputStream( baos );
|
OutputStream os = new GZIPOutputStream(baos);
|
||||||
byte[] ab = gpxMessage.getBytes(Charset.forName("UTF-8")); //StandardCharsets.UTF_8
|
byte[] ab = gpxMessage.getBytes(Charset.forName("UTF-8")); //StandardCharsets.UTF_8
|
||||||
gpxMessage = null;
|
gpxMessage = null;
|
||||||
os.write( ab );
|
os.write(ab);
|
||||||
ab = null;
|
ab = null;
|
||||||
os.close();
|
os.close();
|
||||||
gpxMessage = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
|
gpxMessage = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
|
||||||
return gpxMessage;
|
return gpxMessage;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
return "error compressing result";
|
return "error compressing result";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gpxMessage;
|
return gpxMessage;
|
||||||
}
|
} catch (IllegalArgumentException iae) {
|
||||||
catch (IllegalArgumentException iae)
|
|
||||||
{
|
|
||||||
return iae.getMessage();
|
return iae.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getConfigFromMode( BRouterWorker worker, String baseDir, String mode, String fast )
|
private String getConfigFromMode(BRouterWorker worker, String baseDir, String mode, String fast) {
|
||||||
{
|
boolean isFast = "1".equals(fast) || "true".equals(fast) || "yes".equals(fast);
|
||||||
boolean isFast = "1".equals( fast ) || "true".equals( fast ) || "yes".equals( fast );
|
String mode_key = mode + "_" + (isFast ? "fast" : "short");
|
||||||
String mode_key = mode + "_" + ( isFast ? "fast" : "short" );
|
|
||||||
|
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
String modesFile = baseDir + "/brouter/modes/serviceconfig.dat";
|
String modesFile = baseDir + "/brouter/modes/serviceconfig.dat";
|
||||||
br = new BufferedReader( new FileReader( modesFile ) );
|
br = new BufferedReader(new FileReader(modesFile));
|
||||||
for ( ;; )
|
for (; ; ) {
|
||||||
{
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if ( line == null )
|
if (line == null)
|
||||||
break;
|
break;
|
||||||
ServiceModeConfig smc = new ServiceModeConfig( line );
|
ServiceModeConfig smc = new ServiceModeConfig(line);
|
||||||
if ( !smc.mode.equals( mode_key ) )
|
if (!smc.mode.equals(mode_key))
|
||||||
continue;
|
continue;
|
||||||
worker.profileName = smc.profile;
|
worker.profileName = smc.profile;
|
||||||
worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf";
|
worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf";
|
||||||
|
@ -159,48 +142,42 @@ public class BRouterService extends Service
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return "no brouter service config found, mode " + mode_key;
|
return "no brouter service config found, mode " + mode_key;
|
||||||
|
} finally {
|
||||||
|
if (br != null) try {
|
||||||
|
br.close();
|
||||||
|
} catch (Exception ee) {
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if ( br != null ) try { br.close(); } catch( Exception ee ) {}
|
|
||||||
}
|
}
|
||||||
return "no brouter service config found for mode " + mode_key;
|
return "no brouter service config found for mode " + mode_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getConfigForRemoteProfile( BRouterWorker worker, String baseDir, String remoteProfile )
|
private String getConfigForRemoteProfile(BRouterWorker worker, String baseDir, String remoteProfile) {
|
||||||
{
|
|
||||||
worker.profileName = "remote";
|
worker.profileName = "remote";
|
||||||
worker.profilePath = baseDir + "/brouter/profiles2/remote.brf";
|
worker.profilePath = baseDir + "/brouter/profiles2/remote.brf";
|
||||||
worker.rawTrackPath = baseDir + "/brouter/modes/remote_rawtrack.dat";
|
worker.rawTrackPath = baseDir + "/brouter/modes/remote_rawtrack.dat";
|
||||||
|
|
||||||
// store profile only if not identical (to preserve timestamp)
|
// store profile only if not identical (to preserve timestamp)
|
||||||
byte[] profileBytes = remoteProfile.getBytes();
|
byte[] profileBytes = remoteProfile.getBytes();
|
||||||
File profileFile = new File( worker.profilePath );
|
File profileFile = new File(worker.profilePath);
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
readNogos(worker, baseDir);
|
readNogos(worker, baseDir);
|
||||||
|
|
||||||
if ( !fileEqual( profileBytes, profileFile ) )
|
if (!fileEqual(profileBytes, profileFile)) {
|
||||||
{
|
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
try
|
try {
|
||||||
{
|
os = new FileOutputStream(profileFile);
|
||||||
os = new FileOutputStream( profileFile );
|
os.write(profileBytes);
|
||||||
os.write( profileBytes );
|
} finally {
|
||||||
}
|
if (os != null) try {
|
||||||
finally
|
os.close();
|
||||||
{
|
} catch (IOException io) {
|
||||||
if ( os != null ) try { os.close(); } catch( IOException io ) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
} catch (Exception e) {
|
||||||
{
|
|
||||||
return "error caching remote profile: " + e;
|
return "error caching remote profile: " + e;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -217,18 +194,16 @@ public class BRouterService extends Service
|
||||||
if (ContextCompat.checkSelfPermission(BRouterService.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(BRouterService.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
canAccessSdCard = false;
|
canAccessSdCard = false;
|
||||||
}
|
}
|
||||||
AppLogger.log( "dev/target=" + deviceLevel + "/" + targetSdkVersion + " canAccessSdCard=" + canAccessSdCard );
|
AppLogger.log("dev/target=" + deviceLevel + "/" + targetSdkVersion + " canAccessSdCard=" + canAccessSdCard);
|
||||||
|
|
||||||
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir, canAccessSdCard, true );
|
CoordinateReader cor = CoordinateReader.obtainValidReader(baseDir, worker.segmentDir, canAccessSdCard, 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>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean fileEqual( byte[] fileBytes, File file ) throws Exception
|
private boolean fileEqual(byte[] fileBytes, File file) throws Exception {
|
||||||
{
|
if (!file.exists()) {
|
||||||
if ( !file.exists() )
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int nbytes = fileBytes.length;
|
int nbytes = fileBytes.length;
|
||||||
|
@ -236,67 +211,57 @@ public class BRouterService extends Service
|
||||||
int blen = 8192;
|
int blen = 8192;
|
||||||
byte[] buf = new byte[blen];
|
byte[] buf = new byte[blen];
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try
|
try {
|
||||||
{
|
is = new FileInputStream(file);
|
||||||
is = new FileInputStream( file );
|
while (pos < nbytes) {
|
||||||
while( pos < nbytes )
|
int len = is.read(buf, 0, blen);
|
||||||
{
|
if (len <= 0) return false;
|
||||||
int len = is.read( buf, 0, blen );
|
if (pos + len > nbytes) return false;
|
||||||
if ( len <= 0 ) return false;
|
for (int j = 0; j < len; j++) {
|
||||||
if ( pos + len > nbytes ) return false;
|
if (fileBytes[pos++] != buf[j]) {
|
||||||
for( int j=0; j<len; j++ )
|
|
||||||
{
|
|
||||||
if ( fileBytes[pos++] != buf[j] )
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} finally {
|
||||||
|
if (is != null) try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException io) {
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if ( is != null ) try { is.close(); } catch( IOException io ) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String checkForTestDummy( String baseDir )
|
private String checkForTestDummy(String baseDir) {
|
||||||
{
|
File testdummy = new File(baseDir + "/brouter/profiles2/remotetestdummy.brf");
|
||||||
File testdummy = new File( baseDir + "/brouter/profiles2/remotetestdummy.brf" );
|
if (!testdummy.exists()) return null;
|
||||||
if ( !testdummy.exists() ) return null;
|
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
try
|
try {
|
||||||
{
|
br = new BufferedReader(new FileReader(testdummy));
|
||||||
br = new BufferedReader( new FileReader( testdummy ) );
|
for (; ; ) {
|
||||||
for ( ;; )
|
|
||||||
{
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if ( line == null )
|
if (line == null)
|
||||||
break;
|
break;
|
||||||
sb.append( line ).append( '\n' );
|
sb.append(line).append('\n');
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("error reading " + testdummy);
|
||||||
|
} finally {
|
||||||
|
if (br != null) try {
|
||||||
|
br.close();
|
||||||
|
} catch (Exception ee) {
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException( "error reading " + testdummy );
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if ( br != null ) try { br.close(); } catch( Exception ee ) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logBundle( Bundle params )
|
private void logBundle(Bundle params) {
|
||||||
{
|
if (AppLogger.isLogging()) {
|
||||||
if ( AppLogger.isLogging() )
|
for (String k : params.keySet()) {
|
||||||
{
|
Object val = "remoteProfile".equals(k) ? "<..cut..>" : params.get(k);
|
||||||
for( String k : params.keySet() )
|
String desc = "key=" + k + (val == null ? "" : " class=" + val.getClass() + " val=" + val.toString());
|
||||||
{
|
AppLogger.log(desc);
|
||||||
Object val = "remoteProfile".equals( k ) ? "<..cut..>" : params.get(k);
|
|
||||||
String desc = "key=" + k + (val == null ? "" : " class=" + val.getClass() + " val=" + val.toString() );
|
|
||||||
AppLogger.log( desc );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,17 +269,15 @@ public class BRouterService extends Service
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate() {
|
||||||
{
|
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
Log.d(getClass().getSimpleName(),"onCreate()");
|
Log.d(getClass().getSimpleName(), "onCreate()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy()
|
public void onDestroy() {
|
||||||
{
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
Log.d(getClass().getSimpleName(),"onDestroy()");
|
Log.d(getClass().getSimpleName(), "onDestroy()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,20 +286,17 @@ public class BRouterService extends Service
|
||||||
// method will not be called.
|
// method will not be called.
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void onStart(Intent intent, int startId)
|
public void onStart(Intent intent, int startId) {
|
||||||
{
|
|
||||||
Log.d(getClass().getSimpleName(), "onStart()");
|
Log.d(getClass().getSimpleName(), "onStart()");
|
||||||
handleStart(intent, startId);
|
handleStart(intent, startId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId)
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
{
|
|
||||||
handleStart(intent, startId);
|
handleStart(intent, startId);
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleStart(Intent intent, int startId)
|
void handleStart(Intent intent, int startId) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,8 +17,7 @@ import btools.router.OsmTrack;
|
||||||
import btools.router.RoutingContext;
|
import btools.router.RoutingContext;
|
||||||
import btools.router.RoutingEngine;
|
import btools.router.RoutingEngine;
|
||||||
|
|
||||||
public class BRouterWorker
|
public class BRouterWorker {
|
||||||
{
|
|
||||||
private static final int OUTPUT_FORMAT_GPX = 0;
|
private static final int OUTPUT_FORMAT_GPX = 0;
|
||||||
private static final int OUTPUT_FORMAT_KML = 1;
|
private static final int OUTPUT_FORMAT_KML = 1;
|
||||||
private static final int OUTPUT_FORMAT_JSON = 2;
|
private static final int OUTPUT_FORMAT_JSON = 2;
|
||||||
|
@ -66,16 +65,15 @@ public class BRouterWorker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( params.containsKey( "direction" ) )
|
if (params.containsKey("direction")) {
|
||||||
{
|
rc.startDirection = params.getInt("direction");
|
||||||
rc.startDirection = params.getInt( "direction" );
|
|
||||||
}
|
}
|
||||||
if ( params.containsKey( "alternativeidx" ) ) {
|
if (params.containsKey("alternativeidx")) {
|
||||||
rc.alternativeIdx = params.getInt( "alternativeidx" );
|
rc.alternativeIdx = params.getInt("alternativeidx");
|
||||||
}
|
}
|
||||||
|
|
||||||
readNogos( params ); // add interface provided nogos
|
readNogos(params); // add interface provided nogos
|
||||||
if ( nogoList != null ) {
|
if (nogoList != null) {
|
||||||
RoutingContext.prepareNogoPoints(nogoList);
|
RoutingContext.prepareNogoPoints(nogoList);
|
||||||
if (rc.nogopoints == null) {
|
if (rc.nogopoints == null) {
|
||||||
rc.nogopoints = nogoList;
|
rc.nogopoints = nogoList;
|
||||||
|
@ -85,7 +83,7 @@ public class BRouterWorker
|
||||||
}
|
}
|
||||||
if (rc.nogopoints == null) {
|
if (rc.nogopoints == null) {
|
||||||
rc.nogopoints = nogoPolygonsList;
|
rc.nogopoints = nogoPolygonsList;
|
||||||
} else if ( nogoPolygonsList != null ) {
|
} else if (nogoPolygonsList != null) {
|
||||||
rc.nogopoints.addAll(nogoPolygonsList);
|
rc.nogopoints.addAll(nogoPolygonsList);
|
||||||
}
|
}
|
||||||
List<OsmNodeNamed> poisList = readPoisList(params);
|
List<OsmNodeNamed> poisList = readPoisList(params);
|
||||||
|
@ -100,47 +98,43 @@ public class BRouterWorker
|
||||||
|
|
||||||
if (waypoints == null) return "no pts ";
|
if (waypoints == null) return "no pts ";
|
||||||
|
|
||||||
if (params.containsKey( "extraParams" )) { // add user params
|
if (params.containsKey("extraParams")) { // add user params
|
||||||
String extraParams = params.getString("extraParams");
|
String extraParams = params.getString("extraParams");
|
||||||
if (rc.keyValues == null) rc.keyValues = new HashMap<String,String>();
|
if (rc.keyValues == null) rc.keyValues = new HashMap<String, String>();
|
||||||
StringTokenizer tk = new StringTokenizer( extraParams, "?&" );
|
StringTokenizer tk = new StringTokenizer(extraParams, "?&");
|
||||||
while( tk.hasMoreTokens() ) {
|
while (tk.hasMoreTokens()) {
|
||||||
String t = tk.nextToken();
|
String t = tk.nextToken();
|
||||||
StringTokenizer tk2 = new StringTokenizer( t, "=" );
|
StringTokenizer tk2 = new StringTokenizer(t, "=");
|
||||||
if ( tk2.hasMoreTokens() ) {
|
if (tk2.hasMoreTokens()) {
|
||||||
String key = tk2.nextToken();
|
String key = tk2.nextToken();
|
||||||
if ( tk2.hasMoreTokens() ) {
|
if (tk2.hasMoreTokens()) {
|
||||||
String value = tk2.nextToken();
|
String value = tk2.nextToken();
|
||||||
rc.keyValues.put( key, value );
|
rc.keyValues.put(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
writeTimeoutData(rc);
|
||||||
writeTimeoutData( rc );
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
catch( Exception e ) {}
|
|
||||||
|
|
||||||
RoutingEngine cr = new RoutingEngine( null, null, segmentDir, waypoints, rc );
|
RoutingEngine cr = new RoutingEngine(null, null, segmentDir, waypoints, rc);
|
||||||
cr.quite = true;
|
cr.quite = true;
|
||||||
cr.doRun( maxRunningTime );
|
cr.doRun(maxRunningTime);
|
||||||
|
|
||||||
// store new reference track if any
|
// store new reference track if any
|
||||||
// (can exist for timed-out search)
|
// (can exist for timed-out search)
|
||||||
if ( cr.getFoundRawTrack() != null )
|
if (cr.getFoundRawTrack() != null) {
|
||||||
{
|
try {
|
||||||
try
|
cr.getFoundRawTrack().writeBinary(rawTrackPath);
|
||||||
{
|
} catch (Exception e) {
|
||||||
cr.getFoundRawTrack().writeBinary( rawTrackPath );
|
|
||||||
}
|
}
|
||||||
catch( Exception e ) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( cr.getErrorMessage() != null )
|
if (cr.getErrorMessage() != null) {
|
||||||
{
|
|
||||||
return cr.getErrorMessage();
|
return cr.getErrorMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,109 +146,108 @@ public class BRouterWorker
|
||||||
}
|
}
|
||||||
|
|
||||||
OsmTrack track = cr.getFoundTrack();
|
OsmTrack track = cr.getFoundTrack();
|
||||||
if ( track != null )
|
if (track != null) {
|
||||||
{
|
|
||||||
if (params.containsKey("exportWaypoints")) {
|
if (params.containsKey("exportWaypoints")) {
|
||||||
track.exportWaypoints = (params.getInt("exportWaypoints",0) == 1 );
|
track.exportWaypoints = (params.getInt("exportWaypoints", 0) == 1);
|
||||||
}
|
}
|
||||||
if ( pathToFileResult == null )
|
if (pathToFileResult == null) {
|
||||||
{
|
switch (writeFromat) {
|
||||||
switch ( writeFromat ) {
|
case OUTPUT_FORMAT_GPX:
|
||||||
case OUTPUT_FORMAT_GPX: return track.formatAsGpx();
|
return track.formatAsGpx();
|
||||||
case OUTPUT_FORMAT_KML: return track.formatAsKml();
|
case OUTPUT_FORMAT_KML:
|
||||||
case OUTPUT_FORMAT_JSON: return track.formatAsGeoJson();
|
return track.formatAsKml();
|
||||||
default: return track.formatAsGpx();
|
case OUTPUT_FORMAT_JSON:
|
||||||
|
return track.formatAsGeoJson();
|
||||||
|
default:
|
||||||
|
return track.formatAsGpx();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
switch (writeFromat) {
|
||||||
switch ( writeFromat ) {
|
case OUTPUT_FORMAT_GPX:
|
||||||
case OUTPUT_FORMAT_GPX: track.writeGpx(pathToFileResult); break;
|
track.writeGpx(pathToFileResult);
|
||||||
case OUTPUT_FORMAT_KML: track.writeKml(pathToFileResult); break;
|
break;
|
||||||
case OUTPUT_FORMAT_JSON: track.writeJson(pathToFileResult); break;
|
case OUTPUT_FORMAT_KML:
|
||||||
default: track.writeGpx(pathToFileResult); break;
|
track.writeKml(pathToFileResult);
|
||||||
|
break;
|
||||||
|
case OUTPUT_FORMAT_JSON:
|
||||||
|
track.writeJson(pathToFileResult);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
track.writeGpx(pathToFileResult);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
return "error writing file: " + e;
|
return "error writing file: " + e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OsmNodeNamed> readPositions( Bundle params )
|
private List<OsmNodeNamed> readPositions(Bundle params) {
|
||||||
{
|
|
||||||
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
|
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
|
||||||
|
|
||||||
double[] lats = params.getDoubleArray("lats");
|
double[] lats = params.getDoubleArray("lats");
|
||||||
double[] lons = params.getDoubleArray("lons");
|
double[] lons = params.getDoubleArray("lons");
|
||||||
|
|
||||||
if (lats == null || lats.length < 2 || lons == null || lons.length < 2)
|
if (lats == null || lats.length < 2 || lons == null || lons.length < 2) {
|
||||||
{
|
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||||
throw new IllegalArgumentException( "we need two lat/lon points at least!" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i=0; i<lats.length && i<lons.length; i++ )
|
for (int i = 0; i < lats.length && i < lons.length; i++) {
|
||||||
{
|
|
||||||
OsmNodeNamed n = new OsmNodeNamed();
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
n.name = "via" + i;
|
n.name = "via" + i;
|
||||||
n.ilon = (int)( ( lons[i] + 180. ) *1000000. + 0.5);
|
n.ilon = (int) ((lons[i] + 180.) * 1000000. + 0.5);
|
||||||
n.ilat = (int)( ( lats[i] + 90. ) *1000000. + 0.5);
|
n.ilat = (int) ((lats[i] + 90.) * 1000000. + 0.5);
|
||||||
wplist.add( n );
|
wplist.add(n);
|
||||||
}
|
}
|
||||||
wplist.get(0).name = "from";
|
wplist.get(0).name = "from";
|
||||||
wplist.get(wplist.size()-1).name = "to";
|
wplist.get(wplist.size() - 1).name = "to";
|
||||||
|
|
||||||
return wplist;
|
return wplist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OsmNodeNamed> readLonlats(Bundle params )
|
private List<OsmNodeNamed> readLonlats(Bundle params) {
|
||||||
{
|
|
||||||
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
|
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
|
||||||
|
|
||||||
String lonLats = params.getString( "lonlats" );
|
String lonLats = params.getString("lonlats");
|
||||||
if (lonLats == null) throw new IllegalArgumentException( "lonlats parameter not set" );
|
if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set");
|
||||||
|
|
||||||
String[] coords = lonLats.split("\\|");
|
String[] coords = lonLats.split("\\|");
|
||||||
if (coords.length < 2)
|
if (coords.length < 2)
|
||||||
throw new IllegalArgumentException( "we need two lat/lon points at least!" );
|
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||||
|
|
||||||
for (int i = 0; i < coords.length; i++)
|
for (int i = 0; i < coords.length; i++) {
|
||||||
{
|
|
||||||
String[] lonLat = coords[i].split(",");
|
String[] lonLat = coords[i].split(",");
|
||||||
if (lonLat.length < 2)
|
if (lonLat.length < 2)
|
||||||
throw new IllegalArgumentException( "we need two lat/lon points at least!" );
|
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||||
wplist.add( readPosition( lonLat[0], lonLat[1], "via" + i ) );
|
wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
wplist.get(0).name = "from";
|
wplist.get(0).name = "from";
|
||||||
wplist.get(wplist.size()-1).name = "to";
|
wplist.get(wplist.size() - 1).name = "to";
|
||||||
|
|
||||||
return wplist;
|
return wplist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OsmNodeNamed readPosition( String vlon, String vlat, String name )
|
private static OsmNodeNamed readPosition(String vlon, String vlat, String name) {
|
||||||
{
|
if (vlon == null) throw new IllegalArgumentException("lon " + name + " not found in input");
|
||||||
if ( vlon == null ) throw new IllegalArgumentException( "lon " + name + " not found in input" );
|
if (vlat == null) throw new IllegalArgumentException("lat " + name + " not found in input");
|
||||||
if ( vlat == null ) throw new IllegalArgumentException( "lat " + name + " not found in input" );
|
|
||||||
|
|
||||||
return readPosition(Double.parseDouble( vlon ), Double.parseDouble( vlat ), name);
|
return readPosition(Double.parseDouble(vlon), Double.parseDouble(vlat), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OsmNodeNamed readPosition( double lon, double lat, String name )
|
private static OsmNodeNamed readPosition(double lon, double lat, String name) {
|
||||||
{
|
|
||||||
OsmNodeNamed n = new OsmNodeNamed();
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
n.name = name;
|
n.name = name;
|
||||||
n.ilon = (int)( ( lon + 180. ) *1000000. + 0.5);
|
n.ilon = (int) ((lon + 180.) * 1000000. + 0.5);
|
||||||
n.ilat = (int)( ( lat + 90. ) *1000000. + 0.5);
|
n.ilat = (int) ((lat + 90.) * 1000000. + 0.5);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void readNogos( Bundle params )
|
private void readNogos(Bundle params) {
|
||||||
{
|
|
||||||
if (params.containsKey("nogoLats")) {
|
if (params.containsKey("nogoLats")) {
|
||||||
double[] lats = params.getDoubleArray("nogoLats");
|
double[] lats = params.getDoubleArray("nogoLats");
|
||||||
double[] lons = params.getDoubleArray("nogoLons");
|
double[] lons = params.getDoubleArray("nogoLons");
|
||||||
|
@ -282,17 +275,15 @@ public class BRouterWorker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OsmNodeNamed> readNogoList(Bundle params)
|
private List<OsmNodeNamed> readNogoList(Bundle params) {
|
||||||
{
|
|
||||||
// lon,lat,radius|...
|
// lon,lat,radius|...
|
||||||
String nogos = params.getString( "nogos" );
|
String nogos = params.getString("nogos");
|
||||||
if ( nogos == null ) return null;
|
if (nogos == null) return null;
|
||||||
|
|
||||||
String[] lonLatRadList = nogos.split("\\|");
|
String[] lonLatRadList = nogos.split("\\|");
|
||||||
|
|
||||||
List<OsmNodeNamed> nogoList = new ArrayList<OsmNodeNamed>();
|
List<OsmNodeNamed> nogoList = new ArrayList<OsmNodeNamed>();
|
||||||
for (int i = 0; i < lonLatRadList.length; i++)
|
for (int i = 0; i < lonLatRadList.length; i++) {
|
||||||
{
|
|
||||||
String[] lonLatRad = lonLatRadList[i].split(",");
|
String[] lonLatRad = lonLatRadList[i].split(",");
|
||||||
String nogoWeight = "NaN";
|
String nogoWeight = "NaN";
|
||||||
if (lonLatRad.length > 3) {
|
if (lonLatRad.length > 3) {
|
||||||
|
@ -304,51 +295,43 @@ public class BRouterWorker
|
||||||
return nogoList;
|
return nogoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OsmNodeNamed readNogo( String lon, String lat, String radius, String nogoWeight )
|
private static OsmNodeNamed readNogo(String lon, String lat, String radius, String nogoWeight) {
|
||||||
{
|
double weight = "undefined".equals(nogoWeight) ? Double.NaN : Double.parseDouble(nogoWeight);
|
||||||
double weight = "undefined".equals( nogoWeight ) ? Double.NaN : Double.parseDouble( nogoWeight );
|
return readNogo(Double.parseDouble(lon), Double.parseDouble(lat), Integer.parseInt(radius), weight);
|
||||||
return readNogo(Double.parseDouble( lon ), Double.parseDouble( lat ), Integer.parseInt( radius ), weight );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OsmNodeNamed readNogo( double lon, double lat, int radius, double nogoWeight )
|
private static OsmNodeNamed readNogo(double lon, double lat, int radius, double nogoWeight) {
|
||||||
{
|
|
||||||
OsmNodeNamed n = new OsmNodeNamed();
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
n.name = "nogo" + radius;
|
n.name = "nogo" + radius;
|
||||||
n.ilon = (int)( ( lon + 180. ) *1000000. + 0.5);
|
n.ilon = (int) ((lon + 180.) * 1000000. + 0.5);
|
||||||
n.ilat = (int)( ( lat + 90. ) *1000000. + 0.5);
|
n.ilat = (int) ((lat + 90.) * 1000000. + 0.5);
|
||||||
n.isNogo = true;
|
n.isNogo = true;
|
||||||
n.nogoWeight = nogoWeight;
|
n.nogoWeight = nogoWeight;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OsmNodeNamed> readNogoPolygons(Bundle params)
|
private List<OsmNodeNamed> readNogoPolygons(Bundle params) {
|
||||||
{
|
|
||||||
List<OsmNodeNamed> result = new ArrayList<OsmNodeNamed>();
|
List<OsmNodeNamed> result = new ArrayList<OsmNodeNamed>();
|
||||||
parseNogoPolygons( params.getString("polylines"), result, false );
|
parseNogoPolygons(params.getString("polylines"), result, false);
|
||||||
parseNogoPolygons( params.getString("polygons"), result, true );
|
parseNogoPolygons(params.getString("polygons"), result, true);
|
||||||
return result.size() > 0 ? result : null;
|
return result.size() > 0 ? result : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void parseNogoPolygons(String polygons, List<OsmNodeNamed> result, boolean closed )
|
private static void parseNogoPolygons(String polygons, List<OsmNodeNamed> result, boolean closed) {
|
||||||
{
|
if (polygons != null) {
|
||||||
if ( polygons != null )
|
|
||||||
{
|
|
||||||
OsmNogoPolygon polygon = new OsmNogoPolygon(closed);
|
OsmNogoPolygon polygon = new OsmNogoPolygon(closed);
|
||||||
polygon.name = "nogopoly" ;
|
polygon.name = "nogopoly";
|
||||||
String nogoWeight = "NaN";
|
String nogoWeight = "NaN";
|
||||||
String[] polygonList = polygons.split("\\|");
|
String[] polygonList = polygons.split("\\|");
|
||||||
for (int i = 0; i < polygonList.length; i++)
|
for (int i = 0; i < polygonList.length; i++) {
|
||||||
{
|
|
||||||
String[] lonLatList = polygonList[i].split(",");
|
String[] lonLatList = polygonList[i].split(",");
|
||||||
if ( lonLatList.length > 1 )
|
if (lonLatList.length > 1) {
|
||||||
{
|
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < 2 * (lonLatList.length / 2) - 1;)
|
for (j = 0; j < 2 * (lonLatList.length / 2) - 1; ) {
|
||||||
{
|
|
||||||
String slon = lonLatList[j++];
|
String slon = lonLatList[j++];
|
||||||
String slat = lonLatList[j++];
|
String slat = lonLatList[j++];
|
||||||
int lon = (int)( ( Double.parseDouble(slon) + 180. ) *1000000. + 0.5);
|
int lon = (int) ((Double.parseDouble(slon) + 180.) * 1000000. + 0.5);
|
||||||
int lat = (int)( ( Double.parseDouble(slat) + 90. ) *1000000. + 0.5);
|
int lat = (int) ((Double.parseDouble(slat) + 90.) * 1000000. + 0.5);
|
||||||
polygon.addVertex(lon, lat);
|
polygon.addVertex(lon, lat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,35 +341,29 @@ public class BRouterWorker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
polygon.nogoWeight = Double.parseDouble( nogoWeight );
|
polygon.nogoWeight = Double.parseDouble(nogoWeight);
|
||||||
|
|
||||||
if ( polygon.points.size() > 0 )
|
if (polygon.points.size() > 0) {
|
||||||
{
|
|
||||||
polygon.calcBoundingCircle();
|
polygon.calcBoundingCircle();
|
||||||
result.add(polygon);
|
result.add(polygon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void parseNogoPolygons_alt(String polygons, List<OsmNodeNamed> result, boolean closed )
|
private static void parseNogoPolygons_alt(String polygons, List<OsmNodeNamed> result, boolean closed) {
|
||||||
{
|
if (polygons != null) {
|
||||||
if ( polygons != null )
|
|
||||||
{
|
|
||||||
String[] polygonList = polygons.split("\\|");
|
String[] polygonList = polygons.split("\\|");
|
||||||
for (int i = 0; i < polygonList.length; i++)
|
for (int i = 0; i < polygonList.length; i++) {
|
||||||
{
|
|
||||||
String[] lonLatList = polygonList[i].split(",");
|
String[] lonLatList = polygonList[i].split(",");
|
||||||
if ( lonLatList.length > 1 )
|
if (lonLatList.length > 1) {
|
||||||
{
|
|
||||||
OsmNogoPolygon polygon = new OsmNogoPolygon(closed);
|
OsmNogoPolygon polygon = new OsmNogoPolygon(closed);
|
||||||
polygon.name = "nogo" + i;
|
polygon.name = "nogo" + i;
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < 2 * (lonLatList.length / 2) - 1;)
|
for (j = 0; j < 2 * (lonLatList.length / 2) - 1; ) {
|
||||||
{
|
|
||||||
String slon = lonLatList[j++];
|
String slon = lonLatList[j++];
|
||||||
String slat = lonLatList[j++];
|
String slat = lonLatList[j++];
|
||||||
int lon = (int)( ( Double.parseDouble(slon) + 180. ) *1000000. + 0.5);
|
int lon = (int) ((Double.parseDouble(slon) + 180.) * 1000000. + 0.5);
|
||||||
int lat = (int)( ( Double.parseDouble(slat) + 90. ) *1000000. + 0.5);
|
int lat = (int) ((Double.parseDouble(slat) + 90.) * 1000000. + 0.5);
|
||||||
polygon.addVertex(lon, lat);
|
polygon.addVertex(lon, lat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,10 +371,9 @@ public class BRouterWorker
|
||||||
if (j < lonLatList.length) {
|
if (j < lonLatList.length) {
|
||||||
nogoWeight = lonLatList[j];
|
nogoWeight = lonLatList[j];
|
||||||
}
|
}
|
||||||
polygon.nogoWeight = Double.parseDouble( nogoWeight );
|
polygon.nogoWeight = Double.parseDouble(nogoWeight);
|
||||||
|
|
||||||
if ( polygon.points.size() > 0 )
|
if (polygon.points.size() > 0) {
|
||||||
{
|
|
||||||
polygon.calcBoundingCircle();
|
polygon.calcBoundingCircle();
|
||||||
result.add(polygon);
|
result.add(polygon);
|
||||||
}
|
}
|
||||||
|
@ -406,22 +382,20 @@ public class BRouterWorker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OsmNodeNamed> readPoisList(Bundle params )
|
private List<OsmNodeNamed> readPoisList(Bundle params) {
|
||||||
{
|
|
||||||
// lon,lat,name|...
|
// lon,lat,name|...
|
||||||
String pois = params.getString( "pois" );
|
String pois = params.getString("pois");
|
||||||
if ( pois == null ) return null;
|
if (pois == null) return null;
|
||||||
|
|
||||||
String[] lonLatNameList = pois.split("\\|");
|
String[] lonLatNameList = pois.split("\\|");
|
||||||
|
|
||||||
List<OsmNodeNamed> poisList = new ArrayList<OsmNodeNamed>();
|
List<OsmNodeNamed> poisList = new ArrayList<OsmNodeNamed>();
|
||||||
for (int i = 0; i < lonLatNameList.length; i++)
|
for (int i = 0; i < lonLatNameList.length; i++) {
|
||||||
{
|
|
||||||
String[] lonLatName = lonLatNameList[i].split(",");
|
String[] lonLatName = lonLatNameList[i].split(",");
|
||||||
|
|
||||||
OsmNodeNamed n = new OsmNodeNamed();
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
n.ilon = (int)( ( Double.parseDouble(lonLatName[0]) + 180. ) *1000000. + 0.5);
|
n.ilon = (int) ((Double.parseDouble(lonLatName[0]) + 180.) * 1000000. + 0.5);
|
||||||
n.ilat = (int)( ( Double.parseDouble(lonLatName[1]) + 90. ) *1000000. + 0.5);
|
n.ilat = (int) ((Double.parseDouble(lonLatName[1]) + 90.) * 1000000. + 0.5);
|
||||||
n.name = lonLatName[2];
|
n.name = lonLatName[2];
|
||||||
poisList.add(n);
|
poisList.add(n);
|
||||||
}
|
}
|
||||||
|
@ -429,27 +403,24 @@ public class BRouterWorker
|
||||||
return poisList;
|
return poisList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeTimeoutData( RoutingContext rc ) throws Exception
|
private void writeTimeoutData(RoutingContext rc) throws Exception {
|
||||||
{
|
|
||||||
String timeoutFile = baseDir + "/brouter/modes/timeoutdata.txt";
|
String timeoutFile = baseDir + "/brouter/modes/timeoutdata.txt";
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter( new FileWriter( timeoutFile ) );
|
BufferedWriter bw = new BufferedWriter(new FileWriter(timeoutFile));
|
||||||
bw.write( profileName );
|
bw.write(profileName);
|
||||||
bw.write( "\n" );
|
bw.write("\n");
|
||||||
bw.write( rc.rawTrackPath );
|
bw.write(rc.rawTrackPath);
|
||||||
bw.write( "\n" );
|
bw.write("\n");
|
||||||
writeWPList( bw, waypoints );
|
writeWPList(bw, waypoints);
|
||||||
writeWPList( bw, nogoList );
|
writeWPList(bw, nogoList);
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeWPList( BufferedWriter bw, List<OsmNodeNamed> wps ) throws Exception
|
private void writeWPList(BufferedWriter bw, List<OsmNodeNamed> wps) throws Exception {
|
||||||
{
|
bw.write(wps.size() + "\n");
|
||||||
bw.write( wps.size() + "\n" );
|
for (OsmNodeNamed wp : wps) {
|
||||||
for( OsmNodeNamed wp : wps )
|
bw.write(wp.toString());
|
||||||
{
|
bw.write("\n");
|
||||||
bw.write( wp.toString() );
|
|
||||||
bw.write( "\n" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,31 +10,25 @@ import java.io.File;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
public class ConfigHelper
|
public class ConfigHelper {
|
||||||
{
|
public static File getBaseDir(Context ctx) {
|
||||||
public static File getBaseDir( Context ctx )
|
|
||||||
{
|
|
||||||
// get base dir from private file
|
// get base dir from private file
|
||||||
|
|
||||||
try (InputStream configInput = ctx.openFileInput( "config15.dat" );
|
try (InputStream configInput = ctx.openFileInput("config15.dat");
|
||||||
InputStreamReader isr = new InputStreamReader( configInput );
|
InputStreamReader isr = new InputStreamReader(configInput);
|
||||||
BufferedReader br = new BufferedReader(isr)) {
|
BufferedReader br = new BufferedReader(isr)) {
|
||||||
return new File ( br.readLine() );
|
return new File(br.readLine());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeBaseDir( Context ctx, File baseDir )
|
public static void writeBaseDir(Context ctx, File baseDir) {
|
||||||
{
|
try (OutputStream configOutput = ctx.openFileOutput("config15.dat", Context.MODE_PRIVATE);
|
||||||
try (OutputStream configOutput = ctx.openFileOutput( "config15.dat", Context.MODE_PRIVATE );
|
OutputStreamWriter osw = new OutputStreamWriter(configOutput);
|
||||||
OutputStreamWriter osw = new OutputStreamWriter( configOutput );
|
BufferedWriter bw = new BufferedWriter(osw)) {
|
||||||
BufferedWriter bw = new BufferedWriter( osw)) {
|
bw.write(baseDir.getAbsolutePath());
|
||||||
bw.write( baseDir.getAbsolutePath () );
|
bw.write('\n');
|
||||||
bw.write( '\n' );
|
} catch (Exception e) { /* ignore */ }
|
||||||
}
|
|
||||||
catch (Exception e){ /* ignore */ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,136 +8,101 @@ import java.io.FileWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigMigration
|
public class ConfigMigration {
|
||||||
{
|
public static void tryMigrateStorageConfig(File srcFile, File dstFile) {
|
||||||
public static void tryMigrateStorageConfig( File srcFile, File dstFile )
|
if (!srcFile.exists()) return;
|
||||||
{
|
|
||||||
if ( !srcFile.exists() ) return;
|
|
||||||
|
|
||||||
String ssd = null;
|
String ssd = null;
|
||||||
String amd = null;
|
String amd = null;
|
||||||
|
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
BufferedWriter bw = null;
|
BufferedWriter bw = null;
|
||||||
try
|
try {
|
||||||
{
|
br = new BufferedReader(new FileReader(srcFile));
|
||||||
br = new BufferedReader( new FileReader( srcFile ) );
|
for (; ; ) {
|
||||||
for ( ;; )
|
|
||||||
{
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if ( line == null ) break;
|
if (line == null) break;
|
||||||
if ( line.trim().startsWith( "secondary_segment_dir=" ) )
|
if (line.trim().startsWith("secondary_segment_dir=")) {
|
||||||
{
|
if (!"secondary_segment_dir=../segments2".equals(line)) {
|
||||||
if ( !"secondary_segment_dir=../segments2".equals( line ) )
|
|
||||||
{
|
|
||||||
ssd = line;
|
ssd = line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( line.trim().startsWith( "additional_maptool_dir=" ) )
|
if (line.trim().startsWith("additional_maptool_dir=")) {
|
||||||
{
|
|
||||||
amd = line;
|
amd = line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
|
|
||||||
List<String> lines = new ArrayList<String>();
|
List<String> lines = new ArrayList<String>();
|
||||||
br = new BufferedReader( new FileReader( dstFile ) );
|
br = new BufferedReader(new FileReader(dstFile));
|
||||||
for ( ;; )
|
for (; ; ) {
|
||||||
{
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if ( line == null ) break;
|
if (line == null) break;
|
||||||
if ( ssd != null && line.trim().startsWith( "secondary_segment_dir=" ) )
|
if (ssd != null && line.trim().startsWith("secondary_segment_dir=")) {
|
||||||
{
|
|
||||||
line = ssd;
|
line = ssd;
|
||||||
}
|
}
|
||||||
if ( amd != null && line.trim().startsWith( "#additional_maptool_dir=" ) )
|
if (amd != null && line.trim().startsWith("#additional_maptool_dir=")) {
|
||||||
{
|
|
||||||
line = amd;
|
line = amd;
|
||||||
}
|
}
|
||||||
lines.add( line );
|
lines.add(line);
|
||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
br = null;
|
br = null;
|
||||||
|
|
||||||
bw = new BufferedWriter( new FileWriter( dstFile ) );
|
bw = new BufferedWriter(new FileWriter(dstFile));
|
||||||
for( String line: lines )
|
for (String line : lines) {
|
||||||
{
|
bw.write(line + "\n");
|
||||||
bw.write( line + "\n" );
|
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) { /* ignore */ } finally {
|
||||||
catch (Exception e) { /* ignore */ }
|
if (br != null) {
|
||||||
finally
|
try {
|
||||||
{
|
|
||||||
if ( br != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
br.close();
|
br.close();
|
||||||
|
} catch (Exception ee) { /* ignore */ }
|
||||||
}
|
}
|
||||||
catch (Exception ee) { /* ignore */ }
|
if (bw != null) {
|
||||||
}
|
try {
|
||||||
if ( bw != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
} catch (Exception ee) { /* ignore */ }
|
||||||
catch (Exception ee) { /* ignore */ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File saveAdditionalMaptoolDir( File segmentDir, String value )
|
public static File saveAdditionalMaptoolDir(File segmentDir, String value) {
|
||||||
{
|
return saveStorageLocation(segmentDir, "additional_maptool_dir=", value);
|
||||||
return saveStorageLocation( segmentDir, "additional_maptool_dir=", value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File saveStorageLocation( File segmentDir, String tag, String value )
|
private static File saveStorageLocation(File segmentDir, String tag, String value) {
|
||||||
{
|
|
||||||
File res = null;
|
File res = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
BufferedWriter bw = null;
|
BufferedWriter bw = null;
|
||||||
File configFile = new File (segmentDir, "storageconfig.txt");
|
File configFile = new File(segmentDir, "storageconfig.txt");
|
||||||
List<String> lines = new ArrayList<String>();
|
List<String> lines = new ArrayList<String>();
|
||||||
try
|
try {
|
||||||
{
|
br = new BufferedReader(new FileReader(configFile));
|
||||||
br = new BufferedReader( new FileReader( configFile ) );
|
for (; ; ) {
|
||||||
for ( ;; )
|
|
||||||
{
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if ( line == null ) break;
|
if (line == null) break;
|
||||||
if ( !line.trim().startsWith( tag ) )
|
if (!line.trim().startsWith(tag)) {
|
||||||
{
|
lines.add(line);
|
||||||
lines.add( line );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines.add( tag + value );
|
lines.add(tag + value);
|
||||||
br.close();
|
br.close();
|
||||||
br = null;
|
br = null;
|
||||||
bw = new BufferedWriter( new FileWriter( configFile ) );
|
bw = new BufferedWriter(new FileWriter(configFile));
|
||||||
for( String line : lines )
|
for (String line : lines) {
|
||||||
{
|
bw.write(line + "\r\n");
|
||||||
bw.write( line + "\r\n" );
|
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) { /* ignore */ } finally {
|
||||||
catch (Exception e) { /* ignore */ }
|
if (br != null) {
|
||||||
finally
|
try {
|
||||||
{
|
|
||||||
if ( br != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
br.close();
|
br.close();
|
||||||
|
} catch (Exception ee) { /* ignore */ }
|
||||||
}
|
}
|
||||||
catch (Exception ee) { /* ignore */ }
|
if (bw != null) {
|
||||||
}
|
try {
|
||||||
if ( bw != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
} catch (Exception ee) { /* ignore */ }
|
||||||
catch (Exception ee) { /* ignore */ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -11,14 +11,14 @@ import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import btools.router.OsmNodeNamed;
|
import btools.router.OsmNodeNamed;
|
||||||
import btools.router.RoutingHelper;
|
import btools.router.RoutingHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read coordinates from a gpx-file
|
* Read coordinates from a gpx-file
|
||||||
*/
|
*/
|
||||||
public abstract class CoordinateReader
|
public abstract class CoordinateReader {
|
||||||
{
|
|
||||||
public List<OsmNodeNamed> waypoints;
|
public List<OsmNodeNamed> waypoints;
|
||||||
public List<OsmNodeNamed> nogopoints;
|
public List<OsmNodeNamed> nogopoints;
|
||||||
public String basedir;
|
public String basedir;
|
||||||
|
@ -27,16 +27,15 @@ public abstract class CoordinateReader
|
||||||
|
|
||||||
private boolean nogosOnly;
|
private boolean nogosOnly;
|
||||||
|
|
||||||
private Map<String,Map<String, OsmNodeNamed>> allpointsMap;
|
private Map<String, Map<String, OsmNodeNamed>> allpointsMap;
|
||||||
public List<OsmNodeNamed> allpoints;
|
public List<OsmNodeNamed> allpoints;
|
||||||
|
|
||||||
private HashMap<String,OsmNodeNamed> pointmap;
|
private HashMap<String, OsmNodeNamed> pointmap;
|
||||||
|
|
||||||
protected static String[] posnames
|
protected static String[] posnames
|
||||||
= new String[]{ "from", "via1", "via2", "via3", "via4", "via5", "via6", "via7", "via8", "via9", "to" };
|
= new String[]{"from", "via1", "via2", "via3", "via4", "via5", "via6", "via7", "via8", "via9", "to"};
|
||||||
|
|
||||||
public CoordinateReader( String basedir )
|
public CoordinateReader(String basedir) {
|
||||||
{
|
|
||||||
this.basedir = basedir;
|
this.basedir = basedir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,30 +43,23 @@ public abstract class CoordinateReader
|
||||||
|
|
||||||
public abstract int getTurnInstructionMode();
|
public abstract int getTurnInstructionMode();
|
||||||
|
|
||||||
public void readAllPoints() throws Exception
|
public void readAllPoints() throws Exception {
|
||||||
{
|
allpointsMap = new TreeMap<String, Map<String, OsmNodeNamed>>();
|
||||||
allpointsMap = new TreeMap<String, Map<String,OsmNodeNamed>>();
|
|
||||||
readFromTo();
|
readFromTo();
|
||||||
allpoints = new ArrayList<OsmNodeNamed>();
|
allpoints = new ArrayList<OsmNodeNamed>();
|
||||||
Set<String> names = new HashSet<String>();
|
Set<String> names = new HashSet<String>();
|
||||||
for( String category : allpointsMap.keySet() )
|
for (String category : allpointsMap.keySet()) {
|
||||||
{
|
Map<String, OsmNodeNamed> cat = allpointsMap.get(category);
|
||||||
Map<String, OsmNodeNamed> cat = allpointsMap.get( category );
|
if (cat.size() < 101) {
|
||||||
if ( cat.size() < 101 )
|
for (OsmNodeNamed wp : cat.values()) {
|
||||||
{
|
if (names.add(wp.name)) {
|
||||||
for ( OsmNodeNamed wp : cat.values() )
|
allpoints.add(wp);
|
||||||
{
|
|
||||||
if ( names.add( wp.name ) )
|
|
||||||
{
|
|
||||||
allpoints.add( wp );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
OsmNodeNamed nocatHint = new OsmNodeNamed();
|
OsmNodeNamed nocatHint = new OsmNodeNamed();
|
||||||
nocatHint.name = "<big category " + category + " supressed>";
|
nocatHint.name = "<big category " + category + " supressed>";
|
||||||
allpoints.add( nocatHint);
|
allpoints.add(nocatHint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,73 +67,57 @@ public abstract class CoordinateReader
|
||||||
/*
|
/*
|
||||||
* read the from, to and via-positions from a gpx-file
|
* read the from, to and via-positions from a gpx-file
|
||||||
*/
|
*/
|
||||||
public void readFromTo() throws Exception
|
public void readFromTo() throws Exception {
|
||||||
{
|
pointmap = new HashMap<String, OsmNodeNamed>();
|
||||||
pointmap = new HashMap<String,OsmNodeNamed>();
|
|
||||||
waypoints = new ArrayList<OsmNodeNamed>();
|
waypoints = new ArrayList<OsmNodeNamed>();
|
||||||
nogopoints = new ArrayList<OsmNodeNamed>();
|
nogopoints = new ArrayList<OsmNodeNamed>();
|
||||||
readPointmap();
|
readPointmap();
|
||||||
boolean fromToMissing = false;
|
boolean fromToMissing = false;
|
||||||
for( int i=0; i<posnames.length; i++ )
|
for (int i = 0; i < posnames.length; i++) {
|
||||||
{
|
|
||||||
String name = posnames[i];
|
String name = posnames[i];
|
||||||
OsmNodeNamed n = pointmap.get(name);
|
OsmNodeNamed n = pointmap.get(name);
|
||||||
if ( n != null )
|
if (n != null) {
|
||||||
{
|
waypoints.add(n);
|
||||||
waypoints.add( n );
|
} else {
|
||||||
}
|
if ("from".equals(name)) fromToMissing = true;
|
||||||
else
|
if ("to".equals(name)) fromToMissing = true;
|
||||||
{
|
|
||||||
if ( "from".equals( name ) ) fromToMissing = true;
|
|
||||||
if ( "to".equals( name ) ) fromToMissing = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( fromToMissing ) waypoints.clear();
|
if (fromToMissing) waypoints.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkAddPoint( String category, OsmNodeNamed n )
|
protected void checkAddPoint(String category, OsmNodeNamed n) {
|
||||||
{
|
if (allpointsMap != null) {
|
||||||
if ( allpointsMap != null )
|
if (category == null) category = "";
|
||||||
{
|
Map<String, OsmNodeNamed> cat = allpointsMap.get(category);
|
||||||
if ( category == null ) category = "";
|
if (cat == null) {
|
||||||
Map<String, OsmNodeNamed> cat = allpointsMap.get( category );
|
|
||||||
if ( cat == null )
|
|
||||||
{
|
|
||||||
cat = new TreeMap<String, OsmNodeNamed>();
|
cat = new TreeMap<String, OsmNodeNamed>();
|
||||||
allpointsMap.put( category, cat );
|
allpointsMap.put(category, cat);
|
||||||
}
|
}
|
||||||
if ( cat.size() < 101 )
|
if (cat.size() < 101) {
|
||||||
{
|
cat.put(n.name, n);
|
||||||
cat.put( n.name, n );
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isKnown = false;
|
boolean isKnown = false;
|
||||||
for( int i=0; i<posnames.length; i++ )
|
for (int i = 0; i < posnames.length; i++) {
|
||||||
{
|
if (posnames[i].equals(n.name)) {
|
||||||
if ( posnames[i].equals( n.name ) )
|
|
||||||
{
|
|
||||||
isKnown = true;
|
isKnown = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isKnown )
|
if (isKnown) {
|
||||||
{
|
if (pointmap.put(n.name, n) != null) {
|
||||||
if ( pointmap.put( n.name, n ) != null )
|
if (!nogosOnly) {
|
||||||
{
|
throw new IllegalArgumentException("multiple " + n.name + "-positions!");
|
||||||
if ( !nogosOnly )
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException( "multiple " + n.name + "-positions!" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (n.name != null && n.name.startsWith("nogo")) {
|
||||||
else if ( n.name != null && n.name.startsWith( "nogo" ) )
|
|
||||||
{
|
|
||||||
n.isNogo = true;
|
n.isNogo = true;
|
||||||
n.nogoWeight = Double.NaN;
|
n.nogoWeight = Double.NaN;
|
||||||
nogopoints.add( n );
|
nogopoints.add(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -149,13 +125,11 @@ public abstract class CoordinateReader
|
||||||
protected abstract void readPointmap() throws Exception;
|
protected abstract void readPointmap() throws Exception;
|
||||||
|
|
||||||
|
|
||||||
public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean canAccessSdCard ) throws Exception
|
public static CoordinateReader obtainValidReader(String basedir, File segmentDir, boolean canAccessSdCard) throws Exception {
|
||||||
{
|
return obtainValidReader(basedir, segmentDir, canAccessSdCard, false);
|
||||||
return obtainValidReader( basedir, segmentDir, canAccessSdCard, false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean canAccessSdCard, 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>();
|
||||||
|
|
||||||
|
@ -210,8 +184,7 @@ public abstract class CoordinateReader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( cor == null )
|
if (cor == null) {
|
||||||
{
|
|
||||||
cor = new CoordinateReaderInternal(basedir);
|
cor = new CoordinateReaderInternal(basedir);
|
||||||
}
|
}
|
||||||
cor.nogosOnly = nogosOnly;
|
cor.nogosOnly = nogosOnly;
|
||||||
|
|
|
@ -21,26 +21,20 @@ import btools.router.OsmNogoPolygon;
|
||||||
/**
|
/**
|
||||||
* Read coordinates from a gpx-file
|
* Read coordinates from a gpx-file
|
||||||
*/
|
*/
|
||||||
public class CoordinateReaderInternal extends CoordinateReader
|
public class CoordinateReaderInternal extends CoordinateReader {
|
||||||
{
|
|
||||||
private String internalDir;
|
private String internalDir;
|
||||||
|
|
||||||
public CoordinateReaderInternal(String basedir )
|
public CoordinateReaderInternal(String basedir) {
|
||||||
{
|
this(basedir, false);
|
||||||
this( basedir, false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoordinateReaderInternal(String basedir, boolean shortPath )
|
public CoordinateReaderInternal(String basedir, boolean shortPath) {
|
||||||
{
|
super(basedir);
|
||||||
super( basedir );
|
if (shortPath) {
|
||||||
if ( shortPath )
|
|
||||||
{
|
|
||||||
internalDir = basedir;
|
internalDir = basedir;
|
||||||
tracksdir = "/tracks";
|
tracksdir = "/tracks";
|
||||||
rootdir = "";
|
rootdir = "";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
internalDir = basedir + "/brouter/import";
|
internalDir = basedir + "/brouter/import";
|
||||||
tracksdir = "/brouter/import/tracks";
|
tracksdir = "/brouter/import/tracks";
|
||||||
rootdir = "/brouter/import";
|
rootdir = "/brouter/import";
|
||||||
|
@ -48,16 +42,14 @@ public class CoordinateReaderInternal extends CoordinateReader
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTimeStamp() throws Exception
|
public long getTimeStamp() throws Exception {
|
||||||
{
|
long t1 = new File(internalDir + "/favourites_bak.gpx").lastModified();
|
||||||
long t1 = new File( internalDir + "/favourites_bak.gpx" ).lastModified();
|
long t2 = new File(internalDir + "/favourites.gpx").lastModified();
|
||||||
long t2 = new File( internalDir + "/favourites.gpx" ).lastModified();
|
|
||||||
return t1 > t2 ? t1 : t2;
|
return t1 > t2 ? t1 : t2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTurnInstructionMode()
|
public int getTurnInstructionMode() {
|
||||||
{
|
|
||||||
return 4; // comment style
|
return 4; // comment style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,62 +58,53 @@ public class CoordinateReaderInternal extends CoordinateReader
|
||||||
* (with hardcoded name for now)
|
* (with hardcoded name for now)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readPointmap() throws Exception
|
public void readPointmap() throws Exception {
|
||||||
{
|
if (!_readPointmap(internalDir + "/favourites_bak.gpx")) {
|
||||||
if (! _readPointmap( internalDir + "/favourites_bak.gpx" ) ) {
|
_readPointmap(internalDir + "/favourites.gpx");
|
||||||
_readPointmap( internalDir + "/favourites.gpx" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
_readNogoLines(basedir + tracksdir);
|
||||||
_readNogoLines( basedir+tracksdir );
|
} catch (IOException ioe) {
|
||||||
}
|
|
||||||
catch( IOException ioe )
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean _readPointmap( String filename ) throws Exception
|
private boolean _readPointmap(String filename) throws Exception {
|
||||||
{
|
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
try {
|
try {
|
||||||
br = new BufferedReader(
|
br = new BufferedReader(
|
||||||
new InputStreamReader(
|
new InputStreamReader(
|
||||||
new FileInputStream( filename ) ) );
|
new FileInputStream(filename)));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
// ignore until it's reading error
|
// ignore until it's reading error
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OsmNodeNamed n = null;
|
OsmNodeNamed n = null;
|
||||||
|
|
||||||
for(;;)
|
for (; ; ) {
|
||||||
{
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if ( line == null ) break;
|
if (line == null) break;
|
||||||
|
|
||||||
int idx0 = line.indexOf( " lat=\"" );
|
int idx0 = line.indexOf(" lat=\"");
|
||||||
int idx10 = line.indexOf( "<name>" );
|
int idx10 = line.indexOf("<name>");
|
||||||
if ( idx0 >= 0 )
|
if (idx0 >= 0) {
|
||||||
{
|
|
||||||
n = new OsmNodeNamed();
|
n = new OsmNodeNamed();
|
||||||
idx0 += 6;
|
idx0 += 6;
|
||||||
int idx1 = line.indexOf( '"', idx0 );
|
int idx1 = line.indexOf('"', idx0);
|
||||||
n.ilat = (int)( (Double.parseDouble( line.substring( idx0, idx1 ) ) + 90. )*1000000. + 0.5);
|
n.ilat = (int) ((Double.parseDouble(line.substring(idx0, idx1)) + 90.) * 1000000. + 0.5);
|
||||||
int idx2 = line.indexOf( " lon=\"" );
|
int idx2 = line.indexOf(" lon=\"");
|
||||||
if ( idx2 < 0 ) continue;
|
if (idx2 < 0) continue;
|
||||||
idx2 += 6;
|
idx2 += 6;
|
||||||
int idx3 = line.indexOf( '"', idx2 );
|
int idx3 = line.indexOf('"', idx2);
|
||||||
n.ilon = (int)( ( Double.parseDouble( line.substring( idx2, idx3 ) ) + 180. )*1000000. + 0.5);
|
n.ilon = (int) ((Double.parseDouble(line.substring(idx2, idx3)) + 180.) * 1000000. + 0.5);
|
||||||
if ( idx3 < 0 ) continue;
|
if (idx3 < 0) continue;
|
||||||
}
|
}
|
||||||
if ( n != null && idx10 >= 0 )
|
if (n != null && idx10 >= 0) {
|
||||||
{
|
|
||||||
idx10 += 6;
|
idx10 += 6;
|
||||||
int idx11 = line.indexOf( "</name>", idx10 );
|
int idx11 = line.indexOf("</name>", idx10);
|
||||||
if ( idx11 >= 0 )
|
if (idx11 >= 0) {
|
||||||
{
|
n.name = line.substring(idx10, idx11).trim();
|
||||||
n.name = line.substring( idx10, idx11 ).trim();
|
checkAddPoint("(one-for-all)", n);
|
||||||
checkAddPoint( "(one-for-all)", n );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,32 +112,24 @@ public class CoordinateReaderInternal extends CoordinateReader
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _readNogoLines( String dirname ) throws IOException
|
private void _readNogoLines(String dirname) throws IOException {
|
||||||
{
|
|
||||||
|
|
||||||
File dir = new File( dirname );
|
File dir = new File(dirname);
|
||||||
|
|
||||||
if (dir.exists() && dir.isDirectory())
|
if (dir.exists() && dir.isDirectory()) {
|
||||||
{
|
for (final File file : dir.listFiles()) {
|
||||||
for (final File file : dir.listFiles())
|
|
||||||
{
|
|
||||||
final String name = file.getName();
|
final String name = file.getName();
|
||||||
if (name.startsWith("nogo") && name.endsWith(".gpx"))
|
if (name.startsWith("nogo") && name.endsWith(".gpx")) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
_readNogoLine(file);
|
_readNogoLine(file);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _readNogoLine( File file ) throws Exception
|
private void _readNogoLine(File file) throws Exception {
|
||||||
{
|
|
||||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||||
factory.setNamespaceAware(false);
|
factory.setNamespaceAware(false);
|
||||||
XmlPullParser xpp = factory.newPullParser();
|
XmlPullParser xpp = factory.newPullParser();
|
||||||
|
@ -165,15 +140,15 @@ public class CoordinateReaderInternal extends CoordinateReader
|
||||||
int eventType = xpp.getEventType();
|
int eventType = xpp.getEventType();
|
||||||
int numSeg = 0;
|
int numSeg = 0;
|
||||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||||
switch(eventType) {
|
switch (eventType) {
|
||||||
case XmlPullParser.START_TAG: {
|
case XmlPullParser.START_TAG: {
|
||||||
if (xpp.getName().equals("trkpt") || xpp.getName().equals("rtept")) {
|
if (xpp.getName().equals("trkpt") || xpp.getName().equals("rtept")) {
|
||||||
final String lon = xpp.getAttributeValue(null,"lon");
|
final String lon = xpp.getAttributeValue(null, "lon");
|
||||||
final String lat = xpp.getAttributeValue(null,"lat");
|
final String lat = xpp.getAttributeValue(null, "lat");
|
||||||
if (lon != null && lat != null) {
|
if (lon != null && lat != null) {
|
||||||
tmpPts.add(new Point(
|
tmpPts.add(new Point(
|
||||||
(int)( ( Double.parseDouble(lon) + 180. ) *1000000. + 0.5),
|
(int) ((Double.parseDouble(lon) + 180.) * 1000000. + 0.5),
|
||||||
(int)( ( Double.parseDouble(lat) + 90. ) *1000000. + 0.5)) );
|
(int) ((Double.parseDouble(lat) + 90.) * 1000000. + 0.5)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -182,8 +157,8 @@ public class CoordinateReaderInternal extends CoordinateReader
|
||||||
if (xpp.getName().equals("trkseg") || xpp.getName().equals("rte")) { // rte has no segment
|
if (xpp.getName().equals("trkseg") || xpp.getName().equals("rte")) { // rte has no segment
|
||||||
OsmNogoPolygon nogo = null;
|
OsmNogoPolygon nogo = null;
|
||||||
if (tmpPts.size() >= 0) {
|
if (tmpPts.size() >= 0) {
|
||||||
if (tmpPts.get(0).x == tmpPts.get(tmpPts.size()-1).x &&
|
if (tmpPts.get(0).x == tmpPts.get(tmpPts.size() - 1).x &&
|
||||||
tmpPts.get(0).y == tmpPts.get(tmpPts.size()-1).y) {
|
tmpPts.get(0).y == tmpPts.get(tmpPts.size() - 1).y) {
|
||||||
nogo = new OsmNogoPolygon(true);
|
nogo = new OsmNogoPolygon(true);
|
||||||
} else {
|
} else {
|
||||||
nogo = new OsmNogoPolygon(false);
|
nogo = new OsmNogoPolygon(false);
|
||||||
|
|
|
@ -4,24 +4,22 @@ import java.io.File;
|
||||||
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
import btools.router.OsmNodeNamed;
|
import btools.router.OsmNodeNamed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read coordinates from a gpx-file
|
* Read coordinates from a gpx-file
|
||||||
*/
|
*/
|
||||||
public class CoordinateReaderLocus extends CoordinateReader
|
public class CoordinateReaderLocus extends CoordinateReader {
|
||||||
{
|
public CoordinateReaderLocus(String basedir) {
|
||||||
public CoordinateReaderLocus( String basedir )
|
super(basedir);
|
||||||
{
|
|
||||||
super( basedir );
|
|
||||||
tracksdir = "/Locus/mapItems";
|
tracksdir = "/Locus/mapItems";
|
||||||
rootdir = "/Locus";
|
rootdir = "/Locus";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTimeStamp() throws Exception
|
public long getTimeStamp() throws Exception {
|
||||||
{
|
File f = new File(basedir + "/Locus/data/database/waypoints.db");
|
||||||
File f = new File( basedir + "/Locus/data/database/waypoints.db" );
|
|
||||||
long t1 = f.lastModified();
|
long t1 = f.lastModified();
|
||||||
// Android 10 delivers file size but can't read it
|
// Android 10 delivers file size but can't read it
|
||||||
boolean canRead = f.canRead();
|
boolean canRead = f.canRead();
|
||||||
|
@ -29,8 +27,7 @@ public class CoordinateReaderLocus extends CoordinateReader
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTurnInstructionMode()
|
public int getTurnInstructionMode() {
|
||||||
{
|
|
||||||
return 2; // locus style
|
return 2; // locus style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,16 +36,14 @@ public class CoordinateReaderLocus extends CoordinateReader
|
||||||
* (with hardcoded name for now)
|
* (with hardcoded name for now)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readPointmap() throws Exception
|
public void readPointmap() throws Exception {
|
||||||
{
|
_readPointmap(basedir + "/Locus/data/database/waypoints.db");
|
||||||
_readPointmap( basedir + "/Locus/data/database/waypoints.db" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _readPointmap( String filename ) throws Exception
|
private void _readPointmap(String filename) throws Exception {
|
||||||
{
|
|
||||||
SQLiteDatabase myDataBase = null;
|
SQLiteDatabase myDataBase = null;
|
||||||
try {
|
try {
|
||||||
myDataBase = SQLiteDatabase.openDatabase( filename, null, SQLiteDatabase.OPEN_READONLY);
|
myDataBase = SQLiteDatabase.openDatabase(filename, null, SQLiteDatabase.OPEN_READONLY);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// not open, do not produce an error
|
// not open, do not produce an error
|
||||||
return;
|
return;
|
||||||
|
@ -57,16 +52,15 @@ public class CoordinateReaderLocus extends CoordinateReader
|
||||||
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);
|
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) {
|
if (c.getCount() == 0) {
|
||||||
c.close();
|
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 );
|
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())
|
while (c.moveToNext()) {
|
||||||
{
|
|
||||||
OsmNodeNamed n = new OsmNodeNamed();
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
String category = c.getString(0);
|
String category = c.getString(0);
|
||||||
n.name = c.getString(1);
|
n.name = c.getString(1);
|
||||||
n.ilon = (int)( ( c.getDouble(2) + 180. )*1000000. + 0.5);
|
n.ilon = (int) ((c.getDouble(2) + 180.) * 1000000. + 0.5);
|
||||||
n.ilat = (int)( ( c.getDouble(3) + 90. )*1000000. + 0.5);
|
n.ilat = (int) ((c.getDouble(3) + 90.) * 1000000. + 0.5);
|
||||||
checkAddPoint( category, n );
|
checkAddPoint(category, n);
|
||||||
}
|
}
|
||||||
c.close();
|
c.close();
|
||||||
myDataBase.close();
|
myDataBase.close();
|
||||||
|
|
|
@ -4,24 +4,22 @@ import java.io.File;
|
||||||
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
import btools.router.OsmNodeNamed;
|
import btools.router.OsmNodeNamed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read coordinates from a gpx-file
|
* Read coordinates from a gpx-file
|
||||||
*/
|
*/
|
||||||
public class CoordinateReaderOrux extends CoordinateReader
|
public class CoordinateReaderOrux extends CoordinateReader {
|
||||||
{
|
public CoordinateReaderOrux(String basedir) {
|
||||||
public CoordinateReaderOrux( String basedir )
|
super(basedir);
|
||||||
{
|
|
||||||
super( basedir );
|
|
||||||
tracksdir = "/oruxmaps/tracklogs";
|
tracksdir = "/oruxmaps/tracklogs";
|
||||||
rootdir = "/oruxmaps";
|
rootdir = "/oruxmaps";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTimeStamp() throws Exception
|
public long getTimeStamp() throws Exception {
|
||||||
{
|
File f = new File(basedir + "/oruxmaps/tracklogs/oruxmapstracks.db");
|
||||||
File f = new File( basedir + "/oruxmaps/tracklogs/oruxmapstracks.db" );
|
|
||||||
long t1 = f.lastModified();
|
long t1 = f.lastModified();
|
||||||
// Android 10 delivers file size but can't read it
|
// Android 10 delivers file size but can't read it
|
||||||
boolean canRead = f.canRead();
|
boolean canRead = f.canRead();
|
||||||
|
@ -29,8 +27,7 @@ public class CoordinateReaderOrux extends CoordinateReader
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTurnInstructionMode()
|
public int getTurnInstructionMode() {
|
||||||
{
|
|
||||||
return 0; // none
|
return 0; // none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,29 +36,26 @@ public class CoordinateReaderOrux extends CoordinateReader
|
||||||
* (with hardcoded name for now)
|
* (with hardcoded name for now)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readPointmap() throws Exception
|
public void readPointmap() throws Exception {
|
||||||
{
|
_readPointmap(basedir + "/oruxmaps/tracklogs/oruxmapstracks.db");
|
||||||
_readPointmap( basedir + "/oruxmaps/tracklogs/oruxmapstracks.db" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _readPointmap( String filename ) throws Exception
|
private void _readPointmap(String filename) throws Exception {
|
||||||
{
|
|
||||||
SQLiteDatabase myDataBase = null;
|
SQLiteDatabase myDataBase = null;
|
||||||
try {
|
try {
|
||||||
myDataBase = SQLiteDatabase.openDatabase( filename, null, SQLiteDatabase.OPEN_READONLY);
|
myDataBase = SQLiteDatabase.openDatabase(filename, null, SQLiteDatabase.OPEN_READONLY);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// not open, do not produce an error
|
// not open, do not produce an error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cursor c = myDataBase.rawQuery("SELECT poiname, poilon, poilat, poifolder FROM pois", null);
|
Cursor c = myDataBase.rawQuery("SELECT poiname, poilon, poilat, poifolder FROM pois", null);
|
||||||
while (c.moveToNext())
|
while (c.moveToNext()) {
|
||||||
{
|
|
||||||
OsmNodeNamed n = new OsmNodeNamed();
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
n.name = c.getString(0);
|
n.name = c.getString(0);
|
||||||
n.ilon = (int)( ( c.getDouble(1) + 180. )*1000000. + 0.5);
|
n.ilon = (int) ((c.getDouble(1) + 180.) * 1000000. + 0.5);
|
||||||
n.ilat = (int)( ( c.getDouble(2) + 90. )*1000000. + 0.5);
|
n.ilat = (int) ((c.getDouble(2) + 90.) * 1000000. + 0.5);
|
||||||
String category = c.getString(3);
|
String category = c.getString(3);
|
||||||
checkAddPoint( category, n );
|
checkAddPoint(category, n);
|
||||||
}
|
}
|
||||||
c.close();
|
c.close();
|
||||||
myDataBase.close();
|
myDataBase.close();
|
||||||
|
|
|
@ -16,26 +16,20 @@ import btools.router.OsmNogoPolygon;
|
||||||
/**
|
/**
|
||||||
* Read coordinates from a gpx-file
|
* Read coordinates from a gpx-file
|
||||||
*/
|
*/
|
||||||
public class CoordinateReaderOsmAnd extends CoordinateReader
|
public class CoordinateReaderOsmAnd extends CoordinateReader {
|
||||||
{
|
|
||||||
private String osmandDir;
|
private String osmandDir;
|
||||||
|
|
||||||
public CoordinateReaderOsmAnd( String basedir )
|
public CoordinateReaderOsmAnd(String basedir) {
|
||||||
{
|
this(basedir, false);
|
||||||
this( basedir, false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoordinateReaderOsmAnd( String basedir, boolean shortPath )
|
public CoordinateReaderOsmAnd(String basedir, boolean shortPath) {
|
||||||
{
|
super(basedir);
|
||||||
super( basedir );
|
if (shortPath) {
|
||||||
if ( shortPath )
|
|
||||||
{
|
|
||||||
osmandDir = basedir;
|
osmandDir = basedir;
|
||||||
tracksdir = "/tracks";
|
tracksdir = "/tracks";
|
||||||
rootdir = "";
|
rootdir = "";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
osmandDir = basedir + "/osmand";
|
osmandDir = basedir + "/osmand";
|
||||||
tracksdir = "/osmand/tracks";
|
tracksdir = "/osmand/tracks";
|
||||||
rootdir = "/osmand";
|
rootdir = "/osmand";
|
||||||
|
@ -43,18 +37,16 @@ public class CoordinateReaderOsmAnd extends CoordinateReader
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTimeStamp() throws Exception
|
public long getTimeStamp() throws Exception {
|
||||||
{
|
File f1 = new File(osmandDir + "/favourites_bak.gpx");
|
||||||
File f1 = new File( osmandDir + "/favourites_bak.gpx" );
|
File f2 = new File(osmandDir + "/favourites.gpx");
|
||||||
File f2 = new File( osmandDir + "/favourites.gpx" );
|
long t1 = f1.canRead() ? f1.lastModified() : 0L;
|
||||||
long t1 = f1.canRead()?f1.lastModified():0L;
|
long t2 = f2.canRead() ? f2.lastModified() : 0L;
|
||||||
long t2 = f2.canRead()?f2.lastModified():0L;
|
|
||||||
return t1 > t2 ? t1 : t2;
|
return t1 > t2 ? t1 : t2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTurnInstructionMode()
|
public int getTurnInstructionMode() {
|
||||||
{
|
|
||||||
return 3; // osmand style
|
return 3; // osmand style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,92 +55,72 @@ public class CoordinateReaderOsmAnd extends CoordinateReader
|
||||||
* (with hardcoded name for now)
|
* (with hardcoded name for now)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readPointmap() throws Exception
|
public void readPointmap() throws Exception {
|
||||||
{
|
try {
|
||||||
try
|
_readPointmap(osmandDir + "/favourites_bak.gpx");
|
||||||
{
|
} catch (Exception e) {
|
||||||
_readPointmap( osmandDir + "/favourites_bak.gpx" );
|
_readPointmap(osmandDir + "/favourites.gpx");
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
try {
|
||||||
{
|
_readNogoLines(basedir + tracksdir);
|
||||||
_readPointmap( osmandDir + "/favourites.gpx" );
|
} catch (IOException ioe) {
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_readNogoLines( basedir+tracksdir );
|
|
||||||
}
|
|
||||||
catch( IOException ioe )
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _readPointmap( String filename ) throws Exception
|
private void _readPointmap(String filename) throws Exception {
|
||||||
{
|
|
||||||
BufferedReader br = new BufferedReader(
|
BufferedReader br = new BufferedReader(
|
||||||
new InputStreamReader(
|
new InputStreamReader(
|
||||||
new FileInputStream( filename ) ) );
|
new FileInputStream(filename)));
|
||||||
OsmNodeNamed n = null;
|
OsmNodeNamed n = null;
|
||||||
|
|
||||||
for(;;)
|
for (; ; ) {
|
||||||
{
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if ( line == null ) break;
|
if (line == null) break;
|
||||||
|
|
||||||
int idx0 = line.indexOf( "<wpt lat=\"" );
|
int idx0 = line.indexOf("<wpt lat=\"");
|
||||||
int idx10 = line.indexOf( "<name>" );
|
int idx10 = line.indexOf("<name>");
|
||||||
if ( idx0 >= 0 )
|
if (idx0 >= 0) {
|
||||||
{
|
|
||||||
n = new OsmNodeNamed();
|
n = new OsmNodeNamed();
|
||||||
idx0 += 10;
|
idx0 += 10;
|
||||||
int idx1 = line.indexOf( '"', idx0 );
|
int idx1 = line.indexOf('"', idx0);
|
||||||
n.ilat = (int)( (Double.parseDouble( line.substring( idx0, idx1 ) ) + 90. )*1000000. + 0.5);
|
n.ilat = (int) ((Double.parseDouble(line.substring(idx0, idx1)) + 90.) * 1000000. + 0.5);
|
||||||
int idx2 = line.indexOf( " lon=\"" );
|
int idx2 = line.indexOf(" lon=\"");
|
||||||
if ( idx2 < 0 ) continue;
|
if (idx2 < 0) continue;
|
||||||
idx2 += 6;
|
idx2 += 6;
|
||||||
int idx3 = line.indexOf( '"', idx2 );
|
int idx3 = line.indexOf('"', idx2);
|
||||||
n.ilon = (int)( ( Double.parseDouble( line.substring( idx2, idx3 ) ) + 180. )*1000000. + 0.5);
|
n.ilon = (int) ((Double.parseDouble(line.substring(idx2, idx3)) + 180.) * 1000000. + 0.5);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( n != null && idx10 >= 0 )
|
if (n != null && idx10 >= 0) {
|
||||||
{
|
|
||||||
idx10 += 6;
|
idx10 += 6;
|
||||||
int idx11 = line.indexOf( "</name>", idx10 );
|
int idx11 = line.indexOf("</name>", idx10);
|
||||||
if ( idx11 >= 0 )
|
if (idx11 >= 0) {
|
||||||
{
|
n.name = line.substring(idx10, idx11).trim();
|
||||||
n.name = line.substring( idx10, idx11 ).trim();
|
checkAddPoint("(one-for-all)", n);
|
||||||
checkAddPoint( "(one-for-all)", n );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _readNogoLines( String dirname ) throws IOException
|
private void _readNogoLines(String dirname) throws IOException {
|
||||||
{
|
|
||||||
|
|
||||||
File dir = new File( dirname );
|
File dir = new File(dirname);
|
||||||
|
|
||||||
if (dir.exists() && dir.isDirectory())
|
if (dir.exists() && dir.isDirectory()) {
|
||||||
{
|
for (final File file : dir.listFiles()) {
|
||||||
for (final File file : dir.listFiles())
|
|
||||||
{
|
|
||||||
final String name = file.getName();
|
final String name = file.getName();
|
||||||
if (name.startsWith("nogo") && name.endsWith(".gpx"))
|
if (name.startsWith("nogo") && name.endsWith(".gpx")) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
_readNogoLine(file);
|
_readNogoLine(file);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _readNogoLine( File file ) throws Exception
|
private void _readNogoLine(File file) throws Exception {
|
||||||
{
|
|
||||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||||
factory.setNamespaceAware(false);
|
factory.setNamespaceAware(false);
|
||||||
XmlPullParser xpp = factory.newPullParser();
|
XmlPullParser xpp = factory.newPullParser();
|
||||||
|
@ -158,15 +130,15 @@ public class CoordinateReaderOsmAnd extends CoordinateReader
|
||||||
int eventType = xpp.getEventType();
|
int eventType = xpp.getEventType();
|
||||||
int numSeg = 0;
|
int numSeg = 0;
|
||||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||||
switch(eventType) {
|
switch (eventType) {
|
||||||
case XmlPullParser.START_TAG: {
|
case XmlPullParser.START_TAG: {
|
||||||
if (xpp.getName().equals("trkpt")) {
|
if (xpp.getName().equals("trkpt")) {
|
||||||
final String lon = xpp.getAttributeValue(null,"lon");
|
final String lon = xpp.getAttributeValue(null, "lon");
|
||||||
final String lat = xpp.getAttributeValue(null,"lat");
|
final String lat = xpp.getAttributeValue(null, "lat");
|
||||||
if (lon != null && lat != null) {
|
if (lon != null && lat != null) {
|
||||||
nogo.addVertex(
|
nogo.addVertex(
|
||||||
(int)( ( Double.parseDouble(lon) + 180. ) *1000000. + 0.5),
|
(int) ((Double.parseDouble(lon) + 180.) * 1000000. + 0.5),
|
||||||
(int)( ( Double.parseDouble(lat) + 90. ) *1000000. + 0.5));
|
(int) ((Double.parseDouble(lat) + 90.) * 1000000. + 0.5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -175,13 +147,12 @@ public class CoordinateReaderOsmAnd extends CoordinateReader
|
||||||
if (xpp.getName().equals("trkseg")) {
|
if (xpp.getName().equals("trkseg")) {
|
||||||
nogo.calcBoundingCircle();
|
nogo.calcBoundingCircle();
|
||||||
final String name = file.getName();
|
final String name = file.getName();
|
||||||
nogo.name = name.substring(0, name.length()-4);
|
nogo.name = name.substring(0, name.length() - 4);
|
||||||
if (numSeg > 0)
|
if (numSeg > 0) {
|
||||||
{
|
nogo.name += Integer.toString(numSeg + 1);
|
||||||
nogo.name += Integer.toString(numSeg+1);
|
|
||||||
}
|
}
|
||||||
numSeg++;
|
numSeg++;
|
||||||
checkAddPoint( "(one-for-all)", nogo );
|
checkAddPoint("(one-for-all)", nogo);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,13 +81,11 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
mServiceHandler = new ServiceHandler(mServiceLooper);
|
mServiceHandler = new ServiceHandler(mServiceLooper);
|
||||||
|
|
||||||
availableSize = -1;
|
availableSize = -1;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
availableSize = BInstallerActivity.getAvailableSpace(baseDir);
|
availableSize = BInstallerActivity.getAvailableSpace(baseDir);
|
||||||
//StatFs stat = new StatFs(baseDir);
|
//StatFs stat = new StatFs(baseDir);
|
||||||
//availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong();
|
//availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong();
|
||||||
}
|
} catch (Exception e) { /* ignore */ }
|
||||||
catch (Exception e) { /* ignore */ }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +132,10 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
|
|
||||||
// first check lookup table and profiles
|
// first check lookup table and profiles
|
||||||
String result = checkScripts();
|
String result = checkScripts();
|
||||||
if ( result != null) {
|
if (result != null) {
|
||||||
if (DEBUG) Log.d("BR", "error: " + result);
|
if (DEBUG) Log.d("BR", "error: " + result);
|
||||||
bIsDownloading = false;
|
bIsDownloading = false;
|
||||||
updateProgress( "finished " );
|
updateProgress("finished ");
|
||||||
|
|
||||||
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
|
@ -146,7 +144,7 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
|
|
||||||
int count = 1;
|
int count = 1;
|
||||||
int size = mUrlList.size();
|
int size = mUrlList.size();
|
||||||
for (String part: mUrlList) {
|
for (String part : mUrlList) {
|
||||||
String url = mServerConfig.getSegmentUrl() + part + ".rd5";
|
String url = mServerConfig.getSegmentUrl() + part + ".rd5";
|
||||||
if (DEBUG) Log.d("BR", "downlaod " + url);
|
if (DEBUG) Log.d("BR", "downlaod " + url);
|
||||||
|
|
||||||
|
@ -156,59 +154,54 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
updateProgress( "Download " + part + " " + count + "/"+ size + " finshed");
|
updateProgress("Download " + part + " " + count + "/" + size + " finshed");
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bIsDownloading = false;
|
bIsDownloading = false;
|
||||||
updateProgress( "finished " );
|
updateProgress("finished ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateProgress( String progress )
|
public void updateProgress(String progress) {
|
||||||
{
|
if (!newDownloadAction.equals(progress)) {
|
||||||
if ( !newDownloadAction.equals( progress ) )
|
|
||||||
{
|
|
||||||
if (DEBUG) Log.d("BR", "up " + progress);
|
if (DEBUG) Log.d("BR", "up " + progress);
|
||||||
Intent intent = new Intent(BInstallerActivity.DOWNLOAD_ACTION);
|
Intent intent = new Intent(BInstallerActivity.DOWNLOAD_ACTION);
|
||||||
intent.putExtra("txt", progress);
|
intent.putExtra("txt", progress);
|
||||||
intent.putExtra("ready", bIsDownloading);
|
intent.putExtra("ready", bIsDownloading);
|
||||||
sendBroadcast(intent);;
|
sendBroadcast(intent);
|
||||||
|
;
|
||||||
newDownloadAction = progress;
|
newDownloadAction = progress;
|
||||||
mNotificationHelper.progressUpdate(newDownloadAction);
|
mNotificationHelper.progressUpdate(newDownloadAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String download(int counter, int size, String surl)
|
private String download(int counter, int size, String surl) {
|
||||||
{
|
|
||||||
InputStream input = null;
|
InputStream input = null;
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
File fname = null;
|
File fname = null;
|
||||||
File tmp_file = null;
|
File tmp_file = null;
|
||||||
try
|
try {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
TrafficStats.setThreadStatsTag(1);
|
TrafficStats.setThreadStatsTag(1);
|
||||||
|
|
||||||
int slidx = surl.lastIndexOf( "segments4/" );
|
int slidx = surl.lastIndexOf("segments4/");
|
||||||
String name = surl.substring( slidx+10 );
|
String name = surl.substring(slidx + 10);
|
||||||
String surlBase = surl.substring( 0, slidx+10 );
|
String surlBase = surl.substring(0, slidx + 10);
|
||||||
fname = new File (baseDir, "segments4/" + name);
|
fname = new File(baseDir, "segments4/" + name);
|
||||||
|
|
||||||
boolean delta = true;
|
boolean delta = true;
|
||||||
|
|
||||||
// if (!targetFile.getParentFile().exists()) targetFile.getParentFile().mkdirs();
|
// if (!targetFile.getParentFile().exists()) targetFile.getParentFile().mkdirs();
|
||||||
if ( fname.exists() )
|
if (fname.exists()) {
|
||||||
{
|
updateProgress("Calculating local checksum..");
|
||||||
updateProgress( "Calculating local checksum.." );
|
|
||||||
|
|
||||||
// first check for a delta file
|
// first check for a delta file
|
||||||
String md5 = Rd5DiffManager.getMD5( fname );
|
String md5 = Rd5DiffManager.getMD5(fname);
|
||||||
String surlDelta = surlBase + "diff/" + name.replace( ".rd5", "/" + md5 + ".df5" );
|
String surlDelta = surlBase + "diff/" + name.replace(".rd5", "/" + md5 + ".df5");
|
||||||
|
|
||||||
URL urlDelta = new URL(surlDelta);
|
URL urlDelta = new URL(surlDelta);
|
||||||
|
|
||||||
|
@ -217,17 +210,15 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
// 404 kind of expected here, means there's no delta file
|
// 404 kind of expected here, means there's no delta file
|
||||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND )
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||||
{
|
|
||||||
connection = null;
|
connection = null;
|
||||||
} else {
|
} else {
|
||||||
updateProgress( "Connecting.." + surlDelta );
|
updateProgress("Connecting.." + surlDelta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( connection == null )
|
if (connection == null) {
|
||||||
{
|
updateProgress("Connecting.." + name);
|
||||||
updateProgress( "Connecting.." + name );
|
|
||||||
|
|
||||||
delta = false;
|
delta = false;
|
||||||
URL url = new URL(surl);
|
URL url = new URL(surl);
|
||||||
|
@ -236,7 +227,7 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
connection.connect();
|
connection.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateProgress( "Connecting.." + counter + "/"+size );
|
updateProgress("Connecting.." + counter + "/" + size);
|
||||||
|
|
||||||
// expect HTTP 200 OK, so we don't mistakenly save error report
|
// expect HTTP 200 OK, so we don't mistakenly save error report
|
||||||
// instead of the file
|
// instead of the file
|
||||||
|
@ -249,16 +240,16 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
// might be -1: server did not report the length
|
// might be -1: server did not report the length
|
||||||
int fileLength = connection.getContentLength();
|
int fileLength = connection.getContentLength();
|
||||||
long currentDownloadSize = fileLength;
|
long currentDownloadSize = fileLength;
|
||||||
if ( availableSize >= 0 && fileLength > availableSize ) return "not enough space on sd-card";
|
if (availableSize >= 0 && fileLength > availableSize) return "not enough space on sd-card";
|
||||||
|
|
||||||
currentDownloadOperation = delta ? "Updating" : "Loading";
|
currentDownloadOperation = delta ? "Updating" : "Loading";
|
||||||
updateProgress( currentDownloadOperation);
|
updateProgress(currentDownloadOperation);
|
||||||
|
|
||||||
// download the file
|
// download the file
|
||||||
input = connection.getInputStream();
|
input = connection.getInputStream();
|
||||||
|
|
||||||
tmp_file = new File( fname.getAbsolutePath() + ( delta ? "_diff" : "_tmp" ) );
|
tmp_file = new File(fname.getAbsolutePath() + (delta ? "_diff" : "_tmp"));
|
||||||
output = new FileOutputStream( tmp_file );
|
output = new FileOutputStream(tmp_file);
|
||||||
|
|
||||||
byte[] data = new byte[4096];
|
byte[] data = new byte[4096];
|
||||||
long total = 0;
|
long total = 0;
|
||||||
|
@ -273,50 +264,46 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
if (fileLength > 0) // only if total length is known
|
if (fileLength > 0) // only if total length is known
|
||||||
{
|
{
|
||||||
int pct = (int) (total * 100 / fileLength);
|
int pct = (int) (total * 100 / fileLength);
|
||||||
updateProgress( "Progress " + counter + "/"+size + " .. " + pct + "%" );
|
updateProgress("Progress " + counter + "/" + size + " .. " + pct + "%");
|
||||||
}
|
} else {
|
||||||
else
|
updateProgress("Progress (unnown size)");
|
||||||
{
|
|
||||||
updateProgress( "Progress (unnown size)" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output.write(data, 0, count);
|
output.write(data, 0, count);
|
||||||
|
|
||||||
// enforce < 2 Mbit/s
|
// enforce < 2 Mbit/s
|
||||||
long dt = t0 + total/524 - System.currentTimeMillis();
|
long dt = t0 + total / 524 - System.currentTimeMillis();
|
||||||
if ( dt > 0 )
|
if (dt > 0) {
|
||||||
{
|
try {
|
||||||
try { Thread.sleep( dt ); } catch( InterruptedException ie ) {}
|
Thread.sleep(dt);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output.close();
|
output.close();
|
||||||
output = null;
|
output = null;
|
||||||
|
|
||||||
if ( delta )
|
if (delta) {
|
||||||
{
|
updateProgress("Applying delta..");
|
||||||
updateProgress( "Applying delta.." );
|
|
||||||
File diffFile = tmp_file;
|
File diffFile = tmp_file;
|
||||||
tmp_file = new File( fname + "_tmp" );
|
tmp_file = new File(fname + "_tmp");
|
||||||
Rd5DiffTool.recoverFromDelta( fname, diffFile, tmp_file, this );
|
Rd5DiffTool.recoverFromDelta(fname, diffFile, tmp_file, this);
|
||||||
diffFile.delete();
|
diffFile.delete();
|
||||||
}
|
}
|
||||||
if (isCanceled())
|
if (isCanceled()) {
|
||||||
{
|
|
||||||
return "Canceled!";
|
return "Canceled!";
|
||||||
}
|
}
|
||||||
if ( tmp_file != null )
|
if (tmp_file != null) {
|
||||||
{
|
updateProgress("Verifying integrity..");
|
||||||
updateProgress( "Verifying integrity.." );
|
String check_result = PhysicalFile.checkFileIntegrity(tmp_file);
|
||||||
String check_result = PhysicalFile.checkFileIntegrity( tmp_file );
|
if (check_result != null) {
|
||||||
if ( check_result != null ) {
|
if (check_result.startsWith("version old lookups.dat")) {
|
||||||
if (check_result.startsWith("version old lookups.dat") ) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return check_result;
|
return check_result;
|
||||||
}
|
}
|
||||||
if (fname.exists()) fname.delete();
|
if (fname.exists()) fname.delete();
|
||||||
if ( !tmp_file.renameTo( fname ) )
|
if (!tmp_file.renameTo(fname)) {
|
||||||
{
|
|
||||||
return "Could not rename to " + fname.getAbsolutePath();
|
return "Could not rename to " + fname.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,18 +324,16 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally
|
if (tmp_file != null) tmp_file.delete(); // just to be sure
|
||||||
{
|
|
||||||
if ( tmp_file != null ) tmp_file.delete(); // just to be sure
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String checkScripts() {
|
private String checkScripts() {
|
||||||
|
|
||||||
String[] sa = mServerConfig.getLookups();
|
String[] sa = mServerConfig.getLookups();
|
||||||
for (String f: sa) {
|
for (String f : sa) {
|
||||||
if (f.length()>0) {
|
if (f.length() > 0) {
|
||||||
File file = new File(baseDir + "profiles2", f);
|
File file = new File(baseDir + "profiles2", f);
|
||||||
checkOrDownloadLookup(f, file);
|
checkOrDownloadLookup(f, file);
|
||||||
}
|
}
|
||||||
|
@ -356,7 +341,7 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
|
|
||||||
sa = mServerConfig.getProfiles();
|
sa = mServerConfig.getProfiles();
|
||||||
for (String f : sa) {
|
for (String f : sa) {
|
||||||
if (f.length()>0) {
|
if (f.length() > 0) {
|
||||||
File file = new File(baseDir + "profiles2", f);
|
File file = new File(baseDir + "profiles2", f);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
String result = checkOrDownloadScript(f, file);
|
String result = checkOrDownloadScript(f, file);
|
||||||
|
@ -391,10 +376,8 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
File tmp_file = null;
|
File tmp_file = null;
|
||||||
File targetFile = f;
|
File targetFile = f;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
TrafficStats.setThreadStatsTag(1);
|
TrafficStats.setThreadStatsTag(1);
|
||||||
|
|
||||||
URL url = new URL(surl);
|
URL url = new URL(surl);
|
||||||
|
@ -415,7 +398,7 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
|
|
||||||
// this will be useful to display download percentage
|
// this will be useful to display download percentage
|
||||||
// might be -1: server did not report the length
|
// might be -1: server did not report the length
|
||||||
long fileLength = (long)connection.getContentLength();
|
long fileLength = (long) connection.getContentLength();
|
||||||
if (DEBUG) Log.d("BR", "file size " + size + " == " + fileLength + " " + f.getName());
|
if (DEBUG) Log.d("BR", "file size " + size + " == " + fileLength + " " + f.getName());
|
||||||
if (fileLength != size) {
|
if (fileLength != size) {
|
||||||
long currentDownloadSize = fileLength;
|
long currentDownloadSize = fileLength;
|
||||||
|
@ -463,23 +446,20 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
output = null;
|
output = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCanceled())
|
if (isCanceled()) {
|
||||||
{
|
|
||||||
return "Canceled!";
|
return "Canceled!";
|
||||||
}
|
}
|
||||||
if ( tmp_file != null )
|
if (tmp_file != null) {
|
||||||
{
|
|
||||||
f.delete();
|
f.delete();
|
||||||
|
|
||||||
if ( !tmp_file.renameTo( f ) )
|
if (!tmp_file.renameTo(f)) {
|
||||||
{
|
|
||||||
return "Could not rename to " + f.getName();
|
return "Could not rename to " + f.getName();
|
||||||
}
|
}
|
||||||
if (DEBUG) Log.d("BR", "update " + f.getName());
|
if (DEBUG) Log.d("BR", "update " + f.getName());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e.toString() ;
|
return e.toString();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (output != null)
|
if (output != null)
|
||||||
|
@ -493,10 +473,8 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally
|
if (tmp_file != null) tmp_file.delete(); // just to be sure
|
||||||
{
|
|
||||||
if ( tmp_file != null ) tmp_file.delete(); // just to be sure
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,15 +29,14 @@ public class NotificationHelper {
|
||||||
private PendingIntent mContentIntent;
|
private PendingIntent mContentIntent;
|
||||||
private CharSequence mContentTitle;
|
private CharSequence mContentTitle;
|
||||||
|
|
||||||
public NotificationHelper(Context context)
|
public NotificationHelper(Context context) {
|
||||||
{
|
if (DEBUG) Log.d("NH", "init ");
|
||||||
if (DEBUG) Log.d("NH", "init " );
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
createNotificationChannels();
|
createNotificationChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startNotification(Service service) {
|
public void startNotification(Service service) {
|
||||||
if (DEBUG) Log.d("NH", "startNotification " );
|
if (DEBUG) Log.d("NH", "startNotification ");
|
||||||
|
|
||||||
mNotification = createNotification("BRouter Download", "Download some files");
|
mNotification = createNotification("BRouter Download", "Download some files");
|
||||||
|
|
||||||
|
@ -101,7 +100,7 @@ public class NotificationHelper {
|
||||||
* create notification channels
|
* create notification channels
|
||||||
*/
|
*/
|
||||||
public void createNotificationChannels() {
|
public void createNotificationChannels() {
|
||||||
if (DEBUG) Log.d("NH", "createNotificationChannels " );
|
if (DEBUG) Log.d("NH", "createNotificationChannels ");
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
|
||||||
|
@ -126,7 +125,7 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopNotification() {
|
public void stopNotification() {
|
||||||
if (DEBUG) Log.d("NH", "stopNotification " );
|
if (DEBUG) Log.d("NH", "stopNotification ");
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
mNotificationManager.deleteNotificationChannel(BRouterNotificationChannel1);
|
mNotificationManager.deleteNotificationChannel(BRouterNotificationChannel1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,44 +7,38 @@ import java.util.TreeSet;
|
||||||
/**
|
/**
|
||||||
* Decsription of a service config
|
* Decsription of a service config
|
||||||
*/
|
*/
|
||||||
public class ServiceModeConfig
|
public class ServiceModeConfig {
|
||||||
{
|
|
||||||
public String mode;
|
public String mode;
|
||||||
public String profile;
|
public String profile;
|
||||||
public TreeSet<String> nogoVetos;
|
public TreeSet<String> nogoVetos;
|
||||||
|
|
||||||
public ServiceModeConfig( String line )
|
public ServiceModeConfig(String line) {
|
||||||
{
|
StringTokenizer tk = new StringTokenizer(line);
|
||||||
StringTokenizer tk = new StringTokenizer( line );
|
|
||||||
mode = tk.nextToken();
|
mode = tk.nextToken();
|
||||||
profile = tk.nextToken();
|
profile = tk.nextToken();
|
||||||
nogoVetos = new TreeSet<String>();
|
nogoVetos = new TreeSet<String>();
|
||||||
while( tk.hasMoreTokens() )
|
while (tk.hasMoreTokens()) {
|
||||||
{
|
nogoVetos.add(tk.nextToken());
|
||||||
nogoVetos.add( tk.nextToken() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceModeConfig( String mode, String profile )
|
public ServiceModeConfig(String mode, String profile) {
|
||||||
{
|
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
nogoVetos = new TreeSet<String>();
|
nogoVetos = new TreeSet<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toLine()
|
public String toLine() {
|
||||||
{
|
StringBuilder sb = new StringBuilder(100);
|
||||||
StringBuilder sb = new StringBuilder( 100 );
|
sb.append(mode).append(' ').append(profile);
|
||||||
sb.append( mode ).append( ' ' ).append( profile );
|
for (String veto : nogoVetos) sb.append(' ').append(veto);
|
||||||
for( String veto: nogoVetos ) sb.append( ' ' ).append( veto );
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
StringBuilder sb = new StringBuilder(100);
|
||||||
StringBuilder sb = new StringBuilder( 100 );
|
sb.append(mode).append("->").append(profile);
|
||||||
sb.append( mode ).append( "->" ).append( profile );
|
sb.append(" [" + nogoVetos.size() + "]");
|
||||||
sb.append ( " [" + nogoVetos.size() + "]" );
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@ package btools.routingapp;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class WpDatabaseScanner extends Thread
|
public class WpDatabaseScanner extends Thread {
|
||||||
{
|
|
||||||
private String currentDir = "";
|
private String currentDir = "";
|
||||||
private String bestGuess = "";
|
private String bestGuess = "";
|
||||||
private String lastError = "";
|
private String lastError = "";
|
||||||
|
@ -12,116 +11,87 @@ public class WpDatabaseScanner extends Thread
|
||||||
|
|
||||||
private long maxtimestamp = 0;
|
private long maxtimestamp = 0;
|
||||||
|
|
||||||
public String getCurrentDir()
|
public String getCurrentDir() {
|
||||||
{
|
synchronized (currentDirSync) {
|
||||||
synchronized (currentDirSync)
|
|
||||||
{
|
|
||||||
return currentDir;
|
return currentDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCurrentDir( String dir )
|
private void setCurrentDir(String dir) {
|
||||||
{
|
synchronized (currentDirSync) {
|
||||||
synchronized (currentDirSync)
|
|
||||||
{
|
|
||||||
currentDir = dir;
|
currentDir = dir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBestGuess()
|
public String getBestGuess() {
|
||||||
{
|
synchronized (currentDirSync) {
|
||||||
synchronized (currentDirSync)
|
|
||||||
{
|
|
||||||
return bestGuess;
|
return bestGuess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastError()
|
public String getLastError() {
|
||||||
{
|
synchronized (currentDirSync) {
|
||||||
synchronized (currentDirSync)
|
|
||||||
{
|
|
||||||
return lastError;
|
return lastError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLastError( String msg )
|
private void setLastError(String msg) {
|
||||||
{
|
synchronized (currentDirSync) {
|
||||||
synchronized (currentDirSync)
|
|
||||||
{
|
|
||||||
lastError = msg;
|
lastError = msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] vetos = new String[] { "dev", "sys", "system", "proc", "etc", "init", "d", "cache", "acct", "data" };
|
private static String[] vetos = new String[]{"dev", "sys", "system", "proc", "etc", "init", "d", "cache", "acct", "data"};
|
||||||
|
|
||||||
private void scan( File dir, int level )
|
private void scan(File dir, int level) {
|
||||||
{
|
if (level > 8) {
|
||||||
if ( level > 8 )
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
if (dir.isDirectory()) {
|
||||||
if ( dir.isDirectory() )
|
if (level == 1) {
|
||||||
{
|
|
||||||
if ( level == 1 )
|
|
||||||
{
|
|
||||||
String name = dir.getName();
|
String name = dir.getName();
|
||||||
for( String veto: vetos )
|
for (String veto : vetos) {
|
||||||
{
|
if (veto.equals(name)) {
|
||||||
if ( veto.equals( name ) )
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testPath( dir.getPath() );
|
testPath(dir.getPath());
|
||||||
File[] childs = dir.listFiles();
|
File[] childs = dir.listFiles();
|
||||||
if ( childs == null )
|
if (childs == null) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for ( File child : childs )
|
for (File child : childs) {
|
||||||
{
|
scan(child, level + 1);
|
||||||
scan( child, level+1 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
setLastError(e.toString());
|
||||||
{
|
|
||||||
setLastError( e.toString() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testPath( String path ) throws Exception
|
private void testPath(String path) throws Exception {
|
||||||
{
|
setCurrentDir(path);
|
||||||
setCurrentDir( path );
|
|
||||||
|
|
||||||
testReader( new CoordinateReaderOsmAnd( path ) );
|
testReader(new CoordinateReaderOsmAnd(path));
|
||||||
testReader( new CoordinateReaderOsmAnd( path, true ) );
|
testReader(new CoordinateReaderOsmAnd(path, true));
|
||||||
testReader( new CoordinateReaderLocus( path ) );
|
testReader(new CoordinateReaderLocus(path));
|
||||||
testReader( new CoordinateReaderOrux( path ) );
|
testReader(new CoordinateReaderOrux(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testReader( CoordinateReader cor ) throws Exception
|
private void testReader(CoordinateReader cor) throws Exception {
|
||||||
{
|
|
||||||
long ts = cor.getTimeStamp();
|
long ts = cor.getTimeStamp();
|
||||||
if ( ts > maxtimestamp )
|
if (ts > maxtimestamp) {
|
||||||
{
|
|
||||||
maxtimestamp = ts;
|
maxtimestamp = ts;
|
||||||
synchronized (currentDirSync)
|
synchronized (currentDirSync) {
|
||||||
{
|
|
||||||
bestGuess = cor.basedir;
|
bestGuess = cor.basedir;
|
||||||
}
|
}
|
||||||
}
|
} else if (ts > 0 && ts == maxtimestamp) {
|
||||||
else if ( ts > 0 && ts == maxtimestamp )
|
synchronized (currentDirSync) {
|
||||||
{
|
if (cor.basedir.length() < bestGuess.length()) {
|
||||||
synchronized (currentDirSync)
|
|
||||||
{
|
|
||||||
if ( cor.basedir.length() < bestGuess.length() )
|
|
||||||
{
|
|
||||||
bestGuess = cor.basedir;
|
bestGuess = cor.basedir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,10 +99,9 @@ public class WpDatabaseScanner extends Thread
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
scan(new File("/"), 0);
|
||||||
scan( new File( "/" ), 0 );
|
setCurrentDir(null);
|
||||||
setCurrentDir( null );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue