Add selected point menu

This commit is contained in:
PavelRatushny 2017-08-14 18:55:09 +03:00
parent b478b1c00e
commit 98cff00597
12 changed files with 907 additions and 91 deletions

View file

@ -52,7 +52,37 @@
android:layout_marginStart="16dp"
android:background="@null"
android:visibility="gone"
tools:src="@drawable/ic_action_measure_point"/>
tools:src="@drawable/ic_action_move_point"/>
<ImageView
android:id="@+id/add_point_after_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:background="@null"
android:visibility="gone"
tools:src="@drawable/ic_action_addpoint_above"/>
<ImageView
android:id="@+id/add_point_before_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:background="@null"
android:visibility="gone"
tools:src="@drawable/ic_action_addpoint_below"/>
<ImageView
android:id="@+id/up_down_button"
@ -107,6 +137,36 @@
android:text="@string/move_point"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/>
<TextView
android:id="@+id/add_point_after_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/add_point_after_icon"
android:layout_toRightOf="@id/add_point_after_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/add_point_before_icon"
android:layout_toRightOf="@id/add_point_before_icon"
android:text="@string/add_point_before"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/>
</RelativeLayout>
<View
@ -203,7 +263,7 @@
</LinearLayout>
<RelativeLayout
android:id="@+id/move_point_mode_controls"
android:id="@+id/selected_point_controls"
android:layout_width="0dp"
android:layout_height="52dp"
android:layout_weight="0.6"

View file

@ -52,7 +52,37 @@
android:layout_marginStart="16dp"
android:background="@null"
android:visibility="gone"
tools:src="@drawable/ic_action_measure_point"/>
tools:src="@drawable/ic_action_move_point"/>
<ImageView
android:id="@+id/add_point_after_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:background="@null"
android:visibility="gone"
tools:src="@drawable/ic_action_addpoint_above"/>
<ImageView
android:id="@+id/add_point_before_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:background="@null"
android:visibility="gone"
tools:src="@drawable/ic_action_addpoint_below"/>
<ImageView
android:id="@+id/up_down_button"
@ -107,6 +137,36 @@
android:text="@string/move_point"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/>
<TextView
android:id="@+id/add_point_after_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/add_point_after_icon"
android:layout_toRightOf="@id/add_point_after_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/add_point_before_icon"
android:layout_toRightOf="@id/add_point_before_icon"
android:text="@string/add_point_before"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:visibility="gone"/>
</RelativeLayout>
<View
@ -225,7 +285,7 @@
</LinearLayout>
<RelativeLayout
android:id="@+id/move_point_mode_controls"
android:id="@+id/selected_point_controls"
android:layout_width="match_parent"
android:layout_height="52dp"
android:visibility="gone">

View file

@ -191,7 +191,7 @@
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/snap_to_road_bottom_sheet_cancel_button_height"
android:layout_height="@dimen/measure_distance_bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView

View file

