Search in sources :

Example 1 with CallbackWithObject

use of net.osmand.CallbackWithObject in project Osmand by osmandapp.

the class MeasurementToolFragment method showAddToTrackDialog.

private AlertDialog showAddToTrackDialog(final MapActivity mapActivity) {
    CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {

        @Override
        public boolean processResult(GPXFile[] result) {
            GPXFile gpxFile;
            if (result != null && result.length > 0) {
                gpxFile = result[0];
                SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
                boolean showOnMap = selectedGpxFile != null;
                saveExistingGpx(gpxFile, showOnMap, ActionType.ADD_SEGMENT, false);
            }
            return true;
        }
    };
    return GpxUiHelper.selectGPXFile(mapActivity, false, false, callbackWithObject);
}
Also used : CallbackWithObject(net.osmand.CallbackWithObject) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 2 with CallbackWithObject

use of net.osmand.CallbackWithObject in project Osmand by osmandapp.

the class MapContextMenu method addNewWptToGPXFile.

public AlertDialog addNewWptToGPXFile(final String title) {
    CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {

        @Override
        public boolean processResult(GPXFile[] result) {
            GPXFile gpxFile;
            if (result != null && result.length > 0) {
                gpxFile = result[0];
            } else {
                gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
            }
            getWptPtPointEditor().add(gpxFile, latLon, title);
            return true;
        }
    };
    return GpxUiHelper.selectSingleGPXFile(mapActivity, true, callbackWithObject);
}
Also used : CallbackWithObject(net.osmand.CallbackWithObject) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 3 with CallbackWithObject

use of net.osmand.CallbackWithObject in project Osmand by osmandapp.

the class MapContextMenu method addNewWptToGPXFile.

public AlertDialog addNewWptToGPXFile(final LatLon latLon, final String title, final String categoryName, final int categoryColor, final boolean skipDialog) {
    CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {

        @Override
        public boolean processResult(GPXFile[] result) {
            GPXFile gpxFile;
            if (result != null && result.length > 0) {
                gpxFile = result[0];
            } else {
                gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
            }
            getWptPtPointEditor().add(gpxFile, latLon, title, categoryName, categoryColor, skipDialog);
            return true;
        }
    };
    return GpxUiHelper.selectSingleGPXFile(mapActivity, true, callbackWithObject);
}
Also used : CallbackWithObject(net.osmand.CallbackWithObject) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 4 with CallbackWithObject

use of net.osmand.CallbackWithObject in project Osmand by osmandapp.

the class MapActivityLayers method showGPXFileLayer.

public AlertDialog showGPXFileLayer(List<String> files, final OsmandMapTileView mapView) {
    final OsmandSettings settings = getApplication().getSettings();
    CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {

        @Override
        public boolean processResult(GPXFile[] result) {
            WptPt locToShow = null;
            for (GPXFile g : result) {
                if (g.showCurrentTrack) {
                    if (!settings.SAVE_TRACK_TO_GPX.get() && !settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
                        Toast.makeText(activity, R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_LONG).show();
                    }
                    break;
                } else {
                    locToShow = g.findPointToShow();
                }
            }
            getApplication().getSelectedGpxHelper().setGpxFileToDisplay(result);
            if (locToShow != null) {
                mapView.getAnimatedDraggingThread().startMoving(locToShow.lat, locToShow.lon, mapView.getZoom(), true);
            }
            mapView.refreshMap();
            activity.getDashboard().refreshContent(true);
            return true;
        }
    };
    return GpxUiHelper.selectGPXFiles(files, activity, callbackWithObject);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) CallbackWithObject(net.osmand.CallbackWithObject) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 5 with CallbackWithObject

use of net.osmand.CallbackWithObject in project Osmand by osmandapp.

the class OsmAndLocationSimulation method startStopRouteAnimation.

// public void startStopRouteAnimationRoute(final MapActivity ma) {
// if (!isRouteAnimating()) {
// List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
// if (currentRoute.isEmpty()) {
// Toast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
// } else {
// startAnimationThread(app.getRoutingHelper(), ma, new ArrayList<Location>(currentRoute), false, 1);
// }
// } else {
// stop();
// }
// }
public void startStopRouteAnimation(final Activity ma, final Runnable runnable) {
    if (!isRouteAnimating()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ma);
        builder.setTitle(R.string.animate_route);
        final View view = ma.getLayoutInflater().inflate(R.layout.animate_route, null);
        final View gpxView = ((LinearLayout) view.findViewById(R.id.layout_animate_gpx));
        final RadioButton radioGPX = (RadioButton) view.findViewById(R.id.radio_gpx);
        radioGPX.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                gpxView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        // $NON-NLS-1$
        ((TextView) view.findViewById(R.id.MinSpeedup)).setText("1");
        // $NON-NLS-1$
        ((TextView) view.findViewById(R.id.MaxSpeedup)).setText("4");
        final SeekBar speedup = (SeekBar) view.findViewById(R.id.Speedup);
        speedup.setMax(3);
        builder.setView(view);
        builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean gpxNavigation = radioGPX.isChecked();
                if (gpxNavigation) {
                    GpxUiHelper.selectGPXFile(ma, false, false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {

                        @Override
                        public boolean processResult(GPXUtilities.GPXFile[] result) {
                            GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result[0], app.getSettings());
                            startAnimationThread(app, builder.getPoints(), true, speedup.getProgress() + 1);
                            if (runnable != null) {
                                runnable.run();
                            }
                            return true;
                        }
                    });
                } else {
                    List<Location> currentRoute = app.getRoutingHelper().getCurrentCalculatedRoute();
                    if (currentRoute.isEmpty()) {
                        Toast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
                    } else {
                        startAnimationThread(app, new ArrayList<Location>(currentRoute), false, 1);
                        if (runnable != null) {
                            runnable.run();
                        }
                    }
                }
            }
        });
        builder.setNegativeButton(R.string.shared_string_cancel, null);
        builder.show();
    } else {
        stop();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ArrayList(java.util.ArrayList) RadioButton(android.widget.RadioButton) TextView(android.widget.TextView) View(android.view.View) CallbackWithObject(net.osmand.CallbackWithObject) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) CompoundButton(android.widget.CompoundButton)

Aggregations

CallbackWithObject (net.osmand.CallbackWithObject)6 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)4 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 View (android.view.View)2 TextView (android.widget.TextView)2 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 ImageView (android.widget.ImageView)1 RadioButton (android.widget.RadioButton)1 SeekBar (android.widget.SeekBar)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WptPt (net.osmand.plus.GPXUtilities.WptPt)1 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 MapActivity (net.osmand.plus.activities.MapActivity)1 GPXRouteParamsBuilder (net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder)1