Basic async task thread

This commit is contained in:
vshcherb 2013-10-16 20:52:10 +02:00
parent 82a751545c
commit 639157c224
4 changed files with 20 additions and 12 deletions

View file

@ -396,7 +396,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
private void createNewBugAsync(final double latitude, final double longitude, final String text) { private void createNewBugAsync(final double latitude, final double longitude, final String text) {
new AsyncTask<Void, Void, String>() { AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override @Override
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
return getOsmbugsUtil(null).createNewBug(latitude, longitude, text); return getOsmbugsUtil(null).createNewBug(latitude, longitude, text);
@ -414,11 +414,12 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
openBugAlertDialog(latitude, longitude, text); openBugAlertDialog(latitude, longitude, text);
} }
}; };
}.execute(); };
executeTaskInBackground(task);
} }
private void addingCommentAsync(final OpenStreetNote bug, final String text) { private void addingCommentAsync(final OpenStreetNote bug, final String text) {
new AsyncTask<Void, Void, String>() { AsyncTask<Void,Void,String> task = new AsyncTask<Void, Void, String>() {
@Override @Override
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
return getOsmbugsUtil(bug).addingComment(bug.getId(), text); 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(); 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) { private void closingAsync(final OpenStreetNote bug, final String text) {
new AsyncTask<Void, Void, String>() { AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override @Override
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
return getOsmbugsUtil(bug).closingBug(bug.getId(), ""); return getOsmbugsUtil(bug).closingBug(bug.getId(), "");
@ -520,7 +522,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
}; };
}.execute(); };
executeTaskInBackground(task);
} }
@Override @Override

View file

@ -126,7 +126,7 @@ public class HillshadeLayer extends MapTileLayer {
} }
}; };
task.execute(); executeTaskInBackground(task);
} }
private SQLiteTileSource createTileSource(MapActivity activity) { private SQLiteTileSource createTileSource(MapActivity activity) {

View file

@ -149,7 +149,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
tileBox.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2); tileBox.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2);
AsyncTask<Object, Object, List<BinaryMapDataObject>> task = createNewTask(tileBox); AsyncTask<Object, Object, List<BinaryMapDataObject>> task = createNewTask(tileBox);
if (currentTask == null) { if (currentTask == null) {
task.execute(); executeTaskInBackground(task);
} else { } else {
pendingTask = task; pendingTask = task;
} }
@ -259,7 +259,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
} }
currentTask = null; currentTask = null;
if (pendingTask != null) { if (pendingTask != null) {
pendingTask.execute(); executeTaskInBackground(pendingTask);
pendingTask = null; pendingTask = null;
} }
} }

View file

@ -6,6 +6,7 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.PointF; import android.graphics.PointF;
import android.os.AsyncTask;
import android.view.MotionEvent; import android.view.MotionEvent;
public abstract class OsmandMapLayer { public abstract class OsmandMapLayer {
@ -34,6 +35,10 @@ public abstract class OsmandMapLayer {
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { return false;} public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { return false;}
public <Params> void executeTaskInBackground(AsyncTask<Params, ?, ?> task, Params... params){
task.execute(params);
}
/** /**
* This method returns whether canvas should be rotated as * 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)}. * map rotated before {@link #onDraw(android.graphics.Canvas, net.osmand.data.RotatedTileBox, net.osmand.plus.views.OsmandMapLayer.DrawSettings)}.