Merge pull request #4256 from osmandapp/fab_waypoints

Fab waypoints
This commit is contained in:
Alexey 2017-08-02 11:55:21 +03:00 committed by GitHub
commit 10a99a3b4e
13 changed files with 437 additions and 17 deletions

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/add_gpx_waypoint_bottom_sheet"
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:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
android:clickable="true"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:src="@drawable/ic_action_photo_dark"/>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/add_gpx_waypoint_bottom_sheet_title"
style="@style/TextAppearance.ContextMenuTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="@string/add_gpx_waypoint_bottom_sheet_title"/>
<TextView
android:id="@+id/description"
style="@style/TextAppearance.ContextMenuSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
tools:text="Lat: 50.45375 Lon: 30.48693"/>
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/create_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/shared_string_create"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/cancel_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_gravity="center_vertical"
android:text="@string/shared_string_cancel"/>
</LinearLayout>

View file

@ -261,4 +261,11 @@
android:layout_gravity="bottom|left" android:layout_gravity="bottom|left"
tools:visibility="visible"/> tools:visibility="visible"/>
<include
layout="@layout/add_gpx_waypoint_bottom_sheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
tools:visibility="visible"/>
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/add_gpx_waypoint_bottom_sheet"
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:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
android:clickable="true"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:src="@drawable/ic_action_photo_dark"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/add_gpx_waypoint_bottom_sheet_title"
style="@style/TextAppearance.ContextMenuTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="@string/add_gpx_waypoint_bottom_sheet_title"/>
<TextView
android:id="@+id/description"
style="@style/TextAppearance.ContextMenuSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
tools:text="Lat: 50.45375\nLon: 30.48693"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp">
<Button
android:id="@+id/create_button"
style="@style/DialogActionButton"
android:layout_marginRight="8dp"
android:text="@string/shared_string_create"/>
<Button
android:id="@+id/cancel_button"
style="@style/DialogCancelButton"
android:text="@string/shared_string_cancel"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -223,6 +223,9 @@
<include layout="@layout/move_marker_bottom_sheet" <include layout="@layout/move_marker_bottom_sheet"
tools:visibility="gone"/> tools:visibility="gone"/>
<include layout="@layout/add_gpx_waypoint_bottom_sheet"
tools:visibility="gone"/>
<FrameLayout <FrameLayout
android:id="@+id/bottomFragmentContainer" android:id="@+id/bottomFragmentContainer"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/MainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ExpandableListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:divider="@null"
android:dividerHeight="0dp"
android:drawSelectorOnTop="false"
android:groupIndicator="@android:color/transparent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@drawable/ic_action_plus"
android:contentDescription="@string/quick_action_new_action"
app:backgroundTint="@color/dashboard_blue"/>
</RelativeLayout>

View file

@ -2660,4 +2660,6 @@
<string name="shared_string_action_name">Action name</string> <string name="shared_string_action_name">Action name</string>
<string name="mappilary_no_internet_desc">You need internet to view photos from Mapillary</string> <string name="mappilary_no_internet_desc">You need internet to view photos from Mapillary</string>
<string name="retry">Retry</string> <string name="retry">Retry</string>
<string name="add_gpx_waypoint_bottom_sheet_title">Add gpx waypoint</string>
<string name="shared_string_create">Create</string>
</resources> </resources>

View file

@ -102,6 +102,18 @@ public class GPXUtilities {
public float speed; public float speed;
} }
public static class NewGpxWaypoint {
private GPXFile gpx;
public NewGpxWaypoint(GPXFile gpx) {
this.gpx = gpx;
}
public GPXFile getGpx() {
return gpx;
}
}
public static class WptPt extends GPXExtensions implements LocationPoint { public static class WptPt extends GPXExtensions implements LocationPoint {
public boolean firstPoint = false; public boolean firstPoint = false;
public boolean lastPoint = false; public boolean lastPoint = false;

View file

@ -57,6 +57,8 @@ import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents; import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.NewGpxWaypoint;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
@ -916,6 +918,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} else if (toShow instanceof QuadRect) { } else if (toShow instanceof QuadRect) {
QuadRect qr = (QuadRect) toShow; QuadRect qr = (QuadRect) toShow;
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0); mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
} else if (toShow instanceof NewGpxWaypoint) {
NewGpxWaypoint newGpxWaypoint = (NewGpxWaypoint) toShow;
getMapLayers().getContextMenuLayer().enterAddGpxWaypointMode(newGpxWaypoint);
} else { } else {
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow); mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
} }

