Search in sources :

Example 31 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class MapRouteInfoMenu method selectAddress.

public void selectAddress(String name, LatLon l, final boolean target, final boolean intermediate) {
    PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, name);
    if (intermediate) {
        getTargets().navigateToPoint(l, true, getTargets().getIntermediatePoints().size(), pd);
    } else if (target) {
        getTargets().navigateToPoint(l, true, -1, pd);
    } else {
        getTargets().setStartPoint(l, true, pd);
    }
    updateMenu();
}
Also used : PointDescription(net.osmand.data.PointDescription)

Example 32 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class PlanRouteFragment method createOptionsFragmentListener.

private PlanRouteOptionsFragmentListener createOptionsFragmentListener() {
    return new PlanRouteOptionsFragmentListener() {

        private MapActivity mapActivity = getMapActivity();

        @Override
        public void selectOnClick() {
            selectAllOnClick();
        }

        @Override
        public void navigateOnClick() {
            if (mapActivity != null) {
                boolean hasTargets = false;
                TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                List<MapMarker> markers = markersHelper.getSelectedMarkers();
                if (markers.size() > 0) {
                    int i = 0;
                    if (markersHelper.isStartFromMyLocation()) {
                        targetPointsHelper.clearStartPoint(false);
                    } else {
                        MapMarker m = markers.get(i++);
                        targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()), false, m.getPointDescription(mapActivity));
                    }
                    List<TargetPoint> targetPoints = new ArrayList<>();
                    for (int k = i; k < markers.size(); k++) {
                        MapMarker m = markers.get(k);
                        TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()), m.getPointDescription(mapActivity));
                        targetPoints.add(t);
                    }
                    if (mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()) {
                        TargetPoint end = targetPointsHelper.getPointToStart();
                        if (end == null) {
                            Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
                            if (loc != null) {
                                end = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, getString(R.string.shared_string_my_location)));
                            }
                        }
                        if (end != null) {
                            targetPoints.add(end);
                        }
                    }
                    RoutingHelper routingHelper = mapActivity.getRoutingHelper();
                    boolean updateRoute = routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode();
                    targetPointsHelper.reorderAllTargetPoints(targetPoints, updateRoute);
                    hasTargets = true;
                } else {
                    targetPointsHelper.clearStartPoint(false);
                    targetPointsHelper.clearPointToNavigate(false);
                }
                planRouteContext.setNavigationFromMarkers(true);
                dismiss();
                mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets);
            }
        }

        @Override
        public void makeRoundTripOnClick() {
            roundTripOnClick();
        }

        @Override
        public void doorToDoorOnClick() {
            if (mapActivity != null) {
                OsmandApplication app = mapActivity.getMyApplication();
                Location myLoc = app.getLocationProvider().getLastStaleKnownLocation();
                boolean startFromLocation = app.getMapMarkersHelper().isStartFromMyLocation() && myLoc != null;
                if (selectedCount > (startFromLocation ? 0 : 1)) {
                    sortSelectedMarkersDoorToDoor(mapActivity, startFromLocation, myLoc);
                }
            }
        }

        @Override
        public void reverseOrderOnClick() {
            if (mapActivity != null) {
                markersHelper.reverseActiveMarkersOrder();
                adapter.reloadData();
                adapter.notifyDataSetChanged();
                planRouteContext.recreateSnapTrkSegment(false);
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PlanRouteOptionsFragmentListener(net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener) PointDescription(net.osmand.data.PointDescription) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 33 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class OsmandAidlApi method registerNavigateReceiver.

private void registerNavigateReceiver(final MapActivity mapActivity) {
    navigateReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String profileStr = intent.getStringExtra(AIDL_PROFILE);
            final ApplicationMode profile = ApplicationMode.valueOfStringKey(profileStr, DEFAULT_PROFILE);
            boolean validProfile = false;
            for (ApplicationMode mode : VALID_PROFILES) {
                if (mode == profile) {
                    validProfile = true;
                    break;
                }
            }
            if (validProfile) {
                String startName = intent.getStringExtra(AIDL_START_NAME);
                if (Algorithms.isEmpty(startName)) {
                    startName = "";
                }
                String destName = intent.getStringExtra(AIDL_DEST_NAME);
                if (Algorithms.isEmpty(destName)) {
                    destName = "";
                }
                final LatLon start;
                final PointDescription startDesc;
                double startLat = intent.getDoubleExtra(AIDL_START_LAT, 0);
                double startLon = intent.getDoubleExtra(AIDL_START_LON, 0);
                if (startLat != 0 && startLon != 0) {
                    start = new LatLon(startLat, startLon);
                    startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
                } else {
                    start = null;
                    startDesc = null;
                }
                double destLat = intent.getDoubleExtra(AIDL_DEST_LAT, 0);
                double destLon = intent.getDoubleExtra(AIDL_DEST_LON, 0);
                final LatLon dest = new LatLon(destLat, destLon);
                final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName);
                final RoutingHelper routingHelper = app.getRoutingHelper();
                boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
                if (routingHelper.isFollowingMode() && !force) {
                    AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
                    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            if (!routingHelper.isFollowingMode()) {
                                startNavigation(mapActivity, null, start, startDesc, dest, destDesc, profile);
                            }
                        }
                    });
                } else {
                    startNavigation(mapActivity, null, start, startDesc, dest, destDesc, profile);
                }
            }
        }
    };
    mapActivity.registerReceiver(navigateReceiver, new IntentFilter(AIDL_NAVIGATE));
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) ApplicationMode(net.osmand.plus.ApplicationMode) RoutingHelper(net.osmand.plus.routing.RoutingHelper) BroadcastReceiver(android.content.BroadcastReceiver) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription)

