Search in sources :

Example 26 with FavouritePoint

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

the class FavoriteDialogs method createReplaceFavouriteDialog.

public static Dialog createReplaceFavouriteDialog(final Activity activity, final Bundle args) {
    final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
    final List<FavouritePoint> points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
    final FavouritesAdapter favouritesAdapter = new FavouritesAdapter(activity, ((OsmandApplication) activity.getApplication()).getFavorites().getFavouritePoints(), false);
    final Dialog[] dlgHolder = new Dialog[1];
    OnItemClickListener click = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            confirmReplace(activity, args, helper, favouritesAdapter, dlgHolder, position);
        }
    };
    if (activity instanceof MapActivity) {
        favouritesAdapter.updateLocation(((MapActivity) activity).getMapLocation());
    }
    if (points.size() == 0) {
        Toast.makeText(activity, activity.getString(R.string.fav_points_not_exist), Toast.LENGTH_SHORT).show();
        return null;
    }
    return showFavoritesDialog(activity, favouritesAdapter, click, null, dlgHolder, true);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) FavouritesAdapter(net.osmand.plus.activities.FavoritesListFragment.FavouritesAdapter) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) ArrayList(java.util.ArrayList) AdapterView(android.widget.AdapterView) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ListView(android.widget.ListView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 27 with FavouritePoint

use of net.osmand.data.FavouritePoint 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 28 with FavouritePoint

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

the class SearchActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_FAVORITE_SELECT && resultCode == FavoritesListFragment.SELECT_FAVORITE_POINT_RESULT_OK) {
        FavouritePoint p = (FavouritePoint) data.getSerializableExtra(FavoritesListFragment.SELECT_FAVORITE_POINT_INTENT_KEY);
        if (p != null) {
            LatLon latLon = new LatLon(p.getLatitude(), p.getLongitude());
            updateSearchPoint(latLon, getString(R.string.select_search_position) + " " + p.getName(), false);
        }
    } else if (requestCode == REQUEST_ADDRESS_SELECT && resultCode == SearchAddressFragment.SELECT_ADDRESS_POINT_RESULT_OK) {
        String name = data.getStringExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_INTENT_KEY);
        LatLon latLon = new LatLon(data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LAT, 0), data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LON, 0));
        if (name != null) {
            updateSearchPoint(latLon, getString(R.string.select_search_position) + " " + name, false);
        } else {
            updateSearchPoint(latLon, getString(R.string.select_search_position) + " ", true);
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) FavouritePoint(net.osmand.data.FavouritePoint)

Example 29 with FavouritePoint

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

the class MapMarkersHelper method addMarkers.

private void addMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MapMarkersGroup group, @Nullable List<FavouritePoint> favouritePoints, @Nullable List<WptPt> wptPts, @Nullable List<String> mapObjNames) {
    if (points.size() > 0) {
        int colorIndex = -1;
        List<MapMarker> addedMarkers = new ArrayList<>();
        for (int i = 0; i < points.size(); i++) {
            LatLon point = points.get(i);
            PointDescription historyName = historyNames.get(i);
            FavouritePoint favouritePoint = favouritePoints == null ? null : favouritePoints.get(i);
            WptPt wptPt = wptPts == null ? null : wptPts.get(i);
            String mapObjName = mapObjNames == null ? null : mapObjNames.get(i);
            final PointDescription pointDescription;
            if (historyName == null) {
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
            } else {
                pointDescription = historyName;
            }
            if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
                pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
            }
            if (colorIndex == -1) {
                if (mapMarkers.size() > 0) {
                    colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
                } else {
                    colorIndex = 0;
                }
            } else {
                colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
            }
            MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0);
            if (group != null) {
                marker.id = group.getId() + marker.getName(ctx);
                // TODO ???????
                if (markersDbHelper.getMarker(marker.id) != null) {
                    continue;
                }
                marker.groupName = group.getName();
                marker.groupKey = group.getId();
            }
            marker.history = false;
            marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
            marker.favouritePoint = favouritePoint;
            marker.wptPt = wptPt;
            marker.mapObjectName = mapObjName;
            markersDbHelper.addMarker(marker);
            addToMapMarkersList(0, marker);
            addedMarkers.add(marker);
            reorderActiveMarkersIfNeeded();
            lookupAddress(marker);
        }
        addMarkersToGroups(addedMarkers);
    }
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.plus.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) PointDescription(net.osmand.data.PointDescription) ArrayList(java.util.ArrayList) LocationPoint(net.osmand.data.LocationPoint) FavouritePoint(net.osmand.data.FavouritePoint)

Example 30 with FavouritePoint

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

the class FavoritesListFragment method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (!isSelectFavoriteMode()) {
        FavouritePoint point = favouritesAdapter.getItem(position);
        showOnMap(point, getActivity());
    } else {
        Intent intent = getActivity().getIntent();
        intent.putExtra(SELECT_FAVORITE_POINT_INTENT_KEY, favouritesAdapter.getItem(position));
        getActivity().setResult(SELECT_FAVORITE_POINT_RESULT_OK, intent);
        getActivity().finish();
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) Intent(android.content.Intent)

Aggregations

FavouritePoint (net.osmand.data.FavouritePoint)51 LatLon (net.osmand.data.LatLon)16 PointDescription (net.osmand.data.PointDescription)10 FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)10 View (android.view.View)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.support.v7.app.AlertDialog)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 TextView (android.widget.TextView)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 MapActivity (net.osmand.plus.activities.MapActivity)7 DialogInterface (android.content.DialogInterface)6 ImageView (android.widget.ImageView)6 Amenity (net.osmand.data.Amenity)6 Paint (android.graphics.Paint)5 AdapterView (android.widget.AdapterView)5 ListView (android.widget.ListView)5 FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)5 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)5 Collator (java.text.Collator)4