@ -0,0 +1,225 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<ScrollView
android:id="@+id/selected_point_options_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:paddingBottom="8dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:minHeight="56dp"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<ImageView
android:id="@+id/selected_point_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
tools:src="@drawable/ic_action_measure_point"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toEndOf="@id/selected_point_icon"
android:layout_toRightOf="@id/selected_point_icon"
android:gravity="center_vertical">
<TextView
android:id="@+id/selected_point_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
tools:text="Point 2"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/selected_point_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="386 m"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"
android:layout_marginBottom="8dp"/>
<RelativeLayout
android:id="@+id/move_point_row"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"
android:minHeight="48dp"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<ImageView
android:id="@+id/move_point_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
tools:src="@drawable/ic_action_move_point"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/move_point_icon"
android:layout_toRightOf="@id/move_point_icon"
android:maxLines="1"
android:text="@string/shared_string_move"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/delete_point_row"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"
android:minHeight="48dp"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<ImageView
android:id="@+id/delete_point_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
tools:src="@drawable/ic_action_remove_dark"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/delete_point_icon"
android:layout_toRightOf="@id/delete_point_icon"
android:maxLines="1"
android:text="@string/shared_string_delete"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</RelativeLayout>
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="64dp"
android:layout_marginStart="64dp"
android:layout_marginTop="7dp"
android:background="?attr/dashboard_divider"/>
<RelativeLayout
android:id="@+id/add_point_after_row"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"
android:minHeight="48dp"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<ImageView
android:id="@+id/add_point_after_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
tools:src="@drawable/ic_action_addpoint_above"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/add_point_after_icon"
android:layout_toRightOf="@id/add_point_after_icon"
android:maxLines="1"
android:text="@string/add_point_after"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/add_point_before_row"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"
android:minHeight="48dp"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<ImageView
android:id="@+id/add_point_before_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
tools:src="@drawable/ic_action_addpoint_below"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/add_point_before_icon"
android:layout_toRightOf="@id/add_point_before_icon"
android:maxLines="1"
android:text="@string/add_point_before"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/measure_distance_bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/cancel_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_close"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="14sp"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>

View file

@ -47,7 +47,7 @@
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/snap_to_road_bottom_sheet_cancel_button_height"
android:layout_height="@dimen/measure_distance_bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView

View file

@ -156,6 +156,6 @@
<dimen name="my_places_empty_state_text_button_padding_right">60dp</dimen>
<dimen name="my_places_empty_state_text_button_padding_top">64dp</dimen>
<dimen name="snap_to_road_bottom_sheet_cancel_button_height">48dp</dimen>
<dimen name="measure_distance_bottom_sheet_cancel_button_height">48dp</dimen>
<dimen name="landscape_bottom_sheet_dialog_fragment_width">360dp</dimen>
</resources>

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="add_point_before">Add point before</string>
<string name="add_point_after">Add point after</string>
<string name="shared_string_options">Options</string>
<string name="measurement_tool_snap_to_road_descr">OsmAnd will add additional points, depending on the navigation type.</string>
<string name="choose_navigation_type">Choose navigation type</string>

View file

