Add gpx wptpt editor

This commit is contained in:
Dima-1 2020-03-24 12:14:33 +02:00
parent 92271050be
commit 59e4284d00
11 changed files with 593 additions and 79 deletions

View file

@ -273,15 +273,15 @@ public class GPXUtilities {
getExtensionsToWrite().put(ICON_NAME_EXTENSION, iconName);
}
public String getBackType() {
String backType = getExtensionsToRead().get(BACKGROUND_TYPE_EXTENSION);
if (backType == null) {
backType = DEFAULT_BACKGROUND_TYPE;
public String getBackgroundType() {
String backgroundType = getExtensionsToRead().get(BACKGROUND_TYPE_EXTENSION);
if (backgroundType == null) {
backgroundType = DEFAULT_BACKGROUND_TYPE;
}
return backType;
return backgroundType;
}
public void setBackType(String backType) {
public void setBackgroundType(String backType) {
getExtensionsToWrite().put(BACKGROUND_TYPE_EXTENSION, backType);
}
@ -1130,6 +1130,11 @@ public class GPXUtilities {
}
public WptPt addWptPt(double lat, double lon, long time, String description, String name, String category, int color) {
return addWptPt(lat, lon, time, description, name, category, color, null, null);
}
public WptPt addWptPt(double lat, double lon, long time, String description, String name, String category,
int color, String iconName, String backgroundType) {
double latAdjusted = Double.parseDouble(latLonFormat.format(lat));
double lonAdjusted = Double.parseDouble(latLonFormat.format(lon));
final WptPt pt = new WptPt(latAdjusted, lonAdjusted, time, Double.NaN, 0, Double.NaN);
@ -1139,6 +1144,12 @@ public class GPXUtilities {
if (color != 0) {
pt.setColor(color);
}
if (iconName != null) {
pt.setIconName(iconName);
}
if (backgroundType != null) {
pt.setBackgroundType(backgroundType);
}
points.add(pt);
@ -1224,7 +1235,13 @@ public class GPXUtilities {
modifiedTime = System.currentTimeMillis();
}
public void updateWptPt(WptPt pt, double lat, double lon, long time, String description, String name, String category, int color) {
public void updateWptPt(WptPt pt, double lat, double lon, long time, String description, String name, String category,
int color) {
updateWptPt(pt, lat, lon, System.currentTimeMillis(), description, name, category, color, null, null);
}
public void updateWptPt(WptPt pt, double lat, double lon, long time, String description, String name, String category,
int color, String iconName, String backgroundType) {
int index = points.indexOf(pt);
double latAdjusted = Double.parseDouble(latLonFormat.format(lat));
double lonAdjusted = Double.parseDouble(latLonFormat.format(lon));
@ -1237,6 +1254,12 @@ public class GPXUtilities {
if (color != 0) {
pt.setColor(color);
}
if (iconName != null) {
pt.setIconName(iconName);
}
if (backgroundType != null) {
pt.setBackgroundType(backgroundType);
}
if (index != -1) {
points.set(index, pt);

View file

@ -178,7 +178,7 @@
<color name="row_selection_color">#CC33BBE0</color>
<!-- GPX analysis colors -->
<color name="gpx_color_point">#cd2c33</color>
<color name="gpx_color_point">#d00d0d</color>
<color name="gpx_speed">#c79c00</color>
<color name="gpx_altitude_desc">#32CD32</color>
<color name="gpx_altitude_asc">#EE3232</color>

View file

@ -344,7 +344,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
if (iconName != null) {
fp.setIconIdFromName(ctx, iconName);
}
fp.setBackgroundType(BackgroundType.valueOf((pt.getBackType().toUpperCase())));
fp.setBackgroundType(BackgroundType.valueOf((pt.getBackgroundType().toUpperCase())));
return fp;
}
@ -362,7 +362,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
pt.setIconName(getIconEntryName(ctx).substring(3));
}
if(backgroundType != null) {
pt.setBackType(backgroundType.typeName);
pt.setBackgroundType(backgroundType.typeName);
}
if (getColor() != 0) {
pt.setColor(getColor());

View file

@ -508,8 +508,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
currentTrack.getModifiableGpxFile().modifiedTime = time;
}
public WptPt insertPointData(double lat, double lon, long time, String description, String name, String category, int color) {
public WptPt insertPointData(double lat, double lon, long time, String description, String name, String category,
int color) {
return insertPointData(lat, lon, time, description, name, category, color, null, null);
}
public WptPt insertPointData(double lat, double lon, long time, String description, String name, String category,
int color, String iconName, String backgroundName) {
final WptPt pt = new WptPt(lat, lon, time, Double.NaN, 0, Double.NaN);
pt.name = name;
pt.category = category;
@ -517,6 +523,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
if (color != 0) {
pt.setColor(color);
}
pt.setIconName(iconName);
pt.setBackgroundType(backgroundName);
ctx.getSelectedGpxHelper().addPoint(pt, currentTrack.getModifiableGpxFile());
currentTrack.getModifiableGpxFile().modifiedTime = time;
points++;

View file

@ -206,6 +206,7 @@ public class FavoriteImageDrawable extends Drawable {
if (pt != null) {
point = new FavouritePoint(pt.getLatitude(), pt.getLongitude(), pt.name, pt.category);
point.setIconIdFromName(a, pt.getIconName());
point.setBackgroundType(FavouritePoint.BackgroundType.valueOf(pt.getBackgroundType()));
}
return point;
}

View file

@ -29,7 +29,7 @@ import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.util.Algorithms;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
@ -357,11 +357,6 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
}
}
@Override
public String getHeaderCaption() {
return getString(R.string.favourites_edit_dialog_title);
}
@Override
public String getNameInitValue() {
FavouritePoint favorite = getFavorite();
@ -434,10 +429,30 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
@Override
public Set<String> getCategories() {
Set<String> categories = new HashSet<>();
Set<String> categories = new LinkedHashSet<>();
for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
categories.add(fg.getDisplayName(getMyApplication()));
}
return categories;
}
@Override
public int getCategoryPoints(String category) {
for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
if (fg.getDisplayName(getMyApplication()).equals(category)) {
return fg.getPoints().size();
}
}
return 0;
}
@Override
public int getCategoryColor(String category) {
for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
if (fg.getDisplayName(getMyApplication()).equals(category)) {
return fg.getColor();
}
}
return defaultColor;
}
}

View file

@ -39,7 +39,6 @@ import com.google.android.material.textfield.TextInputLayout;
import net.osmand.AndroidUtils;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -151,6 +150,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public void onClick(View v) {
DialogFragment dialogFragment = createSelectCategoryDialog();
if (dialogFragment != null) {
dialogFragment.show(getChildFragmentManager(), SelectCategoryDialogFragment.TAG);
}
}
@ -305,8 +305,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
ImageView icon = oldColor.findViewById(R.id.icon);
icon.setImageDrawable(UiUtilities.tintDrawable(icon.getDrawable(), R.color.icon_color_default_light));
}
rootView.findViewWithTag(color).findViewById(R.id.outline).setVisibility(View.VISIBLE);
if (rootView.findViewWithTag(color) != null) {
rootView.findViewWithTag(color).findViewById(R.id.outline).setVisibility(View.VISIBLE);
}
((TextView) view.findViewById(R.id.color_name)).setText(ColorDialogs.getColorName(color));
selectedColor = color;
setColor(color);
@ -331,7 +332,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
ContextCompat.getColor(app, R.color.divider_color_light)));
ImageView outline = shapeItemView.findViewById(R.id.outline);
outline.setImageDrawable(getOutlineDrawable(backgroundType.getIconId()));
ImageView icon = shapeItemView.findViewById(R.id.icon);
background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -481,7 +481,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
private String loadJSONFromAsset() {
String json = null;
String json;
try {
InputStream is = app.getAssets().open("poi_categories.json");
int size = is.available();
@ -496,10 +496,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
return json;
}
protected EditText getNameEdit() {
return nameEdit;
}
@Nullable
protected DialogFragment createSelectCategoryDialog() {
PointEditor editor = getEditor();
@ -579,39 +575,20 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
}
protected void savePressed() {
private void savePressed() {
save(true);
}
protected void deletePressed() {
private void deletePressed() {
delete(true);
}
protected abstract boolean wasSaved();
protected abstract void save(boolean needDismiss);
protected abstract void delete(boolean needDismiss);
static int getResIdFromAttribute(final Context ctx, final int attr) {
if (attr == 0) {
return 0;
}
final TypedValue typedvalueattr = new TypedValue();
ctx.getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId;
}
@Nullable
public abstract PointEditor getEditor();
public abstract String getToolbarTitle();
public void setCategory(String name, int color) {
setSelectedItemWithScroll(name);
}
private void setSelectedItemWithScroll(String name) {
groupListAdapter.fillGroups();
groupListAdapter.setSelectedItemName(name);
groupListAdapter.notifyDataSetChanged();
int position;
@ -629,12 +606,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
groupRecyclerView.scrollToPosition(position);
}
public abstract void setColor(int color);
public abstract void setBackgroundType(FavouritePoint.BackgroundType backgroundType);
public abstract void setIcon(int iconId);
protected String getDefaultCategoryName() {
return getString(R.string.shared_string_none);
}
@ -669,7 +640,26 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
}
public abstract String getHeaderCaption();
protected abstract boolean wasSaved();
protected abstract void save(boolean needDismiss);
protected abstract void delete(boolean needDismiss);
@Nullable
public abstract PointEditor getEditor();
public abstract String getToolbarTitle();
public abstract int getCategoryColor(String category);
public abstract int getCategoryPoints(String category);
public abstract void setColor(int color);
public abstract void setBackgroundType(FavouritePoint.BackgroundType backgroundType);
public abstract void setIcon(int iconId);
public abstract String getNameInitValue();
@ -725,7 +715,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
private static final int VIEW_TYPE_FOOTER = 1;
private static final int VIEW_TYPE_CELL = 0;
List<FavouritesDbHelper.FavoriteGroup> items;
List<String> items = new ArrayList<>();
void setSelectedItemName(String selectedItemName) {
this.selectedItemName = selectedItemName;
@ -734,7 +724,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
String selectedItemName;
GroupAdapter() {
items = app.getFavorites().getFavoriteGroups();
fillGroups();
}
private void fillGroups() {
items.clear();
items.addAll(getCategories());
}
@NonNull
@ -770,20 +765,22 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
holder.groupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
selectedItemName = items.get(holder.getAdapterPosition()).getDisplayName(app);
notifyDataSetChanged();
int previousSelectedPosition = getItemPosition(selectedItemName);
selectedItemName = items.get(holder.getAdapterPosition());
notifyItemChanged(holder.getAdapterPosition());
notifyItemChanged(previousSelectedPosition);
}
});
final FavouritesDbHelper.FavoriteGroup group = items.get(position);
holder.groupName.setText(group.getDisplayName(app));
int color = group.getColor() == 0 ? getDefaultColor() : group.getColor();
final String group = items.get(position);
holder.groupName.setText(group);
int categoryColor = getCategoryColor(group);
int color = categoryColor == 0 ? getDefaultColor() : categoryColor;
holder.groupIcon.setImageDrawable(UiUtilities.tintDrawable(
ContextCompat.getDrawable(app, R.drawable.ic_action_folder), color));
holder.pointsCounter.setText(String.valueOf(group.getPoints().size()));
holder.pointsCounter.setText(String.valueOf(getCategoryPoints(group)));
int strokeColor;
int strokeWidth;
if (selectedItemName != null && selectedItemName.equals(items.get(position).getDisplayName(app))) {
if (selectedItemName != null && selectedItemName.equals(items.get(position))) {
strokeColor = ContextCompat.getColor(app, nightMode ?
R.color.active_color_primary_dark : R.color.active_color_primary_light);
strokeWidth = 2;
@ -796,9 +793,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), strokeColor);
holder.groupButton.setImageDrawable(rectContourDrawable);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light, R.drawable.ripple_solid_dark);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light, R.drawable.ripple_solid_dark);
}
}
@ -817,11 +814,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
int getItemPosition(String name) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getDisplayName(app).equals(name))
return i;
}
return 0;
return items.indexOf(name);
}
}

