Search in sources :

Example 56 with Location

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

the class MapMarkersListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
    OsmandApplication app = mapActivity.getMyApplication();
    boolean night = app.getDaynightHelper().isNightModeForMapControls();
    IconsCache iconsCache = app.getIconsCache();
    boolean locationItem = showLocationItem && pos == 0;
    boolean firstMarkerItem = showLocationItem ? pos == 1 : pos == 0;
    boolean lastMarkerItem = pos == getItemCount() - 1;
    boolean start = pos == startPos;
    final boolean finish = pos == finishPos && startPos != finishPos;
    boolean firstSelectedMarker = pos == firstSelectedMarkerPos;
    boolean roundTripFinishItem = finish && showRoundTripItem;
    boolean useLocation = app.getMapMarkersHelper().isStartFromMyLocation() && showLocationItem;
    MapMarker marker = null;
    Location location = null;
    Object item = getItem(pos);
    if (item instanceof Location) {
        location = (Location) item;
    } else {
        marker = (MapMarker) item;
    }
    holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
    holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
    holder.title.setText(location != null ? mapActivity.getString(R.string.shared_string_my_location) : marker.getName(mapActivity));
    holder.iconDirection.setVisibility(View.GONE);
    holder.optionsBtn.setVisibility(roundTripFinishItem ? View.VISIBLE : View.GONE);
    if (roundTripFinishItem) {
        holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
        TypedValue outValue = new TypedValue();
        mapActivity.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        holder.optionsBtn.setBackgroundResource(outValue.resourceId);
        holder.optionsBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                listener.onDisableRoundTripClick();
            }
        });
    }
    holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
    holder.divider.setVisibility(lastMarkerItem ? View.GONE : View.VISIBLE);
    holder.checkBox.setVisibility(roundTripFinishItem ? View.GONE : View.VISIBLE);
    if (!roundTripFinishItem) {
        holder.checkBox.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                listener.onCheckBoxClick(holder.itemView);
            }
        });
        holder.checkBoxContainer.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                holder.checkBox.performClick();
            }
        });
    }
    holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE);
    holder.iconReorder.setVisibility(View.VISIBLE);
    holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder));
    holder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
    holder.firstDescription.setVisibility((start || finish) ? View.VISIBLE : View.GONE);
    if (start) {
        holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + " • ");
    } else if (finish) {
        holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + " • ");
    }
    if (location != null) {
        holder.icon.setImageDrawable(ContextCompat.getDrawable(mapActivity, R.drawable.map_pedestrian_location));
    } else {
        int res = start ? R.drawable.ic_action_point_start : (finish ? R.drawable.ic_action_point_destination : R.drawable.ic_action_flag_dark);
        holder.icon.setImageDrawable(iconsCache.getIcon(res, MapMarker.getColorId(marker.colorIndex)));
    }
    if (locationItem || roundTripFinishItem) {
        holder.iconReorder.setAlpha(.5f);
        holder.iconReorder.setOnTouchListener(null);
    }
    if (locationItem) {
        holder.topDivider.setVisibility(View.VISIBLE);
        holder.checkBox.setChecked(app.getMapMarkersHelper().isStartFromMyLocation());
        holder.distance.setVisibility(View.GONE);
        holder.description.setText(locDescription.getName());
    } else if (roundTripFinishItem) {
        holder.topDivider.setVisibility(View.GONE);
        holder.description.setText(mapActivity.getString(R.string.round_trip));
    } else {
        holder.topDivider.setVisibility((!showLocationItem && firstMarkerItem) ? View.VISIBLE : View.GONE);
        holder.checkBox.setChecked(marker.selected);
        holder.iconReorder.setAlpha(1f);
        holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent event) {
                if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                    inDragAndDrop = true;
                    if (showRoundTripItem) {
                        int roundTripItemPos = finishPos;
                        reloadData();
                        notifyItemRemoved(roundTripItemPos);
                    }
                    listener.onDragStarted(holder);
                }
                return false;
            }
        });
        String descr;
        if ((descr = marker.groupName) != null) {
            if (descr.equals("")) {
                descr = mapActivity.getString(R.string.shared_string_favorites);
            }
        } else {
            Date date = new Date(marker.creationDate);
            String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
            if (month.length() > 1) {
                month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
            }
            String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
            descr = month + " " + day;
        }
        holder.description.setText(descr);
    }
    boolean showDistance = !roundTripFinishItem && (locationItem ? useLocation : marker != null && marker.selected);
    int visibility = showDistance ? View.VISIBLE : View.GONE;
    holder.distance.setVisibility(visibility);
    holder.point.setVisibility(visibility);
    holder.leftPointSpace.setVisibility(visibility);
    holder.rightPointSpace.setVisibility(visibility);
    if (showDistance) {
        holder.distance.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_distance : R.color.color_myloc_distance));
        LatLon first = firstSelectedMarker && useLocation ? new LatLon(myLoc.getLatitude(), myLoc.getLongitude()) : getPreviousSelectedMarkerLatLon(pos);
        float dist = 0;
        if (first != null && marker != null) {
            WptPt pt1 = new WptPt();
            pt1.lat = first.getLatitude();
            pt1.lon = first.getLongitude();
            WptPt pt2 = new WptPt();
            pt2.lat = marker.getLatitude();
            pt2.lon = marker.getLongitude();
            List<WptPt> points = snappedToRoadPoints.get(new Pair<>(pt1, pt2));
            if (points != null) {
                for (int i = 0; i < points.size() - 1; i++) {
                    dist += (float) MapUtils.getDistance(points.get(i).lat, points.get(i).lon, points.get(i + 1).lat, points.get(i + 1).lon);
                }
            } else {
                dist = (float) MapUtils.getDistance(pt1.lat, pt1.lon, pt2.lat, pt2.lon);
            }
        }
        holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Date(java.util.Date) MotionEvent(android.view.MotionEvent) LatLon(net.osmand.data.LatLon) IconsCache(net.osmand.plus.IconsCache) SimpleDateFormat(java.text.SimpleDateFormat) Location(net.osmand.Location) TypedValue(android.util.TypedValue)

Example 57 with Location

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

the class MeasurementEditingContext method getParams.

private RouteCalculationParams getParams() {
    final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
    Location start = new Location("");
    start.setLatitude(currentPair.first.getLatitude());
    start.setLongitude(currentPair.first.getLongitude());
    LatLon end = new LatLon(currentPair.second.getLatitude(), currentPair.second.getLongitude());
    final RouteCalculationParams params = new RouteCalculationParams();
    params.inSnapToRoadMode = true;
    params.start = start;
    params.end = end;
    RoutingHelper.applyApplicationSettings(params, application.getSettings(), snapToRoadAppMode);
    params.mode = snapToRoadAppMode;
    params.ctx = application;
    params.calculationProgress = calculationProgress = new RouteCalculationProgress();
    params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {

        @Override
        public void updateProgress(int progress) {
            int pairs = calculatedPairs + snapToRoadPairsToCalculate.size();
            if (pairs != 0) {
                int pairProgress = 100 / pairs;
                progress = calculatedPairs * pairProgress + progress / pairs;
            }
            progressListener.updateProgress(progress);
        }

        @Override
        public void requestPrivateAccessRouting() {
        }

        @Override
        public void finish() {
            calculatedPairs = 0;
        }
    };
    params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {

        @Override
        public void onRouteCalculated(List<Location> locations) {
            ArrayList<WptPt> pts = new ArrayList<>(locations.size());
            for (Location loc : locations) {
                if (!loc.hasAltitude()) {
                    continue;
                }
                WptPt pt = new WptPt();
                pt.lat = loc.getLatitude();
                pt.lon = loc.getLongitude();
                pt.ele = loc.getAltitude();
                pts.add(pt);
            }
            calculatedPairs++;
            snappedToRoadPoints.put(currentPair, pts);
            updateCacheForSnapIfNeeded(true);
            application.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    progressListener.refresh();
                }
            });
            if (!snapToRoadPairsToCalculate.isEmpty()) {
                application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
            } else {
                application.runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        progressListener.hideProgressBar();
                    }
                });
            }
        }
    };
    return params;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) RouteCalculationParams(net.osmand.plus.routing.RouteCalculationParams) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location) RouteCalculationProgress(net.osmand.router.RouteCalculationProgress)

