From 553f064ce0435da1a8c5a26888a853548fcbfac4 Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sat, 20 Nov 2021 14:42:05 +0100 Subject: [PATCH 01/19] Optimize Imports --- .../btools/routingapp/BInstallerActivity.java | 8 +++--- .../btools/routingapp/BInstallerView.java | 25 +++++-------------- 2 files changed, 9 insertions(+), 24 deletions(-) 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 9fdbc76..9b58547 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -1,8 +1,5 @@ package btools.routingapp; -import java.util.HashSet; -import java.util.Set; - import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -16,9 +13,10 @@ import android.os.Build; import android.os.Bundle; import android.os.PowerManager; import android.os.PowerManager.WakeLock; -import android.speech.tts.TextToSpeech.OnInitListener; import android.os.StatFs; -import android.util.Log; + +import java.util.HashSet; +import java.util.Set; public class BInstallerActivity extends Activity { 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 f262cfc..2752b8e 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -1,15 +1,5 @@ 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 java.util.ArrayList; -import java.util.Locale; - import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -20,21 +10,18 @@ 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.AttributeSet; import android.util.DisplayMetrics; -import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.widget.Toast; -import btools.mapaccess.PhysicalFile; -import btools.mapaccess.Rd5DiffManager; -import btools.mapaccess.Rd5DiffTool; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Locale; + import btools.router.RoutingHelper; -import btools.util.ProgressListener; public class BInstallerView extends View { private static final int MASK_SELECTED_RD5 = 1; From 89ef74f95b6c67549309588f1a721b4d52c0e33d Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Tue, 19 Oct 2021 06:00:04 +0200 Subject: [PATCH 02/19] Android Studio automatic cleanup --- .../btools/routingapp/BInstallerActivity.java | 29 ++-- .../btools/routingapp/BInstallerView.java | 125 ++++++++---------- 2 files changed, 65 insertions(+), 89 deletions(-) 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 9b58547..e42b3d0 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -28,20 +28,7 @@ public class BInstallerActivity extends Activity { private PowerManager mPowerManager; private WakeLock mWakeLock; private DownloadReceiver myReceiver; - - - public class DownloadReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - if (intent.hasExtra("txt")) { - String txt = intent.getStringExtra("txt"); - boolean ready = intent.getBooleanExtra("ready", false); - mBInstallerView.setState(txt, ready); - } - } - } - + private final Set dialogIds = new HashSet(); /** * Called when the activity is first created. @@ -132,8 +119,6 @@ public class BInstallerActivity extends Activity { showDialog(DIALOG_CONFIRM_DELETE_ID); } - private Set dialogIds = new HashSet(); - private void showNewDialog(int id) { if (dialogIds.contains(Integer.valueOf(id))) { removeDialog(id); @@ -142,6 +127,18 @@ public class BInstallerActivity extends Activity { showDialog(id); } + public class DownloadReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + if (intent.hasExtra("txt")) { + String txt = intent.getStringExtra("txt"); + boolean ready = intent.getBooleanExtra("ready", false); + mBInstallerView.setState(txt, ready); + } + } + } + static public long getAvailableSpace(String baseDir) { StatFs stat = new StatFs(baseDir); 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 2752b8e..0ba2448 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -28,50 +28,63 @@ public class BInstallerView extends View { private static final int MASK_DELETED_RD5 = 2; private static final int MASK_INSTALLED_RD5 = 4; private static final int MASK_CURRENT_RD5 = 8; - - private int imgwOrig; - private int imghOrig; - private float scaleOrig; - - 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 availableSize; - private File baseDir; - private File segmentDir; - - private boolean isDownloading = false; public static boolean downloadCanceled = false; - - private long currentDownloadSize; - private String currentDownloadFile = ""; - private volatile String currentDownloadOperation = ""; - private String downloadAction = ""; - private volatile String newDownloadAction = ""; - - private long totalSize = 0; - private long rd5Tiles = 0; - private long delTiles = 0; - Paint pnt_1 = new Paint(); Paint pnt_2 = new Paint(); Paint paint = new Paint(); - Activity mActivity; + int btnh = 40; + int btnw = 160; + float tx, ty; + private final int imgwOrig; + private final int imghOrig; + private final float scaleOrig; + private final int imgw; + private final int imgh; + private float lastDownX; + private float lastDownY; + private Bitmap bmp; + private float viewscale; + private final float[] testVector = new float[2]; + private int[] tileStatus; + private boolean tilesVisible = false; + private long availableSize; + private File baseDir; + private File segmentDir; + private boolean isDownloading = false; + private long currentDownloadSize; + private final String currentDownloadFile = ""; + private volatile String currentDownloadOperation = ""; + private String downloadAction = ""; + private final String newDownloadAction = ""; + private long totalSize = 0; + private long rd5Tiles = 0; + private long delTiles = 0; + private Matrix mat; + private final Matrix matText; + public BInstallerView(Context context) { + super(context); + mActivity = (Activity) context; + + DisplayMetrics metrics = new DisplayMetrics(); + ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); + imgwOrig = metrics.widthPixels; + imghOrig = metrics.heightPixels; + int im = imgwOrig > imghOrig ? imgwOrig : imghOrig; + + scaleOrig = im / 480.f; + + matText = new Matrix(); + matText.preScale(scaleOrig, scaleOrig); + + imgw = (int) (imgwOrig / scaleOrig); + imgh = (int) (imghOrig / scaleOrig); + + totalSize = 0; + rd5Tiles = 0; + delTiles = 0; + } protected String baseNameForTile(int tileIndex) { int lon = (tileIndex % 72) * 5 - 180; @@ -100,7 +113,6 @@ public class BInstallerView extends View { return (ilon + 180) / 5 + 72 * ((ilat + 90) / 5); } - public boolean isDownloadCanceled() { return downloadCanceled; } @@ -167,7 +179,6 @@ public class BInstallerView extends View { deleteRawTracks(); // invalidate raw-tracks after data update } - public void downloadDone(boolean success) { isDownloading = false; if (success) { @@ -234,7 +245,7 @@ public class BInstallerView extends View { availableSize = -1; try { - availableSize = (long) ((BInstallerActivity) getContext()).getAvailableSpace(baseDir.getAbsolutePath()); + availableSize = ((BInstallerActivity) getContext()).getAvailableSpace(baseDir.getAbsolutePath()); //StatFs stat = new StatFs(baseDir.getAbsolutePath ()); //availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong(); } catch (Exception e) { /* ignore */ } @@ -256,9 +267,6 @@ public class BInstallerView extends View { } } - private Matrix mat; - private Matrix matText; - public void startInstaller() { baseDir = ConfigHelper.getBaseDir(getContext()); @@ -285,29 +293,6 @@ public class BInstallerView extends View { tilesVisible = false; } - public BInstallerView(Context context) { - super(context); - mActivity = (Activity) context; - - DisplayMetrics metrics = new DisplayMetrics(); - ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); - imgwOrig = metrics.widthPixels; - imghOrig = metrics.heightPixels; - int im = imgwOrig > imghOrig ? imgwOrig : imghOrig; - - scaleOrig = im / 480.f; - - matText = new Matrix(); - matText.preScale(scaleOrig, scaleOrig); - - imgw = (int) (imgwOrig / scaleOrig); - imgh = (int) (imghOrig / scaleOrig); - - totalSize = 0; - rd5Tiles = 0; - delTiles = 0; - } - @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); @@ -411,12 +396,6 @@ public class BInstallerView extends View { } } - int btnh = 40; - int btnw = 160; - - - float tx, ty; - 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++) { From de7dd71a944e7120a3111b52bc288069c61bcf28 Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Tue, 19 Oct 2021 06:06:34 +0200 Subject: [PATCH 03/19] Apply Quick Fixes suggested by Android Studio --- .../btools/routingapp/BInstallerActivity.java | 6 +-- .../btools/routingapp/BInstallerView.java | 48 ++----------------- 2 files changed, 8 insertions(+), 46 deletions(-) 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 e42b3d0..1b80c6b 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -28,7 +28,7 @@ public class BInstallerActivity extends Activity { private PowerManager mPowerManager; private WakeLock mWakeLock; private DownloadReceiver myReceiver; - private final Set dialogIds = new HashSet(); + private final Set dialogIds = new HashSet<>(); /** * Called when the activity is first created. @@ -120,10 +120,10 @@ public class BInstallerActivity extends Activity { } private void showNewDialog(int id) { - if (dialogIds.contains(Integer.valueOf(id))) { + if (dialogIds.contains(id)) { removeDialog(id); } - dialogIds.add(Integer.valueOf(id)); + dialogIds.add(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 0ba2448..a209bf7 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -13,7 +13,6 @@ import android.graphics.Paint; import android.util.DisplayMetrics; import android.view.MotionEvent; import android.view.View; -import android.widget.Toast; import java.io.File; import java.io.IOException; @@ -52,11 +51,8 @@ public class BInstallerView extends View { private File baseDir; private File segmentDir; private boolean isDownloading = false; - private long currentDownloadSize; - private final String currentDownloadFile = ""; private volatile String currentDownloadOperation = ""; private String downloadAction = ""; - private final String newDownloadAction = ""; private long totalSize = 0; private long rd5Tiles = 0; private long delTiles = 0; @@ -71,7 +67,7 @@ public class BInstallerView extends View { ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); imgwOrig = metrics.widthPixels; imghOrig = metrics.heightPixels; - int im = imgwOrig > imghOrig ? imgwOrig : imghOrig; + int im = Math.max(imgwOrig, imghOrig); scaleOrig = im / 480.f; @@ -80,10 +76,6 @@ public class BInstallerView extends View { imgw = (int) (imgwOrig / scaleOrig); imgh = (int) (imghOrig / scaleOrig); - - totalSize = 0; - rd5Tiles = 0; - delTiles = 0; } protected String baseNameForTile(int tileIndex) { @@ -113,10 +105,6 @@ public class BInstallerView extends View { return (ilon + 180) / 5 + 72 * ((ilat + 90) / 5); } - public boolean isDownloadCanceled() { - return downloadCanceled; - } - private void toggleDownload() { if (isDownloading) { downloadCanceled = true; @@ -129,7 +117,6 @@ public class BInstallerView extends View { return; } - int tidx_min = -1; int min_size = Integer.MAX_VALUE; ArrayList downloadList = new ArrayList<>(); @@ -141,7 +128,6 @@ public class BInstallerView extends View { int tilesize = BInstallerSizes.getRd5Size(tidx); downloadList.add(tidx); if (tilesize > 0 && tilesize < min_size) { - tidx_min = tidx; min_size = tilesize; } } @@ -152,7 +138,7 @@ public class BInstallerView extends View { isDownloading = true; downloadAll(downloadList); for (Integer i : downloadList) { - tileStatus[i.intValue()] ^= tileStatus[i.intValue()] & MASK_SELECTED_RD5; + tileStatus[i] ^= tileStatus[i] & MASK_SELECTED_RD5; } downloadList.clear(); } @@ -161,7 +147,7 @@ public class BInstallerView extends View { private void downloadAll(ArrayList downloadList) { ArrayList urlparts = new ArrayList<>(); for (Integer i : downloadList) { - urlparts.add(baseNameForTile(i.intValue())); + urlparts.add(baseNameForTile(i)); } currentDownloadOperation = "Start download ..."; @@ -169,8 +155,6 @@ public class BInstallerView extends View { downloadCanceled = false; isDownloading = true; - //final DownloadBackground downloadTask = new DownloadBackground(getContext(), urlparts, baseDir); - //downloadTask.execute( ); Intent intent = new Intent(mActivity, DownloadService.class); intent.putExtra("dir", baseDir.getAbsolutePath() + "/brouter/"); intent.putExtra("urlparts", urlparts); @@ -179,15 +163,6 @@ public class BInstallerView extends View { deleteRawTracks(); // invalidate raw-tracks after data update } - public void downloadDone(boolean success) { - isDownloading = false; - if (success) { - scanExistingFiles(); - toggleDownload(); // keep on if no error - } - invalidate(); - } - public void setState(String txt, boolean b) { currentDownloadOperation = txt; downloadAction = ""; @@ -245,9 +220,7 @@ public class BInstallerView extends View { availableSize = -1; try { - availableSize = ((BInstallerActivity) getContext()).getAvailableSpace(baseDir.getAbsolutePath()); - //StatFs stat = new StatFs(baseDir.getAbsolutePath ()); - //availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong(); + availableSize = BInstallerActivity.getAvailableSpace(baseDir.getAbsolutePath()); } catch (Exception e) { /* ignore */ } } @@ -286,7 +259,7 @@ public class BInstallerView extends View { float scaleX = imgwOrig / ((float) bmp.getWidth()); float scaley = imghOrig / ((float) bmp.getHeight()); - viewscale = scaleX < scaley ? scaleX : scaley; + viewscale = Math.min(scaleX, scaley); mat = new Matrix(); mat.postScale(viewscale, viewscale); @@ -298,10 +271,6 @@ public class BInstallerView extends View { super.onSizeChanged(w, h, oldw, oldh); } - private void toast(String msg) { - Toast.makeText(getContext(), msg, Toast.LENGTH_LONG).show(); - } - @Override protected void onDraw(Canvas canvas) { if (!isDownloading) { @@ -359,7 +328,6 @@ public class BInstallerView extends View { long mb = 1024 * 1024; if (isDownloading) { - String sizeHint = currentDownloadSize > 0 ? " (" + ((currentDownloadSize + mb - 1) / mb) + " MB)" : ""; paint.setTextSize(30); canvas.drawText(currentDownloadOperation, 30, (imgh / 3) * 2 - 30, paint); // canvas.drawText( currentDownloadOperation + " " + currentDownloadFile + sizeHint, 30, (imgh/3)*2-30, paint); @@ -443,12 +411,6 @@ public class BInstallerView extends View { @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(); From dd7a2fcd98969bf34fe3f84ecfa9e1985cf70b82 Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Tue, 4 Jan 2022 12:01:57 +0100 Subject: [PATCH 04/19] More Fixes --- .../btools/routingapp/BInstallerActivity.java | 38 ++++++------------- .../btools/routingapp/BInstallerView.java | 14 +++---- 2 files changed, 18 insertions(+), 34 deletions(-) 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 1b80c6b..2c27b50 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -15,26 +15,31 @@ import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.StatFs; -import java.util.HashSet; -import java.util.Set; - public class BInstallerActivity extends Activity { public static final String DOWNLOAD_ACTION = "btools.routingapp.download"; private static final int DIALOG_CONFIRM_DELETE_ID = 1; - private BInstallerView mBInstallerView; private PowerManager mPowerManager; private WakeLock mWakeLock; private DownloadReceiver myReceiver; - private final Set dialogIds = new HashSet<>(); + + static public long getAvailableSpace(String baseDir) { + StatFs stat = new StatFs(baseDir); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + return stat.getAvailableBlocksLong() * stat.getBlockSizeLong(); + } else { + //noinspection deprecation + return (long) stat.getAvailableBlocks() * stat.getBlockSize(); + } + } /** * Called when the activity is first created. */ @Override - @SuppressWarnings("deprecation") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -91,7 +96,6 @@ public class BInstallerActivity extends Activity { } @Override - @SuppressWarnings("deprecation") protected Dialog onCreateDialog(int id) { AlertDialog.Builder builder; switch (id) { @@ -114,19 +118,10 @@ public class BInstallerActivity extends Activity { } } - @SuppressWarnings("deprecation") public void showConfirmDelete() { showDialog(DIALOG_CONFIRM_DELETE_ID); } - private void showNewDialog(int id) { - if (dialogIds.contains(id)) { - removeDialog(id); - } - dialogIds.add(id); - showDialog(id); - } - public class DownloadReceiver extends BroadcastReceiver { @Override @@ -138,15 +133,4 @@ public class BInstallerActivity extends Activity { } } } - - - static public long getAvailableSpace(String baseDir) { - StatFs stat = new StatFs(baseDir); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - return stat.getAvailableBlocksLong() * stat.getBlockSizeLong(); - } else { - return stat.getAvailableBlocks() * stat.getBlockSize(); - } - } } 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 a209bf7..d3c3199 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -28,6 +28,13 @@ public class BInstallerView extends View { private static final int MASK_INSTALLED_RD5 = 4; private static final int MASK_CURRENT_RD5 = 8; public static boolean downloadCanceled = false; + private final int imgwOrig; + private final int imghOrig; + private final float scaleOrig; + private final int imgw; + private final int imgh; + private final float[] testVector = new float[2]; + private final Matrix matText; Paint pnt_1 = new Paint(); Paint pnt_2 = new Paint(); Paint paint = new Paint(); @@ -35,16 +42,10 @@ public class BInstallerView extends View { int btnh = 40; int btnw = 160; float tx, ty; - private final int imgwOrig; - private final int imghOrig; - private final float scaleOrig; - private final int imgw; - private final int imgh; private float lastDownX; private float lastDownY; private Bitmap bmp; private float viewscale; - private final float[] testVector = new float[2]; private int[] tileStatus; private boolean tilesVisible = false; private long availableSize; @@ -57,7 +58,6 @@ public class BInstallerView extends View { private long rd5Tiles = 0; private long delTiles = 0; private Matrix mat; - private final Matrix matText; public BInstallerView(Context context) { super(context); From 64a80e763ba8d8b48bd2cadda045946f1a7f6254 Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Tue, 19 Oct 2021 06:13:37 +0200 Subject: [PATCH 05/19] Merge startInstaller into constructor --- .../btools/routingapp/BInstallerActivity.java | 7 --- .../btools/routingapp/BInstallerView.java | 61 +++++++++---------- 2 files changed, 29 insertions(+), 39 deletions(-) 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 2c27b50..4a3ef2e 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -36,9 +36,6 @@ public class BInstallerActivity extends Activity { } } - /** - * Called when the activity is first created. - */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -52,7 +49,6 @@ public class BInstallerActivity extends Activity { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - // instantiate our simulation view and set it as the activity's content mBInstallerView = new BInstallerView(this); setContentView(mBInstallerView); } @@ -72,9 +68,6 @@ public class BInstallerActivity extends Activity { myReceiver = new DownloadReceiver(); registerReceiver(myReceiver, filter); - - // Start the download manager - mBInstallerView.startInstaller(); } @Override 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 d3c3199..f86188b 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -35,6 +35,12 @@ public class BInstallerView extends View { private final int imgh; private final float[] testVector = new float[2]; private final Matrix matText; + private final File baseDir; + private final File segmentDir; + private final Matrix mat; + private final Bitmap bmp; + private final float viewscale; + private final int[] tileStatus; Paint pnt_1 = new Paint(); Paint pnt_2 = new Paint(); Paint paint = new Paint(); @@ -44,20 +50,14 @@ public class BInstallerView extends View { float tx, ty; private float lastDownX; private float lastDownY; - private Bitmap bmp; - private float viewscale; - private int[] tileStatus; private boolean tilesVisible = false; private long availableSize; - private File baseDir; - private File segmentDir; private boolean isDownloading = false; private volatile String currentDownloadOperation = ""; private String downloadAction = ""; private long totalSize = 0; private long rd5Tiles = 0; private long delTiles = 0; - private Matrix mat; public BInstallerView(Context context) { super(context); @@ -76,6 +76,29 @@ public class BInstallerView extends View { imgw = (int) (imgwOrig / scaleOrig); imgh = (int) (imghOrig / scaleOrig); + + baseDir = ConfigHelper.getBaseDir(getContext()); + segmentDir = new File(baseDir, "brouter/segments4"); + + 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 = imgwOrig / ((float) bmp.getWidth()); + float scaley = imghOrig / ((float) bmp.getHeight()); + + viewscale = Math.min(scaleX, scaley); + + mat = new Matrix(); + mat.postScale(viewscale, viewscale); } protected String baseNameForTile(int tileIndex) { @@ -240,32 +263,6 @@ public class BInstallerView extends View { } } - public void startInstaller() { - - baseDir = ConfigHelper.getBaseDir(getContext()); - segmentDir = new File(baseDir, "brouter/segments4"); - 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 = imgwOrig / ((float) bmp.getWidth()); - float scaley = imghOrig / ((float) bmp.getHeight()); - - viewscale = Math.min(scaleX, scaley); - - mat = new Matrix(); - mat.postScale(viewscale, viewscale); - tilesVisible = false; - } - @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); From 32747a1f6f99249de4b4736dafaaaf72a4d24cd8 Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Fri, 15 Oct 2021 16:30:05 +0200 Subject: [PATCH 06/19] Remove wakelock from BInstallerActivity --- .../btools/routingapp/BInstallerActivity.java | 23 ------------------- 1 file changed, 23 deletions(-) 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 4a3ef2e..1cae08b 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -11,8 +11,6 @@ import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.os.Build; import android.os.Bundle; -import android.os.PowerManager; -import android.os.PowerManager.WakeLock; import android.os.StatFs; public class BInstallerActivity extends Activity { @@ -21,8 +19,6 @@ public class BInstallerActivity extends Activity { private static final int DIALOG_CONFIRM_DELETE_ID = 1; private BInstallerView mBInstallerView; - private PowerManager mPowerManager; - private WakeLock mWakeLock; private DownloadReceiver myReceiver; static public long getAvailableSpace(String baseDir) { @@ -40,13 +36,6 @@ public class BInstallerActivity extends Activity { 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); mBInstallerView = new BInstallerView(this); @@ -56,12 +45,6 @@ public class BInstallerActivity extends Activity { @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(); IntentFilter filter = new IntentFilter(); filter.addAction(DOWNLOAD_ACTION); @@ -73,12 +56,6 @@ public class BInstallerActivity extends Activity { @Override protected void onPause() { super.onPause(); - - - super.onPause(); - - mWakeLock.release(); - } @Override From e045a732fb601725069817c7a507bdc4b12a76ab Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Fri, 15 Oct 2021 16:31:13 +0200 Subject: [PATCH 07/19] Rename DownloadReceiver --- .../main/java/btools/routingapp/BInstallerActivity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 1cae08b..5a787f8 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -19,7 +19,7 @@ public class BInstallerActivity extends Activity { private static final int DIALOG_CONFIRM_DELETE_ID = 1; private BInstallerView mBInstallerView; - private DownloadReceiver myReceiver; + private DownloadReceiver downloadReceiver; static public long getAvailableSpace(String baseDir) { StatFs stat = new StatFs(baseDir); @@ -49,8 +49,8 @@ public class BInstallerActivity extends Activity { IntentFilter filter = new IntentFilter(); filter.addAction(DOWNLOAD_ACTION); - myReceiver = new DownloadReceiver(); - registerReceiver(myReceiver, filter); + downloadReceiver = new DownloadReceiver(); + registerReceiver(downloadReceiver, filter); } @Override @@ -61,7 +61,7 @@ public class BInstallerActivity extends Activity { @Override public void onDestroy() { super.onDestroy(); - if (myReceiver != null) unregisterReceiver(myReceiver); + if (downloadReceiver != null) unregisterReceiver(downloadReceiver); System.exit(0); } From 806ae6250e14defabd306eb3ec9019ae283149ab Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sat, 16 Oct 2021 06:54:02 +0200 Subject: [PATCH 08/19] Draw rect using canvas --- .../src/main/java/btools/routingapp/BInstallerView.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 f86188b..0b9376b 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -352,11 +352,9 @@ public class BInstallerView extends View { RoutingHelper.hasDirectoryAnyDatafiles(segmentDir)) btnText = "Update all"; 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); + paint.setStyle(Paint.Style.STROKE); + canvas.drawRect(imgw - btnw, imgh - btnh, imgw - 2, imgh - 2, paint); + paint.setStyle(Paint.Style.FILL); canvas.drawText(btnText, imgw - btnw + 5, imgh - 10, paint); } } From 89f075fa6162d370bc30629c12ec3ec1ea95c88e Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sun, 17 Oct 2021 07:37:00 +0200 Subject: [PATCH 09/19] Draw only available segments --- .../btools/routingapp/BInstallerView.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) 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 0b9376b..c7e2395 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -284,24 +284,26 @@ public class BInstallerView extends View { boolean drawGrid = tilesVisible && !isDownloading; if (drawGrid) { - 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); + pnt_1.setStyle(Paint.Style.STROKE); + for (int ix = 0; ix < 72; ix++) { + for (int iy = 0; iy < 36; iy++) { + int tidx = gridPos2Tileindex(ix, iy); + int tilesize = BInstallerSizes.getRd5Size(tidx); + if (tilesize > 0) { + canvas.drawRect(fw * ix, fh * (iy + 1), fw * (ix + 1), fh * iy, pnt_1); + } + } } } + rd5Tiles = 0; delTiles = 0; totalSize = 0; int mask2 = MASK_SELECTED_RD5 | MASK_DELETED_RD5 | MASK_INSTALLED_RD5; int mask3 = mask2 | MASK_CURRENT_RD5; + pnt_2.setStyle(Paint.Style.STROKE); pnt_2.setColor(Color.GRAY); pnt_2.setStrokeWidth(1); drawSelectedTiles(canvas, pnt_2, fw, fh, MASK_INSTALLED_RD5, mask3, false, false, drawGrid); @@ -381,10 +383,7 @@ public class BInstallerView extends View { canvas.drawLine(fw * ix, fh * (iy + 1), fw * (ix + 1), fh * iy, pnt); // draw frame - 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); + canvas.drawRect(fw * ix, fh * (iy + 1), fw * (ix + 1), fh * iy, pnt); } } } From 6045a18a610b47a5890dc10b0da126d46684901f Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sat, 30 Oct 2021 08:05:51 +0200 Subject: [PATCH 10/19] Inflate BInstallerView from layout --- .../java/btools/routingapp/BInstallerActivity.java | 4 ++-- .../main/java/btools/routingapp/BInstallerView.java | 5 +++-- .../src/main/res/layout/activity_binstaller.xml | 11 +++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 brouter-routing-app/src/main/res/layout/activity_binstaller.xml 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 5a787f8..e5565e5 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -38,8 +38,8 @@ public class BInstallerActivity extends Activity { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - mBInstallerView = new BInstallerView(this); - setContentView(mBInstallerView); + setContentView(R.layout.activity_binstaller); + mBInstallerView = findViewById(R.id.BInstallerView); } @Override 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 c7e2395..7643050 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -10,6 +10,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; +import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.MotionEvent; import android.view.View; @@ -59,8 +60,8 @@ public class BInstallerView extends View { private long rd5Tiles = 0; private long delTiles = 0; - public BInstallerView(Context context) { - super(context); + public BInstallerView(Context context, AttributeSet attrs) { + super(context, attrs); mActivity = (Activity) context; DisplayMetrics metrics = new DisplayMetrics(); diff --git a/brouter-routing-app/src/main/res/layout/activity_binstaller.xml b/brouter-routing-app/src/main/res/layout/activity_binstaller.xml new file mode 100644 index 0000000..1fd64f7 --- /dev/null +++ b/brouter-routing-app/src/main/res/layout/activity_binstaller.xml @@ -0,0 +1,11 @@ + + + + + From 51ef5c6aad2f21479cc77ea874a170c14343699f Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sat, 30 Oct 2021 09:25:51 +0200 Subject: [PATCH 11/19] Show download progress in different view --- .../btools/routingapp/BInstallerActivity.java | 71 +++++++++++- .../btools/routingapp/BInstallerView.java | 106 ++++-------------- .../btools/routingapp/DownloadService.java | 2 +- .../main/res/layout/activity_binstaller.xml | 33 +++++- .../src/main/res/values/strings.xml | 3 + 5 files changed, 124 insertions(+), 91 deletions(-) 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 e5565e5..f2ec66b 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -12,14 +12,24 @@ import android.content.pm.ActivityInfo; import android.os.Build; import android.os.Bundle; import android.os.StatFs; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import java.io.File; +import java.util.ArrayList; public class BInstallerActivity extends Activity { public static final String DOWNLOAD_ACTION = "btools.routingapp.download"; - private static final int DIALOG_CONFIRM_DELETE_ID = 1; + public static boolean downloadCanceled = false; + private File baseDir; private BInstallerView mBInstallerView; private DownloadReceiver downloadReceiver; + private View mDownloadInfo; + private TextView mDownloadInfoText; + private Button mButtonDownloadCancel; static public long getAvailableSpace(String baseDir) { StatFs stat = new StatFs(baseDir); @@ -40,6 +50,58 @@ public class BInstallerActivity extends Activity { setContentView(R.layout.activity_binstaller); mBInstallerView = findViewById(R.id.BInstallerView); + mDownloadInfo = findViewById(R.id.view_download_progress); + mDownloadInfoText = findViewById(R.id.textViewDownloadProgress); + mButtonDownloadCancel = findViewById(R.id.buttonDownloadCancel); + mButtonDownloadCancel.setOnClickListener(view -> { + cancelDownload(); + }); + + baseDir = ConfigHelper.getBaseDir(this); + } + + private 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 void deleteRawTracks() { + File modeDir = new File(baseDir, "brouter/modes"); + String[] fileNames = modeDir.list(); + if (fileNames == null) return; + for (String fileName : fileNames) { + if (fileName.endsWith("_rawtrack.dat")) { + File f = new File(modeDir, fileName); + f.delete(); + } + } + } + + private void cancelDownload() { + downloadCanceled = true; + mDownloadInfoText.setText(getString(R.string.download_info_cancel)); + } + + public void downloadAll(ArrayList downloadList) { + ArrayList urlparts = new ArrayList<>(); + for (Integer i : downloadList) { + urlparts.add(baseNameForTile(i)); + } + + mBInstallerView.setVisibility(View.GONE); + mDownloadInfo.setVisibility(View.VISIBLE); + downloadCanceled = false; + mDownloadInfoText.setText(R.string.download_info_start); + + Intent intent = new Intent(this, DownloadService.class); + intent.putExtra("dir", baseDir.getAbsolutePath() + "/brouter/"); + intent.putExtra("urlparts", urlparts); + startService(intent); + + deleteRawTracks(); // invalidate raw-tracks after data update } @Override @@ -99,7 +161,12 @@ public class BInstallerActivity extends Activity { if (intent.hasExtra("txt")) { String txt = intent.getStringExtra("txt"); boolean ready = intent.getBooleanExtra("ready", false); - mBInstallerView.setState(txt, ready); + if (!ready) { + mBInstallerView.setVisibility(View.VISIBLE); + mDownloadInfo.setVisibility(View.GONE); + scanExistingFiles(); + } + mDownloadInfoText.setText(txt); } } } 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 7643050..8d3a101 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -2,7 +2,6 @@ package btools.routingapp; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -28,7 +27,12 @@ public class BInstallerView extends View { private static final int MASK_DELETED_RD5 = 2; private static final int MASK_INSTALLED_RD5 = 4; private static final int MASK_CURRENT_RD5 = 8; - public static boolean downloadCanceled = false; + private final File baseDir; + private final File segmentDir; + private final Matrix mat; + private final Bitmap bmp; + private final float viewscale; + private final int[] tileStatus; private final int imgwOrig; private final int imghOrig; private final float scaleOrig; @@ -36,12 +40,6 @@ public class BInstallerView extends View { private final int imgh; private final float[] testVector = new float[2]; private final Matrix matText; - private final File baseDir; - private final File segmentDir; - private final Matrix mat; - private final Bitmap bmp; - private final float viewscale; - private final int[] tileStatus; Paint pnt_1 = new Paint(); Paint pnt_2 = new Paint(); Paint paint = new Paint(); @@ -53,9 +51,6 @@ public class BInstallerView extends View { private float lastDownY; private boolean tilesVisible = false; private long availableSize; - private boolean isDownloading = false; - private volatile String currentDownloadOperation = ""; - private String downloadAction = ""; private long totalSize = 0; private long rd5Tiles = 0; private long delTiles = 0; @@ -130,12 +125,6 @@ public class BInstallerView extends View { } private void toggleDownload() { - if (isDownloading) { - downloadCanceled = true; - downloadAction = "Canceling..."; - return; - } - if (delTiles > 0) { ((BInstallerActivity) getContext()).showConfirmDelete(); return; @@ -159,8 +148,8 @@ public class BInstallerView extends View { } if (downloadList.size() > 0) { - isDownloading = true; - downloadAll(downloadList); + // isDownloading = true; + ((BInstallerActivity) getContext()).downloadAll(downloadList); for (Integer i : downloadList) { tileStatus[i] ^= tileStatus[i] & MASK_SELECTED_RD5; } @@ -168,35 +157,6 @@ public class BInstallerView extends View { } } - private void downloadAll(ArrayList downloadList) { - ArrayList urlparts = new ArrayList<>(); - for (Integer i : downloadList) { - urlparts.add(baseNameForTile(i)); - } - - currentDownloadOperation = "Start download ..."; - downloadAction = ""; - downloadCanceled = false; - isDownloading = true; - - Intent intent = new Intent(mActivity, DownloadService.class); - intent.putExtra("dir", baseDir.getAbsolutePath() + "/brouter/"); - intent.putExtra("urlparts", urlparts); - mActivity.startService(intent); - - deleteRawTracks(); // invalidate raw-tracks after data update - } - - public void setState(String txt, boolean b) { - currentDownloadOperation = txt; - downloadAction = ""; - isDownloading = b; - if (!b) { - scanExistingFiles(); - } - invalidate(); - } - private int tileIndex(float x, float y) { int ix = (int) (72.f * x / bmp.getWidth()); int iy = (int) (36.f * y / bmp.getHeight()); @@ -220,18 +180,6 @@ public class BInstallerView extends View { return testVector[1] / viewscale; } - private void deleteRawTracks() { - File modeDir = new File(baseDir, "brouter/modes"); - String[] fileNames = modeDir.list(); - if (fileNames == null) return; - for (String fileName : fileNames) { - if (fileName.endsWith("_rawtrack.dat")) { - File f = new File(modeDir, fileName); - f.delete(); - } - } - } - private void scanExistingFiles() { clearTileSelection(MASK_INSTALLED_RD5 | MASK_CURRENT_RD5); @@ -271,10 +219,8 @@ public class BInstallerView extends View { @Override protected void onDraw(Canvas canvas) { - 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 int iw = bmp.getWidth(); @@ -282,9 +228,7 @@ public class BInstallerView extends View { float fw = iw / 72.f; float fh = ih / 36.f; - boolean drawGrid = tilesVisible && !isDownloading; - - if (drawGrid) { + if (tilesVisible) { pnt_1.setColor(Color.GREEN); pnt_1.setStyle(Paint.Style.STROKE); for (int ix = 0; ix < 72; ix++) { @@ -307,19 +251,19 @@ public class BInstallerView extends View { pnt_2.setStyle(Paint.Style.STROKE); pnt_2.setColor(Color.GRAY); 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, tilesVisible); pnt_2.setColor(Color.BLUE); 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, tilesVisible); pnt_2.setColor(Color.GREEN); 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, tilesVisible); pnt_2.setColor(Color.YELLOW); 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, tilesVisible); 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); + drawSelectedTiles(canvas, pnt_2, fw, fh, MASK_DELETED_RD5 | MASK_INSTALLED_RD5, mask2, false, true, tilesVisible); canvas.setMatrix(matText); @@ -327,13 +271,7 @@ public class BInstallerView extends View { long mb = 1024 * 1024; - if (isDownloading) { - paint.setTextSize(30); - canvas.drawText(currentDownloadOperation, 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); - } - if (!tilesVisible && !isDownloading) { + if (!this.tilesVisible) { paint.setTextSize(35); canvas.drawText("Touch region to zoom in!", 30, (imgh / 3) * 2, paint); } @@ -347,10 +285,9 @@ public class BInstallerView extends View { String btnText = null; - if (isDownloading) btnText = "Cancel Download"; - else if (delTiles > 0) btnText = "Delete " + delTiles + " tiles"; + if (delTiles > 0) btnText = "Delete " + delTiles + " tiles"; else if (rd5Tiles > 0) btnText = "Start Download"; - else if (tilesVisible && + else if (this.tilesVisible && rd5Tiles == 0 && RoutingHelper.hasDirectoryAnyDatafiles(segmentDir)) btnText = "Update all"; @@ -420,7 +357,6 @@ public class BInstallerView extends View { } case MotionEvent.ACTION_MOVE: { // a pointer was moved - if (isDownloading) break; int np = event.getPointerCount(); int nh = event.getHistorySize(); if (nh == 0) break; @@ -482,7 +418,7 @@ public class BInstallerView extends View { } // download button? - if ((delTiles > 0 || rd5Tiles >= 0 || isDownloading) && event.getX() > imgwOrig - btnw * scaleOrig && event.getY() > imghOrig - btnh * scaleOrig) { + if ((delTiles > 0 || rd5Tiles >= 0) && event.getX() > imgwOrig - btnw * scaleOrig && event.getY() > imghOrig - btnh * scaleOrig) { if (rd5Tiles == 0) { for (int ix = 0; ix < 72; ix++) { for (int iy = 0; iy < 36; iy++) { @@ -511,8 +447,6 @@ public class BInstallerView extends View { break; } - if (isDownloading) break; - Matrix imat = new Matrix(); if (mat.invert(imat)) { float[] touchpoint = new float[2]; diff --git a/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java b/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java index 2726327..7457a84 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java @@ -481,7 +481,7 @@ public class DownloadService extends Service implements ProgressListener { public boolean isCanceled() { - return BInstallerView.downloadCanceled; + return BInstallerActivity.downloadCanceled; } } diff --git a/brouter-routing-app/src/main/res/layout/activity_binstaller.xml b/brouter-routing-app/src/main/res/layout/activity_binstaller.xml index 1fd64f7..ccaa634 100644 --- a/brouter-routing-app/src/main/res/layout/activity_binstaller.xml +++ b/brouter-routing-app/src/main/res/layout/activity_binstaller.xml @@ -1,11 +1,40 @@ + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + + + +