Merge pull request #5610 from osmandapp/CoordinateInputImprovements
Coordinate input with gpx points
This commit is contained in:
commit
19ae2a001c
7 changed files with 242 additions and 108 deletions
|
@ -849,6 +849,11 @@ public class GPXUtilities {
|
|||
modifiedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void addPoint(int position, WptPt point) {
|
||||
points.add(position, point);
|
||||
modifiedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
void addPoints(Collection<? extends WptPt> collection) {
|
||||
points.addAll(collection);
|
||||
modifiedTime = System.currentTimeMillis();
|
||||
|
@ -1041,9 +1046,7 @@ public class GPXUtilities {
|
|||
}
|
||||
|
||||
Route lastRoute = routes.get(routes.size() - 1);
|
||||
|
||||
lastRoute.points.addAll(points);
|
||||
|
||||
modifiedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
@ -1052,16 +1055,13 @@ public class GPXUtilities {
|
|||
routes.add(new Route());
|
||||
Route currentRoute = routes.get(routes.size() - 1);
|
||||
currentRoute.points.addAll(points);
|
||||
|
||||
modifiedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void updateWptPt(WptPt pt, double lat, double lon, long time, String description, String name, String category, int color) {
|
||||
int index = points.indexOf(pt);
|
||||
|
||||
double latAdjusted = Double.parseDouble(latLonFormat.format(lat));
|
||||
double lonAdjusted = Double.parseDouble(latLonFormat.format(lon));
|
||||
|
||||
pt.lat = latAdjusted;
|
||||
pt.lon = lonAdjusted;
|
||||
pt.time = time;
|
||||
|
|
|
@ -31,6 +31,7 @@ import net.osmand.plus.OsmAndAppCustomization;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||
import net.osmand.plus.measurementtool.NewGpxData;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.myplaces.SplitSegmentDialogFragment;
|
||||
|
@ -407,6 +408,8 @@ public class TrackActivity extends TabActivity {
|
|||
trackBitmapDrawer.setDrawEnabled(trackPointFragment.isUpdateEnable());
|
||||
}
|
||||
trackPointFragment.setContent();
|
||||
} else if (gpxFile != null && frag instanceof CoordinateInputDialogFragment) {
|
||||
((CoordinateInputDialogFragment) frag).setGpx(gpxFile);
|
||||
}
|
||||
}
|
||||
OsmandFragmentPagerAdapter pagerAdapter = (OsmandFragmentPagerAdapter) viewPager.getAdapter();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
|
@ -8,6 +9,7 @@ import android.content.Intent;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -51,15 +53,19 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
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.MapMarkersHelper;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener;
|
||||
|
@ -68,9 +74,11 @@ import net.osmand.plus.mapmarkers.CoordinateInputFormats.DMS;
|
|||
import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
|
||||
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
|
||||
import net.osmand.plus.widgets.EditTextEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.LocationParser;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.ArrayList;
|
||||
|
@ -79,16 +87,17 @@ import java.util.Locale;
|
|||
|
||||
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT;
|
||||
|
||||
public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener {
|
||||
|
||||
public static final String TAG = "CoordinateInputDialogFragment";
|
||||
public static final String ADDED_MARKERS_NUMBER_KEY = "added_markers_number_key";
|
||||
public static final String ADDED_POINTS_NUMBER_KEY = "added_points_number_key";
|
||||
|
||||
private final List<MapMarker> mapMarkers = new ArrayList<>();
|
||||
private MapMarker selectedMarker;
|
||||
private OnMapMarkersSavedListener listener;
|
||||
private GPXFile newGpxFile;
|
||||
private OnPointsSavedListener listener;
|
||||
private WptPt selectedWpt;
|
||||
private SavingTrackHelper savingTrackHelper;
|
||||
private GpxSelectionHelper selectedGpxHelper;
|
||||
|
||||
private View mainView;
|
||||
private final List<EditTextEx> editTexts = new ArrayList<>();
|
||||
|
@ -109,22 +118,87 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
private boolean compassUpdateAllowed = true;
|
||||
|
||||
|
||||
public void setListener(OnMapMarkersSavedListener listener) {
|
||||
public void setListener(OnPointsSavedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lightTheme = getMyApplication().getSettings().isLightContent();
|
||||
OsmandApplication app = getMyApplication();
|
||||
|
||||
lightTheme = app.getSettings().isLightContent();
|
||||
setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
|
||||
newGpxFile = new GPXFile();
|
||||
savingTrackHelper = app.getSavingTrackHelper();
|
||||
selectedGpxHelper = app.getSelectedGpxHelper();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GPXFile getGpx() {
|
||||
TrackActivity activity = getTrackActivity();
|
||||
if (activity != null) {
|
||||
GPXFile gpx = activity.getGpx();
|
||||
return gpx != null ? gpx : newGpxFile;
|
||||
} else {
|
||||
return newGpxFile;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TrackActivity getTrackActivity() {
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof TrackActivity) {
|
||||
return (TrackActivity) getActivity();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
|
||||
MapMarkersHelper.MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
helper.runSynchronization(group);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addWpt(GPXFile gpx, String description, String name, String category, int color, double lat, double lon) {
|
||||
if (gpx != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
savingTrackHelper.insertPointData(lat, lon, System.currentTimeMillis(), description, name, category, color);
|
||||
selectedGpxHelper.setGpxFileToDisplay(gpx);
|
||||
} else {
|
||||
gpx.addWptPt(lat, lon, System.currentTimeMillis(), description, name, category, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateWpt(GPXFile gpx, String description, String name, String category, int color, double lat, double lon) {
|
||||
if (gpx != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
savingTrackHelper.updatePointData(selectedWpt, lat, lon, System.currentTimeMillis(), description, name, category, color);
|
||||
selectedGpxHelper.setGpxFileToDisplay(gpx);
|
||||
} else {
|
||||
gpx.updateWptPt(selectedWpt, lat, lon, System.currentTimeMillis(), description, name, category, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void quit() {
|
||||
if (!mapMarkers.isEmpty() && hasUnsavedChanges) {
|
||||
showSaveDialog();
|
||||
if (getGpx().hasWptPt() && hasUnsavedChanges) {
|
||||
if (Algorithms.isEmpty(getGpx().path)) {
|
||||
showSaveDialog();
|
||||
} else {
|
||||
GPXFile gpx = getGpx();
|
||||
new SaveGpxAsyncTask(getMyApplication(), gpx,null, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
syncGpx(gpx);
|
||||
if (listener != null) {
|
||||
listener.onPointsSaved();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
} else {
|
||||
saveMarkers();
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +207,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
hasUnsavedChanges = false;
|
||||
SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size());
|
||||
args.putInt(ADDED_POINTS_NUMBER_KEY, getGpx().getPointsSize());
|
||||
args.putBoolean(SaveAsTrackBottomSheetDialogFragment.COORDINATE_INPUT_MODE_KEY, true);
|
||||
fragment.setArguments(args);
|
||||
fragment.setListener(createSaveAsTrackFragmentListener());
|
||||
fragment.show(getChildFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);
|
||||
|
@ -163,6 +238,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
return dialog;
|
||||
}
|
||||
|
||||
public void setGpx(GPXFile gpx) {
|
||||
this.newGpxFile = gpx;
|
||||
adapter.setGpx(gpx);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -179,8 +259,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
backBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
saveMarkers();
|
||||
dismiss();
|
||||
quit();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -293,7 +372,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
}
|
||||
}
|
||||
});
|
||||
adapter = new CoordinateInputAdapter(getMyApplication(), mapMarkers);
|
||||
adapter = new CoordinateInputAdapter(getMyApplication(), getGpx());
|
||||
final RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
@ -343,7 +422,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
addButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addMapMarker();
|
||||
addWptPt();
|
||||
hasUnsavedChanges = true;
|
||||
}
|
||||
});
|
||||
|
@ -391,8 +470,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
case R.id.keyboard_item_next_field:
|
||||
switchEditText(focusedEditText.getId(), true);
|
||||
break;
|
||||
case R.id.keyboard_item_hide:
|
||||
changeOsmandKeyboardVisibility(false);
|
||||
case R.id.keyboard_item_hide:
|
||||
changeOsmandKeyboardVisibility(false);
|
||||
break;
|
||||
default:
|
||||
focusedEditText.setText(focusedEditText.getText().toString() + getItemObjectById(id));
|
||||
|
@ -628,13 +707,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
v.setBackgroundColor(getResolvedColor(colorResId));
|
||||
}
|
||||
|
||||
private void saveMarkers() {
|
||||
getMyApplication().getMapMarkersHelper().addMarkers(mapMarkers);
|
||||
if (listener != null) {
|
||||
listener.onMapMarkersSaved();
|
||||
}
|
||||
}
|
||||
|
||||
private void addEditTexts(@IdRes int... ids) {
|
||||
editTexts.clear();
|
||||
for (int id : ids) {
|
||||
|
@ -775,7 +847,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
if (i == EditorInfo.IME_ACTION_NEXT) {
|
||||
switchEditText(textView.getId(), true);
|
||||
} else if (i == EditorInfo.IME_ACTION_DONE) {
|
||||
addMapMarker();
|
||||
addWptPt();
|
||||
hasUnsavedChanges = true;
|
||||
}
|
||||
return false;
|
||||
|
@ -916,7 +988,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
public void saveAsTrack() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
if (mapMarkers.isEmpty()) {
|
||||
if (!getGpx().hasWptPt()) {
|
||||
Toast.makeText(app, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
showSaveDialog();
|
||||
|
@ -934,15 +1006,19 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
|
||||
@Override
|
||||
public void saveGpx(final String fileName) {
|
||||
final String gpxPath = app.getMapMarkersHelper().generateGpxFromList(fileName, mapMarkers);
|
||||
new SaveGpxAsyncTask(app, getGpx(),fileName, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
hasUnsavedChanges = false;
|
||||
app.getMapMarkersHelper().addOrEnableGroup(getGpx());
|
||||
if (listener != null) {
|
||||
listener.onPointsSaved();
|
||||
}
|
||||
snackbar = Snackbar.make(mainView, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.shared_string_show, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(app, getMyApplication().getAppCustomization().getTrackActivity());
|
||||
intent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxPath);
|
||||
Intent intent = new Intent(app, app.getAppCustomization().getTrackActivity());
|
||||
intent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
|
||||
intent.putExtra(TrackActivity.TRACK_FILE_NAME, getGpx().path);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
@ -958,8 +1034,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
|
||||
@Override
|
||||
public void removeItem(final int position) {
|
||||
final MapMarker mapMarker = adapter.getItem(position);
|
||||
if (selectedMarker == mapMarker) {
|
||||
final WptPt wpt = adapter.getItem(position);
|
||||
if (selectedWpt == wpt) {
|
||||
dismissEditingMode();
|
||||
clearInputs();
|
||||
}
|
||||
|
@ -969,7 +1045,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mapMarkers.add(position, mapMarker);
|
||||
getGpx().addPoint(position, wpt);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
@ -981,7 +1057,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
public void editItem(int position) {
|
||||
enterEditingMode(adapter.getItem(position));
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1046,7 +1121,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
}
|
||||
|
||||
private void dismissEditingMode() {
|
||||
selectedMarker = null;
|
||||
selectedWpt = null;
|
||||
TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button);
|
||||
addButton.setText(R.string.shared_string_add);
|
||||
@ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
|
||||
|
@ -1054,11 +1129,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
((TextView) mainView.findViewById(R.id.toolbar_text)).setText(R.string.coord_input_add_point);
|
||||
}
|
||||
|
||||
private void enterEditingMode(MapMarker marker) {
|
||||
selectedMarker = marker;
|
||||
private void enterEditingMode(WptPt wptPt) {
|
||||
selectedWpt = wptPt;
|
||||
Format format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
|
||||
double lat = Math.abs(marker.point.getLatitude());
|
||||
double lon = Math.abs(marker.point.getLongitude());
|
||||
double lat = Math.abs(wptPt.lat);
|
||||
double lon = Math.abs(wptPt.lat);
|
||||
if (format == Format.DD_MM_MMM || format == Format.DD_MM_MMMM) {
|
||||
int accuracy = format.getThirdPartSymbolsCount();
|
||||
updateInputsDdm(true, CoordinateInputFormats.ddToDdm(lat), accuracy);
|
||||
|
@ -1071,15 +1146,15 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
updateInputsDms(true, CoordinateInputFormats.ddToDms(lat));
|
||||
updateInputsDms(false, CoordinateInputFormats.ddToDms(lon));
|
||||
}
|
||||
boolean latPositive = marker.point.getLatitude() > 0;
|
||||
boolean latPositive = wptPt.lat > 0;
|
||||
if ((latPositive && !north) || (!latPositive && north)) {
|
||||
updateSideOfTheWorldBtn(mainView.findViewById(R.id.lat_side_of_the_world_btn), true);
|
||||
}
|
||||
boolean lonPositive = marker.point.getLongitude() > 0;
|
||||
boolean lonPositive = wptPt.lon > 0;
|
||||
if ((lonPositive && !east) || (!lonPositive && east)) {
|
||||
updateSideOfTheWorldBtn(mainView.findViewById(R.id.lon_side_of_the_world_btn), true);
|
||||
}
|
||||
((EditText) mainView.findViewById(R.id.point_name_et)).setText(marker.getName(getContext()));
|
||||
((EditText) mainView.findViewById(R.id.point_name_et)).setText(wptPt.name);
|
||||
((TextView) mainView.findViewById(R.id.toolbar_text)).setText(R.string.coord_input_edit_point);
|
||||
TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button);
|
||||
addButton.setText(R.string.shared_string_apply);
|
||||
|
@ -1149,7 +1224,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
return getEditTextById(lat ? R.id.lat_third_input_et : R.id.lon_third_input_et);
|
||||
}
|
||||
|
||||
private void addMapMarker() {
|
||||
private void addWptPt() {
|
||||
final String latitude = getStringCoordinate(true);
|
||||
final String longitude = getStringCoordinate(false);
|
||||
if (latitude.isEmpty() && longitude.isEmpty()) {
|
||||
|
@ -1162,12 +1237,15 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
double lat = parseCoordinate(latitude);
|
||||
double lon = parseCoordinate(longitude);
|
||||
String name = ((EditText) mainView.findViewById(R.id.point_name_et)).getText().toString();
|
||||
if (selectedMarker != null) {
|
||||
updateSelectedMarker(new LatLon(lat, lon), name);
|
||||
if (selectedWpt != null) {
|
||||
updateWpt(getGpx(), null, name, null, 0, lat, lon);
|
||||
dismissEditingMode();
|
||||
} else {
|
||||
addMapMarker(new LatLon(lat, lon), name);
|
||||
addWpt(getGpx(), null, name, null, 0, lat, lon);
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
clearInputs();
|
||||
}
|
||||
|
||||
private String getStringCoordinate(boolean latitude) {
|
||||
|
@ -1216,30 +1294,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
return coordinate;
|
||||
}
|
||||
|
||||
private void updateSelectedMarker(LatLon latLon, String name) {
|
||||
selectedMarker.point = latLon;
|
||||
selectedMarker.setName(name);
|
||||
dismissEditingMode();
|
||||
adapter.notifyDataSetChanged();
|
||||
clearInputs();
|
||||
}
|
||||
|
||||
private void addMapMarker(LatLon latLon, String name) {
|
||||
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name);
|
||||
int colorIndex = mapMarkers.size() > 0 ? mapMarkers.get(mapMarkers.size() - 1).colorIndex : -1;
|
||||
if (colorIndex == -1) {
|
||||
colorIndex = 0;
|
||||
} else {
|
||||
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
|
||||
}
|
||||
MapMarker mapMarker = new MapMarker(latLon, pointDescription, colorIndex, false, 0);
|
||||
mapMarker.history = false;
|
||||
mapMarker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
|
||||
mapMarkers.add(mapMarker);
|
||||
adapter.notifyDataSetChanged();
|
||||
clearInputs();
|
||||
}
|
||||
|
||||
private void clearInputs(int... ids) {
|
||||
for (int id : ids) {
|
||||
View v = mainView.findViewById(id);
|
||||
|
@ -1334,7 +1388,49 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
}
|
||||
}
|
||||
|
||||
interface OnMapMarkersSavedListener {
|
||||
void onMapMarkersSaved();
|
||||
private static class SaveGpxAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private final OsmandApplication app;
|
||||
private final GPXFile gpx;
|
||||
private final boolean gpxSelected;
|
||||
private final String fileName;
|
||||
|
||||
SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx, String fileName, boolean gpxSelected) {
|
||||
this.app = app;
|
||||
this.gpx = gpx;
|
||||
this.fileName = fileName;
|
||||
this.gpxSelected = gpxSelected;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (Algorithms.isEmpty(gpx.path)) {
|
||||
if (!Algorithms.isEmpty(fileName)) {
|
||||
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
File fout = new File(dir, fileName + ".gpx");
|
||||
int ind = 1;
|
||||
while (fout.exists()) {
|
||||
fout = new File(dir, fileName + "_" + (++ind) + ".gpx");
|
||||
}
|
||||
GPXUtilities.writeGpxFile(fout, gpx, app);
|
||||
}
|
||||
} else {
|
||||
GPXUtilities.writeGpxFile(new File(gpx.path), gpx, app);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
if (!gpxSelected) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpx, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnPointsSavedListener {
|
||||
void onPointsSaved();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnMapMarkersSavedListener;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnPointsSavedListener;
|
||||
import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener;
|
||||
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
|
||||
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
|
||||
|
@ -141,7 +141,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
}
|
||||
Fragment coordinateInputDialog = fragmentManager.findFragmentByTag(CoordinateInputDialogFragment.TAG);
|
||||
if (coordinateInputDialog != null) {
|
||||
((CoordinateInputDialogFragment) coordinateInputDialog).setListener(createOnMapMarkersSavedListener());
|
||||
((CoordinateInputDialogFragment) coordinateInputDialog).setListener(createOnPointsSavedListener());
|
||||
}
|
||||
|
||||
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
|
||||
|
@ -293,10 +293,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
private OnMapMarkersSavedListener createOnMapMarkersSavedListener() {
|
||||
return new OnMapMarkersSavedListener() {
|
||||
private OnPointsSavedListener createOnPointsSavedListener() {
|
||||
return new OnPointsSavedListener() {
|
||||
@Override
|
||||
public void onMapMarkersSaved() {
|
||||
public void onPointsSaved() {
|
||||
updateAdapters();
|
||||
}
|
||||
};
|
||||
|
@ -392,7 +392,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
if (mapActivity != null) {
|
||||
CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.setListener(createOnMapMarkersSavedListener());
|
||||
fragment.setListener(createOnPointsSavedListener());
|
||||
fragment.show(getChildFragmentManager(), CoordinateInputDialogFragment.TAG);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,11 +31,12 @@ import java.io.File;
|
|||
import java.util.Date;
|
||||
|
||||
import static net.osmand.plus.helpers.ImportHelper.GPX_SUFFIX;
|
||||
import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.ADDED_MARKERS_NUMBER_KEY;
|
||||
import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.ADDED_POINTS_NUMBER_KEY;
|
||||
|
||||
public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public final static String TAG = "SaveAsTrackBottomSheetDialogFragment";
|
||||
public static final String COORDINATE_INPUT_MODE_KEY = "coordinate_input_mode_key";
|
||||
|
||||
private boolean portrait;
|
||||
private MarkerSaveAsTrackFragmentListener listener;
|
||||
|
@ -48,13 +49,14 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
|
|||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
boolean isCoordInput = false;
|
||||
boolean openFromCoordinateInput = false;
|
||||
int number = 0;
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
number = args.getInt(ADDED_MARKERS_NUMBER_KEY);
|
||||
if (number != 0)
|
||||
isCoordInput = true;
|
||||
openFromCoordinateInput = args.getBoolean(COORDINATE_INPUT_MODE_KEY);
|
||||
if (openFromCoordinateInput) {
|
||||
number = args.getInt(ADDED_POINTS_NUMBER_KEY);
|
||||
}
|
||||
}
|
||||
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||
final boolean nightMode = !app.getSettings().isLightContent();
|
||||
|
@ -63,9 +65,9 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
|
|||
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container);
|
||||
LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout);
|
||||
TextView titleTv = (TextView) mainView.findViewById(R.id.save_as_track_title);
|
||||
titleTv.setText(isCoordInput ? R.string.coord_input_save_as_track : R.string.marker_save_as_track);
|
||||
titleTv.setText(openFromCoordinateInput ? R.string.coord_input_save_as_track : R.string.marker_save_as_track);
|
||||
TextView descriptionTv = (TextView) mainView.findViewById(R.id.save_as_track_description);
|
||||
descriptionTv.setText(isCoordInput ? getString(R.string.coord_input_save_as_track_descr, number) : getString(R.string.marker_save_as_track_descr));
|
||||
descriptionTv.setText(openFromCoordinateInput ? getString(R.string.coord_input_save_as_track_descr, number) : getString(R.string.marker_save_as_track_descr));
|
||||
int layoutRes;
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
layoutRes = R.layout.markers_track_name_text_field_box;
|
||||
|
|
|
@ -11,21 +11,20 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> {
|
||||
|
||||
public static final String ADAPTER_POSITION_KEY = "adapter_position_key";
|
||||
private GPXUtilities.GPXFile gpx;
|
||||
|
||||
private OsmandApplication app;
|
||||
private List<MapMarker> mapMarkers;
|
||||
|
||||
private UiUtilities uiUtilities;
|
||||
private UpdateLocationViewCache updateViewCache;
|
||||
|
@ -43,9 +42,10 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
|
|||
this.actionsListener = actionsListener;
|
||||
}
|
||||
|
||||
public CoordinateInputAdapter(OsmandApplication app, List<MapMarker> mapMarkers) {
|
||||
public CoordinateInputAdapter(OsmandApplication app, GPXUtilities.GPXFile gpx) {
|
||||
this.app = app;
|
||||
this.mapMarkers = mapMarkers;
|
||||
this.gpx = gpx;
|
||||
|
||||
uiUtilities = app.getUIUtilities();
|
||||
updateViewCache = uiUtilities.getUpdateLocationViewCache();
|
||||
nightTheme = !app.getSettings().isLightContent();
|
||||
|
@ -61,10 +61,10 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final MapMarkerItemViewHolder holder, int position) {
|
||||
final MapMarker mapMarker = getItem(position);
|
||||
GPXUtilities.WptPt wpt = getItem(position);
|
||||
|
||||
holder.iconDirection.setVisibility(View.VISIBLE);
|
||||
holder.icon.setImageDrawable(getColoredIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(mapMarker.colorIndex)));
|
||||
holder.icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false));
|
||||
holder.mainLayout.setBackgroundColor(getResolvedColor(nightTheme ? R.color.ctx_menu_bg_dark : R.color.bg_color_light));
|
||||
holder.title.setTextColor(getResolvedColor(nightTheme ? R.color.ctx_menu_title_color_dark : R.color.color_black));
|
||||
holder.divider.setBackgroundColor(getResolvedColor(nightTheme ? R.color.route_info_divider_dark : R.color.dashboard_divider_light));
|
||||
|
@ -84,31 +84,36 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
|
|||
holder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
||||
holder.divider.setVisibility((!singleItem && !lastItem) ? View.VISIBLE : View.GONE);
|
||||
|
||||
holder.title.setText(mapMarker.getName(app));
|
||||
uiUtilities.updateLocationView(updateViewCache,
|
||||
holder.iconDirection, holder.distance, mapMarker.getLatitude(), mapMarker.getLongitude());
|
||||
holder.title.setText(wpt.name);
|
||||
uiUtilities.updateLocationView(updateViewCache, holder.iconDirection, holder.distance, wpt.lat, wpt.lon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mapMarkers.size();
|
||||
return gpx.getPointsSize();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getItemCount() == 0;
|
||||
}
|
||||
|
||||
public MapMarker getItem(int position) {
|
||||
return mapMarkers.get(position);
|
||||
|
||||
public GPXUtilities.WptPt getItem(int position) {
|
||||
return gpx.getPoints().get(position);
|
||||
}
|
||||
|
||||
public void removeItem(int position) {
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
mapMarkers.remove(getItem(position));
|
||||
gpx.deleteWptPt(getItem(position));
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setGpx(GPXUtilities.GPXFile gpx) {
|
||||
this.gpx = gpx;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private Drawable getColoredIcon(@DrawableRes int resId, @ColorRes int colorResId) {
|
||||
return uiUtilities.getIcon(resId, colorResId);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
@ -65,6 +66,7 @@ import net.osmand.plus.activities.SavingTrackHelper;
|
|||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.base.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -83,6 +85,7 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class TrackPointFragment extends OsmandExpandableListFragment implements TrackBitmapDrawerListener {
|
||||
|
||||
public static final int SEARCH_ID = -1;
|
||||
|
@ -90,6 +93,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
public static final int DELETE_ACTION_ID = 3;
|
||||
public static final int SHARE_ID = 4;
|
||||
public static final int SELECT_MAP_MARKERS_ID = 5;
|
||||
public static final int COORDINATE_INPUT_ID = 6;
|
||||
//public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6;
|
||||
public static final int SELECT_FAVORITES_ID = 7;
|
||||
public static final int SELECT_FAVORITES_ACTION_MODE_ID = 8;
|
||||
|
@ -274,6 +278,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
} else if (item.getItemId() == DELETE_ID) {
|
||||
enterDeleteMode();
|
||||
return true;
|
||||
} else if (item.getItemId() == COORDINATE_INPUT_ID) {
|
||||
openCoordinatesInput();
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -301,6 +308,25 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
private void openCoordinatesInput() {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.setListener(createOnPointsSavedListener());
|
||||
fragment.show(fm, CoordinateInputDialogFragment.TAG);
|
||||
}
|
||||
}
|
||||
|
||||
private CoordinateInputDialogFragment.OnPointsSavedListener createOnPointsSavedListener() {
|
||||
return new CoordinateInputDialogFragment.OnPointsSavedListener() {
|
||||
@Override
|
||||
public void onPointsSaved() {
|
||||
setContent();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear();
|
||||
|
@ -367,6 +393,8 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
R.drawable.ic_action_fav_dark, MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark,
|
||||
R.drawable.ic_action_delete_dark, MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
createMenuItem(menu, COORDINATE_INPUT_ID, R.string.coordinate_input, R.drawable.ic_action_coordinates_longitude,
|
||||
R.drawable.ic_action_coordinates_longitude, MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
}
|
||||
this.optionsMenu = menu;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue