diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml
index 3a9674c81f..fa2d1d9cdd 100644
--- a/OsmAnd/res/layout/map_context_menu_fragment.xml
+++ b/OsmAnd/res/layout/map_context_menu_fragment.xml
@@ -346,22 +346,29 @@
-
+ android:foreground="@drawable/bg_contextmenu_shadow"
+ android:foregroundGravity="top|fill_horizontal">
-
+ android:layout_height="match_parent"
+ android:background="?attr/ctx_menu_info_view_bg">
-
+
-
+
+
+
+
diff --git a/OsmAnd/res/layout/point_editor_fragment.xml b/OsmAnd/res/layout/point_editor_fragment.xml
index 39d511e1ce..953885ac12 100644
--- a/OsmAnd/res/layout/point_editor_fragment.xml
+++ b/OsmAnd/res/layout/point_editor_fragment.xml
@@ -24,6 +24,14 @@
android:background="@android:color/transparent"
android:src="@drawable/ic_action_delete_dark"/>
+
+
+
callbackWithObject) {
+ OsmandApplication app = (OsmandApplication) activity.getApplication();
+ final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
+ final List list = getSortedGPXFilenames(dir, false);
+ if (!list.isEmpty() || showCurrentGpx) {
+ if (showCurrentGpx) {
+ list.add(0, activity.getString(R.string.shared_string_currently_recording_track));
+ }
+
+ final ContextMenuAdapter adapter = createGpxContextMenuAdapter(activity, list, null, false,
+ showCurrentGpx);
+ return createDialog(activity, showCurrentGpx, false, callbackWithObject, list, adapter);
+ }
+ return null;
+ }
+
private static ContextMenuAdapter createGpxContextMenuAdapter(Activity activity, List allGpxList,
List selectedGpxList, boolean multipleChoice,
boolean showCurrentTrack) {
@@ -342,7 +361,14 @@ public class GpxUiHelper {
if (showCurrentGpx && position == 0) {
callbackWithObject.processResult(null);
} else {
- loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, list.get(position));
+ String fileName = list.get(position);
+ SelectedGpxFile selectedGpxFile =
+ app.getSelectedGpxHelper().getSelectedFileByName(fileName);
+ if (selectedGpxFile != null) {
+ callbackWithObject.processResult(new GPXFile[]{selectedGpxFile.getGpxFile()});
+ } else {
+ loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
+ }
}
}
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java
index cea39eab00..78970ed346 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java
@@ -1,16 +1,21 @@
package net.osmand.plus.mapcontextmenu;
import android.support.v4.app.Fragment;
+import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.LinearLayout;
+import net.osmand.CallbackWithObject;
+import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ContextMenuAdapter;
+import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.MenuType;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
@@ -24,7 +29,9 @@ import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.util.MapUtils;
+import java.io.File;
import java.lang.ref.WeakReference;
+import java.util.List;
public class MapContextMenu extends MenuTitleController {
@@ -398,7 +405,15 @@ public class MapContextMenu extends MenuTitleController {
if (pointDescription.isWpt() || title.equals(addressNotKnownStr)) {
title = "";
}
- getWptPtPointEditor().add(latLon, title);
+
+ final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
+ final List list = GpxUiHelper.getSortedGPXFilenames(dir, false);
+ if (list.isEmpty()) {
+ GPXFile gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
+ getWptPtPointEditor().add(gpxFile, latLon, title);
+ } else {
+ addNewWptToGPXFile(title);
+ }
}
}
@@ -408,6 +423,24 @@ public class MapContextMenu extends MenuTitleController {
}
}
+ public AlertDialog addNewWptToGPXFile(final String title) {
+ CallbackWithObject callbackWithObject = new CallbackWithObject() {
+ @Override
+ public boolean processResult(GPXFile[] result) {
+ GPXFile gpxFile;
+ if (result != null && result.length > 0) {
+ gpxFile = result[0];
+ } else {
+ gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
+ }
+ getWptPtPointEditor().add(gpxFile, latLon, title);
+ return true;
+ }
+ };
+
+ return GpxUiHelper.selectSingleGPXFile(mapActivity, true, callbackWithObject);
+ }
+
public void setBaseFragmentVisibility(boolean visible) {
WeakReference fragmentRef = findMenuFragment();
if (fragmentRef != null) {
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
index c2c792d116..a315f64db5 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
@@ -47,7 +47,6 @@ import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
-import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_BOTTOM_DP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
@@ -685,7 +684,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight + dy;
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
- menuFullHeightMax = menuTitleHeight + (menuBottomViewHeight > 0 ? menuBottomViewHeight : -dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
+ menuFullHeightMax = menuTitleHeight + menuBottomViewHeight;
if (origMarkerX == 0 && origMarkerY == 0) {
origMarkerX = view.getWidth() / 2;
@@ -802,7 +801,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
int posY = 0;
switch (destinationState) {
case MenuState.HEADER_ONLY:
- posY = viewHeight - (menuTitleHeight - dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
+ posY = viewHeight - menuTitleHeight;
break;
case MenuState.HALF_SCREEN:
posY = viewHeight - menuFullHeightMax;
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
index 7c0501664f..c046a6b6f2 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java
@@ -31,7 +31,6 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class MenuBuilder {
public static final float SHADOW_HEIGHT_TOP_DP = 16f;
- public static final float SHADOW_HEIGHT_BOTTOM_DP = 6f;
protected OsmandApplication app;
protected LinkedList plainMenuItems;
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
index 18f3483551..6feff03e63 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
@@ -65,7 +65,7 @@ public abstract class PointEditorFragment extends Fragment {
}
});
- Button saveButton = (Button)toolbar.findViewById(R.id.save_button);
+ Button saveButton = (Button) toolbar.findViewById(R.id.save_button);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -73,7 +73,15 @@ public abstract class PointEditorFragment extends Fragment {
}
});
- ImageButton deleteButton = (ImageButton)toolbar.findViewById(R.id.delete_button);
+ ImageButton okButton = (ImageButton) toolbar.findViewById(R.id.ok_button);
+ okButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ savePressed();
+ }
+ });
+
+ ImageButton deleteButton = (ImageButton) toolbar.findViewById(R.id.delete_button);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -82,6 +90,7 @@ public abstract class PointEditorFragment extends Fragment {
});
if (getEditor().isNew()) {
+ okButton.setVisibility(View.GONE);
deleteButton.setVisibility(View.GONE);
} else {
saveButton.setVisibility(View.GONE);
@@ -152,11 +161,10 @@ public abstract class PointEditorFragment extends Fragment {
@Override
public void onDestroyView() {
- if (!wasSaved() && !getEditor().isNew()) {
- save(false);
- }
+// if (!wasSaved() && !getEditor().isNew()) {
+// save(false);
+// }
super.onDestroyView();
-
getActivity().findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE);
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java
index 274ce13c11..1e825b7d7f 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java
@@ -1,13 +1,16 @@
package net.osmand.plus.mapcontextmenu.editors;
import net.osmand.data.LatLon;
-import net.osmand.data.PointDescription;
+import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
+import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.activities.MapActivity;
public class WptPtEditor extends PointEditor {
+ private GPXFile gpxFile;
private WptPt wpt;
+ private boolean gpxSelected;
public static final String TAG = "WptPtEditorFragment";
@@ -20,15 +23,29 @@ public class WptPtEditor extends PointEditor {
return TAG;
}
+ public GPXFile getGpxFile() {
+ return gpxFile;
+ }
+
+ public boolean isGpxSelected() {
+ return gpxSelected;
+ }
+
public WptPt getWptPt() {
return wpt;
}
- public void add(LatLon latLon, String title) {
+ public void add(GPXFile gpxFile, LatLon latLon, String title) {
if (latLon == null) {
return;
}
isNew = true;
+
+ this.gpxFile = gpxFile;
+ SelectedGpxFile selectedGpxFile =
+ mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
+ gpxSelected = selectedGpxFile != null;
+
wpt = new WptPt(latLon.getLatitude(), latLon.getLongitude(),
System.currentTimeMillis(), Double.NaN, 0, Double.NaN);
wpt.name = title;
@@ -40,6 +57,12 @@ public class WptPtEditor extends PointEditor {
return;
}
isNew = false;
+ SelectedGpxFile selectedGpxFile =
+ mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFile(wpt);
+ if (selectedGpxFile != null) {
+ gpxSelected = true;
+ gpxFile = selectedGpxFile.getGpxFile();
+ }
this.wpt = wpt;
WptPtEditorFragment.showInstance(mapActivity);
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
index 20bf7bb925..d8afdfcf07 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
@@ -13,7 +13,6 @@ import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
-import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@@ -29,7 +28,6 @@ public class WptPtEditorFragment extends PointEditorFragment {
private WptPt wpt;
private SavingTrackHelper savingTrackHelper;
private GpxSelectionHelper selectedGpxHelper;
- private SelectedGpxFile selectedGpxFile;
private boolean saved;
private int color;
@@ -47,7 +45,6 @@ public class WptPtEditorFragment extends PointEditorFragment {
super.onCreate(savedInstanceState);
wpt = editor.getWptPt();
- selectedGpxFile = selectedGpxHelper.getSelectedGPXFile(wpt);
int defaultColor = getResources().getColor(R.color.gpx_color_point);
color = wpt.getColor(defaultColor);
}
@@ -104,12 +101,6 @@ public class WptPtEditorFragment extends PointEditorFragment {
menu.update(latLon, wpt.getPointDescription(getMapActivity()), wpt);
}
- if (editor.isNew() && selectedGpxFile == null) {
- selectedGpxHelper.setGpxFileToDisplay(savingTrackHelper.getCurrentGpx());
- } else if (selectedGpxFile != null) {
- selectedGpxHelper.setGpxFileToDisplay(selectedGpxFile.getGpxFile());
- }
-
saved = true;
}
@@ -120,22 +111,37 @@ public class WptPtEditorFragment extends PointEditorFragment {
if (color != 0) {
wpt.setColor(color);
}
- wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), description, name, category, color);
- }
- private boolean isCurrentTrack() {
- return selectedGpxFile != null && selectedGpxFile.isShowCurrentTrack();
+ GPXFile gpx = editor.getGpxFile();
+ if (gpx != null) {
+ if (gpx.showCurrentTrack) {
+ wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(),
+ System.currentTimeMillis(), description, name, category, color);
+ if (!editor.isGpxSelected()) {
+ selectedGpxHelper.setGpxFileToDisplay(gpx);
+ }
+ } else {
+ wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(),
+ System.currentTimeMillis(), description, name, category, color);
+ new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute();
+ }
+ }
}
private void doUpdateWpt(String name, String category, String description) {
- if (isCurrentTrack()) {
- savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(),
- System.currentTimeMillis(), description, name, category, color);
- } else if (selectedGpxFile != null) {
- GPXFile gpx = selectedGpxFile.getModifiableGpxFile();
- gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(),
- System.currentTimeMillis(), description, name, category, color);
- new SaveGpxAsyncTask(getMyApplication(), gpx).execute();
+ GPXFile gpx = editor.getGpxFile();
+ if (gpx != null) {
+ if (gpx.showCurrentTrack) {
+ savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(),
+ System.currentTimeMillis(), description, name, category, color);
+ if (!editor.isGpxSelected()) {
+ selectedGpxHelper.setGpxFileToDisplay(gpx);
+ }
+ } else {
+ gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(),
+ System.currentTimeMillis(), description, name, category, color);
+ new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute();
+ }
}
}
@@ -148,12 +154,14 @@ public class WptPtEditorFragment extends PointEditorFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
- if (isCurrentTrack()) {
- savingTrackHelper.deletePointData(wpt);
- } else {
- GPXFile gpx = selectedGpxFile.getModifiableGpxFile();
- gpx.deleteWptPt(wpt);
- new SaveGpxAsyncTask(getMyApplication(), gpx).execute();
+ GPXFile gpx = editor.getGpxFile();
+ if (gpx != null) {
+ if (gpx.showCurrentTrack) {
+ savingTrackHelper.deletePointData(wpt);
+ } else {
+ gpx.deleteWptPt(wpt);
+ new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute();
+ }
}
saved = true;
@@ -212,13 +220,14 @@ public class WptPtEditorFragment extends PointEditorFragment {
}
private static class SaveGpxAsyncTask extends AsyncTask {
-
private final OsmandApplication app;
private final GPXFile gpx;
+ private final boolean gpxSelected;
- public SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx) {
+ public SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx, boolean gpxSelected) {
this.app = app;
this.gpx = gpx;
+ this.gpxSelected = gpxSelected;
}
@Override
@@ -226,5 +235,12 @@ public class WptPtEditorFragment extends PointEditorFragment {
GPXUtilities.writeGpxFile(new File(gpx.path), gpx, app);
return null;
}
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ if (!gpxSelected) {
+ app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
+ }
+ }
}
}