Search in sources :

Example 21 with TargetPoint

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

the class NavigationNotification method buildNotification.

@Override
public Builder buildNotification(boolean wearable) {
    if (!isEnabled()) {
        return null;
    }
    NavigationService service = app.getNavigationService();
    String notificationTitle;
    StringBuilder notificationText = new StringBuilder();
    color = 0;
    icon = R.drawable.ic_action_start_navigation;
    turnBitmap = null;
    ongoing = true;
    RoutingHelper routingHelper = app.getRoutingHelper();
    boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
    if (service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0) {
        color = app.getResources().getColor(R.color.osmand_orange);
        String distanceStr = OsmAndFormatter.getFormattedDistance(app.getRoutingHelper().getLeftDistance(), app);
        String timeStr = OsmAndFormatter.getFormattedDuration(app.getRoutingHelper().getLeftTime(), app);
        String etaStr = SimpleDateFormat.getTimeInstance(DateFormat.SHORT).format(new Date(System.currentTimeMillis() + app.getRoutingHelper().getLeftTime() * 1000));
        TurnType turnType = null;
        boolean deviatedFromRoute;
        int turnImminent = 0;
        int nextTurnDistance = 0;
        int nextNextTurnDistance = 0;
        RouteDirectionInfo ri = null;
        if (routingHelper.isRouteCalculated() && followingMode) {
            deviatedFromRoute = routingHelper.isDeviatedFromRoute();
            if (deviatedFromRoute) {
                turnImminent = 0;
                turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
                nextTurnDistance = (int) routingHelper.getRouteDeviation();
            } else {
                NextDirectionInfo calc1 = new NextDirectionInfo();
                NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
                if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
                    ri = r.directionInfo;
                    turnType = r.directionInfo.getTurnType();
                    nextTurnDistance = r.distanceTo;
                    turnImminent = r.imminent;
                    NextDirectionInfo next = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true);
                    nextNextTurnDistance = next.distanceTo;
                }
            }
            if (turnType != null) {
                TurnDrawable drawable = new TurnDrawable(app, false);
                int height = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_height);
                int width = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_width);
                drawable.setBounds(0, 0, width, height);
                drawable.setTurnType(turnType);
                drawable.setTurnImminent(turnImminent, deviatedFromRoute);
                turnBitmap = drawableToBitmap(drawable);
            }
            notificationTitle = OsmAndFormatter.getFormattedDistance(nextTurnDistance, app) + (turnType != null ? " • " + RouteCalculationResult.toString(turnType, app, true) : "");
            if (ri != null && !Algorithms.isEmpty(ri.getDescriptionRoutePart())) {
                notificationText.append(ri.getDescriptionRoutePart());
                if (nextNextTurnDistance > 0) {
                    notificationText.append(" ").append(OsmAndFormatter.getFormattedDistance(nextNextTurnDistance, app));
                }
                notificationText.append("\n");
            }
            int distanceToNextIntermediate = routingHelper.getLeftDistanceNextIntermediate();
            if (distanceToNextIntermediate > 0) {
                int nextIntermediateIndex = routingHelper.getRoute().getNextIntermediate();
                List<TargetPoint> intermediatePoints = app.getTargetPointsHelper().getIntermediatePoints();
                if (nextIntermediateIndex < intermediatePoints.size()) {
                    TargetPoint nextIntermediate = intermediatePoints.get(nextIntermediateIndex);
                    notificationText.append(OsmAndFormatter.getFormattedDistance(distanceToNextIntermediate, app)).append(" • ").append(nextIntermediate.getOnlyName());
                    notificationText.append("\n");
                }
            }
            notificationText.append(distanceStr).append(" • ").append(timeStr).append(" • ").append(etaStr);
        } else {
            notificationTitle = app.getString(R.string.shared_string_navigation);
            String error = routingHelper.getLastRouteCalcErrorShort();
            if (Algorithms.isEmpty(error)) {
                notificationText.append(app.getString(R.string.route_calculation)).append("...");
            } else {
                notificationText.append(error);
            }
        }
    } else if (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation()) {
        ongoing = false;
        notificationTitle = app.getString(R.string.shared_string_navigation);
        notificationText.append(app.getString(R.string.shared_string_paused));
    } else {
        return null;
    }
    final Builder notificationBuilder = createBuilder(wearable).setContentTitle(notificationTitle).setStyle(new BigTextStyle().bigText(notificationText)).setLargeIcon(turnBitmap);
    Intent stopIntent = new Intent(OSMAND_STOP_NAVIGATION_SERVICE_ACTION);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(app, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.addAction(R.drawable.ic_action_remove_dark, app.getString(R.string.shared_string_control_stop), stopPendingIntent);
    if (routingHelper.isRouteCalculated() && followingMode) {
        Intent pauseIntent = new Intent(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION);
        PendingIntent pausePendingIntent = PendingIntent.getBroadcast(app, 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notificationBuilder.addAction(R.drawable.ic_pause, app.getString(R.string.shared_string_pause), pausePendingIntent);
    } else if (routingHelper.isRouteCalculated() && routingHelper.isPauseNavigation()) {
        Intent resumeIntent = new Intent(OSMAND_RESUME_NAVIGATION_SERVICE_ACTION);
        PendingIntent resumePendingIntent = PendingIntent.getBroadcast(app, 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notificationBuilder.addAction(R.drawable.ic_play_dark, app.getString(R.string.shared_string_continue), resumePendingIntent);
    }
    return notificationBuilder;
}
Also used : Builder(android.support.v4.app.NotificationCompat.Builder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TurnType(net.osmand.router.TurnType) Date(java.util.Date) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) NavigationService(net.osmand.plus.NavigationService) BigTextStyle(android.support.v4.app.NotificationCompat.BigTextStyle) RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) TurnDrawable(net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable) PendingIntent(android.app.PendingIntent)

Example 22 with TargetPoint

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

the class MapRouteInfoMenu method generateViaDescription.

public String generateViaDescription() {
    TargetPointsHelper targets = getTargets();
    List<TargetPoint> points = targets.getIntermediatePointsNavigation();
    if (points.size() == 0) {
        return "";
    }
    StringBuilder via = new StringBuilder();
    for (int i = 0; i < points.size(); i++) {
        if (i > 0) {
            via.append(" ");
        }
        TargetPoint p = points.get(i);
        String description = p.getOnlyName();
        via.append(getRoutePointDescription(p.point, description));
        boolean needAddress = new PointDescription(PointDescription.POINT_TYPE_LOCATION, description).isSearchingAddress(mapActivity) && !intermediateRequestsLatLon.contains(p.point);
        if (needAddress) {
            AddressLookupRequest lookupRequest = new AddressLookupRequest(p.point, new GeocodingLookupService.OnAddressLookupResult() {

                @Override
                public void geocodingDone(String address) {
                    updateMenu();
                }
            }, null);
            intermediateRequestsLatLon.add(p.point);
            geocodingLookupService.lookupAddress(lookupRequest);
        }
    }
    return via.toString();
}
Also used : GeocodingLookupService(net.osmand.plus.GeocodingLookupService) PointDescription(net.osmand.data.PointDescription) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) AddressLookupRequest(net.osmand.plus.GeocodingLookupService.AddressLookupRequest)

