Search in sources :

Example 51 with PointDescription

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

the class DashFavoritesFragment method setupFavorites.

public void setupFavorites() {
    View mainView = getView();
    final FavouritesDbHelper helper = getMyApplication().getFavorites();
    points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
    if (points.size() == 0) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
    }
    final LatLon loc = getDefaultLocation();
    if (loc != null) {
        Collections.sort(points, new Comparator<FavouritePoint>() {

            @Override
            public int compare(FavouritePoint point, FavouritePoint point2) {
                // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
                int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(), loc.getLongitude()));
                int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), loc.getLatitude(), loc.getLongitude()));
                return (dist - dist2);
            }
        });
    }
    LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items);
    favorites.removeAllViews();
    DashboardOnMap.handleNumberOfRows(points, getMyApplication().getSettings(), ROW_NUMBER_TAG);
    List<DashLocationView> distances = new ArrayList<DashLocationFragment.DashLocationView>();
    for (final FavouritePoint 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);
        ImageView groupImage = (ImageView) view.findViewById(R.id.group_image);
        if (point.getCategory().length() > 0) {
            ((TextView) view.findViewById(R.id.group_name)).setText(point.getCategory());
            groupImage.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_small_group));
        } else {
            groupImage.setVisibility(View.GONE);
        }
        ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), point.getColor(), false));
        DashLocationView dv = new DashLocationView(direction, label, new LatLon(point.getLatitude(), point.getLongitude()));
        distances.add(dv);
        name.setText(point.getName());
        name.setTypeface(Typeface.DEFAULT, point.isVisible() ? Typeface.NORMAL : Typeface.ITALIC);
        view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE);
        ((ImageView) view.findViewById(R.id.navigate_to)).setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_gdirections_dark));
        view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), point.getLatitude(), point.getLongitude(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()));
            }
        });
        view.setOnClickListener(new View.OnClickListener() {

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

Example 52 with PointDescription

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

the class SearchPOIActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
    final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
    final OsmandSettings settings = app.getSettings();
    String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
    PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
    int z = Math.max(16, settings.getLastKnownMapZoom());
    LatLon location = amenity.getLocation();
    settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, name, true, // $NON-NLS-1$
    amenity);
    MapActivity.launchMapActivityMoveToTop(this);
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 53 with PointDescription

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

the class TrackActivity method addNewGpxData.

public void addNewGpxData(NewGpxData.ActionType actionType, TrkSegment segment) {
    GPXFile gpxFile = getGpx();
    QuadRect rect = getRect();
    NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment);
    WptPt pointToShow = gpxFile != null ? gpxFile.findPointToShow() : null;
    if (pointToShow != null) {
        LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
        final OsmandSettings settings = app.getSettings();
        settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.add_line)), false, newGpxData);
        MapActivity.launchMapActivityMoveToTop(this);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) NewGpxData(net.osmand.plus.measurementtool.NewGpxData) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) QuadRect(net.osmand.data.QuadRect) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 54 with PointDescription

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

the class SearchHistoryFragment method selectModel.

private void selectModel(final HistoryEntry model) {
    PointDescription name = model.getName();
    OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings();
    LatLon location = new LatLon(model.getLat(), model.getLon());
    settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), name, true, // $NON-NLS-1$
    model);
    MapActivity.launchMapActivityMoveToTop(getActivity());
}
Also used : LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) PointDescription(net.osmand.data.PointDescription) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 55 with PointDescription

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

the class MapActivity method readLocationToShow.

