Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-02-16 10:51:19 +01:00
commit c16f094c7e
8 changed files with 133 additions and 21 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="add_points_to_map_markers_q">Do you want to add all points to Map Markers?</string>
<string name="shared_string_add_to_map_markers">Add to Map Markers</string>
<string name="select_map_markers">Select Map Markers</string>
<string name="shared_string_reverse_order">Reverse order</string>
<string name="show_map_markers">Map Markers</string>

View file

@ -21,6 +21,7 @@ public class MapMarkersHelper {
public interface MapMarkerChangedListener {
void onMapMarkerChanged(MapMarker mapMarker);
void onMapMarkersChanged();
}
@ -199,25 +200,50 @@ public class MapMarkersHelper {
}
public void addMapMarker(LatLon point, PointDescription historyName) {
if (point != null) {
final PointDescription pointDescription;
if (historyName == null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
} else {
pointDescription = historyName;
}
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
}
int colorIndex;
if (mapMarkers.size() > 0) {
colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else {
colorIndex = 0;
}
settings.insertMapMarker(point.getLatitude(), point.getLongitude(),
pointDescription, colorIndex, 0);
List<LatLon> points = new ArrayList<>(1);
List<PointDescription> historyNames = new ArrayList<>(1);
points.add(point);
historyNames.add(historyName);
addMapMarkers(points, historyNames);
}
public void addMapMarkers(List<LatLon> points, List<PointDescription> historyNames) {
if (points.size() > 0) {
int colorIndex = -1;
double[] latitudes = new double[points.size()];
double[] longitudes = new double[points.size()];
List<PointDescription> pointDescriptions = new ArrayList<>();
int[] colorIndexes = new int[points.size()];
int[] indexes = new int[points.size()];
for (int i = 0; i < points.size(); i++) {
LatLon point = points.get(i);
PointDescription historyName = historyNames.get(i);
final PointDescription pointDescription;
if (historyName == null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
} else {
pointDescription = historyName;
}
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
}
if (colorIndex == -1) {
if (mapMarkers.size() > 0) {
colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else {
colorIndex = 0;
}
} else {
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
}
latitudes[i] = point.getLatitude();
longitudes[i] = point.getLongitude();
pointDescriptions.add(pointDescription);
colorIndexes[i] = colorIndex;
indexes[i] = 0;
}
settings.insertMapMarkers(latitudes, longitudes, pointDescriptions, colorIndexes, indexes);
readFromSettings();
refresh();
}

View file

@ -1614,6 +1614,27 @@ public class OsmandSettings {
return savePoints(ps, ds, cs);
}
public boolean insertPoints(double[] latitudes, double[] longitudes,
List<PointDescription> historyDescriptions, int[] colorIndexes, int[] indexes) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
for (int i = 0; i < latitudes.length; i++) {
double latitude = latitudes[i];
double longitude = longitudes[i];
PointDescription historyDescription = historyDescriptions.get(i);
int colorIndex = colorIndexes[i];
int index = indexes[i];
ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
}
return savePoints(ps, ds, cs);
}
public boolean updatePoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex) {
List<LatLon> ps = getPoints();
@ -1827,6 +1848,11 @@ public class OsmandSettings {
return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, index);
}
public boolean insertMapMarkers(double[] latitudes, double[] longitudes,
List<PointDescription> historyDescriptions, int[] colorIndexes, int[] indexes) {
return mapMarkersStorage.insertPoints(latitudes, longitudes, historyDescriptions, colorIndexes, indexes);
}
public boolean updateMapMarker(double latitude, double longitude,
PointDescription historyDescription, int colorIndex) {
return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex);

View file

@ -421,10 +421,13 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
if(!favoritesSelected.isEmpty()) {
if (getSettings().USE_MAP_MARKERS.get()) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
List<LatLon> points = new ArrayList<>(favoritesSelected.size());
List<PointDescription> names = new ArrayList<>(favoritesSelected.size());
for (FavouritePoint fp : favoritesSelected) {
markersHelper.addMapMarker(new LatLon(fp.getLatitude(), fp.getLongitude()),
new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
}
markersHelper.addMapMarkers(points, names);
MapActivity.launchMapActivityMoveToTop(getActivity());
} else {
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();

View file

@ -38,6 +38,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -222,7 +223,24 @@ public class SelectedGPXFragment extends OsmAndListFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
saveFavoritesImpl(flatten(gs), editText.getText().toString());
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
}
protected void saveAsMapMarkers(final GpxDisplayItemType gpxDisplayItemType) {
AlertDialog.Builder b = new AlertDialog.Builder(getMyActivity());
final List<GpxDisplayGroup> gs = filterGroups(gpxDisplayItemType, getMyActivity(), getArguments());
if (gs.size() == 0) {
return;
}
b.setMessage(R.string.add_points_to_map_markers_q);
b.setPositiveButton(R.string.shared_string_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
saveMapMarkersImpl(flatten(gs));
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
@ -241,6 +259,19 @@ public class SelectedGPXFragment extends OsmAndListFragment {
fdb.saveCurrentPointsIntoFile();
}
protected void saveMapMarkersImpl(List<GpxDisplayItem> modifiableList) {
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
List<LatLon> points = new ArrayList<>();
List<PointDescription> names = new ArrayList<>();
for(GpxDisplayItem i : modifiableList) {
if (i.locationStart != null) {
points.add(new LatLon(i.locationStart.lat, i.locationStart.lon));
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name));
}
}
markersHelper.addMapMarkers(points, names);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();

View file

@ -30,5 +30,17 @@ public class TrackPointFragment extends SelectedGPXFragment {
}
});
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
if (app.getSettings().USE_MAP_MARKERS.get()) {
item = menu.add(R.string.shared_string_add_to_map_markers).setIcon(R.drawable.ic_action_flag_dark)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
saveAsMapMarkers(GpxSelectionHelper.GpxDisplayItemType.TRACK_POINTS);
return true;
}
});
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
}
}

View file

@ -33,5 +33,17 @@ public class TrackRoutePointFragment extends SelectedGPXFragment {
}
});
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
if (app.getSettings().USE_MAP_MARKERS.get()) {
item = menu.add(R.string.shared_string_add_to_map_markers).setIcon(R.drawable.ic_action_flag_dark)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
saveAsMapMarkers(GpxSelectionHelper.GpxDisplayItemType.TRACK_ROUTE_POINTS);
return true;
}
});
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
}
}

View file

@ -83,7 +83,7 @@ public class MapMarkersWidget {
});
IconsCache iconsCache = map.getMyApplication().getIconsCache();
if (isLandscapeLayout()) {
if (isLandscapeLayout() && helper.getActiveMapMarkers().size() > 1) {
moreButton.setVisibility(View.GONE);
} else {
moreButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color));