Delete unnecessary variables

This commit is contained in:
PavelRatushny 2017-08-25 17:50:38 +03:00
parent 242c36ba4b
commit 730bf5de8b
5 changed files with 33 additions and 170 deletions

View file

@ -121,7 +121,7 @@
android:visibility="gone"/> android:visibility="gone"/>
<TextView <TextView
android:id="@+id/add_point_after_text" android:id="@+id/add_point_before_after_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@ -131,22 +131,7 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_toEndOf="@id/main_icon" android:layout_toEndOf="@id/main_icon"
android:layout_toRightOf="@id/main_icon" android:layout_toRightOf="@id/main_icon"
android:text="@string/add_point_after" tools:text="@string/add_point_before"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/>
<TextView
android:id="@+id/add_point_before_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_marginStart="8dp"
android:layout_toEndOf="@id/main_icon"
android:layout_toRightOf="@id/main_icon"
android:text="@string/add_point_before"
android:textAppearance="@style/TextAppearance.ListItemTitle" android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/> android:visibility="gone"/>
</RelativeLayout> </RelativeLayout>

View file

@ -116,7 +116,7 @@
android:visibility="gone"/> android:visibility="gone"/>
<TextView <TextView
android:id="@+id/add_point_after_text" android:id="@+id/add_point_before_after_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@ -126,22 +126,7 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_toEndOf="@id/main_icon" android:layout_toEndOf="@id/main_icon"
android:layout_toRightOf="@id/main_icon" android:layout_toRightOf="@id/main_icon"
android:text="@string/add_point_after" tools:text="@string/add_point_after"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/>
<TextView
android:id="@+id/add_point_before_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_marginStart="8dp"
android:layout_toEndOf="@id/main_icon"
android:layout_toRightOf="@id/main_icon"
android:text="@string/add_point_before"
android:textAppearance="@style/TextAppearance.ListItemTitle" android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/> android:visibility="gone"/>
</RelativeLayout> </RelativeLayout>

View file

