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"/>
<TextView
android:id="@+id/add_point_after_text"
android:id="@+id/add_point_before_after_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
@ -131,22 +131,7 @@
android:layout_marginStart="8dp"
android:layout_toEndOf="@id/main_icon"
android:layout_toRightOf="@id/main_icon"
android: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"
tools:text="@string/add_point_before"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/>
</RelativeLayout>

View file

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

View file

@ -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;
}

View file

@ -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);

View file

@ -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) {