View file

@ -8,6 +8,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
@ -29,13 +30,16 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.NewGpxWaypoint;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
@ -89,6 +93,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
private Set<Integer> selectedGroups = new LinkedHashSet<>(); private Set<Integer> selectedGroups = new LinkedHashSet<>();
private ActionMode actionMode; private ActionMode actionMode;
private SearchView searchView; private SearchView searchView;
private FloatingActionButton fab;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -106,10 +111,30 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.favorites_tree, container, false); View view = inflater.inflate(R.layout.points_tree, container, false);
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list); ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
setHasOptionsMenu(true); setHasOptionsMenu(true);
fab = (FloatingActionButton) view.findViewById(R.id.fabButton);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final OsmandSettings settings = app.getSettings();
GPXFile gpx = getGpx();
Location location = app.getLocationProvider().getLastKnownLocation();
if (location != null) {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.context_menu_item_add_waypoint)),
false,
new NewGpxWaypoint(gpx));
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}
});
TextView tv = new TextView(getActivity()); TextView tv = new TextView(getActivity());
tv.setText(R.string.none_selected_gpx); tv.setText(R.string.none_selected_gpx);
tv.setTextSize(24); tv.setTextSize(24);

View file

@ -0,0 +1,102 @@
package net.osmand.plus.views;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.NewGpxWaypoint;
import net.osmand.plus.IconsCache;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
public class AddWaypointBottomSheetHelper {
private final View view;
private final TextView title;
private String titleText = "";
private final TextView description;
private final Context context;
private final MapContextMenu contextMenu;
private final ContextMenuLayer contextMenuLayer;
private boolean applyingPositionMode;
private NewGpxWaypoint newGpxWaypoint;
public AddWaypointBottomSheetHelper(final MapActivity activity, ContextMenuLayer ctxMenuLayer) {
this.contextMenuLayer = ctxMenuLayer;
view = activity.findViewById(R.id.add_gpx_waypoint_bottom_sheet);
title = (TextView) view.findViewById(R.id.add_gpx_waypoint_bottom_sheet_title);
description = (TextView) view.findViewById(R.id.description);
context = activity;
contextMenu = activity.getContextMenu();
ImageView icon = (ImageView) view.findViewById(R.id.icon);
IconsCache iconsCache = activity.getMyApplication().getIconsCache();
icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_photo_dark, R.color.marker_green));
view.findViewById(R.id.create_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
contextMenuLayer.createGpxWaypoint();
GPXFile gpx = newGpxWaypoint.getGpx();
LatLon latLon = contextMenu.getLatLon();
activity.getContextMenu().getWptPtPointEditor().add(gpx, latLon, titleText);
}
});
view.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hide();
contextMenuLayer.cancelAddGpxWaypoint();
}
});
}
public void onDraw(RotatedTileBox rt) {
PointF point = contextMenuLayer.getMovableCenterPoint(rt);
double lat = rt.getLatFromPixel(point.x, point.y);
double lon = rt.getLonFromPixel(point.x, point.y);
description.setText(PointDescription.getLocationName(context, lat, lon, true));
}
public void setTitle(String title) {
titleText = title;
this.title.setText(titleText);
}
public boolean isVisible() {
return view.getVisibility() == View.VISIBLE;
}
public void show(Drawable drawable, NewGpxWaypoint newGpxWaypoint) {
this.newGpxWaypoint = newGpxWaypoint;
exitApplyPositionMode();
view.setVisibility(View.VISIBLE);
((ImageView) view.findViewById(R.id.icon)).setImageDrawable(drawable);
}
public void hide() {
exitApplyPositionMode();
view.setVisibility(View.GONE);
}
public void enterApplyPositionMode() {
if (!applyingPositionMode) {
applyingPositionMode = true;
view.findViewById(R.id.create_button).setEnabled(false);
}
}
public void exitApplyPositionMode() {
if (applyingPositionMode) {
applyingPositionMode = false;
view.findViewById(R.id.create_button).setEnabled(true);
}
}
}