public void readLocationToShow() {
    if (!getDashboard().isVisible()) {
        mapLayers.getMapControlsLayer().showMapControlsIfHidden();
    }
    LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
    LatLon latLonToShow = settings.getAndClearMapLocationToShow();
    PointDescription mapLabelToShow = settings.getAndClearMapLabelToShow(latLonToShow);
    Object toShow = settings.getAndClearObjectToShow();
    boolean editToShow = settings.getAndClearEditObjectToShow();
    int status = settings.isRouteToPointNavigateAndClear();
    String searchRequestToShow = settings.getAndClearSearchRequestToShow();
    if (status != 0) {
        // always enable and follow and let calculate it (i.e.GPS is not accessible in a garage)
        Location loc = new Location("map");
        loc.setLatitude(mapView.getLatitude());
        loc.setLongitude(mapView.getLongitude());
        getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
        if (dashboardOnMap.isVisible()) {
            dashboardOnMap.hideDashboard();
        }
    }
    if (searchRequestToShow != null) {
        showQuickSearch(searchRequestToShow);
    }
    if (latLonToShow != null) {
        if (dashboardOnMap.isVisible()) {
            dashboardOnMap.hideDashboard();
        }
        // remember if map should come back to isMapLinkedToLocation=true
        mapViewTrackingUtilities.setMapLinkedToLocation(false);
        if (mapLabelToShow != null && !mapLabelToShow.contextMenuDisabled()) {
            mapContextMenu.setMapCenter(latLonToShow);
            mapContextMenu.setMapPosition(mapView.getMapPosition());
            mapContextMenu.setCenterMarker(true);
            RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
            LatLon prevCenter = tb.getCenterLatLon();
            double border = 0.8;
            int tbw = (int) (tb.getPixWidth() * border);
            int tbh = (int) (tb.getPixHeight() * border);
            tb.setPixelDimensions(tbw, tbh);
            tb.setLatLonCenter(latLonToShow.getLatitude(), latLonToShow.getLongitude());
            tb.setZoom(ZOOM_LABEL_DISPLAY);
            while (!tb.containsLatLon(prevCenter.getLatitude(), prevCenter.getLongitude()) && tb.getZoom() > MIN_ZOOM_LABEL_DISPLAY) {
                tb.setZoom(tb.getZoom() - 1);
            }
            // mapContextMenu.setMapZoom(settings.getMapZoomToShow());
            mapContextMenu.setMapZoom(tb.getZoom());
            if (toShow instanceof GpxDisplayItem) {
                TrackDetailsMenu trackDetailsMenu = mapLayers.getMapControlsLayer().getTrackDetailsMenu();
                trackDetailsMenu.setGpxItem((GpxDisplayItem) toShow);
                trackDetailsMenu.show();
            } else if (MapRouteInfoMenu.isVisible()) {
                mapContextMenu.showMinimized(latLonToShow, mapLabelToShow, toShow);
                mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateMenu();
                MapRouteInfoMenu.showLocationOnMap(this, latLonToShow.getLatitude(), latLonToShow.getLongitude());
            } else if (toShow instanceof QuadRect) {
                QuadRect qr = (QuadRect) toShow;
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
            } else if (toShow instanceof NewGpxPoint) {
                NewGpxPoint newGpxPoint = (NewGpxPoint) toShow;
                QuadRect qr = newGpxPoint.getRect();
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
                getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
            } else if (toShow instanceof NewGpxData) {
                NewGpxData newGpxData = (NewGpxData) toShow;
                QuadRect qr = newGpxData.getRect();
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
                MeasurementEditingContext editingContext = new MeasurementEditingContext();
                editingContext.setNewGpxData(newGpxData);
                MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
            } else {
                mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
            }
            if (editToShow) {
                mapContextMenu.openEditor();
            }
        } else if (!latLonToShow.equals(cur)) {
            mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), latLonToShow.getLongitude(), settings.getMapZoomToShow(), true);
        }
    }
}
Also used : MeasurementEditingContext(net.osmand.plus.measurementtool.MeasurementEditingContext) RotatedTileBox(net.osmand.data.RotatedTileBox) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) QuadRect(net.osmand.data.QuadRect) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) LatLon(net.osmand.data.LatLon) TrackDetailsMenu(net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu) PointDescription(net.osmand.data.PointDescription) NewGpxData(net.osmand.plus.measurementtool.NewGpxData) Location(net.osmand.Location)

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