Example 23 with TargetPoint

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

the class MapRouteInfoMenu method updateViaView.

private void updateViaView(final View parentView) {
    String via = generateViaDescription();
    View viaLayout = parentView.findViewById(R.id.ViaLayout);
    View viaLayoutDivider = parentView.findViewById(R.id.viaLayoutDivider);
    ImageView swapDirectionView = (ImageView) parentView.findViewById(R.id.swap_direction_image_view);
    if (via.length() == 0) {
        viaLayout.setVisibility(View.GONE);
        viaLayoutDivider.setVisibility(View.GONE);
        swapDirectionView.setVisibility(View.VISIBLE);
    } else {
        swapDirectionView.setVisibility(View.GONE);
        viaLayout.setVisibility(View.VISIBLE);
        viaLayoutDivider.setVisibility(View.VISIBLE);
        ((TextView) parentView.findViewById(R.id.ViaView)).setText(via);
    }
    viaLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getTargets().checkPointToNavigateShort()) {
                mapActivity.getMapActions().openIntermediatePointsDialog();
            }
        }
    });
    ImageView viaIcon = (ImageView) parentView.findViewById(R.id.viaIcon);
    viaIcon.setImageDrawable(getIconOrig(R.drawable.list_intermediate));
    swapDirectionView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_change_navigation_points, isLight() ? R.color.route_info_control_icon_color_light : R.color.route_info_control_icon_color_dark));
    swapDirectionView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            TargetPointsHelper targetPointsHelper = getTargets();
            TargetPoint startPoint = targetPointsHelper.getPointToStart();
            TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
            if (startPoint == null) {
                Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
                if (loc != null) {
                    startPoint = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location)));
                }
            }
            if (startPoint != null && endPoint != null) {
                targetPointsHelper.navigateToPoint(startPoint.point, false, -1, startPoint.getPointDescription(mapActivity));
                targetPointsHelper.setStartPoint(endPoint.point, false, endPoint.getPointDescription(mapActivity));
                targetPointsHelper.updateRouteAndRefresh(true);
                updateFromIcon();
                updateToIcon(parentView);
            }
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Location(net.osmand.Location)

