diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java b/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java index 3b424c0..2990aab 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java @@ -8,7 +8,7 @@ package btools.mapaccess; import java.io.*; import btools.util.Crc32; -final class PhysicalFile +final public class PhysicalFile { RandomAccessFile ra = null; long[] fileIndex = new long[25]; @@ -19,6 +19,42 @@ final class PhysicalFile String fileName; + /** + * Checks the integrity of the file using the build-in checksums + * + * @return the error message if file corrupt, else null + */ + public static String checkFileIntegrity( File f ) + { + PhysicalFile pf = null; + try + { + byte[] iobuffer = new byte[65636]; + pf = new PhysicalFile( f, new byte[65636], -1 ); + for( int tileIndex=0; tileIndex<25; tileIndex++ ) + { + OsmFile osmf = new OsmFile( pf, tileIndex, iobuffer ); + if ( osmf.microCaches != null ) + for( int lonIdx80=0; lonIdx80<80; lonIdx80++ ) + for( int latIdx80=0; latIdx80<80; latIdx80++ ) + new MicroCache( osmf, lonIdx80, latIdx80, iobuffer ); + } + } + catch( IllegalArgumentException iae ) + { + return iae.getMessage(); + } + catch( Exception e ) + { + return e.toString(); + } + finally + { + if ( pf != null ) try{ pf.ra.close(); } catch( Exception ee ) {} + } + return null; + } + public PhysicalFile( File f, byte[] iobuffer, int lookupVersion ) throws Exception { fileName = f.getName(); @@ -31,7 +67,7 @@ final class PhysicalFile { long lv = dis.readLong(); short readVersion = (short)(lv >> 48); - if ( readVersion != lookupVersion ) + if ( readVersion != lookupVersion && lookupVersion != -1 ) { throw new IllegalArgumentException( "lookup version mismatch (old rd5?) lookups.dat=" + lookupVersion + " " + f. getAbsolutePath() + "=" + readVersion ); diff --git a/brouter-routing-app/AndroidManifest.xml b/brouter-routing-app/AndroidManifest.xml index 1908474..d39358a 100644 --- a/brouter-routing-app/AndroidManifest.xml +++ b/brouter-routing-app/AndroidManifest.xml @@ -12,6 +12,10 @@ + + - + + + + \ No newline at end of file diff --git a/brouter-routing-app/assets/modes.zip b/brouter-routing-app/assets/modes.zip new file mode 100644 index 0000000..7e02ada Binary files /dev/null and b/brouter-routing-app/assets/modes.zip differ diff --git a/brouter-routing-app/assets/profiles2.zip b/brouter-routing-app/assets/profiles2.zip new file mode 100644 index 0000000..90fd2e7 Binary files /dev/null and b/brouter-routing-app/assets/profiles2.zip differ diff --git a/brouter-routing-app/assets/world.png b/brouter-routing-app/assets/world.png new file mode 100644 index 0000000..4acf5ed Binary files /dev/null and b/brouter-routing-app/assets/world.png differ diff --git a/brouter-routing-app/pom.xml b/brouter-routing-app/pom.xml index b72774c..d419252 100644 --- a/brouter-routing-app/pom.xml +++ b/brouter-routing-app/pom.xml @@ -11,6 +11,19 @@ brouter-routing-app apk + + + release + + + + performRelease + true + + + + + com.google.android @@ -27,10 +40,64 @@ + + + org.apache.maven.plugins + maven-jarsigner-plugin + + + signing + + sign + verify + + package + true + + true + + + ${project.build.directory}/${project.artifactId}.apk + + \sign\mystore + myalias + mypasswd + mypasswd + true + + + + + com.jayway.maven.plugins.android.generation2 android-maven-plugin + + true + + true + + false + + + true + ${project.build.directory}/${project.artifactId}.apk + ${project.build.directory}/${project.artifactId}-signed-aligned.apk + + + + + + alignApk + package + + zipalign + + + + + diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java new file mode 100644 index 0000000..55d19a6 --- /dev/null +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -0,0 +1,63 @@ +package btools.routingapp; + +import android.app.Activity; +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; +import android.speech.tts.TextToSpeech.OnInitListener; + +public class BInstallerActivity extends Activity implements OnInitListener { + + private BInstallerView mBInstallerView; + private PowerManager mPowerManager; + private WakeLock mWakeLock; + + /** Called when the activity is first created. */ + @Override + @SuppressWarnings("deprecation") + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Get an instance of the PowerManager + mPowerManager = (PowerManager) getSystemService(POWER_SERVICE); + + // Create a bright wake lock + mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass() + .getName()); + + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + + // instantiate our simulation view and set it as the activity's content + mBInstallerView = new BInstallerView(this); + setContentView(mBInstallerView); + } + + @Override + protected void onResume() { + super.onResume(); + /* + * when the activity is resumed, we acquire a wake-lock so that the + * screen stays on, since the user will likely not be fiddling with the + * screen or buttons. + */ + mWakeLock.acquire(); + + // Start the download manager + mBInstallerView.startInstaller(); + } + + @Override + protected void onPause() { + super.onPause(); + System.exit(0); + } + + @Override + public void onInit(int i) + { + } + + + +} diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerSizes.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerSizes.java new file mode 100644 index 0000000..0074a78 --- /dev/null +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerSizes.java @@ -0,0 +1,445 @@ +package btools.routingapp; + + +public class BInstallerSizes { + + public static int[] rd5_sizes = { + + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,73999,0,0, + 0,0,0,0,25842,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,26278,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,51849,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,26259,0,0,0, + 30836,0,0,0,0,0,0,0,0,116332,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 53454,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 51488,51488,25831,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,52198,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,26524,26129,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 54941,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,86757,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,1005199,945429,151598, + 394678,0,0,0,52974,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,26712,0,55549,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,77677,1418043,1568787,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,26508,0,0,42876,0, + 0,0,40644,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,1771014,956869,0, + 126155,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,3717870,1421651,466132, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,176625,4418353,0,0,0,670142,7013939,2942713, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,8111340,2347836,3815539, + 3684129,0,0,0,0,0,0,0,0,28350,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,29348,0,0,0,0,0,0,0,271358, + 0,0,0,2486125,14556552,22399413,673310,0,0,0,5307327,6088284, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,26732,34280,13509376,4907259,12166406, + 18311811,4750344,0,0,0,0,0,0,0,0,0,0, + 0,0,0,7552679,3917687,6199851,1014587,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,106475,13867315, + 1099471,356703,751147,8209358,1648741,4276839,16568211,39154,0,0,169310,0, + 36748,0,0,0,0,0,0,28964,0,32473,0,0, + 0,0,78770,0,0,0,0,29483,0,1762056,4410158,2752373, + 9217723,15974486,8051723,0,0,0,0,0,0,0,0,0, + 0,0,0,2584071,2323801,17949889,9970503,0,302019,2320011,0,0, + 0,0,0,0,0,0,0,0,0,0,528187,922749, + 775954,725499,963136,881886,1083338,1358203,15661541,0,0,73583,0,0, + 129801,26718,0,0,116919,62284,60271,0,0,32356,0,0, + 0,0,0,0,0,0,0,0,0,942829,4653023,2586717, + 2666478,13114798,38032947,18434039,0,0,27216,0,0,0,0,0, + 0,0,605859,2430011,1170900,3756098,2742051,443421,1715666,2801512,0,3457783, + 0,0,0,0,0,0,0,0,0,0,316028,1249382, + 577538,546868,1248268,1085824,1014386,2351037,1239360,0,485897,2530316,0,0, + 161159,122442,91176,25842,116029,212409,402614,54494,0,0,0,0, + 0,0,0,0,0,0,0,0,35913,3493526,10175389,3907219, + 2260919,2411149,10024680,8658888,1031113,0,0,0,0,0,103184,0, + 0,0,1258037,1334840,1120485,2924259,2832202,1068642,367845,4030088,105369,34238, + 63613,0,0,0,0,0,0,0,0,0,0,26154, + 494087,943412,778772,843448,842353,2139470,0,0,0,383103,0,1040737, + 80777,616784,36686,0,0,0,87880,0,30776,0,0,0, + 0,0,0,0,0,0,0,0,8472393,4830559,1497659,1345460, + 1565335,1069569,2306526,3271040,4352960,0,0,0,0,0,0,0, + 0,0,919071,1286931,824212,2404482,2131797,1707550,536753,1326048,167777,26079, + 0,0,0,0,0,0,0,32948,0,30910,0,26089, + 1160160,201038,1308950,302215,674058,126963,129142,27008,27387,120573,0,29548, + 0,0,0,0,0,0,0,129154,111854,0,0,0, + 0,0,0,0,0,0,0,521933,4527841,616710,526657,958389, + 652371,859611,2088582,2511364,7867888,2377585,0,0,0,54066,0,0, + 0,0,2280689,1404909,1437756,1575000,1837045,2223922,0,26580,81614,0, + 0,0,42794,0,0,0,0,0,166974,8695827,8630550,6690003, + 3284936,1156379,278495,159765,728315,1093478,283449,442071,190654,0,0,112187, + 0,33269,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,150329,76100,3113812,11743167,420208,407887,1107726, + 1208790,792936,2326078,2022614,1970028,46373,0,0,0,0,0,0, + 0,175040,853250,2861807,1053282,8167646,3458096,4951035,891438,0,0,192531, + 0,0,62565,0,0,0,0,253883,2477739,1096283,862436,3410350, + 1290216,844327,704052,620597,716347,59815,207743,0,0,71041,62152,115045, + 0,0,0,27294,117815,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,71715,7559009,7578963,356019,1135310, + 495018,1155459,25954,0,0,0,0,0,0,0,165299,181478, + 0,1731259,2555351,2529694,1388878,1372462,7634240,2476253,5969460,2755563,0,0, + 0,0,385341,0,0,0,0,3159704,12736648,423007,1909297,707282, + 925119,813605,26336,0,0,0,0,0,0,0,185213,0, + 0,0,0,26536,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,269709,4760559,5963568,13386046,1412701,2383670, + 1342495,456839,0,0,0,0,0,0,0,2511000,2632084,4903167, + 6203434,4120854,2709849,3559165,1563050,1715815,2582663,5683354,2212338,2452613,184405,0, + 0,0,306012,5030899,4927615,0,140017,3195680,4949863,300983,53603,1591335, + 4987533,5888135,147163,43903,51917,25849,36797,72782,64050,119011,121285,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,4580459,8391094,1862057,1013499,4770241,4967370,5520499, + 553160,0,0,0,0,0,0,242833,4493904,2937622,5011647,6708181, + 2283883,2597923,1897506,1488667,1254005,1328064,1497706,2569358,2629382,1447912,902064,0, + 0,0,1572179,26088071,2278943,77136,435704,2934860,12665978,9454792,25887,507734, + 24812878,645046,0,27225,549678,90910,0,0,31039,84006,0,0, + 0,0,26756,0,1085438,101009,0,0,0,0,0,0, + 0,55912,44071,3328834,19701613,4634387,3639056,255295,2727484,13240358,17196156,3766078, + 0,0,0,0,0,0,297592,497353,1147646,721655,754492,2913568, + 1394039,932458,328260,414437,447988,105486,4522079,1140603,3036086,830112,1917818,595396, + 0,0,9727369,8227411,2734747,127757,508167,10819386,15124245,3454268,353313,297787, + 8191894,0,0,0,0,297690,0,0,0,33199,0,0, + 0,0,0,70817,3058061,0,0,0,0,0,0,0, + 0,509966,3415226,13041283,2823064,182655,5397122,4855074,5219324,966992,0,0, + 0,0,0,0,0,0,0,0,584796,675807,182311,422362, + 420790,630135,550845,457579,225146,343703,946657,4646530,1887778,4448929,3345390,5775174, + 0,2192061,7422468,3980228,2664991,6298780,4160634,5031836,4704873,4424238,11643347,2369507, + 14005061,563770,27632,0,34534,0,29253,0,0,0,0,0, + 54172,0,0,0,0,0,0,0,0,0,0,0, + 143651,1709682,5547784,11621426,44385637,4932836,625260,53013336,891810,0,0,0, + 0,0,0,0,0,0,0,0,9237635,3686686,3687517,329528, + 535789,718245,1072017,733733,533683,588888,5701892,1712964,1800188,3701139,7851572,7238591, + 1803507,2410124,7820039,15437249,9576287,6995800,3122671,2377345,4062437,3165010,2938839,4291319, + 5038179,5266215,145674,0,85057,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,2087476, + 52865036,30367445,23653110,33958692,77647814,60178308,83436698,92560342,13310441,0,0,260431, + 0,0,0,0,0,0,0,0,1421832,51752,15651034,5184437, + 1692549,3225809,5164614,554863,1578254,1197843,16758458,24967222,3794968,3635578,3686193,2274355, + 1566888,2758035,10532443,9529475,683783,492718,768760,1223294,2914399,3496885,4771678,5384416, + 6449650,10433088,140298731,57293386,26049,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,68207278, + 30141523,22698873,43108431,32514095,57177991,85256070,87464774,150099345,185472299,4721690,0,0, + 0,0,0,0,0,92877,1468141,0,0,0,41866492,59635835, + 19534480,13931458,21147673,15893472,48704303,24724861,27092523,23058640,11565055,5793284,5955157,4536323, + 1849851,4241379,1963193,1389927,585795,304973,672979,998734,2431663,2131767,3530135,7547190, + 2528659,27480005,16325896,179649894,70941833,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,56791211, + 28654102,38493476,29127102,25786922,45880907,60638823,79781978,78662642,99927564,141742149,8603687,5115319, + 0,0,0,0,0,0,0,0,0,0,77555760,91537630, + 128067635,70078502,94948461,50149081,45794811,35900758,14867438,12986096,30949364,8742915,924426,698957, + 955568,7508183,7654807,3843184,1198716,1614060,707964,717081,898283,1221752,1568816,3709880, + 2888706,3763485,3448326,998301,54976545,1025113,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,1019540,64439440, + 31596744,19829331,10866457,29260597,27793214,25741834,13911524,8407905,16149757,23522197,15680387,11772634, + 1852390,2034367,0,0,0,0,0,0,0,0,284886,83428213, + 152713355,329494639,278101011,127488599,48683350,29973630,16126341,21971169,12164941,2131789,847601,859861, + 984261,714169,1250430,797020,1643733,1289970,989198,1089069,1370536,2038582,908910,1004876, + 1188773,1495658,1963033,1613704,2564300,106652,32636,0,0,0,0,0, + 46613,34598,176289,80606,0,0,0,0,0,536949,2623906,5722035, + 6332936,15839253,7539214,5576801,3211877,1010638,345693,209170,463957,331916,781778,529477, + 647018,0,25954,0,0,0,0,0,0,715281,41294519,181173713, + 106523261,275156014,172357730,75065803,48820918,19869187,19195357,25382723,7870725,9384439,7410073,7614387, + 3623584,1552016,3731219,1891704,6949145,4986024,2531339,642292,3234327,1813327,1610577,1066702, + 1084282,1678836,627125,1913032,1032816,0,0,981512,27453,28870,57906,108069, + 0,48018,85542,369563,516884,740283,51521,78857,427166,1117148,1113696,3001980, + 2478095,1369219,421235,497960,515950,312698,28084,0,112317,0,0,0, + 30114,0,0,26048,0,0,0,0,0,0,5327229,31165254, + 85281,29978496,67509037,25773442,19358595,19276865,16660709,37223798,15628865,10909714,8021051,10663737, + 13309494,4574228,3243586,1594132,4526360,3196337,3942675,1764732,1172843,917716,638440,376276, + 648857,670717,263479,301198,110646,59589,434024,271715,357015,56699,0,0, + 0,169637,270349,708395,648212,986888,2988924,765957,1062356,438381,277065,225926, + 424253,521243,52186,0,62942,123403,0,32185,61027,81270,75039,0, + 0,191700,233939,30386,0,0,0,4321370,1000107,165595,476052,500263, + 264263,9783750,15956336,13367985,35025754,32716565,10193034,3244402,5382599,3360932,2293568,1823307, + 1567826,2941188,3825581,2616547,545690,336640,192176,224463,401010,226407,541143,612743, + 516087,837227,673964,360571,358939,500575,431343,267569,130426,196914,173448,191305, + 248367,250448,327383,602046,473763,588923,735134,303149,374750,235614,60786,0, + 39939,52551,82896,32021,57797,34035,67762,64808,0,0,33630,56862, + 0,453105,0,0,90126,0,0,838465,949279,328001,0,0, + 0,0,2896373,3841919,5273037,6722175,4162443,569581,391084,192654,896988,915050, + 818622,805302,439882,724463,321077,550649,0,0,79957,0,306936,115443, + 27260,27232,299732,185814,180972,162989,344944,145188,311205,457129,428209,336701, + 60620,0,0,54973,264422,173082,195605,82738,0,0,0,0, + 0,0,0,0,26430,33626,59040,55334,30863,0,32152,0, + 116244,70332,0,0,0,0,0,57096,0,0,57820,0, + 0,0,0,88003,366662,575711,82471,0,0,0,77979,0, + 0,85747,78813,25898,51807,0,0,0,27738,0,198073,25996, + 0,94884,0,55175,77511,26308,0,0,0,25880,52155,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,29684,0,27549,117176,0, + 0,0,0,0,0,0,25849,0,0,0,0,0, + 0,0,113121,169484,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,25863,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,26451, + 0,0,0,0,0,0,0,0,26010,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,26098,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,200,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + }; + + public static int[] cd5_sizes = { + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,70091,0,0, + 0,0,0,0,25842,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,26278,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,200,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,26259,0,0,0, + 30082,0,0,0,0,0,0,0,0,113801,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 200,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 51488,51488,25831,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,26228,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,200,200,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 25996,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,200,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,855984,848057,106076, + 264966,0,0,0,26443,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,200,0,200,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,51664,1229395,1523538,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,200,0,0,200,0, + 0,0,28554,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,1388142,819889,0, + 76581,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,3167520,1396119,447357, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,152900,3043319,0,0,0,419020,4499648,2640604, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,7014974,2204051,3692565, + 3538224,0,0,0,0,0,0,0,0,27506,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,200,0,0,0,0,0,0,0,195022, + 0,0,0,2004936,10752726,15334312,466879,0,0,0,4257348,5052333, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,200,27702,10721885,4463058,11695286, + 15715896,3837469,0,0,0,0,0,0,0,0,0,0, + 0,0,0,6236471,3255699,5702830,952087,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,94437,8698025, + 808755,272655,597627,6623172,1406671,3572554,12157393,29118,0,0,107840,0, + 29747,0,0,0,0,0,0,26420,0,25989,0,0, + 0,0,44771,0,0,0,0,200,0,1509658,3913714,2706437, + 8090199,14507302,7510503,0,0,0,0,0,0,0,0,0, + 0,0,0,1626401,2068012,16198756,8087930,0,102502,1100743,0,0, + 0,0,0,0,0,0,0,0,0,0,424290,814453, + 614422,389030,579953,688421,1013629,1199974,12519388,0,0,68520,0,0, + 118066,26106,0,0,101189,57623,58979,0,0,32261,0,0, + 0,0,0,0,0,0,0,0,0,813781,3727511,2143812, + 1998634,12100594,35961675,16189825,0,0,200,0,0,0,0,0, + 0,0,348291,1681103,926801,3365528,2353136,326104,1117879,2324365,0,3019791, + 0,0,0,0,0,0,0,0,0,0,276481,906721, + 353887,306906,804579,863430,862414,2006354,1088708,0,182926,1180048,0,0, + 155000,120971,68131,200,105943,174661,316332,54494,0,0,0,0, + 0,0,0,0,0,0,0,0,35913,3315952,8289410,3555958, + 2074926,2324324,9479436,8187703,1012172,0,0,0,0,0,93444,0, + 0,0,840718,1131979,877423,2436119,2692661,868852,295741,3016753,96850,32310, + 58487,0,0,0,0,0,0,0,0,0,0,26154, + 435246,699655,621291,635420,732518,1847696,0,0,0,273794,0,942558, + 67839,478467,36473,0,0,0,86228,0,25931,0,0,0, + 0,0,0,0,0,0,0,0,8004515,3921220,1317795,1218386, + 1424326,922444,2163188,3072017,4139586,0,0,0,0,0,0,0, + 0,0,899109,1225760,748944,2114813,1768988,1316740,501928,776440,139099,200, + 0,0,0,0,0,0,0,32223,0,29888,0,200, + 838439,63419,1018352,259837,491713,98911,66814,200,27387,93570,0,29424, + 0,0,0,0,0,0,0,88661,102246,0,0,0, + 0,0,0,0,0,0,0,521425,4247472,537493,454640,923857, + 630078,705171,1743305,2280163,7235320,2249922,0,0,0,41768,0,0, + 0,0,2019015,975576,863693,870974,1610767,1873416,0,26191,55043,0, + 0,0,40884,0,0,0,0,0,106286,7871150,7830021,5687009, + 2768480,922562,273373,79445,564301,808481,176474,344735,175686,0,0,85953, + 0,27352,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,119988,41603,2771778,10293826,302527,299876,1004541, + 1162977,688180,1932725,1866052,1838910,31605,0,0,0,0,0,0, + 0,147657,786084,2001467,627925,3818165,2933263,3841484,396474,0,0,129025, + 0,0,59434,0,0,0,0,232354,2167631,963215,698925,3242509, + 1186175,767466,596232,571662,606461,59816,200077,0,0,59991,29471,111871, + 0,0,0,27289,87346,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,69191,6468546,5653736,263447,839590, + 301743,687038,200,0,0,0,0,0,0,0,163516,173876, + 0,1563689,2262598,1310634,914341,909499,4810677,1810798,1501200,1229133,0,0, + 0,0,335056,0,0,0,0,2578402,11278635,410221,1710437,490548, + 770370,774470,26336,0,0,0,0,0,0,0,164032,0, + 0,0,0,200,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,248339,4081232,5253733,11036844,1312104,1709282, + 1150704,269175,0,0,0,0,0,0,0,2244447,2084894,4530390, + 4964318,3776624,2390256,1723217,1020670,1096413,1317512,4702596,1452761,992111,67022,0, + 0,0,276651,4873787,4415326,0,132663,2494488,4327776,274020,53603,1292989, + 4289781,5219796,133476,37244,26038,25849,36012,54314,63914,60106,91862,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,4391852,7514388,1739114,773938,3952452,4576179,4920746, + 472582,0,0,0,0,0,0,208169,3866534,2111654,3084994,3488690, + 1984559,2444808,1560538,1206873,855351,1044130,1305977,2310140,1859015,843422,401033,0, + 0,0,1502765,25094822,2146339,77136,382183,2341866,10960229,7286828,25887,390462, + 18572412,516634,0,200,507456,81475,0,0,26721,27446,0,0, + 0,0,26692,0,776160,80548,0,0,0,0,0,0, + 0,27342,34108,3063101,18738086,4448347,3205886,238381,2359029,8172826,13978928,2910143, + 0,0,0,0,0,0,136325,373179,988399,671901,350687,997600, + 821522,664832,97923,406062,308207,79802,3962440,897536,2800063,725432,885202,300927, + 0,0,9026494,7942446,2278768,113814,505827,8486099,12888221,3086203,338733,278972, + 7034414,0,0,0,0,286089,0,0,0,200,0,0, + 0,0,0,25891,2710524,0,0,0,0,0,0,0, + 0,373331,2987687,12159158,2509066,163892,4868766,3854312,4263837,741931,0,0, + 0,0,0,0,0,0,0,0,356263,383830,200,52164, + 378086,385938,332530,286545,146588,162413,737343,4366047,1782067,4182775,2880662,5034347, + 0,2078810,7240240,3909505,2511938,6129414,3445600,4370475,4212182,4202772,9468000,2193123, + 12224221,499424,200,0,33754,0,28864,0,0,0,0,0, + 54172,0,0,0,0,0,0,0,0,0,0,0, + 142725,1598472,5011219,10787297,39396269,4601941,577865,46581722,822807,0,0,0, + 0,0,0,0,0,0,0,0,4943168,2133614,1445526,274336, + 415981,484628,814655,694313,411882,442449,4911819,1482339,1789278,3544665,7443296,6221660, + 1687623,1978176,7092380,14861546,7994746,5634309,2748956,2226853,3799379,3064716,2743153,4096999, + 4405343,4928938,132846,0,76995,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,1380543, + 40285622,24548529,16905694,30669785,67054800,54508675,73773672,83649044,12059098,0,0,225966, + 0,0,0,0,0,0,0,0,911085,51752,10700266,4110896, + 1535660,2274696,4322063,542093,1420700,988254,11841263,20710438,3542375,3572656,3591723,2211995, + 684089,1590834,8635545,8222499,533943,417909,710405,1145559,2581718,3357078,4362796,5055766, + 5640731,9091896,113602886,48138375,200,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,54328213, + 18717780,10278901,29259961,25815529,43175293,68090093,78467043,126822478,140844487,4425761,0,0, + 0,0,0,0,0,72067,1133782,0,0,0,29226749,38506462, + 16549533,10978257,16225249,12330151,29074534,19134830,22668613,20521680,9944947,5101342,5682353,4142169, + 1557603,3194307,1390635,1279292,543056,221959,590255,920975,2216698,2066773,3415359,6746539, + 2371133,22623922,13569892,152798833,58503357,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,46743146, + 20769427,27601542,18668147,18603093,32942577,45786577,67464728,69607399,82209702,122340164,5753818,3320647, + 0,0,0,0,0,0,0,0,0,0,55255756,52621687, + 73473866,39224112,61689726,34123848,34880176,29367743,11925278,9153752,24106662,7587052,834865,610300, + 891571,5783714,6572540,3295291,1131879,1457960,685006,695737,704138,1164592,1493345,2804994, + 2654017,3421893,2759904,840614,44252344,770505,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,605826,47241781, + 25257858,15066323,7711203,21500519,19806053,19268603,10634827,6321265,13348789,19194348,10727933,7674160, + 1631680,1800345,0,0,0,0,0,0,0,0,152790,62057382, + 108599841,159996480,129090151,67700331,27514762,21763749,12188130,16193784,8123207,1622818,804643,534911, + 823122,706375,1147880,707446,1294609,1030328,922599,1029357,1235660,1866848,870626,912240, + 1162521,1467231,1794292,1422054,2122279,72611,28369,0,0,0,0,0, + 45444,32085,75262,54183,0,0,0,0,0,449759,1966233,4123088, + 5050260,13531641,5542015,4057486,1970065,889001,344244,206202,455242,328091,707612,524098, + 617620,0,200,0,0,0,0,0,0,586889,34431477,119682249, + 70473640,138403084,81649512,40422397,27928097,14047125,14343210,16526001,5350325,6663457,4782345,5760419, + 2831298,1354263,3114737,1622580,4770732,3625730,2111855,472547,2698922,1592613,1428266,1023346, + 1042886,1438912,560094,1417461,909854,0,0,724159,200,200,57707,26667, + 0,34918,30967,347076,461576,566051,51521,52543,336102,964470,1016187,1634436, + 2451204,1214338,374531,345204,279946,150433,28084,0,60317,0,0,0, + 30114,0,0,26048,0,0,0,0,0,0,3295737,20647296, + 81000,19592714,42049809,15699583,13648777,13620617,11091935,23696672,9896380,7114238,5590637,7290515, + 8492126,3382493,2631488,1418490,3059735,2415177,3194264,1572255,1006959,732137,610159,314443, + 601682,591149,234701,135897,76103,58883,330582,226182,204420,53546,0,0, + 0,94444,214083,522118,434078,621542,2398977,605839,800353,354953,224060,225268, + 299375,344125,200,0,62942,119657,0,32185,34798,81270,75039,0, + 0,158595,181079,29320,0,0,0,2118879,652594,149718,427247,413198, + 198565,6502947,9118685,8953724,20255359,18652807,6001482,1909014,3082130,1971424,1698686,1228900, + 1222503,1800774,3198056,2334523,421355,335691,189425,78417,174729,187642,458306,596013, + 472277,817786,606170,332839,301805,488547,373861,143842,52682,184891,144327,78508, + 66146,88283,194381,356642,171747,379228,476055,112432,238033,175943,58163,0, + 39939,52551,82747,32021,57797,34035,67664,64808,0,0,33630,56862, + 0,356678,0,0,55035,0,0,603468,652320,231882,0,0, + 0,0,2281278,2647710,3181650,2892458,2581204,393964,354906,115932,469432,771477, + 510925,701337,415875,668256,193794,374160,0,0,200,0,250653,87512, + 26292,200,213998,125456,117227,161033,245100,118865,194595,310876,339978,197377, + 200,0,0,28321,172385,59585,161067,30373,0,0,0,0, + 0,0,0,0,26430,33626,59040,55334,30863,0,32152,0, + 113221,38808,0,0,0,0,0,29154,0,0,200,0, + 0,0,0,87063,309737,499023,78183,0,0,0,69523,0, + 0,84890,78693,200,25959,0,0,0,27738,0,59923,200, + 0,35248,0,51843,77511,200,0,0,0,25880,200,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,29684,0,200,61161,0, + 0,0,0,0,0,0,200,0,0,0,0,0, + 0,0,59425,77705,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,25863,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,26081, + 0,0,0,0,0,0,0,0,26010,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,200,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,200,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0, + + }; +} diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java new file mode 100644 index 0000000..9a93196 --- /dev/null +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -0,0 +1,676 @@ +package btools.routingapp; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +import android.app.Activity; +import android.content.Context; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.os.AsyncTask; +import android.os.PowerManager; +import android.os.StatFs; +import android.util.DisplayMetrics; +import android.view.MotionEvent; +import android.view.View; +import android.widget.Toast; +import btools.mapaccess.PhysicalFile; + +public class BInstallerView extends View +{ + private static final int MASK_SELECTED_RD5 = 1; + private static final int MASK_SELECTED_CD5 = 2; + private static final int MASK_INSTALLED_RD5 = 4; + private static final int MASK_INSTALLED_CD5 = 8; + + private static final int[] maskTransitions = new int[] + { 3, 2, 0, 1, + 6, 6, 4, 4, + 9, 8, 9, 8, + 12, 12, 12, 12 }; + + private int imgw; + private int imgh; + + private float lastDownX; + private float lastDownY; + + private Bitmap bmp; + + private float viewscale; + + private float[] testVector = new float[2]; + + private int[] tileStatus; + + private boolean tilesVisible = false; + + private long lastDownTime = 0; + + private long availableSize; + private String baseDir; + + private boolean isDownloading = false; + private transient boolean downloadCanceled = false; + + private long currentDownloadSize; + private String currentDownloadFile = ""; + private String downloadAction = ""; + + private long totalSize = 0; + private long rd5Tiles = 0; + private long cd5Tiles = 0; + + protected String baseNameForTile( int tileIndex ) + { + int lon = (tileIndex % 72 ) * 5 - 180; + int lat = (tileIndex / 72 ) * 5 - 90; + String slon = lon < 0 ? "W" + (-lon) : "E" + lon; + String slat = lat < 0 ? "S" + (-lat) : "N" + lat; + return slon + "_" + slat; + } + + private int gridPos2Tileindex( int ix, int iy ) + { + return (35-iy)*72 + ( ix >= 70 ? ix-70: ix+2 ); + } + + private int tileForBaseName( String basename ) + { + String uname = basename.toUpperCase(); + int idx = uname.indexOf( "_" ); + if ( idx < 0 ) return -1; + String slon = uname.substring( 0, idx ); + String slat = uname.substring( idx+1 ); + int ilon = slon.charAt(0) == 'W' ? -Integer.valueOf( slon.substring(1) ) : + ( slon.charAt(0) == 'E' ? Integer.valueOf( slon.substring(1) ) : -1 ); + int ilat = slat.charAt(0) == 'S' ? -Integer.valueOf( slat.substring(1) ) : + ( slat.charAt(0) == 'N' ? Integer.valueOf( slat.substring(1) ) : -1 ); + if ( ilon < -180 || ilon >= 180 || ilon % 5 != 0 ) return -1; + if ( ilat < - 90 || ilat >= 90 || ilat % 5 != 0 ) return -1; + return (ilon+180) / 5 + 72*((ilat+90)/5); + } + + + public boolean isDownloadCanceled() + { + return downloadCanceled; + } + + private void toggleDownload() + { + if ( isDownloading ) + { + downloadCanceled = true; + downloadAction = "Canceling..."; + return; + } + + int tidx_min = -1; + boolean isCd5_min = false; + int min_size = Integer.MAX_VALUE; + + // prepare download list + for( int ix=0; ix<72; ix++ ) + { + for( int iy=0; iy<36; iy++ ) + { + int tidx = gridPos2Tileindex( ix, iy ); + for( int mask = 1; mask <= 2; mask *= 2 ) + { + int s = tileStatus[tidx]; + boolean isCd5 = (mask == 2); + if ( ( s & mask ) != 0 && ( s & (mask*4)) == 0 ) + { + int tilesize = isCd5 ? BInstallerSizes.cd5_sizes[tidx] : BInstallerSizes.rd5_sizes[tidx]; + if ( tilesize > 0 && tilesize < min_size ) + { + tidx_min = tidx; + isCd5_min = isCd5; + min_size = tilesize; + } + } + } + } + } + if ( tidx_min != -1 ) + { + startDownload( tidx_min, isCd5_min ); + } + } + + private void startDownload( int tileIndex, boolean isCd5 ) + { + String namebase = baseNameForTile( tileIndex ); + String baseurl = "http://h2096617.stratoserver.net/brouter/segments2/"; + currentDownloadFile = namebase + (isCd5 ? ".cd5" : ".rd5" ); + String url = baseurl + (isCd5 ? "carsubset/" : "" ) + currentDownloadFile; + isDownloading = true; + downloadCanceled = false; + currentDownloadSize = 0; + downloadAction = "Connecting... "; + final DownloadTask downloadTask = new DownloadTask(getContext()); + downloadTask.execute( url ); + } + + public void downloadDone( boolean success ) + { + isDownloading = false; + if ( success ) + { + scanExistingFiles(); + toggleDownload(); // keep on if no error + } + invalidate(); + } + + private int tileIndex( float x, float y ) + { + int ix = (int)(72.f * x / bmp.getWidth()); + int iy = (int)(36.f * y / bmp.getHeight()); + if ( ix >= 0 && ix < 72 && iy >= 0 && iy < 36 ) return gridPos2Tileindex(ix, iy); + return -1; + } + + private void clearTileSelection( int mask ) + { + // clear selection if zooming out + for( int ix=0; ix<72; ix++ ) + for( int iy=0; iy<36; iy++ ) + { + int tidx = gridPos2Tileindex( ix, iy ); + tileStatus[tidx] ^= tileStatus[tidx] & mask; + } + } + + // get back the current image scale + private float currentScale() + { + testVector[1] = 1.f; + mat.mapVectors(testVector); + return testVector[1] / viewscale; + } + + private void scanExistingFiles() + { + clearTileSelection( MASK_INSTALLED_CD5 | MASK_INSTALLED_RD5 ); + + scanExistingFiles( new File( baseDir + "/brouter/segments2" ), ".rd5", MASK_INSTALLED_RD5 ); + scanExistingFiles( new File( baseDir + "/brouter/segments2/carsubset" ), ".cd5", MASK_INSTALLED_CD5 ); + + StatFs stat = new StatFs(baseDir); + availableSize = (long)stat.getAvailableBlocks()*stat.getBlockSize(); + } + + private void scanExistingFiles( File dir, String suffix, int maskBit ) + { + String[] fileNames = dir.list(); + if ( fileNames == null ) return; + for( String fileName : fileNames ) + { + if ( fileName.endsWith( suffix ) ) + { + String basename = fileName.substring( 0, fileName.length() - suffix.length() ); + int tidx = tileForBaseName( basename ); + tileStatus[tidx] |= maskBit; + tileStatus[tidx] ^= tileStatus[tidx] & (maskBit >> 2); + } + } + } + + private Matrix mat; + + public void startInstaller() { + + baseDir = ConfigHelper.getBaseDir( getContext() ); + + try + { + AssetManager assetManager = getContext().getAssets(); + InputStream istr = assetManager.open("world.png"); + bmp = BitmapFactory.decodeStream(istr); + istr.close(); + } + catch( IOException io ) + { + throw new RuntimeException( "cannot read world.png from assets" ); + } + + tileStatus = new int[72*36]; + scanExistingFiles(); + + float scaleX = imgw / ((float)bmp.getWidth()); + float scaley = imgh / ((float)bmp.getHeight()); + + viewscale = scaleX < scaley ? scaleX : scaley; + + mat = new Matrix(); + mat.postScale( viewscale, viewscale ); + tilesVisible = false; + } + + public void stopInstaller() { + downloadCanceled = true; + bmp = null; + tileStatus = null; + } + + public BInstallerView(Context context) { + super(context); + + DisplayMetrics metrics = new DisplayMetrics(); + ((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); + imgw = metrics.widthPixels; + imgh = metrics.heightPixels; + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + } + + private void toast( String msg ) + { + Toast.makeText(getContext(), msg, Toast.LENGTH_LONG ).show(); + } + + @Override + protected void onDraw(Canvas canvas) + { + if ( !isDownloading ) + { + canvas.setMatrix( mat ); + canvas.drawBitmap(bmp, 0,0, null); + } + // draw 5*5 lattice starting at scale=3 + + int iw = bmp.getWidth(); + int ih = bmp.getHeight(); + float fw = iw / 72.f; + float fh = ih / 36.f; + + boolean drawGrid = tilesVisible && !isDownloading; + + if ( drawGrid ) + { + + Paint pnt_1 = new Paint(); + pnt_1.setColor(Color.GREEN); + + for( int ix=1; ix<72; ix++ ) + { + float fx = fw*ix; + canvas.drawLine( fx, 0, fx, ih, pnt_1); + } + for( int iy=1; iy<36; iy++ ) + { + float fy = fh*iy; + canvas.drawLine( 0, fy, iw, fy, pnt_1); + } + } + rd5Tiles = 0; + cd5Tiles = 0; + totalSize = 0; + Paint pnt_2 = new Paint(); + pnt_2.setColor(Color.GRAY); + pnt_2.setStrokeWidth(1); + drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5, MASK_INSTALLED_CD5, false, drawGrid ); + pnt_2.setColor(Color.GREEN); + pnt_2.setStrokeWidth(2); + drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5, MASK_SELECTED_CD5, true, drawGrid ); + + canvas.setMatrix( null ); + + Paint paint = new Paint(); + paint.setColor(Color.RED); + + long mb = 1024*1024; + + if ( isDownloading ) + { + String sizeHint = currentDownloadSize > 0 ? " (" + ((currentDownloadSize + mb-1)/mb) + " MB)" : ""; + paint.setTextSize(30); + canvas.drawText( "Loading " + currentDownloadFile + sizeHint, 30, (imgh/3)*2-30, paint); + canvas.drawText( downloadAction, 30, (imgh/3)*2, paint); + } + if ( !tilesVisible ) + { + paint.setTextSize(40); + canvas.drawText( "Zoom in to see grid!", 30, (imgh/3)*2, paint); + } + paint.setTextSize(20); + + + + String totmb = ((totalSize + mb-1)/mb) + " MB"; + String freemb = ((availableSize + mb-1)/mb) + " MB"; + canvas.drawText( "Selected: full=" + rd5Tiles + " carsubset=" + cd5Tiles, 10, 25, paint ); + canvas.drawText( "Size=" + totmb + " Free=" + freemb , 10, 45, paint ); + + + String btnText = null; + if ( isDownloading ) btnText = "Cancel Download"; + else if ( rd5Tiles + cd5Tiles > 0 ) btnText = "Start Download"; + + if ( btnText != null ) + { + 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-btnw, 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.drawText( btnText , imgw-btnw+5, imgh-10, paint ); + } + } + + int btnh = 40; + int btnw = 160; + + +float tx, ty; + + private void drawSelectedTiles( Canvas canvas, Paint pnt, float fw, float fh, int maskRd5, int maskCd5, boolean doCount, boolean doDraw ) + { + for( int ix=0; ix<72; ix++ ) + for( int iy=0; iy<36; iy++ ) + { + int tidx = gridPos2Tileindex( ix, iy ); + boolean isRd5 = (tileStatus[tidx] & maskRd5) != 0; + boolean isCd5 = (tileStatus[tidx] & maskCd5) != 0; + if ( isRd5 || isCd5 ) + { + int tilesize = BInstallerSizes.rd5_sizes[tidx]; + if ( tilesize > 0 ) + { + if ( doCount ) + { + if ( isRd5) { rd5Tiles++; totalSize += BInstallerSizes.rd5_sizes[tidx]; }; + if ( isCd5) { cd5Tiles++; totalSize += BInstallerSizes.cd5_sizes[tidx]; }; + } + if ( !doDraw ) continue; + if ( isRd5 ) canvas.drawLine( fw*ix, fh*iy, fw*(ix+1), fh*(iy+1), pnt); + if ( isCd5 ) canvas.drawLine( fw*ix, fh*(iy+1), 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, fw*ix, fh*(iy+1), pnt); + canvas.drawLine( fw*(ix+1), fh*iy, fw*(ix+1), fh*(iy+1), pnt); + } + } + } + } + + + @Override + public boolean onTouchEvent(MotionEvent event) { + + // get pointer index from the event object + int pointerIndex = event.getActionIndex(); + + // get pointer ID + int pointerId = event.getPointerId(pointerIndex); + + // get masked (not specific to a pointer) action + int maskedAction = event.getActionMasked(); + + switch (maskedAction) { + + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: { + lastDownX = event.getX(); + lastDownY = event.getY(); + + break; + } + case MotionEvent.ACTION_MOVE: { // a pointer was moved + + if ( isDownloading ) break; + int np = event.getPointerCount(); + int nh = event.getHistorySize(); + if ( nh == 0 ) break; + + float x0 = event.getX( 0 ); + float y0 = event.getY( 0 ); + float hx0 = event.getHistoricalX(0,0); + float hy0 = event.getHistoricalY(0,0); + + if ( np > 1 ) // multi-touch + { + float x1 = event.getX( 1 ); + float y1 = event.getY( 1 ); + float hx1 = event.getHistoricalX(1,0); + float hy1 = event.getHistoricalY(1,0); + + 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) ); + + if ( hr > 10. ) + { + float ratio = r/hr; + + float mx = (x1+x0)/2.f; + float my = (y1+y0)/2.f; + + float scale = currentScale(); + float newscale = scale*ratio; + + if ( newscale > 10.f ) ratio *= (10.f / newscale ); + if ( newscale < 0.5f ) ratio *= (0.5f / newscale ); + + mat.postScale( ratio, ratio, mx, my ); + + mat.postScale( ratio, ratio, mx, my ); + + boolean tilesv = currentScale() >= 3.f; + if ( tilesVisible && !tilesv ) + { + clearTileSelection( MASK_SELECTED_CD5 | MASK_SELECTED_RD5 ); + } + tilesVisible = tilesv; + } + + break; + } + mat.postTranslate( x0-hx0, y0-hy0 ); + + break; + } + case MotionEvent.ACTION_UP: + + lastDownTime = event.getEventTime() - event.getDownTime(); + + if ( lastDownTime < 5 || lastDownTime > 500 ) + { + break; + } + + if ( Math.abs(lastDownX - event.getX() ) > 10 || Math.abs(lastDownY - event.getY() ) > 10 ) + { + break; + } + + // download button? + if ( rd5Tiles + cd5Tiles > 0 && event.getX() > imgh - btnh && event.getY() > imgh-btnh ) + { + toggleDownload(); + invalidate(); + break; + } + + if ( isDownloading || !tilesVisible ) break; + + Matrix imat = new Matrix(); + if ( mat.invert(imat) ) + { + float[] touchpoint = new float[2]; + touchpoint[0] = event.getX(); + touchpoint[1] = event.getY(); + imat.mapPoints(touchpoint); + + int tidx = tileIndex( touchpoint[0], touchpoint[1] ); + if ( tidx != -1 ) + { + tileStatus[tidx] = maskTransitions[tileStatus[tidx]]; + } + + tx = touchpoint[0]; + ty = touchpoint[1]; + } + + + break; + case MotionEvent.ACTION_POINTER_UP: + case MotionEvent.ACTION_CANCEL: { + // TODO use data + break; + } + } + invalidate(); + + return true; + } + + // usually, subclasses of AsyncTask are declared inside the activity class. + // that way, you can easily modify the UI thread from here + private class DownloadTask extends AsyncTask { + + private Context context; + private PowerManager.WakeLock mWakeLock; + + public DownloadTask(Context context) { + this.context = context; + } + + @Override + protected String doInBackground(String... sUrls) + { + InputStream input = null; + OutputStream output = null; + HttpURLConnection connection = null; + String surl = sUrls[0]; + String fname = null; + File tmp_file = null; + try + { + try + { + URL url = new URL(surl); + + connection = (HttpURLConnection) url.openConnection(); + connection.connect(); + + // expect HTTP 200 OK, so we don't mistakenly save error report + // instead of the file + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { + return "Server returned HTTP " + connection.getResponseCode() + + " " + connection.getResponseMessage(); + } + + // this will be useful to display download percentage + // might be -1: server did not report the length + int fileLength = connection.getContentLength(); + currentDownloadSize = fileLength; + if ( fileLength > availableSize ) return "not enough space on sd-card"; + + // download the file + input = connection.getInputStream(); + + int slidx = surl.lastIndexOf( "segments2/" ); + fname = baseDir + "/brouter/segments2/" + surl.substring( slidx+10 ); + tmp_file = new File( fname + "_tmp" ); + if ( new File( fname ).exists() ) return "internal error: file exists: " + fname; + output = new FileOutputStream( tmp_file ); + + byte data[] = new byte[4096]; + long total = 0; + long t0 = System.currentTimeMillis(); + int count; + while ((count = input.read(data)) != -1) { + if (isDownloadCanceled()) { + return "Download canceled!"; + } + total += count; + // publishing the progress.... + if (fileLength > 0) // only if total length is known + publishProgress((int) (total * 100 / fileLength)); + output.write(data, 0, count); + + // enforce < 200kB/s + long dt = t0 + total/200 - System.currentTimeMillis(); + if ( dt > 0 ) + { + try { Thread.sleep( dt ); } catch( InterruptedException ie ) {} + } + } + } catch (Exception e) { + return e.toString(); + } finally { + try { + if (output != null) + output.close(); + if (input != null) + input.close(); + } catch (IOException ignored) { + } + + if (connection != null) + connection.disconnect(); + } + publishProgress( 101 ); + String check_result = PhysicalFile.checkFileIntegrity( tmp_file ); + if ( check_result != null ) return check_result; + + if ( !tmp_file.renameTo( new File( fname ) ) ) + { + return "Could not rename to " + fname; + } + return null; + } + finally + { + if ( tmp_file != null ) tmp_file.delete(); // just to be sure + } + } + + @Override + protected void onPreExecute() { + super.onPreExecute(); + // take CPU lock to prevent CPU from going off if the user + // presses the power button during download + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); + mWakeLock.acquire(); + } + + @Override + protected void onProgressUpdate(Integer... progress) { + String newAction = progress[0] == 101 ? "Verifying.." : "Progress " + progress[0] + "%"; + if ( !newAction.equals( downloadAction ) ) + { + downloadAction = newAction; + invalidate(); + } + } + + @Override + protected void onPostExecute(String result) { + mWakeLock.release(); + downloadDone( result == null ); + + if (result != null) + Toast.makeText(context,"Download error: "+result, Toast.LENGTH_LONG).show(); + else + Toast.makeText(context,"File downloaded", Toast.LENGTH_SHORT).show(); + } + + } // download task +} diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java index 2bbbc66..6358fdd 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java @@ -1,5 +1,7 @@ package btools.routingapp; +import java.text.DecimalFormat; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -7,10 +9,14 @@ import java.util.Set; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; +import android.net.ConnectivityManager; import android.os.Bundle; import android.os.PowerManager; import android.os.PowerManager.WakeLock; +import android.os.StatFs; import android.speech.tts.TextToSpeech.OnInitListener; import android.widget.EditText; import btools.router.OsmNodeNamed; @@ -19,7 +25,7 @@ public class BRouterActivity extends Activity implements OnInitListener { private static final int DIALOG_SELECTPROFILE_ID = 1; private static final int DIALOG_EXCEPTION_ID = 2; - private static final int DIALOG_WARNEXPIRY_ID = 3; + private static final int DIALOG_SHOW_DM_INFO_ID = 3; private static final int DIALOG_TEXTENTRY_ID = 4; private static final int DIALOG_VIASELECT_ID = 5; private static final int DIALOG_NOGOSELECT_ID = 6; @@ -27,6 +33,8 @@ public class BRouterActivity extends Activity implements OnInitListener { private static final int DIALOG_ROUTINGMODES_ID = 8; private static final int DIALOG_MODECONFIGOVERVIEW_ID = 9; private static final int DIALOG_PICKWAYPOINT_ID = 10; + private static final int DIALOG_SELECTBASEDIR_ID = 11; + private static final int DIALOG_MAINACTION_ID = 12; private BRouterView mBRouterView; private PowerManager mPowerManager; @@ -67,6 +75,37 @@ public class BRouterActivity extends Activity implements OnInitListener { } }); return builder.create(); + case DIALOG_MAINACTION_ID: + builder = new AlertDialog.Builder(this); + builder.setTitle("Select Main Action"); + builder.setItems( new String[] { "Download Manager", "BRouter App" }, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int item) { + if ( item == 0 ) startDownloadManager(); + else showDialog( DIALOG_SELECTPROFILE_ID ); + } + }); + return builder.create(); + case DIALOG_SHOW_DM_INFO_ID: + builder = new AlertDialog.Builder(this); + builder.setTitle( "BRouter Download Manager" ) + .setMessage( "*** Attention: ***\n\n" + + "The Download Manager is used to download routing-data " + + "files which can be huge. Do not start the Download Manager " + + "on a cellular data connection without a flat-rate! " + + "Download speed is restricted to 200 kB/s." ) + .setPositiveButton( "I know", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Intent intent = new Intent(BRouterActivity.this, BInstallerActivity.class); + startActivity(intent); + finish(); + } + }) + .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + finish(); + } + }); + return builder.create(); case DIALOG_ROUTINGMODES_ID: builder = new AlertDialog.Builder(this); builder.setTitle( message ); @@ -93,15 +132,6 @@ public class BRouterActivity extends Activity implements OnInitListener { } }); return builder.create(); - case DIALOG_WARNEXPIRY_ID: - builder = new AlertDialog.Builder(this); - builder.setMessage( errorMessage ) - .setPositiveButton( "OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - mBRouterView.startProcessing(selectedProfile); - } - }); - return builder.create(); case DIALOG_TEXTENTRY_ID: builder = new AlertDialog.Builder(this); builder.setTitle("Enter SDCARD base dir:"); @@ -116,6 +146,30 @@ public class BRouterActivity extends Activity implements OnInitListener { } }); return builder.create(); + case DIALOG_SELECTBASEDIR_ID: + builder = new AlertDialog.Builder(this); + builder.setTitle("Select an SDCARD base dir:"); + builder.setSingleChoiceItems(basedirOptions, 0, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int item ) + { + selectedBasedir = item; + } + }); + builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) + { + if ( selectedBasedir < availableBasedirs.size() ) + { + mBRouterView.startSetup(availableBasedirs.get(selectedBasedir), true ); + } + else + { + showDialog( DIALOG_TEXTENTRY_ID ); + } + } + }); + return builder.create(); case DIALOG_VIASELECT_ID: builder = new AlertDialog.Builder(this); builder.setTitle("Check VIA Selection:"); @@ -221,6 +275,10 @@ public class BRouterActivity extends Activity implements OnInitListener { private String[] availableProfiles; private String selectedProfile = null; + private List availableBasedirs; + private String[] basedirOptions; + private int selectedBasedir; + private String[] availableWaypoints; private String[] routingModes; @@ -234,11 +292,64 @@ public class BRouterActivity extends Activity implements OnInitListener { private List nogoList; + public boolean isOnline() { + ConnectivityManager cm = + (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + + return cm.getActiveNetworkInfo() != null && + cm.getActiveNetworkInfo().isConnectedOrConnecting(); + } + @SuppressWarnings("deprecation") public void selectProfile( String[] items ) { availableProfiles = items; - showDialog( DIALOG_SELECTPROFILE_ID ); + + // if we have internet access, first show the main action dialog + if ( isOnline() ) + { + showDialog( DIALOG_MAINACTION_ID ); + } + else + { + showDialog( DIALOG_SELECTPROFILE_ID ); + } + } + + @SuppressWarnings("deprecation") + public void startDownloadManager() + { + showDialog( DIALOG_SHOW_DM_INFO_ID ); + } + + @SuppressWarnings("deprecation") + public void selectBasedir( List items, String defaultBasedir, String message ) + { + this.defaultbasedir = defaultBasedir; + this.message = message; + availableBasedirs = new ArrayList(); + ArrayList dirFreeSizes = new ArrayList(); + for( String d : items ) + { + StatFs stat = new StatFs(d); + long size = (long)stat.getAvailableBlocks()*stat.getBlockSize(); + int idx = 0; + while ( idx < availableBasedirs.size() && dirFreeSizes.get(idx).longValue() > size ) idx++; + availableBasedirs.add( idx, d ); + dirFreeSizes.add( idx, Long.valueOf( size ) ); + } + + basedirOptions= new String[items.size() + 1]; + int bdidx = 0; + DecimalFormat df = new DecimalFormat( "###0.00" ); + for( int idx=0; idx getStorageDirectories() + { + ArrayList res = new ArrayList(); + res.add( Environment.getExternalStorageDirectory().getPath() ); + BufferedReader br = null; + try + { + br = new BufferedReader(new FileReader("/proc/mounts")); + for(;;) + { + String line = br.readLine(); + if ( line == null ) break; + if (line.indexOf("vfat") < 0 && line.indexOf("/mnt") < 0 ) continue; + StringTokenizer tokens = new StringTokenizer(line, " "); + tokens.nextToken(); + String d = tokens.nextToken(); + boolean isExternalDir = false; + if ( line.contains( "/dev/block/vold" ) ) + { + isExternalDir = true; + String[] vetos = new String[] { "/mnt/secure", "/mnt/asec", "/mnt/obb", "/dev/mapper", "tmpfs" }; + for( String v: vetos ) + { + if ( d.indexOf( v ) >= 0 ) + { + isExternalDir = false; + } + } + } + if ( isExternalDir ) + { + if ( !res.contains( d ) ) + { + res.add( d ); + } + } + } + } + catch ( Exception e) { /* ignore */ } + finally + { + if (br != null) { try { br.close(); } catch (Exception e) { /* ignore */ } } + } + return res; + } + } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/ConfigHelper.java b/brouter-routing-app/src/main/java/btools/routingapp/ConfigHelper.java new file mode 100644 index 0000000..720c9ac --- /dev/null +++ b/brouter-routing-app/src/main/java/btools/routingapp/ConfigHelper.java @@ -0,0 +1,51 @@ +package btools.routingapp; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +import android.content.Context; + + +/** + * Decsription of a service config + */ +public class ConfigHelper +{ + public static String getBaseDir( Context ctx ) + { + // get base dir from private file + InputStream configInput = null; + try + { + configInput = ctx.openFileInput( "config.dat" ); + BufferedReader br = new BufferedReader( new InputStreamReader (configInput ) ); + return br.readLine(); + } + catch( Exception e ) { return null; } + finally + { + if ( configInput != null ) try { configInput.close(); } catch( Exception ee ) {} + } + } + + public static void writeBaseDir( Context ctx, String baseDir ) + { + BufferedWriter bw = null; + try + { + OutputStream configOutput = ctx.openFileOutput( "config.dat", Context.MODE_PRIVATE ); + bw = new BufferedWriter( new OutputStreamWriter (configOutput ) ); + bw.write( baseDir ); + bw.write( '\n' ); + } + catch( Exception e ) {} + finally + { + if ( bw != null ) try { bw.close(); } catch( Exception ee ) {} + } + } +} diff --git a/pom.xml b/pom.xml index 474dee7..f806f11 100644 --- a/pom.xml +++ b/pom.xml @@ -40,15 +40,22 @@ com.jayway.maven.plugins.android.generation2 android-maven-plugin - 3.8.2 + 3.6.0 true gen gen true - 19 + 10 + + + -Xmn16m + -Xms256m + -Xmx512m + +