Search in sources :

Example 31 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapMarkersDbHelper method getMarker.

@Nullable
public MapMarker getMarker(String id) {
    MapMarker res = null;
    SQLiteConnection db = openConnection(true);
    if (db != null) {
        try {
            SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ID + " = ?", new String[] { id });
            if (query.moveToFirst()) {
                res = readItem(query);
            }
            query.close();
        } finally {
            db.close();
        }
    }
    return res;
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) Nullable(android.support.annotation.Nullable)

Example 32 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapMarkersDbHelper method getActiveMarkers.

public List<MapMarker> getActiveMarkers() {
    Map<String, MapMarker> markers = new LinkedHashMap<>();
    Set<String> nextKeys = new HashSet<>();
    SQLiteConnection db = openConnection(true);
    if (db != null) {
        try {
            SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", new String[] { String.valueOf(1) });
            if (query.moveToFirst()) {
                do {
                    MapMarker marker = readItem(query);
                    markers.put(marker.id, marker);
                    nextKeys.add(marker.nextKey);
                } while (query.moveToNext());
            }
            query.close();
        } finally {
            db.close();
        }
    }
    return buildLinkedList(markers, nextKeys);
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 33 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapMarkersHistoryFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final boolean night = !app.getSettings().isLightContent();
    final MapActivity mapActivity = (MapActivity) getActivity();
    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 activateStr = getString(R.string.local_index_mi_restore).toUpperCase();
    Rect bounds = new Rect();
    textPaint.getTextBounds(activateStr, 0, activateStr.length(), bounds);
    final int activateStrWidth = bounds.width();
    final int textHeight = bounds.height();
    Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
    if (historyMarkerMenuFragment != null) {
        ((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
    }
    final View mainView = inflater.inflate(R.layout.fragment_map_markers_history, container, false);
    final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    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 resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark);

        private boolean iconHidden;

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (viewHolder instanceof MapMarkerHeaderViewHolder) {
                return 0;
            }
            return super.getSwipeDirs(recyclerView, viewHolder);
        }

        @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);
                    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) deleteBitmap.getHeight()) / 2;
                    c.drawBitmap(deleteBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
                    c.drawText(delStr, itemView.getLeft() + 2 * marginSides + deleteBitmap.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) resetBitmap.getHeight()) / 2;
                    c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
                    c.drawText(activateStr, itemView.getRight() - resetBitmap.getWidth() - 2 * marginSides - activateStrWidth, 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;
            }
            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.LEFT) {
                    app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
                    snackbarStringRes = R.string.marker_moved_to_active;
                } else {
                    app.getMapMarkersHelper().removeMarker((MapMarker) item);
                    snackbarStringRes = R.string.item_removed;
                }
                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.LEFT) {
                            app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
                        } else {
                            app.getMapMarkersHelper().addMarker(marker);
                        }
                    }
                });
                AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
                snackbar.show();
            }
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
    adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {

        @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;
                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(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
            }
        }
    });
    final View emptyView = mainView.findViewById(R.id.empty_view);
    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_history_night : R.drawable.ic_empty_state_marker_history_day);
    } else {
        emptyImageView.setVisibility(View.INVISIBLE);
    }
    recyclerView.setEmptyView(emptyView);
    recyclerView.setAdapter(adapter);
    app.getMapMarkersHelper().addListener(this);
    return mainView;
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) MapMarkerItemViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Fragment(android.support.v4.app.Fragment) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Bitmap(android.graphics.Bitmap) MapMarkerItemViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder) MapMarkerHeaderViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerHeaderViewHolder) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity) Rect(android.graphics.Rect) Bundle(android.os.Bundle) Canvas(android.graphics.Canvas) MapMarkerHeaderViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerHeaderViewHolder) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Paint(android.graphics.Paint) MapMarkersHistoryAdapter(net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) Nullable(android.support.annotation.Nullable)

Example 34 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class OsmandAidlApi method removeMapMarker.

boolean removeMapMarker(AMapMarker marker) {
    if (marker != null) {
        LatLon latLon = new LatLon(marker.getLatLon().getLatitude(), marker.getLatLon().getLongitude());
        MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
        for (MapMarker m : mapMarkers) {
            if (m.getOnlyName().equals(marker.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
                markersHelper.moveMapMarkerToHistory(m);
                refreshMap();
                return true;
            }
        }
        return false;
    } else {
        return false;
    }
}
Also used : LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) AMapMarker(net.osmand.aidl.mapmarker.AMapMarker)

Example 35 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class OsmandAidlApi method updateMapMarker.

boolean updateMapMarker(AMapMarker markerPrev, AMapMarker markerNew) {
    if (markerPrev != null && markerNew != null) {
        LatLon latLon = new LatLon(markerPrev.getLatLon().getLatitude(), markerPrev.getLatLon().getLongitude());
        LatLon latLonNew = new LatLon(markerNew.getLatLon().getLatitude(), markerNew.getLatLon().getLongitude());
        MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
        for (MapMarker m : mapMarkers) {
            if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
                PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : "");
                MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index);
                marker.id = m.id;
                marker.creationDate = m.creationDate;
                marker.visitedDate = m.visitedDate;
                markersHelper.moveMapMarker(marker, latLonNew);
                refreshMap();
                return true;
            }
        }
        return false;
    } else {
        return false;
    }
}
Also used : LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) AMapMarker(net.osmand.aidl.mapmarker.AMapMarker) PointDescription(net.osmand.data.PointDescription)

Aggregations

MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)38 LatLon (net.osmand.data.LatLon)20 View (android.view.View)13 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)11 RecyclerView (android.support.v7.widget.RecyclerView)10 OsmandApplication (net.osmand.plus.OsmandApplication)10 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)9 ImageView (android.widget.ImageView)8 Location (net.osmand.Location)8 PointDescription (net.osmand.data.PointDescription)8 Paint (android.graphics.Paint)7 Nullable (android.support.annotation.Nullable)6 MapActivity (net.osmand.plus.activities.MapActivity)6 ArrayList (java.util.ArrayList)5 Amenity (net.osmand.data.Amenity)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)4 FavouritePoint (net.osmand.data.FavouritePoint)4 QuadPoint (net.osmand.data.QuadPoint)4 Bitmap (android.graphics.Bitmap)3