Save selected point menu on rotate
This commit is contained in:
parent
9b819c305d
commit
6eca185f37
2 changed files with 102 additions and 57 deletions
|
@ -103,18 +103,82 @@ public class MeasurementToolFragment extends Fragment {
|
|||
private boolean inAddPointAfterMode;
|
||||
private boolean inAddPointBeforeMode;
|
||||
|
||||
private int selectedPointPos = -1;
|
||||
private WptPt selectedCachedPoint;
|
||||
|
||||
private int positionToAddPoint = -1;
|
||||
|
||||
public void setNewGpxLine(NewGpxLine newGpxLine) {
|
||||
this.newGpxLine = newGpxLine;
|
||||
}
|
||||
|
||||
private SelectedPointOptionOnClickListener createSelectedPointOptionOnClickListener() {
|
||||
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
|
||||
return new SelectedPointOptionOnClickListener() {
|
||||
@Override
|
||||
public void moveOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
measurementLayer.enterMovingPointMode();
|
||||
}
|
||||
switchMovePointMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteOnClick() {
|
||||
clearSelection();
|
||||
if (measurementLayer != null) {
|
||||
int position = measurementLayer.getSelectedPointPos();
|
||||
commandManager.execute(new RemovePointCommand(measurementLayer, position));
|
||||
adapter.notifyDataSetChanged();
|
||||
disable(redoBtn);
|
||||
updateText();
|
||||
saved = false;
|
||||
hidePointsListIfNoPoints();
|
||||
measurementLayer.clearSelection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPointAfterOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
positionToAddPoint = measurementLayer.getSelectedPointPos() + 1;
|
||||
measurementLayer.enterAddingPointAfterMode();
|
||||
}
|
||||
switchAddPointAfterMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPointBeforeOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
positionToAddPoint = measurementLayer.getSelectedPointPos();
|
||||
measurementLayer.enterAddingPointBeforeMode();
|
||||
}
|
||||
switchAddPointBeforeMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCloseMenu() {
|
||||
setPreviousMapPosition();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
||||
measurementLayer.setMeasurementPoints(measurementPoints);
|
||||
if (selectedPointPos != -1 && selectedCachedPoint != null) {
|
||||
measurementLayer.setSelectedPointPos(selectedPointPos);
|
||||
measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
|
||||
}
|
||||
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(SelectedPointMenuBottomSheetDialogFragment.TAG);
|
||||
if (fragment != null) {
|
||||
SelectedPointMenuBottomSheetDialogFragment selectedPointMenuBottomSheetDialogFragment = (SelectedPointMenuBottomSheetDialogFragment) fragment;
|
||||
selectedPointMenuBottomSheetDialogFragment.setSelectedPointOptionOnClickListener(createSelectedPointOptionOnClickListener());
|
||||
}
|
||||
commandManager.resetMeasurementLayer(measurementLayer);
|
||||
iconsCache = mapActivity.getMyApplication().getIconsCache();
|
||||
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
|
@ -301,11 +365,15 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSelectPoint() {
|
||||
public void onSelectPoint(int selectedPointPos, WptPt selectedCachedPoint) {
|
||||
if (pointsListOpened) {
|
||||
hidePointsList();
|
||||
}
|
||||
openSelectedPointMenu(mapActivity);
|
||||
MeasurementToolFragment.this.selectedPointPos = selectedPointPos;
|
||||
MeasurementToolFragment.this.selectedCachedPoint = selectedCachedPoint;
|
||||
if (selectedPointPos != -1 && selectedCachedPoint != null) {
|
||||
openSelectedPointMenu(mapActivity);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -383,6 +451,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onItemClick(View view) {
|
||||
clearSelection();
|
||||
int position = pointsRv.indexOfChild(view);
|
||||
if (pointsListOpened) {
|
||||
hidePointsList();
|
||||
|
@ -395,7 +464,6 @@ public class MeasurementToolFragment extends Fragment {
|
|||
mapActivity.refreshMap();
|
||||
measurementLayer.moveMapToPoint(position);
|
||||
measurementLayer.selectPoint(position);
|
||||
openSelectedPointMenu(mapActivity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -457,7 +525,6 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
MeasurementToolLayer layer = getMeasurementLayer();
|
||||
if (layer != null) {
|
||||
layer.clearSelection();
|
||||
layer.exitMovePointMode();
|
||||
layer.exitAddPointAfterMode();
|
||||
layer.exitAddPointBeforeMode();
|
||||
|
@ -482,52 +549,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
||||
|
||||
SelectedPointMenuBottomSheetDialogFragment fragment = new SelectedPointMenuBottomSheetDialogFragment();
|
||||
fragment.setSelectedPointOptionOnClickListener(new SelectedPointOptionOnClickListener() {
|
||||
@Override
|
||||
public void moveOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
measurementLayer.enterMovingPointMode();
|
||||
}
|
||||
switchMovePointMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
int position = measurementLayer.getSelectedPointPos();
|
||||
commandManager.execute(new RemovePointCommand(measurementLayer, position));
|
||||
adapter.notifyDataSetChanged();
|
||||
disable(redoBtn);
|
||||
updateText();
|
||||
saved = false;
|
||||
hidePointsListIfNoPoints();
|
||||
measurementLayer.clearSelection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPointAfterOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
positionToAddPoint = measurementLayer.getSelectedPointPos() + 1;
|
||||
measurementLayer.enterAddingPointAfterMode();
|
||||
}
|
||||
switchAddPointAfterMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPointBeforeOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
positionToAddPoint = measurementLayer.getSelectedPointPos();
|
||||
measurementLayer.enterAddingPointBeforeMode();
|
||||
}
|
||||
switchAddPointBeforeMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCloseMenu() {
|
||||
setPreviousMapPosition();
|
||||
}
|
||||
});
|
||||
fragment.setSelectedPointOptionOnClickListener(createSelectedPointOptionOnClickListener());
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointMenuBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
|
||||
|
@ -550,6 +572,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (inMovePointMode) {
|
||||
switchMovePointMode(false);
|
||||
}
|
||||
clearSelection();
|
||||
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
|
||||
if (measurementToolLayer != null) {
|
||||
measurementToolLayer.exitMovePointMode();
|
||||
|
@ -562,6 +585,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (inAddPointAfterMode) {
|
||||
switchAddPointAfterMode(false);
|
||||
}
|
||||
clearSelection();
|
||||
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
|
||||
if (measurementToolLayer != null) {
|
||||
measurementToolLayer.exitAddPointAfterMode();
|
||||
|
@ -575,6 +599,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (inAddPointBeforeMode) {
|
||||
switchAddPointBeforeMode(false);
|
||||
}
|
||||
clearSelection();
|
||||
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
|
||||
if (measurementToolLayer != null) {
|
||||
measurementToolLayer.exitAddPointBeforeMode();
|
||||
|
@ -588,6 +613,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (inMovePointMode) {
|
||||
switchMovePointMode(false);
|
||||
}
|
||||
clearSelection();
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
WptPt newPoint = measurementLayer.getMovedPointToApply();
|
||||
|
@ -609,6 +635,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (inAddPointAfterMode) {
|
||||
switchAddPointAfterMode(false);
|
||||
}
|
||||
clearSelection();
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null && positionToAddPoint != -1) {
|
||||
addPointToPosition(positionToAddPoint);
|
||||
|
@ -619,10 +646,16 @@ public class MeasurementToolFragment extends Fragment {
|
|||
positionToAddPoint = -1;
|
||||
}
|
||||
|
||||
private void clearSelection() {
|
||||
selectedPointPos = -1;
|
||||
selectedCachedPoint = null;
|
||||
}
|
||||
|
||||
private void applyAddPointBeforeMode() {
|
||||
if (inAddPointBeforeMode) {
|
||||
switchAddPointBeforeMode(false);
|
||||
}
|
||||
clearSelection();
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null && positionToAddPoint != -1) {
|
||||
addPointToPosition(positionToAddPoint);
|
||||
|
|
|
@ -76,6 +76,14 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
this.enterMovePointModeListener = listener;
|
||||
}
|
||||
|
||||
void setSelectedPointPos(int pos) {
|
||||
selectedPointPos = pos;
|
||||
}
|
||||
|
||||
void setSelectedCachedPoint(WptPt selectedCachedPoint) {
|
||||
this.selectedCachedPoint = selectedCachedPoint;
|
||||
}
|
||||
|
||||
WptPt getSelectedCachedPoint() {
|
||||
return selectedCachedPoint;
|
||||
}
|
||||
|
@ -131,10 +139,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||
if (singleTapListener != null) {
|
||||
if (inMeasurementMode && !inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode) {
|
||||
selectPoint(point.x, point.y);
|
||||
if (selectedPointPos != -1) {
|
||||
singleTapListener.onSelectPoint();
|
||||
} else {
|
||||
selectPoint(point.x, point.y, true);
|
||||
if (selectedPointPos == -1) {
|
||||
pressedPointLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
|
||||
singleTapListener.onAddPoint();
|
||||
}
|
||||
|
@ -152,7 +158,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
|
||||
if (inMeasurementMode) {
|
||||
if (!inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode && measurementPoints.size() > 0) {
|
||||
selectPoint(point.x, point.y);
|
||||
selectPoint(point.x, point.y, false);
|
||||
if (selectedCachedPoint != null && selectedPointPos != -1) {
|
||||
enterMovingPointMode();
|
||||
if (inMeasurementMode && inMovePointMode && enterMovePointModeListener != null) {
|
||||
|
@ -179,7 +185,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
moveMapToPoint(selectedPointPos);
|
||||
}
|
||||
|
||||
private void selectPoint(double x, double y) {
|
||||
private void selectPoint(double x, double y, boolean singleTap) {
|
||||
clearSelection();
|
||||
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
||||
double lowestDistance = AndroidUtils.dpToPx(view.getContext(), 20);
|
||||
|
@ -196,12 +202,18 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
}
|
||||
}
|
||||
}
|
||||
if (singleTap && singleTapListener != null) {
|
||||
singleTapListener.onSelectPoint(selectedPointPos, selectedCachedPoint);
|
||||
}
|
||||
}
|
||||
|
||||
void selectPoint(int position) {
|
||||
clearSelection();
|
||||
selectedCachedPoint = new WptPt(measurementPoints.get(position));
|
||||
selectedPointPos = position;
|
||||
if (singleTapListener != null) {
|
||||
singleTapListener.onSelectPoint(selectedPointPos, selectedCachedPoint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -430,7 +442,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
|
||||
void onAddPoint();
|
||||
|
||||
void onSelectPoint();
|
||||
void onSelectPoint(int selectedPointPos, WptPt selectedCachedPoint);
|
||||
}
|
||||
|
||||
interface OnEnterMovePointModeListener {
|
||||
|
|
Loading…
Reference in a new issue