Search in sources :

Example 6 with RouteDirectionInfo

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

the class ExternalApiHelper method updateTurnInfo.

private void updateTurnInfo(String prefix, Intent result, NextDirectionInfo ni) {
    result.putExtra(prefix + PARAM_NT_DISTANCE, ni.distanceTo);
    result.putExtra(prefix + PARAM_NT_IMMINENT, ni.imminent);
    if (ni.directionInfo != null && ni.directionInfo.getTurnType() != null) {
        TurnType tt = ni.directionInfo.getTurnType();
        RouteDirectionInfo a = ni.directionInfo;
        result.putExtra(prefix + PARAM_NT_DIRECTION_NAME, RoutingHelper.formatStreetName(a.getStreetName(), a.getRef(), a.getDestinationName(), ""));
        result.putExtra(prefix + PARAM_NT_DIRECTION_TURN, tt.toXmlString());
        if (tt.getLanes() != null) {
            result.putExtra(prefix + PARAM_NT_DIRECTION_LANES, Arrays.toString(tt.getLanes()));
        }
    }
}
Also used : RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) TurnType(net.osmand.router.TurnType)

Example 7 with RouteDirectionInfo

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

the class ShowRouteInfoDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    helper = app.getRoutingHelper();
    view = inflater.inflate(R.layout.route_info_layout, container, false);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationContentDescription(R.string.shared_string_close);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    ((ImageView) view.findViewById(R.id.distance_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_route_distance));
    ((ImageView) view.findViewById(R.id.time_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_time_span));
    buildMenuButtons();
    listView = (ListView) view.findViewById(android.R.id.list);
    listView.setBackgroundColor(getResources().getColor(app.getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark));
    View topShadowView = inflater.inflate(R.layout.list_shadow_header, listView, false);
    listView.addHeaderView(topShadowView, null, false);
    View bottomShadowView = inflater.inflate(R.layout.list_shadow_footer, listView, false);
    listView.addFooterView(bottomShadowView, null, false);
    adapter = new RouteInfoAdapter(helper.getRouteDirections());
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position < 2) {
                return;
            }
            RouteDirectionInfo item = adapter.getItem(position - 2);
            Location loc = helper.getLocationFromRouteDirection(item);
            if (loc != null) {
                MapRouteInfoMenu.directionInfo = position - 2;
                OsmandSettings settings = getMyApplication().getSettings();
                settings.setMapLocationToShow(loc.getLatitude(), loc.getLongitude(), Math.max(13, settings.getLastKnownMapZoom()), new PointDescription(PointDescription.POINT_TYPE_MARKER, item.getDescriptionRoutePart() + " " + getTimeDescription(item)), false, null);
                MapActivity.launchMapActivityMoveToTop(getActivity());
                dismiss();
            }
        }
    });
    int dist = helper.getLeftDistance();
    int time = helper.getLeftTime();
    int hours = time / (60 * 60);
    int minutes = (time / 60) % 60;
    ((TextView) view.findViewById(R.id.distance)).setText(OsmAndFormatter.getFormattedDistance(dist, app));
    StringBuilder timeStr = new StringBuilder();
    if (hours > 0) {
        timeStr.append(hours).append(" ").append(getString(R.string.osmand_parking_hour)).append(" ");
    }
    if (minutes > 0) {
        timeStr.append(minutes).append(" ").append(getString(R.string.osmand_parking_minute));
    }
    ((TextView) view.findViewById(R.id.time)).setText(timeStr);
    view.findViewById(R.id.go_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity activity = (MapActivity) getActivity();
            if (activity != null) {
                activity.getMapLayers().getMapControlsLayer().startNavigation();
                dismiss();
            }
        }
    });
    makeGpx();
    if (hasHeights) {
        View headerView = inflater.inflate(R.layout.route_info_header, null);
        buildHeader(headerView);
        listView.addHeaderView(headerView);
    }
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandSettings(net.osmand.plus.OsmandSettings) PointDescription(net.osmand.data.PointDescription) RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar) Location(net.osmand.Location)

Example 8 with RouteDirectionInfo

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

the class ShowRouteInfoDialogFragment method generateHtml.

private StringBuilder generateHtml(RouteInfoAdapter routeInfo, String title) {
    StringBuilder html = new StringBuilder();
    if (!TextUtils.isEmpty(title)) {
        html.append("<h1>");
        html.append(title);
        html.append("</h1>");
    }
    final String NBSP = "&nbsp;";
    final String BR = "<br>";
    for (int i = 0; i < routeInfo.getCount(); i++) {
        RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) routeInfo.getItem(i);
        StringBuilder sb = new StringBuilder();
        sb.append(OsmAndFormatter.getFormattedDistance(routeDirectionInfo.distance, getMyApplication()));
        sb.append(", ").append(NBSP);
        sb.append(getTimeDescription(routeDirectionInfo));
        String distance = sb.toString().replaceAll("\\s", NBSP);
        String description = routeDirectionInfo.getDescriptionRoutePart();
        html.append(BR);
        html.append("<p>" + String.valueOf(i + 1) + ". " + NBSP + description + NBSP + "(" + distance + ")</p>");
    }
    return html;
}
Also used : RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo)

Aggregations

RouteDirectionInfo (net.osmand.plus.routing.RouteDirectionInfo)8 Location (net.osmand.Location)4 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 TurnType (net.osmand.router.TurnType)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 BigTextStyle (android.support.v4.app.NotificationCompat.BigTextStyle)1 Builder (android.support.v4.app.NotificationCompat.Builder)1 Toolbar (android.support.v7.widget.Toolbar)1 ListView (android.widget.ListView)1 Date (java.util.Date)1 LatLon (net.osmand.data.LatLon)1 PointDescription (net.osmand.data.PointDescription)1 NavigationService (net.osmand.plus.NavigationService)1 OsmandSettings (net.osmand.plus.OsmandSettings)1