Remove thread, add sync

This commit is contained in:
Alexey Kulish 2016-03-30 18:03:26 +03:00
parent f51997540c
commit fef2d1c648

View file

@ -1,5 +1,7 @@
package net.osmand.plus; package net.osmand.plus;
import android.os.AsyncTask;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -59,16 +61,29 @@ public class CurrentPositionHelper {
defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, rs); defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, rs);
} }
private boolean scheduleRouteSegmentFind(final Location loc, final boolean storeFound, final ResultMatcher<GeocodingResult> geoCoding, final ResultMatcher<RouteDataObject> result) { private boolean scheduleRouteSegmentFind(final Location loc, final boolean storeFound, final ResultMatcher<GeocodingResult> geoCoding, final ResultMatcher<RouteDataObject> result) {
boolean res = false; boolean res = false;
if (loc != null) { if (loc != null) {
new Thread(new Runnable() { new AsyncTask<Void, Void, Void>() {
@Override @Override
public void run() { protected Void doInBackground(Void... params) {
try { try {
processGeocoding(loc, geoCoding, storeFound, result);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}.execute((Void) null);
res = true;
}
return res;
}
private synchronized void processGeocoding(Location loc, ResultMatcher<GeocodingResult> geoCoding, boolean storeFound, final ResultMatcher<RouteDataObject> result) throws IOException {
final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude(), final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude(),
geoCoding != null); geoCoding != null);
if (storeFound) { if (storeFound) {
@ -84,14 +99,6 @@ public class CurrentPositionHelper {
} }
}); });
} }
} catch (IOException e) {
e.printStackTrace();
}
}
}, "Geocoding...").start();
res = true;
}
return res;
} }
protected void justifyResult(List<GeocodingResult> res, final ResultMatcher<GeocodingResult> result) { protected void justifyResult(List<GeocodingResult> res, final ResultMatcher<GeocodingResult> result) {