Add updating of progress bar
This commit is contained in:
parent
7de0483150
commit
07c75ddc97
1 changed files with 29 additions and 3 deletions
|
@ -73,6 +73,7 @@ import net.osmand.plus.routing.RouteProvider;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||||
|
import net.osmand.router.RouteCalculationProgress;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
@ -764,11 +765,10 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
|
|
||||||
ProgressBar snapToRoadProgressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar);
|
ProgressBar snapToRoadProgressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar);
|
||||||
snapToRoadProgressBar.setMinimumHeight(0);
|
snapToRoadProgressBar.setMinimumHeight(0);
|
||||||
snapToRoadProgressBar.setProgress(45);
|
|
||||||
snapToRoadProgressBar.setVisibility(View.VISIBLE);
|
snapToRoadProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (measurementPoints.size() > 1) {
|
if (measurementPoints.size() > 1) {
|
||||||
new SnapToRoadTask(mapActivity).execute();
|
new SnapToRoadTask(mapActivity, snapToRoadProgressBar).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
mapActivity.refreshMap();
|
mapActivity.refreshMap();
|
||||||
|
@ -1534,9 +1534,13 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
private class SnapToRoadTask extends AsyncTask<Void, Void, RouteCalculationResult> {
|
private class SnapToRoadTask extends AsyncTask<Void, Void, RouteCalculationResult> {
|
||||||
|
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
|
private ProgressBar progressBar;
|
||||||
|
private boolean calculated;
|
||||||
|
|
||||||
SnapToRoadTask(MapActivity mapActivity) {
|
SnapToRoadTask(MapActivity mapActivity, ProgressBar progressBar) {
|
||||||
this.mapActivity = mapActivity;
|
this.mapActivity = mapActivity;
|
||||||
|
this.progressBar = progressBar;
|
||||||
|
progressBar.setProgress(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1560,6 +1564,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
params.type = settings.ROUTER_SERVICE.getModeValue(snapToRoadAppMode);
|
params.type = settings.ROUTER_SERVICE.getModeValue(snapToRoadAppMode);
|
||||||
params.mode = snapToRoadAppMode;
|
params.mode = snapToRoadAppMode;
|
||||||
params.ctx = app;
|
params.ctx = app;
|
||||||
|
params.calculationProgress = new RouteCalculationProgress();
|
||||||
|
|
||||||
List<LatLon> intermediates = new ArrayList<>();
|
List<LatLon> intermediates = new ArrayList<>();
|
||||||
if (measurementPoints.size() > 2) {
|
if (measurementPoints.size() > 2) {
|
||||||
|
@ -1570,11 +1575,32 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
params.intermediates = intermediates;
|
params.intermediates = intermediates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateProgress(params.calculationProgress);
|
||||||
|
|
||||||
return new RouteProvider().calculateRouteImpl(params);
|
return new RouteProvider().calculateRouteImpl(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateProgress(final RouteCalculationProgress progress) {
|
||||||
|
mapActivity.getMyApplication().runInUIThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
float p = Math.max(progress.distanceFromBegin, progress.distanceFromEnd);
|
||||||
|
float all = progress.totalEstimatedDistance * 1.25f;
|
||||||
|
if (all > 0) {
|
||||||
|
int t = (int) Math.min(p * p / (all * all) * 100f, 99);
|
||||||
|
progressBar.setProgress(t);
|
||||||
|
}
|
||||||
|
if (!calculated) {
|
||||||
|
updateProgress(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(RouteCalculationResult result) {
|
protected void onPostExecute(RouteCalculationResult result) {
|
||||||
|
calculated = true;
|
||||||
measurementPoints.clear();
|
measurementPoints.clear();
|
||||||
for (Location loc : result.getRouteLocations()) {
|
for (Location loc : result.getRouteLocations()) {
|
||||||
WptPt pt = new WptPt();
|
WptPt pt = new WptPt();
|
||||||
|
|
Loading…
Reference in a new issue