From 639157c2248094c64b6402abc1b72ba2bfd8c2ee Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 16 Oct 2013 20:52:10 +0200 Subject: [PATCH] Basic async task thread --- .../src/net/osmand/plus/osmedit/OsmBugsLayer.java | 15 +++++++++------ .../osmand/plus/srtmplugin/HillshadeLayer.java | 8 ++++---- .../osmand/plus/views/DownloadedRegionsLayer.java | 4 ++-- .../src/net/osmand/plus/views/OsmandMapLayer.java | 5 +++++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index d7d2dff34b..2fa79edb9e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -396,7 +396,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider } private void createNewBugAsync(final double latitude, final double longitude, final String text) { - new AsyncTask() { + AsyncTask task = new AsyncTask() { @Override protected String doInBackground(Void... params) { return getOsmbugsUtil(null).createNewBug(latitude, longitude, text); @@ -414,11 +414,12 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider openBugAlertDialog(latitude, longitude, text); } }; - }.execute(); + }; + executeTaskInBackground(task); } private void addingCommentAsync(final OpenStreetNote bug, final String text) { - new AsyncTask() { + AsyncTask task = new AsyncTask() { @Override protected String doInBackground(Void... params) { return getOsmbugsUtil(bug).addingComment(bug.getId(), text); @@ -431,7 +432,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider AccessibleToast.makeText(activity, activity.getResources().getString(R.string.osb_comment_dialog_error) + "\n" + warn, Toast.LENGTH_LONG).show(); } }; - }.execute(); + }; + executeTaskInBackground(task); } @@ -504,7 +506,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider } private void closingAsync(final OpenStreetNote bug, final String text) { - new AsyncTask() { + AsyncTask task = new AsyncTask() { @Override protected String doInBackground(Void... params) { return getOsmbugsUtil(bug).closingBug(bug.getId(), ""); @@ -520,7 +522,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider Toast.LENGTH_LONG).show(); } }; - }.execute(); + }; + executeTaskInBackground(task); } @Override diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java index d99e3d46d8..726103f28f 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java @@ -126,7 +126,7 @@ public class HillshadeLayer extends MapTileLayer { } }; - task.execute(); + executeTaskInBackground(task); } private SQLiteTileSource createTileSource(MapActivity activity) { @@ -143,11 +143,11 @@ public class HillshadeLayer extends MapTileLayer { List getTileSource(int x, int y, int zoom) { ArrayList ls = new ArrayList(); - int z = (zoom- ZOOM_BOUNDARY ); - if(z > 0){ + int z = (zoom - ZOOM_BOUNDARY); + if (z > 0) { indexedResources.queryInBox(new QuadRect(x >> z, y >> z, (x >> z), (y >> z)), ls); } else { - indexedResources.queryInBox(new QuadRect(x << -z, y << -z, (x+1)<<-z, (y+1)<<-z), ls); + indexedResources.queryInBox(new QuadRect(x << -z, y << -z, (x + 1) << -z, (y + 1) << -z), ls); } return ls; } diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index c23bb4fb7f..70a9cdc88c 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -149,7 +149,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { tileBox.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2); AsyncTask> task = createNewTask(tileBox); if (currentTask == null) { - task.execute(); + executeTaskInBackground(task); } else { pendingTask = task; } @@ -259,7 +259,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { } currentTask = null; if (pendingTask != null) { - pendingTask.execute(); + executeTaskInBackground(pendingTask); pendingTask = null; } } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 071da3b0e8..18a74abe8c 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -6,6 +6,7 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; import android.graphics.Canvas; import android.graphics.PointF; +import android.os.AsyncTask; import android.view.MotionEvent; public abstract class OsmandMapLayer { @@ -34,6 +35,10 @@ public abstract class OsmandMapLayer { public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { return false;} + public void executeTaskInBackground(AsyncTask task, Params... params){ + task.execute(params); + } + /** * This method returns whether canvas should be rotated as * map rotated before {@link #onDraw(android.graphics.Canvas, net.osmand.data.RotatedTileBox, net.osmand.plus.views.OsmandMapLayer.DrawSettings)}.