Fix track segment context menu
This commit is contained in:
parent
59ea0b71a3
commit
7d39da011c
9 changed files with 167 additions and 30 deletions
|
@ -116,6 +116,7 @@
|
|||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/context_menu_line2_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
|
|
|
@ -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<GpxDisplayItem> list = new ArrayList<GpxDisplayItem>();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<GpxDisplayGroup> groups, final List<Double> distanceSplit,
|
||||
final TIntArrayList timeSplit, final int which, final SelectedGpxFile sf) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue