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);
}
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;
}
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);
}
}
}
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);
}
}
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();
}
}
Aggregations