From 24742f78ce04f2f8e88be2c229bd3862b6af1a05 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 8 Mar 2017 11:33:11 +0300 Subject: [PATCH] Track details menu fixes, added to route info. --- OsmAnd/res/layout/route_info_header.xml | 36 +++++++++ .../net/osmand/plus/GpxSelectionHelper.java | 44 ++++++---- .../osmand/plus/activities/MapActivity.java | 5 +- .../ShowRouteInfoDialogFragment.java | 80 ++++++++++++++++++- .../net/osmand/plus/helpers/GpxUiHelper.java | 4 + .../other/MapRouteInfoMenu.java | 17 ++-- .../other/TrackDetailsMenu.java | 12 +-- .../MapMarkerSelectionFragment.java | 12 --- .../osmand/plus/views/ContextMenuLayer.java | 2 + .../osmand/plus/views/MapControlsLayer.java | 9 ++- 10 files changed, 170 insertions(+), 51 deletions(-) diff --git a/OsmAnd/res/layout/route_info_header.xml b/OsmAnd/res/layout/route_info_header.xml index 6a49090c88..9e6242942d 100644 --- a/OsmAnd/res/layout/route_info_header.xml +++ b/OsmAnd/res/layout/route_info_header.xml @@ -252,6 +252,42 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index f05f1f2768..bef33a0419 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -86,8 +86,25 @@ public class GpxSelectionHelper { return app.getString(resId, formatArgs); } - public List collectDisplayGroups(GPXFile g) { - List dg = new ArrayList<>(); + public GpxDisplayGroup buildGpxDisplayGroup(GPXFile g, int trackIndex, String name) { + Track t = g.tracks.get(trackIndex); + GpxDisplayGroup group = new GpxDisplayGroup(g); + group.gpxName = name; + group.color = t.getColor(g.getColor(0)); + group.setType(GpxDisplayItemType.TRACK_SEGMENT); + group.setTrack(t); + String ks = (trackIndex + 1) + ""; + group.setName(getString(R.string.gpx_selection_track, name, g.tracks.size() == 1 ? "" : ks)); + String d = ""; + if (t.name != null && t.name.length() > 0) { + d = t.name + " " + d; + } + group.setDescription(d); + processGroupTrack(app, group); + return group; + } + + private String getGroupName(GPXFile g) { String name = g.path; if (g.showCurrentTrack) { name = getString(R.string.shared_string_currently_recording_track); @@ -105,23 +122,16 @@ public class GpxSelectionHelper { } name = name.replace('_', ' '); } + return name; + } + + public List collectDisplayGroups(GPXFile g) { + List dg = new ArrayList<>(); + String name = getGroupName(g); if (g.tracks.size() > 0) { - 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); - String ks = (k++) + ""; - group.setName(getString(R.string.gpx_selection_track, name, g.tracks.size() == 1 ? "" : ks)); - String d = ""; - if (t.name != null && t.name.length() > 0) { - d = t.name + " " + d; - } - group.setDescription(d); + for (int i = 0; i < g.tracks.size(); i++) { + GpxDisplayGroup group = buildGpxDisplayGroup(g, i, name); dg.add(group); - processGroupTrack(app, group); } } if (g.routes.size() > 0) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index ec9a25adb1..bf2b326cea 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -54,7 +54,6 @@ import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.InitEvents; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; @@ -91,7 +90,6 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; -import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; @@ -448,6 +446,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } if (TrackDetailsMenu.isVisible()) { getMapLayers().getMapControlsLayer().getTrackDetailsMenu().hide(); + if (prevActivityIntent == null) { + return; + } } if (prevActivityIntent != null && getSupportFragmentManager().getBackStackEntryCount() == 0) { prevActivityIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index 3de64e5bac..27408bf84e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -1,6 +1,8 @@ package net.osmand.plus.activities; import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnDismissListener; import android.content.Intent; import android.graphics.Color; import android.graphics.PorterDuff; @@ -30,6 +32,7 @@ import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import net.osmand.Location; +import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; @@ -37,6 +40,8 @@ import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.Track; import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.IconsCache; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; @@ -44,6 +49,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; +import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; @@ -68,6 +74,8 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { private ListView listView; private RouteInfoAdapter adapter; private GPXFile gpx; + private OrderedLineDataSet elevationDataSet; + private GpxDisplayItem gpxItem; private boolean hasHeights; public ShowRouteInfoDialogFragment() { @@ -210,6 +218,12 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { } track.segments.add(seg); gpx.tracks.add(track); + + String groupName = getMyApplication().getString(R.string.current_route); + GpxDisplayGroup group = getMyApplication().getSelectedGpxHelper().buildGpxDisplayGroup(gpx, 0, groupName); + if (group != null && group.getModifiableList().size() > 0) { + gpxItem = group.getModifiableList().get(0); + } } } @@ -228,11 +242,11 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { GPXTrackAnalysis analysis = gpx.getAnalysis(0); if (analysis.totalDistance > 0) { List dataSets = new ArrayList<>(); - GpxUiHelper.OrderedLineDataSet elevationDataSet = + elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, mChart, analysis, GPXDataSetAxisType.DISTANCE, false, true); dataSets.add(elevationDataSet); if (analysis.elevationData.size() > 1) { - GpxUiHelper.OrderedLineDataSet slopeDataSet = + OrderedLineDataSet slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, mChart, analysis, GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true); dataSets.add(slopeDataSet); } @@ -263,6 +277,68 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_descent)); ((ImageView) headerView.findViewById(R.id.ascent_icon)) .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_ascent)); + + headerView.findViewById(R.id.details_view).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + openDetails(); + } + }); + } + + void openDetails() { + if (gpxItem != null) { + LatLon location = null; + WptPt wpt = null; + gpxItem.chartType = GpxUiHelper.GPXDataSetType.ALTITUDE; + if (gpxItem.chartHighlightPos != -1) { + TrkSegment segment = gpx.tracks.get(0).segments.get(0); + if (segment != null) { + float distance = gpxItem.chartHighlightPos * elevationDataSet.getDivX(); + for (WptPt p : segment.points) { + if (p.distance >= distance) { + wpt = p; + break; + } + } + if (wpt != null) { + location = new LatLon(wpt.lat, wpt.lon); + } + } + } + + if (location == null) { + location = new LatLon(gpxItem.locationStart.lat, gpxItem.locationStart.lon); + } + if (wpt != null) { + gpxItem.locationOnMap = wpt; + } else { + gpxItem.locationOnMap = gpxItem.locationStart; + } + + final MapActivity activity = (MapActivity)getActivity(); + if (activity != null) { + dismiss(); + final MapRouteInfoMenu mapRouteInfoMenu = activity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); + final LatLon fLocation = location; + mapRouteInfoMenu.setOnDismissListener(new OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + mapRouteInfoMenu.setOnDismissListener(null); + + final OsmandSettings settings = activity.getMyApplication().getSettings(); + settings.setMapLocationToShow(fLocation.getLatitude(), fLocation.getLongitude(), + settings.getLastKnownMapZoom(), + new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name), + false, + gpxItem); + + MapActivity.launchMapActivityMoveToTop(activity); + } + }); + mapRouteInfoMenu.hide(); + } + } } private void buildMenuButtons() { diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index be00ec5e94..ebff0a5bf0 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -1198,6 +1198,10 @@ public class GpxUiHelper { for (Speed s : speedData) { x = axisType == GPXDataSetAxisType.TIME ? s.time : (float) s.distance; if (x > 0) { + if (axisType == GPXDataSetAxisType.TIME && x > 60) { + values.add(new Entry(nextX + 1, 0)); + values.add(new Entry(nextX + x - 1, 0)); + } nextX += x / divX; if (Float.isNaN(divSpeed)) { nextY = (float) (s.speed * mulSpeed); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java index 919a0b8d66..825caa2c4c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java @@ -80,9 +80,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener { private AddressLookupRequest startPointRequest; private AddressLookupRequest targetPointRequest; private List intermediateRequestsLatLon = new ArrayList<>(); + private OnDismissListener onDismissListener; private OnMarkerSelectListener onMarkerSelectListener; - private OnDismissListener onDismissDialogListener; private static final long SPINNER_MY_LOCATION_ID = 1; private static final long SPINNER_FAV_ID = 2; @@ -116,6 +116,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener { }; } + public OnDismissListener getOnDismissListener() { + return onDismissListener; + } + + public void setOnDismissListener(OnDismissListener onDismissListener) { + this.onDismissListener = onDismissListener; + } + public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { if (selectFromMapTouch) { LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y); @@ -136,10 +144,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener { return onMarkerSelectListener; } - public OnDismissListener getOnDismissDialogListener() { - return onDismissDialogListener; - } - private void cancelStartPointAddressRequest() { if (startPointRequest != null) { geocodingLookupService.cancel(startPointRequest); @@ -848,6 +852,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener { if (getTargets().getPointToNavigate() == null && !selectFromMapTouch) { mapActivity.getMapActions().stopNavigationWithoutConfirm(); } + if (onDismissListener != null) { + onDismissListener.onDismiss(null); + } } public void show() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 6546cc8d4c..cddfa56157 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -31,8 +31,6 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; -import net.osmand.plus.views.MapControlsLayer; -import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -43,18 +41,13 @@ import java.util.List; public class TrackDetailsMenu { private MapActivity mapActivity; - private OsmandMapTileView mapView; - private MapControlsLayer mapControlsLayer; private GpxDisplayItem gpxItem; private TrackDetailsBarController toolbarController; private static boolean VISIBLE; - private boolean nightMode; - public TrackDetailsMenu(MapActivity mapActivity, MapControlsLayer mapControlsLayer) { + public TrackDetailsMenu(MapActivity mapActivity) { this.mapActivity = mapActivity; - this.mapControlsLayer = mapControlsLayer; - mapView = mapActivity.getMapView(); } public GpxDisplayItem getGpxItem() { @@ -138,7 +131,6 @@ public class TrackDetailsMenu { } public void updateInfo(final View main) { - nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); updateView(main); } @@ -299,6 +291,7 @@ public class TrackDetailsMenu { yAxisArrow.setVisibility(View.VISIBLE); } else { yAxis.setOnClickListener(null); + yAxis.setBackgroundResource(0); yAxisArrow.setVisibility(View.GONE); } @@ -342,6 +335,7 @@ public class TrackDetailsMenu { xAxisArrow.setVisibility(View.VISIBLE); } else { xAxis.setOnClickListener(null); + xAxis.setBackgroundResource(0); xAxisArrow.setVisibility(View.GONE); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java index 3cbb42af5c..ad4f54e62f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java @@ -1,8 +1,6 @@ package net.osmand.plus.mapmarkers; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnDismissListener; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; @@ -41,7 +39,6 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment { private boolean target; private OnMarkerSelectListener onClickListener; - private OnDismissListener onDismissListener; @Nullable @Override @@ -62,7 +59,6 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment { if (mapActivity != null) { MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); onClickListener = routeInfoMenu.getOnMarkerSelectListener(); - onDismissListener = routeInfoMenu.getOnDismissDialogListener(); screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity); @@ -112,14 +108,6 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment { return view; } - @Override - public void onDismiss(DialogInterface dialog) { - super.onDismiss(dialog); - if (onDismissListener != null) { - onDismissListener.onDismiss(dialog); - } - } - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 6482e820bc..236c0a1a79 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -315,6 +315,7 @@ public class ContextMenuLayer extends OsmandMapLayer { menu.hide(); mInGpxDetailsMode = true; + activity.disableDrawer(); mark(View.INVISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); @@ -329,6 +330,7 @@ public class ContextMenuLayer extends OsmandMapLayer { public void exitGpxDetailsMode() { mInGpxDetailsMode = false; + activity.enableDrawer(); mark(View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 37b443410f..bcd4749004 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -282,7 +282,7 @@ public class MapControlsLayer extends OsmandMapLayer { private void initRouteControls() { mapRouteInfoMenu = new MapRouteInfoMenu(mapActivity, this); - trackDetailsMenu = new TrackDetailsMenu(mapActivity, this); + trackDetailsMenu = new TrackDetailsMenu(mapActivity); } public void updateRouteButtons(View main, boolean routeInfo) { @@ -633,6 +633,7 @@ public class MapControlsLayer extends OsmandMapLayer { } boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode(); boolean routeDialogOpened = MapRouteInfoMenu.isVisible(); + boolean trackDialogOpened = TrackDetailsMenu.isVisible(); boolean showRouteCalculationControls = routePlanningMode || ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode); updateMyLocation(rh, routeDialogOpened); @@ -654,13 +655,13 @@ public class MapControlsLayer extends OsmandMapLayer { mapZoomIn.updateVisibility(!routeDialogOpened); mapZoomOut.updateVisibility(!routeDialogOpened); - compassHud.updateVisibility(!routeDialogOpened && shouldShowCompass()); + compassHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && shouldShowCompass()); if (layersHud.setIconResId(settings.getApplicationMode().getSmallIconDark())) { layersHud.update(app, isNight); } - layersHud.updateVisibility(!routeDialogOpened); - quickSearchHud.updateVisibility(!routeDialogOpened); + layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened); + quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened); if (!routePlanningMode && !routeFollowingMode) { if (mapView.isZooming()) {