@ -172,6 +172,27 @@ public class AndroidUtils {
return result;
}
public static int getNavBarHeight(Context ctx) {
if (!hasNavBar(ctx)) {
return 0;
}
boolean landscape = ctx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
boolean isSmartphone = ctx.getResources().getConfiguration().smallestScreenWidthDp < 600;
if (isSmartphone && landscape) {
return 0;
}
int id = ctx.getResources().getIdentifier(landscape ? "navigation_bar_height_landscape" : "navigation_bar_height", "dimen", "android");
if (id > 0) {
return ctx.getResources().getDimensionPixelSize(id);
}
return 0;
}
public static boolean hasNavBar(Context ctx) {
int id = ctx.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
return id > 0 && ctx.getResources().getBoolean(id);
}
public static int getScreenHeight(Activity activity) {
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

View file

@ -93,6 +93,10 @@ public class MeasurementToolFragment extends Fragment {
private NewGpxLine newGpxLine;
private boolean inMovePointMode;
private boolean inAddPointAfterMode;
private boolean inAddPointBeforeMode;
private int positionToAddPoint = -1;
public void setNewGpxLine(NewGpxLine newGpxLine) {
this.newGpxLine = newGpxLine;
@ -130,7 +134,13 @@ public class MeasurementToolFragment extends Fragment {
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_ruler, R.color.color_myloc_distance));
((ImageView) mainView.findViewById(R.id.move_point_icon))
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_measure_point, R.color.color_myloc_distance));
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_move_point, R.color.color_myloc_distance));
((ImageView) mainView.findViewById(R.id.add_point_after_icon))
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_addpoint_above, R.color.color_myloc_distance));
((ImageView) mainView.findViewById(R.id.add_point_before_icon))
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_addpoint_below, R.color.color_myloc_distance));
upDownBtn = (ImageView) mainView.findViewById(R.id.up_down_button);
upDownBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_arrow_up));
@ -138,7 +148,13 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.cancel_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cancelMovePointMode();
if (inMovePointMode) {
cancelMovePointMode();
} else if (inAddPointAfterMode) {
cancelAddPointAfterMode();
} else if (inAddPointBeforeMode) {
cancelAddPointBeforeMode();
}
}
});
@ -146,7 +162,7 @@ public class MeasurementToolFragment extends Fragment {
upDownRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!pointsListOpened && measurementLayer.getPointsCount() > 0 && !measurementLayer.isInMovePointMode()) {
if (!pointsListOpened && measurementLayer.getPointsCount() > 0 && !measurementLayer.isInMovePointMode() && !measurementLayer.isInAddPointAfterMode() && !measurementLayer.isInAddPointBeforeMode()) {
showPointsList();
} else {
hidePointsList();
@ -157,7 +173,13 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.apply_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applyMovePointMode();
if (inMovePointMode) {
applyMovePointMode();
} else if (inAddPointAfterMode) {
applyAddPointAfterMode();
} else if (inAddPointBeforeMode) {
applyAddPointBeforeMode();
}
}
});
@ -267,9 +289,14 @@ public class MeasurementToolFragment extends Fragment {
measurementLayer.setOnSingleTapListener(new MeasurementToolLayer.OnSingleTapListener() {
@Override
public void onSingleTap() {
public void onAddPoint() {
addPoint();
}
@Override
public void onSelectPoint() {
openSelectedPointMenu(mapActivity);
}
});
measurementLayer.setOnEnterMovePointModeListener(new MeasurementToolLayer.OnEnterMovePointModeListener() {
@ -362,6 +389,54 @@ public class MeasurementToolFragment extends Fragment {
return view;
}
private void openSelectedPointMenu(MapActivity mapActivity) {
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
SelectedPointMenuBottomSheetDialogFragment fragment = new SelectedPointMenuBottomSheetDialogFragment();
fragment.setSelectedPointOptionOnClickListener(new SelectedPointMenuBottomSheetDialogFragment.SelectedPointOptionOnClickListener() {
@Override
public void moveOnClick() {
if (measurementLayer != null) {
measurementLayer.enterMovingPointMode();
}
enterMovePointMode();
}
@Override
public void deleteOnClick() {
if (measurementLayer != null) {
int position = measurementLayer.getSelectedPointPos();
commandManager.execute(new RemovePointCommand(measurementLayer, position));
adapter.notifyDataSetChanged();
disable(redoBtn);
updateText();
saved = false;
hidePointsListIfNoPoints();
measurementLayer.clearSelection();
}
}
@Override
public void addPointAfterOnClick() {
if (measurementLayer != null) {
positionToAddPoint = measurementLayer.getSelectedPointPos() + 1;
measurementLayer.enterAddingPointAfterMode();
}
enterAddPointAfterMode();
}
@Override
public void addPointBeforeOnClick() {
if (measurementLayer != null) {
positionToAddPoint = measurementLayer.getSelectedPointPos();
measurementLayer.enterAddingPointBeforeMode();
}
enterAddPointBeforeMode();
}
});
fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointMenuBottomSheetDialogFragment.TAG);
}
private AlertDialog showAddSegmentDialog(final MapActivity mapActivity) {
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
@Override
@ -384,10 +459,37 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
measurementToolLayer.exitMovePointMode();
measurementToolLayer.clearSelection();
measurementToolLayer.refreshMap();
}
}
private void cancelAddPointAfterMode() {
if (inAddPointAfterMode) {
exitAddPointAfterMode();
}
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointAfterMode();
measurementToolLayer.clearSelection();
measurementToolLayer.refreshMap();
}
positionToAddPoint = -1;
}
private void cancelAddPointBeforeMode() {
if (inAddPointBeforeMode) {
exitAddPointBeforeMode();
}
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointBeforeMode();
measurementToolLayer.clearSelection();
measurementToolLayer.refreshMap();
}
positionToAddPoint = -1;
}
private void applyMovePointMode() {
if (inMovePointMode) {
exitMovePointMode();
@ -395,8 +497,8 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
WptPt newPoint = measurementLayer.getMovedPointToApply();
WptPt oldPoint = measurementLayer.getPointBeforeMovement();
int position = measurementLayer.getMovePointPosition();
WptPt oldPoint = measurementLayer.getSelectedCachedPoint();
int position = measurementLayer.getSelectedPointPos();
commandManager.execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
enable(undoBtn, upDownBtn);
disable(redoBtn);
@ -404,10 +506,39 @@ public class MeasurementToolFragment extends Fragment {
adapter.notifyDataSetChanged();
saved = false;
measurementLayer.exitMovePointMode();
measurementLayer.clearSelection();
measurementLayer.refreshMap();
}
}
private void applyAddPointAfterMode() {
if (inAddPointAfterMode) {
exitAddPointAfterMode();
}
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null && positionToAddPoint != -1) {
addPointToPosition(positionToAddPoint);
measurementLayer.exitAddPointAfterMode();
measurementLayer.clearSelection();
measurementLayer.refreshMap();
}
positionToAddPoint = -1;
}
private void applyAddPointBeforeMode() {
if (inAddPointBeforeMode) {
exitAddPointBeforeMode();
}
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null && positionToAddPoint != -1) {
addPointToPosition(positionToAddPoint);
measurementLayer.exitAddPointBeforeMode();
measurementLayer.clearSelection();
measurementLayer.refreshMap();
}
positionToAddPoint = -1;
}
private void enterMovePointMode() {
inMovePointMode = true;
mark(View.GONE,
@ -419,7 +550,7 @@ public class MeasurementToolFragment extends Fragment {
mark(View.VISIBLE,
R.id.move_point_icon,
R.id.move_point_text,
R.id.move_point_mode_controls);
R.id.selected_point_controls);
}
private void exitMovePointMode() {
@ -427,7 +558,63 @@ public class MeasurementToolFragment extends Fragment {
mark(View.GONE,
R.id.move_point_icon,
R.id.move_point_text,
R.id.move_point_mode_controls);
R.id.selected_point_controls);
mark(View.VISIBLE,
R.id.ruler_icon,
R.id.measurement_distance_text_view,
R.id.measurement_points_text_view,
R.id.up_down_button,
R.id.measure_mode_controls);
}
private void enterAddPointAfterMode() {
inAddPointAfterMode = true;
mark(View.GONE,
R.id.ruler_icon,
R.id.measurement_distance_text_view,
R.id.measurement_points_text_view,
R.id.up_down_button,
R.id.measure_mode_controls);
mark(View.VISIBLE,
R.id.add_point_after_icon,
R.id.add_point_after_text,
R.id.selected_point_controls);
}
private void enterAddPointBeforeMode() {
inAddPointBeforeMode = true;
mark(View.GONE,
R.id.ruler_icon,
R.id.measurement_distance_text_view,
R.id.measurement_points_text_view,
R.id.up_down_button,
R.id.measure_mode_controls);
mark(View.VISIBLE,
R.id.add_point_before_icon,
R.id.add_point_before_text,
R.id.selected_point_controls);
}
private void exitAddPointAfterMode() {
inAddPointAfterMode = false;
mark(View.GONE,
R.id.add_point_after_icon,
R.id.add_point_after_text,
R.id.selected_point_controls);
mark(View.VISIBLE,
R.id.ruler_icon,
R.id.measurement_distance_text_view,
R.id.measurement_points_text_view,
R.id.up_down_button,
R.id.measure_mode_controls);
}
private void exitAddPointBeforeMode() {
inAddPointBeforeMode = false;
mark(View.GONE,
R.id.add_point_before_icon,
R.id.add_point_before_text,
R.id.selected_point_controls);
mark(View.VISIBLE,
R.id.ruler_icon,
R.id.measurement_distance_text_view,
@ -460,6 +647,18 @@ public class MeasurementToolFragment extends Fragment {
}
}
private void addPointToPosition(int position) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
commandManager.execute(new AddPointCommand(measurementLayer, position));
enable(undoBtn, upDownBtn);
disable(redoBtn);
updateText();
adapter.notifyDataSetChanged();
saved = false;
}
}
private void showPointsList() {
pointsListOpened = true;
upDownBtn.setImageDrawable(downIcon);
@ -848,9 +1047,24 @@ public class MeasurementToolFragment extends Fragment {
if (inMovePointMode) {
exitMovePointMode();
}
if (inAddPointAfterMode) {
exitAddPointAfterMode();
}
if (inAddPointBeforeMode) {
exitAddPointBeforeMode();
}
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null && measurementToolLayer.isInMovePointMode()) {
measurementToolLayer.exitMovePointMode();
if (measurementToolLayer != null) {
measurementToolLayer.clearSelection();
if (measurementToolLayer.isInMovePointMode()) {
measurementToolLayer.exitMovePointMode();
}
if (measurementToolLayer.isInAddPointAfterMode()) {
measurementToolLayer.exitAddPointAfterMode();
}
if (measurementToolLayer.isInAddPointBeforeMode()) {
measurementToolLayer.exitAddPointBeforeMode();
}
}
if (newGpxLine != null) {
GPXFile gpx = newGpxLine.getGpxFile();

View file

@ -7,6 +7,7 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
@ -29,11 +30,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private OsmandMapTileView view;
private boolean inMeasurementMode;
private boolean inMovePointMode;
private boolean inAddPointAfterMode;
private boolean inAddPointBeforeMode;
private final LinkedList<WptPt> measurementPoints = new LinkedList<>();
private Bitmap centerIconDay;
private Bitmap centerIconNight;
private Bitmap pointIcon;
private Bitmap movePointIcon;
private Bitmap applyingPointIcon;
private Paint bitmapPaint;
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
private final Path path = new Path();
@ -43,8 +46,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private final TIntArrayList ty = new TIntArrayList();
private OnSingleTapListener singleTapListener;
private OnEnterMovePointModeListener enterMovePointModeListener;
private int movePointPos;
private WptPt pointBeforeMovement;
private int selectedPointPos = -1;
private WptPt selectedCachedPoint;
@Override
public void initLayer(OsmandMapTileView view) {
@ -53,7 +56,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
centerIconDay = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_day);
centerIconNight = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_night);
pointIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_pedestrian_location);
movePointIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_mapillary_location);
applyingPointIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_mapillary_location);
bitmapPaint = new Paint();
bitmapPaint.setAntiAlias(true);
@ -72,12 +75,12 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
this.enterMovePointModeListener = listener;
}
WptPt getPointBeforeMovement() {
return pointBeforeMovement;
WptPt getSelectedCachedPoint() {
return selectedCachedPoint;
}
int getMovePointPosition() {
return movePointPos;
int getSelectedPointPos() {
return selectedPointPos;
}
public boolean isInMeasurementMode() {
@ -88,6 +91,14 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
return inMovePointMode;
}
boolean isInAddPointAfterMode() {
return inAddPointAfterMode;
}
boolean isInAddPointBeforeMode() {
return inAddPointBeforeMode;
}
void setInMeasurementMode(boolean inMeasurementMode) {
this.inMeasurementMode = inMeasurementMode;
}
@ -113,47 +124,69 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode && !inMovePointMode && singleTapListener != null) {
singleTapListener.onSingleTap();
}
return false;
}
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (inMovePointMode || measurementPoints.size() == 0) {
return false;
}
double pressedPointLat = tileBox.getLatFromPixel(point.x, point.y);
double pressedPointLon = tileBox.getLonFromPixel(point.x, point.y);
getPointToMove(pressedPointLat, pressedPointLon);
if (pointBeforeMovement != null && movePointPos != -1) {
enterMovingPointMode();
if (inMeasurementMode && inMovePointMode && enterMovePointModeListener != null) {
enterMovePointModeListener.onEnterMovePointMode();
if (singleTapListener != null) {
if (inMeasurementMode && !inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode) {
selectPoint(point.x, point.y);
if (selectedPointPos != -1) {
singleTapListener.onSelectPoint();
} else {
singleTapListener.onAddPoint();
}
}
}
return false;
}
private void enterMovingPointMode() {
inMovePointMode = true;
moveMapToPoint(movePointPos);
public void clearSelection() {
selectedPointPos = -1;
selectedCachedPoint = null;
}
private void getPointToMove(double lat, double lon) {
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode) {
if (!inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode && measurementPoints.size() > 0) {
selectPoint(point.x, point.y);
if (selectedCachedPoint != null && selectedPointPos != -1) {
enterMovingPointMode();
if (inMeasurementMode && inMovePointMode && enterMovePointModeListener != null) {
enterMovePointModeListener.onEnterMovePointMode();
}
}
}
}
return false;
}
public void enterMovingPointMode() {
inMovePointMode = true;
moveMapToPoint(selectedPointPos);
}
public void enterAddingPointAfterMode() {
inAddPointAfterMode = true;
moveMapToPoint(selectedPointPos);
}
public void enterAddingPointBeforeMode() {
inAddPointBeforeMode = true;
moveMapToPoint(selectedPointPos);
}
private void selectPoint(double x, double y) {
clearSelection();
RotatedTileBox tb = view.getCurrentRotatedTileBox();
double lowestDistance = Double.MAX_VALUE;
double lowestDistance = AndroidUtils.dpToPx(view.getContext(), 10);
for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i);
if (tb.containsLatLon(pt.getLatitude(), pt.getLongitude())) {
double latDiff = pt.getLatitude() - lat;
double lonDiff = pt.getLongitude() - lon;
double distToPoint = Math.sqrt(Math.pow(latDiff, 2) + Math.pow(lonDiff, 2));
double xDiff = tb.getPixXFromLonNoRot(pt.getLongitude()) - x;
double yDiff = tb.getPixYFromLatNoRot(pt.getLatitude()) - y;
double distToPoint = Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
if (distToPoint < lowestDistance) {
lowestDistance = distToPoint;
pointBeforeMovement = new WptPt(pt);
movePointPos = i;
selectedCachedPoint = new WptPt(pt);
selectedPointPos = i;
}
}
}
@ -163,7 +196,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (inMeasurementMode) {
lineAttrs.updatePaints(view, settings, tb);
if (!inMovePointMode) {
if (!inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode) {
drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode());
}
@ -175,7 +208,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
WptPt pt = measurementPoints.get(i);
int locX;
int locY;
if (inMovePointMode && movePointPos == i) {
if (selectedPointPos == i && (inMovePointMode || inAddPointAfterMode || inAddPointBeforeMode)) {
locX = tb.getCenterPixelX();
locY = tb.getCenterPixelY();
} else {
@ -183,14 +216,56 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
locY = tb.getPixYFromLatNoRot(pt.lat);
}
if (i == 0) {
path.moveTo(locX, locY);
if (inAddPointAfterMode) {
int previousLocX = tb.getPixXFromLonNoRot(pt.lon);
int previousLocY = tb.getPixYFromLatNoRot(pt.lat);
path.moveTo(previousLocX, previousLocY);
tx.add(previousLocX);
ty.add(previousLocY);
path.lineTo(locX, locY);
tx.add(locX);
ty.add(locY);
} else if (inAddPointBeforeMode) {
path.moveTo(locX, locY);
tx.add(locX);
ty.add(locY);
int followingLocX = tb.getPixXFromLonNoRot(pt.lon);
int followingLocY = tb.getPixYFromLatNoRot(pt.lat);
path.lineTo(followingLocX, followingLocY);
tx.add(followingLocX);
ty.add(followingLocY);
} else {
path.moveTo(locX, locY);
tx.add(locX);
ty.add(locY);
}
} else {
path.lineTo(locX, locY);
if (inAddPointAfterMode) {
int previousLocX = tb.getPixXFromLonNoRot(pt.lon);
int previousLocY = tb.getPixYFromLatNoRot(pt.lat);
path.lineTo(previousLocX, previousLocY);
tx.add(previousLocX);
ty.add(previousLocY);
path.lineTo(locX, locY);
tx.add(locX);
ty.add(locY);
} else if (inAddPointBeforeMode) {
path.lineTo(locX, locY);
tx.add(locX);
ty.add(locY);
int followingLocX = tb.getPixXFromLonNoRot(pt.lon);
int followingLocY = tb.getPixYFromLatNoRot(pt.lat);
path.lineTo(followingLocX, followingLocY);
tx.add(followingLocX);
ty.add(followingLocY);
} else {
path.lineTo(locX, locY);
tx.add(locX);
ty.add(locY);
}
}
tx.add(locX);
ty.add(locY);
}
if (!inMovePointMode) {
if (!inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode) {
path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
tx.add(tb.getCenterPixelX());
ty.add(tb.getCenterPixelY());
@ -201,7 +276,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
WptPt pointToDrawOnTop = null;
for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i);
if (inMovePointMode && i == movePointPos) {
if (inMovePointMode && i == selectedPointPos) {
pointToDrawOnTop = pt;
} else {
if (tb.containsLatLon(pt.lat, pt.lon)) {
@ -211,10 +286,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
}
}
if (pointToDrawOnTop != null) {
if (inAddPointAfterMode || inAddPointBeforeMode || pointToDrawOnTop != null) {
int locX = tb.getCenterPixelX();
int locY = tb.getCenterPixelY();
canvas.drawBitmap(movePointIcon, locX - marginX, locY - marginY, bitmapPaint);
canvas.drawBitmap(applyingPointIcon, locX - marginX, locY - marginY, bitmapPaint);
}
}
}
@ -222,8 +297,14 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
void exitMovePointMode() {
inMovePointMode = false;
movePointPos = -1;
pointBeforeMovement = null;
}
public void exitAddPointAfterMode() {
inAddPointAfterMode = false;
}
public void exitAddPointBeforeMode() {
inAddPointBeforeMode = false;
}
private void drawCenterIcon(Canvas canvas, RotatedTileBox tb, QuadPoint center, boolean nightMode) {
@ -255,7 +336,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
WptPt getMovedPointToApply() {
RotatedTileBox tb = view.getCurrentRotatedTileBox();
LatLon latLon = tb.getCenterLatLon();
WptPt pt = measurementPoints.get(movePointPos);
WptPt pt = measurementPoints.get(selectedPointPos);
pt.lat = latLon.getLatitude();
pt.lon = latLon.getLongitude();
return pt;
@ -318,7 +399,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
interface OnSingleTapListener {
void onSingleTap();
void onAddPoint();
void onSelectPoint();
}
interface OnEnterMovePointModeListener {

View file

@ -0,0 +1,171 @@
package net.osmand.plus.measurementtool;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.util.MapUtils;
import java.util.List;
public class SelectedPointMenuBottomSheetDialogFragment extends BottomSheetDialogFragment{
public final static String TAG = "SelectedPointMenuBottomSheetDialogFragment";
private SelectedPointOptionOnClickListener listener;
public void setSelectedPointOptionOnClickListener(SelectedPointOptionOnClickListener listener) {
this.listener = listener;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity();
final IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
final boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_selected_menu_bottom_sheet_dialog, null);
if (portrait) {
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
}
((ImageView) mainView.findViewById(R.id.selected_point_icon)).setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_measure_point, R.color.color_myloc_distance));
((ImageView) mainView.findViewById(R.id.move_point_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_move_point));
((ImageView) mainView.findViewById(R.id.delete_point_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark));
((ImageView) mainView.findViewById(R.id.add_point_after_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_addpoint_above));
((ImageView) mainView.findViewById(R.id.add_point_before_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_addpoint_below));
mainView.findViewById(R.id.move_point_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.moveOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.delete_point_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.deleteOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.add_point_after_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.addPointAfterOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.add_point_before_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.addPointBeforeOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
List<WptPt> points = measurementLayer.getMeasurementPoints();
int pos = measurementLayer.getSelectedPointPos();
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " " + (pos + 1));
if (pos < 1) {
((TextView) mainView.findViewById(R.id.selected_point_distance)).setText(mapActivity.getString(R.string.shared_string_control_start));
} else {
float dist = 0;
for (int i = 1; i <= pos; i++) {
dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon, points.get(i).lat, points.get(i).lon);
}
((TextView) mainView.findViewById(R.id.selected_point_distance)).setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
}
final int height = AndroidUtils.getScreenHeight(getActivity());
final int statusbarHeight = AndroidUtils.getStatusBarHeight(getActivity());
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
final View scrollView = mainView.findViewById(R.id.selected_point_options_scroll_view);
int scrollViewHeight = scrollView.getHeight();
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.measure_distance_bottom_sheet_cancel_button_height);
int spaceForScrollView = height - statusbarHeight - AndroidUtils.getNavBarHeight(getActivity()) - dividerHeight - cancelButtonHeight;
if (scrollViewHeight > spaceForScrollView) {
scrollView.getLayoutParams().height = spaceForScrollView;
scrollView.requestLayout();
}
ViewTreeObserver obs = mainView.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
}
});
return mainView;
}
@Override
public void onStart() {
super.onStart();
if (!AndroidUiHelper.isOrientationPortrait(getActivity())) {
final Window window = getDialog().getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
window.setAttributes(params);
}
}
@Override
protected Drawable getContentIcon(@DrawableRes int id) {
return getIcon(id, getMyApplication().getSettings().isLightContent() ? R.color.on_map_icon_color : 0);
}
interface SelectedPointOptionOnClickListener {
void moveOnClick();
void deleteOnClick();
void addPointAfterOnClick();
void addPointBeforeOnClick();
}
}