View file

@ -35,6 +35,7 @@ import net.osmand.osm.PoiFilter;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities.NewGpxWaypoint;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -75,12 +76,14 @@ public class ContextMenuLayer extends OsmandMapLayer {
private GestureDetector movementListener; private GestureDetector movementListener;
private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper; private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper;
private final AddWaypointBottomSheetHelper mAddWaypointBottomSheetHelper;
private boolean mInChangeMarkerPositionMode; private boolean mInChangeMarkerPositionMode;
private IContextMenuProvider selectedObjectContextMenuProvider; private IContextMenuProvider selectedObjectContextMenuProvider;
private boolean cancelApplyingNewMarkerPosition; private boolean cancelApplyingNewMarkerPosition;
private LatLon applyingMarkerLatLon; private LatLon applyingMarkerLatLon;
private boolean wasCollapseButtonVisible; private boolean wasCollapseButtonVisible;
private boolean mInGpxDetailsMode; private boolean mInGpxDetailsMode;
private boolean mInAddGpxWaypointMode;
private List<String> publicTransportTypes; private List<String> publicTransportTypes;
private Object selectedObject; private Object selectedObject;
@ -91,6 +94,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
multiSelectionMenu = menu.getMultiSelectionMenu(); multiSelectionMenu = menu.getMultiSelectionMenu();
movementListener = new GestureDetector(activity, new MenuLayerOnGestureListener()); movementListener = new GestureDetector(activity, new MenuLayerOnGestureListener());
mMoveMarkerBottomSheetHelper = new MoveMarkerBottomSheetHelper(activity, this); mMoveMarkerBottomSheetHelper = new MoveMarkerBottomSheetHelper(activity, this);
mAddWaypointBottomSheetHelper = new AddWaypointBottomSheetHelper(activity, this);
} }
@Override @Override
@ -194,7 +198,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
canvas.drawBitmap(pressedBitmap, x - pressedBitmap.getWidth() / 2, y - pressedBitmap.getHeight() / 2, paint); canvas.drawBitmap(pressedBitmap, x - pressedBitmap.getWidth() / 2, y - pressedBitmap.getHeight() / 2, paint);
} }
if (mapQuickActionLayer!= null && mapQuickActionLayer.isInChangeMarkerPositionMode()) if (mapQuickActionLayer!= null && mapQuickActionLayer.isInMovingMarkerMode())
return; return;
if (mInChangeMarkerPositionMode) { if (mInChangeMarkerPositionMode) {
@ -203,6 +207,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
contextMarker.draw(canvas); contextMarker.draw(canvas);
} }
mMoveMarkerBottomSheetHelper.onDraw(box); mMoveMarkerBottomSheetHelper.onDraw(box);
} else if (mInAddGpxWaypointMode) {
canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight());
contextMarker.draw(canvas);
mAddWaypointBottomSheetHelper.onDraw(box);
} else if (menu.isActive()) { } else if (menu.isActive()) {
LatLon latLon = menu.getLatLon(); LatLon latLon = menu.getLatLon();
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
@ -281,7 +289,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
public Object getMoveableObject() { public Object getMoveableObject() {
return mInChangeMarkerPositionMode ? menu.getObject() : null; return mInChangeMarkerPositionMode || mInAddGpxWaypointMode ? menu.getObject() : null;
} }
public boolean isInChangeMarkerPositionMode() { public boolean isInChangeMarkerPositionMode() {
@ -292,6 +300,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
return mInGpxDetailsMode; return mInGpxDetailsMode;
} }
public boolean isInAddGpxWaypointMode() {
return mInAddGpxWaypointMode;
}
public boolean isObjectMoveable(Object o) { public boolean isObjectMoveable(Object o) {
if (o == null) { if (o == null) {
return true; return true;
@ -313,7 +325,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
l.applyNewObjectPosition(o, position, callback); l.applyNewObjectPosition(o, position, callback);
} }
} }
} else if (mInChangeMarkerPositionMode) { } else if (mInChangeMarkerPositionMode || mInAddGpxWaypointMode) {
callback.onApplyMovedObject(true, null); callback.onApplyMovedObject(true, null);
} }
} }
@ -357,6 +369,45 @@ public class ContextMenuLayer extends OsmandMapLayer {
}); });
} }
public void createGpxWaypoint() {
if (!mInAddGpxWaypointMode) {
throw new IllegalStateException("Not in add gpx waypoint mode");
}
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
PointF newMarkerPosition = getMovableCenterPoint(tileBox);
final LatLon ll = tileBox.getLatLonFromPixel(newMarkerPosition.x, newMarkerPosition.y);
applyingMarkerLatLon = ll;
Object obj = getMoveableObject();
cancelApplyingNewMarkerPosition = false;
mAddWaypointBottomSheetHelper.enterApplyPositionMode();
applyMovedObject(obj, ll, new ApplyMovedObjectCallback() {
@Override
public void onApplyMovedObject(boolean success, @Nullable Object newObject) {
mAddWaypointBottomSheetHelper.exitApplyPositionMode();
if (success && !cancelApplyingNewMarkerPosition) {
mAddWaypointBottomSheetHelper.hide();
quitAddGpxWaipoint();
PointDescription pointDescription = null;
if (selectedObjectContextMenuProvider != null) {
pointDescription = selectedObjectContextMenuProvider.getObjectName(newObject);
}
menu.show(ll, pointDescription, newObject);
view.refreshMap();
}
selectedObjectContextMenuProvider = null;
applyingMarkerLatLon = null;
}
@Override
public boolean isCancelled() {
return cancelApplyingNewMarkerPosition;
}
});
}
public void enterGpxDetailsMode() { public void enterGpxDetailsMode() {
menu.updateMapCenter(null); menu.updateMapCenter(null);
menu.hide(); menu.hide();
@ -398,6 +449,39 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
} }
private void quitAddGpxWaipoint() {
mInAddGpxWaypointMode = false;
mark(View.VISIBLE, R.id.map_ruler_layout,
R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);
View collapseButton = activity.findViewById(R.id.map_collapse_button);
if (collapseButton != null && wasCollapseButtonVisible) {
collapseButton.setVisibility(View.VISIBLE);
}
}
public void enterAddGpxWaypointMode(NewGpxWaypoint newGpxWaypoint) {
menu.updateMapCenter(null);
menu.hide();
activity.disableDrawer();
mInAddGpxWaypointMode = true;
mAddWaypointBottomSheetHelper.show(menu.getLeftIcon(), newGpxWaypoint);
mark(View.INVISIBLE, R.id.map_ruler_layout,
R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);
View collapseButton = activity.findViewById(R.id.map_collapse_button);
if (collapseButton != null && collapseButton.getVisibility() == View.VISIBLE) {
wasCollapseButtonVisible = true;
collapseButton.setVisibility(View.INVISIBLE);
} else {
wasCollapseButtonVisible = false;
}
view.refreshMap();
}
private void enterMovingMode(RotatedTileBox tileBox) { private void enterMovingMode(RotatedTileBox tileBox) {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_SHORT); vibrator.vibrate(VIBRATE_SHORT);
@ -445,6 +529,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
applyingMarkerLatLon = null; applyingMarkerLatLon = null;
} }
public void cancelAddGpxWaypoint() {
cancelApplyingNewMarkerPosition = true;
quitAddGpxWaipoint();
activity.getContextMenu().show();
applyingMarkerLatLon = null;
}
public boolean showContextMenu(double latitude, double longitude, boolean showUnknownLocation) { public boolean showContextMenu(double latitude, double longitude, boolean showUnknownLocation) {
RotatedTileBox cp = activity.getMapView().getCurrentRotatedTileBox(); RotatedTileBox cp = activity.getMapView().getCurrentRotatedTileBox();
float x = cp.getPixXFromLatLon(latitude, longitude); float x = cp.getPixXFromLatLon(latitude, longitude);
@ -550,7 +641,14 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (latLon == null) { if (latLon == null) {
latLon = getLatLon(point, tileBox); latLon = getLatLon(point, tileBox);
} }
showContextMenu(latLon, pointDescription, selectedObj, provider); if (mInAddGpxWaypointMode) {
if (pointDescription != null) {
mAddWaypointBottomSheetHelper.setTitle(pointDescription.getName());
}
view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true);
} else {
showContextMenu(latLon, pointDescription, selectedObj, provider);
}
return true; return true;
} else if (selectedObjects.size() > 1) { } else if (selectedObjects.size() > 1) {
@ -592,7 +690,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
public boolean disableLongPressOnMap() { public boolean disableLongPressOnMap() {
if (mInChangeMarkerPositionMode || mInGpxDetailsMode) { if (mInChangeMarkerPositionMode || mInGpxDetailsMode || mInAddGpxWaypointMode) {
return true; return true;
} }
boolean res = false; boolean res = false;

View file

@ -712,7 +712,7 @@ public class MapControlsLayer extends OsmandMapLayer {
((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode); ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode);
updateMyLocation(rh, routeDialogOpened || trackDialogOpened); updateMyLocation(rh, routeDialogOpened || trackDialogOpened);
boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) boolean showButtons = (showRouteCalculationControls || !routeFollowingMode)
&& !isInChangeMarkerPositionMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode(); && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode();
//routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions); //routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions);
if (rh.isFollowingMode()) { if (rh.isFollowingMode()) {
routePlanningBtn.setIconResId(R.drawable.map_start_navigation); routePlanningBtn.setIconResId(R.drawable.map_start_navigation);
@ -1119,9 +1119,9 @@ public class MapControlsLayer extends OsmandMapLayer {
this.mapQuickActionLayer = mapQuickActionLayer; this.mapQuickActionLayer = mapQuickActionLayer;
} }
private boolean isInChangeMarkerPositionMode(){ private boolean isInMovingMarkerMode(){
return mapQuickActionLayer == null ? contextMenuLayer.isInChangeMarkerPositionMode() : return mapQuickActionLayer == null ? contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxWaypointMode():
mapQuickActionLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInChangeMarkerPositionMode(); mapQuickActionLayer.isInMovingMarkerMode() || contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxWaypointMode();
} }
private boolean isInGpxDetailsMode() { private boolean isInGpxDetailsMode() {

View file

@ -54,7 +54,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
private boolean wasCollapseButtonVisible; private boolean wasCollapseButtonVisible;
private int previousMapPosition; private int previousMapPosition;
private boolean inChangeMarkerPositionMode; private boolean inMovingMarkerMode;
private boolean isLayerOn; private boolean isLayerOn;
private boolean nightMode; private boolean nightMode;
@ -236,7 +236,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
double lon = rb.getLonFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); double lon = rb.getLonFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
view.setLatLon(lat, lon); view.setLatLon(lat, lon);
inChangeMarkerPositionMode = true; inMovingMarkerMode = true;
mark(View.INVISIBLE, R.id.map_ruler_layout, mark(View.INVISIBLE, R.id.map_ruler_layout,
R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);
@ -271,7 +271,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
} }
view.setMapPosition(previousMapPosition); view.setMapPosition(previousMapPosition);
inChangeMarkerPositionMode = false; inMovingMarkerMode = false;
mark(View.VISIBLE, R.id.map_ruler_layout, mark(View.VISIBLE, R.id.map_ruler_layout,
R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);
@ -293,7 +293,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
@Override @Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (isInChangeMarkerPositionMode() && !pressedQuickActionWidget(point.x, point.y)) { if (isInMovingMarkerMode() && !pressedQuickActionWidget(point.x, point.y)) {
setLayerState(false); setLayerState(false);
return true; return true;
} else } else
@ -307,7 +307,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) { public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) {
boolean nightMode = settings != null && settings.isNightMode(); boolean nightMode = settings != null && settings.isNightMode();
if (isInChangeMarkerPositionMode()) { if (isInMovingMarkerMode()) {
canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight()); canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight());
contextMarker.draw(canvas); contextMarker.draw(canvas);
} }
@ -356,8 +356,8 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2); return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
} }
public boolean isInChangeMarkerPositionMode() { public boolean isInMovingMarkerMode() {
return isLayerOn && inChangeMarkerPositionMode; return isLayerOn && inMovingMarkerMode;
} }
public boolean isLayerOn() { public boolean isLayerOn() {