From 7d1f4c38b651d87c3c3113f8f99f5b41b16ac30f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 19 Aug 2014 10:53:23 +0200 Subject: [PATCH] Refactor points --- .../plus/helpers/WaypointDialogHelper.java | 9 ++-- .../osmand/plus/helpers/WaypointHelper.java | 52 +++++++++---------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index be75cb4f6b..633b6e8cc4 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -9,7 +9,6 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.MapControlsLayer; @@ -43,6 +42,7 @@ public class WaypointDialogHelper { public final static boolean OVERLAP_LAYOUT = true; // only true is supported private View closePointDialog; + private List many = new ArrayList(); public WaypointDialogHelper(MapActivity mapActivity) { @@ -53,11 +53,10 @@ public class WaypointDialogHelper { } public void updateDialog() { - List vlp = waypointHelper.getWaypoints(WaypointHelper.FAVORITES); - if (vlp.isEmpty()) { + final LocationPointWrapper point = waypointHelper.getMostImportantLocationPoint(many); + if (point == null) { removeDialog(); } else { - final LocationPointWrapper point = vlp.get(0); boolean created = false; if (closePointDialog == null) { created = true; @@ -66,7 +65,7 @@ public class WaypointDialogHelper { } updatePointInfoView(app, mapActivity, closePointDialog, point); View all = closePointDialog.findViewById(R.id.all_points); - all.setVisibility(vlp.size() <= 1 ? View.GONE : View.VISIBLE); + all.setVisibility(many.size() <= 1 ? View.GONE : View.VISIBLE); if (created) { closePointDialog.setBackgroundColor(mapActivity.getResources().getColor(R.color.color_black)); ((TextView) closePointDialog.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 984371fbd1..811c0a9e33 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -89,41 +89,37 @@ public class WaypointHelper { } } - public LocationPointWrapper getMostImportantLocationPoint(LocationPoint p) { + public LocationPointWrapper getMostImportantLocationPoint(List list ) { //Location lastProjection = app.getRoutingHelper().getLastProjection(); + if(list != null) { + list.clear(); + } + LocationPointWrapper found = null; for (int type = 0; type < locationPoints.size(); type++) { if(type == ALARMS || type == TARGETS) { continue; } int kIterator = pointsProgress.get(type); + List lp = locationPoints.get(type); + while(kIterator < lp.size()) { + LocationPointWrapper lwp = lp.get(kIterator); + if(lp.get(kIterator).routeIndex < route.getCurrentRoute()) { + // skip + } else { + if(route.getDistanceToPoint(lwp.routeIndex) <= LONG_ANNOUNCE_RADIUS ) { + if(found == null || found.routeIndex < lwp.routeIndex) { + found = lwp; + if(list != null) { + list.add(lwp); + } + } + } + break; + } + kIterator++; + } } - if(ALARMS < pointsProgress.size()) { - -// List lp = locationPoints.get(ALARMS); -// while(kIterator < lp.size()) { -// LocationPointWrapper lwp = lp.get(kIterator); -// if(lp.get(kIterator).routeIndex < route.getCurrentRoute()) { -// // skip -// } else if(route.getDistanceToPoint(lwp.routeIndex) > LONG_ANNOUNCE_RADIUS ){ -// break; -// } else { -// AlarmInfo inf = (AlarmInfo) lwp.point; -// int d = route.getDistanceToPoint(lwp.routeIndex); -// if(d > 250){ -// break; -// } -// float speed = lastProjection != null && lastProjection.hasSpeed() ? lastProjection.getSpeed() : 0; -// float time = speed > 0 ? d / speed : Integer.MAX_VALUE; -// int vl = inf.updateDistanceAndGetPriority(time, d); -// if(vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)){ -// mostImportant = inf; -// value = vl; -// } -// } -// kIterator++; -// } - } - return null; + return found; } public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) {