Example 58 with Location

use of net.osmand.Location 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 59 with Location

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

the class MapMarkerSelectionFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = null;
    if (getArguments() != null) {
        bundle = getArguments();
    } else if (savedInstanceState != null) {
        bundle = savedInstanceState;
    }
    if (bundle != null) {
        target = bundle.getBoolean(TARGET_KEY);
        intermediate = bundle.getBoolean(INTERMEDIATE_KEY);
    }
    MapActivity mapActivity = getMapActivity();
    OsmandApplication app = getMyApplication();
    if (mapActivity != null) {
        MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
        onClickListener = routeInfoMenu.getOnMarkerSelectListener();
        screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
        MapViewTrackingUtilities trackingUtils = mapActivity.getMapViewTrackingUtilities();
        if (trackingUtils != null) {
            Float head = trackingUtils.getHeading();
            float mapRotation = mapActivity.getMapRotate();
            LatLon mw = mapActivity.getMapLocation();
            Location l = trackingUtils.getMyLocation();
            boolean mapLinked = trackingUtils.isMapLinkedToLocation() && l != null;
            LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
            useCenter = !mapLinked;
            loc = (useCenter ? mw : myLoc);
            if (useCenter) {
                heading = -mapRotation;
            } else {
                heading = head;
            }
        }
    }
    nightMode = !app.getSettings().isLightContent();
    View view = inflater.inflate(R.layout.map_marker_selection_fragment, container, false);
    ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
    closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back));
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    ListView listView = (ListView) view.findViewById(android.R.id.list);
    final ArrayAdapter<MapMarker> adapter = new MapMarkersListAdapter();
    List<MapMarker> markers = getMyApplication().getMapMarkersHelper().getMapMarkers();
    if (markers.size() > 0) {
        for (MapMarker marker : markers) {
            adapter.add(marker);
        }
    }
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (onClickListener != null) {
                onClickListener.onSelect(position, target, intermediate);
            }
            dismiss();
        }
    });
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) Bundle(android.os.Bundle) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location) Nullable(android.support.annotation.Nullable)

Example 60 with Location

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

the class MarkersPlanRouteContext method getParams.

private RouteCalculationParams getParams() {
    final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
    Location start = new Location("");
    start.setLatitude(currentPair.first.getLatitude());
    start.setLongitude(currentPair.first.getLongitude());
    LatLon end = new LatLon(currentPair.second.getLatitude(), currentPair.second.getLongitude());
    final RouteCalculationParams params = new RouteCalculationParams();
    params.inSnapToRoadMode = true;
    params.start = start;
    params.end = end;
    RoutingHelper.applyApplicationSettings(params, app.getSettings(), snappedMode);
    params.mode = snappedMode;
    params.ctx = app;
    params.calculationProgress = calculationProgress = new RouteCalculationProgress();
    params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {

        @Override
        public void updateProgress(int progress) {
            int pairs = calculatedPairs + snapToRoadPairsToCalculate.size();
            if (pairs != 0) {
                int pairProgress = 100 / pairs;
                progress = calculatedPairs * pairProgress + progress / pairs;
            }
            listener.updateProgress(progress);
        }

        @Override
        public void requestPrivateAccessRouting() {
        }

        @Override
        public void finish() {
            calculatedPairs = 0;
        }
    };
    params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {

        @Override
        public void onRouteCalculated(List<Location> locations) {
            ArrayList<WptPt> pts = new ArrayList<>(locations.size());
            for (Location loc : locations) {
                WptPt pt = new WptPt();
                pt.lat = loc.getLatitude();
                pt.lon = loc.getLongitude();
                pts.add(pt);
            }
            calculatedPairs++;
            snappedToRoadPoints.put(currentPair, pts);
            recreateSnapTrkSegment(false);
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    listener.refresh();
                }
            });
            if (!snapToRoadPairsToCalculate.isEmpty()) {
                app.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
            } else {
                app.runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        listener.hideProgressBar(false);
                    }
                });
            }
        }
    };
    return params;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) RouteCalculationParams(net.osmand.plus.routing.RouteCalculationParams) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location) RouteCalculationProgress(net.osmand.router.RouteCalculationProgress)

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5