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) {
new AsyncTask<Void, Void, String>() {
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@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<Void, Void, String>() {
AsyncTask<Void,Void,String> task = new AsyncTask<Void, Void, String>() {
@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<Void, Void, String>() {
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@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

View file

@ -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<String> getTileSource(int x, int y, int zoom) {
ArrayList<String> ls = new ArrayList<String>();
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;
}

View file

@ -149,7 +149,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
tileBox.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2);
AsyncTask<Object, Object, List<BinaryMapDataObject>> 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;
}
}

View file

@ -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 <Params> void executeTaskInBackground(AsyncTask<Params, ?, ?> 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)}.