Merge pull request #4352 from osmandapp/sasha_pasha_branch

Sasha pasha branch
This commit is contained in:
Alexey 2017-08-29 10:20:13 +03:00 committed by GitHub
commit 829b6c5bec
3 changed files with 167 additions and 29 deletions

View file

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="56dp"
android:descendantFocusability="blocksDescendants">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/bg_color">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/marker_reorder_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:padding="16dp"
android:tint="?attr/secondary_icon_color"
tools:src="@drawable/ic_action_reorder"/>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/marker_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_toEndOf="@id/marker_reorder_icon"
android:layout_toRightOf="@id/marker_reorder_icon"
tools:src="@drawable/ic_action_flag_dark"/>
<ImageButton
android:id="@+id/marker_options_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="16dp"
android:background="?attr/selectableItemBackground"
android:focusableInTouchMode="true"
tools:src="@drawable/ic_overflow_menu_white"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/marker_icon"
android:layout_toLeftOf="@id/marker_options_button"
android:layout_toRightOf="@+id/marker_icon"
android:layout_toStartOf="@id/marker_options_button"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/measure_point_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size"
tools:text="Van Gogh Museum"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/direction_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:src="@drawable/ic_direction_arrow"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/marker_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:maxLines="1"
android:textColor="@color/marker_blue"
android:textSize="@dimen/default_sub_text_size"
tools:text="213 m"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/point_icon_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="•"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/marker_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="Amsterdam Weekend"/>
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/points_divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:layout_toEndOf="@+id/marker_reorder_icon"
android:layout_toRightOf="@+id/marker_reorder_icon"
android:background="?attr/dashboard_divider"/>
</RelativeLayout>
</FrameLayout>

View file

@ -112,7 +112,8 @@ public class MeasurementToolFragment extends Fragment {
private enum SaveType {
ROUTE_POINT,
LINE
LINE,
SNAP_TO_ROAD
}
private void setEditingCtx(MeasurementEditingContext editingCtx) {
@ -459,12 +460,12 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onDestroyView() {
super.onDestroyView();
cancelModes();
exitMeasurementMode();
adapter.setAdapterListener(null);
if (pointsListOpened) {
hidePointsList();
}
closeModes();
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
layer.setOnSingleTapListener(null);
@ -837,7 +838,7 @@ public class MeasurementToolFragment extends Fragment {
int position = editingCtx.getSelectedPointPosition();
editingCtx.getCommandManager().execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
editingCtx.addPoint(newPoint);
measurementLayer.exitMovePointMode(false);
exitMovePointMode(false);
doAddOrMovePointCommonStuff();
measurementLayer.refreshMap();
}
@ -845,22 +846,28 @@ public class MeasurementToolFragment extends Fragment {
private void cancelMovePointMode() {
switchMovePointMode(false);
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
measurementToolLayer.exitMovePointMode(true);
measurementToolLayer.refreshMap();
exitMovePointMode(true);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.refreshMap();
}
}
private void closeModes() {
if (editingCtx.getOriginalPointToMove() != null) {
switchMovePointMode(false);
} else if (editingCtx.getSelectedPointPosition() != -1) {
switchAddPointBeforeAfterMode(false);
void exitMovePointMode(boolean saveOriginalPoint) {
if (saveOriginalPoint) {
WptPt pt = editingCtx.getOriginalPointToMove();
editingCtx.addPoint(pt);
}
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null && editingCtx.getOriginalPointToMove() != null) {
layer.exitMovePointMode(true);
editingCtx.setOriginalPointToMove(null);
editingCtx.setSelectedPointPosition(-1);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
}
private void cancelModes() {
if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode();
} else if (editingCtx.getSelectedPointPosition() != -1) {
cancelAddPointBeforeOrAfterMode();
}
}
@ -1074,7 +1081,7 @@ public class MeasurementToolFragment extends Fragment {
final SwitchCompat showOnMapToggle = (SwitchCompat) view.findViewById(R.id.toggle_show_on_map);
showOnMapToggle.setChecked(true);
final String suggestedName = new SimpleDateFormat("yyyy-M-dd_HH-mm_EEE", Locale.US).format(new Date());
final String suggestedName = new SimpleDateFormat("yyyy-MM-dd_HH-mm_EEE", Locale.US).format(new Date());
String displayedName = suggestedName;
File fout = new File(dir, suggestedName + GPX_SUFFIX);
int ind = 1;
@ -1156,7 +1163,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
protected void onPreExecute() {
closeModes();
cancelModes();
MapActivity activity = getMapActivity();
if (activity != null) {
progressDialog = new ProgressDialog(activity);
@ -1184,6 +1191,19 @@ public class MeasurementToolFragment extends Fragment {
Route rt = new Route();
gpx.routes.add(rt);
rt.points.addAll(points);
} else if (saveType == SaveType.SNAP_TO_ROAD) {
TrkSegment segmentToSave = new TrkSegment();
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
segmentToSave.points.addAll(before.points);
segmentToSave.points.addAll(after.points);
Track track = new Track();
track.segments.add(segmentToSave);
gpx.tracks.add(track);
Route rt = new Route();
rt.points.addAll(points);
gpx.routes.add(rt);
}
}
if (activity != null) {
@ -1390,7 +1410,7 @@ public class MeasurementToolFragment extends Fragment {
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final String name = new SimpleDateFormat("yyyy-M-dd_HH-mm_EEE", Locale.US).format(new Date());
final String name = new SimpleDateFormat("yyyy-MM-dd_HH-mm_EEE", Locale.US).format(new Date());
String fileName = name + GPX_SUFFIX;
File fout = new File(dir, fileName);
int ind = 1;
@ -1398,7 +1418,13 @@ public class MeasurementToolFragment extends Fragment {
fileName = name + "_" + (++ind) + GPX_SUFFIX;
fout = new File(dir, fileName);
}
saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), SaveType.LINE, true);
SaveType saveType;
if (editingCtx.isInSnapToRoadMode()) {
saveType = SaveType.SNAP_TO_ROAD;
} else {
saveType = SaveType.LINE;
}
saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType, true);
}
});
} else {

View file

@ -300,16 +300,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
}
void exitMovePointMode(boolean saveOriginalPoint) {
if (saveOriginalPoint) {
WptPt pt = editingCtx.getOriginalPointToMove();
editingCtx.addPoint(pt);
}
editingCtx.setOriginalPointToMove(null);
editingCtx.setSelectedPointPosition(-1);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
}
private void drawCenterIcon(Canvas canvas, RotatedTileBox tb, QuadPoint center, boolean nightMode) {
canvas.rotate(-tb.getRotate(), center.x, center.y);
if (nightMode) {