Search in sources :

Example 1 with MeasurementAdapterListener

use of net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter.MeasurementAdapterListener in project Osmand by osmandapp.

the class MeasurementToolFragment method createMeasurementAdapterListener.

private MeasurementAdapterListener createMeasurementAdapterListener(final ItemTouchHelper touchHelper) {
    return new MeasurementAdapterListener() {

        final MapActivity mapActivity = getMapActivity();

        final MeasurementToolLayer measurementLayer = getMeasurementLayer();

        private int fromPosition;

        private int toPosition;

        @Override
        public void onRemoveClick(int position) {
            if (measurementLayer != null) {
                removePoint(measurementLayer, position);
            }
        }

        @Override
        public void onItemClick(int position) {
            if (mapActivity != null && measurementLayer != null) {
                if (pointsListOpened) {
                    hidePointsList();
                }
                OsmandMapTileView tileView = mapActivity.getMapView();
                if (portrait) {
                    previousMapPosition = tileView.getMapPosition();
                    tileView.setMapPosition(MIDDLE_TOP_CONSTANT);
                }
                mapActivity.refreshMap();
                measurementLayer.moveMapToPoint(position);
                measurementLayer.selectPoint(position);
            }
        }

        @Override
        public void onDragStarted(RecyclerView.ViewHolder holder) {
            fromPosition = holder.getAdapterPosition();
            touchHelper.startDrag(holder);
        }

        @Override
        public void onDragEnded(RecyclerView.ViewHolder holder) {
            if (mapActivity != null && measurementLayer != null) {
                toPosition = holder.getAdapterPosition();
                if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
                    editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
                    adapter.notifyDataSetChanged();
                    disable(redoBtn);
                    updateText();
                    mapActivity.refreshMap();
                    saved = false;
                }
            }
        }
    };
}
Also used : ReorderPointCommand(net.osmand.plus.measurementtool.command.ReorderPointCommand) MeasurementAdapterListener(net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter.MeasurementAdapterListener) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

MapActivity (net.osmand.plus.activities.MapActivity)1 MeasurementAdapterListener (net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter.MeasurementAdapterListener)1 ReorderPointCommand (net.osmand.plus.measurementtool.command.ReorderPointCommand)1 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)1