Example 24 with TargetPoint

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

the class DestinationReachedMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.dest_reached_menu_fragment, container, false);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismissMenu();
        }
    });
    IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache();
    ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
    closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
    closeImageButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismissMenu();
        }
    });
    Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
    removeDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
    AndroidUtils.setTextPrimaryColor(view.getContext(), removeDestButton, !menu.isLight());
    removeDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getMapActivity().getMyApplication().getTargetPointsHelper().removeWayPoint(true, -1);
            Object contextMenuObj = getMapActivity().getContextMenu().getObject();
            if (getMapActivity().getContextMenu().isActive() && contextMenuObj != null && contextMenuObj instanceof TargetPoint) {
                TargetPoint targetPoint = (TargetPoint) contextMenuObj;
                if (!targetPoint.start && !targetPoint.intermediate) {
                    getMapActivity().getContextMenu().close();
                }
            }
            OsmandSettings settings = getMapActivity().getMyApplication().getSettings();
            settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
            getMapActivity().getMapActions().stopNavigationWithoutConfirm();
            dismissMenu();
        }
    });
    Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
    recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
    AndroidUtils.setTextPrimaryColor(view.getContext(), recalcDestButton, !menu.isLight());
    recalcDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TargetPointsHelper helper = getMapActivity().getMyApplication().getTargetPointsHelper();
            TargetPoint target = helper.getPointToNavigate();
            dismissMenu();
            if (target != null) {
                helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), true, -1, target.getOriginalPointDescription());
                getMapActivity().getMapActions().recalculateRoute(false);
                getMapActivity().getMapLayers().getMapControlsLayer().startNavigation();
            }
        }
    });
    Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
    ApplicationMode appMode = getMapActivity().getMyApplication().getRoutingHelper().getAppMode();
    if (!appMode.isDerivedRoutingFrom(appMode.CAR)) {
        findParkingButton.setVisibility(View.GONE);
    }
    findParkingButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
    AndroidUtils.setTextPrimaryColor(view.getContext(), findParkingButton, !menu.isLight());
    findParkingButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PoiFiltersHelper helper = getMapActivity().getMyApplication().getPoiFilters();
            // PoiType place = getMapActivity().getMyApplication().getPoiTypes().getPoiTypeByKey("parking");
            PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking");
            if (parkingFilter != null) {
                final Intent newIntent = new Intent(getActivity(), SearchPOIActivity.class);
                newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, parkingFilter.getFilterId());
                newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true);
                startActivityForResult(newIntent, 0);
            }
            dismissMenu();
        }
    });
    View mainView = view.findViewById(R.id.main_view);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_left_menu_light, R.drawable.bg_left_menu_dark);
    } else {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    }
    TextView title = (TextView) view.findViewById(R.id.titleTextView);
    AndroidUtils.setTextPrimaryColor(view.getContext(), title, !menu.isLight());
    return view;
}
Also used : Intent(android.content.Intent) ApplicationMode(net.osmand.plus.ApplicationMode) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) SearchPOIActivity(net.osmand.plus.activities.search.SearchPOIActivity) TextView(android.widget.TextView) IconsCache(net.osmand.plus.IconsCache) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Nullable(android.support.annotation.Nullable)

