Search in sources :

Example 16 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class MapRouteInfoMenu method choosePointTypeAction.

private void choosePointTypeAction(LatLon latLon, PointType pointType, PointDescription pd, String address) {
    OsmandApplication app = getApp();
    FavouritesHelper favorites = app.getFavoritesHelper();
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    switch(pointType) {
        case START:
            targetPointsHelper.setStartPoint(latLon, true, pd);
            break;
        case TARGET:
            targetPointsHelper.navigateToPoint(latLon, true, -1, pd);
            break;
        case INTERMEDIATE:
            targetPointsHelper.navigateToPoint(latLon, true, targetPointsHelper.getIntermediatePoints().size(), pd);
            break;
        case HOME:
            favorites.setSpecialPoint(latLon, FavouritePoint.SpecialPointType.HOME, address);
            break;
        case WORK:
            favorites.setSpecialPoint(latLon, FavouritePoint.SpecialPointType.WORK, address);
            break;
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 17 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class WaypointsFragment method updateWaypointItemView.

private View updateWaypointItemView(final boolean edit, final List<LocationPointWrapper> deletedPoints, final MapActivity mapActivity, View v, final LocationPointWrapper point, final ArrayAdapter adapter, final boolean nightMode, final boolean flat, final int position) {
    final OsmandApplication app = mapActivity.getMyApplication();
    final WaypointDialogHelper helper = mapActivity.getDashboard().getWaypointDialogHelper();
    if (v == null || v.findViewById(R.id.info_close) == null) {
        v = UiUtilities.getInflater(mapActivity, nightMode).inflate(R.layout.route_waypoint_item, null);
    }
    v.setBackgroundColor(ColorUtilities.getCardAndListBackgroundColor(mapActivity, nightMode));
    updatePointInfoView(mapActivity, v, point, true, nightMode, edit, false);
    final ImageView move = (ImageView) v.findViewById(R.id.info_move);
    final ImageButton remove = (ImageButton) v.findViewById(R.id.info_close);
    final View topDivider = (View) v.findViewById(R.id.top_divider);
    if (!edit) {
        remove.setVisibility(View.GONE);
        move.setVisibility(View.GONE);
    } else {
        boolean targets = point.type == WaypointHelper.TARGETS;
        boolean notFlatTargets = targets && !flat;
        boolean startPoint = notFlatTargets && ((TargetPoint) point.point).start;
        final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
        boolean canRemove = !targets || !targetPointsHelper.getIntermediatePoints().isEmpty();
        remove.setVisibility(View.VISIBLE);
        remove.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark));
        remove.setEnabled(canRemove);
        remove.setAlpha(canRemove ? 1 : .5f);
        if (canRemove) {
            if (notFlatTargets && startPoint) {
                remove.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (targetPointsHelper.getPointToStart() == null) {
                            if (!targetPointsHelper.getIntermediatePoints().isEmpty()) {
                                WaypointDialogHelper.replaceStartWithFirstIntermediate(targetPointsHelper, mapActivity, helper);
                            }
                        } else {
                            targetPointsHelper.setStartPoint(null, true, null);
                            WaypointDialogHelper.updateControls(mapActivity, helper);
                        }
                    }
                });
            } else {
                remove.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        WaypointDialogHelper.deletePoint(app, mapActivity, adapter, helper, point, deletedPoints, true);
                    }
                });
            }
        }
        AndroidUtils.setBackground(mapActivity, topDivider, ColorUtilities.getDividerColorId(nightMode));
        topDivider.setVisibility(position != 0 ? View.VISIBLE : View.GONE);
        move.setVisibility(notFlatTargets ? View.VISIBLE : View.GONE);
        if (notFlatTargets) {
            move.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_item_move, R.color.description_font_and_bottom_sheet_icons));
            move.setTag(new DynamicListView.DragIcon() {

                @Override
                public void onClick() {
                // do nothing
                }
            });
        }
    }
    return v;
}
Also used : ImageButton(android.widget.ImageButton) OsmandApplication(net.osmand.plus.OsmandApplication) WaypointDialogHelper(net.osmand.plus.helpers.WaypointDialogHelper) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) DynamicListView(net.osmand.plus.views.controls.DynamicListView) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) DynamicListView(net.osmand.plus.views.controls.DynamicListView)

Example 18 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class RouteDetailsFragment method buildTransportRouteRow.

