diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java index 55d19a6..52c2c98 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -1,6 +1,12 @@ package btools.routingapp; +import java.util.HashSet; +import java.util.Set; + import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.PowerManager; @@ -9,6 +15,8 @@ import android.speech.tts.TextToSpeech.OnInitListener; public class BInstallerActivity extends Activity implements OnInitListener { + private static final int DIALOG_CONFIRM_DELETE_ID = 1; + private BInstallerView mBInstallerView; private PowerManager mPowerManager; private WakeLock mWakeLock; @@ -58,6 +66,52 @@ public class BInstallerActivity extends Activity implements OnInitListener { { } + @Override + @SuppressWarnings("deprecation") + protected Dialog onCreateDialog( int id ) + { + AlertDialog.Builder builder; + switch ( id ) + { + case DIALOG_CONFIRM_DELETE_ID: + builder = new AlertDialog.Builder( this ); + builder + .setTitle( "Confirm Delete" ) + .setMessage( "Really delete?" ).setPositiveButton( "Yes", new DialogInterface.OnClickListener() + { + public void onClick( DialogInterface dialog, int id ) + { + mBInstallerView.deleteSelectedTiles(); + } + } ).setNegativeButton( "No", new DialogInterface.OnClickListener() + { + public void onClick( DialogInterface dialog, int id ) + { + } + } ); + return builder.create(); + + default: + return null; + } + } + @SuppressWarnings("deprecation") + public void showConfirmDelete() + { + showDialog( DIALOG_CONFIRM_DELETE_ID ); + } + + private Set dialogIds = new HashSet(); + + private void showNewDialog( int id ) + { + if ( dialogIds.contains( Integer.valueOf( id ) ) ) + { + removeDialog( id ); + } + dialogIds.add( Integer.valueOf( id ) ); + showDialog( id ); + } } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java index 2302a5a..53f3787 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -32,7 +32,8 @@ import btools.util.ProgressListener; 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_INSTALLED_RD5 = 4; private static final int MASK_CURRENT_RD5 = 8; @@ -70,6 +71,7 @@ public class BInstallerView extends View private long totalSize = 0; private long rd5Tiles = 0; + private long delTiles = 0; protected String baseNameForTile( int tileIndex ) { @@ -116,6 +118,12 @@ public class BInstallerView extends View return; } + if ( delTiles > 0 ) + { + ( (BInstallerActivity) getContext() ).showConfirmDelete(); + return; + } + int tidx_min = -1; int min_size = Integer.MAX_VALUE; @@ -247,7 +255,7 @@ public class BInstallerView extends View tileStatus[tidx] |= MASK_INSTALLED_RD5; long age = System.currentTimeMillis() - new File( dir, fileName ).lastModified(); - if ( age < 300000 ) tileStatus[tidx] |= MASK_CURRENT_RD5; // 5 minutes + if ( age < 10800000 ) tileStatus[tidx] |= MASK_CURRENT_RD5; // 3 hours } } } @@ -346,22 +354,26 @@ public class BInstallerView extends View } } rd5Tiles = 0; + delTiles = 0; totalSize = 0; - int mask2 = MASK_SELECTED_RD5 | MASK_INSTALLED_RD5; + int mask2 = MASK_SELECTED_RD5 | MASK_DELETED_RD5 | MASK_INSTALLED_RD5; int mask3 = mask2 | MASK_CURRENT_RD5; Paint pnt_2 = new Paint(); pnt_2.setColor(Color.GRAY); pnt_2.setStrokeWidth(1); - drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5, mask3, false, drawGrid ); + drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5, mask3, false, false, drawGrid ); pnt_2.setColor(Color.BLUE); pnt_2.setStrokeWidth(1); - drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5 | MASK_CURRENT_RD5, mask3, 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.setStrokeWidth(2); - drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5, mask2, true, drawGrid ); + drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5, mask2, true, false, drawGrid ); pnt_2.setColor(Color.YELLOW); pnt_2.setStrokeWidth(2); - drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5 | MASK_INSTALLED_RD5, mask2, true, drawGrid ); + drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5 | MASK_INSTALLED_RD5, mask2, true, false, drawGrid ); + pnt_2.setColor(Color.RED); + pnt_2.setStrokeWidth(2); + drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_DELETED_RD5 | MASK_INSTALLED_RD5, mask2, false, true, drawGrid ); canvas.setMatrix( matText ); @@ -394,6 +406,7 @@ public class BInstallerView extends View String btnText = null; if ( isDownloading ) btnText = "Cancel Download"; + else if ( delTiles > 0 ) btnText = "Delete " + delTiles + " tiles"; else if ( rd5Tiles > 0 ) btnText = "Start Download"; if ( btnText != null ) @@ -413,7 +426,7 @@ public class BInstallerView extends View float tx, ty; - private void drawSelectedTiles( Canvas canvas, Paint pnt, float fw, float fh, int status, int mask, boolean doCount, 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 iy = 0; iy < 36; iy++ ) @@ -429,6 +442,11 @@ float tx, ty; rd5Tiles++; totalSize += BInstallerSizes.getRd5Size( tidx ); } + if ( cntDel ) + { + delTiles++; + totalSize += BInstallerSizes.getRd5Size( tidx ); + } if ( !doDraw ) continue; // draw cross @@ -445,6 +463,23 @@ float tx, ty; } } + public void deleteSelectedTiles() + { + for ( int ix = 0; ix < 72; ix++ ) + { + for ( int iy = 0; iy < 36; iy++ ) + { + int tidx = gridPos2Tileindex( ix, iy ); + if ( ( tileStatus[tidx] & MASK_DELETED_RD5 ) != 0 ) + { + new File( baseDir + "/brouter/segments4/" + baseNameForTile( tidx ) + ".rd5").delete(); + } + } + } + scanExistingFiles(); + invalidate(); + } + @Override public boolean onTouchEvent(MotionEvent event) { @@ -508,7 +543,7 @@ float tx, ty; boolean tilesv = currentScale() >= 3.f; if ( tilesVisible && !tilesv ) { - clearTileSelection( MASK_SELECTED_RD5 ); + clearTileSelection( MASK_SELECTED_RD5 | MASK_DELETED_RD5 ); } tilesVisible = tilesv; } @@ -534,7 +569,7 @@ float tx, ty; } // download button? - if ( ( 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 ) { toggleDownload(); invalidate(); @@ -554,9 +589,21 @@ float tx, ty; int tidx = tileIndex( touchpoint[0], touchpoint[1] ); if ( tidx != -1 ) { - if ( ( tileStatus[tidx] & MASK_CURRENT_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 ) + { + tileStatus[tidx] |= MASK_DELETED_RD5; + } + } + else if ( ( tileStatus[tidx] & MASK_DELETED_RD5 ) != 0 ) + { + tileStatus[tidx] ^= MASK_DELETED_RD5; + } + else + { + tileStatus[tidx] ^= MASK_SELECTED_RD5; } }