use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class FavouritePointMenuBuilder method buildGroupFavouritesView.
private void buildGroupFavouritesView(View view) {
FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav);
List<FavouritePoint> groupFavourites = favoriteGroup.points;
if (groupFavourites.size() > 0) {
int color = favoriteGroup.color == 0 || favoriteGroup.color == Color.BLACK ? view.getResources().getColor(R.color.color_favorite) : favoriteGroup.color;
int disabledColor = light ? R.color.secondary_text_light : R.color.secondary_text_dark;
color = favoriteGroup.visible ? (color | 0xff000000) : view.getResources().getColor(disabledColor);
String name = view.getContext().getString(R.string.context_menu_points_of_group);
buildRow(view, app.getIconsCache().getPaintedIcon(R.drawable.ic_action_folder, color), null, name, 0, null, true, getCollapsableFavouritesView(view.getContext(), true, favoriteGroup, fav), false, 0, false, null, false);
}
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class FavoritePointEditor method add.
public void add(LatLon latLon, String title, String originObjectName) {
if (latLon == null) {
return;
}
isNew = true;
String lastCategory = app.getSettings().LAST_FAV_CATEGORY_ENTERED.get();
if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) {
lastCategory = "";
}
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory);
favorite.setDescription("");
favorite.setOriginObjectName(originObjectName);
FavoritePointEditorFragment.showInstance(mapActivity);
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class FavoritePointEditor method add.
public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, boolean autoFill) {
if (latLon == null)
return;
isNew = true;
if (categoryName != null && !categoryName.isEmpty()) {
FavouritesDbHelper.FavoriteGroup category = mapActivity.getMyApplication().getFavorites().getGroup(categoryName);
if (category == null)
mapActivity.getMyApplication().getFavorites().addEmptyCategory(categoryName, categoryColor);
} else
categoryName = "";
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName);
favorite.setDescription("");
favorite.setOriginObjectName(originObjectName);
FavoritePointEditorFragment.showAutoFillInstance(mapActivity, autoFill);
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class FavoritePointEditorFragment method save.
@Override
protected void save(final boolean needDismiss) {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), getNameTextValue(), getCategoryTextValue());
point.setDescription(getDescriptionTextValue());
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
if (favorite.getName().equals(point.getName()) && favorite.getCategory().equals(point.getCategory()) && Algorithms.stringsEqual(favorite.getDescription(), point.getDescription())) {
if (needDismiss) {
dismiss(false);
}
return;
}
if (builder != null && !autoFill) {
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
}
});
builder.create().show();
} else {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
}
saved = true;
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class MapMarkersGroupsFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity();
final boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
mainView = inflater.inflate(R.layout.fragment_map_markers_groups, container, false);
Fragment selectionMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(SelectionMarkersGroupBottomSheetDialogFragment.TAG);
if (selectionMarkersGroupFragment != null) {
((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
}
Fragment historyMarkerMenuFragment = getChildFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
if (historyMarkerMenuFragment != null) {
((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
}
final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
}
});
backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
backgroundPaint.setAntiAlias(true);
iconPaint.setAntiAlias(true);
iconPaint.setFilterBitmap(true);
iconPaint.setDither(true);
textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
textPaint.setFakeBoldText(true);
textPaint.setAntiAlias(true);
final String delStr = getString(R.string.shared_string_delete).toUpperCase();
final String moveToHistoryStr = getString(R.string.move_to_history).toUpperCase();
final Rect bounds = new Rect();
textPaint.getTextBounds(delStr, 0, delStr.length(), bounds);
final int delStrWidth = bounds.width();
final int textHeight = bounds.height();
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);
private Bitmap historyBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_history);
private boolean iconHidden;
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
boolean markerViewHolder = viewHolder instanceof MapMarkerItemViewHolder;
int pos = viewHolder.getAdapterPosition();
if (markerViewHolder && pos != -1) {
MapMarker marker = (MapMarker) adapter.getItem(pos);
if (marker.history) {
return ItemTouchHelper.LEFT;
} else {
return ItemTouchHelper.RIGHT;
}
} else {
return 0;
}
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
if (!iconHidden && isCurrentlyActive) {
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
compassUpdateAllowed = false;
iconHidden = true;
}
View itemView = viewHolder.itemView;
int colorIcon;
int colorText;
if (Math.abs(dX) > itemView.getWidth() / 2) {
colorIcon = R.color.map_widget_blue;
colorText = R.color.map_widget_blue;
} else {
colorIcon = night ? 0 : R.color.icon_color;
colorText = R.color.dashboard_subheader_text_light;
}
if (colorIcon != 0) {
iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN));
}
textPaint.setColor(ContextCompat.getColor(getActivity(), colorText));
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
if (dX > 0) {
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
float iconMarginTop = ((float) itemView.getHeight() - (float) historyBitmap.getHeight()) / 2;
c.drawBitmap(historyBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + historyBitmap.getWidth(), itemView.getTop() + textMarginTop + textHeight, textPaint);
} else {
c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
c.drawBitmap(deleteBitmap, itemView.getRight() - deleteBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
c.drawText(delStr, itemView.getRight() - deleteBitmap.getWidth() - 2 * marginSides - delStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
}
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof MapMarkerItemViewHolder) {
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
iconHidden = false;
compassUpdateAllowed = true;
}
super.clearView(recyclerView, viewHolder);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, final int direction) {
final int pos = viewHolder.getAdapterPosition();
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
final MapMarker marker = (MapMarker) item;
int snackbarStringRes;
if (direction == ItemTouchHelper.RIGHT) {
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
snackbarStringRes = R.string.marker_moved_to_history;
} else {
mapActivity.getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
snackbarStringRes = R.string.item_removed;
}
updateAdapter();
snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (direction == ItemTouchHelper.RIGHT) {
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
} else {
mapActivity.getMyApplication().getMapMarkersHelper().addMarker(marker);
}
updateAdapter();
}
});
AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
snackbar.show();
}
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
adapter = new MapMarkersGroupsAdapter(mapActivity);
adapter.setListener(new MapMarkersGroupsAdapter.MapMarkersGroupsAdapterListener() {
@Override
public void onItemClick(View view) {
int pos = recyclerView.getChildAdapterPosition(view);
if (pos == RecyclerView.NO_POSITION) {
return;
}
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item;
OsmandApplication app = mapActivity.getMyApplication();
if (!marker.history) {
if (app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
app.getMapMarkersHelper().moveMarkerToTop(marker);
updateAdapter();
} else {
FavouritePoint fav = marker.favouritePoint == null ? app.getFavorites().getVisibleFavByLatLon(marker.point) : marker.favouritePoint;
if (fav != null) {
showMap(marker.point, fav.getPointDescription(), fav);
return;
}
WptPt pt = marker.wptPt == null ? app.getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point) : marker.wptPt;
if (pt != null) {
showMap(marker.point, pt.getPointDescription(mapActivity), pt);
return;
}
Amenity mapObj = mapActivity.getMapLayers().getMapMarkersLayer().getMapObjectByMarker(marker);
PointDescription desc = mapObj == null ? marker.getPointDescription(mapActivity) : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj);
showMap(marker.point, desc, mapObj == null ? marker : mapObj);
}
} else {
showHistoryMenuFragment(pos, marker);
}
}
}
private void showMap(LatLon latLon, PointDescription desc, Object objToShow) {
mapActivity.getMyApplication().getSettings().setMapLocationToShow(latLon.getLatitude(), latLon.getLongitude(), 15, desc, true, objToShow);
MapActivity.launchMapActivityMoveToTop(mapActivity);
((DialogFragment) getParentFragment()).dismiss();
}
private void showHistoryMenuFragment(int pos, MapMarker marker) {
HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment();
fragment.setUsedOnMap(false);
Bundle arguments = new Bundle();
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos);
arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity));
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex);
arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate);
fragment.setArguments(arguments);
fragment.setListener(createHistoryMarkerMenuListener());
fragment.show(getChildFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
}
});
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
changeFabVisibilityIfNeeded();
}
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
changeFabVisibilityIfNeeded();
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
changeFabVisibilityIfNeeded();
}
});
final View emptyView = mainView.findViewById(R.id.empty_view);
mainView.findViewById(R.id.import_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openAddGroupMenu();
}
});
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
if (Build.VERSION.SDK_INT >= 18) {
emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_group_night : R.drawable.ic_empty_state_marker_group_day);
} else {
emptyImageView.setVisibility(View.INVISIBLE);
}
recyclerView.setEmptyView(emptyView);
recyclerView.setAdapter(adapter);
mainView.findViewById(R.id.add_group_fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openAddGroupMenu();
}
});
if (groupIdToOpen != null) {
int groupHeaderPosition = adapter.getGroupHeaderPosition(groupIdToOpen);
if (groupHeaderPosition != -1) {
((EmptyStateRecyclerView) mainView.findViewById(R.id.list)).scrollToPosition(groupHeaderPosition);
}
}
return mainView;
}
Aggregations