diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml
index 47dfee7ff8..7ad35e3364 100644
--- a/OsmAnd/res/layout/fragment_measurement_tool.xml
+++ b/OsmAnd/res/layout/fragment_measurement_tool.xml
@@ -22,7 +22,7 @@
android:paddingBottom="12dp"
android:paddingTop="12dp">
-
@@ -88,7 +88,7 @@
android:layout_height="wrap_content">
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
index 5320090d2b..5e1d1fbd87 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
@@ -9,6 +9,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -55,21 +56,59 @@ public class MeasurementToolFragment extends Fragment {
((ImageView) mainView.findViewById(R.id.ruler_icon))
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_ruler, R.color.color_myloc_distance));
- ((ImageView) mainView.findViewById(R.id.up_down_icon))
- .setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_arrow_up));
- ((ImageView) mainView.findViewById(R.id.previous_dot_icon))
- .setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_undo_dark));
- ((ImageView) mainView.findViewById(R.id.next_dot_icon))
- .setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_redo_dark));
+
+ final ImageButton upDownBtn = ((ImageButton) mainView.findViewById(R.id.up_down_button));
+ upDownBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_arrow_up));
+ upDownBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Toast.makeText(getActivity(), "Up / Down", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ final ImageButton undoBtn = ((ImageButton) mainView.findViewById(R.id.undo_point_button));
+ final ImageButton redoBtn = ((ImageButton) mainView.findViewById(R.id.redo_point_button));
+
+ undoBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_undo_dark));
+ undoBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (measurementLayer.undoPointOnClick()) {
+ enable(undoBtn);
+ } else {
+ disable(undoBtn);
+ }
+ enable(redoBtn);
+ updateText();
+ }
+ });
+
+ redoBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_redo_dark));
+ redoBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (measurementLayer.redoPointOnClick()) {
+ enable(redoBtn);
+ } else {
+ disable(redoBtn);
+ }
+ enable(undoBtn);
+ updateText();
+ }
+ });
mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
measurementLayer.addPointOnClick();
+ enable(undoBtn);
+ disable(redoBtn);
updateText();
}
});
+ disable(undoBtn, redoBtn);
+
enterMeasurementMode();
if (portrait) {
@@ -99,6 +138,7 @@ public class MeasurementToolFragment extends Fragment {
return true;
case R.id.action_clear_all:
measurementLayer.clearPoints();
+ disable(undoBtn, redoBtn);
updateText();
return true;
}
@@ -132,6 +172,20 @@ public class MeasurementToolFragment extends Fragment {
return null;
}
+ private void enable(View... views) {
+ for (View view : views) {
+ view.setEnabled(true);
+ view.setAlpha(1);
+ }
+ }
+
+ private void disable(View... views) {
+ for (View view : views) {
+ view.setEnabled(false);
+ view.setAlpha(.5f);
+ }
+ }
+
private void updateText() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
index ee7924a484..a0b9af50dc 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
@@ -25,6 +25,7 @@ public class MeasurementToolLayer extends OsmandMapLayer {
private OsmandMapTileView view;
private boolean inMeasurementMode;
private LinkedList measurementPoints = new LinkedList<>();
+ private LinkedList cacheMeasurementPoints;
private Bitmap centerIconDay;
private Bitmap centerIconNight;
private Bitmap pointIcon;
@@ -78,6 +79,7 @@ public class MeasurementToolLayer extends OsmandMapLayer {
void clearPoints() {
measurementPoints.clear();
+ cacheMeasurementPoints.clear();
view.refreshMap();
}
@@ -141,9 +143,24 @@ public class MeasurementToolLayer extends OsmandMapLayer {
} else {
measurementPoints.add(pt);
}
+ cacheMeasurementPoints = new LinkedList<>(measurementPoints);
view.refreshMap();
}
+ boolean undoPointOnClick() {
+ measurementPoints.remove(measurementPoints.size() - 1);
+ WptPt pt = measurementPoints.get(measurementPoints.size() - 1);
+ view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true);
+ return measurementPoints.size() > 0;
+ }
+
+ boolean redoPointOnClick() {
+ WptPt pt = cacheMeasurementPoints.get(measurementPoints.size());
+ measurementPoints.add(pt);
+ view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true);
+ return cacheMeasurementPoints.size() > measurementPoints.size();
+ }
+
@Override
public void destroyLayer() {