View file

@ -134,14 +134,14 @@ public class WptPtEditor extends PointEditor {
public void showEditorFragment() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
WptPtEditorFragment.showInstance(mapActivity);
WptPtEditorFragmentNew.showInstance(mapActivity);
}
}
public void showEditorFragment(boolean skipDialog) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
WptPtEditorFragment.showInstance(mapActivity, skipDialog);
WptPtEditorFragmentNew.showInstance(mapActivity, skipDialog);
}
}
}

View file

@ -0,0 +1,472 @@
package net.osmand.plus.mapcontextmenu.editors;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.WptLocationPoint;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener;
import net.osmand.util.Algorithms;
import java.io.File;
import java.util.Map;
import java.util.Set;
public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
@Nullable
protected WptPtEditor editor;
@Nullable
protected WptPt wpt;
@Nullable
private SavingTrackHelper savingTrackHelper;
@Nullable
private GpxSelectionHelper selectedGpxHelper;
private boolean saved;
private int color;
private int defaultColor;
protected boolean skipDialog;
private String iconName;
@NonNull
private String backgroundTypeName = FavouritePoint.BackgroundType.CIRCLE.name();
private Map<String, Integer> categoriesMap;
private OsmandApplication app;
@Override
public void onAttach(Context context) {
super.onAttach(context);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
app = mapActivity.getMyApplication();
savingTrackHelper = app.getSavingTrackHelper();
selectedGpxHelper = app.getSelectedGpxHelper();
assignEditor();
defaultColor = getResources().getColor(R.color.gpx_color_point);
}
}
@Override
protected DialogFragment createSelectCategoryDialog() {
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
SelectCategoryDialogFragment selectCategoryDialogFragment = SelectCategoryDialogFragment.createInstance(editor.getFragmentTag());
GPXFile gpx = editor.getGpxFile();
if (gpx != null) {
selectCategoryDialogFragment.setGpxFile(gpx);
selectCategoryDialogFragment.setGpxCategories(categoriesMap);
}
return selectCategoryDialogFragment;
} else {
return null;
}
}
protected void assignEditor() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
editor = mapActivity.getContextMenu().getWptPtPointEditor();
}
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
WptPt wpt = editor.getWptPt();
this.wpt = wpt;
color = wpt.getColor(0);
iconName = wpt.getIconName();
categoriesMap = editor.getGpxFile().getWaypointCategoriesWithColors(false);
backgroundTypeName = wpt.getBackgroundType();
}
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (skipDialog) {
save(true);
}
}
@Override
public void dismiss(boolean includingMenu) {
super.dismiss(includingMenu);
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
OnDismissListener listener = editor.getOnDismissListener();
if (listener != null) {
listener.onDismiss();
}
editor.setNewGpxPointProcessing(false);
editor.setOnDismissListener(null);
}
}
@Override
public PointEditor getEditor() {
return editor;
}
public WptPtEditor getWptPtEditor() {
return editor;
}
@Nullable
public SavingTrackHelper getSavingTrackHelper() {
return savingTrackHelper;
}
@Nullable
public GpxSelectionHelper getSelectedGpxHelper() {
return selectedGpxHelper;
}
@Nullable
public WptPt getWpt() {
return wpt;
}
@Override
public String getToolbarTitle() {
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
if (editor.isNewGpxPointProcessing()) {
return getString(R.string.save_gpx_waypoint);
} else {
if (editor.isNew()) {
return getString(R.string.context_menu_item_add_waypoint);
} else {
return getString(R.string.shared_string_edit);
}
}
}
return "";
}
public static void showInstance(final MapActivity mapActivity) {
WptPtEditor editor = mapActivity.getContextMenu().getWptPtPointEditor();
if (editor != null) {
WptPtEditorFragmentNew fragment = new WptPtEditorFragmentNew();
mapActivity.getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
.addToBackStack(null).commit();
}
}
public static void showInstance(final MapActivity mapActivity, boolean skipDialog) {
WptPtEditor editor = mapActivity.getContextMenu().getWptPtPointEditor();
if (editor != null) {
WptPtEditorFragmentNew fragment = new WptPtEditorFragmentNew();
fragment.skipDialog = skipDialog;
mapActivity.getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
.addToBackStack(null).commit();
}
}
@Override
protected boolean wasSaved() {
return saved;
}
@Override
protected void save(final boolean needDismiss) {
MapActivity mapActivity = getMapActivity();
WptPtEditor editor = getWptPtEditor();
WptPt wpt = getWpt();
if (mapActivity != null && editor != null && wpt != null) {
String name = Algorithms.isEmpty(getNameTextValue()) ? null : getNameTextValue();
String category = Algorithms.isEmpty(getCategoryTextValue()) ? null : getCategoryTextValue();
String description = Algorithms.isEmpty(getDescriptionTextValue()) ? null : getDescriptionTextValue();
if (editor.isNew()) {
doAddWpt(name, category, description);
} else {
doUpdateWpt(name, category, description);
}
mapActivity.refreshMap();
if (needDismiss) {
dismiss(false);
}
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.getLatLon() != null && menu.isActive()) {
LatLon latLon = new LatLon(wpt.getLatitude(), wpt.getLongitude());
if (menu.getLatLon().equals(latLon)) {
menu.update(latLon, new WptLocationPoint(wpt).getPointDescription(mapActivity), wpt);
}
}
saved = true;
}
}
private void syncGpx(GPXFile gpxFile) {
OsmandApplication app = getMyApplication();
if (app != null) {
MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) {
helper.runSynchronization(group);
}
}
}
private void doAddWpt(String name, String category, String description) {
WptPt wpt = getWpt();
WptPtEditor editor = getWptPtEditor();
if (wpt != null && editor != null) {
wpt.name = name;
wpt.category = category;
wpt.desc = description;
if (color != 0) {
wpt.setColor(color);
} else {
wpt.removeColor();
}
GPXFile gpx = editor.getGpxFile();
SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
GpxSelectionHelper selectedGpxHelper = getSelectedGpxHelper();
if (gpx != null && savingTrackHelper != null && selectedGpxHelper != null) {
if (gpx.showCurrentTrack) {
this.wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color, iconName, backgroundTypeName);
if (!editor.isGpxSelected()) {
selectedGpxHelper.setGpxFileToDisplay(gpx);
}
} else {
addWpt(gpx, description, name, category, color, iconName, backgroundTypeName);
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
syncGpx(gpx);
}
}
}
protected void addWpt(GPXFile gpx, String description, String name, String category, int color, String iconName,
String backgroundType) {
WptPt wpt = getWpt();
if (wpt != null) {
this.wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color, iconName, backgroundType);
syncGpx(gpx);
}
}
private void doUpdateWpt(String name, String category, String description) {
WptPt wpt = getWpt();
WptPtEditor editor = getWptPtEditor();
SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
GpxSelectionHelper selectedGpxHelper = getSelectedGpxHelper();
if (wpt != null && editor != null && savingTrackHelper != null && selectedGpxHelper != null) {
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, iconName, backgroundTypeName);
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
syncGpx(gpx);
}
}
}
@Override
protected void delete(final boolean needDismiss) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.context_menu_item_delete_waypoint));
builder.setNegativeButton(R.string.shared_string_no, null);
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
WptPt wpt = getWpt();
WptPtEditor editor = getWptPtEditor();
SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
if (wpt != null && editor != null && savingTrackHelper != null) {
GPXFile gpx = editor.getGpxFile();
if (gpx != null) {
if (gpx.showCurrentTrack) {
savingTrackHelper.deletePointData(wpt);
} else {
gpx.deleteWptPt(wpt);
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
syncGpx(gpx);
}
saved = true;
}
if (needDismiss) {
dismiss(true);
} else {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.refreshMap();
}
}
}
});
builder.create().show();
}
@Override
public void setCategory(String name, int color) {
if (categoriesMap != null) {
categoriesMap.put(name, color);
}
this.color = color;
super.setCategory(name, color);
}
@Override
public void setColor(int color) {
this.color = color;
}
@Override
public void setBackgroundType(FavouritePoint.BackgroundType backgroundType) {
this.backgroundTypeName = backgroundType.name();
}
@Override
public void setIcon(int iconId) {
this.iconName = getIconNameFromID(iconId).substring(3);
}
private String getIconNameFromID(int iconId) {
return app.getResources().getResourceEntryName(iconId);
}
@Override
protected String getDefaultCategoryName() {
return getString(R.string.shared_string_favorites);
}
@Override
public String getNameInitValue() {
return wpt != null ? wpt.name : "";
}
@Override
public String getCategoryInitValue() {
return wpt == null || Algorithms.isEmpty(wpt.category) ? "" : wpt.category;
}
@Override
public String getDescriptionInitValue() {
return wpt != null ? wpt.desc : "";
}
@Override
public Drawable getNameIcon() {
WptPt wptPt = getWpt();
WptPt point = null;
if (wptPt != null) {
point = new WptPt(wptPt);
point.setColor(getPointColor());
point.setBackgroundType(backgroundTypeName);
point.setIconName(iconName);
}
return FavoriteImageDrawable.getOrCreate(getMapActivity(), getPointColor(), false, point);
}
@Override
public Drawable getCategoryIcon() {
return getPaintedIcon(R.drawable.ic_action_folder_stroke, getPointColor());
}
@Override
public int getDefaultColor() {
return 0;
}
@Override
public int getPointColor() {
return color == 0 ? defaultColor : color;
}
@Override
public FavouritePoint.BackgroundType getBackgroundType() {
return FavouritePoint.BackgroundType.valueOf(backgroundTypeName);
}
@Override
public int getIconId() {
return getIconIdFromName(iconName);
}
public int getIconIdFromName(String iconName) {
return app.getResources().getIdentifier("mx_" + iconName, "drawable", app.getPackageName());
}
@Override
public Set<String> getCategories() {
return categoriesMap.keySet();
}
@Override
public int getCategoryColor(String category) {
return categoriesMap != null ? categoriesMap.get(category) : defaultColor;
}
@Override
public int getCategoryPoints(String category) {
return 0;
}
private static class SaveGpxAsyncTask extends AsyncTask<Void, Void, Void> {
private final OsmandApplication app;
private final GPXFile gpx;
private final boolean gpxSelected;
SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx, boolean gpxSelected) {
this.app = app;
this.gpx = gpx;
this.gpxSelected = gpxSelected;
}
@Override
protected Void doInBackground(Void... params) {
GPXUtilities.writeGpxFile(new File(gpx.path), gpx);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (!gpxSelected) {
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
}
}
}
}

View file

@ -263,7 +263,8 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
System.currentTimeMillis(), wpt.desc, wpt.name, category, color);
} else {
gpxFile.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), wpt.desc, wpt.name, category, color);
System.currentTimeMillis(), wpt.desc, wpt.name, category, color,
wpt.getIconName(), wpt.getBackgroundType());
}
}
}

View file

@ -683,7 +683,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
GPXFile gpxFile = selectedGpxFile.getGpxFile();
gpxFile.updateWptPt(objectInMotion, position.getLatitude(),
position.getLongitude(), System.currentTimeMillis(), objectInMotion.desc,
objectInMotion.name, objectInMotion.category, objectInMotion.getColor());
objectInMotion.name, objectInMotion.category, objectInMotion.getColor(),
objectInMotion.getIconName(), objectInMotion.getBackgroundType());
syncGpx(gpxFile);
if (gpxFile.showCurrentTrack) {
if (callback != null) {