View file

@ -64,8 +64,8 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
final View scrollView = view.findViewById(R.id.navigation_types_scroll_view);
int scrollViewHeight = scrollView.getHeight();
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.snap_to_road_bottom_sheet_cancel_button_height);
int spaceForScrollView = height - statusbarHeight - getNavBarHeight() - dividerHeight - cancelButtonHeight;
int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.measure_distance_bottom_sheet_cancel_button_height);
int spaceForScrollView = height - statusbarHeight - AndroidUtils.getNavBarHeight(getActivity()) - dividerHeight - cancelButtonHeight;
if (scrollViewHeight > spaceForScrollView) {
scrollView.getLayoutParams().height = spaceForScrollView;
scrollView.requestLayout();
@ -93,25 +93,4 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
window.setAttributes(params);
}
}
private int getNavBarHeight() {
if (!hasNavBar()) {
return 0;
}
boolean landscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
if (isSmartphone && landscape) {
return 0;
}
int id = getResources().getIdentifier(landscape ? "navigation_bar_height_landscape" : "navigation_bar_height", "dimen", "android");
if (id > 0) {
return getResources().getDimensionPixelSize(id);
}
return 0;
}
private boolean hasNavBar() {
int id = getResources().getIdentifier("config_showNavigationBar", "bool", "android");
return id > 0 && getResources().getBoolean(id);
}
}