Example 34 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class TrackSegmentFragment method updateHeader.

private void updateHeader() {
    imageView = (ImageView) headerView.findViewById(R.id.imageView);
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            GpxDataItem gpxDataItem = getGpxDataItem();
            GPXFile gpx = getGpx();
            WptPt pointToShow = gpx != null ? gpx.findPointToShow() : null;
            if (pointToShow != null) {
                LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
                final OsmandSettings settings = app.getSettings();
                String trackName = "";
                if (gpx.showCurrentTrack) {
                    trackName = getString(R.string.shared_string_currently_recording_track);
                } else if (gpxDataItem != null) {
                    trackName = gpxDataItem.getFile().getName();
                } else {
                    trackName = gpx.path;
                }
                settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, trackName), false, getRect());
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }
    });
    final View splitColorView = headerView.findViewById(R.id.split_color_view);
    final View divider = headerView.findViewById(R.id.divider);
    final View splitIntervalView = headerView.findViewById(R.id.split_interval_view);
    final View colorView = headerView.findViewById(R.id.color_view);
    vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle);
    final ProgressBar progressBar = (ProgressBar) headerView.findViewById(R.id.mapLoadProgress);
    final boolean selected = getGpx() != null && ((getGpx().showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || (getGpx().path != null && app.getSelectedGpxHelper().getSelectedFileByPath(getGpx().path) != null));
    vis.setChecked(selected);
    vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
                selectedSplitInterval = 0;
            }
            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
            final List<GpxDisplayGroup> groups = getDisplayGroups();
            if (groups.size() > 0) {
                updateSplit(groups, vis.isChecked() ? sf : null);
                if (getGpxDataItem() != null) {
                    updateSplitInDatabase();
                }
            }
            updateSplitIntervalView(splitIntervalView);
            updateColorView(colorView);
        }
    });
    updateColorView(colorView);
    colorView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            colorListPopupWindow = new ListPopupWindow(getActivity());
            colorListPopupWindow.setAnchorView(colorView);
            colorListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            colorListPopupWindow.setModal(true);
            colorListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
            colorListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            colorListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(getActivity(), getGpx().getColor(0), GpxAppearanceAdapterType.TRACK_COLOR);
            colorListPopupWindow.setAdapter(gpxApprAdapter);
            colorListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    AppearanceListItem item = gpxApprAdapter.getItem(position);
                    if (item != null) {
                        if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) {
                            int clr = item.getColor();
                            if (vis.isChecked()) {
                                SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                                if (clr != 0 && sf.getModifiableGpxFile() != null) {
                                    sf.getModifiableGpxFile().setColor(clr);
                                    if (getGpxDataItem() != null) {
                                        app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                                    }
                                }
                            } else if (getGpxDataItem() != null) {
                                app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                            }
                            if (getGpx().showCurrentTrack) {
                                app.getSettings().CURRENT_TRACK_COLOR.set(clr);
                            }
                            refreshTrackBitmap();
                        }
                    }
                    colorListPopupWindow.dismiss();
                    updateColorView(colorView);
                }
            });
            colorListPopupWindow.show();
        }
    });
    boolean hasPath = getGpx() != null && (getGpx().tracks.size() > 0 || getGpx().routes.size() > 0);
    if (rotatedTileBox == null || mapBitmap == null || mapTrackBitmap == null) {
        QuadRect rect = getRect();
        if (rect.left != 0 && rect.top != 0) {
            progressBar.setVisibility(View.VISIBLE);
            double clat = rect.bottom / 2 + rect.top / 2;
            double clon = rect.left / 2 + rect.right / 2;
            WindowManager mgr = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics dm = new DisplayMetrics();
            mgr.getDefaultDisplay().getMetrics(dm);
            RotatedTileBoxBuilder boxBuilder = new RotatedTileBoxBuilder().setLocation(clat, clon).setZoom(15).density(dm.density).setPixelDimensions(dm.widthPixels, AndroidUtils.dpToPx(app, 152f), 0.5f, 0.5f);
            rotatedTileBox = boxBuilder.build();
            while (rotatedTileBox.getZoom() < 17 && rotatedTileBox.containsLatLon(rect.top, rect.left) && rotatedTileBox.containsLatLon(rect.bottom, rect.right)) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() + 1);
            }
            while (rotatedTileBox.getZoom() >= 7 && (!rotatedTileBox.containsLatLon(rect.top, rect.left) || !rotatedTileBox.containsLatLon(rect.bottom, rect.right))) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() - 1);
            }
            final DrawSettings drawSettings = new DrawSettings(!app.getSettings().isLightContent(), true);
            final ResourceManager resourceManager = app.getResourceManager();
            final MapRenderRepositories renderer = resourceManager.getRenderer();
            if (resourceManager.updateRenderedMapNeeded(rotatedTileBox, drawSettings)) {
                resourceManager.updateRendererMap(rotatedTileBox, new AsyncLoadingThread.OnMapLoadedListener() {

                    @Override
                    public void onMapLoaded(boolean interrupted) {
                        app.runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                if (updateEnable) {
                                    mapBitmap = renderer.getBitmap();
                                    if (mapBitmap != null) {
                                        progressBar.setVisibility(View.GONE);
                                        refreshTrackBitmap();
                                    }
                                }
                            }
                        });
                    }
                });
            }
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }
    } else {
        refreshTrackBitmap();
    }
    if (hasPath) {
        if (getGpx() != null && !getGpx().showCurrentTrack && adapter.getCount() > 0) {
            prepareSplitIntervalAdapterData();
            setupSplitIntervalView(splitIntervalView);
            updateSplitIntervalView(splitIntervalView);
            splitIntervalView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    splitListPopupWindow = new ListPopupWindow(getActivity());
                    splitListPopupWindow.setAnchorView(splitIntervalView);
                    splitListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
                    splitListPopupWindow.setModal(true);
                    splitListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
                    splitListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
                    splitListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
                    splitListPopupWindow.setAdapter(new ArrayAdapter<>(getTrackActivity(), R.layout.popup_list_text_item, options));
                    splitListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            selectedSplitInterval = position;
                            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                            final List<GpxDisplayGroup> groups = getDisplayGroups();
                            if (groups.size() > 0) {
                                updateSplit(groups, vis.isChecked() ? sf : null);
                                if (getGpxDataItem() != null) {
                                    updateSplitInDatabase();
                                }
                            }
                            splitListPopupWindow.dismiss();
                            updateSplitIntervalView(splitIntervalView);
                        }
                    });
                    splitListPopupWindow.show();
                }
            });
            splitIntervalView.setVisibility(View.VISIBLE);
        } else {
            splitIntervalView.setVisibility(View.GONE);
        }
        splitColorView.setVisibility(View.VISIBLE);
        divider.setVisibility(View.VISIBLE);
    } else {
        splitColorView.setVisibility(View.GONE);
        divider.setVisibility(View.GONE);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDisplayGroup(net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup) QuadRect(net.osmand.data.QuadRect) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) AppearanceListItem(net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) GpxAppearanceAdapter(net.osmand.plus.dialogs.ConfigureMapMenu.GpxAppearanceAdapter) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ProgressBar(android.widget.ProgressBar) ResourceManager(net.osmand.plus.resources.ResourceManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) OsmandSettings(net.osmand.plus.OsmandSettings) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) RotatedTileBoxBuilder(net.osmand.data.RotatedTileBox.RotatedTileBoxBuilder) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) PointDescription(net.osmand.data.PointDescription) AdapterView(android.widget.AdapterView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) AsyncLoadingThread(net.osmand.plus.resources.AsyncLoadingThread) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter)