Example 25 with TargetPoint

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

the class DashWaypointsFragment method setupTargets.

public void setupTargets() {
    View mainView = getView();
    final TargetPointsHelper helper = getMyApplication().getTargetPointsHelper();
    if (helper.getPointToNavigate() == null) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
    }
    points = SHOW_ALL ? helper.getIntermediatePointsWithTarget() : Collections.singletonList(helper.getPointToNavigate());
    ((Button) mainView.findViewById(R.id.show_all)).setText(SHOW_ALL ? getString(R.string.shared_string_collapse) : getString(R.string.shared_string_show_all));
    ((Button) mainView.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SHOW_ALL = !SHOW_ALL;
            setupView();
        }
    });
    ((Button) mainView.findViewById(R.id.show_all)).setVisibility(helper.getIntermediatePoints().size() == 0 ? View.INVISIBLE : View.VISIBLE);
    ((TextView) mainView.findViewById(R.id.fav_text)).setText(getString(R.string.waypoints) + " (" + helper.getIntermediatePointsWithTarget().size() + ")");
    LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items);
    favorites.removeAllViews();
    List<DashLocationView> distances = new ArrayList<DashLocationFragment.DashLocationView>();
    for (final TargetPoint point : points) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.favorites_list_item, null, false);
        TextView name = (TextView) view.findViewById(R.id.favourite_label);
        TextView label = (TextView) view.findViewById(R.id.distance);
        ImageView direction = (ImageView) view.findViewById(R.id.direction);
        direction.setVisibility(View.VISIBLE);
        label.setVisibility(View.VISIBLE);
        view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
        view.findViewById(R.id.group_image).setVisibility(View.GONE);
        boolean target = helper.getPointToNavigate() == point;
        int id;
        if (!target) {
            id = R.drawable.list_intermediate;
        } else {
            id = R.drawable.list_destination;
        }
        ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(getMyApplication().getIconsCache().getIcon(id, 0));
        DashLocationView dv = new DashLocationView(direction, label, new LatLon(point.getLatitude(), point.getLongitude()));
        distances.add(dv);
        name.setText(PointDescription.getSimpleName(point, getActivity()));
        ImageButton options = ((ImageButton) view.findViewById(R.id.options));
        options.setVisibility(View.VISIBLE);
        final boolean optionsVisible = (SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0);
        options.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(optionsVisible ? R.drawable.ic_overflow_menu_white : R.drawable.ic_action_remove_dark));
        options.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (optionsVisible) {
                    selectTargetModel(point, view);
                } else {
                    deletePointConfirm(point, view);
                }
            }
        });
        ImageButton navigate = ((ImageButton) view.findViewById(R.id.navigate_to));
        navigate.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_gdirections_dark));
        navigate.setVisibility(target ? View.VISIBLE : View.GONE);
        navigate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                dashboard.navigationAction();
            }
        });
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, point.getPointDescription(getActivity()), false, // $NON-NLS-1$
                point);
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        });
        favorites.addView(view);
    }
    this.distances = distances;
}
Also used : ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) LinearLayout(android.widget.LinearLayout)

Aggregations

TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)39 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)18 LatLon (net.osmand.data.LatLon)17 View (android.view.View)13 TextView (android.widget.TextView)13 Location (net.osmand.Location)10 PointDescription (net.osmand.data.PointDescription)10 AdapterView (android.widget.AdapterView)9 ArrayList (java.util.ArrayList)9 ImageView (android.widget.ImageView)8 SuppressLint (android.annotation.SuppressLint)6 LocationPoint (net.osmand.data.LocationPoint)6 FavouritePoint (net.osmand.data.FavouritePoint)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 Paint (android.graphics.Paint)4 ImageButton (android.widget.ImageButton)4 ListView (android.widget.ListView)4 List (java.util.List)4 RoutingHelper (net.osmand.plus.routing.RoutingHelper)4 DialogInterface (android.content.DialogInterface)3