private void buildTransportRouteRow(@NonNull ViewGroup parent, TransportRouteResult routeResult, boolean showDivider) {
    OsmandApplication app = requireMyApplication();
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    TargetPoint startPoint = targetPointsHelper.getPointToStart();
    TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
    int[] startTime = { 0 };
    List<TransportRouteResultSegment> segments = routeResult.getSegments();
    for (int i = 0; i < segments.size(); i++) {
        boolean first = i == 0;
        boolean last = i == segments.size() - 1;
        final TransportRouteResultSegment segment = segments.get(i);
        if (first) {
            buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed());
        }
        buildSegmentItem(parent, segment, !last ? segments.get(i + 1) : null, startTime, routeResult.getWalkSpeed(), routeResult.getBoardingTime());
        if (last) {
            buildDestinationItem(parent, endPoint, startTime, segment, routeResult.getWalkSpeed());
        }
        if (showDivider && !last) {
            buildRowDivider(parent, true);
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) TransportRouteResultSegment(net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) SuppressLint(android.annotation.SuppressLint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)

Example 19 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createIntermediateDistanceControl.

public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
    final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
    DistanceToPointWidget distanceControl = new DistanceToPointWidget(map, R.drawable.widget_intermediate_day, R.drawable.widget_intermediate_night) {

        @Override
        protected void click(OsmandMapTileView view) {
            if (targets.getIntermediatePoints().size() > 1) {
                map.getMapActions().openIntermediatePointsDialog();
            } else {
                super.click(view);
            }
        }

        @Override
        public LatLon getPointToNavigate() {
            TargetPoint p = targets.getFirstIntermediatePoint();
            return p == null ? null : p.point;
        }

        @Override
        public int getDistance() {
            if (getPointToNavigate() != null && map.getRoutingHelper().isRouteCalculated()) {
                return map.getRoutingHelper().getLeftDistanceNextIntermediate();
            }
            return super.getDistance();
        }
    };
    return distanceControl;
}
Also used : DistanceToPointWidget(net.osmand.plus.views.mapwidgets.widgets.DistanceToPointWidget) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 20 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class SearchScreen method reloadHistoryInternal.

private void reloadHistoryInternal() {
    if (!destroyed) {
        OsmandApplication app = getApp();
        try {
            List<SearchResult> recentResults = new ArrayList<>();
            // Home / work
            /* Disable since points exists at favorites screen
				FavouritesDbHelper favorites = app.getFavorites();
				FavouritePoint homePoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.HOME);
				FavouritePoint workPoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.WORK);
				if (homePoint != null) {
					SearchResult result = new SearchResult();
					result.location = new LatLon(homePoint.getLatitude(), homePoint.getLongitude());
					result.objectType = ObjectType.FAVORITE;
					result.object = homePoint;
					result.localeName = homePoint.getAddress();
					recentResults.add(result);
				}
				if (workPoint != null) {
					SearchResult result = new SearchResult();
					result.location = new LatLon(workPoint.getLatitude(), workPoint.getLongitude());
					result.objectType = ObjectType.FAVORITE;
					result.object = workPoint;
					result.localeName = workPoint.getAddress();
					recentResults.add(result);
				}
				*/
            // Previous route card
            TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
            TargetPoint startPoint = targetPointsHelper.getPointToStartBackup();
            boolean myLocation = false;
            if (startPoint == null) {
                myLocation = true;
                startPoint = targetPointsHelper.getMyLocationToStart();
            }
            TargetPoint destinationPoint = targetPointsHelper.getPointToNavigateBackup();
            if (startPoint != null && destinationPoint != null) {
                StringBuilder startText = new StringBuilder(myLocation ? app.getText(R.string.my_location) : "");
                String startDescr = getPointName(startPoint);
                if (!Algorithms.isEmpty(startDescr)) {
                    if (startText.length() > 0) {
                        startText.append(" — ");
                    }
                    startText.append(startDescr);
                }
                String destDescr = getPointName(destinationPoint);
                SearchResult result = new SearchResult();
                result.location = new LatLon(destinationPoint.getLatitude(), destinationPoint.getLongitude());
                result.objectType = ObjectType.ROUTE;
                result.object = destinationPoint;
                result.localeName = destDescr;
                result.relatedObject = startPoint;
                result.localeRelatedObjectName = startText.toString();
                recentResults.add(result);
            }
            // Map markers
            List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
            int mapMarkersCount = 0;
            for (MapMarker marker : mapMarkers) {
                SearchResult result = new SearchResult();
                result.location = new LatLon(marker.getLatitude(), marker.getLongitude());
                result.objectType = ObjectType.MAP_MARKER;
                result.object = marker;
                result.localeName = marker.getName(app);
                recentResults.add(result);
                mapMarkersCount++;
                if (mapMarkersCount >= MAP_MARKERS_LIMIT) {
                    break;
                }
            }
            // History
            SearchResultCollection res = getSearchUICore().shallowSearch(SearchHistoryAPI.class, "", null, false, false);
            if (res != null) {
                recentResults.addAll(res.getCurrentSearchResults());
            }
            this.recentResults = recentResults;
            if (!searchHelper.isSearching() && Algorithms.isEmpty(searchHelper.getSearchQuery())) {
                showRecents();
                invalidate();
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            app.showToastMessage(e.getMessage());
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ArrayList(java.util.ArrayList) SearchResult(net.osmand.search.core.SearchResult) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Aggregations

TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)42 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)24 LatLon (net.osmand.data.LatLon)22 OsmandApplication (net.osmand.plus.OsmandApplication)19 MapActivity (net.osmand.plus.activities.MapActivity)14 View (android.view.View)11 RoutingHelper (net.osmand.plus.routing.RoutingHelper)11 TextView (android.widget.TextView)10 PointDescription (net.osmand.data.PointDescription)9 ImageView (android.widget.ImageView)8 ArrayList (java.util.ArrayList)8 Location (net.osmand.Location)8 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)7 Bundle (android.os.Bundle)4 OnClickListener (android.view.View.OnClickListener)4 FavouritePoint (net.osmand.data.FavouritePoint)4 DialogInterface (android.content.DialogInterface)3 HorizontalScrollView (android.widget.HorizontalScrollView)3 ImageButton (android.widget.ImageButton)3 LinearLayout (android.widget.LinearLayout)3