Example 35 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class DashParkingFragment method initView.

@Override
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = getActivity().getLayoutInflater().inflate(R.layout.dash_parking_fragment, container, false);
    Typeface typeface = FontCache.getRobotoMedium(getActivity());
    Button remove = (Button) view.findViewById(R.id.remove_tag);
    remove.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog dialog = plugin.showDeleteDialog(getActivity());
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    updateParkingPosition();
                }
            });
        }
    });
    remove.setTypeface(typeface);
    view.findViewById(R.id.parking_header).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LatLon point = plugin.getParkingPosition();
            getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, new PointDescription(PointDescription.POINT_TYPE_PARKING_MARKER, getString(R.string.osmand_parking_position_name)), false, // $NON-NLS-1$
            point);
            MapActivity.launchMapActivityMoveToTop(getActivity());
        }
    });
    return view;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LatLon(net.osmand.data.LatLon) Typeface(android.graphics.Typeface) Button(android.widget.Button) DialogInterface(android.content.DialogInterface) PointDescription(net.osmand.data.PointDescription) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

PointDescription (net.osmand.data.PointDescription)72 LatLon (net.osmand.data.LatLon)44 View (android.view.View)16 ImageView (android.widget.ImageView)13 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)13 FavouritePoint (net.osmand.data.FavouritePoint)12 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)11 OsmandApplication (net.osmand.plus.OsmandApplication)10 OsmandSettings (net.osmand.plus.OsmandSettings)10 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 Amenity (net.osmand.data.Amenity)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 RoutingHelper (net.osmand.plus.routing.RoutingHelper)7 Intent (android.content.Intent)6 Paint (android.graphics.Paint)6 LinearLayout (android.widget.LinearLayout)6 Location (net.osmand.Location)6 DialogInterface (android.content.DialogInterface)5