diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml index a6ed13b8d8..5bf50846eb 100644 --- a/OsmAnd/res/layout/map_context_menu_fragment.xml +++ b/OsmAnd/res/layout/map_context_menu_fragment.xml @@ -116,6 +116,7 @@ android:layout_height="match_parent"> diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 1197f0f862..d711392e49 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -88,6 +88,7 @@ public class GpxSelectionHelper { int k = 1; for (Track t : g.tracks) { GpxDisplayGroup group = new GpxDisplayGroup(g); + group.gpxName = name; group.color = t.getColor(g.getColor(0)); group.setType(GpxDisplayItemType.TRACK_SEGMENT); group.setTrack(t); @@ -106,6 +107,7 @@ public class GpxSelectionHelper { int k = 0; for (Route route : g.routes) { GpxDisplayGroup group = new GpxDisplayGroup(g); + group.gpxName = name; group.setType(GpxDisplayItemType.TRACK_ROUTE_POINTS); String d = getString(R.string.gpx_selection_number_of_points, name, route.points.size()); if(route.name != null && route.name.length() > 0) { @@ -136,6 +138,7 @@ public class GpxSelectionHelper { if (g.points.size() > 0) { GpxDisplayGroup group = new GpxDisplayGroup(g); + group.gpxName = name; group.setType(GpxDisplayItemType.TRACK_POINTS); group.setDescription(getString(R.string.gpx_selection_number_of_points, g.points.size())); group.setName(getString(R.string.gpx_selection_points, name)); @@ -195,7 +198,6 @@ public class GpxSelectionHelper { item.description = GpxUiHelper.getDescription(app, analysis, true); item.analysis = analysis; - /* String name = ""; // if(group.track.segments.size() > 1) { // name += t++ + ". "; @@ -238,8 +240,7 @@ public class GpxSelectionHelper { OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app)); } } - */ - item.name = group.getName();//.replace("\n", ""); + item.name = name; item.locationStart = analysis.locationStart; item.locationEnd = analysis.locationEnd; list.add(item); @@ -513,6 +514,7 @@ public class GpxSelectionHelper { private GpxDisplayItemType type = GpxDisplayItemType.TRACK_SEGMENT; private List list = new ArrayList(); private GPXFile gpx; + private String gpxName; private String name; private String description; private Track track; @@ -557,7 +559,11 @@ public class GpxSelectionHelper { public void setName(String name) { this.name = name; } - + + public String getGpxName() { + return gpxName; + } + public String getName() { return name; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 900ca1855d..4f2f968985 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu; import android.support.v4.app.Fragment; import android.view.View; +import android.widget.LinearLayout; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -526,6 +527,16 @@ public class MapContextMenu extends MenuTitleController { } } + public boolean hasCustomAddressLine() { + return menuController != null && menuController.hasCustomAddressLine(); + } + + public void buildCustomAddressLine(LinearLayout ll) { + if (menuController != null) { + menuController.buildCustomAddressLine(ll); + } + } + public LatLon getMyLocation() { return myLocation; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index a32000016a..d78cae8b48 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -721,23 +721,29 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { line1.setText(menu.getTitleStr()); // Text line 2 + LinearLayout line2layout = (LinearLayout) view.findViewById(R.id.context_menu_line2_layout); TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2); - String typeStr = menu.getTypeStr(); - String streetStr = menu.getStreetStr(); - StringBuilder line2Str = new StringBuilder(); - if (!Algorithms.isEmpty(typeStr)) { - line2Str.append(typeStr); - Drawable icon = menu.getTypeIcon(); - line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); - line2.setCompoundDrawablePadding(dpToPx(5f)); - } - if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) { - if (line2Str.length() > 0) { - line2Str.append(", "); + if (menu.hasCustomAddressLine()) { + line2layout.removeAllViews(); + menu.buildCustomAddressLine(line2layout); + } else { + String typeStr = menu.getTypeStr(); + String streetStr = menu.getStreetStr(); + StringBuilder line2Str = new StringBuilder(); + if (!Algorithms.isEmpty(typeStr)) { + line2Str.append(typeStr); + Drawable icon = menu.getTypeIcon(); + line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + line2.setCompoundDrawablePadding(dpToPx(5f)); } - line2Str.append(streetStr); + if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) { + if (line2Str.length() > 0) { + line2Str.append(", "); + } + line2Str.append(streetStr); + } + line2.setText(line2Str.toString()); } - line2.setText(line2Str.toString()); updateCompassVisibility(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 00904f9a37..8fda2f1856 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -222,6 +222,13 @@ public class MenuBuilder { ((LinearLayout) view).addView(horizontalLine); } + public boolean hasCustomAddressLine() { + return false; + } + + public void buildCustomAddressLine(LinearLayout ll) { + } + public void addPlainMenuItem(int iconId, String text, boolean needLinks) { plainMenuItems.add(new PlainMenuItem(iconId, text, needLinks)); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 5e647065c4..7b28f7f000 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu; import android.graphics.drawable.Drawable; import android.view.View; +import android.widget.LinearLayout; import net.osmand.binary.BinaryMapDataObject; import net.osmand.data.Amenity; @@ -271,6 +272,14 @@ public abstract class MenuController extends BaseMenuController { public void updateData() { } + public boolean hasCustomAddressLine() { + return builder.hasCustomAddressLine(); + } + + public void buildCustomAddressLine(LinearLayout ll) { + builder.buildCustomAddressLine(ll); + } + public abstract class TitleButtonController { public String caption = ""; public int leftIconId = 0; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java new file mode 100644 index 0000000000..b7148be0c1 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java @@ -0,0 +1,86 @@ +package net.osmand.plus.mapcontextmenu.builders; + +import android.content.res.Resources; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.util.Algorithms; + +public class GpxItemMenuBuilder extends MenuBuilder { + private GpxDisplayItem item; + + public GpxItemMenuBuilder(OsmandApplication app, GpxDisplayItem item) { + super(app); + this.item = item; + } + + @Override + protected boolean needBuildPlainMenuItems() { + return false; + } + + @Override + public void buildInternal(View view) { + String description = GpxUiHelper.getDescription(app, item.analysis, false); + String[] lines = description.split("\n"); + for (String line : lines) { + buildRow(view, R.drawable.ic_action_info_dark, line, 0, false, 0); + } + } + + @Override + public boolean hasCustomAddressLine() { + return true; + } + + public void buildCustomAddressLine(LinearLayout ll) { + int gpxSmallIconMargin = (int) ll.getResources().getDimension(R.dimen.gpx_small_icon_margin); + int gpxSmallTextMargin = (int) ll.getResources().getDimension(R.dimen.gpx_small_text_margin); + float gpxTextSize = ll.getResources().getDimension(R.dimen.default_desc_text_size); + + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = app.getTheme(); + theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true); + int textColor = typedValue.data; + + buildIcon(ll, gpxSmallIconMargin, R.drawable.ic_small_point); + buildTextView(ll, gpxSmallTextMargin, gpxTextSize, textColor, "" + item.analysis.wptPoints); + buildIcon(ll, gpxSmallIconMargin, R.drawable.ic_small_distance); + buildTextView(ll, gpxSmallTextMargin, gpxTextSize, textColor, + OsmAndFormatter.getFormattedDistance(item.analysis.totalDistance, app)); + buildIcon(ll, gpxSmallIconMargin, R.drawable.ic_small_time); + buildTextView(ll, gpxSmallTextMargin, gpxTextSize, textColor, Algorithms.formatDuration((int) (item.analysis.timeSpan / 1000)) + ""); + } + + private void buildIcon(LinearLayout ll, int gpxSmallIconMargin, int iconId) { + ImageView icon = new ImageView(ll.getContext()); + LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + llIconParams.setMargins(0, 0, gpxSmallIconMargin, 0); + llIconParams.gravity = Gravity.CENTER_VERTICAL; + icon.setLayoutParams(llIconParams); + icon.setImageDrawable(app.getIconsCache().getContentIcon(iconId)); + ll.addView(icon); + } + + private void buildTextView(LinearLayout ll, int gpxSmallTextMargin, float gpxTextSize, int textColor, String text) { + TextView textView = new TextView(ll.getContext()); + LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + llTextParams.setMargins(0, 0, gpxSmallTextMargin, 0); + textView.setLayoutParams(llTextParams); + textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, gpxTextSize); + textView.setTextColor(textColor); + textView.setText(text); + ll.addView(textView); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java index d116a48475..b7d10fe088 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java @@ -3,19 +3,18 @@ package net.osmand.plus.mapcontextmenu.controllers; import android.graphics.drawable.Drawable; import net.osmand.data.PointDescription; -import net.osmand.plus.ApplicationMode; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.mapcontextmenu.builders.GpxItemMenuBuilder; public class GpxItemMenuController extends MenuController { private GpxDisplayItem item; public GpxItemMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, GpxDisplayItem item) { - super(new MenuBuilder(app), pointDescription, mapActivity); + super(new GpxItemMenuBuilder(app, item), pointDescription, mapActivity); this.item = item; } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java index d210f98b11..81c826e794 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java @@ -344,20 +344,32 @@ public class SelectedGPXFragment extends OsmAndListFragment { : null); } if(vis.isChecked() && sf.getGpxFile() != null) { - WptPt wpt = sf.getGpxFile().findPointToShow(); - if (wpt != null) { - app.getSettings().setMapLocationToShow(wpt.getLatitude(), wpt.getLongitude(), 15, null, false, - false); //$NON-NLS-1$ - MapActivity.launchMapActivityMoveToTop(activity); + if (groups.size() > 0 && groups.get(0).getModifiableList().size() > 0) { + GpxDisplayItem item = groups.get(0).getModifiableList().get(0); + app.getSettings().setMapLocationToShow(item.locationStart.lat, item.locationStart.lon, + 15, + new PointDescription(PointDescription.POINT_TYPE_GPX_ITEM, item.group.getGpxName()), + false, + item); //$NON-NLS-1$ + } else { + WptPt wpt = sf.getGpxFile().findPointToShow(); + if (wpt != null) { + app.getSettings().setMapLocationToShow(wpt.getLatitude(), wpt.getLongitude(), + 15, + new PointDescription(PointDescription.POINT_TYPE_WPT, wpt.name), + false, + wpt); //$NON-NLS-1$ + } } + MapActivity.launchMapActivityMoveToTop(activity); } } }); - + bld.show(); - + } - + private void updateSplit(final List groups, final List distanceSplit, final TIntArrayList timeSplit, final int which, final SelectedGpxFile sf) { new AsyncTask() { @@ -496,7 +508,7 @@ public class SelectedGPXFragment extends OsmAndListFragment { } else { settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), - new PointDescription(PointDescription.POINT_TYPE_GPX_ITEM, child.name), + new PointDescription(PointDescription.POINT_TYPE_GPX_ITEM, child.group.getGpxName()), false, child); }