@ -34,10 +34,6 @@ public class MeasurementEditingContext {
// cache should be deleted if after changed or snappedToRoadPoints // cache should be deleted if after changed or snappedToRoadPoints
private TrkSegment afterCacheForSnap; private TrkSegment afterCacheForSnap;
private boolean inMovePointMode;
private boolean inAddPointBeforeMode;
private boolean inAddPointAfterMode;
private int selectedPointPosition = -1; private int selectedPointPosition = -1;
private WptPt originalPointToMove; private WptPt originalPointToMove;
@ -56,30 +52,10 @@ public class MeasurementEditingContext {
return commandManager; return commandManager;
} }
public boolean isInMovePointMode() {
return inMovePointMode;
}
public void setInMovePointMode(boolean inMovePointMode) {
this.inMovePointMode = inMovePointMode;
}
public boolean isInSnapToRoadMode() { public boolean isInSnapToRoadMode() {
return inSnapToRoadMode; 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() { public int getSelectedPointPosition() {
return selectedPointPosition; return selectedPointPosition;
} }
@ -96,10 +72,6 @@ public class MeasurementEditingContext {
this.originalPointToMove = originalPointToMove; this.originalPointToMove = originalPointToMove;
} }
public boolean isInAddPointAfterMode() {
return inAddPointAfterMode;
}
public void setInSnapToRoadMode(boolean inSnapToRoadMode) { public void setInSnapToRoadMode(boolean inSnapToRoadMode) {
this.inSnapToRoadMode = inSnapToRoadMode; this.inSnapToRoadMode = inSnapToRoadMode;
} }

View file

@ -231,11 +231,7 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (editingCtx.isInAddPointAfterMode()) { cancelAddPointBeforeOrAfterMode();
cancelAddPointAfterMode();
} else if (editingCtx.isInAddPointBeforeMode()) {
cancelAddPointBeforeMode();
}
} }
}); });
@ -243,11 +239,7 @@ public class MeasurementToolFragment extends Fragment {
upDownRow.setOnClickListener(new View.OnClickListener() { upDownRow.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (!pointsListOpened if (!pointsListOpened && editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) {
&& editingCtx.getPointsCount() > 0
&& !editingCtx.isInMovePointMode()
&& !editingCtx.isInAddPointAfterMode()
&& !editingCtx.isInAddPointBeforeMode()) {
showPointsList(); showPointsList();
} else { } else {
hidePointsList(); hidePointsList();
@ -265,22 +257,14 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (editingCtx.isInAddPointAfterMode()) { applyAddPointBeforeOrAfterMode();
applyAddPointAfterMode();
} else if (editingCtx.isInAddPointBeforeMode()) {
applyAddPointBeforeMode();
}
} }
}); });
mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (editingCtx.isInAddPointAfterMode()) { addPointBeforeOrAfter();
addPointAfter();
} else if (editingCtx.isInAddPointBeforeMode()) {
addPointBefore();
}
} }
}); });
@ -391,7 +375,7 @@ public class MeasurementToolFragment extends Fragment {
} }
toolBarController = new MeasurementToolBarController(newGpxData); 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); toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else { } else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); 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) { if (pointsListOpened) {
hidePointsList(); hidePointsList();
} }
if (editingCtx.isInMovePointMode()) { if (editingCtx.getOriginalPointToMove() != null) {
switchMovePointMode(false); switchMovePointMode(false);
} } else if (editingCtx.getSelectedPointPosition() != -1) {
if (editingCtx.isInAddPointAfterMode()) { switchAddPointBeforeAfterMode(false);
switchAddPointAfterMode(false);
}
if (editingCtx.isInAddPointBeforeMode()) {
switchAddPointBeforeMode(false);
} }
MeasurementToolLayer layer = getMeasurementLayer(); MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) { if (layer != null) {
if (editingCtx.isInMovePointMode()) { if (editingCtx.getOriginalPointToMove() != null) {
layer.exitMovePointMode(true); layer.exitMovePointMode(true);
} }
layer.exitAddPointAfterMode();
layer.exitAddPointBeforeMode();
layer.setOnSingleTapListener(null); layer.setOnSingleTapListener(null);
layer.setOnEnterMovePointModeListener(null); layer.setOnEnterMovePointModeListener(null);
} }
@ -632,7 +610,8 @@ public class MeasurementToolFragment extends Fragment {
editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
measurementLayer.enterAddingPointAfterMode(); 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 @Override
@ -641,7 +620,8 @@ public class MeasurementToolFragment extends Fragment {
editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
measurementLayer.enterAddingPointBeforeMode(); 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 @Override
@ -877,63 +857,31 @@ public class MeasurementToolFragment extends Fragment {
} }
} }
private void addPointAfter() { private void addPointBeforeOrAfter() {
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
if (addPointToPosition(editingCtx.getSelectedPointPosition())) { if (addPointToPosition(editingCtx.getPointsCount())) {
editingCtx.setSelectedPointPosition(editingCtx.getSelectedPointPosition() + 1); editingCtx.setSelectedPointPosition(editingCtx.getPointsCount());
editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
measurementLayer.refreshMap(); measurementLayer.refreshMap();
} }
} }
} }
private void applyAddPointAfterMode() { private void applyAddPointBeforeOrAfterMode() {
switchAddPointAfterMode(false); switchAddPointAfterMode(false);
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.exitAddPointAfterMode();
measurementLayer.refreshMap(); measurementLayer.refreshMap();
} }
} }
private void cancelAddPointAfterMode() { private void cancelAddPointBeforeOrAfterMode() {
switchAddPointAfterMode(false); switchAddPointBeforeAfterMode(false);
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { 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(); measurementToolLayer.refreshMap();
} }
} }
@ -969,14 +917,14 @@ public class MeasurementToolFragment extends Fragment {
} }
markGeneralComponents(enable ? View.GONE : View.VISIBLE); markGeneralComponents(enable ? View.GONE : View.VISIBLE);
mark(enable ? View.VISIBLE : View.GONE, 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); R.id.add_point_before_after_controls);
mainIcon.setImageDrawable(getActiveIcon(enable mainIcon.setImageDrawable(getActiveIcon(enable
? R.drawable.ic_action_addpoint_above ? R.drawable.ic_action_addpoint_above
: R.drawable.ic_action_ruler)); : R.drawable.ic_action_ruler));
} }
private void switchAddPointBeforeMode(boolean enable) { private void switchAddPointBeforeAfterMode(boolean enable) {
if (enable) { if (enable) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back); toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else { } else {
@ -988,7 +936,7 @@ public class MeasurementToolFragment extends Fragment {
} }
markGeneralComponents(enable ? View.GONE : View.VISIBLE); markGeneralComponents(enable ? View.GONE : View.VISIBLE);
mark(enable ? View.VISIBLE : View.GONE, 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); R.id.add_point_before_after_controls);
mainIcon.setImageDrawable(getActiveIcon(enable mainIcon.setImageDrawable(getActiveIcon(enable
? R.drawable.ic_action_addpoint_below ? R.drawable.ic_action_addpoint_below
@ -1417,16 +1365,11 @@ public class MeasurementToolFragment extends Fragment {
} }
public void quit(boolean hidePointsListFirst) { public void quit(boolean hidePointsListFirst) {
if (editingCtx.isInMovePointMode()) { if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode(); cancelMovePointMode();
return; return;
} } else if (editingCtx.getSelectedPointPosition() != -1) {
if (editingCtx.isInAddPointAfterMode()) { cancelAddPointBeforeOrAfterMode();
cancelAddPointAfterMode();
return;
}
if (editingCtx.isInAddPointBeforeMode()) {
cancelAddPointBeforeMode();
return; return;
} }
showQuitDialog(hidePointsListFirst); showQuitDialog(hidePointsListFirst);

View file

@ -114,10 +114,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
@Override @Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode if (inMeasurementMode && editingCtx.getSelectedPointPosition() == -1) {
&& !editingCtx.isInMovePointMode()
&& !editingCtx.isInAddPointBeforeMode()
&& !editingCtx.isInAddPointAfterMode()) {
if (!overlapped) { if (!overlapped) {
selectPoint(point.x, point.y, true); selectPoint(point.x, point.y, true);
} }
@ -134,10 +131,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
@Override @Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode) { if (inMeasurementMode) {
if (!overlapped && !editingCtx.isInMovePointMode() if (!overlapped && getEditingCtx().getSelectedPointPosition() == -1 && editingCtx.getPointsCount() > 0) {
&& !editingCtx.isInAddPointBeforeMode()
&& !editingCtx.isInAddPointAfterMode()
&& editingCtx.getPointsCount() > 0) {
selectPoint(point.x, point.y, false); selectPoint(point.x, point.y, false);
if (editingCtx.getSelectedPointPosition() != -1) { if (editingCtx.getSelectedPointPosition() != -1) {
enterMovingPointMode(); enterMovingPointMode();
@ -151,7 +145,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
} }
void enterMovingPointMode() { void enterMovingPointMode() {
editingCtx.setInMovePointMode(true);
moveMapToPoint(editingCtx.getSelectedPointPosition()); moveMapToPoint(editingCtx.getSelectedPointPosition());
WptPt pt = editingCtx.removePoint(editingCtx.getSelectedPointPosition()); WptPt pt = editingCtx.removePoint(editingCtx.getSelectedPointPosition());
editingCtx.setOriginalPointToMove(pt); editingCtx.setOriginalPointToMove(pt);
@ -159,12 +152,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
} }
void enterAddingPointAfterMode() { void enterAddingPointAfterMode() {
editingCtx.setInAddPointAfterMode(true);
moveMapToPoint(editingCtx.getSelectedPointPosition() - 1); moveMapToPoint(editingCtx.getSelectedPointPosition() - 1);
} }
void enterAddingPointBeforeMode() { void enterAddingPointBeforeMode() {
editingCtx.setInAddPointBeforeMode(true);
moveMapToPoint(editingCtx.getSelectedPointPosition()); moveMapToPoint(editingCtx.getSelectedPointPosition());
} }
@ -217,9 +208,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
if (inMeasurementMode) { if (inMeasurementMode) {
lineAttrs.updatePaints(view, settings, tb); lineAttrs.updatePaints(view, settings, tb);
if (!editingCtx.isInMovePointMode() if (editingCtx.getSelectedPointPosition() == -1) {
&& !editingCtx.isInAddPointBeforeMode()
&& !editingCtx.isInAddPointAfterMode()) {
drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode()); drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode());
if (measureDistanceToCenterListener != null) { if (measureDistanceToCenterListener != null) {
float distance = 0; float distance = 0;
@ -311,9 +300,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
} }
} }
if (editingCtx.isInMovePointMode() if (editingCtx.getSelectedPointPosition() != -1) {
|| editingCtx.isInAddPointBeforeMode()
|| editingCtx.isInAddPointAfterMode()) {
int locX = tb.getCenterPixelX(); int locX = tb.getCenterPixelX();
int locY = tb.getCenterPixelY(); int locY = tb.getCenterPixelY();
canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint); canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint);
@ -322,7 +309,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
} }
void exitMovePointMode(boolean saveOriginalPoint) { void exitMovePointMode(boolean saveOriginalPoint) {
editingCtx.setInMovePointMode(false);
if (saveOriginalPoint) { if (saveOriginalPoint) {
WptPt pt = editingCtx.getOriginalPointToMove(); WptPt pt = editingCtx.getOriginalPointToMove();
editingCtx.addPoint(pt); editingCtx.addPoint(pt);
@ -332,14 +318,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size()); 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) { private void drawCenterIcon(Canvas canvas, RotatedTileBox tb, QuadPoint center, boolean nightMode) {
canvas.rotate(-tb.getRotate(), center.x, center.y); canvas.rotate(-tb.getRotate(), center.x, center.y);
if (nightMode) { if (nightMode) {