Search in sources :

Example 1 with RouteCalculationProgressCallback

use of net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback in project Osmand by osmandapp.

the class MapActivity method createProgressBarForRouting.

private void createProgressBarForRouting() {
    final ProgressBar pb = (ProgressBar) findViewById(R.id.map_horizontal_progress);
    final View pbExtView = findViewById(R.id.progress_layout_external);
    final ProgressBar pbExt = (ProgressBar) findViewById(R.id.map_horizontal_progress_external);
    app.getRoutingHelper().setProgressBar(new RouteCalculationProgressCallback() {

        @Override
        public void updateProgress(int progress) {
            if (findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE) {
                if (pbExtView.getVisibility() == View.VISIBLE) {
                    pbExtView.setVisibility(View.GONE);
                }
                if (pb.getVisibility() == View.GONE) {
                    pb.setVisibility(View.VISIBLE);
                }
                pb.setProgress(progress);
                pb.invalidate();
                pb.requestLayout();
            } else {
                if (pb.getVisibility() == View.VISIBLE) {
                    pb.setVisibility(View.GONE);
                }
                if (pbExtView.getVisibility() == View.GONE) {
                    pbExtView.setVisibility(View.VISIBLE);
                }
                pbExt.setProgress(progress);
                pbExt.invalidate();
                pbExt.requestLayout();
            }
        }

        @Override
        public void requestPrivateAccessRouting() {
            if (!settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(getRoutingHelper().getAppMode())) {
                final OsmandSettings.CommonPreference<Boolean> allowPrivate = settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false);
                final List<ApplicationMode> modes = ApplicationMode.values(settings);
                for (ApplicationMode mode : modes) {
                    if (!allowPrivate.getModeValue(mode)) {
                        settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, true);
                    }
                }
                if (!allowPrivate.getModeValue(getRoutingHelper().getAppMode())) {
                    AlertDialog.Builder dlg = new AlertDialog.Builder(MapActivity.this);
                    dlg.setMessage(R.string.private_access_routing_req);
                    dlg.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            for (ApplicationMode mode : modes) {
                                if (!allowPrivate.getModeValue(mode)) {
                                    allowPrivate.setModeValue(mode, true);
                                }
                            }
                            getRoutingHelper().recalculateRouteDueToSettingsChange();
                        }
                    });
                    dlg.setNegativeButton(R.string.shared_string_no, null);
                    dlg.show();
                }
            }
        }

        @Override
        public void finish() {
            pbExtView.setVisibility(View.GONE);
            pb.setVisibility(View.GONE);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) RouteCalculationProgressCallback(net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback) ApplicationMode(net.osmand.plus.ApplicationMode) AtlasMapRendererView(net.osmand.core.android.AtlasMapRendererView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) OsmAndMapSurfaceView(net.osmand.plus.views.OsmAndMapSurfaceView) OsmAndMapLayersView(net.osmand.plus.views.OsmAndMapLayersView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) ArrayList(java.util.ArrayList) List(java.util.List) ProgressBar(android.widget.ProgressBar)

Aggregations

DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtlasMapRendererView (net.osmand.core.android.AtlasMapRendererView)1 QuadPoint (net.osmand.data.QuadPoint)1 ApplicationMode (net.osmand.plus.ApplicationMode)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1 RouteCalculationProgressCallback (net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback)1 NewGpxPoint (net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint)1 OsmAndMapLayersView (net.osmand.plus.views.OsmAndMapLayersView)1 OsmAndMapSurfaceView (net.osmand.plus.views.OsmAndMapSurfaceView)1 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)1