From 730bf5de8b107831a60da06236f27ee35ef35595 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 25 Aug 2017 17:50:38 +0300 Subject: [PATCH] Delete unnecessary variables --- .../layout-land/fragment_measurement_tool.xml | 19 +--- .../res/layout/fragment_measurement_tool.xml | 19 +--- .../MeasurementEditingContext.java | 28 ----- .../MeasurementToolFragment.java | 107 ++++-------------- .../measurementtool/MeasurementToolLayer.java | 30 +---- 5 files changed, 33 insertions(+), 170 deletions(-) diff --git a/OsmAnd/res/layout-land/fragment_measurement_tool.xml b/OsmAnd/res/layout-land/fragment_measurement_tool.xml index c67868f0a9..c211f3148c 100644 --- a/OsmAnd/res/layout-land/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout-land/fragment_measurement_tool.xml @@ -121,7 +121,7 @@ android:visibility="gone"/> - - diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index 0e0feba970..c1977ac715 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -116,7 +116,7 @@ android:visibility="gone"/> - - diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index c5f465b219..53f0054112 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -34,10 +34,6 @@ public class MeasurementEditingContext { // cache should be deleted if after changed or snappedToRoadPoints private TrkSegment afterCacheForSnap; - private boolean inMovePointMode; - private boolean inAddPointBeforeMode; - private boolean inAddPointAfterMode; - private int selectedPointPosition = -1; private WptPt originalPointToMove; @@ -56,30 +52,10 @@ public class MeasurementEditingContext { return commandManager; } - public boolean isInMovePointMode() { - return inMovePointMode; - } - - public void setInMovePointMode(boolean inMovePointMode) { - this.inMovePointMode = inMovePointMode; - } - public boolean isInSnapToRoadMode() { return inSnapToRoadMode; } - public void setInAddPointBeforeMode(boolean inAddPointBeforeMode) { - this.inAddPointBeforeMode = inAddPointBeforeMode; - } - - public boolean isInAddPointBeforeMode() { - return inAddPointBeforeMode; - } - - public void setInAddPointAfterMode(boolean inAddPointAfterMode) { - this.inAddPointAfterMode = inAddPointAfterMode; - } - public int getSelectedPointPosition() { return selectedPointPosition; } @@ -96,10 +72,6 @@ public class MeasurementEditingContext { this.originalPointToMove = originalPointToMove; } - public boolean isInAddPointAfterMode() { - return inAddPointAfterMode; - } - public void setInSnapToRoadMode(boolean inSnapToRoadMode) { this.inSnapToRoadMode = inSnapToRoadMode; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 50483dab0f..086c83c707 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -231,11 +231,7 @@ public class MeasurementToolFragment extends Fragment { mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (editingCtx.isInAddPointAfterMode()) { - cancelAddPointAfterMode(); - } else if (editingCtx.isInAddPointBeforeMode()) { - cancelAddPointBeforeMode(); - } + cancelAddPointBeforeOrAfterMode(); } }); @@ -243,11 +239,7 @@ public class MeasurementToolFragment extends Fragment { upDownRow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (!pointsListOpened - && editingCtx.getPointsCount() > 0 - && !editingCtx.isInMovePointMode() - && !editingCtx.isInAddPointAfterMode() - && !editingCtx.isInAddPointBeforeMode()) { + if (!pointsListOpened && editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) { showPointsList(); } else { hidePointsList(); @@ -265,22 +257,14 @@ public class MeasurementToolFragment extends Fragment { mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (editingCtx.isInAddPointAfterMode()) { - applyAddPointAfterMode(); - } else if (editingCtx.isInAddPointBeforeMode()) { - applyAddPointBeforeMode(); - } + applyAddPointBeforeOrAfterMode(); } }); mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (editingCtx.isInAddPointAfterMode()) { - addPointAfter(); - } else if (editingCtx.isInAddPointBeforeMode()) { - addPointBefore(); - } + addPointBeforeOrAfter(); } }); @@ -391,7 +375,7 @@ public class MeasurementToolFragment extends Fragment { } toolBarController = new MeasurementToolBarController(newGpxData); - if (editingCtx.isInAddPointAfterMode() || editingCtx.isInAddPointBeforeMode() || editingCtx.isInMovePointMode()) { + if (editingCtx.getSelectedPointPosition() != -1) { toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back); } else { toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); @@ -479,22 +463,16 @@ public class MeasurementToolFragment extends Fragment { if (pointsListOpened) { hidePointsList(); } - if (editingCtx.isInMovePointMode()) { + if (editingCtx.getOriginalPointToMove() != null) { switchMovePointMode(false); - } - if (editingCtx.isInAddPointAfterMode()) { - switchAddPointAfterMode(false); - } - if (editingCtx.isInAddPointBeforeMode()) { - switchAddPointBeforeMode(false); + } else if (editingCtx.getSelectedPointPosition() != -1) { + switchAddPointBeforeAfterMode(false); } MeasurementToolLayer layer = getMeasurementLayer(); if (layer != null) { - if (editingCtx.isInMovePointMode()) { + if (editingCtx.getOriginalPointToMove() != null) { layer.exitMovePointMode(true); } - layer.exitAddPointAfterMode(); - layer.exitAddPointBeforeMode(); layer.setOnSingleTapListener(null); layer.setOnEnterMovePointModeListener(null); } @@ -632,7 +610,8 @@ public class MeasurementToolFragment extends Fragment { editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); measurementLayer.enterAddingPointAfterMode(); } - switchAddPointAfterMode(true); + ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after)); + switchAddPointBeforeAfterMode(true); } @Override @@ -641,7 +620,8 @@ public class MeasurementToolFragment extends Fragment { editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); measurementLayer.enterAddingPointBeforeMode(); } - switchAddPointBeforeMode(true); + ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before)); + switchAddPointBeforeAfterMode(true); } @Override @@ -877,63 +857,31 @@ public class MeasurementToolFragment extends Fragment { } } - private void addPointAfter() { + private void addPointBeforeOrAfter() { MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { - if (addPointToPosition(editingCtx.getSelectedPointPosition())) { - editingCtx.setSelectedPointPosition(editingCtx.getSelectedPointPosition() + 1); + if (addPointToPosition(editingCtx.getPointsCount())) { + editingCtx.setSelectedPointPosition(editingCtx.getPointsCount()); editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); measurementLayer.refreshMap(); } } } - private void applyAddPointAfterMode() { + private void applyAddPointBeforeOrAfterMode() { switchAddPointAfterMode(false); editingCtx.setSelectedPointPosition(-1); MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { - measurementLayer.exitAddPointAfterMode(); measurementLayer.refreshMap(); } } - private void cancelAddPointAfterMode() { - switchAddPointAfterMode(false); + private void cancelAddPointBeforeOrAfterMode() { + switchAddPointBeforeAfterMode(false); editingCtx.setSelectedPointPosition(-1); MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); if (measurementToolLayer != null) { - measurementToolLayer.exitAddPointAfterMode(); - measurementToolLayer.refreshMap(); - } - } - - private void addPointBefore() { - MeasurementToolLayer measurementLayer = getMeasurementLayer(); - if (measurementLayer != null) { - if (addPointToPosition(editingCtx.getSelectedPointPosition())) { - editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); - measurementLayer.refreshMap(); - } - } - } - - private void applyAddPointBeforeMode() { - switchAddPointBeforeMode(false); - editingCtx.setSelectedPointPosition(-1); - MeasurementToolLayer measurementLayer = getMeasurementLayer(); - if (measurementLayer != null) { - measurementLayer.exitAddPointBeforeMode(); - measurementLayer.refreshMap(); - } - } - - private void cancelAddPointBeforeMode() { - switchAddPointBeforeMode(false); - editingCtx.setSelectedPointPosition(-1); - MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); - if (measurementToolLayer != null) { - measurementToolLayer.exitAddPointBeforeMode(); measurementToolLayer.refreshMap(); } } @@ -969,14 +917,14 @@ public class MeasurementToolFragment extends Fragment { } markGeneralComponents(enable ? View.GONE : View.VISIBLE); mark(enable ? View.VISIBLE : View.GONE, - R.id.add_point_after_text, + R.id.add_point_before_after_text, R.id.add_point_before_after_controls); mainIcon.setImageDrawable(getActiveIcon(enable ? R.drawable.ic_action_addpoint_above : R.drawable.ic_action_ruler)); } - private void switchAddPointBeforeMode(boolean enable) { + private void switchAddPointBeforeAfterMode(boolean enable) { if (enable) { toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back); } else { @@ -988,7 +936,7 @@ public class MeasurementToolFragment extends Fragment { } markGeneralComponents(enable ? View.GONE : View.VISIBLE); mark(enable ? View.VISIBLE : View.GONE, - R.id.add_point_before_text, + R.id.add_point_before_after_text, R.id.add_point_before_after_controls); mainIcon.setImageDrawable(getActiveIcon(enable ? R.drawable.ic_action_addpoint_below @@ -1417,16 +1365,11 @@ public class MeasurementToolFragment extends Fragment { } public void quit(boolean hidePointsListFirst) { - if (editingCtx.isInMovePointMode()) { + if (editingCtx.getOriginalPointToMove() != null) { cancelMovePointMode(); return; - } - if (editingCtx.isInAddPointAfterMode()) { - cancelAddPointAfterMode(); - return; - } - if (editingCtx.isInAddPointBeforeMode()) { - cancelAddPointBeforeMode(); + } else if (editingCtx.getSelectedPointPosition() != -1) { + cancelAddPointBeforeOrAfterMode(); return; } showQuitDialog(hidePointsListFirst); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index e02ed487a5..59297113b9 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -114,10 +114,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL @Override public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { - if (inMeasurementMode - && !editingCtx.isInMovePointMode() - && !editingCtx.isInAddPointBeforeMode() - && !editingCtx.isInAddPointAfterMode()) { + if (inMeasurementMode && editingCtx.getSelectedPointPosition() == -1) { if (!overlapped) { selectPoint(point.x, point.y, true); } @@ -134,10 +131,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL @Override public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { if (inMeasurementMode) { - if (!overlapped && !editingCtx.isInMovePointMode() - && !editingCtx.isInAddPointBeforeMode() - && !editingCtx.isInAddPointAfterMode() - && editingCtx.getPointsCount() > 0) { + if (!overlapped && getEditingCtx().getSelectedPointPosition() == -1 && editingCtx.getPointsCount() > 0) { selectPoint(point.x, point.y, false); if (editingCtx.getSelectedPointPosition() != -1) { enterMovingPointMode(); @@ -151,7 +145,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL } void enterMovingPointMode() { - editingCtx.setInMovePointMode(true); moveMapToPoint(editingCtx.getSelectedPointPosition()); WptPt pt = editingCtx.removePoint(editingCtx.getSelectedPointPosition()); editingCtx.setOriginalPointToMove(pt); @@ -159,12 +152,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL } void enterAddingPointAfterMode() { - editingCtx.setInAddPointAfterMode(true); moveMapToPoint(editingCtx.getSelectedPointPosition() - 1); } void enterAddingPointBeforeMode() { - editingCtx.setInAddPointBeforeMode(true); moveMapToPoint(editingCtx.getSelectedPointPosition()); } @@ -217,9 +208,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL if (inMeasurementMode) { lineAttrs.updatePaints(view, settings, tb); - if (!editingCtx.isInMovePointMode() - && !editingCtx.isInAddPointBeforeMode() - && !editingCtx.isInAddPointAfterMode()) { + if (editingCtx.getSelectedPointPosition() == -1) { drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode()); if (measureDistanceToCenterListener != null) { float distance = 0; @@ -311,9 +300,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL } } - if (editingCtx.isInMovePointMode() - || editingCtx.isInAddPointBeforeMode() - || editingCtx.isInAddPointAfterMode()) { + if (editingCtx.getSelectedPointPosition() != -1) { int locX = tb.getCenterPixelX(); int locY = tb.getCenterPixelY(); canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint); @@ -322,7 +309,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL } void exitMovePointMode(boolean saveOriginalPoint) { - editingCtx.setInMovePointMode(false); if (saveOriginalPoint) { WptPt pt = editingCtx.getOriginalPointToMove(); editingCtx.addPoint(pt); @@ -332,14 +318,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size()); } - void exitAddPointAfterMode() { - editingCtx.setInAddPointAfterMode(false); - } - - void exitAddPointBeforeMode() { - editingCtx.setInAddPointBeforeMode(false); - } - private void drawCenterIcon(Canvas canvas, RotatedTileBox tb, QuadPoint center, boolean nightMode) { canvas.rotate(-tb.getRotate(), center.x, center.y); if (nightMode) {